From 9880c43c86b699f30eef2cc78143162d34cff70c Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Wed, 10 Nov 2021 19:58:06 +0300 Subject: [PATCH] Add specular strength shader parameter --- apps/openmw/mwrender/objectpaging.cpp | 1 + apps/openmw/mwrender/renderingmanager.cpp | 1 + components/nifosg/nifloader.cpp | 3 +++ components/resource/scenemanager.cpp | 1 + files/shaders/nv_default_fragment.glsl | 3 ++- files/shaders/objects_fragment.glsl | 2 ++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index 4e21d33475..90069c2d8d 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -359,6 +359,7 @@ namespace MWRender stateset->setAttribute(m); stateset->addUniform(new osg::Uniform("colorMode", 0)); stateset->addUniform(new osg::Uniform("emissiveMult", 1.f)); + stateset->addUniform(new osg::Uniform("specStrength", 1.f)); node.setStateSet(stateset); } }; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 06bfb3582f..e0cd3f713a 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -500,6 +500,7 @@ namespace MWRender defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f)); sceneRoot->getOrCreateStateSet()->setAttribute(defaultMat); sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("emissiveMult", 1.f)); + sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", 1.f)); mFog.reset(new FogManager()); diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index a745d50eda..e46e2d934b 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1932,6 +1932,7 @@ namespace NifOsg int lightmode = 1; float emissiveMult = 1.f; + float specStrength = 1.f; for (const Nif::Property* property : properties) { @@ -2081,6 +2082,8 @@ namespace NifOsg stateset->setAttributeAndModes(mat, osg::StateAttribute::ON); if (emissiveMult != 1.f) stateset->addUniform(new osg::Uniform("emissiveMult", emissiveMult)); + if (specStrength != 1.f) + stateset->addUniform(new osg::Uniform("specStrength", specStrength)); } }; diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 8a88f7def9..f6c041a879 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -524,6 +524,7 @@ namespace Resource result.getNode()->accept(colladaAlphaTrickVisitor); result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("emissiveMult", 1.f)); + result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", 1.f)); result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("envMapColor", osg::Vec4f(1,1,1,1))); result.getNode()->getOrCreateStateSet()->addUniform(new osg::Uniform("useFalloff", false)); } diff --git a/files/shaders/nv_default_fragment.glsl b/files/shaders/nv_default_fragment.glsl index 17204534e3..ff81a2b94d 100644 --- a/files/shaders/nv_default_fragment.glsl +++ b/files/shaders/nv_default_fragment.glsl @@ -39,6 +39,7 @@ varying vec3 passNormal; #include "alpha.glsl" uniform float emissiveMult; +uniform float specStrength; void main() { @@ -80,7 +81,7 @@ void main() gl_FragData[0].xyz *= lighting; float shininess = gl_FrontMaterial.shininess; - vec3 matSpec = getSpecularColor().xyz; + vec3 matSpec = getSpecularColor().xyz * specStrength; #if @normalMap matSpec *= normalTex.a; #endif diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index d750a4dd1f..99ed44919b 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -71,6 +71,7 @@ centroid varying vec3 shadowDiffuseLighting; #else uniform float emissiveMult; #endif +uniform float specStrength; varying vec3 passViewPos; varying vec3 passNormal; @@ -204,6 +205,7 @@ void main() vec3 matSpec = getSpecularColor().xyz; #endif + matSpec *= specStrength; if (matSpec != vec3(0.0)) { #if (!@normalMap && !@parallax && !@forcePPL)