From 5770227e378c6eaa8879a85127a19cecbd4b267e Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 5 Mar 2020 13:15:18 +0300 Subject: [PATCH] Avoid using auto-detected normal maps that are bump map namesakes --- components/shader/shadervisitor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index d090c3397..7fb5d53f5 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -96,6 +96,7 @@ namespace Shader const osg::Texture* diffuseMap = nullptr; const osg::Texture* normalMap = nullptr; const osg::Texture* specularMap = nullptr; + const osg::Texture* bumpMap = nullptr; for(unsigned int unit=0;unitgetTextureAttribute(unit, osg::StateAttribute::TEXTURE); @@ -133,6 +134,7 @@ namespace Shader specularMap = texture; else if (texName == "bumpMap") { + bumpMap = texture; mRequirements.back().mShaderRequired = true; if (!writableStateSet) writableStateSet = getWritableStateSet(node); @@ -173,8 +175,11 @@ namespace Shader image = mImageManager.getImage(normalMapFileName); } } + // Avoid using the auto-detected normal map if it's already being used as a bump map. + // It's probably not an actual normal map. + bool hasNamesakeBumpMap = image && bumpMap && bumpMap->getImage(0) && image->getFileName() == bumpMap->getImage(0)->getFileName(); - if (image) + if (!hasNamesakeBumpMap && image) { osg::ref_ptr normalMapTex (new osg::Texture2D(image)); normalMapTex->setTextureSize(image->s(), image->t());