Make shadow map front-face culling configurable

pull/541/head
AnyOldName3 6 years ago
parent dd207d9e54
commit 0a409c0ab8

@ -836,6 +836,22 @@ void SceneUtil::MWShadowTechnique::setPolygonOffset(float factor, float units)
}
}
void SceneUtil::MWShadowTechnique::enableFrontFaceCulling()
{
_useFrontFaceCulling = true;
if (_shadowCastingStateSet)
_shadowCastingStateSet->setAttribute(new osg::CullFace(osg::CullFace::FRONT), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
}
void SceneUtil::MWShadowTechnique::disableFrontFaceCulling()
{
_useFrontFaceCulling = false;
if (_shadowCastingStateSet)
_shadowCastingStateSet->removeAttribute(osg::StateAttribute::CULLFACE);
}
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,8 +1438,8 @@ void MWShadowTechnique::createShaders()
// backface nor front face so they usually use CullMode off set here.
// In this case we will draw them in their entirety.
_shadowCastingStateSet->setAttribute( new osg::CullFace( osg::CullFace::FRONT ),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
if (_useFrontFaceCulling)
_shadowCastingStateSet->setAttribute(new osg::CullFace(osg::CullFace::FRONT), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
// make sure GL_CULL_FACE is off by default
// we assume that if object has cull face attribute set to back

@ -76,6 +76,10 @@ namespace SceneUtil {
virtual void setPolygonOffset(float factor, float units);
virtual void enableFrontFaceCulling();
virtual void disableFrontFaceCulling();
virtual void setupCastingShader(Shader::ShaderManager &shaderManager);
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
@ -249,6 +253,8 @@ namespace SceneUtil {
float _polygonOffsetFactor = 1.1;
float _polygonOffsetUnits = 4.0;
bool _useFrontFaceCulling = true;
class DebugHUD : public osg::Referenced
{
public:

@ -44,6 +44,11 @@ namespace SceneUtil
mShadowTechnique->setPolygonOffset(Settings::Manager::getFloat("polygon offset factor", "Shadows"), Settings::Manager::getFloat("polygon offset units", "Shadows"));
if (Settings::Manager::getBool("use front face culling", "Shadows"))
mShadowTechnique->enableFrontFaceCulling();
else
mShadowTechnique->disableFrontFaceCulling();
if (Settings::Manager::getBool("allow shadow map overlap", "Shadows"))
mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::CASCADED);
else

@ -163,6 +163,16 @@ 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.
use front face culling
----------------------
:Type: boolean
:Range: True/False
:Default: True
Excludes theoretically unnecessary faces from shadow maps, slightly increasing performance.
In practice, Peter Panning can be much less visible with these faces included, so if you have high polygon offset values, disabling this may help minimise the side effects.
split point uniform logarithmic ratio
-------------------------------------

@ -666,6 +666,8 @@ minimum lispsm near far ratio = 0.25
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
# Excludes theoretically unnecessary faces from shadow maps, slightly increasing performance. In practice, Peter Panning can be much less visible with these faces included, so if you have high polygon offset values, disabling this may help minimise the side effects.
use front face culling = true
# Allow actors to cast shadows. Potentially decreases performance.
actor shadows = false
# Allow the player to cast shadows. Potentially decreases performance.

Loading…
Cancel
Save