From b52357409011ce7b19bf9df8b554975a7fcf9e7c Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Mon, 9 Nov 2020 13:53:58 +0300 Subject: [PATCH] Remove shader visitor settings manager dependency --- apps/openmw/mwrender/renderingmanager.cpp | 1 + components/resource/scenemanager.cpp | 7 +++++++ components/resource/scenemanager.hpp | 3 +++ components/shader/shadervisitor.cpp | 13 ++++++++----- components/shader/shadervisitor.hpp | 4 ++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 0aef614c8..8e5a01eaf 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -216,6 +216,7 @@ namespace MWRender resourceSystem->getSceneManager()->setNormalHeightMapPattern(Settings::Manager::getString("normal height map pattern", "Shaders")); resourceSystem->getSceneManager()->setAutoUseSpecularMaps(Settings::Manager::getBool("auto use object specular maps", "Shaders")); resourceSystem->getSceneManager()->setSpecularMapPattern(Settings::Manager::getString("specular map pattern", "Shaders")); + resourceSystem->getSceneManager()->setApplyLightingToEnvMaps(Settings::Manager::getBool("apply lighting to environment maps", "Shaders")); osg::ref_ptr sceneRoot = new SceneUtil::LightManager; sceneRoot->setLightingMask(Mask_Lighting); diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 571ea6d0d..44ba7e687 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -220,6 +220,7 @@ namespace Resource , mClampLighting(true) , mAutoUseNormalMaps(false) , mAutoUseSpecularMaps(false) + , mApplyLightingToEnvMaps(false) , mInstanceCache(new MultiObjectCache) , mSharedStateManager(new SharedStateManager) , mImageManager(imageManager) @@ -284,6 +285,11 @@ namespace Resource mSpecularMapPattern = pattern; } + void SceneManager::setApplyLightingToEnvMaps(bool apply) + { + mApplyLightingToEnvMaps = apply; + } + SceneManager::~SceneManager() { // this has to be defined in the .cpp file as we can't delete incomplete types @@ -770,6 +776,7 @@ namespace Resource shaderVisitor->setNormalHeightMapPattern(mNormalHeightMapPattern); shaderVisitor->setAutoUseSpecularMaps(mAutoUseSpecularMaps); shaderVisitor->setSpecularMapPattern(mSpecularMapPattern); + shaderVisitor->setApplyLightingToEnvMaps(mApplyLightingToEnvMaps); return shaderVisitor; } diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 0ee32a9b7..8df556158 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -73,6 +73,8 @@ namespace Resource void setSpecularMapPattern(const std::string& pattern); + void setApplyLightingToEnvMaps(bool apply); + void setShaderPath(const std::string& path); /// Check if a given scene is loaded and if so, update its usage timestamp to prevent it from being unloaded @@ -156,6 +158,7 @@ namespace Resource std::string mNormalHeightMapPattern; bool mAutoUseSpecularMaps; std::string mSpecularMapPattern; + bool mApplyLightingToEnvMaps; osg::ref_ptr mInstanceCache; diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index 0eab2fd89..e11f09930 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include "shadermanager.hpp" @@ -43,6 +42,7 @@ namespace Shader , mAllowedToModifyStateSets(true) , mAutoUseNormalMaps(false) , mAutoUseSpecularMaps(false) + , mApplyLightingToEnvMaps(false) , mShaderManager(shaderManager) , mImageManager(imageManager) , mDefaultVsTemplate(defaultVsTemplate) @@ -144,11 +144,9 @@ namespace Shader // Bump maps are off by default as well writableStateSet->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::ON); } - else if (texName == "envMap") + else if (texName == "envMap" && mApplyLightingToEnvMaps) { - static const bool preLightEnv = Settings::Manager::getBool("apply lighting to environment maps", "Shaders"); - if (preLightEnv) - mRequirements.back().mShaderRequired = true; + mRequirements.back().mShaderRequired = true; } } else @@ -477,4 +475,9 @@ namespace Shader mSpecularMapPattern = pattern; } + void ShaderVisitor::setApplyLightingToEnvMaps(bool apply) + { + mApplyLightingToEnvMaps = apply; + } + } diff --git a/components/shader/shadervisitor.hpp b/components/shader/shadervisitor.hpp index bf1022180..3089845a3 100644 --- a/components/shader/shadervisitor.hpp +++ b/components/shader/shadervisitor.hpp @@ -38,6 +38,8 @@ namespace Shader void setSpecularMapPattern(const std::string& pattern); + void setApplyLightingToEnvMaps(bool apply); + void apply(osg::Node& node) override; void apply(osg::Drawable& drawable) override; @@ -59,6 +61,8 @@ namespace Shader bool mAutoUseSpecularMaps; std::string mSpecularMapPattern; + bool mApplyLightingToEnvMaps; + ShaderManager& mShaderManager; Resource::ImageManager& mImageManager;