1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-20 18:39:39 +00:00

Set dummy state when disabling shadows indoors

As we don't reconfigure all shaders without shadows when we disable them
indoors (as it'd probably add a hitch to transitioning in and out) we
need to set up dummy state so the shaders don't do anything illegal.

This hadn't had symptoms for most objects as when indoors, nearly
everything would be drawn first in one of the water RTTs, which had
dummy state to disable shadows already. This wasn't true of the water
plane itself, though, yet somehow it took until just now for anyone to
report that.

This resolves vtastek's issue where the water would be invisible indoors
This commit is contained in:
AnyOldName3 2020-11-16 21:01:20 +00:00
parent 894bcb8bcc
commit 7768556ce6
3 changed files with 28 additions and 3 deletions

View file

@ -820,9 +820,10 @@ void MWShadowTechnique::enableShadows()
_enableShadows = true;
}
void MWShadowTechnique::disableShadows()
void MWShadowTechnique::disableShadows(bool setDummyState)
{
_enableShadows = false;
mSetDummyStateWhenDisabled = setDummyState;
}
void SceneUtil::MWShadowTechnique::enableDebugHUD()
@ -914,7 +915,28 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv)
{
if (!_enableShadows)
{
if (mSetDummyStateWhenDisabled)
{
osg::ref_ptr<osg::StateSet> dummyState = new osg::StateSet();
ShadowSettings* settings = getShadowedScene()->getShadowSettings();
int baseUnit = settings->getBaseShadowTextureUnit();
int endUnit = baseUnit + settings->getNumShadowMapsPerLight();
for (int i = baseUnit; i < endUnit; ++i)
{
dummyState->setTextureAttributeAndModes(i, _fallbackShadowMapTexture, osg::StateAttribute::ON);
dummyState->addUniform(new osg::Uniform(("shadowTexture" + std::to_string(i - baseUnit)).c_str(), i));
dummyState->addUniform(new osg::Uniform(("shadowTextureUnit" + std::to_string(i - baseUnit)).c_str(), i));
}
cv.pushStateSet(dummyState);
}
_shadowedScene->osg::Group::traverse(cv);
if (mSetDummyStateWhenDisabled)
cv.popStateSet();
return;
}
@ -1577,6 +1599,8 @@ void MWShadowTechnique::createShaders()
_fallbackShadowMapTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
_fallbackShadowMapTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
_fallbackShadowMapTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
_fallbackShadowMapTexture->setShadowComparison(true);
_fallbackShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS);
}

View file

@ -67,7 +67,7 @@ namespace SceneUtil {
virtual void enableShadows();
virtual void disableShadows();
virtual void disableShadows(bool setDummyState = false);
virtual void enableDebugHUD();
@ -252,6 +252,7 @@ namespace SceneUtil {
osg::ref_ptr<osg::Program> _program;
bool _enableShadows;
bool mSetDummyStateWhenDisabled;
double _splitPointUniformLogRatio = 0.5;
double _splitPointDeltaBias = 0.0;

View file

@ -168,7 +168,7 @@ namespace SceneUtil
if (Settings::Manager::getBool("enable indoor shadows", "Shadows"))
mShadowSettings->setCastsShadowTraversalMask(mIndoorShadowCastingMask);
else
mShadowTechnique->disableShadows();
mShadowTechnique->disableShadows(true);
}
void ShadowManager::enableOutdoorMode()