From 69a4ba4fa3e4694887087ab6dddc784a593d2b03 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 10 Dec 2015 13:20:08 +0100 Subject: [PATCH] slight simplification of cull test still horrible, need to precalculate stuff outside the loop --- src/geometry/geometry.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/geometry/geometry.cpp b/src/geometry/geometry.cpp index ebd47e9..7798d33 100644 --- a/src/geometry/geometry.cpp +++ b/src/geometry/geometry.cpp @@ -199,21 +199,19 @@ bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept { { box.max.x, box.max.y, box.min.z, 1.0f }, { box.max.x, box.max.y, box.max.z, 1.0f }, }; + + // check how many corners lie outside + int hits[6] = { 0, 0, 0, 0, 0, 0 }; for (glm::vec4 &corner : corners) { corner = MVP * corner; + // replacing this with *= 1/w is effectively more expensive corner /= corner.w; - } - - int hits[6] = { 0, 0, 0, 0, 0, 0 }; - - // check how many corners lie outside - for (const glm::vec4 &corner : corners) { - if (corner.x > 1.0f) ++hits[0]; - if (corner.x < -1.0f) ++hits[1]; - if (corner.y > 1.0f) ++hits[2]; - if (corner.y < -1.0f) ++hits[3]; - if (corner.z > 1.0f) ++hits[4]; - if (corner.z < -1.0f) ++hits[5]; + hits[0] += (corner.x > 1.0f); + hits[1] += (corner.x < -1.0f); + hits[2] += (corner.y > 1.0f); + hits[3] += (corner.y < -1.0f); + hits[4] += (corner.z > 1.0f); + hits[5] += (corner.z < -1.0f); } // if all corners are outside any given clip plane, the test is true -- 2.39.2