mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-08 03:28:15 +03:00
Make shadow map front-face culling configurable
This commit is contained in:
parent
dd207d9e54
commit
0a409c0ab8
5 changed files with 41 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue