Rendering Issue

I have two planes that represent different grounds in my scene. The first is a blank texture with A value of 150 and alpha of 130 (it’s grey), and the second has a value of 100 and alpha of 130 (it’s black). I need to have them at similar levels, because they way the game works is if you step on the black you lose health, but I know that if i put them both at a y of 0 they will flicker, so I put the black one 0.1 below the gray one, but they still flicker, this is really annoying and looks bad, can you help?
Thanks!

There are several ways to do it. Look up how to add decals for one. However, in the short term, you can adjust your camera’s near clip plane to a higher value and the far clip plane to a lower value. The reason for the Z fighting (flicker) is due to the resolution you are provided in the Z (Depth) Buffer. So, let’s say you draw one plane. That plane will set a value in the Depth buffer for each pixel saying “I’ve drawn a pixel at this depth!”, so when the second plane draws, the render pipeline says “Is there anything already in the depth buffer for this pixel, and if so, is it closer than the pixel I want to draw now?” So what happens is you can only store a depth value with some pre-defined precision, and that precision is based on your near and far clip planes. Without getting into the math, it’s basically a ratio of your near plane over your far plane. Check out:

Often times, when you draw two things too close together, they are considered co-planar if the depth buffer can’t distinguish the distance between them. What I mean is that the depth buffer will have the same value of depth for both of them in some places and not others. The Z fighting occurs when you move, because you are seeing the implication of a single bit of precision change in the depth buffer.

Anyway, you should always set the near plane to be as far out as makes sense for your game, and always set the far plane as close as makes sense. Another thing you can do is add a bias to the shader for one of the planes. The bias adds a “fake” offset that makes the plane either closer or farther away (it can be + and -). The common name for this is Z Bias, but Unity calls it Offset in the shader:

Another approach you could take is to set the Z Test to always pass when drawing the tile that should ALWAYS be drawn on top of the other tile. That means the thing drawn on top will be stored in the depth and color buffers, and anything you draw later will still obey and overwrite that. You have to make sure you set the shader queue up properly though so the shader for the bottom tile always draws first.