From 0cdc46dfd6b17257859260211eed66ac22dc6389 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH] Move forcePPL and clamp to global shader defines (bug #4869) --- apps/openmw/mwrender/renderingmanager.cpp | 5 ++++- components/resource/scenemanager.cpp | 13 ------------- components/resource/scenemanager.hpp | 6 ------ components/shader/shadervisitor.cpp | 15 --------------- components/shader/shadervisitor.hpp | 9 --------- components/terrain/chunkmanager.cpp | 6 ++---- components/terrain/material.cpp | 6 ++---- components/terrain/material.hpp | 2 +- 8 files changed, 9 insertions(+), 53 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 038438f32..f54e423f1 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -220,8 +220,8 @@ namespace MWRender resourceSystem->getSceneManager()->setParticleSystemMask(MWRender::Mask_ParticleSystem); resourceSystem->getSceneManager()->setShaderPath(resourcePath + "/shaders"); resourceSystem->getSceneManager()->setForceShaders(Settings::Manager::getBool("force shaders", "Shaders") || Settings::Manager::getBool("enable shadows", "Shadows")); // Shadows have problems with fixed-function mode + // FIXME: calling dummy method because terrain needs to know whether lighting is clamped resourceSystem->getSceneManager()->setClampLighting(Settings::Manager::getBool("clamp lighting", "Shaders")); - resourceSystem->getSceneManager()->setForcePerPixelLighting(Settings::Manager::getBool("force per pixel lighting", "Shaders")); resourceSystem->getSceneManager()->setAutoUseNormalMaps(Settings::Manager::getBool("auto use object normal maps", "Shaders")); resourceSystem->getSceneManager()->setNormalMapPattern(Settings::Manager::getString("normal map pattern", "Shaders")); resourceSystem->getSceneManager()->setNormalHeightMapPattern(Settings::Manager::getString("normal height map pattern", "Shaders")); @@ -253,6 +253,9 @@ namespace MWRender for (auto itr = shadowDefines.begin(); itr != shadowDefines.end(); itr++) globalDefines[itr->first] = itr->second; + globalDefines["forcePPL"] = Settings::Manager::getBool("force per pixel lighting", "Shaders") ? "1" : "0"; + globalDefines["clamp"] = Settings::Manager::getBool("clamp lighting", "Shaders") ? "1" : "0"; + // It is unnecessary to stop/start the viewer as no frames are being rendered yet. mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines); diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index d360e92b1..d371a8ce4 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -218,7 +218,6 @@ namespace Resource , mShaderManager(new Shader::ShaderManager) , mForceShaders(false) , mClampLighting(true) - , mForcePerPixelLighting(false) , mAutoUseNormalMaps(false) , mAutoUseSpecularMaps(false) , mInstanceCache(new MultiObjectCache) @@ -260,16 +259,6 @@ namespace Resource return mClampLighting; } - void SceneManager::setForcePerPixelLighting(bool force) - { - mForcePerPixelLighting = force; - } - - bool SceneManager::getForcePerPixelLighting() const - { - return mForcePerPixelLighting; - } - void SceneManager::setAutoUseNormalMaps(bool use) { mAutoUseNormalMaps = use; @@ -749,8 +738,6 @@ namespace Resource { Shader::ShaderVisitor* shaderVisitor = new Shader::ShaderVisitor(*mShaderManager.get(), *mImageManager, "objects_vertex.glsl", "objects_fragment.glsl"); shaderVisitor->setForceShaders(mForceShaders); - shaderVisitor->setClampLighting(mClampLighting); - shaderVisitor->setForcePerPixelLighting(mForcePerPixelLighting); shaderVisitor->setAutoUseNormalMaps(mAutoUseNormalMaps); shaderVisitor->setNormalMapPattern(mNormalMapPattern); shaderVisitor->setNormalHeightMapPattern(mNormalHeightMapPattern); diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 4f1523ece..1c1c60a58 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -56,14 +56,9 @@ namespace Resource void setForceShaders(bool force); bool getForceShaders() const; - /// @see ShaderVisitor::setClampLighting void setClampLighting(bool clamp); bool getClampLighting() const; - /// @see ShaderVisitor::setForcePerPixelLighting - void setForcePerPixelLighting(bool force); - bool getForcePerPixelLighting() const; - /// @see ShaderVisitor::setAutoUseNormalMaps void setAutoUseNormalMaps(bool use); @@ -155,7 +150,6 @@ namespace Resource std::unique_ptr mShaderManager; bool mForceShaders; bool mClampLighting; - bool mForcePerPixelLighting; bool mAutoUseNormalMaps; std::string mNormalMapPattern; std::string mNormalHeightMapPattern; diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index 911a8cbbf..63c676118 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -37,8 +37,6 @@ namespace Shader ShaderVisitor::ShaderVisitor(ShaderManager& shaderManager, Resource::ImageManager& imageManager, const std::string &defaultVsTemplate, const std::string &defaultFsTemplate) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) , mForceShaders(false) - , mClampLighting(true) - , mForcePerPixelLighting(false) , mAllowedToModifyStateSets(true) , mAutoUseNormalMaps(false) , mAutoUseSpecularMaps(false) @@ -55,16 +53,6 @@ namespace Shader mForceShaders = force; } - void ShaderVisitor::setClampLighting(bool clamp) - { - mClampLighting = clamp; - } - - void ShaderVisitor::setForcePerPixelLighting(bool force) - { - mForcePerPixelLighting = force; - } - void ShaderVisitor::apply(osg::Node& node) { if (node.getStateSet()) @@ -297,9 +285,6 @@ namespace Shader defineMap[texIt->second + std::string("UV")] = std::to_string(texIt->first); } - defineMap["forcePPL"] = mForcePerPixelLighting ? "1" : "0"; - defineMap["clamp"] = mClampLighting ? "1" : "0"; - defineMap["parallax"] = reqs.mNormalHeight ? "1" : "0"; writableStateSet->addUniform(new osg::Uniform("colorMode", reqs.mColorMode)); diff --git a/components/shader/shadervisitor.hpp b/components/shader/shadervisitor.hpp index 8737baf59..ac0ecc699 100644 --- a/components/shader/shadervisitor.hpp +++ b/components/shader/shadervisitor.hpp @@ -23,13 +23,6 @@ namespace Shader /// Setting force = true will cause all objects to render using shaders, regardless of having a bump map. void setForceShaders(bool force); - /// Set whether lighting is clamped for visual compatibility with the fixed function pipeline. - void setClampLighting(bool clamp); - - /// By default, only bump mapped objects use per-pixel lighting. - /// Setting force = true will cause all shaders to use per-pixel lighting, regardless of having a bump map. - void setForcePerPixelLighting(bool force); - /// Set if we are allowed to modify StateSets encountered in the graph (default true). /// @par If set to false, then instead of modifying, the StateSet will be cloned and this new StateSet will be assigned to the node. /// @par This option is useful when the ShaderVisitor is run on a "live" subgraph that may have already been submitted for rendering. @@ -57,8 +50,6 @@ namespace Shader private: bool mForceShaders; - bool mClampLighting; - bool mForcePerPixelLighting; bool mAllowedToModifyStateSets; bool mAutoUseNormalMaps; diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 27d87b031..80f414541 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -161,8 +161,7 @@ std::vector > ChunkManager::createPasses(float chunk float blendmapScale = mStorage->getBlendmapScale(chunkSize); - return ::Terrain::createPasses(useShaders, mSceneManager->getForcePerPixelLighting(), - mSceneManager->getClampLighting(), &mSceneManager->getShaderManager(), layers, blendmapTextures, blendmapScale, blendmapScale); + return ::Terrain::createPasses(useShaders, &mSceneManager->getShaderManager(), layers, blendmapTextures, blendmapScale, blendmapScale); } osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Vec2f &chunkCenter, int lod, unsigned int lodFlags) @@ -217,8 +216,7 @@ osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Ve layer.mDiffuseMap = compositeMap->mTexture; layer.mParallax = false; layer.mSpecular = false; - geometry->setPasses(::Terrain::createPasses(mSceneManager->getForceShaders() || !mSceneManager->getClampLighting(), mSceneManager->getForcePerPixelLighting(), - mSceneManager->getClampLighting(), &mSceneManager->getShaderManager(), std::vector(1, layer), std::vector >(), 1.f, 1.f)); + geometry->setPasses(::Terrain::createPasses(mSceneManager->getForceShaders() || !mSceneManager->getClampLighting(), &mSceneManager->getShaderManager(), std::vector(1, layer), std::vector >(), 1.f, 1.f)); } else { diff --git a/components/terrain/material.cpp b/components/terrain/material.cpp index c61bdb455..1c989cc2a 100644 --- a/components/terrain/material.cpp +++ b/components/terrain/material.cpp @@ -153,7 +153,7 @@ namespace namespace Terrain { - std::vector > createPasses(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager, const std::vector &layers, + std::vector > createPasses(bool useShaders, Shader::ShaderManager* shaderManager, const std::vector &layers, const std::vector > &blendmaps, int blendmapScale, float layerTileSize) { std::vector > passes; @@ -211,8 +211,6 @@ namespace Terrain } Shader::ShaderManager::DefineMap defineMap; - defineMap["forcePPL"] = forcePerPixelLighting ? "1" : "0"; - defineMap["clamp"] = clampLighting ? "1" : "0"; defineMap["normalMap"] = (it->mNormalMap) ? "1" : "0"; defineMap["blendMap"] = !firstLayer ? "1" : "0"; defineMap["specularMap"] = it->mSpecular ? "1" : "0"; @@ -223,7 +221,7 @@ namespace Terrain if (!vertexShader || !fragmentShader) { // Try again without shader. Error already logged by above - return createPasses(false, forcePerPixelLighting, clampLighting, shaderManager, layers, blendmaps, blendmapScale, layerTileSize); + return createPasses(false, shaderManager, layers, blendmaps, blendmapScale, layerTileSize); } stateset->setAttributeAndModes(shaderManager->getProgram(vertexShader, fragmentShader)); diff --git a/components/terrain/material.hpp b/components/terrain/material.hpp index 25aa69540..5f78af6a0 100644 --- a/components/terrain/material.hpp +++ b/components/terrain/material.hpp @@ -26,7 +26,7 @@ namespace Terrain bool mSpecular; }; - std::vector > createPasses(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager, + std::vector > createPasses(bool useShaders, Shader::ShaderManager* shaderManager, const std::vector& layers, const std::vector >& blendmaps, int blendmapScale, float layerTileSize);