Added ShadowSettings::s/getMaximumShadowMapDistance(double) property, usage of these property in ViewDependentShadowMap,

and setting of it with --max-shadow-distance <double> in the osgshadow example.
This commit is contained in:
Robert Osfield 2012-08-15 12:40:48 +00:00
parent 52861ecbb0
commit 284f410436
4 changed files with 22 additions and 2 deletions

View File

@ -742,6 +742,7 @@ int main(int argc, char** argv)
arguments.getApplicationUsage()->addCommandLineOption("--two-sided", "Use two-sided stencil extension for shadow volumes."); 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("--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"); 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");
arguments.getApplicationUsage()->addCommandLineOption("--max-shadow-distance","<float> Maximum distance that the shadow map should extend from the eye point.");
// construct the viewer. // construct the viewer.
osgViewer::Viewer viewer(arguments); osgViewer::Viewer viewer(arguments);
@ -859,6 +860,14 @@ int main(int argc, char** argv)
} }
OSG_NOTICE<<std::endl; OSG_NOTICE<<std::endl;
} }
double distance;
if (arguments.read("--max-shadow-distance",distance))
{
settings->setMaximumShadowMapDistance(distance);
OSG_NOTICE<<"MaximumShadowMapDistance set to "<<settings->getMaximumShadowMapDistance()<<std::endl;
}
osg::ref_ptr<osgShadow::MinimalShadowMap> msm = NULL; osg::ref_ptr<osgShadow::MinimalShadowMap> msm = NULL;
if (arguments.read("--no-shadows")) if (arguments.read("--no-shadows"))

View File

@ -65,6 +65,10 @@ class OSGSHADOW_EXPORT ShadowSettings : public osg::Object
void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; } void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; }
double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; } double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; }
void setMaximumShadowMapDistance(double distance) { _maximumShadowMapDistance = distance; }
double getMaximumShadowMapDistance() const { return _maximumShadowMapDistance; }
enum ShadowMapProjectionHint enum ShadowMapProjectionHint
{ {
ORTHOGRAPHIC_SHADOW_MAP, ORTHOGRAPHIC_SHADOW_MAP,
@ -126,6 +130,7 @@ class OSGSHADOW_EXPORT ShadowSettings : public osg::Object
osg::Vec2s _textureSize; osg::Vec2s _textureSize;
double _minimumShadowMapNearFarRatio; double _minimumShadowMapNearFarRatio;
double _maximumShadowMapDistance;
ShadowMapProjectionHint _shadowMapProjectionHint; ShadowMapProjectionHint _shadowMapProjectionHint;
double _perspectiveShadowMapCutOffAngle; double _perspectiveShadowMapCutOffAngle;

View File

@ -12,6 +12,7 @@
*/ */
#include <osgShadow/ShadowSettings> #include <osgShadow/ShadowSettings>
#include <float.h>
using namespace osgShadow; using namespace osgShadow;
@ -24,6 +25,7 @@ ShadowSettings::ShadowSettings():
_useShadowMapTextureOverride(true), _useShadowMapTextureOverride(true),
_textureSize(2048,2048), _textureSize(2048,2048),
_minimumShadowMapNearFarRatio(0.05), _minimumShadowMapNearFarRatio(0.05),
_maximumShadowMapDistance(DBL_MAX),
_shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP), _shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP),
_perspectiveShadowMapCutOffAngle(2.0), _perspectiveShadowMapCutOffAngle(2.0),
_numShadowMapsPerLight(1), _numShadowMapsPerLight(1),
@ -46,6 +48,7 @@ ShadowSettings::ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copy
_useShadowMapTextureOverride(ss._useShadowMapTextureOverride), _useShadowMapTextureOverride(ss._useShadowMapTextureOverride),
_textureSize(ss._textureSize), _textureSize(ss._textureSize),
_minimumShadowMapNearFarRatio(ss._minimumShadowMapNearFarRatio), _minimumShadowMapNearFarRatio(ss._minimumShadowMapNearFarRatio),
_maximumShadowMapDistance(ss._maximumShadowMapDistance),
_shadowMapProjectionHint(ss._shadowMapProjectionHint), _shadowMapProjectionHint(ss._shadowMapProjectionHint),
_perspectiveShadowMapCutOffAngle(ss._perspectiveShadowMapCutOffAngle), _perspectiveShadowMapCutOffAngle(ss._perspectiveShadowMapCutOffAngle),
_numShadowMapsPerLight(ss._numShadowMapsPerLight), _numShadowMapsPerLight(ss._numShadowMapsPerLight),

View File

@ -799,9 +799,12 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
cv.computeNearPlane(); cv.computeNearPlane();
} }
//minZNear = osg::maximum(10.0,minZNear); // clamp the minZNear and maxZFar to those provided by ShadowSettings
//maxZFar = osg::minimum(60.0,maxZFar); maxZFar = osg::minimum(settings->getMaximumShadowMapDistance(),maxZFar);
if (minZNear>maxZFar) minZNear = maxZFar*settings->getMinimumShadowMapNearFarRatio();
//OSG_NOTICE<<"maxZFar "<<maxZFar<<std::endl;
Frustum frustum(&cv, minZNear, maxZFar); Frustum frustum(&cv, minZNear, maxZFar);
// return compute near far mode back to it's original settings // return compute near far mode back to it's original settings