- Home /
Z Fighting Problem
I have a bunch of planes with alpha textures attached to them. THey are seperated in the Z and do not collide at all. Whe I run in game mode the layers bug out and fight with each other for draw order and flicker back and forth. Any ideas?
Answer by Eric5h5 · Sep 16, 2010 at 09:14 PM
Make the camera's near clip plane as big as possible, and the far clip plane as small as possible, so the depth buffer's precision isn't wasted.
Tried that and it had no effect on the problem.
I had a similar problem and found this answer very useful. Changing the clip values indeed helped make better use of the camera's depth buffer and everything looks good now. Thanks Eric.
Great advice, if you just double the near clipping to 0.7 it already makes a ton of difference, if i make nearby planes overlap by 0.005 and set near clip to that it seems ok from most distances. ill use this comment to add search words: overlap overlapping mesh surfaces vertexes vertex combine mesh
I was so hoping the question would be about dragon ball z :(
This did indeed solve the flickering problem for me when implementing an animated skinned mesh comprised of multiple 2D planes. I set the near clip of the camera to 500 and the far clip to 601 and it worked perfectly (but also did with higher and lower values).
Answer by vestax_ion · Jul 23, 2011 at 08:37 AM
Here is a video about unity depth shader workarounds:
also his tutorial 6.2 and 6.3 are all about depth...
and this unity resource: http://unity3d.com/support/documentation/Components/SL-CullAndDepth.html
Here is a Ton of info about it with 3 solutions:
http://software.intel.com/en-us/articles/alternatives-to-using-z-bias-to-fix-z-fighting-issues/
Answer by Kronnect · Feb 11, 2015 at 01:13 PM
I have ended with a custom-non-optimal-solution that at least works for me. I add a "ZFighter" component to any GameObject which I want to get a little bit distanced from a back object/wall. This separation is calculated according to Camera distance.
using UnityEngine;
using System.Collections;
public class ZFighter : MonoBehaviour {
// Use this for initialization
private Vector3 lastLocalPosition;
private Vector3 lastCamPos;
private Vector3 lastPos;
void Start () {
lastLocalPosition = transform.localPosition;
lastPos = transform.position;
lastCamPos = Camera.main.transform.position - Vector3.up; // just to force update on first frame
}
void Update () {
Vector3 camPos = Camera.main.transform.position;
if (camPos != lastCamPos || transform.position != lastPos) {
lastCamPos = camPos;
transform.localPosition = lastLocalPosition + (camPos - transform.position) * 0.01f;
lastPos = transform.position;
}
}
}
Interesting! Still leaves a question for water from aeroplane: it will flood all the continent be lifted.
Your answer
Follow this Question
Related Questions
Render texture above something else 1 Answer
Layer Dependent Reflections 1 Answer
Strange rendering - unsupported shader? -> Pink screen 0 Answers
How to remove URP from the project 0 Answers