[osg-users] Clip planes and instanced rendering

Alberto Luaces aluaces at udc.es
Tue Apr 9 03:41:38 PDT 2019


Hi,

I want to set a clipping plane for my scene, but it is not working for
instanced geometries.  I have not found any resource telling that
clipping planes are ignored by GLSL.

Simple test: if I make the following modifications to osgforest,

diff --git a/examples/osgforest/osgforest.cpp b/examples/osgforest/osgforest.cpp
index 5f569de66..d5eb2c0a6 100644
--- a/examples/osgforest/osgforest.cpp
+++ b/examples/osgforest/osgforest.cpp
@@ -36,6 +36,7 @@
 #include <osg/TexEnv>
 #include <osg/VertexProgram>
 #include <osg/FragmentProgram>
+#include <osg/ClipNode>
 
 #include <osgDB/ReadFile>
 #include <osgDB/FileUtils>
@@ -1487,7 +1488,11 @@ int main( int argc, char **argv )
     viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
 
     // add model to viewer.
-    viewer.setSceneData( ttm->createScene(numTreesToCreate, maxNumTreesPerCell) );
+       osg::Node *ttmnode = ttm->createScene(numTreesToCreate, maxNumTreesPerCell);
+       osg::ClipNode *cn = new osg::ClipNode;
+       cn->addClipPlane(new osg::ClipPlane(0, osg::Vec4d(1, 0, 0, -500)));
+       cn->addChild(ttmnode);
+    viewer.setSceneData( cn );
 
 
     return viewer.run();

...the terrain and the trees are split by my additional clipping plane,
except when the trees are instances; in that case they are drawn as
normal.

How can I make clipping planes work for  instanced rendering?

Thanks!

-- 
Alberto



More information about the osg-users mailing list