I am sorry I did not describe the solution clearly. Now I need to do some extra operations in the models,so I must use shaders .And different models have little different operations,but mostly same operations, So I use the same shaders and send a flag variable to the shaders to judge which model the vertexs belong to. then I could solve the different operations. and now I use the nodevisitor to judge which model the vertex belongs to ,but I occur error. Actually the problem I need to solve is: how the judge which model the vertex belongs to in the vertex shaders and fragment shaders?
thanks Date: Wed, 22 Apr 2015 10:58:35 +0100 From: Robert Osfield <[email protected]> To: OpenSceneGraph Users <[email protected]> Subject: Re: [osg-users] attribute variable transfers error Message-ID: <cafn7y+xeofdyfr9h9z9j+sosnqai+szuyauuovkdvgisqdy...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi Allan, Could you take a step back and tells us what problem you are trying to solve as you've dived in with a rather perplexing implementation for a problem that may well have a very straight forward solution. Robert. On 22 April 2015 at 10:34, allan xia <[email protected]> wrote: > 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 defined > 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 seems nodeB.accept(anvB) override > the modeType variable of nodeA. what is wrong with it?Am I misunderstand it > ?
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

