Motivation
Projection produces continuous geometry, while an image stores a finite array of values. Rasterization connects them by deciding which image samples a primitive covers and which attributes belong at those samples. Visibility is a separate decision: several triangles can cover the same sample, but an opaque image usually displays the nearest one. Keeping coverage, interpolation, and visibility distinct makes the graphics pipeline understandable and helps locate errors. A crack along a mesh edge, a warped texture, and an object showing through another object have different mathematical causes.
We work first with a triangle that has already been clipped to the viewing region and projected to the image plane. Pixel samples lie at specified locations, commonly pixel centers; the convention must be stated. We use a Cartesian image coordinate system with upward vertical axis. A screen with downward-growing row indices requires a sign adjustment or a coordinate conversion. All coverage statements initially use exact arithmetic. Finite precision requires consistent edge evaluation and tie rules across neighboring triangles.
Sampling a triangle once per pixel is not the same as measuring the fraction of the pixel covered by that triangle. A pixel is a finite image region, whereas a sample is a point or a weighted measurement. This distinction matters at edges and for thin features. The first goal is a correct discrete coverage rule; antialiasing then asks how that discrete representation should approximate the desired image measurement.
Definitions
Definition 2.1.1
(Oriented edge function and barycentric coordinates)
For image points and , define . It is positive to the left of the directed edge . For a counterclockwise nondegenerate triangle , let and define
The denominator is twice the signed area. A zero denominator means the projected triangle has no two-dimensional interior, so the ordinary triangle formula does not apply. A clockwise triangle can be reordered, or the signs can be handled consistently; blindly testing three nonnegative edge functions would reject it.
Concept lensGeometric
Weights as ratios of signed areas
The value is twice the signed area of the triangle , positive when run counterclockwise. Hence is the signed area of divided by the area of , and similarly for the other weights: each weight is the share of the triangle's area belonging to the sub-triangle opposite the corresponding vertex. In the triangle , which has area , the point gives the sub-triangle of area , so , matching . A point outside gives a sub-triangle of opposite orientation, hence a negative weight.
Definition 2.1.2
(Depth buffer and interpolated attribute)
At each image sample a depth buffer stores the nearest accepted depth so far. In this note smaller divided depth means nearer, and the buffer begins at a value beyond all valid geometry. A fragment is a candidate contribution from a primitive at a covered sample. An attribute may be a texture coordinate, color, or another quantity attached to the vertices; its intended variation over the original triangle must be specified before choosing an interpolation formula.
Depth comparisons operate on a chosen monotone depth convention, such as the normalized depth derived in the previous note. They need not store Euclidean distance to the camera. A fragment can fail other tests or be discarded, so the simple proof below assumes every valid opaque fragment participates and writes depth on acceptance.
Theorem / proposition
Theorem 2.1.3
(Barycentric reconstruction and coverage)
For the nondegenerate counterclockwise triangle above, and . A point belongs to the closed triangle exactly when all three weights are nonnegative. Every function affine in image coordinates satisfies .
Theorem 2.1.4
(Perspective-correct attribute interpolation)
Suppose clipped vertices have clip coordinates with , and a scalar attribute is affine in the original triangle's barycentric parameters. If a covered projected point has screen barycentric weights , then
The original barycentric weights are . Apply the formula component by component for vector attributes.
The positivity hypothesis avoids a vanishing denominator for points inside the triangle and is secured by proper clipping to the visible frustum. The theorem does not say every physical quantity is affine on a surface. It corrects projection distortion for the specified piecewise-affine vertex model. An interpolated normal must be normalized before use as a unit vector only when its length is nonzero. Opposite unit normals with equal original weights average to zero, where normalization is undefined. Such data require a separately specified normal or shading convention, rather than division by a small invented length.
Proposition 2.1.5
(Depth-buffer minimum invariant)
At one sample the stored depth starts at a value beyond all valid geometry. Valid opaque fragments with depths arrive in any order, and a fragment replaces the stored depth and color exactly when its depth is strictly smaller than the stored depth. Then after fragments the stored depth is , whatever the order. If this minimum is attained by exactly one fragment, the stored color is that fragment's color.
Proof sketch or proof idea
Proof
(Barycentric weights from affine functions)
Each edge function is affine in . The proposed weights take values at the three vertices. Their sum is an affine function equal to one at three noncollinear points, so it is identically one. Likewise the affine map agrees with at the vertices, hence everywhere. Nonnegative weights express a convex combination; conversely the edge functions of any convex combination of the vertices are nonnegative. Applying an affine to the reconstruction proves the last assertion.
Proof
(From original weights to screen weights)
For the second theorem, form a homogeneous point with . Its projected first two coordinates are
Uniqueness of screen barycentric weights gives . Dividing by and normalizing recovers . Finally, yields the stated quotient. Clipping-created vertices must receive attributes interpolated at their original edge parameter before this projection argument is used.
Proof X-ray
Interpolate two affine quantities, then divide
The screen weights are correct for the projected triangle, but they are not the original surface weights. The proof identifies the missing factor as each vertex's homogeneous denominator. Both and are affine functions of screen position under this model; their quotient reconstructs . This explains why a renderer can increment two planar functions across a row and perform a division per sample. It also explains why simply interpolating cannot be repaired by normalizing its final value.
Opaque visibility has its own elementary proof, by induction on the number of fragments.
Proof
(Induction on the number of fragments)
Write and claim: after fragments the stored depth is , and if is attained by exactly one fragment, the stored color is that fragment's. For the fragment is accepted because . Suppose the claim holds for , and fragment arrives. If , it replaces depth and color; the new minimum is , attained only by this fragment, which is what is stored. Otherwise , so nothing changes and . If is attained by exactly one fragment, that fragment cannot be (that would force ), so it is the unique minimizer among the first , and by hypothesis its color is stored. The minimum does not depend on the order of the fragments. Equal-depth color selection needs a declared tie rule, which is why the color statement assumes a unique minimum.
This is a statement about the sampled geometry, not a guarantee that every feature of a continuous scene was sampled.
Worked examples
Worked example 2.1.6
(A complete triangle coverage calculation)
Take vertices and sample . The denominator is . The three edge functions are , so the weights are . They are nonnegative and reconstruct . The sample has weights , so it lies outside across the edge opposite the first vertex. An affine color component with vertex values has value at the first sample.
Worked example 2.1.7
(A texture coordinate that bends under the wrong rule)
Along a projected edge take screen weights , clip denominators , and texture coordinates . Ordinary interpolation gives . Perspective correction gives . The corresponding original weights are : the same screen midpoint is closer in surface parameter to the nearer endpoint. This is exactly the midpoint discrepancy obtained geometrically in the previous note.
The interactive example below uses different clip denominators, : its corrected midpoint is . Compare it with the example above, whose corrected midpoint is .
Worked example 2.1.8
(Depth is already a divided quantity)
At the same screen midpoint, let clip depths be with . The projected vertex depths are . Correct divided depth is their screen-linear average . To verify, original weights give and , hence . Applying the generic perspective quotient directly to the vertex values instead would give and would correct depth twice.
Incremental evaluation and shared edges
For a fixed edge, expanding the determinant gives , with and . Moving one sample to the right changes the value by ; moving one sample up changes it by . A rasterizer can therefore evaluate edges once at a bounding-box corner and update with additions. It still needs an integer bounding box enclosing all relevant sample centers. Incremental arithmetic saves work; it does not change the geometric coverage test.
A closed-edge rule covers every sample exactly on a shared edge twice. Rejecting every boundary sample creates cracks. A consistent half-open rule gives the boundary to exactly one of two adjacent, consistently oriented triangles. For our upward-axis convention, one possible rule accepts a zero edge value only when the directed edge has positive vertical increment, or has zero vertical increment and negative horizontal increment. Reversing a nonzero edge reverses this ownership. Other rules are valid when implemented consistently; row direction changes which familiar edge names describe them.
Counterexample mode
A closed edge test is harmless only for opaque color
The claim: letting both triangles accept a sample with edge value zero merely paints the shared-edge sample twice with the same color. For opaque color this is true. Now blend a half-transparent triangle pair with alpha and color over background using . A sample covered once becomes . A shared-edge sample covered by both triangles becomes , a visible bright seam. Giving the boundary to exactly one triangle by a half-open rule restores at every sample.
Line rasterization uses the same principle of incremental implicit functions. For a segment with increasing and slope between zero and one, the implicit line expression can decide whether the next sample should stay on the current row or advance one row. Comparing at a midpoint gives an integer-update algorithm after clearing constant factors. Handling other octants requires exchanging axes or signs. A line drawn as a one-dimensional primitive and the boundary of a filled triangle need not use identical sample ownership conventions; assuming they do can make a diagnostic wireframe appear misaligned.
Visibility, precision, and measurement
Back-face culling and hidden-surface removal solve different problems. Culling can reject a triangle whose oriented face points away from the camera, given a consistent winding convention and a suitable closed opaque surface. Two front-facing triangles may still overlap; the depth test decides which is nearest at each sample. Open sheets, mirrored transforms, and two-sided materials require care before applying a culling rule.
The depth buffer avoids a global ordering of triangles. Sorting by one center depth is insufficient when triangles intersect or when the front/back relation varies across their projections. It also does not solve ordinary transparency: two partially transparent layers both contribute, so discarding the farther layer changes the image. Alpha compositing needs a separate ordering or a method that preserves the relevant contributions.
For the standard perspective depth of the previous note, with . The derivative is , so equal representable changes in correspond to larger distance changes far away. Nearby nearly coplanar surfaces can then alternate which one wins after rounding, producing depth fighting. Increasing the near distance while preserving the needed scene can improve this standard depth allocation; the precise effect depends on the depth format and convention. A tiny arbitrary offset is not a substitute for understanding the geometry and comparison rule.
A single point sample produces unstable results when an edge moves across a pixel. Multiple sample positions approximate coverage more finely, but no fixed finite set detects every arbitrarily thin feature. A proper antialiasing model specifies a pixel filter and approximates its integral over the image. Texture filtering, treated next, addresses a related sampling problem within a surface. More samples can reduce an error without establishing exact area coverage or eliminating all aliasing.
Common mistakes
Counterexample mode
A visibility answer at one sample says nothing about its neighbor
Two overlapping projected triangles may have depth functions and over part of their overlap. The first is nearer at , and the second at . No single front-to-back order describes both locations. A center-depth sort cannot make either complete triangle uniformly correct. The depth buffer works because it compares the two functions separately at each covered sample.
An interpolated texture coordinate and an interpolated color are not automatically treated the same by every shading model. The relevant question is which quantity the model assumes varies affinely before projection.
Common mistake
(Perspective-correcting a depth that is already divided)
Normalized device depth is screen-affine for a planar triangle, so its screen interpolation is already correct. Applying the perspective quotient to the projected vertex depths at the screen midpoint with gives , whereas the correct value is (see the third worked example). The division by has been applied twice. Decide for each quantity whether it is affine in screen space or in the original triangle, and correct only the latter.
Common mistake
(Requiring three nonnegative edge values for any winding)
The test presumes . For the clockwise triangle we have , and at the interior sample the three edge values are . A test for three nonnegative values rejects this sample. Dividing by gives the weights , or one can swap two vertices to restore counterclockwise order before testing.
Summary
Edge functions give both a coverage test and barycentric weights. Consistent boundary ownership prevents shared-edge cracks and double coverage. Opaque depth testing maintains a minimum independently at each sample. Perspective-correct interpolation reconstructs original surface parameters by dividing screen weights by clip and renormalizing; divided depth itself is already screen-linear. All these statements describe samples and must be distinguished from continuous pixel integration.
Exercises
Quick check
(For triangle compute the barycentric weights of and decide whether is inside.)
First compute the denominator .
Solution · Guided solution
The denominator is . Coordinates give and , so has weights . At they are , so the point is outside. The negative first weight identifies the violated edge.
Quick check
(For edge , derive and its updates for one step right and one step up. Test the point .)
Expand the determinant and read off the coefficients of and .
Solution · Guided solution
Expansion gives . The right update is and the up update is . At the value is , placing the point to the right of the directed line. Reversing the edge changes every sign, so boundary and interior conventions must be reversed together.
Quick check
(At a triangle sample take , , and scalar attributes . Compute the perspective-correct value and compare ordinary interpolation.)
Form the two sums and .
Solution · Guided solution
The reciprocal-denominator sum is . The numerator is , so the answer is . The original weights are and give the same result. Ordinary interpolation gives and assigns too much weight to the far vertex.
Quick check
(At one sample valid opaque fragment depths arrive as . Starting from depth , list the accepted updates. What changes if the final fragment has alpha and the goal is transparency?)
Compare each arriving depth with the stored value.
Solution · Guided solution
The buffer changes from to , then to , rejects , and changes to . For opaque fragments only the last accepted color survives. A half-transparent nearest layer should also transmit some color from behind; replacing the color and rejecting all deeper contributions is insufficient. One must retain or recompute the background contribution and composite according to a declared transparency model.