Re: [osg-users] Several clipping planes

2021-02-10 Thread Claudio Benghi
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

On Thursday, 4 February 2021 at 13:40:27 UTC+1 robert@gmail.com wrote:

> 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osg-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osg-users/18d25f40-3a7f-4c24-9115-b140d5fe490dn%40googlegroups.com.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Several clipping planes

2021-02-04 Thread Robert Osfield
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.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Several clipping planes

2021-02-03 Thread Claudio Benghi
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:

[image: 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

-- 
You received this message because you are subscribed to the Google Groups 
"OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osg-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osg-users/9173059e-957c-471c-a71b-f0dd52a1afb0n%40googlegroups.com.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org