Previous | Next --- Slide 6 of 63
Back to Lecture Thumbnails
A-star

What would be a good barycentric metric to use to calculate the barycentric coordinates for depth?

Kalecgos

I'm not sure what you mean by barycentric metric, but presumably you could apply any of the equivalent formulas (e.g. whichever one you used for rgba in the last quiz)with the depth of each vertex as input. The slide suggests that depth varies linearly over the triangle (and this is relevant in order for barycentric coordinates to be useful). But now that linearity is being invoked, I recall a slide from the Perspective Projection and Texture Mapping lecture (http://15462.courses.cs.cmu.edu/fall2019/lecture/texture/slide_022) that illustrated how the z-value of perspective transforms are not linear, and this makes me wonder whether the depth buffer is really linear either...

motoole2

@Kalecgos You're absolutely right, and this is a good point! The values stored in the depth buffer are (essentially) the reciprocal of the true depth values, as detailed in the previous lecture. This provides more precision for accurately depth testing objects that are close to the camera, versus objects that are far away. So there's a bit of a mismatch between the depth values illustrated in this slide, and how they are represented in a depth buffer.

As stated in this slide, we can use the perspective correct interpolation procedure to compute vertex attributes at any point within the triangle, and follow the same procedure for computing depth values at any point.

At the end of the day though, the values stored in the depth buffer do not need to be linearly related to the true depth values z. All that's required is that the depth buffer values monotonically increase with smaller depth values z (where z=-infinity represents the far plane when using the infinite perspective transform, which corresponds to a depth buffer value of 1). This is because the main goal of the depth buffer is to simply test whether one object is in front or behind another, so linearity is not required.