From e25e0a0600b95c1f2c1d7a228fffc5b226465b10 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 20 Feb 2016 23:43:05 +0100 Subject: [PATCH] ShaderVisitor: assume the first texture unit is the diffuseMap --- components/shader/shadervisitor.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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