From 788a4d32aab74c33cad25ba24ae23e60b705458a Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sun, 21 May 2023 03:28:02 +0200 Subject: [PATCH] Handle DoubleSided and TreeAnim flags in BSLightingShaderProperty. --- apps/openmw/mwrender/renderingmanager.cpp | 1 + components/nif/property.hpp | 3 +++ components/nifosg/nifloader.cpp | 10 ++++++++++ files/shaders/compatibility/bs/default.frag | 4 +++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index d8582ccef1..7d23ff9622 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -172,6 +172,7 @@ namespace MWRender stateset->addUniform(new osg::Uniform("isReflection", false)); stateset->addUniform(new osg::Uniform("windSpeed", 0.0f)); stateset->addUniform(new osg::Uniform("playerPos", osg::Vec3f(0.f, 0.f, 0.f))); + stateset->addUniform(new osg::Uniform("useTreeAnim", false)); } void apply(osg::StateSet* stateset, osg::NodeVisitor* nv) override diff --git a/components/nif/property.hpp b/components/nif/property.hpp index 108fb62a2b..3e45c83ad6 100644 --- a/components/nif/property.hpp +++ b/components/nif/property.hpp @@ -138,6 +138,9 @@ namespace Nif unsigned int type{ 0u }, flags1{ 0u }, flags2{ 0u }; float envMapIntensity{ 0.f }; void read(NIFStream* nif) override; + + bool doubleSided() const { return (flags2 >> 4) & 1; } + bool treeAnim() const { return (flags2 >> 29) & 1; } }; struct BSShaderLightingProperty : public BSShaderProperty diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index c158055d40..386f4d30a7 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -2150,6 +2150,8 @@ namespace NifOsg textureSet, texprop->clamp, node->getName(), stateset, imageManager, boundTextures); } handleTextureControllers(texprop, composite, imageManager, stateset, animflags); + if (texprop->doubleSided()) + stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); break; } case Nif::RC_BSShaderNoLightingProperty: @@ -2190,6 +2192,8 @@ namespace NifOsg stateset->addUniform(new osg::Uniform("useFalloff", false)); } handleTextureControllers(texprop, composite, imageManager, stateset, animflags); + if (texprop->doubleSided()) + stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); break; } case Nif::RC_BSLightingShaderProperty: @@ -2203,6 +2207,10 @@ namespace NifOsg handleTextureSet(texprop->mTextureSet.getPtr(), texprop->mClamp, node->getName(), stateset, imageManager, boundTextures); handleTextureControllers(texprop, composite, imageManager, stateset, animflags); + if (texprop->doubleSided()) + stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); + if (texprop->treeAnim()) + stateset->addUniform(new osg::Uniform("useTreeAnim", true)); break; } case Nif::RC_BSEffectShaderProperty: @@ -2253,6 +2261,8 @@ namespace NifOsg stateset->addUniform(new osg::Uniform("useFalloff", false)); // Should use the shader flag stateset->addUniform(new osg::Uniform("falloffParams", texprop->mFalloffParams)); handleTextureControllers(texprop, composite, imageManager, stateset, animflags); + if (texprop->doubleSided()) + stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); break; } // unused by mw diff --git a/files/shaders/compatibility/bs/default.frag b/files/shaders/compatibility/bs/default.frag index 240ff0907f..8c429947b0 100644 --- a/files/shaders/compatibility/bs/default.frag +++ b/files/shaders/compatibility/bs/default.frag @@ -38,6 +38,7 @@ uniform float far; uniform float alphaRef; uniform float emissiveMult; uniform float specStrength; +uniform bool useTreeAnim; #include "lib/light/lighting.glsl" #include "lib/material/alpha.glsl" @@ -58,7 +59,8 @@ void main() #endif vec4 diffuseColor = getDiffuseColor(); - gl_FragData[0].a *= diffuseColor.a; + if (!useTreeAnim) + gl_FragData[0].a *= diffuseColor.a; gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef); #if @normalMap