Water shader

Shader for the water in the sea surrounding the island, and in smaller water ponds.

Deep water is not accessible by the player (they can’t swim), but we can consider shallow ponds in which they can walk.

Needs support for water moving up and down, and some kind of foam (that can be turned off for ponds?).

Even though it would still be toon-like, it can be a different shader than the one used for toon objects. For instance, it doesn’t need to support additional lights, baking, etc.

Hello @cirocontinisio , I made a basic cartoon water shader. Will something like this work?

6478088--727556--Cartoon Water UOP1.gif
Here is a view of the shader graph;


The Base Color, Opaqueness, Ripple Speed, Ripple Density, Ripple Slimness, Ripple Color, Wave Speed, and Wave Height are adjustable.

If this is fine I can make a PR. However, I didn’t add any foam effect. Since I’m still new to shader graphs, left it out for someone else.

I made this by following a tutorial by Brakyes:

6478088--727556--Cartoon Water UOP1.gif

2 Likes

Looks good! I would just add one thing to make it more cartoon: a Step node just after the Power node?

That’s perfectly fine. Maybe somebody will pick up the challenge :slight_smile:

Please try playing with the Step node, and then make a PR on the ‘art-assets’ branch. Thanks!

1 Like

Thankyou @cirocontinisio for the feedback!
I was wondering how to sharpen the ripple edges but didn’t know which node to use. Following your advice, I added the step node and it certainly enhanced the toon effect! Here’s how it looks now;
6479540--727814--modified toon water.gif

Here is the modified shader graph

I have made a PR: Water shader v1 by Dickmendra · Pull Request #137 · UnityTechnologies/open-project-1 · GitHub

I’m eagerly waiting for someone to work on the foam effect and tell us how they did it. Once again this project is a great learning experience. Thank you! :slight_smile:

4 Likes

You killed the cells a little bit though, now they don’t connect anymore! I think playing with the Power values before you “step” it, it should bring the values back. It’s an act of balance :slight_smile:
Looks good already though!

For the foam, I think you can take out the learning from this Brackeys tutorial about how to use the depth node:

It’s the same concept he uses to make the side of the barrier that glows at the intersection with the wall.

1 Like

Hello @cirocontinisio and all,

What about a mix toon/realistic water shader? It seems aligned with the detailed rocks textures or the characters small details.

I did some tests based on this tutorial:

What do you think about this result?

6480916--728101--water_shader.gif

3 Likes

Hey @dickmendra , nice impovement, thanks for sharing! I haven’t played around with Shader Graph much (I was just passing by this thread) but I happened to stumble across this link which might be useful as it explains the process of adding foam lines, following as it seems a similar approach to the Brackey’s video above. It also explains how to add refraction and interactivity to the water and even shares the Shader Graph file. Here is also the video I got the link from:

Seem like pretty interesting examples to learn and try different approaches should you wish to explore more. And she has made a good amount of other interesting tutorials too :slight_smile:

@treivize seems like we posted simultaneously. Nice work! I like the color gradience between the deep and the shallow waters and I think it would be nice to have refraction indeed. I like the movement as well, although for now it resembles more that of a river. Would you be interested in trying to figure out a more palindromic movement for the beach shore? (thanks for sharing the tutorial video)

2 Likes

Hi @itsLevi0sa ,
Thanks for you feedback, I had the same feeling as you regarding the river movement. It was too late yesterday to find out where to inject the Sine function :slight_smile:

I found it this morning. Here is how it looks like now. Lots of things could be still improved. I do not know if vertex displacement is a requirement or not, currently the movement is simulate by color distortion the geometry is still perfectly flat.

Another source of inspiration for water shader comes from this shader example (implemented UE4 ;))

Updated version with a periodic movement:
6481759--728200--water_shader_2.gif

3 Likes

The whole shader looks great, @treivize !

I also merged the PR that @dickmendra made earlier today, but by his own admission that’s as far as he could go, so it would be great to integrate the stuff you are making into it / with it.

A couple of suggestions:

  • I think it would be better if the shader was Unlit. This means that for it to pick-up shadows, you need to use the same custom HLSL currently used in the Toon shader. Would you be able to do that?
  • The sine wave looks ok, but the back and forth is really visible. What about having it go up and down instead? It might mean modulating the noise, or offsetting it, by the value of Sin(time). This way you would have a foam on the shoreline that doesn’t move, but instead forms and dissolves all the time in a noise pattern, while not going anywhere.

Looks good though! Once we have this integration it might be time to open a PR.

2 Likes

I have updated my PR following your suggestions.

I have struggled a bit to merge both shaders, but at the end, I kept the vertex displacement and move for unlit master shader.

Again here is the result after the latest changes:
6484673--728735--water_shader_3.gif

3 Likes

Hello @cirocontinisio ,

I guess you do not have time to local pull all the PR to review them, so here are some details about the shader from Shader Graph:

A new Sub Shader (Shaders/SubGraphs/WaterNoise) has been added to handle the water noisy movement used in refraction and in foam simulation.


As suggested, it is based on offsetting + lerp over time.

Wave is based on vertex displacement and I reuse the graph of @dickmendra as it is:

Based on the design from the tutorial attached earlier in this thread (Water refraction, Water Depth Fade and Water Foam sections) using the water noisy movement sub graph and depth fade sub graph.

Toon Shader Custom Shadow computation integration (might be useful to extract it into a Sub Graph instead of copy/pasting it, what do you think?)

2 Likes

Oh! I’ve missed so much of the discussion.

Thank you @cirocontinisio for the feedback!

Yes, you are correct. I might have overplayed with the value trying to make it look good :sweat_smile: Also thanks for sharing the foam tutorial I’ll try to learn from it.:slight_smile:

Hey @itsLevi0sa thank you for the feedback! I’ll certainly watch the tutorial you shared, there seems to be a lot to learn:)

Wow I think this looks great! It even has shoreline foam. With all the tweaks everyone has suggested this will be the perfect water shader for this game.

Great work @treivize I’m in love with this final result! Thank you for sharing the shader graphs and explaining them.

Yes absolutely! I only started on this because it seemed that no one else was working on it and personally to gather some experience in the shader graph. Now that @treivize has done some amazing work, I am more than happy to step aside and learn:)

All in all, this is a great learning experience, Thank you!

2 Likes

Hi,

Playing with the shader, I noticed glitch effect where the water surface becomes far from the camera. So I was thinking about introducing a fading effect on the foam/refraction/wave to nullify them for far water.

Yes, it’s a great idea and I noticed it too from previous screenshots. Great idea!

And by the way, it’s coming out fantastic!

1 Like

Hi @cirocontinisio ,

I am glad you are happy with it. Everything is pushed in my current PR, with some extra shader properties to fine tune the shadow and global illumination.

I am currently looking at the wind effect for the toon shader and I came across this article in unity blog:

There are also detailed explanations to achieve gerstner wave simulation:


I was wondering if it would be required for open water part of the level design? The current shader looks suitable for calm sea, water pound or swamps, but if open sea with true waves are needed, I can try to integrate something like the result above.

Hehe, I remember that blog post, John was an intern in our team when he wrote it!

Feel free to enhance it with better waves. Just maybe don’t spend waaaay too much time on it, since for the sea we mostly see it in one scene only. (although we might have other smaller and less important Beach scenes, just to bring the protagonist back down to the water)

Hi @cirocontinisio ,

Indeed, adding such waves is complexifying a lot the shader. I will focus on other tasks (shader/coding/modeling) from now. Maybe later someone else or myself will add new stuff based on the real needs of the scene composition where water is needed.

My PR is ready to be reviewed!

1 Like

I have found this video that talks about how Nintendo approached water in SMG2. I fount it interesting, but since I’m pretty much a noob when it comes to these things, I don’t know how much of the stuff he says is actually useful or isn’t. I hope this helps!

2 Likes

Hmm, I’m pulling your branch and a first attempt just gives me a flat plane with none of the effects… need to investigate further :eyes:

Maybe jumping from branch to branch in Git has broken something internally. I will do a full reimport as a first step.

EDIT: Nope, nevermind, it was a matter of parameters. I think the fading was too low, and so the whole effect was faded away even if I was looking at the water from very close.

My first perception is that we need a lot of sliders in the Material inspector, to make sure people select the right values and can’t “break” the shader while trying to configure it.

Wow, the shader looks great! I left a few comments on the PR regarding some tweaks that it would be great to do before merging, although if you’re super busy they can also be done later on (or by somebody else).

I’ll repost them here:

  • One thing that would be great to fix is to make sure that planes put next to each other displace at the same rate, so that their edges match. Is that possible, or does it depend on geometry, size and position of the object?
    You can see what I mean in the image below:

  • I think it would be better to have only one displacement effect. Right now, the displacement is transparent and overlaid on top of the regular geometry render. This creates a ghosting effect that makes it a bit confusing.
    In other words, even if the shader/material is in the transparent queue, it should completely covers the pixels of the existing geometry.

  • And finally as mentioned before, it would be great to have sliders that limit the values within reasonable ones, so you can’t break the shader involuntarily while tweaking it.
2 Likes