OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Clip planes and instanced rendering


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Alberto Luaces
Guest





PostPosted: Tue Apr 09, 2019 10:43 am    Post subject:
Clip planes and instanced rendering
Reply with quote

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



------------------
Post generated by Mail2Forum
Back to top
Wojtek
User


Joined: 02 Nov 2011
Posts: 91

PostPosted: Tue Apr 09, 2019 11:25 am    Post subject:
Clip planes and instanced rendering
Reply with quote

Hi Alberto,

You may need to add support for clip planes via gl_ClipVertex or gl_ClipDistance to your shaders (which one depends on GLSL version used -see https://stackoverflow.com/questions/19125628/how-does-gl-clipvertex-work-relative-to-gl-clipdistance). My experience with these vars was not always positive, though. I remember times when I was unable to use them and once had to do my own cliping in vertex shader (=major PITA). But maybe these days newer drivers or OSG version make it easier.


Cheers,
WL


wt., 9 kwi 2019 o 12:41 Alberto Luaces < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> napisał(a):

Quote:
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

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Alberto Luaces
Guest





PostPosted: Tue Apr 09, 2019 2:06 pm    Post subject:
Clip planes and instanced rendering
Reply with quote

Wojciech Lewandowski writes:

Quote:
Hi Alberto,

You may need to add support for clip planes via gl_ClipVertex or gl_ClipDistance to your shaders (which one depends on GLSL version used -see
https://stackoverflow.com/questions/19125628/how-does-gl-clipvertex-work-relative-to-gl-clipdistance). My experience with these vars was not always positive, though. I remember times when I was unable to use
them and once had to do my own cliping in vertex shader (=major PITA). But maybe these days newer drivers or OSG version make it easier.

Hi, Wojciech, many thanks! Following your pointer about gl_ClipDistance
I made this work. Nevertheless I take your advice on not relying too
much in this feature for compatibility reasons :-)

--
Alberto



------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts two pass rendering without enhancing ... Trajce Nikolov NICK General 2 Tue Jul 02, 2019 9:58 am View latest post
No new posts Rendering a Depthmap lucasamparo General 2 Tue Jun 04, 2019 6:27 pm View latest post
No new posts Layered rendering with a geometry shader AnyOldName3 General 8 Tue May 14, 2019 11:25 pm View latest post
No new posts off screen rendering with OSG Sorin General 0 Mon May 13, 2019 8:14 am View latest post
No new posts Volume Rendering and Depth Buffer AnnieOwl General 5 Fri Apr 12, 2019 5:20 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP