3D Projection: Orthographic Projection
We need to derive a projection matrix, as alluded to in the previous post. The orthographic is the simplest to start with, but we’ll move on to a perspective projection in a subsequent post. I want to use a perspective projection for the WebGPU game series, to make the environment a little bit more interesting.
What is an orthographic projection?
An orthographic projection is one in which objects in the distance do not appear smaller than objects that are nearby. This is not true to how we experience the natural world around us1. However, it is common for stylistic applications or for computer-aided design (CAD) software. The following is a representation of an orthographic projection compared to a perspective projection.
In both cases, the volume is transformed into a cube volume with specific dimensions – the canonical view volume. As you can imagine, this doesn’t really distort the orthographic projection, but it heavily influences the perspective projection.
Desired outcome
We want to map the cube into the following ranges, assuming a left-handed coordinate system.
However, assume we have some orthographic camera that is not centered on the axis and scaled to suit these requirements such as the following:
Derivation
We want to shift the cube to the center and scale it to fit within the ranges specified above.
Steps
We want to perform the following steps (in order):
-
Translate the center, , of the near plane to the origin:
-
Scale the volume to the size of the canonical view volume, :
Therefore, we can calculate the orthographic projection matrix, , as:
There are some additional reductions that can be made, but that’s essentially the orthographic projection matrix. For example, if using this as your projection matrix, you may simply want to store the near, far, screen width and screen height values. Then, you simply create this matrix from the specified values when doing the full MVP transformation.
Footnotes
-
Otherwise cosmic background radiation would have been really obvious (given we could also perceive microwave radiation). ↩