Water foam using distance fields

I’m trying to create water foam using distance fields. I’ve seen tons of people do it but for some reason I can’t replicate the result. What am I doing wrong?

Here are a few example of people that have done it:


When I try it this is the result I get

I made the area bigger so I can see the results more clearly and this is what I got


Messing around with the numbers yield even weirder results


This is what the distance to nearest surface node looks like when plugged directly into base color. Does this look correct to anyone?


Here’s a water shaderwhere I used Distance fields and flow maps for dynamic foam. It’s a bit messier than the ones you posted but I always have to play a bit with the numbers depending on how big my uvs/mesh are.

In your first screenshot the distance to nearest multiplier constant seems to be at 1, have you tried lowering it quite a bit? If I remember correctly I multiply with something like 0.01.

Thanks for the reply. I originally tried it at .05 and then went up and down by increments of .01 to see if changing the value worked but nothing did. It just got stranger and stranger.

Could you do me a favor and recreate the basic foam section of any of the materials I posted just to see if I’m the only one having this issue?

I just got my friend to recreate it and it worked for him. For some reason it wont work for me regardless of what version of the engine I try it in. I’m more confused now than I was before.

What type of hardware do you have? I’ve had issues on my older machine (around 8 year old AMD cpu/gpu) where distance fields didn’t seem to work properly on any UE version past 4.14

Did you enable Mesh Distant Field Generation in the project settings?

Of course. The effect im looking for does show up but only in between these weird black and white bands

I’m using a GTX 970, some 6 core i7, 32 gigs of ram. I think my friends graphics card is even older than mine but it works for him.

The node outputs a sign float value in centimeters, so when you plug you should see a gradient representing the outside of an object and the inside. The reason is that you can easily decide how to bias and clamp the values the way you want. If you look in the second link you provided in your 1st post, the step two is the correct way of do it indeed. The code you showed in the 3rd link is not like it.

As for the hardware, you are all OK, everything works with hardware half the potency you got.

The code from the 3rd link was from another foam material which also worked for my friend and not me. There seems to be something wrong with my version of the engine rather than something wrong with the code.

Just as an example of what I mean here are the results of the “correct” code.

Regardless of what I do I get these strange bands that move around as I move the camera. You can see that the proper foam effect is there and working, though very sloppy, but these bands also exist. This happens regardless of what version of the material I use.

Would it be too much trouble to see the code for your material? I’m curious to see if this will happen with that one too. It might be something wrong with the distance to nearest surface node.

I have replicated exactly same thing, just it is my map instead, all worked. I have put the project inside google drive, so pick it up and check: https://drive.google.com/file/d/1wy6…ew?usp=sharing

Even if you change the dimension for the water plane to 1000, there are no weird bands. Maybe the issue is with the plane mesh you are using, not sure.

I’ll do a video tutorial on how I did this:


I just reinstalled the engine and all the versions of it I had. It works in my actual game project but not in the one I use to test stuff in before it gets added to the game. I also tested in other projects I have and have gotten various results from the same banding I currently have to just a solid black or white material. Which project it works in seems to be completely random as 2 projects made in the same version of the engine present 2 different results.

@NilsonLima The banding happens across mulitple meshes so I don’t think thats the issue. I’ve also tested it using the ue4 primitives and that gives me the same results.

This is one of the things that I really hate about game development. Things can just stop working for no reason. It currently works in my actual game project but how long before it randomly doesn’t?

Did the project I posted work at least?
Also there is a way to visualize the distant fields in the viewport: click on top of viewport, Show->Visualize->Mesh Distance Field, and the screen will show how the meshes distance field will look like. If this does not work and all are the same, the only thing that remains that I know is that Distance Fields are disabled at Low and Mid scalability settings, it will only work starting on High settings.

I would not say that in game developments things just stop working, this is accurate. What we can assure right now, is that there is something different between setups that we didn’t catch yet.

Here she blows or something:

Slightly unrelated question but is there a way to disable distance fields for a specific mesh in the environment?

Not really. Theoretically with project settings disabled and on mesh editor enabling mesh distance fields for that specific mesh should work, but doesnt. The only way, not a perfect one, is to use the mesh instance position and the mesh bounds multiplied by its scale, to create a sphere mask or box mask and cut it out of the result, at least the cost is quite cheap.

IIRC,Set Distance field resolution scale to 0 works for me in earlier version.

Is that a global setting that applies to all instances of whatever mesh you set it for or can be 2 instances of the same mesh have different DF settings?

I ask because I created a really cool effect for water flowing past rocks as a backup effect if I couldn’t get distance fields to work. I’d like to combine the 2 effects so that Distance fields are used for landscapes, large objects such as rocks, and the player (I don’t think skeletal meshes even have distance fields so that might not even be possible) and then a custom effect for other objects.

It’s a global setting for the mesh,but you can duplicate the mesh since it’s not costly.And skeletal meshes don’t have distance field yet.Once I used a masked cylinder mesh instead in the player BP for interactive grass.