Several clipping planes

76 views
Skip to first unread message

Claudio Benghi

unread,
Feb 3, 2021, 12:17:31 PM2/3/21
to OpenSceneGraph Users
Hello all,

My first post on the new forum, thanks for accepting my request, and for the amazing work on OSG over the years.

I intend to use OSG to display the construction sequence of a building site.
Some elements will just appear at a given frame (that's easy), but others I'd like to appear progressively.

I don't mean that they will "move" to their destination, but rather, that they will be partially visible in their final position as if being partially clipped, until they are entirely visible:

Clipping.svg.png

Since timing will be different for each object, a few clipping planes would not be enough. 

From what I read, it should be possible to use the fragment shader to cut elements fairly arbitrarily. 

I've got a couple of questions:

1) Is it possible to use fragment shaders to cut objects at a custom distance from a shared reference plane (the distance should be independent for each object, see hA and hB in the image above)?

2) What path would you suggest me to attempt? Is gl_ClipDistance the right way to go?
Am I completely wrong thinking of something like:

gl_ClipDistance[0] = dot(u_plane0,vsPos) + CustomObjectH;

3) Is the StateSet of an object the right way to pass (and update) a custom variable for the fragment shader (i.e. the distance from the reference plane)?

Many thanks,
Claudio

Robert Osfield

unread,
Feb 4, 2021, 7:40:27 AM2/4/21
to OpenSceneGraph Users, OpenSceneGraph Users
Hi Claudio,

Welcome to the OSG community. For your first post you sure are diving into an advanced topic :-)

Conventionally one would do clipping using gl_ClipPlane, this is set by osg::ClipPlane state attribute and osg::ClipNode to place one or more ClipPlane in a final position in space,  I think OpenGL implementations provide at least 6 clip planes, but It's while since I've head my head deep in OpenGL as I'm mostly working with Vulkan these days.  There is a hard limit though that is driver/hardware dependent.  This type of clipping gets applied during the traseration step just prior to the fragment shader.  It can be used with fixed function and shader pipelines.

From your description it sounds like something custom will be best, which in essence would be to use a fragment shader test to discard/fade out fragments based on some combination of uniform or vertex attribute settings.

Is the clipping always going to base on a horizontal plane?  If so then you just need to encode the height to clip at for each object via a uniform or more efficiently with a vertex attribute bound with BIND_OVERALL.  Uniforms have a higher overhead than vertex attributes in OSG/OpenGL so general best used for rarely changing values, with values that change with high frequency i.e. different for each object using vertex attributes will be more efficient.

Cheers,
Robert.

Claudio Benghi

unread,
Feb 10, 2021, 4:11:18 AM2/10/21
to OpenSceneGraph Users
Thanks Robert,

apologies for the long delay, It's taking me a lot of studying to understand shaders uniforms and attributes, 
so I'm responding to your question as I go on reading and testing.

> Is the clipping always going to base on a horizontal plane?  

Unfortunately no. While this will be the case in 90% of the models, I need to have a more flexible API,
so I'm thinking to have uniforms to store reference planes (which will rarely or never change) and some method
(uniform or attribute) to pass the clipping distance for the relevant primitives.

Are there benefits in moving the objects that need clipping under a different group? They will always be a minority of the model geometry.

Thanks,
Claudio
Reply all
Reply to author
Forward
0 new messages