Strange results with distanceToNearestSurface


I am trying to make a coastline.
It is all nice so far, but now I am attempting to make foam at the edges, where the water hits the ground or a mesh.
That should work with the distanceToNearestSurface-Node. I generated a material to see, how it works. Look screenshot.
I assume, that the distance fields provide values between 0 and 1.

It worked almost, only two problems (see screenshot).

  1. the distance fields around meshes are very sharp, whilst the edges of the landscape is smooth and nice.
  2. When the camera moves, there are strange fields appearing and hiding on the ‘water’

In the mesh-settings, I tried different settings for the ‘distance field resolution scale’, without any effect.

Does anyone have any idea, how to achieve a map, which indicates distance to the nearest surface?

DistanceToNearestSurface gives world space units, not [0-1].

There’s definitely some weird stuff going on there. Use the Show->Visualize->Mesh Distance fields to see which mesh is causing the problem. Maybe your skybox is affecting the distance field or something. And of course you need to have the GenerateMeshDistanceFields rendering project setting enabled.

Here’s what it’s supposed to look like:


The material just did DistanceToNearestSurface / MaxDistance. Be sure to disable bAffectsDistanceFieldLighting on the water surface itself.

btw in your material screenshot you are multiplying the distance by 0 with the stretch parameter

Thank you for your reply,

the multiplication by zero should be no problem, as I made an instance from the material, where I tweak that parameter.
GenerateMeshDistanceFields rendering project setting is set.

I can imagine, that your idea with the skybox is right, because that part is at the very edge of the landscape, where the skybox may affect it.
But I need to have three questions answered. please:

  • How do I disable bAffectsDistanceFieldLighting on the water surface?
  • How do I disable distance Field for an object?
  • When are the distance fields being rendered? Immediately, when I change an object?

Have a look at the screenshot for the distance fields.

Kind Regards

That setting is on meshes called “Affect Distance Field Lighting”

Changing the setting should cause it to rebuild the global DF texture right away.

Thank you for that info,

when I swtch off the option ‘affect distance field’ for the waterplane, nothing changes.
when I switch off that option for the meshes, the distance-field is gone immediately - as expected. But the black areas are still appearing.

In my research I looked for visualizations and found, that in the ‘distance field ambient occlusion’ there are dark areas visible, exactly where the black areas in the lit version are. (See screenshot).
Did I mention, that the dark areas are changing, when I move the camera?
Maybe that helps finding a conclusion.

Kind regards

P.S.: DanielW said, he used DistanceToNearestSurface / MaxDistance. I can’t find information about that MaxDistance. Where should I look for it?