From bf013aea54128c97cf314f2999cfd44e8f9d24f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Mon, 30 Mar 2020 18:40:59 +0200 Subject: [PATCH] Compositor: Improve custom depth range handling in scene passes. --- simgear/scene/viewer/CompositorPass.cxx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/simgear/scene/viewer/CompositorPass.cxx b/simgear/scene/viewer/CompositorPass.cxx index dd89237f..625aae76 100644 --- a/simgear/scene/viewer/CompositorPass.cxx +++ b/simgear/scene/viewer/CompositorPass.cxx @@ -573,7 +573,7 @@ RegisterPassBuilder registerShadowMapPass("shadow-map"); class SceneUpdateCallback : public Pass::PassUpdateCallback { public: - SceneUpdateCallback(int cubemap_face, float zNear, float zFar) : + SceneUpdateCallback(int cubemap_face, double zNear, double zFar) : _cubemap_face(cubemap_face), _zNear(zNear), _zFar(zFar) {} @@ -608,10 +608,14 @@ public: 1.0, 10000.0); } - if (_zNear != 0.0f && _zFar != 0.0f) { - osg::Matrix new_proj; - makeNewProjMat(camera->getProjectionMatrix(), - _zNear, _zFar, new_proj); + if (_zNear != 0.0 || _zFar != 0.0) { + osg::Matrixd given_proj = camera->getProjectionMatrix(); + double left, right, bottom, top, znear, zfar; + given_proj.getFrustum(left, right, bottom, top, znear, zfar); + if (_zNear != 0.0) znear = _zNear; + if (_zFar != 0.0) zfar = _zFar; + osg::Matrixd new_proj; + makeNewProjMat(given_proj, znear, zfar, new_proj); camera->setProjectionMatrix(new_proj); } } @@ -652,8 +656,8 @@ protected: } int _cubemap_face; - float _zNear; - float _zFar; + double _zNear; + double _zFar; }; class SceneCullCallback : public osg::NodeCallback {