Hello J-S,

Is the solution you posted below the final solution you settled on? I had trouble determining what you finally ended up deciding was the best path forward. Thanks for posting this information on the list.


On Apr 22, 2009, at 12:40 AM, Jean-Sébastien Guay wrote:

Hi again Paul,

Anyways, that's a design concern, not implementation. Thanks for your suggestions.

And I do want to emphasize that your solution (using a separate osg::Camera) does work. I've implemented it for both the skydome and cloud plane (which can get really big too) and I can now get really close to small models without them being clipped by the near plane. Barring any breakthrough on the other front, this will still be a very good solution.

If anyone's curious, the code looks like:

// Callback that checks other cameras

namespace {

int s_skyDomePreRenderCameraNum = -100;

class CheckCamerasCallback : public osg::NodeCallback
   virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
       osgUtil::CullVisitor *cv =
           dynamic_cast< osgUtil::CullVisitor *>( nv );
       if (cv)
           // Do not use cv->getCurrentCamera() because it did not
           // exist in 2.2 which we still support
           osg::Camera* camera =
           // If the camera is either a pre-render camera with num >
           // our pre-render order, or not a pre-render camera
           if (camera->getRenderOrder() != osg::Camera::PRE_RENDER ||
               camera->getRenderOrderNum() >
// I should also check if the camera is set to render to
               // the framebuffer and is not an RTT camera, just to be
// sure I'm only affecting the cameras I want to affect.

               // Set the camera to not clear the color buffer.
               if (camera->getClearMask() & GL_COLOR_BUFFER_BIT)
                       camera->getClearMask() & ~GL_COLOR_BUFFER_BIT);



   // Skydome initialization (the code is a modified version of the
   // osgEphemeris skydome)
   // ...
   // ...

// Render the skydome through another camera so that the cloud plane
   // won't influence the main camera's near/far plane computations.
   // I'd prefer to find some other way to have the sky dome not
   // influence the main camera near/far values, because this has
   // repercussions on the viewer setup (see how CheckCamerasCallback
   // affects all other cameras). But it works well.
   osg::Camera* camera = new osg::Camera;
       s_skyDomePreRenderCameraNum);   // set to -100 by default
   // Hopefully this will be the first pre-render camera, so it should
// clear the color and depth buffers (this skydome is not guaranteed
   // to fill the whole view at all times).
   // The dome hangs under m_skyTransform.
   // m_node is the node that's exposed to be added to the graph by
   // client code.

   // Make sure the main viewer camera only clears the depth buffer
   // otherwise it will clear our skydome...
   m_node->setCullCallback(new CheckCamerasCallback);
   // The dome hangs under m_skyTransform.
   // m_node is the node that's exposed to be added to the graph by
   // client code.
m_node->addChild(m_skyTransform.get()); // The dome hangs under this


Thanks a lot.

osg-users mailing list

Reply via email to