Software rendering in 500 lines of bare C++

10 points by RaphGL


pervognsen

This is the one of the few perspective-correct texture mappers I've seen which uses non-normalized barycentric coordinates. The way it's usually taught, if (a, b, c) are your normalized barycentric coordinates (normalized means that a + b + c = 1) then you linearly interpolate (a/w, b/w, 1/w) in screen space and recover w = 1/(1/w); a = (a/w) * w, b = (b/w) * w; c = 1 - a - b for each sample position.

But since 1/w is just serving as a reference scale for the homogeneous coordinates, you can alternatively use a symmetric interpolation scheme with not necessarily normalized barycentric coordinates. You linearly interpolate (a/w, b/w, c/w) and use 1/(a/w + b/w + c/w) = 1/((a + b + c)/w) = w/(a + b + c) instead of 1/(1/w) as the normalizer and hence recover a/(a + b + c) = (a/w) * (w/(a + b + c)) and so on for b and c. That's what this renderer does (or did when I looked at the code years ago).

pervognsen
Comment removed by author