Error distance field generated when using two-sided material

Error distance field generated when using two-sided material

重现步骤
1.Open Modeling Mode, create a box.

[Image Removed]

2.Create a Two-Sided material

[Image Removed]

3.Open StaticMesh Editor, give the Two-Sided material to the box

[Image Removed]

4.Show Mesh DistanceFields

[Image Removed]

5.Whether to check the TwoSided DistanceField option in StaticMesh’s BuildSettings will not affect the results

Hello,

Thank you for reaching out.

There might be an issue with the visualizer that we are investigating further.

Testing using a simple material setup using DistanceToNearestSurface shows that the actual data is what is expected. Are you seeing lighting issues with this or are you only seeing the visualizer as an issue in this case like we are?

[Image Removed]There is a difference in the effect of switching the TwoSided Flag on and off. I think it is not just a visualization problem.

When using a Material to check the Distance Fields, you need to apply it to a separate mesh, such as a plane, that does not write into the distance field.

If you apply the checking Material to any mesh writing into the distance field, you will get artifacts on the surface based on how close the mesh surface is to the voxels in the Global Distance Field texture. Since, with a two-sided Distance Field representation, the voxels inside will be positive, the artifacts will be different in that case.

For an example of this, you can see how it is done for the documentation of the DistanceToNearestSurface Material Expression:

https://dev.epicgames.com/documentation/en-us/unreal-engine/utility-material-expressions-in-unreal-engine#distance-to-nearest-surface

Please let us know if this helps.

This issue can be reproduced in 5.7.1, and it’s not a simple visual bug. I initially discovered that the problem was that Niagara leaf particles using GPU Distance Field collision were not colliding with a double-sided floor, but re-importing the same mesh without materials allowed for proper collision and they stayed on the surface (this took me a lot of time).
I removed double-sided textures from all materials, slightly changed the build resolution in LOD Build Settings to rebuild, and the holes and artifacts in the MDF disappeared in the viewport. The artifacts also appear to be related to the current camera (see this image). More details are similar to Distance fields issue

Due to confidentiality requirements, I cannot provide my screenshots.

Well sure is visual, sure not no bug… btw since 5.0 and nanite introduction reproduceable… hf
mesh needs to reapply generate distance fields to show changing the setting having an effect…

It’s expected behavior, the mesh is being treated as a paper thin wall, you can use two sided distance field generation in the static mesh settings, but I believe that’s intended more for things like trees and sparse/thin meshes. It’s generally not a good idea to use two sided materials for everything.

Well, I did not know that. As far as I understand it now, the two-sided material flag makes distance field generation behave as if that section of the mesh where the material is applied was two-sided distancefield by default. In that case, the two-sided flag inside the mesh does not make much sense anymore and feels redundant, it turns the whole mesh twosided not just the material which is twosided. This should be a separate material flag, not bundled into the two-sided flag on materials. It kind of sucks for cutout shaders, inside faces turning black, etc. But who makes isometric games with Unreal anyway…

Using twosided materials on a lot of stuff is a bad idea when using Nanite, that much is true, because there it sadly tanks performance, because the overdraw calculations do not like it then.

My hacky solution/workaround i will try to do is an editor script that takes a mesh and turns off twosided on materials, generates distancefields and then turns twosided on again…yey

after some more investigations… the documentation also mentions nowwhere, that twosided flag on a material will generate the distancefield for this section of the mesh as twosided. - i think this is just some oversight nobody noticed and or complained about. - this makes only sense when any and all twosided geometry is by defenition a foliage like object…