I’m going to fix the post tomorrow, but in the post on implementing perspective-correct z-interpolation, I took $$\frac{c}{z}=\sum_i \frac{c_i}{z_i}\lambda_i(\mathbf{v})$$ and $$z_\text{ndc}=A+\frac{B}{z}$$ and claimed to demonstrate $$\sum_i c_i \lambda_i z_{\text{ndc} i}=A \sum_i c_i \lambda_i + B \sum_i \frac{c_i}{z_i} \lambda_i= \frac{z}{c} + A \sum_i c_i \lambda_i$$

This is kind of embarassingly wrong in at least two ways. And somehow I didn’t realise how wrong it was despite going to the effort of implementing it. It was only when my texture coordinates were doing all kinds of weird things that I realised what I’d done.

A correct derivation would have gone: \begin{align*}\sum_i c_i \lambda_i z_{\text{ndc} i}&=A \sum_i c_i \lambda_i + B \sum_i \frac{c_i}{z_i} \lambda_i\\&= \frac{cB}{z} + A \sum_i c_i \lambda_i\\&= c(z_\text{ndc}-A)+A\sum_i c_i \lambda_i\end{align*}which means $$c=\frac{1}{z_\text{ndc}-A}\sum_i c_i \lambda_i (z_{\text{ndc} i}-A)$$but actually this could have been obtained much easier by observing $$\frac{1}{z}=\frac{z_\text{ndc}-A}{B}$$

I am increasingly confused as to why the openGL frustum matrix was designed to have the term I’m calling \(A\), that is matrix element 3,3. Sure, it guarantees that \(z\) will be mapped to the range [-1,1] but I don’t really see the point of that, and it’d be much more convenient if it was 0 and \(z_\text{ndc}\) was proportional to \(\frac{1}{z}\)