Sorting bug with Mesh Decals (decal proj

Hello,

when using decal shaders on mesh projector, they act normally. However, when placed on meshes, they have sorting bugs: the mesh decals go on top of standard meshes as your camera gets a little bit farther away.

In unreal 4, a workaround was using Flat Tesselation to fix this, but tesselation does not exist in UE5.

Is there a real solution to prevent this from happening? I’m trying with nodes that measure camera distance to try and offset this, but is works poorly. I’d need a precise formula for it to compensate properly.

Thank you

1 Like

Hello, I found an old thread with the solution!

In the meshdecals.usf file, located in C:\Program Files\Epic Games\UE_5.0EA\Engine\Shaders\Private,
either comment out (with //) or massively reduce the number in '“Output.Position.z += 0.0001f * Output.Position.w;” (change it from 0.0001f to something like 0.0000001f)

This is supposed to prevent zfighting at a distance, so removing it completely might zfight.

Try this console command and some small value:
r.DecalDepthBias

By default it is 0.005.
Works in UE 5.2.

1 Like

This has been bugging me for a while, this did the job for me! Thank you very much

I finally figured out a solution for this in my scenes. I use mesh decals a ton, so this has been bugging me for years.

In my mesh decal master material, I added a custom stencil mask multiplied by my opacity map, and added a channel ID of 1 and 2. So now every mesh I tag with channel one will mask out the mesh decal, and it will appear behind it. I used this to stencil the crosswalk mesh decals that were appearing above the cars when I zoomed out. I also mixed this with some WPO controls that allow me to move the decals higher or lower from the surface. It works great, finally no z-fighting or mesh decals showing up in front of unintended meshes.

You can see an example here: https://www.youtube.com/watch?v=aM4uAW1E4Ew