diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index bcce4a09c..46d4edf44 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -88,6 +88,15 @@ namespace Shader return newStateSet.get(); } + const char* defaultTextures[] = { "diffuseMap", "normalMap", "emissiveMap", "darkMap", "detailMap", "envMap", "specularMap" }; + bool isTextureNameRecognized(const std::string& name) + { + for (unsigned int i=0; i stateset, osg::Node& node) { osg::StateSet* writableStateSet = NULL; @@ -107,10 +116,14 @@ namespace Shader const osg::Texture* texture = attr->asTexture(); if (texture) { - if (!texture->getName().empty()) + std::string texName = texture->getName(); + if ((texName.empty() || !isTextureNameRecognized(texName)) && unit == 0) + texName = "diffuseMap"; + + if (!texName.empty()) { - mRequirements.back().mTextures[unit] = texture->getName(); - if (texture->getName() == "normalMap") + mRequirements.back().mTextures[unit] = texName; + if (texName == "normalMap") { mRequirements.back().mTexStageRequiringTangents = unit; mRequirements.back().mShaderRequired = true; @@ -120,9 +133,9 @@ namespace Shader writableStateSet->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::ON); normalMap = texture; } - if (texture->getName() == "diffuseMap") + if (texName == "diffuseMap") diffuseMap = texture; - if (texture->getName() == "specularMap") + if (texName == "specularMap") specularMap = texture; } else @@ -222,7 +235,6 @@ namespace Shader writableStateSet = getWritableStateSet(node); ShaderManager::DefineMap defineMap; - const char* defaultTextures[] = { "diffuseMap", "normalMap", "emissiveMap", "darkMap", "detailMap", "envMap", "specularMap" }; for (unsigned int i=0; i