From: Mikko Rasa Date: Fri, 4 Dec 2015 18:41:43 +0000 (+0200) Subject: Calculate depths in ZSortedScene more efficiently X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b345b919f572b35042d7c50291422f2f917e5a08;p=libs%2Fgl.git Calculate depths in ZSortedScene more efficiently --- diff --git a/source/zsortedscene.cpp b/source/zsortedscene.cpp index f61de577..0d50ae1e 100644 --- a/source/zsortedscene.cpp +++ b/source/zsortedscene.cpp @@ -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 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 *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)); }