Y-Fighting, Standard and Shader Materials, and useLogarithmicDepth

I’ve got a variant on z-fighting… let’s call it y-fighting.

Looking down at a XoZ ground for a 2D digital toy.
Moving tiles around which, by design, have very little y difference. y = 0.001 and y = 0.002, for example. I found that using useLogarithmicDepth made the y-fighting problems go away.

Now I’ve written a custom shader material and… I have no way (methinks) to set useLogarithmicDepth on a non-standard material, and the custom shader tile is always under all the other tiles.

Is my problem I’m not working z? (I’m willing to convert if that’s the best solution.)
Is there a way to “add” useLogarithmicDepth to shaderMaterials?

Suggestions for other tactics more than welcome.

I worked around this for now by using a more complicated mesh that uses a standard material for the pattern (rather than having the pattern be generated in the shader), but I’m sure I’ll run into other cases where I’ll want to use shaders and useLogarthmicDepth.

Hey! adding log depth to your shader should be not too complicated
Just add this in your vertex shader:


and that in your fragment:


2 Likes

Is there a way works with NME?

1 Like

Adding @Evgeni_Popov the king of NME :slight_smile:

Logarithmic depth is not supported in the NME at the time.

You should create an issue in the Babylon.js repo if you want someone to follow up.

1 Like

Or create a PR which might be awesome :slight_smile: if you are willing to contribute

1 Like

This PR will add the logarithmic depth support to node materials:

3 Likes

Thanks a lot!
This community is so active!

1 Like