The objective of this step is to find a transformation matrix to transform points expressed in normalized device coordinates to screen coordinates
The canonical view volume needs to be mapped to the screen that has $n_x \times n_y$ pixels in a way so that points with $x = -1, x = 1$ are mapped to the left and right sides of the screen respectively and $y = -1, y = 1$ are mapped to the bottom and top sides of the screen respectively, the $z$ coordinate isn’t visible in a 2D image so it can be discarded for the mapping
Since the mapping is linear we can use the linear interpolation method
Given
- $out_{lo} = -0.5$
- $out_{hi} = n_x - 0.5$
- $in_{lo} = -1$
- $in_{hi} = 1$
The value of $x_{screen}$ is
The value of $y_{screen}$ is found in a similar way
Finally the transformation matrix that converts points from NDC to screen coordinates is
Note that the $z$-coordinate doesn’t need to be modified since it doesn’t affect the projection in the image, the $z$-coordinate is still used to check the order in which objects should be drawn