Z-fighting

The flickering, stripey mess where two surfaces sit at the same depth and the GPU can't decide which one is in front.

two surfaces flickering into each otherstripey glitch on the flat thingcrawling stripes appear when I orbit the modelzfightingdepth fightingdecal flickering through the wallshimmering when the camera moves slightlytwo textures fighting for the same spot

See it

Live demo coming soon

What it is

The depth buffer stores one number per pixel saying how far away the winning surface was. When two surfaces land on effectively the same number, rounding decides the winner, and rounding changes as the camera moves. The result is that crawling stripey shimmer across a floor decal, a sticker on a car body, or two walls modeled in the same plane.

The usual culprit is not the geometry, it's the camera. Depth precision is not linear: after the perspective divide the stored values fall off hyperbolically with distance, so almost all of the precision gets spent between your near plane and a short way past it. (Logarithmic depth is a different technique, covered below, not how ordinary perspective depth behaves.) A camera with near 0.001 and far 100000 has essentially no precision left at 50 units out. Push the near plane out as far as your scene tolerates before touching anything else, it is the single biggest win. Then pull the far plane in.

Fixes for the geometry itself: separate coplanar faces by a small real offset instead of stacking them; use polygon offset (polygonOffsetFactor / polygonOffsetUnits) to nudge decals toward the camera in depth only; delete hidden interior faces that duplicate an outer wall. Logarithmic depth buffers exist and help on planet-scale scenes, but they cost performance and break some post effects, so treat that as the last resort, not the first move.

Ask AI for it

Diagnose and fix z-fighting in this three.js scene. First widen the depth precision: raise camera.near to the largest value the scene tolerates (try 0.1 instead of 0.001) and lower camera.far to just past the scene bounds, then updateProjectionMatrix. For any decal or overlay sitting flat on another surface, either offset it along the surface normal by a small epsilon or set material.polygonOffset = true with polygonOffsetFactor -1 and polygonOffsetUnits -1. Remove duplicate coplanar faces rather than hiding them.

You might have meant

depth buffer z buffercamera projection matrixtransparency sortingsurface normals backface cullingshadow mapping shadow acne peter panning

Go deeper