- Home /
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!
this depends on your game world size. try increasing the distance between them, just check that it isnt visible, and set it to not cast shadows. also it's better to use cubes (at least for my game it is :p )
Answer by supernat · Jan 30, 2014 at 06:26 AM
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: http://en.wikipedia.org/wiki/Z-fighting
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: http://docs.unity3d.com/Documentation/Components/SL-CullAndDepth.html
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.
Ok, so I tried some things on all of the suggestions you told me. As for changing the clipping planes, I changed them to what made sense for my game and it didn't appear to do anything. For adding the Z Bias, I looked at the Wiki and the other page you referenced, and I have no idea how I would add the Offset. I guess I didn't know shaders were scripts, and know nothing about them. Again with the Z Test, no idea what's going on here. I appreciate your hard work on this, this must have taken a while to write. Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613132055im_/https://answers.unity.com/themes/thub/images/avi.jpg)