Projection of frustum on cube

279 Views Asked by At

We have a camera $C$ and two parallel planes $A$ amd $B$, $near$=$dist(C, A)$, $far=dist(C,B)$. The matrix which maps points in frustum (defined as the space surrounded by these two planes and a couple of lines) on a cube with side 1 is given by \begin{bmatrix}\frac fa&0&0&0\\0&f&0&0\\0&0&x&y\\0&0&-1&0\end{bmatrix} where $a$ is the scale we need to project to a screen ( because it may be bigger or smaller , $x=((near+far)/(near-far))$, $y=(2.near.far)/(near-far)$. I don't understand how is this matrix derived, why we scale only the first $f$, why do we have $-1$ on the 4th row 3rd column. Here is a picture ( with different annotations ): enter image description here Thank you in advance.

1

There are 1 best solutions below

0
On

The first f is scaled by the aspect ratio, otherwise you are stuck with a square viewport instead of a rectangle one.

x and y values are scaled by f to take into account the angle of view.

The "-1" is to store the z value as depth in w coordinate. The minus is for flipping the axes.

The x and y fields with near and far are for mapping the z value between near and far to -1 to 1.

All three x, y and z coordinates need a division by original z, which is stored in w thanks to that "1" (or "-1").