What To Do About Water

Recently I’ve been working on water, and the shaders and physics that go along with moving a character through it. Turns out writing a basic water shader and applying it to a plane is fairly simple. I followed a very well-made tutorial on Youtube which I’ll embed below. If you need a one-stop channel that will cover all your Godot specific needs I’d highly recommend GDQuest.

So, once you finish with the tutorial you’ll have a very nice floating body of water with some smooth waves and pleasant reflections. Well, it’s not quite a “body” of water yet.

Now what?

Since our water is just an undulating plane, we’ll need to think about how to implement and consider a few design decisions. For a more fully-realized body of water we’ll first look at lighting. We’ll need to look at two cases: how far down the player sees when looking into the water, and what the player sees when the camera is submerged in water. For the first case you’ll need to look no further than the GDQuest tutorial above. For the second case we’ll need to apply a shader to the entire viewport of our scene. Your scene tree will have this basic structure: your root node will have a ViewportContainer, which will contain a viewport, and that viewport will house everything else. Then all we need to do is apply a ShaderMaterial to the ViewportContainer and attach a script to that. In this case I use an Area node for our body of water, and if the camera is detected entering that body it supplies a boolean value to the shader to change the color of the screen texture in our viewport.

Things now look a bit darker underwater, but I’ll need to add some more convincing effects.

There’s still more work to be done of course. Underwater physics and (hopefully decent) character controller coming soon.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.