<div dir="ltr"><span style="font-size:14px"> 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 </span><a href="http://shaders.as/" target="_blank" style="font-size:14px">shaders.as</a><span style="font-size:14px"> follows:</span><div style="font-size:14px">I transfer different value to the vertex  shader if the type is dedined different. </div><div style="font-size:14px"><br><div><div>class AnalysisNodeVisitor :public osg::NodeVisitor{</div><div>public:</div><div><span style="white-space:pre-wrap">  </span>AnalysisNodeVisitor(INPUTTYPE type):osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN){</div><div><span style="white-space:pre-wrap">           </span>m_InputType=type;</div><div><span style="white-space:pre-wrap">        </span>}</div><div><span style="white-space:pre-wrap">        </span>virtual void apply(osg::Geode &node)</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap">                </span>for ( unsigned int i=0; i<node.getNumDrawables(); ++i )</div><div><span style="white-space:pre-wrap">               </span>{</div><div><span style="white-space:pre-wrap">                        </span>osg::Geometry* geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i) );</div><div><span style="white-space:pre-wrap">                  </span>if ( geom ){</div><div><span style="white-space:pre-wrap">                             </span>osg::FloatArray *fa=new osg::FloatArray;</div><div><span style="white-space:pre-wrap">                         </span>switch(m_InputType){</div><div><span style="white-space:pre-wrap">                                     </span>case INPUTTEXTURE:</div><div><span style="white-space:pre-wrap">                                               </span>{</div><div><span style="white-space:pre-wrap">                                                        </span>fa->push_back(0.1);</div><div><span style="white-space:pre-wrap">                                                   </span>break;</div><div><span style="white-space:pre-wrap">                                           </span>}</div><div><span style="white-space:pre-wrap">                                        </span>case INPUTMATERIAL:</div><div><span style="white-space:pre-wrap">                                              </span>{</div><div><span style="white-space:pre-wrap">                                                        </span>fa->push_back(0.2);</div><div><span style="white-space:pre-wrap">                                                   </span>break;</div><div><span style="white-space:pre-wrap">                                           </span>}</div><div><span style="white-space:pre-wrap">                                        </span>default :</div><div><span style="white-space:pre-wrap">                                                </span>{</div><div><span style="white-space:pre-wrap">                                                        </span>fa->push_back(0.9);</div><div><span style="white-space:pre-wrap">                                           </span>}</div><div><span style="white-space:pre-wrap">                                </span>}</div><div><span style="white-space:pre-wrap">                                </span>geom->setVertexAttribArray(6,fa);</div><div><span style="white-space:pre-wrap">                             </span>geom->setVertexAttribBinding(6,osg::Geometry::BIND_OVERALL);</div><div><span style="white-space:pre-wrap">                  </span>}</div><div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">                </span>traverse( node );</div><div><span style="white-space:pre-wrap">        </span>}</div><div><span style="white-space:pre-wrap">        </span>virtual void apply(osg::Node &node){</div><div><span style="white-space:pre-wrap">         </span>traverse(node);</div><div><span style="white-space:pre-wrap">  </span>}</div><div>public:</div><div><span style="white-space:pre-wrap">  </span>INPUTTYPE m_InputType;</div><div>};</div></div></div><div style="font-size:14px"><br></div><div style="font-size:14px">and bind the attribute to the shader:</div><div style="font-size:14px"><span style="white-space:pre-wrap">  </span>program->addBindAttribLocation("modelType",6);<br></div><div style="font-size:14px"><br></div><div style="font-size:14px">but when I use the AnalysisNodeVisitor,I occur a error.</div><div style="font-size:14px"><br></div><div style="font-size:14px">AnalysisNodeVisitor anvA(INPUTTEXTURE);<br></div><div style="font-size:14px">nodeA.accept(anvA);</div><div style="font-size:14px">AnalysisNodeVisitor anvB(INPUTMATERIAL);<br></div><div style="font-size:14px">nodeB.accept(anvB);</div><div style="font-size:14px"><br></div><div style="font-size:14px">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 <a href="http://0.2.it/" target="_blank">0.2 .It</a> seems nodeB.accept(anvB) override the modeType variable of nodeA. what is wrong with it?Am I misunderstand it ?</div></div>