Discard a geometry inside 4 points

20 views
Skip to first unread message

Daoudou Souffou

unread,
May 16, 2023, 8:04:17 AM5/16/23
to OpenSceneGraph Users
Hello everyone

I would need help.

I have a surface created with geometry and I would like to cut out part of the surface to place an object on it without the surface being inside the object (I have an open boat and the blue surface crosses the boat and is therefore visible inside). (see picture)

For this I have 4 corner points and I would like to delete the geometry and primitives located inside these 4 corners. (the white square on the image)

For this how could I proceed?

A solution would be to obtain the position of these 4 points in a shader and to delete the fragments inside with the "discrad" method in glsl if I'm not mistaken? (However I don't have enough knowledge with shaders ^^')

Or do you have any other suggestions?

i found this source : 

[osg-users] [osgOcean] Culling and intersects with ocean and model...

Thanks in advance
Cordially
Capture4.png

Chris Djali / AnyOldName3

unread,
May 16, 2023, 7:16:19 PM5/16/23
to OpenSceneGraph Users
Hi,

If you want to do it on the actual geometry, plenty of polygon triangulation libraries (e.g. earcut.hpp) let you specify holes. That's not something you want to do every frame, though, so if the boat moves, it's not suitable.

Another classic option for this kind of thing is to make use of the stencil buffer. I can't find a good guide on doing this for OpenGL (although a couple exist for Unity, and I've seen it in the wild), but the gist is that you draw some invisible geometry for the top deck of the boat (so something that ends up between the camera and all the bits of the lower deck you want to see, effectively forming a cap on the volume you'll cut out of the water) that has depth writes enabled and also writes a particular value to the stencil buffer. You then draw the lower decks with depth writes disabled and the depth test disabled, too, but the stencil test enabled so it only ends up in pixels your other mesh was drawn in. This can put some annoying restrictions on the geometry for your lower decks, though, as you need to make sure they draw okay with depth writes and the depth test disabled.

A potentially less restrictive option, if you can control, or at least test, whether the boat is drawn after the water, would be to either:
  • Guarantee the water is drawn before the boat. Right before drawing the boat, draw the upper deck cap mesh with depth writes on and the depth test off, but the depth set to a far value (it's better to do this by altering the vertex position in the vertex shader than altering the depth in the fragment shader as modern GPUs don't like doing the latter). This will cut a hole in the depth buffer representation of the water, so when you draw the boat normally, it'll be as if the water was never there.
  • Guarantee the boat is drawn before the water. Right after drawing the boat, draw an invisible upper deck cap mesh with depth writes and the depth test on as normal. This will mean there's something in the depth buffer preventing the water being drawn there.
  • Determine whether the boat or water is drawn first each frame, and pick one of the above as appropriate.
Hope this gives you some ideas.

Chris
Reply all
Reply to author
Forward
0 new messages