diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index d929bb652..c352f5ec5 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -793,6 +793,16 @@ int main(int argc, char** argv) osg::ref_ptr sm = new osgShadow::SoftShadowMap; shadowedScene->setShadowTechnique(sm.get()); } + else if( arguments.read("--vdsm") ) + { + osg::ref_ptr vdsm = new osgShadow::ViewDependentShadowMap; + while( arguments.read("--debugHUD") ) vdsm->setDebugDraw( true ); + + if (arguments.read("--persp")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::PERSPECTIVE_SHADOW_MAP); + if (arguments.read("--lispsm")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::LIGHT_SPACE_PERSPECTIVE_SHADOW_MAP); + + shadowedScene->setShadowTechnique(vdsm.get()); + } else if ( arguments.read("--lispsm") ) { if( arguments.read( "--ViewBounds" ) ) @@ -811,12 +821,6 @@ int main(int argc, char** argv) else // if( arguments.read( "--DrawBounds" ) ) // default msm = new osgShadow::MinimalDrawBoundsShadowMap; } - else if( arguments.read("--vdsm") ) - { - osg::ref_ptr vdsm = new osgShadow::ViewDependentShadowMap; - while( arguments.read("--debugHUD") ) vdsm->setDebugDraw( true ); - shadowedScene->setShadowTechnique(vdsm.get()); - } else /* if (arguments.read("--sm")) */ { osg::ref_ptr sm = new osgShadow::ShadowMap; diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index fc3604909..ba180f237 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -145,8 +145,22 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique virtual osg::Polytope computeLightViewFrustumPolytope(Frustum& frustum, LightData& positionedLight); + enum ShadowMapProjectionHint + { + STANDARD_SHADOW_MAP, + PERSPECTIVE_SHADOW_MAP, + LIGHT_SPACE_PERSPECTIVE_SHADOW_MAP + }; + + void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; } + ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; } + virtual bool computeShadowCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); + virtual bool standardShadowMapCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); + virtual bool perspectiveShadowMapCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); + virtual bool lightSpacePerspectiveShadowMapCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); + virtual bool assignTexGenSettings(osgUtil::CullVisitor* cv, osg::Camera* camera, unsigned int textureUnit, osg::TexGen* texgen); virtual void cullShadowReceivingScene(osgUtil::CullVisitor* cv) const; @@ -175,8 +189,9 @@ protected: typedef std::vector< osg::ref_ptr > Uniforms; Uniforms _uniforms; osg::ref_ptr _program; - - bool _debugDraw; + + ShadowMapProjectionHint _shadowMapProjectionHint; + bool _debugDraw; }; diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index e2141c78f..6c4996545 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -122,7 +122,7 @@ void VDSMCameraCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv) cv->clampProjectionMatrix(projection, zNear, zFar); //OSG_INFO<<"RTT zNear = "<setProjectionMatrix(projection); } @@ -151,19 +151,19 @@ void ViewDependentShadowMap::LightData::setLightData(osg::RefMatrix* lm, const o lightPos3.set(0.0, 0.0, 0.0); // directional light has no destinct position lightDir.set(-lightPos.x(), -lightPos.y(), -lightPos.z()); lightDir.normalize(); - OSG_NOTICE<<" Directional light, lightPos="<getCalculatedNearPlane(); osgUtil::CullVisitor::value_type zFar = cv->getCalculatedFarPlane(); @@ -403,6 +403,7 @@ ViewDependentShadowMap::ViewDependentData::ViewDependentData(ViewDependentShadow // ViewDependentShadowMap::ViewDependentShadowMap(): ShadowTechnique(), + _shadowMapProjectionHint(STANDARD_SHADOW_MAP), _debugDraw(false) { _shadowRecievingPlaceholderStateSet = new osg::StateSet; @@ -410,6 +411,7 @@ ViewDependentShadowMap::ViewDependentShadowMap(): ViewDependentShadowMap::ViewDependentShadowMap(const ViewDependentShadowMap& vdsm, const osg::CopyOp& copyop): ShadowTechnique(vdsm,copyop), + _shadowMapProjectionHint(vdsm._shadowMapProjectionHint), _debugDraw(vdsm._debugDraw) { _shadowRecievingPlaceholderStateSet = new osg::StateSet; @@ -454,13 +456,13 @@ ViewDependentShadowMap::ViewDependentData* ViewDependentShadowMap::getViewDepend void ViewDependentShadowMap::update(osg::NodeVisitor& nv) { - OSG_NOTICE<<"ViewDependentShadowMap::update(osg::NodeVisitor& "<<&nv<<")"<osg::Group::traverse(nv); } void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv) { - OSG_NOTICE<0) { - OSG_NOTICE<<"Need to assign "<setStateSet(selectStateSetForRenderingShadow(*vdd)); } @@ -602,7 +604,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv) bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const { - OSG_NOTICE<<"selectActiveLights"<getLightDataList(); @@ -632,14 +634,14 @@ bool ViewDependentShadowMap::selectActiveLights(osgUtil::CullVisitor* cv, ViewDe if (pll_itr==pll.end()) { - OSG_NOTICE<<"Light num "<getLightNum()<getLightNum()<setLightData(itr->second, light, modelViewMatrix); pll.push_back(ld); } else { - OSG_NOTICE<<"Light num "<getLightNum()<<" already used, ignore light"<getLightNum()<<" already used, ignore light"<setMode(osg::TexGen::EYE_LINEAR); @@ -975,7 +1001,7 @@ bool ViewDependentShadowMap::assignTexGenSettings(osgUtil::CullVisitor* cv, osg: void ViewDependentShadowMap::cullShadowReceivingScene(osgUtil::CullVisitor* cv) const { - OSG_NOTICE<<"cullShadowReceivingScene()"<getTraversalMask(); @@ -991,7 +1017,7 @@ void ViewDependentShadowMap::cullShadowReceivingScene(osgUtil::CullVisitor* cv) void ViewDependentShadowMap::cullShadowCastingScene(osgUtil::CullVisitor* cv, osg::Camera* camera) const { - OSG_NOTICE<<"cullShadowCastingScene()"<getTraversalMask(); @@ -1007,7 +1033,7 @@ void ViewDependentShadowMap::cullShadowCastingScene(osgUtil::CullVisitor* cv, os osg::StateSet* ViewDependentShadowMap::selectStateSetForRenderingShadow(ViewDependentData& vdd) const { - OSG_NOTICE<<" selectStateSetForRenderingShadow() "< stateset = vdd.getStateSet(); @@ -1040,7 +1066,7 @@ osg::StateSet* ViewDependentShadowMap::selectStateSetForRenderingShadow(ViewDepe atu_itr != pl.textureUnits.end(); ++atu_itr) { - OSG_NOTICE<<" Need to assign state for "<<*atu_itr<setTextureAttributeAndModes(sd._textureUnit, sd._texture.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); @@ -1067,4 +1093,3 @@ osg::StateSet* ViewDependentShadowMap::selectStateSetForRenderingShadow(ViewDepe return vdd.getStateSet(); } -