in specs/1.3/html/chap25.html#triangle_perspective_interpolation
First,
f = {{ a {f_a / w_a} + b {f_b / w_b} + c {f_c / w_c} } \over
{ {a / w_a} + {b / w_b} + {c / w_c} }}
what is f stands for, in my understanding f can stands for normal or z or anything else that need interpolation of the fragment, is that right?
Second, but in spec we see z = a za + b zb + c zc
in my mind depth interpolation should be 1/P.z = a * 1/V0.z + b * 1/V1.z + c * 1/V2.z
why spec say Depth values for triangles must be determined using linear interpolation?
“Shader output” is whatever you put in the out block in the shader (in a shader stage that preceeds the rasterization stage). Takes the shader outputs fa, fb, and fc and during rasterization stage produce value f as a shader input for the fragment shader.
That’s linear over 1/z. Depth in screenspace is sort of a 1/z after projection. You can find plentiful articles online in context of DirectX or OpenGL about this searching for something like “linear vs non-linear depth”.
Well, you provide za, zb, and zc, so z is whatever you make it to be. Spec just says it will assume that it is linear and interpolate it as such. For depth buffer, it just matters that it is order preserving. Anyway…
With perspective division, zNDC = zclip / wclip. In typical perspective projection matrix, you would have wclip = zworld. And you would have something like zclip = (far Ă— zworld - far Ă— near) / (far - near). So if you divide that by the wclip, you get: zNDC = -1/zworld Ă— far Ă— near/(far - near) + far/(far - near).