From 966981f1000af337f3173e840b69f201c1adf90f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 25 Aug 2011 17:21:38 +0000 Subject: [PATCH] Improved the handling of depth partitioning and orthographic datasets --- include/osgShadow/ViewDependentShadowMap | 2 +- src/osgShadow/ViewDependentShadowMap.cpp | 123 +++++++++++++++++------ 2 files changed, 93 insertions(+), 32 deletions(-) diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index bfacedefa..1855e65ec 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -49,7 +49,7 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique struct OSGSHADOW_EXPORT Frustum { - Frustum(osgUtil::CullVisitor* cv); + Frustum(osgUtil::CullVisitor* cv, double minZNear, double maxZFar); osg::Matrixd projectionMatrix; osg::Matrixd modelViewMatrix; diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 42d747d12..b4bc949da 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -320,7 +320,7 @@ ViewDependentShadowMap::ShadowData::ShadowData(ViewDependentShadowMap::ViewDepen //_camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); _camera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f)); - //_camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR); + _camera->setComputeNearFarMode(osg::Camera::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES); // set viewport _camera->setViewport(0,0,textureSize,textureSize); @@ -359,7 +359,7 @@ ViewDependentShadowMap::ShadowData::ShadowData(ViewDependentShadowMap::ViewDepen // // Frustum // -ViewDependentShadowMap::Frustum::Frustum(osgUtil::CullVisitor* cv): +ViewDependentShadowMap::Frustum::Frustum(osgUtil::CullVisitor* cv, double minZNear, double maxZFar): corners(8), faces(6), edges(12) @@ -369,14 +369,17 @@ ViewDependentShadowMap::Frustum::Frustum(osgUtil::CullVisitor* cv): OSG_INFO<<"Projection matrix "<getCalculatedNearPlane(); - osgUtil::CullVisitor::value_type zFar = cv->getCalculatedFarPlane(); + if (cv->getComputeNearFarMode()!=osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR) + { + double zNear = osg::maximum(static_cast(cv->getCalculatedNearPlane()),minZNear); + double zFar = osg::minimum(static_cast(cv->getCalculatedFarPlane()),maxZFar); - cv->clampProjectionMatrix(projectionMatrix,zNear,zFar); - - OSG_INFO<<"zNear = "<clampProjectionMatrix(projectionMatrix, zNear, zFar); + OSG_INFO<<"zNear = "<getProjectionMatrix()="<<*cv.getProjectionMatrix()<