diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index 2d4341a9b..2967cea26 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -837,6 +837,9 @@ int main(int argc, char** argv) unsigned int unit=1; if (arguments.read("--unit",unit)) vdsm->setBaseShadowTextureUnit(unit); + double n=0.0; + if (arguments.read("-n",n)) vdsm->setMinimumShadowMapNearFarRatio(n); + shadowedScene->setShadowTechnique(vdsm.get()); } else if ( arguments.read("--lispsm") ) diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index e8285da0a..af7dcf111 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -168,6 +168,10 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; } ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; } + void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; } + double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; } + + virtual void createShaders(); virtual bool selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const; @@ -210,6 +214,7 @@ protected: osg::ref_ptr _program; ShadowMapProjectionHint _shadowMapProjectionHint; + double _minimumShadowMapNearFarRatio; bool _debugDraw; }; diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 04b7d1c83..729158e4d 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -522,8 +522,9 @@ void ViewDependentShadowMap::ViewDependentData::releaseGLObjects(osg::State* sta // ViewDependentShadowMap::ViewDependentShadowMap(): ShadowTechnique(), - _baseShadowTextureUnit(1), + _baseShadowTextureUnit(1), _shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP), + _minimumShadowMapNearFarRatio(0.01), _debugDraw(false) { _shadowRecievingPlaceholderStateSet = new osg::StateSet; @@ -533,6 +534,7 @@ ViewDependentShadowMap::ViewDependentShadowMap(const ViewDependentShadowMap& vds ShadowTechnique(vdsm,copyop), _baseShadowTextureUnit(vdsm._baseShadowTextureUnit), _shadowMapProjectionHint(vdsm._shadowMapProjectionHint), + _minimumShadowMapNearFarRatio(vdsm._minimumShadowMapNearFarRatio), _debugDraw(vdsm._debugDraw) { _shadowRecievingPlaceholderStateSet = new osg::StateSet; @@ -1581,7 +1583,7 @@ bool ViewDependentShadowMap::adjustPerspectiveShadowMapCameraSettings(osgUtil::R double alpha = osg::DegreesToRadians(30.0); double n = tan(alpha)*tan(osg::PI_2-gamma_v)*tan(osg::PI_2-gamma_v); //double n = tan(alpha)*tan(osg::PI_2-gamma_v); - double min_n = osg::maximum(-1.0-eye_ls.y(), 0.01); + double min_n = osg::maximum(-1.0-eye_ls.y(), _minimumShadowMapNearFarRatio); if (n