[osg-users] attribute variable transfers error

allan xia softpeo at gmail.com
Wed Apr 22 02:34:01 PDT 2015


 I need to distinguish the vertexs in different models in vertex shaders
and fragment shaders  .so I use a nodevisitor to transfer a attribute
variable to the vertex shaders.as follows:
I transfer different value to the vertex  shader if the type is dedined
different.

class AnalysisNodeVisitor :public osg::NodeVisitor{
public:
AnalysisNodeVisitor(INPUTTYPE
type):osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN){
m_InputType=type;
}
virtual void apply(osg::Geode &node)
{
for ( unsigned int i=0; i<node.getNumDrawables(); ++i )
{
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i) );
if ( geom ){
osg::FloatArray *fa=new osg::FloatArray;
switch(m_InputType){
case INPUTTEXTURE:
{
fa->push_back(0.1);
break;
}
case INPUTMATERIAL:
{
fa->push_back(0.2);
break;
}
default :
{
fa->push_back(0.9);
}
}
geom->setVertexAttribArray(6,fa);
geom->setVertexAttribBinding(6,osg::Geometry::BIND_OVERALL);
}
}
traverse( node );
}
virtual void apply(osg::Node &node){
traverse(node);
}
public:
INPUTTYPE m_InputType;
};

and bind the attribute to the shader:
program->addBindAttribLocation("modelType",6);

but when I use the AnalysisNodeVisitor,I occur a error.

AnalysisNodeVisitor anvA(INPUTTEXTURE);
nodeA.accept(anvA);
AnalysisNodeVisitor anvB(INPUTMATERIAL);
nodeB.accept(anvB);

and in the vertex shader  modelType variable of vertexs in nodeA should be
0.1 and modeType variable of vertexs in NodeB should be 0.2 ,but actually
modeType variable of all vertex is 0.2 .It <http://0.2.it/> seems
nodeB.accept(anvB) override the modeType variable of nodeA. what is wrong
with it?Am I misunderstand it ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150422/04aa9bdd/attachment-0001.htm>


More information about the osg-users mailing list