From 7768556ce64c240bdcf361910e6520b2e32b224f Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 16 Nov 2020 21:01:20 +0000 Subject: [PATCH 1/2] 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 --- components/sceneutil/mwshadowtechnique.cpp | 26 +++++++++++++++++++++- components/sceneutil/mwshadowtechnique.hpp | 3 ++- components/sceneutil/shadow.cpp | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 0411dbc431..c49a147776 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -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 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); } diff --git a/components/sceneutil/mwshadowtechnique.hpp b/components/sceneutil/mwshadowtechnique.hpp index a7208cfa6d..5125247dda 100644 --- a/components/sceneutil/mwshadowtechnique.hpp +++ b/components/sceneutil/mwshadowtechnique.hpp @@ -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 _program; bool _enableShadows; + bool mSetDummyStateWhenDisabled; double _splitPointUniformLogRatio = 0.5; double _splitPointDeltaBias = 0.0; diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index 1e14fbbb13..35646b834e 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -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() From 06ae2a0536274b45fc04d0b1a1a3585fda25ac3a Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 16 Nov 2020 21:07:30 +0000 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f19783ef5..51babd907b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Bug #5644: Summon effects running on the player during game initialization cause crashes Bug #5656: Sneaking characters block hits while standing Bug #5661: Region sounds don't play at the right interval + Bug #5688: Water shader broken indoors with enable indoor shadows = false Feature #390: 3rd person look "over the shoulder" Feature #2386: Distant Statics in the form of Object Paging Feature #2404: Levelled List can not be placed into a container