Mr. Latte


Lesson 6 of 10

Turn Triangles into Screen Samples

After projection, a triangle’s vertices have screen positions. Rasterization decides which pixel sample locations lie inside it.

Values between vertices

An interior point can be expressed as a weighted combination of the three vertices. These are barycentric coordinates: they sum to one and are nonnegative inside. Weights (0.2, 0.3, 0.5) blend vertex information in those proportions.

Interpolation supplies depth, color, and texture coordinates. Not every projected attribute should be interpolated linearly in screen space; texture coordinates may require perspective correction.

Keep the front surface

A depth buffer helps choose among overlapping triangles. Here, smaller depth means closer.

depth = float("inf")
color = None
for candidate_depth, candidate_color in [(0.7, "red"), (0.3, "blue")]:
    if candidate_depth < depth:
        depth = candidate_depth
        color = candidate_color
print(color)

The result is blue: depth 0.3 replaces 0.7. Actual APIs may use different depth ranges or comparison directions.

Depth testing works well for opaque surfaces. Transparent surfaces also need colors behind them, making compositing order important. Nearly coincident surfaces can flicker because limited depth precision causes z-fighting.

Check your understanding

Should a distant triangle overwrite a nearer one merely because it was drawn later?

Show explanation

Not for opaque visibility. Update color and depth only when the intended depth test passes. Drawing order alone does not guarantee correct visibility.

Looking for a product partner? Founders, teams, businesses: from problem framing to launch.