To use pixel coordinates, we need a view transformation. These are implemented as matrices which are multiplied with the vertex positions to transform them. A matrix consists of several vectors, giving the new direction and size for each axis. To multiply a matrix by a vector, you simply multiply and sum the components, going x units in the new x direction, y units in the new y direction, etc.

$$\begin{pmatrix}x & y & z & 1\end{pmatrix} \begin{bmatrix} x_x & x_y & x_z \\ y_x & y_y & y_z \\ z_x & z_y & z_z \\ x_0 & y_0 & z_0 \end{bmatrix} = x\begin{pmatrix}x_x & x_y & x_z\end{pmatrix} + y\begin{pmatrix}y_x & y_y & y_z\end{pmatrix} + z\begin{pmatrix}z_x & z_y & z_z\end{pmatrix} + 1\begin{pmatrix}x_0 & y_0 & z_0\end{pmatrix}$$

If we leave 0 at the center, then we just need to divide the (2D) pixel coordinates by width and height respectively, and then multiply by 2 (the distance from -1 to 1), which gives us the following matrix.

$$\begin{bmatrix} 2/w & 0 & 0 \\ 0 & 2/h & 0 \\ 0 & 0 & 0 \end{bmatrix}$$

<< [Per-Pixel Attributes] [Index] [Textured Quad] >>