Avoid using auto-detected normal maps that are bump map namesakes

pull/558/head
Capostrophic 5 years ago
parent 624a9ac353
commit 5770227e37

@ -96,6 +96,7 @@ namespace Shader
const osg::Texture* diffuseMap = nullptr; const osg::Texture* diffuseMap = nullptr;
const osg::Texture* normalMap = nullptr; const osg::Texture* normalMap = nullptr;
const osg::Texture* specularMap = nullptr; const osg::Texture* specularMap = nullptr;
const osg::Texture* bumpMap = nullptr;
for(unsigned int unit=0;unit<texAttributes.size();++unit) for(unsigned int unit=0;unit<texAttributes.size();++unit)
{ {
const osg::StateAttribute *attr = stateset->getTextureAttribute(unit, osg::StateAttribute::TEXTURE); const osg::StateAttribute *attr = stateset->getTextureAttribute(unit, osg::StateAttribute::TEXTURE);
@ -133,6 +134,7 @@ namespace Shader
specularMap = texture; specularMap = texture;
else if (texName == "bumpMap") else if (texName == "bumpMap")
{ {
bumpMap = texture;
mRequirements.back().mShaderRequired = true; mRequirements.back().mShaderRequired = true;
if (!writableStateSet) if (!writableStateSet)
writableStateSet = getWritableStateSet(node); writableStateSet = getWritableStateSet(node);
@ -173,8 +175,11 @@ namespace Shader
image = mImageManager.getImage(normalMapFileName); 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<osg::Texture2D> normalMapTex (new osg::Texture2D(image)); osg::ref_ptr<osg::Texture2D> normalMapTex (new osg::Texture2D(image));
normalMapTex->setTextureSize(image->s(), image->t()); normalMapTex->setTextureSize(image->s(), image->t());

Loading…
Cancel
Save