|
|
@ -248,6 +248,9 @@ namespace Shader
|
|
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::createProgram(const ShaderRequirements &reqs)
|
|
|
|
void ShaderVisitor::createProgram(const ShaderRequirements &reqs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!reqs.mShaderRequired && !mForceShaders)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
osg::Node& node = *reqs.mNode;
|
|
|
|
osg::Node& node = *reqs.mNode;
|
|
|
|
osg::StateSet* writableStateSet = NULL;
|
|
|
|
osg::StateSet* writableStateSet = NULL;
|
|
|
|
if (mAllowedToModifyStateSets)
|
|
|
|
if (mAllowedToModifyStateSets)
|
|
|
@ -305,55 +308,51 @@ namespace Shader
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::apply(osg::Geometry& geometry)
|
|
|
|
bool ShaderVisitor::adjustGeometry(osg::Geometry& sourceGeometry, const ShaderRequirements& reqs)
|
|
|
|
{
|
|
|
|
|
|
|
|
bool needPop = (geometry.getStateSet() != NULL);
|
|
|
|
|
|
|
|
if (geometry.getStateSet()) // TODO: check if stateset affects shader permutation before pushing it
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushRequirements(geometry);
|
|
|
|
|
|
|
|
applyStateSet(geometry.getStateSet(), geometry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool useShader = reqs.mShaderRequired || mForceShaders;
|
|
|
|
bool useShader = reqs.mShaderRequired || mForceShaders;
|
|
|
|
bool generateTangents = reqs.mTexStageRequiringTangents != -1;
|
|
|
|
bool generateTangents = reqs.mTexStageRequiringTangents != -1;
|
|
|
|
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (mAllowedToModifyStateSets && (useShader || generateTangents))
|
|
|
|
if (mAllowedToModifyStateSets && (useShader || generateTangents))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = &geometry;
|
|
|
|
|
|
|
|
SceneUtil::RigGeometry* rig = dynamic_cast<SceneUtil::RigGeometry*>(&geometry);
|
|
|
|
|
|
|
|
if (rig)
|
|
|
|
|
|
|
|
sourceGeometry = rig->getSourceGeometry();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool requiresSetGeometry = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make sure that all UV sets are there
|
|
|
|
// make sure that all UV sets are there
|
|
|
|
for (std::map<int, std::string>::const_iterator it = reqs.mTextures.begin(); it != reqs.mTextures.end(); ++it)
|
|
|
|
for (std::map<int, std::string>::const_iterator it = reqs.mTextures.begin(); it != reqs.mTextures.end(); ++it)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (sourceGeometry->getTexCoordArray(it->first) == NULL)
|
|
|
|
if (sourceGeometry.getTexCoordArray(it->first) == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sourceGeometry->setTexCoordArray(it->first, sourceGeometry->getTexCoordArray(0));
|
|
|
|
sourceGeometry.setTexCoordArray(it->first, sourceGeometry.getTexCoordArray(0));
|
|
|
|
requiresSetGeometry = true;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (generateTangents)
|
|
|
|
if (generateTangents)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgUtil::TangentSpaceGenerator> generator (new osgUtil::TangentSpaceGenerator);
|
|
|
|
osg::ref_ptr<osgUtil::TangentSpaceGenerator> generator (new osgUtil::TangentSpaceGenerator);
|
|
|
|
generator->generate(sourceGeometry, reqs.mTexStageRequiringTangents);
|
|
|
|
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;
|
|
|
|
changed = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rig && requiresSetGeometry)
|
|
|
|
void ShaderVisitor::apply(osg::Geometry& geometry)
|
|
|
|
rig->setSourceGeometry(sourceGeometry);
|
|
|
|
{
|
|
|
|
|
|
|
|
bool needPop = (geometry.getStateSet() != NULL);
|
|
|
|
|
|
|
|
if (geometry.getStateSet()) // TODO: check if stateset affects shader permutation before pushing it
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pushRequirements(geometry);
|
|
|
|
|
|
|
|
applyStateSet(geometry.getStateSet(), geometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (useShader)
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
adjustGeometry(geometry, reqs);
|
|
|
|
|
|
|
|
|
|
|
|
createProgram(reqs);
|
|
|
|
createProgram(reqs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -375,8 +374,14 @@ namespace Shader
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
if (reqs.mShaderRequired || mForceShaders)
|
|
|
|
|
|
|
|
createProgram(reqs);
|
|
|
|
createProgram(reqs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SceneUtil::RigGeometry* rig = dynamic_cast<SceneUtil::RigGeometry*>(&drawable))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Geometry> sourceGeometry = rig->getSourceGeometry();
|
|
|
|
|
|
|
|
if (sourceGeometry && adjustGeometry(*sourceGeometry, reqs))
|
|
|
|
|
|
|
|
rig->setSourceGeometry(sourceGeometry);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (needPop)
|
|
|
|
if (needPop)
|
|
|
|