Motivation
A depth buffer answers a question at a point: among the opaque triangles covering this sample, which one is nearest? A pixel average asks a different question: which triangle is nearest at each point of a finite region, and what color does that triangle contribute there? Testing the center, or averaging each triangle's coverage separately, cannot in general answer the second question. Two surfaces can exchange their front-to-back order inside a pixel.
The earlier rasterization note established barycentric interpolation and the sample-wise minimum invariant. Here we develop the geometry behind that invariant. A planar triangle has an affine divided-depth function in screen coordinates. Comparing two such functions therefore cuts their common footprint along a straight line. With finitely many opaque contenders, these comparisons produce polygonal regions on which a particular triangle is visible. For a color component that is affine in screen coordinates, its integral over each region has a short exact formula.
The goal is a finite mathematical model whose assumptions can be checked. We use exact arithmetic, nondegenerate projected triangles, positive homogeneous denominators, opaque surfaces, and an explicitly declared smaller-is-nearer convention. We do not model transparency, a native graphics API's rounding or rasterization rules, or the integration of a general textured shading function. In particular, a screen-affine color model is a separate assumption, not a consequence of perspective-correct interpolation.
Definitions
Definition 2.5.1
(Screen coordinates, divided depth, and the local footprint)
Use a Cartesian screen with horizontal coordinate and upward vertical coordinate . A clipped planar triangle has clip vertices with , projected vertices , and nonzero projected area. Its screen barycentric functions are , with .
Its divided depth is . We may replace it by a fixed increasing affine function of without changing any nearer/farther comparison. In the formulas below we retain itself, with smaller values nearer.
A local footprint is a bounded closed convex polygon of positive area on which a declared finite list of triangles is present everywhere. Each listed triangle covers in the closed geometric sense, and the local model includes no further contenders. To represent an actual scene pointwise, no omitted surface may occlude that list there. For area integration, this scene condition is needed only away from zero-area subdivision boundaries. Depth and color functions refer to that same screen coordinate system. The footprint may be a rectangular pixel, or one polygonal piece of a pixel after coverage boundaries have been separated.
The common-footprint condition is essential. A triangle that covers only the left half of a pixel must not compete for visibility in its right half by an unrestricted extension of its depth plane. Later we explain how a finite collection of triangle edges supplies a subdivision with a constant contender list on each open piece. Boundary ownership remains a separate issue for point samples.
Definition 2.5.2
(A deterministic opaque winner)
Give each contender a distinct fixed integer key . At a covered point , compare pairs lexicographically: first compare exact depths; if they are equal, the smaller key wins. The winner is the index of the smallest pair. A sample buffer starts empty, or with a sentinel pair larger than every contender pair. It stores the smallest pair seen and the associated color, updating only when a smaller pair arrives. If the contender list is empty, use a separately declared constant background color ; no winning contender pair is required.
For a scalar color component , the resolved image value is . Its uniform box-style average over a footprint is
Here is screen area. Color components used in mixtures are in a declared linear-light space; an encoded display value must not silently be treated as a linear intensity.
The key chooses a reproducible representative when exact geometry supplies no unique front surface. It does not resolve an underlying modeling ambiguity of coincident materials. Keys must remain fixed while the arrival order changes. A counter increased whenever a fragment arrives would merely rename the arrival order.
Theorem / proposition
Theorem 2.5.3
(A triangle's divided depth is a screen plane)
Under the first definition's hypotheses, divided depth on the projected triangle is
Thus for fixed coefficients. It is already affine after division; applying the usual perspective-attribute quotient to the vertex values would generally produce a different, incorrect function.
For a particular forward-distance camera, let be distance along the viewing axis, use unit-focal-length projection , and choose near/far distances . Set
Then , with near depth zero and far depth one. On a projected triangle,
The forward distance is generally not screen-affine.
Theorem 2.5.4
(Exact visibility cells and order-independent sampled winners)
On a common footprint , suppose the finite contenders have affine depths . The exact winner region of contender is
These possibly empty convex sets, formed by intersecting with open and closed half-planes, partition : every point belongs to exactly one . At each point, the pair-storing sample buffer returns the same winner in every arrival order, provided every contender participates, accepted fragments write both depth and key, and no other operation changes the comparison.
For area integration, first remove every contender whose entire affine depth function equals that of a smaller-key contender. For each remaining , form the closed weak cell
Each is a closed bounded convex set: a polygon, a segment, a point, or the empty set. Their union is , and distinct overlap only on sets of area zero. Integrating over these closed cells therefore gives the same average as the exact winner partition, for bounded integrable color functions.
Deleting identical depth functions is required for the last conclusion. Two coincident planes may tie on the whole footprint, rather than along a line. Summing both of their weak-cell integrals would count a region twice, even though the key definition chooses only one surface there. Conversely, a genuinely lower-dimensional cell contributes zero area to an integral but can still contain a point sample whose tie must be resolved.
Theorem 2.5.5
(Integrating an affine color over a convex polygon)
Let have counterclockwise vertices and positive area. Fan-triangulate it using . For , set
For a convex polygon these areas are nonnegative, including possible zero-area fan pieces. Its area and first-moment vector are
For any screen-affine scalar color ,
Consequently the resolved average on is obtained by summing this expression over its nonempty positive-area visible cells and dividing by . Apply the formula component by component for a vector color.
No color value is needed at the centroid when the three vertex values of a fan triangle are already known. If the color is affine, their arithmetic mean equals the value at that triangle's centroid. If the color is nonlinear, neither statement makes centroid sampling an exact integration rule.
Proof sketch or proof idea
Proof
(Why divided depth is a screen plane)
For the depth theorem, let be the original triangle weights of the point before division. The usual homogeneous reconstruction gives
The interpolated clip coordinates satisfy and . Therefore
The screen barycentric functions are affine, proving the plane claim. For the forward-distance camera, , so
Substitution into gives the formula. Since , : increasing forward distance increases depth in this convention. The monotonicity connects the algebraic comparison to physical front-to-back order along one viewing ray.
Proof X-ray
Why divided depth needs no second correction
An ordinary affine surface attribute is reconstructed as a quotient because its original weights differ from screen weights. Divided depth already contains the division by the same homogeneous . In the proof, that denominator cancels precisely the factor converting to . The screen-affine quantity is , while the forward distance is recovered from the reciprocal plane. A formula chosen merely because the word “perspective” appears can therefore correct the wrong quantity twice.
Proof
(Order independence and the visibility cells)
For the visibility theorem, lexicographic order is a total order on the finite distinct pairs. A point chooses exactly when its pair precedes every other pair. If another contender has a smaller key, must beat it strictly in depth; if the other key is larger, equality is allowed. These are precisely the stated half-plane conditions. Strict and weak half-planes are convex, as is their intersection with , so each exact region is convex. The unique minimum proves both disjointness and coverage of the partition.
The specified initial state supplies the base case of a simple invariant: after any nonempty set of arrivals, the buffer holds the smallest pair seen so far. Comparing the next pair and retaining the smaller of the two gives the minimum of the enlarged set. Induction establishes the invariant for all arrivals, independently of their order. A key-free strict depth test instead keeps the first color at an exact tie; a key-free non-strict test keeps the last. Their minimum depth agrees, but their selected color need not.
Proof
(Weak cells and the first-moment formula)
For the integration version, equal affine functions have already been reduced to their smallest-key representative. Two remaining affine depths either never agree, or agree on one straight line. Each such line has two-dimensional area zero. Away from the finite union of these lines, there is a unique smallest depth, and the weak-cell rule agrees with the exact rule. The cells cover because a finite set of real depths has a minimum at every point. Their pairwise intersections lie on those zero-area lines. Half-plane intersection gives the polygon statement; empty or lower-dimensional cases cause no area contribution.
For the moment formula, a convex polygon is the union of the indicated fan triangles with disjoint interiors. On one nondegenerate triangle with vertices , write on the reference triangle , . The constant area Jacobian is twice the physical triangle's area . Direct integration on the reference triangle gives integrals for the constant function and for each of . Since is affine,
The zero-area case contributes zero. Apply this identity to the constant function and both coordinate functions to obtain area and first moments, then sum the fan pieces. Integrating gives the final expression. This proof also shows why a different valid triangulation has the same integral: every triangulation integrates the same function over the same region.
Worked examples
Worked example 2.5.6
(A depth plane and the non-affine distance behind it)
Use near/far distances , hence . Let the projected triangle have vertices and forward vertex distances . One compatible set of camera-space vertices is , using the positive forward coordinate of our declared camera.
The screen weights are , , . Therefore
At the weights are , , , and . The vertex depths yield the same by ordinary screen interpolation.
Screen-interpolating the forward distances instead gives and then depth , which is wrong. Applying the perspective-attribute quotient to the already divided vertex depths gives , also wrong. The two mistakes differ because they interpolate different quantities, and neither recovers the declared point on the planar triangle.
Worked example 2.5.7
(Two crossing surfaces and their exact color average)
Let the common footprint be the triangle , of area . Surface has and scalar color ; surface has and . Give the smaller key. Both depths stay in on this footprint. They are compatible with planar perspective triangles: with the previous camera, recover each vertex distance from , then use camera vertex .
The depth difference is . Thus wins at , while wins at . Ignoring the zero-area tie edge for integration, their polygons are
The first polygon has fan areas and fan centroids . Its area is , and its first -moment is . Hence its color integral is . The second polygon has area and constant color one, so its color integral is . The resolved footprint average is
The footprint centroid is . Its visible color is , which is different from . Even sampling a geometrically distinguished point does not integrate a function that switches between surfaces. Weighting the visible areas by each surface's value at that same footprint centroid would give , also wrong: the appropriate affine averages belong to the visible polygons, not the original footprint.
Worked example 2.5.8
(Three planes, pairwise ties, and a triple junction)
On the unit square, take depths , , and keys . The weak visible regions satisfy respectively and ; and ; and . Their areas are . For the first, integrate vertical slice length from to ; the second follows by reflection; the third is a square of side .
At all depths equal and key one wins. On the diagonal below that point, keys one and two tie in front of three, so one wins. On the edge , one beats three by its key. These boundary choices do not alter the areas. If the surfaces have constant linear RGB colors red, green, and blue, the exact box average is .
Now add a fourth plane identical to but with key four and a white color. It never wins. Removing it before the weak-cell integration is essential; otherwise its square would be integrated a second time. The exact lexicographic buffer needs no special duplicate-plane preprocessing at a sample: its key comparison already rejects the loser.
From actual triangle footprints to local cells
A practical scene does not usually have a single contender list over a whole pixel. Nevertheless, the finite polygon model still applies piece by piece. Intersect the pixel domain conceptually with the arrangement of all supporting lines of the projected triangle edges. On each open two-dimensional arrangement cell, every edge function has a fixed sign. A triangle's three inside/outside tests are consequently constant there, so the covering-triangle list is constant. The cell is convex because it is specified by a sign choice for each line and the convex pixel domain.
For integration, use the closure of each open cell and extend that cell's fixed contender list and its affine functions to the boundary. This defines a local model for integration; it need not reproduce the actual scene's contender list on those boundaries. Apply the visibility comparison to that list, then integrate the resulting visible polygons. A cell with no contender contributes its area times . The finitely many arrangement boundaries have area zero, so their ownership does not change a bounded area integral. A point sample on such a boundary still needs the separate shared-edge coverage convention from the rasterization note, followed by the depth/key convention among the fragments actually covered there.
This is a finite geometric specification, not an efficient clipping implementation. It can produce many cells and presupposes exact intersections and predicates. Pairwise depth-equality lines are also needed within each constant-coverage cell. There is no claim that drawing a few wireframe lines, or sorting complete triangles once, implements this integration.
What survives small depth errors?
Theorem 2.5.9
(A verified depth gap protects a winner)
At a fixed point, let contender have true gaps for all . If every computed depth satisfies and , then is still the unique smallest computed depth.
On a convex polygon where all those depth functions are affine and the contender list is constant, the same conclusion holds throughout if every gap is at least at every vertex and the stated error bound holds throughout .
Proof
(Subtracting the error bounds)
For each , . For the regional claim, an affine gap at a convex combination of vertices is the same convex combination of its vertex gaps, so its lower bound holds everywhere.
For example, a certified gap of protects the winner for any per-depth error bound ; is one sufficient choice, because . The theorem assumes an actual error certificate; it does not supply one for a floating-point implementation. At a true crossing the gap is zero, so no fixed can guarantee that the computed winner equals the true winner at points arbitrarily close to that crossing, on either side.
Common mistakes
Counterexample mode
An $\varepsilon$ tie can destroy the comparison order
Consider the rule “if two depths differ by at most , choose the smaller key; otherwise choose the smaller depth.” Three fragments have depth/key pairs , and . The rule prefers to , and to , because those neighboring depth gaps are within the tolerance. It prefers to , because their gap exceeds the tolerance. The resulting preference is a cycle, so it is not an order.
Starting with an empty buffer, arrivals leave , while arrivals leave . An approximate tie rule introduced to suppress a numerical symptom has invalidated the minimum invariant. A fixed quantization of each depth, followed by exact lexicographic comparison of quantized value and key, does define a total order; its objective is the smallest quantized depth and key, which need not be the geometrically nearest true surface. State that changed objective explicitly.
Common mistake
(Averaging each triangle's coverage separately)
A mean color cannot generally be computed from each triangle's individual pixel coverage: their overlap pattern and depth order determine which portions are actually visible. In the second worked example both surfaces cover the whole footprint, yet their visible areas are and .
Common mistake
(Assuming other attributes are screen-affine too)
Screen-affine divided depth is not evidence that texture coordinates or lighting are screen-affine. A perspective-correct attribute is usually a quotient of affine functions, and a lighting model can introduce normalization, products, clamps, or discontinuities. The polygon moment rule above does not integrate those functions exactly.
Common mistake
(Reading the tie key as a physical fact)
A deterministic tie on a genuinely coplanar overlap is a declared drawing policy. It is not a physical explanation of which of two coincident opaque materials should be visible. Geometry modeling, depth precision, coverage ownership, and color integration are four distinct questions even when one image artifact involves all of them.
Summary
For a planar perspective triangle, divided depth is a screen plane, while, for the declared forward-distance camera, forward distance is the reciprocal of a screen-affine function and is usually not screen-affine itself. On a region with a fixed set of opaque contenders, pairwise depth comparisons produce convex visibility cells. Fixed keys resolve equal depths and make sampled selection independent of fragment arrival order. After duplicate planes are resolved, the closed cells overlap only on zero-area boundaries, allowing exact integration of screen-affine color by triangle areas and first moments. These are exact results for the stated finite model, not a general antialiasing or transparency algorithm.
Exercises
Quick check
(In the first worked example, evaluate at and at . Check depth once more using the vertex depths and screen barycentric weights.)
Use the screen weights and the formula for from the first example.
Solution · Answer
At , , , and . The vertex-depth interpolation is . At , , , and . The vertex calculation is . Different screen points with the same lie on the same depth contour for this particular plane.
Quick check
(On the unit square, take and , with the smaller key assigned to . Describe the exact two winner regions. For constant colors , find the resolved average and the winner at .)
Check the sign of .
Solution · Guided solution
The difference is . Therefore wins on the closed lower-left triangle , and wins on the remaining part where . Their areas are each , so the average is . The specified point lies exactly on the tie line; the smaller key gives it to and color zero. Changing this zero-area boundary assignment would not change the average.
Quick check
(For the quadrilateral in the second worked example, compute its first -moment and its integral of . Give the average of this affine function on .)
Use the fan triangles of and their centroids.
Solution · Guided solution
The two fan triangles have areas and centroid -coordinates . Hence , while and . The integral is
Divide by area to get average . Equivalently, the polygon centroid is and . This equivalence uses the affine form of this particular color.
Quick check
(On a common square let two depth planes be identical everywhere, with keys seven and two and constant colors zero and one respectively. Explain the exact winner, the effect of using only a strict depth comparison, and the result of incorrectly integrating both weak cells.)
Compare the two planes before comparing any keys.
Solution · Guided solution
Key two wins everywhere and the correct average is one. A key-free strict depth comparison retains whichever fragment arrives first, so its selected color is not order-independent. Both weak cells would equal the whole square. Summing their integrals happens to give one because one color is zero, but their summed areas equal twice the square's area, and replacing the zero color by any nonzero value exposes the wrong color total immediately. For example, changing the losing color to one would give a spurious average of two. Identical planes must be reduced to their winning representative before using the zero-area-overlap claim.
Quick check
(At one point the true winner has depth , and its two competitors have depths . Each computed depth has absolute error at most . Prove whether the winner is protected. If the error bound becomes , show whether a computed tie is possible.)
Compare the smallest true gap with .
Solution · Guided solution
The two true gaps are . Their minimum exceeds , so the strict error-gap theorem protects the winner. With error , increase the winner depth to and decrease the nearer competitor to . Both perturbations have the allowed magnitude, so a computed tie is possible. If the competitor has the smaller key, the tie-break selects the true loser. The strict inequality in the theorem cannot simply be replaced by a non-strict one.
Quick check
(On a triangle with vertices , let a color be . Calculate its exact average, the value at the triangle centroid, and the average predicted by the affine vertex rule. Explain why all three need not agree.)
Integrate over .
Solution · Guided solution
The integral is
The area is , so the exact average is . At the centroid , the value is . The vertex values are , so applying the affine vertex rule would predict average . That rule exactly integrates the affine interpolant of the vertex data, which is , rather than the specified nonlinear function . The failure is in the model assumption, not in the polygon area calculation.