Skip to content

Step 1 of 5 · Reading · ~1 min

Read

Rasterization

Barycentric Coordinates

A point inside a triangle (V0, V1, V2) can be written as:

P = u * V0 + v * V1 + w * V2  where u + v + w = 1

The triple (u, v, w) is the barycentric coordinate of P with respect to the triangle. They are the weights you'll use to interpolate any per-vertex attribute (color, UV, normal, depth) across the triangle.

Geometric meaning: each weight equals the area of the sub-triangle opposite to that vertex divided by the area of the full triangle. u is the share owed to V0, and so on.

Inside test: P is inside the triangle iff u >= 0, v >= 0, w >= 0. Negative means outside the edge opposite that vertex.

Cross-product derivation for a 2D triangle:

python

If denom is 0, the triangle is degenerate (collinear vertices) — return early.

Why we care: barycentrics are the bridge from "is this pixel covered?" to "what color is it?". Multiply each vertex attribute by its weight, sum, done.

In a real rasterizer, you compute the barycentric of every pixel inside the bounding box of the triangle in one fused step — see the next lesson on triangle rasterization.

Up nextTriangle Rasterization with a Z-BufferRasterization

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…