]> git.tdb.fi Git - libs/gl.git/commitdiff
Account for scale when performing frustum culling
authorMikko Rasa <tdb@tdb.fi>
Fri, 25 Nov 2016 21:19:08 +0000 (23:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 25 Nov 2016 21:19:08 +0000 (23:19 +0200)
It will still break with non-uniform scaling.

source/scene.cpp

index 1625ca32c7c74052cdec47cdf10f741d26115f12..6c3d2910706db98d6f2ecd7ed67b3dd771c372e8 100644 (file)
@@ -66,11 +66,15 @@ bool Scene::frustum_cull(const Renderable &renderable) const
                return false;
 
        Vector4 center = culling_matrix*(*matrix*compose(bsphere->get_center(), 1.0f));
-       float radius = bsphere->get_radius();
+       Vector4 x_axis = *matrix*Vector4(1.0f, 0.0f, 0.0f, 0.0f);
+       float radius_sq = bsphere->get_radius()*inner_product(x_axis, x_axis);
 
        for(unsigned i=0; i<6; ++i)
-               if(inner_product(center, frustum_edges[i])>radius)
+       {
+               float distance = inner_product(center, frustum_edges[i]);
+               if(distance*distance>radius_sq)
                        return true;
+       }
 
        return false;
 }