Can't add depth and foam to my water help :(

So I’ve been learning the unity shader graph lately and decided to start with some water. The first water i did was okay, managed to do everything - depth, foam and all. But then i decided i wanted something more stylized. I followed various tutorials but nothing seems to work with the voronoi noise type of stylized water.
Here’s my water:

and here’s the shader (based in two of Gabriel Aguiar’s tutorials):

I tried to add this from the first more realistic shader I made, but no success:

And this one too:

I’m clearly missing something, but can’t manage to find out what, if I can get some help I would be grateful!

The version in which you use the scene depth node to compare against is the one that holds the most promise to get a usable foam mask. The other ones probably won’t work at all I think (last solution gives you a value describing how much aligned the vector from camera transform position to pixel world space position and the view vector of the camera are which… should be the same?)

Anyway, reasons why the foam setup using the scene depth node might node work:

  • is your shader rendering in transparent queue (depth buffer is only available for shaders in queue 2501 and above)?
  • are you generating a depth texture (in built pipeline a message is displayed in the camera inspector if you do, if not you can enable it with a script, in URP you enable it on the URP settings asset)

Apart from that I think you might be doing something wrong with position you compare against. Try to get a useful gradient out of scene depth before doing anything else.
You should either reconstruct the worldspace position from the depth buffer and work with normal worldspace position OR unnormalize the depth value from the multiplying it with the far clip plane because screen pos.w is world space depth…

1 Like

Thanks a lot for the tips man! I know I enabled depth texture in the built pipeline, but I see that I have a lot to study to solve this, I’ll try those things out :smiley: