Commits

rob...@16af8721-9629-0410-8352-f15c8da7e697  committed 2b73cd7 Draft

Introduced --near-far-mode into osgshadow and ShadowSettings::setComputeNearFarModeOverride(..) to allow user control of how the cull traversal is optimized for computing the depth range of the shadow map.

  • Participants
  • Parent commits 33b7491

Comments (0)

Files changed (4)

File examples/osgshadow/osgshadow.cpp

     arguments.getApplicationUsage()->addCommandLineOption("-4", "Use test model four - island scene.");
     arguments.getApplicationUsage()->addCommandLineOption("--two-sided", "Use two-sided stencil extension for shadow volumes.");
     arguments.getApplicationUsage()->addCommandLineOption("--two-pass", "Use two-pass stencil for shadow volumes.");
+    arguments.getApplicationUsage()->addCommandLineOption("--near-far-mode","COMPUTE_NEAR_USING_PRIMITIVES, COMPUTE_NEAR_FAR_USING_PRIMITIVES, COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES, DO_NOT_COMPUTE_NEAR_FAR");
 
     // construct the viewer.
     osgViewer::Viewer viewer(arguments);
     settings->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
     settings->setCastsShadowTraversalMask(CastsShadowTraversalMask);
 
+    std::string nearFarMode("");
+    if (arguments.read("--near-far-mode",nearFarMode))
+    {
+        if (nearFarMode=="COMPUTE_NEAR_USING_PRIMITIVES")                settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_USING_PRIMITIVES);
+        else if (nearFarMode=="COMPUTE_NEAR_FAR_USING_PRIMITIVES")       settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
+        else if (nearFarMode=="DO_NOT_COMPUTE_NEAR_FAR")                 settings->setComputeNearFarModeOverride(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
+        else if (nearFarMode=="COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES") settings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
+
+        OSG_NOTICE<<"ComputeNearFarModeOverride set to ";
+        switch(settings->getComputeNearFarModeOverride())
+        {
+            case(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES): OSG_NOTICE<<"COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES"; break;
+            case(osg::CullSettings::COMPUTE_NEAR_USING_PRIMITIVES): OSG_NOTICE<<"COMPUTE_NEAR_USING_PRIMITIVES"; break;
+            case(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES): OSG_NOTICE<<"COMPUTE_NEAR_FAR_USING_PRIMITIVES"; break;
+            case(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR): OSG_NOTICE<<"DO_NOT_COMPUTE_NEAR_FAR"; break;
+        }
+        OSG_NOTICE<<std::endl;
+    }
+    
     osg::ref_ptr<osgShadow::MinimalShadowMap> msm = NULL;
     if (arguments.read("--no-shadows"))
     {

File include/osgShadow/ShadowSettings

 #define OSGSHADOW_SHADOWSETTINGS 1
 
 #include <osg/Uniform>
+#include <osg/CullSettings>
 #include <osgShadow/Export>
 
 namespace osgShadow {
         void setCastsShadowTraversalMask(unsigned int mask) { _castsShadowTraversalMask = mask; }
         unsigned int getCastsShadowTraversalMask() const { return _castsShadowTraversalMask; }
 
+        void setComputeNearFarModeOverride(osg::CullSettings::ComputeNearFarMode cnfn) { _computeNearFearModeOverride = cnfn; }
+        osg::CullSettings::ComputeNearFarMode getComputeNearFarModeOverride() const { return _computeNearFearModeOverride; }
+
+        
         /** Set the LightNum of the light in the scene to assign a shadow for.
           * Default value is -1, which signifies that shadow technique should automatically select an active light
           * to assign a shadow, typically this will be the first active light found. */
         unsigned int            _receivesShadowTraversalMask;
         unsigned int            _castsShadowTraversalMask;
 
+        osg::CullSettings::ComputeNearFarMode _computeNearFearModeOverride;
+
         int                     _lightNum;
         unsigned int            _baseShadowTextureUnit;
         bool                    _useShadowMapTextureOverride;

File src/osgShadow/ShadowSettings.cpp

 ShadowSettings::ShadowSettings():
     _receivesShadowTraversalMask(0xffffffff),
     _castsShadowTraversalMask(0xffffffff),
+    _computeNearFearModeOverride(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR),
     _lightNum(-1),
     _baseShadowTextureUnit(1),
     _useShadowMapTextureOverride(true),
 //    _shaderHint(PROVIDE_FRAGMENT_SHADER),
     _debugDraw(false)
 {
+    //_computeNearFearModeOverride = osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES;
+    //_computeNearFearModeOverride = osg::CullSettings::COMPUTE_NEAR_USING_PRIMITIVES);
 }
 
 ShadowSettings::ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copyop):
     Object(ss,copyop),
     _receivesShadowTraversalMask(ss._receivesShadowTraversalMask),
     _castsShadowTraversalMask(ss._castsShadowTraversalMask),
+    _computeNearFearModeOverride(ss._computeNearFearModeOverride),
     _lightNum(ss._lightNum),
     _baseShadowTextureUnit(ss._baseShadowTextureUnit),
     _useShadowMapTextureOverride(ss._useShadowMapTextureOverride),

File src/osgShadow/ViewDependentShadowMap.cpp

         return;
     }
 
+    ShadowSettings* settings = getShadowedScene()->getShadowSettings();
+
     OSG_INFO<<"cv->getProjectionMatrix()="<<*cv.getProjectionMatrix()<<std::endl;
 
     osg::CullSettings::ComputeNearFarMode cachedNearFarMode = cv.getComputeNearFarMode();
     }
 
     // set the compute near/far mode to the highest quality setting to ensure we push the near plan out as far as possible
-    cv.setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
-    //cv.setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_USING_PRIMITIVES);
+    if (settings->getComputeNearFarModeOverride()!=osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR)
+    {
+        cv.setComputeNearFarMode(settings->getComputeNearFarModeOverride());
+    }
 
     // 1. Traverse main scene graph
     cv.pushStateSet( _shadowRecievingPlaceholderStateSet.get() );
         cv.computeNearPlane();
     }
 
+    //minZNear = osg::maximum(10.0,minZNear);
+    //maxZFar = osg::minimum(60.0,maxZFar);
+
     Frustum frustum(&cv, minZNear, maxZFar);
 
     // return compute near far mode back to it's original settings
     //    create a list of light sources + their matrices to place them
     selectActiveLights(&cv, vdd);
 
-    ShadowSettings* settings = getShadowedScene()->getShadowSettings();
 
     unsigned int pos_x = 0;
     unsigned int textureUnit = settings->getBaseShadowTextureUnit();