Builtin Library
README.md
zfighting render feature
Draws the zfighting capture view: where two opaque surfaces sit too close
together for the depth buffer to keep them apart.
A full-screen fill blacks out the lit scene, a geometry pass over
@geometry.opaque re-runs the depth test the scene already resolved
(lessEqual, writing no depth of its own) and blends a quarter-unit additively
into the scene target, and a full-screen pass turns the resulting count into a
verdict colour. The count accumulates into the scene target rather than a
private one because only that target carries the scene's depth buffer, and the
depth test is the whole measurement.
The counting pass carries a depth bias, which is what makes the measurement match what the eye sees. Unbiased, the test is exact to the last step the buffer holds, so it counts a second surface only where the two land on the identical value — a contour through the fight rather than the fight. The bias widens the test to a band 16 steps deep, plus four times the fragment's depth gradient, so every surface close enough for the winner to change hands is counted. Stating the band in depth-buffer steps keeps it honest at range: the steps grow with distance and so does the fight.
Verdict: near-black no opaque surface, dark grey one surface (healthy), red two surfaces the buffer cannot separate, white three or more.
All three passes carry the view's debug channel, so none draws for a camera that
is not a capture of pass = "zfighting". The feature is created on demand by
@builtin::systems.renderDiagnostics.renderDiagnostics.