Water foam using distance fields

I’m having trouble getting my water foam to work. I planned on using distance fields to create foam for my water but I get a very strange result. The lines look blocky which could just be a quality setting I need to change but there is also this large white square that appears if I get too close to my water making the entire surface white.

In the screen shot below I have a plane with the foam material on it and as you can see the white square is appearing. The material is displayed at the bottom. Can someone explain what I am doing wrong.

I added more planes just so I could see the effect over a larger area and it seem as if there is a large square that follows the camera. I’ve taken a screen shot of the corner of it. I’ve also noticed other strange behavior with the material. I made a change to a parameter that wasn’t even hooked up to anything and the whole material went white. I am really confused.

I’m not sure how to advise on using distance fields, but have you considered using the Depth Fade node in your material instead? Depth Fade returns 0 where two surfaces intersect and “fades” to 1 as the surfaces get further and further apart. You can use this to drive a Lerp between two values or just as an input to some other logic. It’s very useful for shoreline effects or force fields that get more intense as they get closer to the ground, as just two examples. It only works with translucent materials, though.

Thats my backup if this doesn’t work. Currently my material isn’t translucent and changing that would change the look of the game so I’m holding off on that. Thanks for the suggestion.

If I play with the numbers a bit more weird things start to happen.

This is what the “distance to nearest surface” node looks like plugged directly into base color.

Still no clue what is causing this strange behavior.
There is more info about it here if anyone is interested.
https://forums.unrealengine.com/development-discussion/rendering/1437124-water-foam-using-distance-fields

If anyone else has this issue just migrate your stuff over to a fresh project in the newest version of the engine and it should fix it.