Page 1 of 1

Cut out water at intersection with ship

Posted: Wed Apr 13, 2011 9:39 pm
by elvman
I would like to hear your thoughts about the following problem:
I want to not render water inside of a ship. The water is not a plane, it can have waves. Here is the image of what I mean:
Image

I have searched all over the internet and thought about this problem for many hours, but haven't found solution that works in Irrlicht.

The methods I can think of are:
1. Some kind of scissor cut (available in Direct3D, but not available in Irrlicht)
2. Use stencil buffer, but it is not available in Irrlicht and it doesn't fully solve the provblem
3. Render ship from below in a Render target and then in a shader set pixels intersecting the ship to invisible (alpha 0). But that doesn't solve my problem too, because rendering from below, I don't know where the water intersects with the ship (because of waves)

Posted: Thu Apr 14, 2011 1:20 am
by Iyad
This problem seems really hard to solve. If I was you, I would try to hack this; the solutions that comes to my mind right now :
-Dont let the camera see what is inside the boat.
-If the camera enter or sees what is in the boat, move the boat up on the z axis.
-Make the boat model much more larger and add a floor on top of the water waves.

Posted: Thu Apr 14, 2011 7:53 am
by hybrid
Fill the ship with an invisible z-buffer-writing component or use clip planes (is it that you meant by scissor cuts?)
If you need to render using stencil buffer we could arrange for some flags to configure this in the video driver. Just tell me which way you'd like to access the stencil buffer. But I doubt that it would work here.

Posted: Thu Apr 14, 2011 8:06 am
by CuteAlien
I think with the invisible z-buffer-writing he also wouldn't see the floor of the ship anymore. Clearing the z-buffer after rendering the water and rendering the ship afterward might work while inside. But then it fails when the camera is outside. Can't think right now of a solution which works in both cases - so maybe the camera-position needs to be checked first.

Posted: Thu Apr 14, 2011 8:33 am
by hybrid
Wouldn't it work by fixing the render order then? Ship->z-block->water

Posted: Thu Apr 14, 2011 10:13 am
by CuteAlien
hybrid wrote:Wouldn't it work by fixing the render order then? Ship->z-block->water
Hm, yeah - without z-buffer reset. Could that be done currently? I think transparent would be rendered after normal already, so using 2 SceneManagers, putting Ship+z-Block in the first and putting the water in the second SceneManager could be a way to do this I guess.

Posted: Thu Apr 14, 2011 2:52 pm
by nespa
1st, render to target without water;
2nd, render with water, but change the inner pixels with the same pixels saved at the 1st pass in the render target;

Posted: Thu Apr 14, 2011 3:32 pm
by elvman
nespa wrote:1st, render to target without water;
2nd, render with water, but change the inner pixels with the same pixels saved at the 1st pass in the render target;
The problem is that Render Target Textures can not be Multisampled so the ship would not be antialiased.

Posted: Thu Apr 14, 2011 4:03 pm
by hendu
elvman wrote: The problem is that you Render Target Textures can not be Multisampled so the ship would not be antialiased.
Whose limitation is that? Irrlicht, DX9 or something else?

I certainly remember reading how that's been supported in opengl for years...

edit: http://www.opengl.org/registry/specs/EX ... sample.txt
In core 3.0, extension before that.

Posted: Thu Apr 14, 2011 7:10 pm
by Auradrummer
Everyone is giving oppinion, I'll give mine:

I had this problem once, when rendering in a professional program. I made a transparency texture with the form of the boat moving together the boat and projected on the water.

I think that can be solved by a simple shader...

The masters here can do it, sure.