Z-fighting

From Valve Developer Community
Jump to navigation Jump to search
Z-fighting seen in Hammer
Z-fighting between non-coplanar faces. They are close together, and at a distance the GPU starts rendering them as coplanar.

Z-fighting occurs when the GPU renders coplanar triangles at the same time. It generally manifests as flickering between the polygons with a striped pattern changing with the camera angle. It can also appear due to imprecision in the Z buffer. For example, non-coplanar faces that are close together might look normal up close, but might flicker at a long distance.

Mitigation

  • SourceVBSP and GoldSrcHLCSG will automatically chop brush coplanar brush faces within the same bmodel. In Source, this does not seem to occur for detail brushes[confirm].
  • (only in GoldSrc) HLCSG provides some additional control over this with func_detail and func_group's zhlt_coplanarpriority KV.
  • Move polygons away from eachother. The bigger the gap, the longer the distance at which they will Z-fight.
  • (only in Source) Use $decal for one of the overlapping materials. It offsets any faces by a minuscule amount along the surface normal, thus increasing the gap and reducing Z-fighting. Note that it will also disable writing to the Z buffer, causing the triangle's depth to be inherited from geometry rendered behind it.
  • Increase the precision of the Z buffer by bumping up the near Z and reducing the far Z (in Source, this is controlled via env_fog_controller; in GoldSrc, this is controlled via worldspawn). This can also be done in Hammer Hammer's settings (titled Back clipping plane), but it will not change anything in-game. In Hammer++ Hammer++, the near Z can also be changed.
  • If Z-fighting occurs on a studio model, the geometry can be split into multiple $body meshes; later-defined meshes will be rendered on top of earlier-defined meshes.
  • Due to the mathematics of how additive blending works, Additive-blended surfaces will never Z-fight with other additive-blended surfaces.

External links