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()<