Hello OSG users,

My problem is simple to describe: When in our application we press 's' or 'h' 
to display either the stats or help, the
lighting changes when it should not.

Now although I've used OSG for a little while, I am not familiar with the 
rendering backend of it and may need some
suggestions to figure out what exactly the problem is.

I saw that these two handlers use a renderer with a default light and it is 
that light that is active when the scene is rendered.
Actually if I look at the Light::apply() and Geometry::drawImplementation() 
functions, I can see that first the drawImplementation()
is called for my geometry / scene, then the Light::apply() for the scene light, 
then the Light::apply() of the HelpHandler.
Therefore at the next frame the active light is always the default HelpHandler 
one when the scene is drawn. Looks like the rendering
/ light apply order is screwed up, and even without the handlers I am always 
using the light setting set at the end of the previous frame.

I have an effect in the scene that does RTT to a quad and another branch that 
renders the RTT result on a quad. The scene graph is the
EffectNode with the Scene as child. The RTTCam and RenderQuad are not in the
scene graph, they are added "by hand" in the traversals. Any idea of what is 
wrong ?

void EffectNode::traverse(osg::NodeVisitor& nv)
  {
    if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
    {
      osg::Group::traverse(nv);
      if(m_pSceneRTTCam.valid())
        m_pSceneRTTCam->traverse(nv);
      if(m_pRenderQuad.valid())
        m_pRenderQuad->traverse(nv);
    }
    else if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR &&
            dynamic_cast<osgUtil::CullVisitor*>(&nv))
    {
      cull(*static_cast<osgUtil::CullVisitor*>(&nv));
    }
    else
    {
      osg::Group::traverse(nv);
    }
  }

void EffectNode::cull(osgUtil::CullVisitor& cv)
  {
     // do RTT camera traversal, rendering the scene graph under EffectNode 
group
     m_pSceneRTTCam->accept(cv); // write to texture

     // render texture on quad and apply post-process shader
     cv.apply(*m_pRenderQuad.get());
}

m_pSceneRTTCam->setCullCallback(new CameraCullCallback(this)); // this == 
EffectNode

/*!
  Needed to be able to render the scene which is not a child of
  a camera (which has this culling callback)
*/
class VSSFX_Export CameraCullCallback : public osg::NodeCallback
  {
    public:
          CameraCullCallback(osg::Group* fx) : m_fx(fx)
          { }
          virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
          { m_fx->osg::Group::traverse(*nv); }

        private:
          osg::observer_ptr<osg::Group> m_fx; /// group which has the scene 
under it
};



cheers,


guillaume

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to