diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index 33fd9186f..a734151eb 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -317,34 +317,46 @@ namespace Shader { const ShaderRequirements& reqs = mRequirements.back(); - osg::ref_ptr sourceGeometry = &geometry; - SceneUtil::RigGeometry* rig = dynamic_cast(&geometry); - if (rig) - sourceGeometry = rig->getSourceGeometry(); + bool useShader = reqs.mShaderRequired || mForceShaders; + bool generateTangents = reqs.mTexStageRequiringTangents != -1 && mAllowedToModifyStateSets; - if (mAllowedToModifyStateSets) + if (useShader || generateTangents) { - // make sure that all UV sets are there - for (std::map::const_iterator it = reqs.mTextures.begin(); it != reqs.mTextures.end(); ++it) + osg::ref_ptr sourceGeometry = &geometry; + SceneUtil::RigGeometry* rig = dynamic_cast(&geometry); + if (rig) + sourceGeometry = rig->getSourceGeometry(); + + bool requiresSetGeometry = false; + + if (mAllowedToModifyStateSets) { - if (sourceGeometry->getTexCoordArray(it->first) == NULL) - sourceGeometry->setTexCoordArray(it->first, sourceGeometry->getTexCoordArray(0)); + // make sure that all UV sets are there + for (std::map::const_iterator it = reqs.mTextures.begin(); it != reqs.mTextures.end(); ++it) + { + if (sourceGeometry->getTexCoordArray(it->first) == NULL) + { + sourceGeometry->setTexCoordArray(it->first, sourceGeometry->getTexCoordArray(0)); + requiresSetGeometry = true; + } + } } - } - if (reqs.mTexStageRequiringTangents != -1 && mAllowedToModifyStateSets) - { - osg::ref_ptr generator (new osgUtil::TangentSpaceGenerator); - generator->generate(sourceGeometry, reqs.mTexStageRequiringTangents); + if (generateTangents) + { + osg::ref_ptr generator (new osgUtil::TangentSpaceGenerator); + generator->generate(sourceGeometry, reqs.mTexStageRequiringTangents); - sourceGeometry->setTexCoordArray(7, generator->getTangentArray(), osg::Array::BIND_PER_VERTEX); - } + sourceGeometry->setTexCoordArray(7, generator->getTangentArray(), osg::Array::BIND_PER_VERTEX); + requiresSetGeometry = true; + } - if (rig) - rig->setSourceGeometry(sourceGeometry); + if (rig && requiresSetGeometry) + rig->setSourceGeometry(sourceGeometry); + } // TODO: find a better place for the stateset - if (reqs.mShaderRequired || mForceShaders) + if (useShader) createProgram(reqs, geometry); }