Added support for setting the MinimumShadowMapNearFarRatio.

This commit is contained in:
Robert Osfield 2011-08-29 09:59:47 +00:00
parent 771075084b
commit 2d71a390d3
3 changed files with 12 additions and 2 deletions

View File

@ -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") )

View File

@ -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<osg::Program> _program;
ShadowMapProjectionHint _shadowMapProjectionHint;
double _minimumShadowMapNearFarRatio;
bool _debugDraw;
};

View File

@ -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<min_n)
{
OSG_INFO<<"Clamping n to eye point"<<std::endl;