Skip to content

Commit

Permalink
Added ShadowSettings::s/getMaximumShadowMapDistance(double) property,…
Browse files Browse the repository at this point in the history
… usage of these property in ViewDependentShadowMap,

and setting of it with --max-shadow-distance <double> in the osgshadow example.
  • Loading branch information
robertosfield committed Aug 15, 2012
1 parent 7cee00d commit c078223
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/osgshadow/osgshadow.cpp
Expand Up @@ -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-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("--max-shadow-distance","<float> Maximum distance that the shadow map should extend from the eye point.");

// construct the viewer.
osgViewer::Viewer viewer(arguments);
Expand Down Expand Up @@ -859,6 +860,14 @@ int main(int argc, char** argv)
}
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;
if (arguments.read("--no-shadows"))
Expand Down
5 changes: 5 additions & 0 deletions include/osgShadow/ShadowSettings
Expand Up @@ -65,6 +65,10 @@ class OSGSHADOW_EXPORT ShadowSettings : public osg::Object
void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; }
double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; }

void setMaximumShadowMapDistance(double distance) { _maximumShadowMapDistance = distance; }
double getMaximumShadowMapDistance() const { return _maximumShadowMapDistance; }


enum ShadowMapProjectionHint
{
ORTHOGRAPHIC_SHADOW_MAP,
Expand Down Expand Up @@ -126,6 +130,7 @@ class OSGSHADOW_EXPORT ShadowSettings : public osg::Object
osg::Vec2s _textureSize;

double _minimumShadowMapNearFarRatio;
double _maximumShadowMapDistance;
ShadowMapProjectionHint _shadowMapProjectionHint;
double _perspectiveShadowMapCutOffAngle;

Expand Down
3 changes: 3 additions & 0 deletions src/osgShadow/ShadowSettings.cpp
Expand Up @@ -12,6 +12,7 @@
*/

#include <osgShadow/ShadowSettings>
#include <float.h>

using namespace osgShadow;

Expand All @@ -24,6 +25,7 @@ ShadowSettings::ShadowSettings():
_useShadowMapTextureOverride(true),
_textureSize(2048,2048),
_minimumShadowMapNearFarRatio(0.05),
_maximumShadowMapDistance(DBL_MAX),
_shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP),
_perspectiveShadowMapCutOffAngle(2.0),
_numShadowMapsPerLight(1),
Expand All @@ -46,6 +48,7 @@ ShadowSettings::ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copy
_useShadowMapTextureOverride(ss._useShadowMapTextureOverride),
_textureSize(ss._textureSize),
_minimumShadowMapNearFarRatio(ss._minimumShadowMapNearFarRatio),
_maximumShadowMapDistance(ss._maximumShadowMapDistance),
_shadowMapProjectionHint(ss._shadowMapProjectionHint),
_perspectiveShadowMapCutOffAngle(ss._perspectiveShadowMapCutOffAngle),
_numShadowMapsPerLight(ss._numShadowMapsPerLight),
Expand Down
7 changes: 5 additions & 2 deletions src/osgShadow/ViewDependentShadowMap.cpp
Expand Up @@ -799,9 +799,12 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv)
cv.computeNearPlane();
}

//minZNear = osg::maximum(10.0,minZNear);
//maxZFar = osg::minimum(60.0,maxZFar);
// clamp the minZNear and maxZFar to those provided by ShadowSettings
maxZFar = osg::minimum(settings->getMaximumShadowMapDistance(),maxZFar);
if (minZNear>maxZFar) minZNear = maxZFar*settings->getMinimumShadowMapNearFarRatio();

//OSG_NOTICE<<"maxZFar "<<maxZFar<<std::endl;

Frustum frustum(&cv, minZNear, maxZFar);

// return compute near far mode back to it's original settings
Expand Down

0 comments on commit c078223

Please sign in to comment.