ArticleslgStudy

science

Z-fighting

Z-fighting is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Z-fighting rather than just read about it. In short: Z-fighting, also called stitching or planefighting, is a phenomenon in 3D rendering that occurs when two or more primitives have very similar distance to the camera. This would cause them to have near-similar or identical values in the z-buffer, which keeps track of depth.

Z-fighting — main illustration
Z-fighting — illustration

Key takeaways

  • Z-fighting belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Z-fighting to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Z-fighting from memory before moving on to harder problems.

Reference excerpt

Z-fighting, also called stitching or planefighting, is a phenomenon in 3D rendering that occurs when two or more primitives have very similar distance to the camera. This would cause them to have near-similar or identical values in the z-buffer, which keeps track of depth. This then means when a specific pixel is being rendered, it is ambiguous which one of the two primitives are drawn in that pixel because the z-buffer cannot distinguish precisely which one is further from the other. If one pixel was unambiguously closer, the less close one could be discarded. It is particularly prevalent with coplanar polygons, where two faces occupy essentially the same space, with neither in front. As a result, affected pixels are rendered with fragments from one polygon or the other arbitrarily, in a manner determined by the precision of the z-buffer. It can also vary as the scene or camera is changed, causing one polygon to "win" the z test, then another, and so on. The overall effect is flickering, noisy rasterization of two polygons which "fight" to color the screen pixels. This problem is usually caused by limited sub-pixel precision, floating point and fixed point round-off errors. The more z-buffer precision one uses, the less likely it is that z-fighting will be encountered. However, for coplanar polygons, the problem is inevitable unless corrective action is taken. As the distance between near and far clip planes increases, and in particular the close plane is selected near the eye, the greater the likelihood exists that z-fighting between primitives will occur. With large virtual environments inevitably there is an inherent conflict between the need to resolve visibility in the distance and in the foreground, so for example in a space flight simulator, if a distant galaxy is drawn to scale, the viewer will not have the precision to resolve visibility on any cockpit geometry in the foreground (although even a numerical representation would present problems prior to z-buffered rendering). To mitigate these problems, z-buffer precision is weighted towards the near clip plane, but this is not the case with all visibility schemes and it is insufficient to eliminate all z-fighting issues.

Mitigation

Z-fighting can be reduced through the use of a higher resolution depth buffer, by z-buffering in some scenarios, or by simply moving the polygons further apart. Z-fighting which cannot be entirely eliminated in this manner is often resolved by the use of a stencil buffer, or by applying a post-transformation screen space z-buffer offset to one polygon which does not affect the projected shape on screen, but does affect the z-buffer value to eliminate the overlap during pixel interpolation and comparison. Where z-fighting is caused by different transformation paths in hardware for the same geometry (for example in a multi-pass rendering scheme) it can sometimes be resolved by requesting that the hardware use invariant vertex transformation. Z-fighting that is caused by insufficient precision in the depth buffer can be resolved by simply reducing the visible distance in the world. This reduces the distance between the near and far planes and solves the precision issue. However, in certain virtual environments where long-distance visibility is essential or where reduced visibility would be unbelievable, such as a space simulator or a flight simulator, this is not possible. Alternative techniques exist in these cases. One of these techniques is to "simulate" the distance of objects far from the user without actually changing their position. For example, if the maximum safe view distance (beyond which z-fighting occurs) is 10,000 units, and an object to be rendered is 15,000 units away, that object could instead be rendered at 10,000 units, but it could be scaled down in proportion to the distance which it was moved. An object that has been scaled down by half will look like it is twice as far as it actually is. If this is done only for objects that are already close to, or at, the maximum view distance, and objects close to the user are rendered normally, this technique should not be noticeable. Another technique that is utilized to reduce or completely eliminate Z-fighting is switching to a logarithmic Z-buffer, reversing Z. This technique is seen in the game Grand Theft Auto V. Due to the way they are encoded, floating-point numbers have much more precision when closer to 0. Here, reversing Z leads to more precision when storing the depth of very distant objects, hence greatly reducing Z-fighting.

References

Illustrations

Z-fighting: Demonstration of z-fighting with multiple colors and textures over a grey background
Demonstration of z-fighting with multiple colors and textures over a grey background
Z-fighting: The effect seen on two co-planar polygons
The effect seen on two co-planar polygons

Worked examples

Example 1 — a first encounter with Z-fighting

Start with the simplest possible case. Write down what Z-fighting claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Z-fighting before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Z-fighting ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Z-fighting

In research
Z-fighting appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Z-fighting in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Z-fighting is common in secondary-school and first-year university syllabi. It links to neighbouring topics 3D graphic artifacts, 3D rendering, so understanding it makes those chapters shorter.
In everyday life
Look for Z-fighting outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Z-fighting” →

How to study Z-fighting in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Z-fighting means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Z-fighting out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Z-fighting in simple terms?

Z-fighting, also called stitching or planefighting, is a phenomenon in 3D rendering that occurs when two or more primitives have very similar distance to the camera. This would cause them to have near-similar or identical values in the z-buffer, which keeps track of depth.

Why does Z-fighting matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Z-fighting?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Z-fighting.

Tags

  • 3D graphic artifacts
  • 3D rendering

Keep exploring