Make shadow map front-face culling configurable

This commit is contained in:
AnyOldName3 2018-12-01 00:26:43 +00:00
parent dd207d9e54
commit 0a409c0ab8
5 changed files with 41 additions and 2 deletions

View file

@ -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

View file

@ -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:

View file

@ -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