Question

Perspective-Correct Barycentric Interpolation in Triangles
Original question: I've seen how weights in a line in 3D space are perspective-corrected anc displayed on a screen as shown in the image. But I can't seem to find a proper explanation on how you'd do the same but for a point in a triangle whose weights would be it's barycentric coordinates. 1 image plane (X,Z₁) S 1 (1-t) (1-q) (X,Z) S q t X So 0 (X,Z) Z (coordinate system not to scale)
Expert Verified Solution
The image illustrates a 2D side view of a perspective projection. It shows a line segment in "view space" with endpoints and , with an intermediate point defined by a weight . These are projected onto an image plane at , resulting in screen coordinates . The diagram demonstrates that the interpolation weight in screen space is not equal to the weight in world/view space due to the non-linear nature of the perspective divide ().
Answer
To perform perspective-correct interpolation in a triangle, you must interpolate the values divided by depth () and the reciprocal of depth () using screen-space barycentric coordinates . The final attribute is recovered by dividing the interpolated product by the interpolated reciprocal depth.
Explanation
-
Analyze the non-linearity of projection In perspective projection, a 3D point projects to screen coordinates and . Because varies linearly across a triangle in 3D space, varies linearly in screen space. Linear interpolation of an attribute directly in screen space leads to "texture warping" because screen horizontal/vertical steps do not correspond to equal steps in 3D space.
-
Define the perspective-correct formulation Let a triangle have vertices with depths and attribute values . In screen space, we calculate barycentric coordinates such that . The attribute at a pixel is found using: The interpolated attribute divided by depth is a linear combination of the vertices' attributes divided by their respective depths.
-
Interpolate the reciprocal depth To isolate , we need the depth at that specific pixel. We use the property that is linear in screen space: The reciprocal of the projected depth is the linearly interpolated sum of the reciprocal depths of the vertices.
-
Recover the final attribute value Finally, we divide the result of Step 2 by the result of Step 3. This cancels out the term, leaving the perspective-correct attribute. The final attribute is the weighted sum of depth-divided attributes normalized by the weighted sum of reciprocal depths.
Final Answer
The perspective-correct barycentric interpolation for an attribute across a triangle is given by:
Common Mistakes
- Linear Screen Interpolation: Assuming that will yield the correct result. This causes "affine mapping" artifacts, which are highly visible in low-poly models with textures (textures appear to "swim" or bend as the camera moves).
- Using instead of : In modern graphics APIs (OpenGL/DirectX), the value used for the division is usually the clip-space component. While is proportional to view-space , using the wrong depth buffer value (like a non-linear value) will break the math.
Related Topics: Rasterization, Hyperbolic Interpolation, Texture Mapping, Homogeneous Coordinates.
FAQ
Why can't I simply interpolate attributes linearly in screen space?
Perspective projection makes depth Z non-linear in screen space, so linear interpolation causes texture warping (affine mapping artifacts). You must interpolate attributes divided by depth.
What is the formula for perspective-correct barycentric interpolation?
The correct formula is: I_pixel = (λ0 I0/Z0 + λ1 I1/Z1 + λ2 I2/Z2) / (λ0/Z0 + λ1/Z1 + λ2/Z2), where λ are screen-space barycentric coordinates.
What common mistake leads to affine mapping artifacts?
Using simple linear interpolation of attributes (λ0 I0 + λ1 I1 + λ2 I2) instead of the depth-weighted method. This ignores the non-linear 1/Z term.