[osg-users] Can I add more then one ClipNodeBox to a scene?

Robert Osfield robert.osfield at gmail.com
Mon Sep 15 01:49:20 PDT 2008

Hi Karl,

glClipPlane (and associated osg::ClipPlane) are positional state,
which means that the modelview matrix which is current when glClipLane
is called affects the setting down on the GPU of the associated
parameters, this is very different from most OpenGL state that is
totally unaffected by modelview matrix.  The consequence of being
positional state is that the OSG has to tightly control the modelview
matrix before the osg::ClipPlane is called, so that the plane goes in
the correct place rather than jump around randomly as would be the
cause if you just allow state sorting to do its work with any old
modelview matrix being applied.

To control the modelview matrix for clip planes the OSG has a special
node osg::ClipNode, which tells cull traversal to build a rendering
backend that binds the modelview matrix, inherited down to the
ClipNode, with the clip planes associated with the ClipNode; and then
during the draw traversal all the positional state for each
RenderiStage is applied together so that they are all placed in their
correct positions.

While this system does solve the problem of placing positional state
correctly in the scene it does mean that each clip plane can only have
one position per stage in the draw traversal - which is why you are
seeing only one ClipNode active.  To be able to multiple ClipNode you
either need to keep the clip plane numbers distinct (which is limited
because OpenGL only supports a small number of clip planes (typically
just 8), or for you to set up your scene graph so that each ClipNode
subgraph is placed in its own RenderStage - for this you'll need to
write a CullCallback.


On Sun, Sep 14, 2008 at 7:33 PM, Karl Karsten <kkarsten62 at yahoo.de> wrote:
> Hello,
> I am still a newbie and I am just coding around ClipNode Boxes. My intention
> is to have multiple ClipNode Boxes in a scene.
> I try to extend the osgclip example with a simple second box. Now my problem
> is that only the last ClipNodeBox will taken into account.
> Can have I have more than one ClipNodeBox  in a scene?
> If yes does anybody have an example code?
> Many thanks for a  help .
> Best regards
> Karl ...
> ...
> //Code from osgclip.cpp
>     osg::ClipNode* clipnode = new osg::ClipNode;
>     osg::BoundingSphere bs = subgraph->getBound();
>     bs.radius()*= 0.4f;
>     osg::BoundingBox bb;
>     bb.expandBy(bs);
>     clipnode->createClipBox(bb);
>     clipnode->setCullingActive(false);
>     transform->addChild(clipnode);
>     rootnode->addChild(transform);
>     // create clipped part.
>     osg::Group* clipped_subgraph = new osg::Group;
>     clipped_subgraph->setStateSet(clipnode->getStateSet());
>     clipped_subgraph->addChild(subgraph);
>     rootnode->addChild(clipped_subgraph);
> // My extension code for a 2nd ClipNodeBox
>     osg::ClipNode * clipNode2 = new osg::ClipNode;
>     clipNode2->createClipBox(osg::BoundingBox(-5, -5, -5, -3, 5, 5));
>     clipNode2->setCullingActive(false);
>     rootnode->addChild(clipNode2);
>     osg::Group* clipped_subgraph2 = new osg::Group;
>     clipped_subgraph2->setStateSet(clipNode2->getStateSet());
>     clipped_subgraph2->addChild(subgraph);
>     rootnode->addChild(clipped_subgraph2);
> ...
> __________________________________________________
> Do You Yahoo!?
> Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz
> gegen Massenmails.
> http://mail.yahoo.com
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

More information about the osg-users mailing list