DistanceToNearestSurface doesn't work correctly

Hello,

We are testing different approaches to blend static meshes with the terrain. Using RVT is problematic for us, since we run out of memory. Another option is to reuse the global mesh distance field. However after a lot of testing, I realised it’s actually not working in the shadows pass, which makes it unusable for WPO. For some reason, it’s also flickering on this simple test scene.

Do you plan improving support for this node? Or any other ideas how to blend meshes with the terrain via per vertex alpha?

Thanks,

Ivo

Steps to Reproduce
Open the attached project

Hello,

Thank you for reaching out.

I’ve been assigned this issue, and we will be looking into the behavior of the DistanceToNearestSurface Material Expression during shadow passes for you.

Hello,

Global Distance Field textures are not bound for VSM or cascade shadow passes. Sampling the Global Distance Field for the nearest surface will always return 0 in shadow passes.

We are looking into more blending options for you.

Hello,

Thank you for your patience as we continue looking into more blending options for you.

Hello,

So that we can better help you with the mesh blending, can you please clarify a few questions for us?

  1. Are you using this on a large-scale, or only on a few assets?
  2. You mention per-vertex alpha. Is the Material already translucent or masked for other reasons?
  3. Are you using this for meshes set at fixed heights relative to the ground (like grass)?

Hi,

  1. Yes, it’s large scale. From my tests, the global mesh distance field was kind of ok for distance. I mean, after certain distance, there is no global distance field and the deformation is disabled. That wasn’t very noticeable. But it’s a large scale map with many of these objects that must deform well around the camera.
  2. The per vertex alpha is used to control the amount of deformation, since some parts of the mesh are not deformed
  3. The meshes are terrain features like cliffs and craters

Hello,

Thank you for this information.

For your memory restrictions with RVTs, is adjusting the MIP bias and the pool size not able to address the issue?

Using WPO on large numbers of meshes can have performance implications, particularly with Nanite.

You could also try to make Global Distance Fields bound for shadow passes. As a starting point, please see “FProjectedShadowInfo::ModifyViewForShadow(…)” from ShadowDepthRendering.cpp and “FViewInfo::SetupGlobalDistanceFieldUniformBufferParameters(…)” from GlobalDistanceField.cpp. For engine modifications like this, we can offer information about existing functionality, and we leave the details of the implementation to you.

However, if you are primarily trying to blend the meshes with the landscape, and WPO is just a means to that end, you could consider other techniques. Another possible technique is to use a screen-space blend. This would not have the same level of accuracy as RVT, as it relies on screen-space information, and you would have to implement it yourself.

Please let us know if this helps.