How to hide the water plane inside a boat

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MagnusS

Hello together,

I am planning on creating a game that takes place mainly on the water and in 3D. I was hoping to add interiors below sea level to the boats in this game. The problem is that the water plane would be rendered inside the boat when viewed from above.

To solve this it would be really awesome to have the ability to set some transparent plane that stops the water from being rendered. Unity achieves this by using something called a depth mask.

Now that I’ve layed out my problem lets come to my question(s). I hope it’s ok to ask all of them in ne question as they’re basically all the same question.

  • Is it possible to achieve something like this in godot
  • If it’s not possible how would I achieve my goal (interior without water) in Godot

Here are some alternatives that might achieve the same effect

  • Use a water-plane with a ship sized hole (not so good with multiple ships and ship sizes)
  • Render the interior via render-to-texture everywhere it should be visible (expensive)

Thanks in advance
Magnus

  1. Draw the boat
  2. Draw whatever is inside the boat (passengers…)
  3. Draw a mesh hull enclosing the boat, but only write it to the depth buffer, no color (not even transparency because that would break draw order)
  4. Draw the sea: due to 3), it won’t overlap with the inside of the boat’s hull.

Now I wonder if step 3) is possible to do in Godot… if not, it could be a feature request. We would need a depth_only shader render mode.

Zylann | 2018-05-15 12:58

Yeah I was trying something like that the other day. Didn’t work out. But then I realized a project setting called depth pre-pass. With that on, the depth buffer is written before any color is written. I wonder what happens if I disable that?

Edit:
Well that didn’t work out either. I guess it’s not a feature yet. I second what Zylann said. If you really want it, make a feature request.

SIsilicon | 2018-05-15 15:04

:bust_in_silhouette: Reply From: SIsilicon

I figured it out!!

The water plane will have to be considered transparent for this to work though.

  • First you must have two versions of the boat mesh. The original one, and the other being a hull of the other.
  • Make the hull a child of the original mesh.
  • Then give the hull mesh a ShaderMaterial with the following shader code.
    shader_type spatial;
    render_mode unshaded;
    
    void fragment() {
        ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
    }
  • Set the refraction to enabled, and set the refraction scale to 0.
  • ???
  • Profit!!

How can I set the refraction enabled in the ShaderMaterial? It’s only available on SpatialMaterial.

cucaido | 2020-06-13 16:26