Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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. alt text

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.

Product Version: UE 4.10
waterfoam.png (287.0 kB)
more ▼

asked Nov 20 '15 at 11:32 PM in Rendering

avatar image

89 22 22 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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!


Andrew Hurley

more ▼

answered Nov 25 '15 at 05:38 PM

avatar image EliasPa Nov 25 '15 at 09:12 PM

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:

alt text

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:

alt text

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:

alt text

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!

waterfoam.png (74.2 kB)
waterfoamfixed.png (46.6 kB)
avatar image EliasPa Nov 26 '15 at 03:37 PM

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!

avatar image AndrewHurley Nov 30 '15 at 04:23 PM

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! ;)


Andrew Hurley

avatar image EliasPa Nov 30 '15 at 08:24 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question