1#include "Foundation/Logging/Logger.h"
2#include "Utilities/FrustumClassification.h"
4#include <glm/gtc/packing.hpp>
10Cogs::Core::FrustumPlanes Cogs::Core::frustumClassifyBoundingBox(
const glm::mat4& localToClip,
13 const float discardThreshold,
14 const float keepThreshold)
16 FrustumPlanes retval = FrustumPlanes::InsideNone;
20 for (
int i = 0; i < 8; i++) {
21 glm::vec3 p((i & 1) ? min.x : max.x,
22 (i & 2) ? min.y : max.y,
23 (i & 4) ? min.z : max.z);
24 glm::vec4 h = localToClip * glm::vec4(p.x, p.y, p.z, 1.f);
25 retval |= (h.x <= h.w ? FrustumPlanes::InsidePosX : FrustumPlanes::InsideNone) |
26 (-h.w <= h.x ? FrustumPlanes::InsideNegX : FrustumPlanes::InsideNone) |
27 (h.y <= h.w ? FrustumPlanes::InsidePosY : FrustumPlanes::InsideNone) |
28 (-h.w <= h.y ? FrustumPlanes::InsideNegY : FrustumPlanes::InsideNone) |
29 (h.z <= h.w ? FrustumPlanes::InsidePosZ : FrustumPlanes::InsideNone) |
30 (-h.w <= h.z ? FrustumPlanes::InsideNegZ : FrustumPlanes::InsideNone);
31 float rcp_w = 1.f / h.w;
32 float px = rcp_w * h.x;
33 float py = rcp_w * h.y;
34 lx[0] = ((i == 0) || (px < lx[0])) ? px : lx[0];
35 lx[1] = ((i == 0) || (lx[1] < px)) ? px : lx[1];
36 ly[0] = ((i == 0) || (py < ly[0])) ? py : ly[0];
37 ly[1] = ((i == 0) || (ly[1] < py)) ? py : ly[1];
39 bool discard = (lx[1] - lx[0])*(ly[1] - ly[0]) < discardThreshold;
41 auto diff = max - min;
42 if (glm::any(glm::greaterThan(diff, glm::vec3(keepThreshold)))) {
46 return discard ? FrustumPlanes::InsideNone : retval;
49Cogs::Core::FrustumPlanes Cogs::Core::frustumClassifyBoundingBox(
const glm::mat4& localToClip,
53 FrustumPlanes retval = FrustumPlanes::InsideNone;
54 for (
int i = 0; i < 8; i++) {
55 glm::vec3 p((i & 1) ? min.x : max.x,
56 (i & 2) ? min.y : max.y,
57 (i & 4) ? min.z : max.z);
58 glm::vec4 h = localToClip * glm::vec4(p.x, p.y, p.z, 1.f);
59 retval |= (h.x <= h.w ? FrustumPlanes::InsidePosX : FrustumPlanes::InsideNone) |
60 (-h.w <= h.x ? FrustumPlanes::InsideNegX : FrustumPlanes::InsideNone) |
61 (h.y <= h.w ? FrustumPlanes::InsidePosY : FrustumPlanes::InsideNone) |
62 (-h.w <= h.y ? FrustumPlanes::InsideNegY : FrustumPlanes::InsideNone) |
63 (h.z <= h.w ? FrustumPlanes::InsidePosZ : FrustumPlanes::InsideNone) |
64 (-h.w <= h.z ? FrustumPlanes::InsideNegZ : FrustumPlanes::InsideNone);
Log implementation class.
constexpr Log getLogger(const char(&name)[LEN]) noexcept