Cut out water at intersection with ship

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Cut out water at intersection with ship

Post 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)
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Post 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.
#include <Iyad.h>
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Wouldn't it work by fixing the render order then? Ship->z-block->water
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Post 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;
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post 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.
Last edited by elvman on Thu Apr 14, 2011 6:24 pm, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post 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.
Last edited by hendu on Fri Apr 15, 2011 11:06 am, edited 1 time in total.
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post 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.
Professional Software Developer and Amateur Game Designer ;-)
Post Reply