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
{
public:
    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 =
                cv->getCurrentRenderBin()->getStage()->getCamera();
            // 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() >
                                       s_skyDomePreRenderCameraNum)
            {
                // 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->setClearMask(
                        camera->getClearMask() & ~GL_COLOR_BUFFER_BIT);
            }
        }

        traverse(node,nv);
    }
};

}

SkyDome::SkyDome(...)
{
    // 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.
#define USE_EXTRA_CAMERA
#ifdef USE_EXTRA_CAMERA
    osg::Camera* camera = new osg::Camera;
    camera->setRenderOrder(osg::Camera::PRE_RENDER,
        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).
    camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    // The dome hangs under m_skyTransform.
    camera->addChild(m_skyTransform.get());
    // m_node is the node that's exposed to be added to the graph by
    // client code.
    m_node->addChild(camera);

    // Make sure the main viewer camera only clears the depth buffer
    // otherwise it will clear our skydome...
    m_node->setCullCallback(new CheckCamerasCallback);
#else
    // 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
#endif

}

Thanks a lot.

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to