<div dir="ltr">I am sorry I did not describe the solution clearly.<div>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.</div><div>Actually the problem I need to solve is:</div><div>how the judge which model the vertex belongs to in the vertex shaders and fragment shaders?</div><div><br></div><div>thanks</div><div><br></div><div><span style="font-size:14px">Date: Wed, 22 Apr 2015 10:58:35 +0100</span><br style="font-size:14px"><span style="font-size:14px">From: Robert Osfield <</span><a href="mailto:robert.osfield@gmail.com" style="font-size:14px">robert.osfield@gmail.com</a><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">To: OpenSceneGraph Users <</span><a href="mailto:osg-users@lists.openscenegraph.org" style="font-size:14px">osg-users@lists.openscenegraph.org</a><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">Subject: Re: [osg-users] attribute variable transfers error</span><br style="font-size:14px"><span style="font-size:14px">Message-ID:</span><br style="font-size:14px"><span style="font-size:14px">        <</span><a href="mailto:CAFN7Y%2BXeofDyFr9H9Z9j%2BsOSnQAi%2BSzuyaUuOvkDvGiSQdyBdQ@mail.gmail.com" style="font-size:14px">CAFN7Y+XeofDyFr9H9Z9j+sOSnQAi+SzuyaUuOvkDvGiSQdyBdQ@mail.gmail.com</a><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">Content-Type: text/plain; charset=ISO-8859-1</span><br style="font-size:14px"><br style="font-size:14px"><span style="font-size:14px">Hi Allan,</span><br style="font-size:14px"><br style="font-size:14px"><span style="font-size:14px">Could you take a step back and tells us what problem you are trying to</span><br style="font-size:14px"><span style="font-size:14px">solve as you've dived in with a rather perplexing implementation for a</span><br style="font-size:14px"><span style="font-size:14px">problem that may well have a very straight forward solution.</span><br style="font-size:14px"><br style="font-size:14px"><span style="font-size:14px">Robert.</span><br style="font-size:14px"><br style="font-size:14px"><span style="font-size:14px">On 22 April 2015 at 10:34, allan xia <</span><a href="mailto:softpeo@gmail.com" style="font-size:14px">softpeo@gmail.com</a><span style="font-size:14px">> wrote:</span><br style="font-size:14px"><span style="font-size:14px">>  I need to distinguish the vertexs in different models in vertex shaders and</span><br style="font-size:14px"><span style="font-size:14px">> fragment shaders  .so I use a nodevisitor to transfer a attribute variable</span><br style="font-size:14px"><span style="font-size:14px">> to the vertex </span><a href="http://shaders.as/" target="_blank" style="font-size:14px">shaders.as</a><span style="font-size:14px"> follows:</span><br style="font-size:14px"><span style="font-size:14px">> I transfer different value to the vertex  shader if the type is defined</span><br style="font-size:14px"><span style="font-size:14px">> different.</span><br style="font-size:14px"><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">> class AnalysisNodeVisitor :public osg::NodeVisitor{</span><br style="font-size:14px"><span style="font-size:14px">> public:</span><br style="font-size:14px"><span style="font-size:14px">> AnalysisNodeVisitor(INPUTTYPE</span><br style="font-size:14px"><span style="font-size:14px">> type):osg::NodeVisitor(osg::</span><span style="font-size:14px">NodeVisitor::TRAVERSE_ALL_</span><span style="font-size:14px">CHILDREN){</span><br style="font-size:14px"><span style="font-size:14px">> m_InputType=type;</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> virtual void apply(osg::Geode &node)</span><br style="font-size:14px"><span style="font-size:14px">> {</span><br style="font-size:14px"><span style="font-size:14px">> for ( unsigned int i=0; i<node.getNumDrawables(); ++i )</span><br style="font-size:14px"><span style="font-size:14px">> {</span><br style="font-size:14px"><span style="font-size:14px">> osg::Geometry* geom = dynamic_cast<osg::Geometry*>(</span><span style="font-size:14px">node.getDrawable(i) );</span><br style="font-size:14px"><span style="font-size:14px">> if ( geom ){</span><br style="font-size:14px"><span style="font-size:14px">> osg::FloatArray *fa=new osg::FloatArray;</span><br style="font-size:14px"><span style="font-size:14px">> switch(m_InputType){</span><br style="font-size:14px"><span style="font-size:14px">> case INPUTTEXTURE:</span><br style="font-size:14px"><span style="font-size:14px">> {</span><br style="font-size:14px"><span style="font-size:14px">> fa->push_back(0.1);</span><br style="font-size:14px"><span style="font-size:14px">> break;</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> case INPUTMATERIAL:</span><br style="font-size:14px"><span style="font-size:14px">> {</span><br style="font-size:14px"><span style="font-size:14px">> fa->push_back(0.2);</span><br style="font-size:14px"><span style="font-size:14px">> break;</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> default :</span><br style="font-size:14px"><span style="font-size:14px">> {</span><br style="font-size:14px"><span style="font-size:14px">> fa->push_back(0.9);</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> geom->setVertexAttribArray(6,</span><span style="font-size:14px">fa);</span><br style="font-size:14px"><span style="font-size:14px">> geom->setVertexAttribBinding(</span><span style="font-size:14px">6,osg::Geometry::BIND_OVERALL)</span><span style="font-size:14px">;</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> traverse( node );</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> virtual void apply(osg::Node &node){</span><br style="font-size:14px"><span style="font-size:14px">> traverse(node);</span><br style="font-size:14px"><span style="font-size:14px">> }</span><br style="font-size:14px"><span style="font-size:14px">> public:</span><br style="font-size:14px"><span style="font-size:14px">> INPUTTYPE m_InputType;</span><br style="font-size:14px"><span style="font-size:14px">> };</span><br style="font-size:14px"><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">> and bind the attribute to the shader:</span><br style="font-size:14px"><span style="font-size:14px">> program-></span><span style="font-size:14px">addBindAttribLocation("</span><span style="font-size:14px">modelType",6);</span><br style="font-size:14px"><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">> but when I use the AnalysisNodeVisitor,I occur a error.</span><br style="font-size:14px"><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">> AnalysisNodeVisitor anvA(INPUTTEXTURE);</span><br style="font-size:14px"><span style="font-size:14px">> nodeA.accept(anvA);</span><br style="font-size:14px"><span style="font-size:14px">> AnalysisNodeVisitor anvB(INPUTMATERIAL);</span><br style="font-size:14px"><span style="font-size:14px">> nodeB.accept(anvB);</span><br style="font-size:14px"><span style="font-size:14px">></span><br style="font-size:14px"><span style="font-size:14px">> and in the vertex shader  modelType variable of vertexs in nodeA should be</span><br style="font-size:14px"><span style="font-size:14px">> 0.1 and modeType variable of vertexs in NodeB should be 0.2 ,but actually</span><br style="font-size:14px"><span style="font-size:14px">> modeType variable of all vertex is 0.2 .It seems nodeB.accept(anvB) override</span><br style="font-size:14px"><span style="font-size:14px">> the modeType variable of nodeA. what is wrong with it?Am I misunderstand it</span><br style="font-size:14px"><span style="font-size:14px">> ?</span><br></div></div>