Dynamicly working water foam texture material

Hi guys!

I want to make water with a foam texture around its edges and I would like it to be dynamically changing with the environment, not necessarily with any other actor like the player character. I’ve been trying to figure this out for quite a while now and I’ve tried doing it with the depthfade node without any success.

This looks like a promising start but it might just look like it. The depthfade affects the z direction also, which is something I don’t need.

I was wondering if there was maybe a way to make the depthfade only in x and y directions and somehow use it as a mask to then apply some textures on to? There’s probably a better way to do it though, thanks for any help.

Hello EliasPa,

So essentially what you want to do is take the Depth Fade you are using to create the waters edge, and Lerp your foam into the Alpha of the channel of the Lerp to create the edge foam look you are going for. There are a lot of different ways to do this, and there is a community project as a work in progress that implements a lot of commonly requested water features that add to its realism.

You can download this project and reverse engineer their Materials to get a better understanding of how to create a realistic and dynamic water shader. I will warn you, some of the things they are doing are fairly advanced, so take your time when going through it.

Ocean Shader [WIP]

If you have questions, DotCam and the others who contributed to the shader are more than willing to help. They are great community members and have provided this as a free open source project to help anyone who is interested. Let me know if you have questions!

Cheers,

Hey Andrew!
Thank you for answering the question. I checked the forum post and saw some amazing things but I’m not sure if that’s what I’m looking for. This is basically the result I would like to get:

The white on the edges would be the “foam” and it really doesn’t have to be realistic. It would be great if the foam was rounded in the corners as well, but that’s not necessary. The foam could also just be around the edges (and not offset from the walls like in the picture, which I think would mean a little bit of extra work?).
I played around with the depth fade and I noticed that the opacity it gives depends on the cameras location, so unwanted effects occur when looking at corners:

As you can see the “foam” disappears in the corners ( the distance between the water face and the surface below is too great?) and I think i noticed this happening in the forum posts water foam which is fine but not exactly what I’m going for. Just to clarify, here’s how I’d like it to be:

Please excuse the quality of my pictures:D.
Do you happen to know if there’s something for me in that post or do you have other ideas? Thank you!

I’ve now started thinking if depth fade is even capable of doing such a thing? Could I maybe cast some rays from certain points of the water plane in x and y directions and then check if the cast hit a wall (if this method is possible, maybe it would be easier to offset the foam in this way?) and then somehow use that in defining the place of the foam? I really have no idea if that could even be done or how since I’m pretty bad at this stuff. Thanks!

Honestly, I wish my knowledge on this topic was greater, and you might have luck with the approach I mentioned earlier where you Lerp the Alpha of your depth fade where the edges are defined around your objects, with the foams diffuse color.

You can increase the depth fade amount, and then change the tiling of your foam so it looks a bit more random.

To be honest, if you were going to run line traces and attempt to detect where the foam should be applied, that could become very very costly as far as performance. Especially if you are updating this every frame.

Hopefully you can find a good solution, as this is possible and will require some further digging. As a hint, there is a pack on the Marketplace called Procedural Nature Pack Vol. 1, and he has a river shader that does almost exactly what you are looking for! :wink:

Cheers,

Yea that’s what I was thinking too, thank you so much Andrew!