+1 vote

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.

depth mask example

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

in Engine by (330 points)

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.

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.

1 Answer

+1 vote
Best answer

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!!
by (3,936 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.