]> git.tdb.fi Git - libs/gl.git/commitdiff
Calculate depths in ZSortedScene more efficiently
authorMikko Rasa <tdb@tdb.fi>
Fri, 4 Dec 2015 18:41:43 +0000 (20:41 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 4 Dec 2015 18:41:43 +0000 (20:41 +0200)
source/zsortedscene.cpp

index f61de57720fc8f394f72aa752f678964a2046ace..0d50ae1ea46fe9536f19c9ee094dee5272beb7a1 100644 (file)
@@ -28,13 +28,13 @@ void ZSortedScene::render(Renderer &renderer, const Tag &tag) const
        if(!camera)
                return SimpleScene::render(renderer, tag);
 
-       const Matrix &view_matrix = camera->get_matrix();
-
        std::vector<DepthRenderable> sorted_renderables;
        sorted_renderables.reserve(renderables.size());
 
-       float radius_factor = 1.0f-reference;
-       float sign = order*2.0f-1.0f;
+       const Vector3 &camera_pos = camera->get_position();
+       const Vector3 &look_dir = camera->get_look_direction();
+       float radius_factor = reference-1.0f;
+       float sign = 1.0f-order*2.0f;
 
        bool use_frustum = setup_frustum(renderer);
        for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
@@ -44,9 +44,9 @@ void ZSortedScene::render(Renderer &renderer, const Tag &tag) const
                        if(const Matrix *model_matrix = (*i)->get_matrix())
                        {
                                if(const Geometry::BoundingSphere<float, 3> *bsphere = (*i)->get_bounding_sphere())
-                                       z = (view_matrix**model_matrix*compose(bsphere->get_center(), 1.0f)).z+bsphere->get_radius()*radius_factor;
+                                       z = dot(*model_matrix*bsphere->get_center()-camera_pos, look_dir)+bsphere->get_radius()*radius_factor;
                                else
-                                       z = (view_matrix**model_matrix*Vector4(0.0f, 0.0f, 0.0f, 1.0f)).z;
+                                       z = dot(*model_matrix*Vector3()-camera_pos, look_dir);
                        }
                        sorted_renderables.push_back(DepthRenderable(z*sign, *i));
                }