1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00

Merge branch 'settings_values_shadows' into 'master'

Use settings values for Shadows settings (#6876)

See merge request OpenMW/openmw!3550
This commit is contained in:
AnyOldName3 2023-11-03 11:35:58 +00:00
commit 07594037ca
8 changed files with 92 additions and 114 deletions

View File

@ -158,32 +158,32 @@ bool Launcher::GraphicsPage::loadSettings()
lightingMethodComboBox->setCurrentIndex(lightingMethod); lightingMethodComboBox->setCurrentIndex(lightingMethod);
// Shadows // Shadows
if (Settings::Manager::getBool("actor shadows", "Shadows")) if (Settings::shadows().mActorShadows)
actorShadowsCheckBox->setCheckState(Qt::Checked); actorShadowsCheckBox->setCheckState(Qt::Checked);
if (Settings::Manager::getBool("player shadows", "Shadows")) if (Settings::shadows().mPlayerShadows)
playerShadowsCheckBox->setCheckState(Qt::Checked); playerShadowsCheckBox->setCheckState(Qt::Checked);
if (Settings::Manager::getBool("terrain shadows", "Shadows")) if (Settings::shadows().mTerrainShadows)
terrainShadowsCheckBox->setCheckState(Qt::Checked); terrainShadowsCheckBox->setCheckState(Qt::Checked);
if (Settings::Manager::getBool("object shadows", "Shadows")) if (Settings::shadows().mObjectShadows)
objectShadowsCheckBox->setCheckState(Qt::Checked); objectShadowsCheckBox->setCheckState(Qt::Checked);
if (Settings::Manager::getBool("enable indoor shadows", "Shadows")) if (Settings::shadows().mEnableIndoorShadows)
indoorShadowsCheckBox->setCheckState(Qt::Checked); indoorShadowsCheckBox->setCheckState(Qt::Checked);
shadowComputeSceneBoundsComboBox->setCurrentIndex(shadowComputeSceneBoundsComboBox->findText( shadowComputeSceneBoundsComboBox->setCurrentIndex(
QString(tr(Settings::Manager::getString("compute scene bounds", "Shadows").c_str())))); shadowComputeSceneBoundsComboBox->findText(QString(tr(Settings::shadows().mComputeSceneBounds.get().c_str()))));
int shadowDistLimit = Settings::Manager::getInt("maximum shadow map distance", "Shadows"); const int shadowDistLimit = Settings::shadows().mMaximumShadowMapDistance;
if (shadowDistLimit > 0) if (shadowDistLimit > 0)
{ {
shadowDistanceCheckBox->setCheckState(Qt::Checked); shadowDistanceCheckBox->setCheckState(Qt::Checked);
shadowDistanceSpinBox->setValue(shadowDistLimit); shadowDistanceSpinBox->setValue(shadowDistLimit);
} }
float shadowFadeStart = Settings::Manager::getFloat("shadow fade start", "Shadows"); const float shadowFadeStart = Settings::shadows().mShadowFadeStart;
if (shadowFadeStart != 0) if (shadowFadeStart != 0)
fadeStartSpinBox->setValue(shadowFadeStart); fadeStartSpinBox->setValue(shadowFadeStart);
int shadowRes = Settings::Manager::getInt("shadow map resolution", "Shadows"); const int shadowRes = Settings::shadows().mShadowMapResolution;
int shadowResIndex = shadowResolutionComboBox->findText(QString::number(shadowRes)); int shadowResIndex = shadowResolutionComboBox->findText(QString::number(shadowRes));
if (shadowResIndex != -1) if (shadowResIndex != -1)
shadowResolutionComboBox->setCurrentIndex(shadowResIndex); shadowResolutionComboBox->setCurrentIndex(shadowResIndex);
@ -240,55 +240,36 @@ void Launcher::GraphicsPage::saveSettings()
Settings::shaders().mLightingMethod.set(lightingMethodMap[lightingMethodComboBox->currentIndex()]); Settings::shaders().mLightingMethod.set(lightingMethodMap[lightingMethodComboBox->currentIndex()]);
// Shadows // Shadows
int cShadowDist = shadowDistanceCheckBox->checkState() != Qt::Unchecked ? shadowDistanceSpinBox->value() : 0; const int cShadowDist = shadowDistanceCheckBox->checkState() != Qt::Unchecked ? shadowDistanceSpinBox->value() : 0;
if (Settings::Manager::getInt("maximum shadow map distance", "Shadows") != cShadowDist) Settings::shadows().mMaximumShadowMapDistance.set(cShadowDist);
Settings::Manager::setInt("maximum shadow map distance", "Shadows", cShadowDist); const float cFadeStart = fadeStartSpinBox->value();
float cFadeStart = fadeStartSpinBox->value(); if (cShadowDist > 0)
if (cShadowDist > 0 && Settings::Manager::getFloat("shadow fade start", "Shadows") != cFadeStart) Settings::shadows().mShadowFadeStart.set(cFadeStart);
Settings::Manager::setFloat("shadow fade start", "Shadows", cFadeStart);
bool cActorShadows = actorShadowsCheckBox->checkState(); const bool cActorShadows = actorShadowsCheckBox->checkState() != Qt::Unchecked;
bool cObjectShadows = objectShadowsCheckBox->checkState(); const bool cObjectShadows = objectShadowsCheckBox->checkState() != Qt::Unchecked;
bool cTerrainShadows = terrainShadowsCheckBox->checkState(); const bool cTerrainShadows = terrainShadowsCheckBox->checkState() != Qt::Unchecked;
bool cPlayerShadows = playerShadowsCheckBox->checkState(); const bool cPlayerShadows = playerShadowsCheckBox->checkState() != Qt::Unchecked;
if (cActorShadows || cObjectShadows || cTerrainShadows || cPlayerShadows) if (cActorShadows || cObjectShadows || cTerrainShadows || cPlayerShadows)
{ {
if (!Settings::Manager::getBool("enable shadows", "Shadows")) Settings::shadows().mEnableShadows.set(true);
Settings::Manager::setBool("enable shadows", "Shadows", true); Settings::shadows().mActorShadows.set(cActorShadows);
if (Settings::Manager::getBool("actor shadows", "Shadows") != cActorShadows) Settings::shadows().mPlayerShadows.set(cPlayerShadows);
Settings::Manager::setBool("actor shadows", "Shadows", cActorShadows); Settings::shadows().mObjectShadows.set(cObjectShadows);
if (Settings::Manager::getBool("player shadows", "Shadows") != cPlayerShadows) Settings::shadows().mTerrainShadows.set(cTerrainShadows);
Settings::Manager::setBool("player shadows", "Shadows", cPlayerShadows);
if (Settings::Manager::getBool("object shadows", "Shadows") != cObjectShadows)
Settings::Manager::setBool("object shadows", "Shadows", cObjectShadows);
if (Settings::Manager::getBool("terrain shadows", "Shadows") != cTerrainShadows)
Settings::Manager::setBool("terrain shadows", "Shadows", cTerrainShadows);
} }
else else
{ {
if (Settings::Manager::getBool("enable shadows", "Shadows")) Settings::shadows().mEnableShadows.set(false);
Settings::Manager::setBool("enable shadows", "Shadows", false); Settings::shadows().mActorShadows.set(false);
if (Settings::Manager::getBool("actor shadows", "Shadows")) Settings::shadows().mPlayerShadows.set(false);
Settings::Manager::setBool("actor shadows", "Shadows", false); Settings::shadows().mObjectShadows.set(false);
if (Settings::Manager::getBool("player shadows", "Shadows")) Settings::shadows().mTerrainShadows.set(false);
Settings::Manager::setBool("player shadows", "Shadows", false);
if (Settings::Manager::getBool("object shadows", "Shadows"))
Settings::Manager::setBool("object shadows", "Shadows", false);
if (Settings::Manager::getBool("terrain shadows", "Shadows"))
Settings::Manager::setBool("terrain shadows", "Shadows", false);
} }
bool cIndoorShadows = indoorShadowsCheckBox->checkState(); Settings::shadows().mEnableIndoorShadows.set(indoorShadowsCheckBox->checkState() != Qt::Unchecked);
if (Settings::Manager::getBool("enable indoor shadows", "Shadows") != cIndoorShadows) Settings::shadows().mShadowMapResolution.set(shadowResolutionComboBox->currentText().toInt());
Settings::Manager::setBool("enable indoor shadows", "Shadows", cIndoorShadows); Settings::shadows().mComputeSceneBounds.set(shadowComputeSceneBoundsComboBox->currentText().toStdString());
int cShadowRes = shadowResolutionComboBox->currentText().toInt();
if (cShadowRes != Settings::Manager::getInt("shadow map resolution", "Shadows"))
Settings::Manager::setInt("shadow map resolution", "Shadows", cShadowRes);
auto cComputeSceneBounds = shadowComputeSceneBoundsComboBox->currentText().toStdString();
if (cComputeSceneBounds != Settings::Manager::getString("compute scene bounds", "Shadows"))
Settings::Manager::setString("compute scene bounds", "Shadows", cComputeSceneBounds);
} }
QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)

View File

@ -247,7 +247,7 @@ namespace MWRender
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f)); defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
stateset->setAttribute(defaultMat); stateset->setAttribute(defaultMat);
SceneUtil::ShadowManager::disableShadowsForStateSet(stateset); SceneUtil::ShadowManager::disableShadowsForStateSet(Settings::shadows(), *stateset);
// assign large value to effectively turn off fog // assign large value to effectively turn off fog
// shaders don't respect glDisable(GL_FOG) // shaders don't respect glDisable(GL_FOG)

View File

@ -763,7 +763,7 @@ namespace MWRender
lightSource->setStateSetModes(*stateset, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); lightSource->setStateSetModes(*stateset, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
SceneUtil::ShadowManager::disableShadowsForStateSet(stateset); SceneUtil::ShadowManager::disableShadowsForStateSet(Settings::shadows(), *stateset);
// override sun for local map // override sun for local map
SceneUtil::configureStateSetSunOverride(static_cast<SceneUtil::LightManager*>(mSceneRoot), light, stateset); SceneUtil::configureStateSetSunOverride(static_cast<SceneUtil::LightManager*>(mSceneRoot), light, stateset);

View File

@ -331,8 +331,8 @@ namespace MWRender
// Shadows and radial fog have problems with fixed-function mode. // Shadows and radial fog have problems with fixed-function mode.
bool forceShaders = Settings::fog().mRadialFog || Settings::fog().mExponentialFog bool forceShaders = Settings::fog().mRadialFog || Settings::fog().mExponentialFog
|| Settings::shaders().mSoftParticles || Settings::shaders().mForceShaders || Settings::shaders().mSoftParticles || Settings::shaders().mForceShaders
|| Settings::Manager::getBool("enable shadows", "Shadows") || Settings::shadows().mEnableShadows || lightingMethod != SceneUtil::LightingMethod::FFP || reverseZ
|| lightingMethod != SceneUtil::LightingMethod::FFP || reverseZ || mSkyBlending || Stereo::getMultiview(); || mSkyBlending || Stereo::getMultiview();
resourceSystem->getSceneManager()->setForceShaders(forceShaders); resourceSystem->getSceneManager()->setForceShaders(forceShaders);
// FIXME: calling dummy method because terrain needs to know whether lighting is clamped // FIXME: calling dummy method because terrain needs to know whether lighting is clamped
@ -367,22 +367,22 @@ namespace MWRender
sceneRoot->setName("Scene Root"); sceneRoot->setName("Scene Root");
int shadowCastingTraversalMask = Mask_Scene; int shadowCastingTraversalMask = Mask_Scene;
if (Settings::Manager::getBool("actor shadows", "Shadows")) if (Settings::shadows().mActorShadows)
shadowCastingTraversalMask |= Mask_Actor; shadowCastingTraversalMask |= Mask_Actor;
if (Settings::Manager::getBool("player shadows", "Shadows")) if (Settings::shadows().mPlayerShadows)
shadowCastingTraversalMask |= Mask_Player; shadowCastingTraversalMask |= Mask_Player;
int indoorShadowCastingTraversalMask = shadowCastingTraversalMask; int indoorShadowCastingTraversalMask = shadowCastingTraversalMask;
if (Settings::Manager::getBool("object shadows", "Shadows")) if (Settings::shadows().mObjectShadows)
shadowCastingTraversalMask |= (Mask_Object | Mask_Static); shadowCastingTraversalMask |= (Mask_Object | Mask_Static);
if (Settings::Manager::getBool("terrain shadows", "Shadows")) if (Settings::shadows().mTerrainShadows)
shadowCastingTraversalMask |= Mask_Terrain; shadowCastingTraversalMask |= Mask_Terrain;
mShadowManager = std::make_unique<SceneUtil::ShadowManager>(sceneRoot, mRootNode, shadowCastingTraversalMask, mShadowManager = std::make_unique<SceneUtil::ShadowManager>(sceneRoot, mRootNode, shadowCastingTraversalMask,
indoorShadowCastingTraversalMask, Mask_Terrain | Mask_Object | Mask_Static, indoorShadowCastingTraversalMask, Mask_Terrain | Mask_Object | Mask_Static, Settings::shadows(),
mResourceSystem->getSceneManager()->getShaderManager()); mResourceSystem->getSceneManager()->getShaderManager());
Shader::ShaderManager::DefineMap shadowDefines = mShadowManager->getShadowDefines(); Shader::ShaderManager::DefineMap shadowDefines = mShadowManager->getShadowDefines(Settings::shadows());
Shader::ShaderManager::DefineMap lightDefines = sceneRoot->getLightDefines(); Shader::ShaderManager::DefineMap lightDefines = sceneRoot->getLightDefines();
Shader::ShaderManager::DefineMap globalDefines Shader::ShaderManager::DefineMap globalDefines
= mResourceSystem->getSceneManager()->getShaderManager().getGlobalDefines(); = mResourceSystem->getSceneManager()->getShaderManager().getGlobalDefines();
@ -770,7 +770,7 @@ namespace MWRender
if (enabled) if (enabled)
mShadowManager->enableOutdoorMode(); mShadowManager->enableOutdoorMode();
else else
mShadowManager->enableIndoorMode(); mShadowManager->enableIndoorMode(Settings::shadows());
mPostProcessor->getStateUpdater()->setIsInterior(!enabled); mPostProcessor->getStateUpdater()->setIsInterior(!enabled);
} }

View File

@ -220,7 +220,7 @@ namespace
camera->setNodeMask(MWRender::Mask_RenderToTexture); camera->setNodeMask(MWRender::Mask_RenderToTexture);
camera->setCullMask(MWRender::Mask_Sky); camera->setCullMask(MWRender::Mask_Sky);
camera->addChild(mEarlyRenderBinRoot); camera->addChild(mEarlyRenderBinRoot);
SceneUtil::ShadowManager::disableShadowsForStateSet(camera->getOrCreateStateSet()); SceneUtil::ShadowManager::disableShadowsForStateSet(Settings::shadows(), *camera->getOrCreateStateSet());
} }
private: private:
@ -271,7 +271,7 @@ namespace MWRender
if (!mSceneManager->getForceShaders()) if (!mSceneManager->getForceShaders())
skyroot->getOrCreateStateSet()->setAttributeAndModes(new osg::Program(), skyroot->getOrCreateStateSet()->setAttributeAndModes(new osg::Program(),
osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON); osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
SceneUtil::ShadowManager::disableShadowsForStateSet(skyroot->getOrCreateStateSet()); SceneUtil::ShadowManager::disableShadowsForStateSet(Settings::shadows(), *skyroot->getOrCreateStateSet());
parentNode->addChild(skyroot); parentNode->addChild(skyroot);
mEarlyRenderBinRoot = new osg::Group; mEarlyRenderBinRoot = new osg::Group;

View File

@ -265,7 +265,8 @@ namespace MWRender
camera->setNodeMask(Mask_RenderToTexture); camera->setNodeMask(Mask_RenderToTexture);
if (Settings::water().mRefractionScale != 1) // TODO: to be removed with issue #5709 if (Settings::water().mRefractionScale != 1) // TODO: to be removed with issue #5709
SceneUtil::ShadowManager::disableShadowsForStateSet(camera->getOrCreateStateSet()); SceneUtil::ShadowManager::disableShadowsForStateSet(
Settings::shadows(), *camera->getOrCreateStateSet());
} }
void apply(osg::Camera* camera) override void apply(osg::Camera* camera) override
@ -341,7 +342,7 @@ namespace MWRender
camera->addChild(mClipCullNode); camera->addChild(mClipCullNode);
camera->setNodeMask(Mask_RenderToTexture); camera->setNodeMask(Mask_RenderToTexture);
SceneUtil::ShadowManager::disableShadowsForStateSet(camera->getOrCreateStateSet()); SceneUtil::ShadowManager::disableShadowsForStateSet(Settings::shadows(), *camera->getOrCreateStateSet());
} }
void apply(osg::Camera* camera) override void apply(osg::Camera* camera) override

View File

@ -4,7 +4,7 @@
#include <osgShadow/ShadowedScene> #include <osgShadow/ShadowedScene>
#include <components/misc/strings/algorithm.hpp> #include <components/misc/strings/algorithm.hpp>
#include <components/settings/settings.hpp> #include <components/settings/categories/shadows.hpp>
#include <components/stereo/stereomanager.hpp> #include <components/stereo/stereomanager.hpp>
#include "mwshadowtechnique.hpp" #include "mwshadowtechnique.hpp"
@ -13,9 +13,10 @@ namespace SceneUtil
{ {
using namespace osgShadow; using namespace osgShadow;
void ShadowManager::setupShadowSettings(Shader::ShaderManager& shaderManager) void ShadowManager::setupShadowSettings(
const Settings::ShadowsCategory& settings, Shader::ShaderManager& shaderManager)
{ {
mEnableShadows = Settings::Manager::getBool("enable shadows", "Shadows"); mEnableShadows = settings.mEnableShadows;
if (!mEnableShadows) if (!mEnableShadows)
{ {
@ -28,64 +29,58 @@ namespace SceneUtil
mShadowSettings->setLightNum(0); mShadowSettings->setLightNum(0);
mShadowSettings->setReceivesShadowTraversalMask(~0u); mShadowSettings->setReceivesShadowTraversalMask(~0u);
const int numberOfShadowMapsPerLight const int numberOfShadowMapsPerLight = settings.mNumberOfShadowMaps;
= std::clamp(Settings::Manager::getInt("number of shadow maps", "Shadows"), 1, 8);
mShadowSettings->setNumShadowMapsPerLight(numberOfShadowMapsPerLight); mShadowSettings->setNumShadowMapsPerLight(numberOfShadowMapsPerLight);
mShadowSettings->setBaseShadowTextureUnit(shaderManager.reserveGlobalTextureUnits( mShadowSettings->setBaseShadowTextureUnit(shaderManager.reserveGlobalTextureUnits(
Shader::ShaderManager::Slot::ShadowMaps, numberOfShadowMapsPerLight)); Shader::ShaderManager::Slot::ShadowMaps, numberOfShadowMapsPerLight));
const float maximumShadowMapDistance = Settings::Manager::getFloat("maximum shadow map distance", "Shadows"); const float maximumShadowMapDistance = settings.mMaximumShadowMapDistance;
if (maximumShadowMapDistance > 0) if (maximumShadowMapDistance > 0)
{ {
const float shadowFadeStart const float shadowFadeStart = settings.mShadowFadeStart;
= std::clamp(Settings::Manager::getFloat("shadow fade start", "Shadows"), 0.f, 1.f);
mShadowSettings->setMaximumShadowMapDistance(maximumShadowMapDistance); mShadowSettings->setMaximumShadowMapDistance(maximumShadowMapDistance);
mShadowTechnique->setShadowFadeStart(maximumShadowMapDistance * shadowFadeStart); mShadowTechnique->setShadowFadeStart(maximumShadowMapDistance * shadowFadeStart);
} }
mShadowSettings->setMinimumShadowMapNearFarRatio( mShadowSettings->setMinimumShadowMapNearFarRatio(settings.mMinimumLispsmNearFarRatio);
Settings::Manager::getFloat("minimum lispsm near far ratio", "Shadows"));
const std::string& computeSceneBounds = Settings::Manager::getString("compute scene bounds", "Shadows"); const std::string& computeSceneBounds = settings.mComputeSceneBounds;
if (Misc::StringUtils::ciEqual(computeSceneBounds, "primitives")) if (Misc::StringUtils::ciEqual(computeSceneBounds, "primitives"))
mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
else if (Misc::StringUtils::ciEqual(computeSceneBounds, "bounds")) else if (Misc::StringUtils::ciEqual(computeSceneBounds, "bounds"))
mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES); mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
int mapres = Settings::Manager::getInt("shadow map resolution", "Shadows"); const int mapres = settings.mShadowMapResolution;
mShadowSettings->setTextureSize(osg::Vec2s(mapres, mapres)); mShadowSettings->setTextureSize(osg::Vec2s(mapres, mapres));
mShadowTechnique->setSplitPointUniformLogarithmicRatio( mShadowTechnique->setSplitPointUniformLogarithmicRatio(settings.mSplitPointUniformLogarithmicRatio);
Settings::Manager::getFloat("split point uniform logarithmic ratio", "Shadows")); mShadowTechnique->setSplitPointDeltaBias(settings.mSplitPointBias);
mShadowTechnique->setSplitPointDeltaBias(Settings::Manager::getFloat("split point bias", "Shadows"));
mShadowTechnique->setPolygonOffset(Settings::Manager::getFloat("polygon offset factor", "Shadows"), mShadowTechnique->setPolygonOffset(settings.mPolygonOffsetFactor, settings.mPolygonOffsetUnits);
Settings::Manager::getFloat("polygon offset units", "Shadows"));
if (Settings::Manager::getBool("use front face culling", "Shadows")) if (settings.mUseFrontFaceCulling)
mShadowTechnique->enableFrontFaceCulling(); mShadowTechnique->enableFrontFaceCulling();
else else
mShadowTechnique->disableFrontFaceCulling(); mShadowTechnique->disableFrontFaceCulling();
if (Settings::Manager::getBool("allow shadow map overlap", "Shadows")) if (settings.mAllowShadowMapOverlap)
mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::CASCADED); mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::CASCADED);
else else
mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::PARALLEL_SPLIT); mShadowSettings->setMultipleShadowMapHint(osgShadow::ShadowSettings::PARALLEL_SPLIT);
if (Settings::Manager::getBool("enable debug hud", "Shadows")) if (settings.mEnableDebugHud)
mShadowTechnique->enableDebugHUD(); mShadowTechnique->enableDebugHUD();
else else
mShadowTechnique->disableDebugHUD(); mShadowTechnique->disableDebugHUD();
} }
void ShadowManager::disableShadowsForStateSet(osg::ref_ptr<osg::StateSet> stateset) void ShadowManager::disableShadowsForStateSet(const Settings::ShadowsCategory& settings, osg::StateSet& stateset)
{ {
if (!Settings::Manager::getBool("enable shadows", "Shadows")) if (!settings.mEnableShadows)
return; return;
const int numberOfShadowMapsPerLight const int numberOfShadowMapsPerLight = settings.mNumberOfShadowMaps;
= std::clamp(Settings::Manager::getInt("number of shadow maps", "Shadows"), 1, 8);
int baseShadowTextureUnit = 8 - numberOfShadowMapsPerLight; int baseShadowTextureUnit = 8 - numberOfShadowMapsPerLight;
@ -99,18 +94,18 @@ namespace SceneUtil
fakeShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS); fakeShadowMapTexture->setShadowCompareFunc(osg::Texture::ShadowCompareFunc::ALWAYS);
for (int i = baseShadowTextureUnit; i < baseShadowTextureUnit + numberOfShadowMapsPerLight; ++i) for (int i = baseShadowTextureUnit; i < baseShadowTextureUnit + numberOfShadowMapsPerLight; ++i)
{ {
stateset->setTextureAttributeAndModes(i, fakeShadowMapTexture, stateset.setTextureAttributeAndModes(i, fakeShadowMapTexture,
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED); osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
stateset->addUniform( stateset.addUniform(
new osg::Uniform(("shadowTexture" + std::to_string(i - baseShadowTextureUnit)).c_str(), i)); new osg::Uniform(("shadowTexture" + std::to_string(i - baseShadowTextureUnit)).c_str(), i));
stateset->addUniform( stateset.addUniform(
new osg::Uniform(("shadowTextureUnit" + std::to_string(i - baseShadowTextureUnit)).c_str(), i)); new osg::Uniform(("shadowTextureUnit" + std::to_string(i - baseShadowTextureUnit)).c_str(), i));
} }
} }
ShadowManager::ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode, ShadowManager::ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode,
unsigned int outdoorShadowCastingMask, unsigned int indoorShadowCastingMask, unsigned int worldMask, unsigned int outdoorShadowCastingMask, unsigned int indoorShadowCastingMask, unsigned int worldMask,
Shader::ShaderManager& shaderManager) const Settings::ShadowsCategory& settings, Shader::ShaderManager& shaderManager)
: mShadowedScene(new osgShadow::ShadowedScene) : mShadowedScene(new osgShadow::ShadowedScene)
, mShadowTechnique(new MWShadowTechnique) , mShadowTechnique(new MWShadowTechnique)
, mOutdoorShadowCastingMask(outdoorShadowCastingMask) , mOutdoorShadowCastingMask(outdoorShadowCastingMask)
@ -126,7 +121,7 @@ namespace SceneUtil
mShadowedScene->setNodeMask(sceneRoot->getNodeMask()); mShadowedScene->setNodeMask(sceneRoot->getNodeMask());
mShadowSettings = mShadowedScene->getShadowSettings(); mShadowSettings = mShadowedScene->getShadowSettings();
setupShadowSettings(shaderManager); setupShadowSettings(settings, shaderManager);
mShadowTechnique->setupCastingShader(shaderManager); mShadowTechnique->setupCastingShader(shaderManager);
mShadowTechnique->setWorldMask(worldMask); mShadowTechnique->setWorldMask(worldMask);
@ -140,7 +135,7 @@ namespace SceneUtil
Stereo::Manager::instance().setShadowTechnique(nullptr); Stereo::Manager::instance().setShadowTechnique(nullptr);
} }
Shader::ShaderManager::DefineMap ShadowManager::getShadowDefines() Shader::ShaderManager::DefineMap ShadowManager::getShadowDefines(const Settings::ShadowsCategory& settings)
{ {
if (!mEnableShadows) if (!mEnableShadows)
return getShadowsDisabledDefines(); return getShadowsDisabledDefines();
@ -155,24 +150,19 @@ namespace SceneUtil
definesWithShadows["shadow_texture_unit_list"] = definesWithShadows["shadow_texture_unit_list"].substr( definesWithShadows["shadow_texture_unit_list"] = definesWithShadows["shadow_texture_unit_list"].substr(
0, definesWithShadows["shadow_texture_unit_list"].length() - 1); 0, definesWithShadows["shadow_texture_unit_list"].length() - 1);
definesWithShadows["shadowMapsOverlap"] definesWithShadows["shadowMapsOverlap"] = settings.mAllowShadowMapOverlap ? "1" : "0";
= Settings::Manager::getBool("allow shadow map overlap", "Shadows") ? "1" : "0";
definesWithShadows["useShadowDebugOverlay"] definesWithShadows["useShadowDebugOverlay"] = settings.mEnableDebugOverlay ? "1" : "0";
= Settings::Manager::getBool("enable debug overlay", "Shadows") ? "1" : "0";
// switch this to reading settings if it's ever exposed to the user // switch this to reading settings if it's ever exposed to the user
definesWithShadows["perspectiveShadowMaps"] definesWithShadows["perspectiveShadowMaps"]
= mShadowSettings->getShadowMapProjectionHint() == ShadowSettings::PERSPECTIVE_SHADOW_MAP ? "1" : "0"; = mShadowSettings->getShadowMapProjectionHint() == ShadowSettings::PERSPECTIVE_SHADOW_MAP ? "1" : "0";
definesWithShadows["disableNormalOffsetShadows"] definesWithShadows["disableNormalOffsetShadows"] = settings.mNormalOffsetDistance == 0.0 ? "1" : "0";
= Settings::Manager::getFloat("normal offset distance", "Shadows") == 0.0 ? "1" : "0";
definesWithShadows["shadowNormalOffset"] definesWithShadows["shadowNormalOffset"] = std::to_string(settings.mNormalOffsetDistance);
= std::to_string(Settings::Manager::getFloat("normal offset distance", "Shadows"));
definesWithShadows["limitShadowMapDistance"] definesWithShadows["limitShadowMapDistance"] = settings.mMaximumShadowMapDistance > 0 ? "1" : "0";
= Settings::Manager::getFloat("maximum shadow map distance", "Shadows") > 0 ? "1" : "0";
return definesWithShadows; return definesWithShadows;
} }
@ -200,9 +190,9 @@ namespace SceneUtil
return definesWithoutShadows; return definesWithoutShadows;
} }
void ShadowManager::enableIndoorMode() void ShadowManager::enableIndoorMode(const Settings::ShadowsCategory& settings)
{ {
if (Settings::Manager::getBool("enable indoor shadows", "Shadows")) if (settings.mEnableIndoorShadows)
mShadowSettings->setCastsShadowTraversalMask(mIndoorShadowCastingMask); mShadowSettings->setCastsShadowTraversalMask(mIndoorShadowCastingMask);
else else
mShadowTechnique->disableShadows(true); mShadowTechnique->disableShadows(true);

View File

@ -8,32 +8,38 @@ namespace osg
class StateSet; class StateSet;
class Group; class Group;
} }
namespace osgShadow namespace osgShadow
{ {
class ShadowSettings; class ShadowSettings;
class ShadowedScene; class ShadowedScene;
} }
namespace Settings
{
struct ShadowsCategory;
}
namespace SceneUtil namespace SceneUtil
{ {
class MWShadowTechnique; class MWShadowTechnique;
class ShadowManager class ShadowManager
{ {
public: public:
static void disableShadowsForStateSet(osg::ref_ptr<osg::StateSet> stateSet); static void disableShadowsForStateSet(const Settings::ShadowsCategory& settings, osg::StateSet& stateset);
static Shader::ShaderManager::DefineMap getShadowsDisabledDefines(); static Shader::ShaderManager::DefineMap getShadowsDisabledDefines();
ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode, explicit ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode,
unsigned int outdoorShadowCastingMask, unsigned int indoorShadowCastingMask, unsigned int worldMask, unsigned int outdoorShadowCastingMask, unsigned int indoorShadowCastingMask, unsigned int worldMask,
Shader::ShaderManager& shaderManager); const Settings::ShadowsCategory& settings, Shader::ShaderManager& shaderManager);
~ShadowManager(); ~ShadowManager();
void setupShadowSettings(Shader::ShaderManager& shaderManager); void setupShadowSettings(const Settings::ShadowsCategory& settings, Shader::ShaderManager& shaderManager);
Shader::ShaderManager::DefineMap getShadowDefines(); Shader::ShaderManager::DefineMap getShadowDefines(const Settings::ShadowsCategory& settings);
void enableIndoorMode(); void enableIndoorMode(const Settings::ShadowsCategory& settings);
void enableOutdoorMode(); void enableOutdoorMode();