Make the shadow polygon offset parameters configurable

pull/541/head
AnyOldName3 6 years ago
parent 49487355a5
commit dd207d9e54

@ -807,9 +807,6 @@ void MWShadowTechnique::disableShadows()
void SceneUtil::MWShadowTechnique::enableDebugHUD()
{
_debugHud = new DebugHUD(getShadowedScene()->getShadowSettings()->getNumShadowMapsPerLight());
}
void SceneUtil::MWShadowTechnique::disableDebugHUD()
@ -827,6 +824,18 @@ void SceneUtil::MWShadowTechnique::setSplitPointDeltaBias(double bias)
_splitPointDeltaBias = bias;
}
void SceneUtil::MWShadowTechnique::setPolygonOffset(float factor, float units)
{
_polygonOffsetFactor = factor;
_polygonOffsetUnits = units;
if (_polygonOffset)
{
_polygonOffset->setFactor(factor);
_polygonOffset->setUnits(units);
}
}
void SceneUtil::MWShadowTechnique::setupCastingShader(Shader::ShaderManager & shaderManager)
{
// This can't be part of the constructor as OSG mandates that there be a trivial constructor available
@ -1422,14 +1431,7 @@ void MWShadowTechnique::createShaders()
_shadowCastingStateSet->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
}
#if 1
float factor = 1.1;
float units = 4.0;
#else
float factor = -1.1;
float units = -4.0;
#endif
_polygonOffset = new osg::PolygonOffset(factor, units);
_polygonOffset = new osg::PolygonOffset(_polygonOffsetFactor, _polygonOffsetUnits);
_shadowCastingStateSet->setAttribute(_polygonOffset.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
_shadowCastingStateSet->setMode(GL_POLYGON_OFFSET_FILL, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

@ -74,6 +74,8 @@ namespace SceneUtil {
virtual void setSplitPointDeltaBias(double bias);
virtual void setPolygonOffset(float factor, float units);
virtual void setupCastingShader(Shader::ShaderManager &shaderManager);
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
@ -244,6 +246,9 @@ namespace SceneUtil {
double _splitPointUniformLogRatio = 0.5;
double _splitPointDeltaBias = 0.0;
float _polygonOffsetFactor = 1.1;
float _polygonOffsetUnits = 4.0;
class DebugHUD : public osg::Referenced
{
public:

@ -42,6 +42,8 @@ namespace SceneUtil
mShadowTechnique->setSplitPointUniformLogarithmicRatio(Settings::Manager::getFloat("split point uniform logarithmic ratio", "Shadows"));
mShadowTechnique->setSplitPointDeltaBias(Settings::Manager::getFloat("split point bias", "Shadows"));
mShadowTechnique->setPolygonOffset(Settings::Manager::getFloat("polygon offset factor", "Shadows"), Settings::Manager::getFloat("polygon offset units", "Shadows"));
if (Settings::Manager::getBool("allow shadow map overlap", "Shadows"))
mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::CASCADED);
else

@ -135,10 +135,34 @@ Some might feel this is distracting as shadows can be cast through other objects
Expert settings
***************
You probably shouldn't be changing these yourself if you haven't read `this paper on Parallel Split Shadow Maps <https://pdfs.semanticscholar.org/15a9/f2a7cf6b1494f45799617c017bd42659d753.pdf>`_ and understood how they interact with the transformation used with Light Space Perspective Shadow Maps.
If you have, then you may get better results tuning these for your specific view distance.
These settings are probably too complicated for regular users to judge what might be good values to set them to.
If you've got a good understanding of how shadow mapping works, or you've got enough time to try a large set of values, you may get better results tuning these yourself.
Copying values from another user who's done careful tuning is the recommended way of arriving at an optimal value for these settings.
Understanding what some of these do might be easier for people who've read `this paper on Parallel Split Shadow Maps <https://pdfs.semanticscholar.org/15a9/f2a7cf6b1494f45799617c017bd42659d753.pdf>`_ and understood how they interact with the transformation used with Light Space Perspective Shadow Maps.
polygon offset factor
---------------------
:Type: float
:Range: Theoretically the whole range of 32-bit floating point, but values just above 1.0 are most sensible.
:Default: 1.1
Used as the factor parameter for the polygon offset used for shadow map rendering.
Higher values reduce shadow flicker, but risk increasing Peter Panning.
See `the OpenGL documentation for glPolygonOffset <https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml>`_ for details.
polygon offset units
---------------------
:Type: float
:Range: Theoretically the whole range of 32-bit floating point, but values between 1 and 10 are most sensible.
:Default: 4.0
Used as the units parameter for the polygon offset used for shadow map rendering.
Higher values reduce shadow flicker, but risk increasing Peter Panning.
See `the OpenGL documentation for glPolygonOffset <https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml>`_ for details.
split point uniform logarithmic ratio
-------------------------------------

@ -662,6 +662,10 @@ compute tight scene bounds = false
shadow map resolution = 1024
# Controls the minimum near/far ratio for the Light Space Perspective Shadow Map transformation. Helps prevent too much detail being brought towards the camera at the expense of detail further from the camera. Increasing this pushes detail further away.
minimum lispsm near far ratio = 0.25
# Used as the factor parameter for the polygon offset used for shadow map rendering. Higher values reduce shadow flicker, but risk increasing Peter Panning. See https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml for details.
polygon offset factor = 1.1
# Used as the units parameter for the polygon offset used for shadow map rendering. Higher values reduce shadow flicker, but risk increasing Peter Panning. See https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml for details.
polygon offset units = 4.0
# Allow actors to cast shadows. Potentially decreases performance.
actor shadows = false
# Allow the player to cast shadows. Potentially decreases performance.

Loading…
Cancel
Save