1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:53:50 +00:00

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) 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 // 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. // backface nor front face so they usually use CullMode off set here.
// In this case we will draw them in their entirety. // In this case we will draw them in their entirety.
_shadowCastingStateSet->setAttribute( new osg::CullFace( osg::CullFace::FRONT ), if (_useFrontFaceCulling)
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); _shadowCastingStateSet->setAttribute(new osg::CullFace(osg::CullFace::FRONT), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
// make sure GL_CULL_FACE is off by default // make sure GL_CULL_FACE is off by default
// we assume that if object has cull face attribute set to back // 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 setPolygonOffset(float factor, float units);
virtual void enableFrontFaceCulling();
virtual void disableFrontFaceCulling();
virtual void setupCastingShader(Shader::ShaderManager &shaderManager); virtual void setupCastingShader(Shader::ShaderManager &shaderManager);
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
@ -249,6 +253,8 @@ namespace SceneUtil {
float _polygonOffsetFactor = 1.1; float _polygonOffsetFactor = 1.1;
float _polygonOffsetUnits = 4.0; float _polygonOffsetUnits = 4.0;
bool _useFrontFaceCulling = true;
class DebugHUD : public osg::Referenced class DebugHUD : public osg::Referenced
{ {
public: 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")); 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")) if (Settings::Manager::getBool("allow shadow map overlap", "Shadows"))
mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::CASCADED); mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::CASCADED);
else else

View file

@ -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. 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. 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 split point uniform logarithmic ratio
------------------------------------- -------------------------------------

View file

@ -666,6 +666,8 @@ minimum lispsm near far ratio = 0.25
polygon offset factor = 1.1 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. # 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 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. # Allow actors to cast shadows. Potentially decreases performance.
actor shadows = false actor shadows = false
# Allow the player to cast shadows. Potentially decreases performance. # Allow the player to cast shadows. Potentially decreases performance.