hi,robert: I think I can use shader to achieve my goal:clipping child nodes
without these limitations.Am i right?------------------ Original
------------------
From: "Robert Osfield"<[email protected]>
Date: Thu, Jun 12, 2014 10:44 PM
To: "OpenSceneGraph Users"<[email protected]>;
Subject: Re: [osg-users] a bug with clipnode?
HI Wu,
ClipNode has limitations because it controls position state - OpenGL
state that has to be applied with a specific modelview matrix that
gets encoded when that attribute is applied. This means that you
can't just apply positional state at any time as it's value would be
affected by rendering order/culling etc. The way the OSG avoids these
issues is my applying positional state along with it's specific
modelview matrix at the start of each RenderingStage and that
particular state is then valid for the whole stage, but also you can't
have multiple instances of that state applied otherwise you'd get
clipplanes trying to be in multiple places at once. In the case of
ClipNode it's the mechanism that allows the OSG to know which
modelview matrix to use when applying the ClipPlane associated with
it.
While this approach solves the issue of needing a reliable way to
place positional state it does mean that you can only have one
position in space for each positional state attribute per
RenderingStage. My guess is that you are expecting ClipPlanes to work
like non positional OpenGL state and can apply it multiple times by
applying above different subgraphs, this however won't work one will
take precidence.
Robert.
On 12 June 2014 11:25, ttaw <[email protected]> wrote:
> Hi, everyone:
> In my opinion, the clip effect of a clipnode only affects its child
> nodes, and a new clipnode only uses its own clipplanes. But the fact seems
> different from this. In the following project, a clipnode with a cow is
> added to two parents, but only one cow is shown. How can I get two clipped
> cows in result in the following code?
>
>
> osg::Node* decorate_with_clip_node(osg::Node* node)
> {
> osg::Group* rootnode = new osg::Group;
> osg::ClipNode* clipped_subgraph = new osg::ClipNode;
> osg::BoundingSphere bs = node->getBound();
> bs.radius()*= 0.4f;
> osg::BoundingBox bb;
> bb.expandBy(bs);
> clipped_subgraph->createClipBox(bb);
> clipped_subgraph->addChild(node);
> osg::MatrixTransform *mt1 = new osg::MatrixTransform;
> mt1->addChild(clipped_subgraph);
> osg::MatrixTransform *mt2 = new osg::MatrixTransform;
> osg::Matrixd mat;
> mat.makeTranslate(bs.radius()*2, bs.radius()*2, bs.radius()*2);
> mt2->setMatrix(mat);
> mt2->addChild(clipped_subgraph);
> rootnode->addChild(mt1);
> rootnode->addChild(mt2);
> return rootnode;
> }
>
> int main( int argc, char **argv )
> {
> // use an ArgumentParser object to manage the program arguments.
> // load the nodes from the commandline arguments.
> osg::Node* loadedModel = osgDB::readNodeFile("cow.osgt");
>
> if (!loadedModel)
> {
> osg::notify(osg::NOTICE)<<"Please specifiy a filename and the
> command line"<<std::endl;
> return 1;
> }
>
> // decorate the scenegraph with a clip node.
> osg::Node* rootnode = decorate_with_clip_node(loadedModel);
>
> // run optimization over the scene graph
> osgUtil::Optimizer optimzer;
> optimzer.optimize(rootnode);
>
> osgViewer::Viewer viewer;
>
> // set the scene to render
> viewer.setSceneData(rootnode);
> return viewer.run();
> }
>
> ------------------
> Failure is the mother of success.
> Wu Zhicheng
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
._______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org