A Comprehensive Guide To Projection Matrices In Computer Graphics Constructing Projection Matrices Using Matrix Representations Of Projective Transformations In Real Projective Space
September 11, 2024
Abstract¶ We derive perspective projection and orthographic projection matrices from first principles using projective geometry. After establishing the topological manifold structure of real projective space, we find matrix representations for linear, affine, and projective transformations in real projective space. We then formulate the projection specifications in a coordinate-independent manner, leading to general formulas for perspective and orthographic projection matrices. Finally, we apply these results to succinctly calculate the projection matrices for OpenGL, Vulkan, Metal, and DirectX. This process illustrates why real projective space is a convenient setting for solving computer graphics problems.
Keywords: computer-graphics computer-science linear-algebra rendering computer-vision geometric-modeling projective-geometry applied-computing ¶ Introduction ¶ We construct the perspective and orthographic projection matrices common to computer graphics in a
very general way. The usual parametrizations are defined with respect to specific coordinate system
and a specific canonical view volume, such that the view volume parameters define the view volume
planes directly in terms of coordinates. This is how most computer graphics books construct the
projection transformations.
Rendering is done in the manifold R P 3 \mathbb{RP}^{3} RP 3 in homogeneous coordinates for multiple reasons:
Affine transformations become linear transformations one dimension higher, so translations
can be treated like any other linear transformations. Transformations in R P 3 \mathbb{RP}^{3} RP 3 are well-defined under changes in scale, so we can handle
projective transformations in a unified fashion with affine transformations. Coordinate systems and scales become equivalent, allowing spatial simulation problems to be
expressed directly in a coordinate independent way. We can change coordinate systems to whatever coordinate system makes the problem at hand convenient to
work with. For very practical reasons, we can express the problem in a coordinate system that affords the best
numerical precision possible on the hardware. A platform such as OpenGL, Vulkan, DirectX, Metal, or WebGPU typically defines its normalized device
coordinate system as one that is a numerically favorable coordinate system. Any spatial computing
domain whose problems are formulated in Euclidean space can take advantage of the manifold
R P 3 \mathbb{RP}^{3} RP 3 . Such domains include computer graphics, computer vision, geometric modeling, and
robotics. In the context of computer graphics, the platform coordinate system is whichever one maps
the view volume in the viewing space to the canonical view volume defined by the platform interface.
In particular, the canonical view volume tends to be parametrized by either
[ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] [-1, 1] \times [-1, 1] \times [-1, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] or [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times \ [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] . In
either case, transforming the problem to a unit interval adds one free bit of extra precision when
working with floating point numbers. This maximizes the accuracy of floating point computations on
the GPU, including tasks such as intersection testing, depth testing, texture sampling, and clipping
algorithms.
We parametrize the view space view volume in a slightly different way than the usual one to
make the perspective view volume specification coordinate independent. This allows us to construct the
matrices for any specific view space coordinate system, perspective view volume, orthographic view volume,
normalized device coordinate system, and canonical view volume. We define a canonical set of transformations
where the view space is a left-handed orthonormal frame where the horizontal axis points right, the vertical
axis points up, and the depth axis points into the view volume, and a clip coordinate system with a
left-handed orthonormal frame where the horizontal axis points right, the vertical axis points up, and the
depth axis points into the view volume. We show how to construct a general perspective projection or
orthographic projection from any source view coordinate system to any target clip coordinate system.
The Topological Manifold Structure Of Real Projective Space ¶ This section establishes the topological structure and manifold structure of the real
projective space R P 3 \mathbb{RP}^{3} RP 3 . It can be skipped if the reader so desires.
We define real projective space R P 3 \mathbb{RP}^{3} RP 3 as follows. Define w 1 ∼ w 2 \mathbf{w_{1}} \sim \mathbf{w_{2}} w 1 ∼ w 2
if an only if there exists a nonzero real number λ ∈ R − { 0 } \lambda \in \mathbb{R} - \{0\} λ ∈ R − { 0 } such that
w 1 = λ w 2 \mathbf{w_{1}} = \lambda \mathbf{w_{2}} w 1 = λ w 2 . The relation ∼ \sim ∼ is an equivalence relation.
To prove this, we need to show that ∼ \sim ∼ is reflexive, symmetric, and transitive. For reflexivity,
trivially w = w \mathbf{w} = \mathbf{w} w = w so we can take λ = 1 \lambda = 1 λ = 1 which shows that
w ∼ w \mathbf{w} \sim \mathbf{w} w ∼ w . To show symmetry, suppose that w 1 ∼ w 2 \mathbf{w}_{1} \sim \mathbf{w}_{2} w 1 ∼ w 2 .
Then there exists λ ∈ R − { 0 } \lambda \in \mathbb{R} - \{ 0 \} λ ∈ R − { 0 } such that w 2 = λ w 1 \mathbf{w}_{2} = \lambda \mathbf{w}_{1} w 2 = λ w 1
implying that w 1 = 1 λ w 2 \mathbf{w}_{1} = \frac{1}{\lambda} \mathbf{w}_{2} w 1 = λ 1 w 2 hence w 2 ∼ w 1 \mathbf{w}_{2} \sim \mathbf{w}_{1} w 2 ∼ w 1 .
Now it remains to prove that ∼ \sim ∼ is transitive. Suppose that w 1 ∼ w 2 \mathbf{w}_{1} \sim \mathbf{w}_{2} w 1 ∼ w 2
and w 2 ∼ w 3 \mathbf{w}_{2} \sim \mathbf{w}_{3} w 2 ∼ w 3 . Then there exist real numbers
λ , μ ∈ R − { 0 } \mathbf{\lambda}, \mathbf{\mu} \in \mathbb{R} - \{ 0 \} λ , μ ∈ R − { 0 } such that w 2 = λ w 1 \mathbf{w}_{2} = \lambda \mathbf{w}_{1} w 2 = λ w 1
and w 3 = μ w 2 \mathbf{w}_{3} = \mu \mathbf{w}_{2} w 3 = μ w 2 . This implies that
w 3 = μ w 2 = μ ( λ w 1 ) = ( μ λ ) w 1 = μ λ w 1 \mathbf{w}_{3}
= \mu \mathbf{w}_{2}
= \mu \left( \lambda \mathbf{w}_{1} \right)
= \left( \mu \lambda \right) \mathbf{w}_{1}
= \mu \lambda \mathbf{w}_{1} w 3 = μ w 2 = μ ( λ w 1 ) = ( μ λ ) w 1 = μ λ w 1 implying that w 1 ∼ w 3 \mathbf{w}_{1} \sim \mathbf{w}_{3} w 1 ∼ w 3 . This proves transitivity. Therefore, ∼ \sim ∼ is
and equivalence relation.
We define the real projective space by R P 3 = ( R 4 − { 0 } ) / ∼ \mathbb{RP}^{3} = ( \mathbb{R}^{4} - \{ \mathbf{0}\} )/\sim RP 3 = ( R 4 − { 0 }) / ∼ .
The real projective space identifies lines through the origin in R 3 \mathbb{R}^{3} R 3 with points in
R P 3 \mathbb{RP}^{3} RP 3 .
Define a map
π : R 4 − { 0 } → R P 3 \pi : \mathbb{R}^{4} - \{\mathbf{0}\} \rightarrow \mathbb{RP}^{3} π : R 4 − { 0 } → RP 3 by
π ( P ) = [ P ] \pi\left( P \right) = \begin{bmatrix} P \end{bmatrix} π ( P ) = [ P ] where [ . ] [.] [ . ] on the right-hand side indicates the equivalence class of
( P T , w ) T \begin{pmatrix} P^{T}, w \end{pmatrix}^{T} ( P T , w ) T . The function π \pi π is surjective. To show this,
suppose that [ P ] [P] [ P ] is a homogeneous point in R P 3 \mathbb{RP}^{3} RP 3 . Since
[ P ] [P] [ P ] is an equivalence class, it is nonempty, so there is at least one element in [ P ] [P] [ P ] , namely
P P P itself. Since the map π \pi π maps elements to its equivalence class, we obtain
π ( P ) = [ P ] \pi(P) = [P] π ( P ) = [ P ] . Since the equivalence class [ P ] [P] [ P ] was chosen
arbitrarily, the function π \pi π is surjective.
Now that we have established that π \pi π is surjective, we can use π \pi π to define a topology on
R P 3 \mathbb{RP}^{3} RP 3 . We say that a set U ⊂ R P 3 U \subset \mathbb{RP}^{3} U ⊂ RP 3 is open if and only if
the inverse image π − 1 ( U ) \pi^{-1}(U) π − 1 ( U ) is open in R 4 \mathbb{R}^{4} R 4 . In particular, we define the topology
of R P 3 \mathbb{RP}^{3} RP 3 to be the quotient topology induced by π \pi π . The real projective
space R P 3 \mathbb{RP}^{3} RP 3 in conjunction with the quotient toplogy induced by π \pi π is a topological
space. The quotient topology automatically makes the surjection π \pi π a continuous function.
Now we want to create a topological manifold out of R P 3 \mathbb{RP}^{3} RP 3 . We need to define an atlas,
then show that the charts in the atlas are homeomorphic to open subsets of
R 3 − { 0 } \mathbb{R}^{3} - \{ \mathbf{0} \} R 3 − { 0 } . Then we need to show that the resulting atlas makes
R P 3 \mathbb{RP}^{3} RP 3 locally Euclidean. That is, every point in R P 3 \mathbb{RP}^{3} RP 3 has an open
neighborhood homeomorphic to R 3 − { 0 } \mathbb{R}^{3} - \{ \mathbf{0} \} R 3 − { 0 } . After that, we show that
R P 3 \mathbb{RP}^{3} RP 3 is Hausdorff and second countable. All of this together shows that
R P 3 \mathbb{RP}^{3} RP 3 is a topological 3-manifold.
For every i ∈ { 0 , 1 , 2 , 3 } i \in \{ 0, 1, 2, 3 \} i ∈ { 0 , 1 , 2 , 3 } , define the set U i U_{i} U i by
U i = { x ∈ R 4 − { 0 } ∣ x i ≠ 0 } U_{i} = \{ \mathbf{x} \in \mathbb{R}^{4} - \{ \mathbf{0} \} \mid x_{i} \neq 0 \} U i = { x ∈ R 4 − { 0 } ∣ x i = 0 } The set U i U_{i} U i is an open set in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } . To prove this, we will
show that U i U_{i} U i can be covered by open balls of elements in U i U_{i} U i . Suppose that
p ∈ U i \mathbf{p} \in U_{i} p ∈ U i . Let h = ∣ p ⋅ e ^ i ∣ = ∣ p i ∣ h = |\mathbf{p} \cdot \mathbf{\hat{e}}_{i}| = |p_{i}| h = ∣ p ⋅ e ^ i ∣ = ∣ p i ∣ be the distance
of the point p \mathbf{p} p from the hyperplane defined by x i = 0 x_{i} = 0 x i = 0 . Let
d = ∥ p ∥ = ∥ p − 0 ∥ d = \Vert \mathbf{p} \Vert = \Vert \mathbf{p} - \mathbf{0} \Vert d = ∥ p ∥ = ∥ p − 0 ∥ be the Euclidean norm of the vector
p \mathbf{p} p . Let r = min { d , h } r = \min \{ d, h \} r = min { d , h } and consider the open ball B r ( p ) B_{r}(\mathbf{p}) B r ( p ) in
R 4 \mathbb{R}^{4} R 4 . Choose q ∈ B r ( p ) \mathbf{q} \in B_{r}(\mathbf{p}) q ∈ B r ( p ) . By the triangle inequality
∥ q ∥ ≥ ∥ p ∥ − ∥ q − p ∥ > d − r ≥ d − d 2 = d 2 > 0. \Vert \mathbf{q} \Vert
\geq \Vert \mathbf{p} \Vert - \Vert \mathbf{q} - \mathbf{p} \Vert
> d - r
\geq d - \frac{d}{2}
= \frac{d}{2}
> 0. ∥ q ∥ ≥ ∥ p ∥ − ∥ q − p ∥ > d − r ≥ d − 2 d = 2 d > 0. Hence q ∈ R 4 − { 0 } \mathbf{q} \in \mathbb{R}^{4} - \{ \mathbf{0} \} q ∈ R 4 − { 0 } . Since q \mathbf{q} q was chosen arbitrarily,
this implies that B r ( p ) ⊂ R 4 − { 0 } B_{r}(\mathbf{p}) \subset \mathbb{R}^{4} - \{ \mathbf{0} \} B r ( p ) ⊂ R 4 − { 0 } .
Applying the triangle inequality again,
∣ q i ∣ ≥ ∣ p i ∣ − ∣ q i − p i ∣ > h − r ≥ h − h 2 = h 2 > 0. |q_{i}| \geq |p_{i}| - |q_{i} - p_{i}| > h - r \geq h - \frac{h}{2} = \frac{h}{2} > 0. ∣ q i ∣ ≥ ∣ p i ∣ − ∣ q i − p i ∣ > h − r ≥ h − 2 h = 2 h > 0. Thus q \mathbf{q} q does not lie on the hyperplane defined by x i = 0 x_{i} = 0 x i = 0 . Therefore
q ∈ U i \mathbf{q} \in U_{i} q ∈ U i implying that B r ( p ) ⊂ U i B_{r}(\mathbf{p}) \subset U_{i} B r ( p ) ⊂ U i . Since the vector
p ∈ U i \mathbf{p} \in U_{i} p ∈ U i was arbitrary, every point in U i U_{i} U i lies in an open neighborhood
that contains only elements of U i U_{i} U i , we see that
⋃ p ∈ U i B r ( p ) ( p ) = U i . \bigcup_{\mathbf{p} \in U_{i}} B_{r(\mathbf{p})}(\mathbf{p}) = U_{i}. p ∈ U i ⋃ B r ( p ) ( p ) = U i . The open balls constructed above cover U i U_{i} U i in open sets. Since R 4 \mathbb{R}^{4} R 4 is a
topological space, and U i U_{i} U i is the union of open sets in the topology of R 4 \mathbb{R}^{4} R 4 ,
then U i U_{i} U i is an open set in R 4 \mathbb{R}^{4} R 4 . Moreover, since R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 }
is an open set in R 4 \mathbb{R}^{4} R 4 , the set U i U_{i} U i is an open set of R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } in
the subspace topology that R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } inherits from R 4 \mathbb{R}^{4} R 4 .
Define the set V i ⊂ R P 3 V_{i} \subset \mathbb{RP}^{3} V i ⊂ RP 3 by V i = π ( U i ) V_{i} = \pi\left(U_{i}\right) V i = π ( U i ) . The set
V i V_{i} V i is open in R P 3 \mathbb{RP}^{3} RP 3 . To show this, observe the following equalities
π − 1 ( V i ) = π − 1 ( π ( U i ) ) = { p ∈ R 4 − { 0 } ∣ π ( p ) ∈ V i } = { p ∈ R 4 − { 0 } ∣ ∃ λ ∈ R − { 0 } such that p ∈ λ U i } = U i \begin{align*}
\pi^{-1}\left( V_{i} \right)
&= \pi^{-1}\left( \pi\left( U_{i} \right) \right) \\
&= \{ \mathbf{p} \in \mathbb{R}^{4} - \{ \mathbf{0} \} \mid \pi\left( \mathbf{p} \right) \in V_{i} \} \\
&= \{ \mathbf{p} \in \mathbb{R}^{4} - \{ \mathbf{0} \} \mid \exists \lambda \in \mathbb{R} - \{ 0 \} \hspace{4 pt} \text{such that} \hspace{4 pt} \mathbf{p} \in \lambda U_{i} \} \\
&= U_{i}
\end{align*} π − 1 ( V i ) = π − 1 ( π ( U i ) ) = { p ∈ R 4 − { 0 } ∣ π ( p ) ∈ V i } = { p ∈ R 4 − { 0 } ∣ ∃ λ ∈ R − { 0 } such that p ∈ λ U i } = U i where the last equality follows because the preimage of any element in V i V_{i} V i contains all nonzero
multiples of an element of U i U_{i} U i , which are still an elements of U i U_{i} U i . Therefore, the set
π − 1 ( V i ) \pi^{-1}(V_{i}) π − 1 ( V i ) is an open set in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } , which makes V i V_{i} V i
an open set in R P 3 \mathbb{RP}^{3} RP 3 under the quotient topology.
For each i ∈ { 0 , 1 , 2 , 3 } i \in \{ 0, 1, 2, 3 \} i ∈ { 0 , 1 , 2 , 3 } define the map π i : U i → V i \pi_{i} : U_{i} \rightarrow V_{i} π i : U i → V i by
π i = π ∣ U i \pi_{i} = \pi|_{U_{i}} π i = π ∣ U i . Since the map π i \pi_{i} π i is the restriction of a continuous map, it is also a
continuous map. It is surjective by definition, since the codomain is the image π ( U i ) \pi(U_{i}) π ( U i ) .
To show that π i \pi_{i} π i is a quotient map, we must prove that a subset W ⊂ V i W \subset V_{i} W ⊂ V i is open
in V i V_{i} V i if and only if π i − 1 ( W ) \pi^{-1}_{i}(W) π i − 1 ( W ) is open in U i U_{i} U i . Suppose that W W W is
open in V i V_{i} V i . Then the inverse image of W W W under π \pi π is open in
R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } . Since U i U_{i} U i is open in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 }
we see that π i − 1 ( W ) = π − 1 ( W ) ∩ U i \pi^{-1}_{i}(W) = \pi^{-1}(W) \cap U_{i} π i − 1 ( W ) = π − 1 ( W ) ∩ U i . Since W W W is open in V i V_{i} V i , there exists an
open set X ⊂ R P 3 X \subset \mathbb{RP}^{3} X ⊂ RP 3 such that W = X ∩ V i W = X \cap V_{i} W = X ∩ V i . Since π \pi π is continuous,
π − 1 ( X ) \pi^{-1}(X) π − 1 ( X ) is open in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } , which implies that π − 1 ( X ) ∩ U i \pi^{-1}(X) \cap U_{i} π − 1 ( X ) ∩ U i
is open in U i U_{i} U i . But
π − 1 ( X ) ∩ U i = π − 1 ( X ∩ V i ) ∩ U i = π − 1 ( W ) ∩ U i = π i − 1 ( W ) \pi^{-1}\left( X \right) \cap U_{i}
= \pi^{-1}\left( X \cap V_{i} \right) \cap U_{i}
= \pi^{-1}\left( W \right) \cap U_{i}
= \pi^{-1}_{i}\left( W \right) π − 1 ( X ) ∩ U i = π − 1 ( X ∩ V i ) ∩ U i = π − 1 ( W ) ∩ U i = π i − 1 ( W ) which is an open set in U i U_{i} U i . Thus π i − 1 ( W ) \pi^{-1}_{i}(W) π i − 1 ( W ) is an open set in U i U_{i} U i . This
proves that if W ⊂ V i W \subset V_{i} W ⊂ V i is open, then π − 1 ( W ) ⊂ U i \pi^{-1}(W) \subset U_{i} π − 1 ( W ) ⊂ U i is open. Conversely, suppose
that π i − 1 ( W ) \pi^{-1}_{i}(W) π i − 1 ( W ) is open in U i U_{i} U i . Since U i U_{i} U i is open in
R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } , there exists an open set X X X of R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 }
such that π i − 1 ( W ) = X ∩ U i \pi^{-1}_{i}(W) = X \cap U_{i} π i − 1 ( W ) = X ∩ U i . Define the set X ′ = X ∪ ( ( R 4 − { 0 } ) − U i ) X^{\prime} = X \cup ((\mathbb{R}^{4} - \{ \mathbf{0} \}) - U_{i}) X ′ = X ∪ (( R 4 − { 0 }) − U i ) .
We show that the set X ′ X^{\prime} X ′ is open in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } .
Suppose that q ∈ ( R 4 − { 0 } ) − U i \mathbf{q} \in (\mathbb{R}^{4} - \{ \mathbf{0} \}) - U_{i} q ∈ ( R 4 − { 0 }) − U i . We can find a radius r > 0 r > 0 r > 0
such that B r ( q ) B_{r}(\mathbf{q}) B r ( q ) does not intersect U i U_{i} U i such that B r ( q ) ∩ U i = ∅ B_{r}(\mathbf{q}) \cap U_{i} = \emptyset B r ( q ) ∩ U i = ∅ .
Indeed, we can choose r r r to be less than the distance to the nearest point where the i t h i^{th} i t h coordinate
is zero, i.e. r < ∣ q i ∣ r < |q_{i}| r < ∣ q i ∣ . Choose r = ∣ q i ∣ / 2 r = |q_{i}| / 2 r = ∣ q i ∣/2 for concreteness. With the chosen r r r , we have
B r ( q ) ⊂ R 4 − { 0 } − U i B_{r}(\mathbf{q}) \subset \mathbb{R}^{4} - \{ \mathbf{0} \} - U_{i} B r ( q ) ⊂ R 4 − { 0 } − U i for each
q ∈ R 4 − { 0 } − U i \mathbf{q} \in \mathbb{R}^{4} - \{ \mathbf{0} \} - U_{i} q ∈ R 4 − { 0 } − U i . This shows that
R 4 − { 0 } − U i \mathbb{R}^{4} - \{ \mathbf{0} \} - U_{i} R 4 − { 0 } − U i is open in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } .
Since X ′ X^{\prime} X ′ is the union of two open sets, it is also open. The set X ′ X^{\prime} X ′ is open and
saturated with respect to π \pi π , so that image π ( X ′ ) \pi(X^{\prime}) π ( X ′ ) is open in R P 3 \mathbb{RP}^{3} RP 3 because
π \pi π is a quotient map. We have
W = π i ( π i − 1 ( W ) ) = π i ( X ∩ U i ) = π ( X ′ ) ∩ V i . W = \pi_{i}(\pi^{-1}_{i}\left( W \right)) = \pi_{i}\left( X \cap U_{i} \right) = \pi\left( X^{\prime} \right) \cap V_{i}. W = π i ( π i − 1 ( W ) ) = π i ( X ∩ U i ) = π ( X ′ ) ∩ V i . and it follows that π i − 1 ( W ) \pi^{-1}_{i}(W) π i − 1 ( W ) is open in R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } . This demonstrates
that π i \pi_{i} π i is a quotient map.
We show that each set V i V_{i} V i is homeomorphic to R 4 \mathbb{R}^{4} R 4 . For each i ∈ { 0 , 1 , 2 , 3 } i \in \{ 0, 1, 2, 3 \} i ∈ { 0 , 1 , 2 , 3 } ,
define the map H i : V i → R P 3 H_{i} : V_{i} \rightarrow \mathbb{RP}^{3} H i : V i → RP 3 by
H i ( [ ( P 0 P 1 ⋮ P i − 1 P i P i + 1 ⋮ P 3 ) ] ) = [ ( P 0 / P i P 1 / P i ⋮ P i − 1 / P i 1 P i + 1 / P i ⋮ P 3 / P i ) ] . H_{i} \left(
\begin{bmatrix}
\begin{pmatrix}
P_{0} \\
P_{1} \\
\vdots \\
P_{i - 1} \\
P_{i} \\
P_{i + 1} \\
\vdots \\
P_{3} \\
\end{pmatrix}
\end{bmatrix}
\right)
= \begin{bmatrix}
\begin{pmatrix}
P_{0} / P_{i} \\
P_{1} / P_{i} \\
\vdots \\
P_{i-1} / P_{i} \\
1 \\
P_{i+1} / {P_{i}} \\
\vdots \\
P_{3} / P_{i} \\
\end{pmatrix}
\end{bmatrix}. H i ⎝ ⎛ ⎣ ⎡ ⎝ ⎛ P 0 P 1 ⋮ P i − 1 P i P i + 1 ⋮ P 3 ⎠ ⎞ ⎦ ⎤ ⎠ ⎞ = ⎣ ⎡ ⎝ ⎛ P 0 / P i P 1 / P i ⋮ P i − 1 / P i 1 P i + 1 / P i ⋮ P 3 / P i ⎠ ⎞ ⎦ ⎤ . That is, the i t h i^{th} i t h coordinate is 1, and the rest are divided by P i P_{i} P i . This map sends
a homogeneous point to the homogeneous point with the i t h i^{th} i t h coordinate normalized. Let W i W_{i} W i
be the set of points in R P 3 \mathbb{RP}^{3} RP 3 whose i t h i^{th} i t h coordinate is 1. Define the map
proj i : R P 3 ⊃ W i → R 3 \text{proj}_{i} : \mathbb{RP}^{3} \supset W_{i} \rightarrow \mathbb{R}^3 proj i : RP 3 ⊃ W i → R 3 by
proj i ( [ ( P 0 P 1 ⋮ P i − 1 1 P i + 1 ⋮ P 3 ) ] ) = ( P 0 P 1 ⋮ P i − 1 P i + 1 ⋮ P 3 ) \text{proj}_{i}
\left(
\begin{bmatrix}
\begin{pmatrix}
P_{0} \\
P_{1} \\
\vdots \\
P_{i-1} \\
1 \\
P_{i+1} \\
\vdots \\
P_{3} \\
\end{pmatrix}
\end{bmatrix}
\right)
=
\begin{pmatrix}
P_{0} \\
P_{1} \\
\vdots \\
P_{i-1} \\
P_{i+1} \\
\vdots \\
P_{3} \\
\end{pmatrix} proj i ⎝ ⎛ ⎣ ⎡ ⎝ ⎛ P 0 P 1 ⋮ P i − 1 1 P i + 1 ⋮ P 3 ⎠ ⎞ ⎦ ⎤ ⎠ ⎞ = ⎝ ⎛ P 0 P 1 ⋮ P i − 1 P i + 1 ⋮ P 3 ⎠ ⎞ which maps the homogeneous point to a Euclidean point with the i t h i^{th} i t h component removed.
The maps proj i \text{proj}_{i} proj i and H i H_{i} H i together allow us to define our coordinate maps. Define the map
ψ i : V i → R 3 \psi_{i} : V_{i} \rightarrow \mathbb{R}^{3} ψ i : V i → R 3 by ψ i = proj i ∘ H i \psi_{i} = \text{proj}_{i} \circ H_{i} ψ i = proj i ∘ H i ,
written out as
ψ i ( [ ( P 0 P 1 ⋮ P i − 1 P i P i + 1 ⋮ P 3 ) ] ) = ( P 0 / P i P 1 / P i ⋮ P i − 1 / P i P i + 1 / P i ⋮ P 3 / P i ) . \psi_{i}
\left(
\begin{bmatrix}
\begin{pmatrix}
P_{0} \\
P_{1} \\
\vdots \\
P_{i - 1} \\
P_{i} \\
P_{i + 1} \\
\vdots \\
P_{3} \\
\end{pmatrix}
\end{bmatrix}
\right)
=
\begin{pmatrix}
P_{0} / P_{i} \\
P_{1} / P_{i} \\
\vdots \\
P_{i-1} / P_{i} \\
P_{i+1} / {P_{i}} \\
\vdots \\
P_{3} / P_{i} \\
\end{pmatrix}. ψ i ⎝ ⎛ ⎣ ⎡ ⎝ ⎛ P 0 P 1 ⋮ P i − 1 P i P i + 1 ⋮ P 3 ⎠ ⎞ ⎦ ⎤ ⎠ ⎞ = ⎝ ⎛ P 0 / P i P 1 / P i ⋮ P i − 1 / P i P i + 1 / P i ⋮ P 3 / P i ⎠ ⎞ . Let φ i : U i → R 3 \varphi_{i} : U_{i} \rightarrow \mathbb{R}^{3} φ i : U i → R 3 be given by φ i = ψ i ∘ π \varphi_{i} = \psi_{i} \circ \pi φ i = ψ i ∘ π ,
written out as
φ i ( ( P 0 P 1 ⋮ P i − 1 P i P i + 1 ⋮ P 3 ) ) = ( P 0 / P i P 1 / P i ⋮ P i − 1 / P i P i + 1 / P i ⋮ P 3 / P i ) . \varphi_{i}
\left(
\begin{pmatrix}
P_{0} \\
P_{1} \\
\vdots \\
P_{i - 1} \\
P_{i} \\
P_{i + 1} \\
\vdots \\
P_{3} \\
\end{pmatrix}
\right)
=
\begin{pmatrix}
P_{0} / P_{i} \\
P_{1} / P_{i} \\
\vdots \\
P_{i-1} / P_{i} \\
P_{i+1} / {P_{i}} \\
\vdots \\
P_{3} / P_{i} \\
\end{pmatrix}. φ i ⎝ ⎛ ⎝ ⎛ P 0 P 1 ⋮ P i − 1 P i P i + 1 ⋮ P 3 ⎠ ⎞ ⎠ ⎞ = ⎝ ⎛ P 0 / P i P 1 / P i ⋮ P i − 1 / P i P i + 1 / P i ⋮ P 3 / P i ⎠ ⎞ . The map φ i \varphi_{i} φ i is continuous by the universal property of product spaces applied to R 4 \mathbb{R}^{4} R 4 .
Since the map φ i \varphi_{i} φ i is continuous, the universal property of quotient maps implies that the map
ψ i \psi_{i} ψ i is continuous. We must show that ψ i \psi_{i} ψ i is bijective. Let’s prove surjectivity: let
( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T ∈ R 3 \begin{pmatrix} P_{0} \ P_{1} \ \dots \ P_{i-1} \ P_{i+1} \ \dots & P_{3} \end{pmatrix}^{T} \in \mathbb{R}^{3} ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T ∈ R 3 ,
let
[ ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) ] T ∈ V i \begin{bmatrix} \begin{pmatrix} P_{0} \ P_{1} \ \dots \ P_{i-1} \ 1 \ P_{i+1} \dots \ P_{3} \end{pmatrix} \end{bmatrix}^{T} \in V_{i} [ ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) ] T ∈ V i ,
From the definition of ψ i \psi_{i} ψ i , we see that
ψ i ( [ ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) ] T ) = ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T . \psi_{i}
\left(
\begin{bmatrix}
\begin{pmatrix}
P_{0} \
P_{1} \
\dots \
P_{i - 1} \
1 \
P_{i + 1} \
\dots \
P_{3} \
\end{pmatrix}
\end{bmatrix}^{T}
\right)
=
\begin{pmatrix}
P_{0} \
P_{1} \
\dots \
P_{i-1} \
P_{i+1} \
\dots \
P_{3} \
\end{pmatrix}^{T}. ψ i ( [ ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) ] T ) = ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T . which establishes surjectivity. To show injectivity, we require the following fact: every element in V i V_{i} V i
has a unique representative whose i t h i^{th} i t h coordinate is 1. To see this, suppose that [ Q ] [Q] [ Q ] is a
homogeneous point in V i V_{i} V i with representatives
( Q 0 Q 1 … Q i − 1 1 Q i + 1 … Q 3 ) T ∈ R 3 \begin{pmatrix} Q_{0} \ Q_{1} \ \dots \ Q_{i-1} \ 1 \ Q_{i+1} \dots \ Q_{3} \end{pmatrix}^{T} \in \mathbb{R}^{3} ( Q 0 Q 1 … Q i − 1 1 Q i + 1 … Q 3 ) T ∈ R 3
and
( Q 0 ′ Q 1 ′ … Q i − 1 ′ 1 Q i + 1 ′ … Q 3 ′ ) T ∈ R 3 \begin{pmatrix} Q^{\prime}_{0} \ Q^{\prime}_{1} \ \dots \ Q^{\prime}_{i-1} \ 1 \ Q^{\prime}_{i+1} \dots \ Q^{\prime}_{3} \end{pmatrix}^{T} \in \mathbb{R}^{3} ( Q 0 ′ Q 1 ′ … Q i − 1 ′ 1 Q i + 1 ′ … Q 3 ′ ) T ∈ R 3
where the i t h i^{th} i t h component is 1. Since both representatives represent the same point, they
must be equivalent, i.e. there exists λ ∈ R − { 0 } \lambda \in \mathbb{R} - \{0\} λ ∈ R − { 0 } such that
( Q 0 Q 1 … Q i − 1 1 Q i + 1 … Q 3 ) T = λ ( Q 0 ′ Q 1 ′ … Q i − 1 ′ 1 Q i + 1 ′ … Q 3 ′ ) T . \begin{pmatrix} Q_{0} \ Q_{1} \ \dots \ Q_{i-1} \ 1 \ Q_{i+1} \dots \ Q_{3} \end{pmatrix}^{T}
=
\lambda
\begin{pmatrix} Q^{\prime}_{0} \ Q^{\prime}_{1} \ \dots \ Q^{\prime}_{i-1} \ 1 \ Q^{\prime}_{i+1} \dots \ Q^{\prime}_{3} \end{pmatrix}^{T}. ( Q 0 Q 1 … Q i − 1 1 Q i + 1 … Q 3 ) T = λ ( Q 0 ′ Q 1 ′ … Q i − 1 ′ 1 Q i + 1 ′ … Q 3 ′ ) T . The fact that the i t h i^{th} i t h component is 1 in both representatives implies that
Q j ′ = Q j Q^{\prime}_{j} = Q_{j} Q j ′ = Q j for each j ∈ { 0 , 1 , 2 , 3 } j \in \{ 0, 1, 2, 3 \} j ∈ { 0 , 1 , 2 , 3 } . Therefore
( Q 0 Q 1 … Q i − 1 1 Q i + 1 … Q 3 ) T = ( Q 0 ′ Q 1 ′ … Q i − 1 ′ 1 Q i + 1 ′ … Q 3 ′ ) T . \begin{pmatrix} Q_{0} \ Q_{1} \ \dots \ Q_{i-1} \ 1 \ Q_{i+1} \dots \ Q_{3} \end{pmatrix}^{T}
=
\begin{pmatrix} Q^{\prime}_{0} \ Q^{\prime}_{1} \ \dots \ Q^{\prime}_{i-1} \ 1 \ Q^{\prime}_{i+1} \dots \ Q^{\prime}_{3} \end{pmatrix}^{T}. ( Q 0 Q 1 … Q i − 1 1 Q i + 1 … Q 3 ) T = ( Q 0 ′ Q 1 ′ … Q i − 1 ′ 1 Q i + 1 ′ … Q 3 ′ ) T . establishing uniqueness of the representative of [ Q ] [Q] [ Q ] whose i t h i^{th} i t h component is 1.
Proving the injectivity of ψ i \psi_{i} ψ i becomes easy. Recall the original definition of ψ i \psi_{i} ψ i as
ψ i = proj i ∘ H i \psi_{i} = \text{proj}_{i} \circ H_{i} ψ i = proj i ∘ H i . Since a given homogeneous point has a unique representative whose
i t h i^{th} i t h component is 1, the normalization map H i H_{i} H i is injective. That is, given homogeneous
points [ Q ] [Q] [ Q ] and [ Q ′ ] [Q^{\prime}] [ Q ′ ] with H i ( [ Q ] ) = H i ( [ Q ′ ] ) H_{i}([Q]) = H_{i}([Q^{\prime}]) H i ([ Q ]) = H i ([ Q ′ ]) , we conclude
[ Q ] = [ Q ′ ] [Q] = [Q^{\prime}] [ Q ] = [ Q ′ ] . Also, notice that proj i \text{proj}_{i} proj i is bijective with inverse map
proj i − 1 : R 3 → R P 3 \text{proj}^{-1}_{i} : \mathbb{R}^{3} \rightarrow \mathbb{RP}^{3} proj i − 1 : R 3 → RP 3 defined by
proj i − 1 ( ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T ) = [ ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) T ] . \text{proj}^{-1}_{i}
\left(
\begin{pmatrix}
P_{0} \
P_{1} \
\dots \
P_{i-1} \
P_{i+1} \
\dots \
P_{3} \
\end{pmatrix}^{T}
\right)
=
\begin{bmatrix}
\begin{pmatrix}
P_{0} \
P_{1} \
\dots \
P_{i-1} \
1 \
P_{i+1} \
\dots \
P_{3} \
\end{pmatrix}^{T}
\end{bmatrix}. proj i − 1 ( ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T ) = [ ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) T ] . Since proj i \text{proj}_{i} proj i is bijective, it is injective, and since H i H_{i} H i is injective, so is
their composite ψ i \psi_{i} ψ i . This proves that ψ i \psi_{i} ψ i is bijective.
Next, we show that ψ i − 1 \psi^{-1}_{i} ψ i − 1 is continuous. Consider the map
ρ i : R 3 → R 4 − { 0 } \rho_{i} : \mathbb{R}^{3} \rightarrow \mathbb{R}^{4} - \{ \mathbf{0} \} ρ i : R 3 → R 4 − { 0 } given by
ρ i ( ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T ) = ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) T . \rho_{i}
\left(
\begin{pmatrix}
P_{0} \
P_{1} \
\dots \
P_{i-1} \
P_{i+1} \
\dots \
P_{3} \
\end{pmatrix}^{T}
\right)
=
\begin{pmatrix}
P_{0} \
P_{1} \
\dots \
P_{i-1} \
1 \
P_{i+1} \
\dots \
P_{3} \
\end{pmatrix}^{T}. ρ i ( ( P 0 P 1 … P i − 1 P i + 1 … P 3 ) T ) = ( P 0 P 1 … P i − 1 1 P i + 1 … P 3 ) T . The map ρ i \rho_{i} ρ i is continuous, its image is contained in V i V_{i} V i , and
π i ∘ ρ i = ψ i − 1 \pi_{i} \circ \rho_{i} = \psi^{-1}_{i} π i ∘ ρ i = ψ i − 1 . This implies that ψ i − 1 \psi^{-1}_{i} ψ i − 1 is continuous, since
it is the composite of continuous functions. We have shown that ψ i \psi_{i} ψ i is continuous, bijective,
and has a continuous inverse. Therefore, it is a homeomorphism. Moreover, we can cover R P 3 \mathbb{RP}^{3} RP 3
with the charts { ( V i , ψ i ) ∣ i ∈ { 0 , 1 , 2 , 3 } } \{ (V_{i}, \psi_{i}) \mid i \in \{ 0, 1, 2, 3 \} \} {( V i , ψ i ) ∣ i ∈ { 0 , 1 , 2 , 3 }} , which means that
R P 3 \mathbb{RP}^{3} RP 3 is locally Euclidean.
We show that R P 3 \mathbb{RP}^{3} RP 3 is Hausdorff. Suppose that [ P ] [P] [ P ] and [ Q ] [Q] [ Q ] are two distinct
points in R P 3 \mathbb{RP}^{3} RP 3 . There are two possibilities: there is an 0 ≤ i ≤ 2 0 \leq i \leq 2 0 ≤ i ≤ 2 such that
both points lie in V i V_{i} V i , or no such i i i exists such that both points lie in V i V_{i} V i .
In the first case, ψ i ( [ P ] ) \psi_{i}([P]) ψ i ([ P ]) and ψ i ( [ Q ] ) \psi_{i}([Q]) ψ i ([ Q ]) are distinct points in R 3 \mathbb{R}^{3} R 3 .
Since R 3 \mathbb{R}^{3} R 3 is Hausdorff, there exist disjoint sets A A A and B B B such that
ψ i ( [ P ] ) ∈ A \psi_{i}([P]) \in A ψ i ([ P ]) ∈ A and ψ i ( [ Q ] ) ∈ B \psi_{i}([Q]) \in B ψ i ([ Q ]) ∈ B . Hence, ψ i − 1 ( A ) \psi^{-1}_{i}(A) ψ i − 1 ( A ) and ψ i − 1 \psi^{-1}_{i} ψ i − 1
are disjoint open subsets of V i V_{i} V i , and hence ψ i − 1 ( A ) \psi^{-1}_{i}(A) ψ i − 1 ( A ) and ψ i − 1 \psi^{-1}_{i} ψ i − 1 are open
subsets of R P 3 \mathbb{RP}^{3} RP 3 . This yields the first case. Consider the second case. Suppose that no
such i i i exists such that ψ i ( [ P ] ) \psi_{i}([P]) ψ i ([ P ]) and ψ i ( [ Q ] ) \psi_{i}([Q]) ψ i ([ Q ]) are distinct points in V i V_{i} V i .
Let ( x 0 , x 1 , x 2 , x 3 ) (x_{0}, x_{1}, x_{2}, x_{3}) ( x 0 , x 1 , x 2 , x 3 ) be a representative of [ P ] [P] [ P ] and let ( y 0 , y 1 , y 2 , y 3 ) (y_{0}, y_{1}, y_{2}, y_{3}) ( y 0 , y 1 , y 2 , y 3 )
be a representative of [ Q ] [Q] [ Q ] . There exists i ≠ j i \neq j i = j or 0 ≤ i , j ≤ 3 0 \leq i, j \leq 3 0 ≤ i , j ≤ 3 such that
x i ≠ 0 , y i = 0 x_{i} \neq 0, y_{i} = 0 x i = 0 , y i = 0 and x j = 0 , y j ≠ 0 x_{j} = 0, y_{j} \neq 0 x j = 0 , y j = 0 . Choose a representative such that x i = 1 x_{i} = 1 x i = 1
and y j = 1 y_{j} = 1 y j = 1 . Assume without loss of generality that i < j i < j i < j , and choose 0 < ϵ < 1 0 < \epsilon < 1 0 < ϵ < 1 .
The set
A = { ( a 0 a 1 … a i − 1 1 a i + 1 … a 3 ) T ∣ ∀ k ≠ i ∣ a k − x k ∣ < ϵ } ⊂ V i A = \{
\begin{pmatrix} a_{0} \ a_{1} \ \dots a_{i-1} \ 1 \ a_{i + 1} \dots a_{3} \end{pmatrix}^{T}
\mid
\forall k \neq i \hspace{4 pt} \lvert a_{k} - x_{k} \rvert < \epsilon
\}
\subset
V_{i} A = { ( a 0 a 1 … a i − 1 1 a i + 1 … a 3 ) T ∣ ∀ k = i ∣ a k − x k ∣ < ϵ } ⊂ V i is an open set containing [ P ] [P] [ P ] and the set
B = { ( b 0 b 1 … b j − 1 1 b j + 1 … b 3 ) T ∣ ∀ k ≠ i ∣ b k − y k ∣ < ϵ } ⊂ V j B = \{
\begin{pmatrix} b_{0} \ b_{1} \ \dots b_{j-1} \ 1 \ b_{j + 1} \dots b_{3} \end{pmatrix}^{T}
\mid
\forall k \neq i \hspace{4 pt} \lvert b_{k} - y_{k} \rvert < \epsilon
\}
\subset
V_{j} B = { ( b 0 b 1 … b j − 1 1 b j + 1 … b 3 ) T ∣ ∀ k = i ∣ b k − y k ∣ < ϵ } ⊂ V j is an open set containing [ Q ] [Q] [ Q ] . The image ψ i ( A ) \psi_{i}(A) ψ i ( A ) is an open rectangle in R 3 \mathbb{R}^{3} R 3
centered on ψ i ( [ P ] ) \psi_{i}([P]) ψ i ([ P ]) with a side length of 2 ϵ 2 \epsilon 2 ϵ . Similarly, the image ψ i ( B ) \psi_{i}(B) ψ i ( B ) is
an open rectangle in R 3 \mathbb{R}^{3} R 3 centered on ψ i ( [ Q ] ) \psi_{i}([Q]) ψ i ([ Q ]) with a side length of 2 ϵ 2 \epsilon 2 ϵ .
The sets A A A and B B B are disjoint. To show this, suppose A A A and B B B are not disjoint. Then for
( a 0 a 1 … a i − 1 1 a i + 1 … a 3 ) T = ( b 0 b 1 … b j − 1 1 b j + 1 … b 3 ) T \begin{pmatrix} a_{0} \ a_{1} \ \dots a_{i-1} \ 1 \ a_{i + 1} \dots a_{3} \end{pmatrix}^{T} = \begin{pmatrix} b_{0} \ b_{1} \ \dots b_{j-1} \ 1 \ b_{j + 1} \dots b_{3} \end{pmatrix}^{T} ( a 0 a 1 … a i − 1 1 a i + 1 … a 3 ) T = ( b 0 b 1 … b j − 1 1 b j + 1 … b 3 ) T
we must have a j ≠ 0 a_{j} \neq 0 a j = 0 and b i ≠ 0 b_{i} \neq 0 b i = 0 which implies that a j b i = 1 a_{j} b_{i} = 1 a j b i = 1 . But this is
impossible, because ∣ a j ∣ < 1 \lvert a_{j} \rvert < 1 ∣ a j ∣ < 1 and ∣ b i ∣ < 1 \lvert b_{i} \rvert < 1 ∣ b i ∣ < 1 .
Therefore, the sets A A A and B B B must be disjoint. This proves that R P 3 \mathbb{RP}^{3} RP 3 is Hausdorff.
Finally, second countability follows from the fact that R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } is
second countable. More precisely, let B \mathcal{B} B be a countable base for the topology on
R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } . The set
B ′ = { π ( U ) ∣ U ∈ B } \mathcal{B}^{\prime} = \{ \pi\left( U \right) \mid U \in \mathcal{B} \} B ′ = { π ( U ) ∣ U ∈ B } is a countable set of open sets in R P 3 \mathbb{RP}^{3} RP 3 because π \pi π is saturated. Since π \pi π
is surjective, ∪ B ∈ B ′ B = R P 3 \cup_{B \in \mathcal{B}^{\prime}} B = \mathbb{RP}^{3} ∪ B ∈ B ′ B = RP 3 , i.e. the set
B ′ \mathcal{B}^{\prime} B ′ covers R P 3 \mathbb{RP}^{3} RP 3 . Hence R P 3 \mathbb{RP}^{3} RP 3 is second countable.
Note that second countability implies that R P 3 \mathbb{RP}^{3} RP 3 is compact. We sketch a proof here.
It comes from the fact that the 3-sphere S 3 S^{3} S 3 is a compact subset of R 4 \mathbb{R}^{4} R 4 ,
that the canonical surjection π S 3 \pi_{S^{3}} π S 3 is continuous, and that the image of a compact set by a
continuous map is compact. Since π S 3 ( S 3 ) \pi_{S^{3}}(S^{3}) π S 3 ( S 3 ) is compact, and π S 3 ( S 3 ) = R P 3 \pi_{S^{3}}(S^{3}) = \mathbb{RP}^{3} π S 3 ( S 3 ) = RP 3
we immediately infer that R P 3 \mathbb{RP}^{3} RP 3 is compact.
We have topologized real projective space, and proven that R P 3 \mathbb{RP}^{3} RP 3 is second countable,
Hausdorff and locally Euclidean. Therefore R P 3 \mathbb{RP}^{3} RP 3 is a topological 3-manifold
(or we just say that it is a 3-manifold, or a manifold). Finally, R P 3 \mathbb{RP}^{3} RP 3 is
compact, so it is a nice setting to work with topologically.
The real projective space R P 3 \mathbb{RP}^{3} RP 3 is a compact topological manifold
R P 3 = ( R 4 − { 0 } ) / ∼ \mathbb{RP}^{3} = (\mathbb{R}^{4} - \{ \mathbf{0} \}) / \sim RP 3 = ( R 4 − { 0 }) / ∼ where the topology
is the quotient topology induced by the canonical surjection
π : R 3 → R P 3 \pi : \mathbb{R}^{3} \rightarrow \mathbb{RP}^{3} π : R 3 → RP 3 given by π ( P ) = [ P ] \pi(P) = [P] π ( P ) = [ P ] , and the atlas consists of charts which
normalize along one of the coordinates.
Any orthonormal frame ( O ~ f r a m e , ( u ^ h , u ^ v , u ^ d ) ) (\tilde{O}_{frame}, \left( \mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d} \right)) ( O ~ f r am e , ( u ^ h , u ^ v , u ^ d ) )
on E 3 \mathbb{E}^{3} E 3 induces a coordinate chart as follows. A point P ~ ∈ E 3 \tilde{P} \in \mathbb{E}^{3} P ~ ∈ E 3 is written as
P ~ = O ~ f r a m e + P h u ^ h + P v u ^ v + P d u ^ d \tilde{P} = \tilde{O}_{frame} + P_{h} \mathbf{\hat{u}}_{h} + P_{v} \mathbf{\hat{u}}_{v} + P_{d} \mathbf{\hat{u}}_{d} P ~ = O ~ f r am e + P h u ^ h + P v u ^ v + P d u ^ d and the orthonormal frame
( O ~ f r a m e , ( u ^ h , u ^ v , u ^ d ) ) (\tilde{O}_{frame}, \left( \mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d} \right)) ( O ~ f r am e , ( u ^ h , u ^ v , u ^ d ) )
defines a coordinate chart φ f r a m e : E 3 → R 3 \varphi_{frame} : \mathbb{E}^{3} \rightarrow \mathbb{R}^{3} φ f r am e : E 3 → R 3 by
φ f r a m e ( P ~ ) = P ~ − O ~ \varphi_{frame}( \tilde{P} ) = \tilde{P} - \tilde{O} φ f r am e ( P ~ ) = P ~ − O ~ . Written out
P = φ f r a m e ( P ~ ) ≡ P ~ − O ~ f r a m e = P h u ^ h + P v u ^ v + P d u ^ d P = \varphi_{frame}(\tilde{P}) \equiv \tilde{P} - \tilde{O}_{frame} = P_{h} \mathbf{\hat{u}}_{h} + P_{v} \mathbf{\hat{u}}_{v} + P_{d} \mathbf{\hat{u}}_{d} P = φ f r am e ( P ~ ) ≡ P ~ − O ~ f r am e = P h u ^ h + P v u ^ v + P d u ^ d is the representation of P ~ \tilde{P} P ~ in R 3 \mathbb{R}^{3} R 3 . Also, the coordinate chart
φ f r a m e \varphi_{frame} φ f r am e maps the origin O ~ f r a m e \tilde{O}_{frame} O ~ f r am e of the view coordinate system in E 3 \mathbb{E}^{3} E 3
to 0 \mathbf{0} 0 :
O f r a m e O_{frame} O f r am e = φ f r a m e ( O ~ f r a m e ) = O ~ f r a m e − O ~ f r a m e = 0 \varphi_{frame}(\tilde{O}_{frame}) = \tilde{O}_{frame} - \tilde{O}_{frame} = \mathbf{0} φ f r am e ( O ~ f r am e ) = O ~ f r am e − O ~ f r am e = 0 .
This shows that the view space frame origin in E 3 \mathbb{E}^{3} E 3 indeed maps to the vector space origin
0 \mathbf{0} 0 in R 3 \mathbb{R}^{3} R 3 .
Recall that the definition of real projective space defines the manifold structure using the surjection
π : R 4 − { 0 } → R P 3 \pi : \mathbb{R}^{4} - \{\mathbf{0}\} \rightarrow \mathbb{RP}^{3} π : R 4 − { 0 } → RP 3 given by
π ( ( P w ) ) = [ ( P w ) ] \pi\left( \begin{pmatrix} P \\ w \\ \end{pmatrix} \right) = \begin{bmatrix} \begin{pmatrix} P \\ w \\ \end{pmatrix} \end{bmatrix} π ( ( P w ) ) = [ ( P w ) ] where [ . ] [.] [ . ] on the right-hand side indicates the equivalence class of
( P T , w ) T \begin{pmatrix} P^{T}, w \end{pmatrix}^{T} ( P T , w ) T .
Define a map ρ : R 3 → R 4 − { 0 } \rho : \mathbb{R}^{3} \rightarrow \mathbb{R}^{4} - \{\mathbf{0}\} ρ : R 3 → R 4 − { 0 } by
ρ ( P ) = ( P 1 ) \rho\left( P \right) = \begin{pmatrix} P \\ 1 \\ \end{pmatrix} ρ ( P ) = ( P 1 ) The maps π \pi π and ρ \rho ρ together allow us to map from view space to
projective view space with the camera orthonormal frame by
( π ∘ ρ ) ( P ) = π ( ρ ( P ) ) = π ( ( P 1 ) ) = [ ( P 1 ) ] . \left(\pi \circ \rho\right)\left(P\right)
= \pi\left( \rho\left( P \right) \right)
= \pi\left( \begin{pmatrix} P \\ 1 \\ \end{pmatrix} \right)
= \begin{bmatrix} \begin{pmatrix} P \\ 1 \\ \end{pmatrix} \end{bmatrix}. ( π ∘ ρ ) ( P ) = π ( ρ ( P ) ) = π ( ( P 1 ) ) = [ ( P 1 ) ] . The map ρ \rho ρ defines an embedding (injection) of R 3 \mathbb{R}^{3} R 3 into R 4 − { 0 } \mathbb{R}^{4} - \{ \mathbf{0} \} R 4 − { 0 } ,
because each element in ρ ( R 3 ) \rho(\mathbb{R}^{3}) ρ ( R 3 ) has a unique elements P ∈ R 3 P \in \mathbb{R}^{3} P ∈ R 3 such that
ρ ( P ) = ( P T 1 ) T \rho(P) = \begin{pmatrix} P^{T} \ 1 \end{pmatrix}^{T} ρ ( P ) = ( P T 1 ) T . Since ρ \rho ρ is surjective on its image, injective, and
continuous with continuous inverse, it is a homeomorphism on its image, hence an embedding. Since every element
of R 3 \mathbb{R}^{3} R 3 has a unique homogeneous point Q Q Q such that
Q = [ ( P T 1 ) T ] Q = [\begin{pmatrix} P^{T} \ 1 \end{pmatrix}^{T}] Q = [ ( P T 1 ) T ] , the map π ∘ ρ \pi \circ \rho π ∘ ρ is also an embedding.
The set π ( ρ ( R 3 ) ) \pi(\rho(\mathbb{R}^{3})) π ( ρ ( R 3 )) is sometimes called the affine patch or Euclidean patch of
R P 3 \mathbb{RP}^{3} RP 3 .
We can lift points in E 3 \mathbb{E}^{3} E 3 into R P 3 \mathbb{RP}^{3} RP 3 . Let’s do the same for transformations.
Suppose that A : R 3 → R 3 A : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} A : R 3 → R 3 is an affine map. We define the lifted map
of A A A over to R P 3 \mathbb{RP}^{3} RP 3 to be the map
A ^ : R P 3 → R P 3 \hat{A} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} A ^ : RP 3 → RP 3 such that
( ρ ∘ A ) ( P ) = ( A ^ ∘ ρ ) ( P ) . \left( \rho \circ A \right)\left( P \right) = \left( \hat{A} \circ \rho \right) \begin{pmatrix} P \end{pmatrix}. ( ρ ∘ A ) ( P ) = ( A ^ ∘ ρ ) ( P ) . Recall that an affine map has the form A ( P ) = L ( P ) + t A(P) = L(P) + \mathbf{t} A ( P ) = L ( P ) + t where
L : R 3 → R 3 L : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} L : R 3 → R 3 is a linear map, and
t \mathbf{t} t is a vector, i.e. a linear map plus a translation term. Expanding this out,
the left-hand side of (27) becomes
( ρ ∘ A ) ( P ) = ( A ( P ) 1 ) = ( L ( P ) + t 1 ) = [ L t 0 T 1 ] ( P 1 ) \left( \rho \circ A \right)\left( P \right)
= \begin{pmatrix} A\left( P \right) \\ 1 \\ \end{pmatrix}
= \begin{pmatrix} L\left( P \right) + \mathbf{t} \\ 1 \\ \end{pmatrix}
= \begin{bmatrix} L & \mathbf{t} \\ \mathbf{0}^{T} & 1 \\ \end{bmatrix} \begin{pmatrix} P \\ 1 \\ \end{pmatrix} ( ρ ∘ A ) ( P ) = ( A ( P ) 1 ) = ( L ( P ) + t 1 ) = [ L 0 T t 1 ] ( P 1 ) and on the right-hand side we have
( A ^ ∘ ρ ) ( P ) = A ^ ( ρ ( P ) ) = A ^ ( ( P 1 ) ) . \left( \hat{A} \circ \rho \right) \left( P \right)
= \hat{A} \left(\rho \left( P \right) \right)
= \hat{A} \left( \begin{pmatrix} P \\ 1 \\ \end{pmatrix} \right). ( A ^ ∘ ρ ) ( P ) = A ^ ( ρ ( P ) ) = A ^ ( ( P 1 ) ) . Equating both sides of (27) we have
A ^ ( ( P 1 ) ) = [ L t 0 T 1 ] ( P 1 ) \hat{A} \left( \begin{pmatrix} P \\ 1 \\ \end{pmatrix} \right)
= \begin{bmatrix} L & \mathbf{t} \\ \mathbf{0}^{T} & 1 \\ \end{bmatrix} \begin{pmatrix} P \\ 1 \\ \end{pmatrix} A ^ ( ( P 1 ) ) = [ L 0 T t 1 ] ( P 1 ) or
A ^ = [ L t 0 T 1 ] \hat{A} = \begin{bmatrix} L & \mathbf{t} \\ \mathbf{0}^{T} & 1 \\ \end{bmatrix} A ^ = [ L 0 T t 1 ] so that A ^ \hat{A} A ^ is unique. An affine map in R 3 \mathbb{R}^{3} R 3 becomes a linear map in
R P 3 \mathbb{RP}^{3} RP 3 . In the case of a linear map L L L , t = 0 \mathbf{t} = \mathbf{0} t = 0 and
L ^ = [ L 0 0 T 1 ] . \hat{L} = \begin{bmatrix} L & \mathbf{0} \\ \mathbf{0}^{T} & 1 \\ \end{bmatrix}. L ^ = [ L 0 T 0 1 ] . Now suppose that T : R 3 → R 3 T : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} T : R 3 → R 3 is a projective transformation.
A projective transformation is a map of the form
T ( P ) = ( 1 g ( P ) ) A ( P ) = ( 1 g ( P ) ) ( L ( P ) + t ) T \left( P \right) = \left( \frac{1}{g(P)} \right) A \left( P \right) = \left( \frac{1}{g(P)} \right) \left( L(P) + \mathbf{t} \right) T ( P ) = ( g ( P ) 1 ) A ( P ) = ( g ( P ) 1 ) ( L ( P ) + t ) where A A A is an affine map and g : R 3 → R g : \mathbb{R}^{3} \rightarrow \mathbb{R} g : R 3 → R is an affine
scalar function. This means that g g g has the form g ( P ) = c ⋅ P + h g(P) = \mathbf{c} \cdot P + h g ( P ) = c ⋅ P + h . We define
the lifted map of T T T over to R P 3 \mathbb{RP}^{3} RP 3 to be the map
T ^ : R P 3 → R P 3 \hat{T} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} T ^ : RP 3 → RP 3 such that
g ( P ) ( ρ ∘ T ) ( P ) = ( T ^ ∘ ρ ) ( P ) g\left( P \right) \left( \rho \circ T \right) \left( P \right) = \left( \hat{T} \circ \rho \right) \left( P \right) g ( P ) ( ρ ∘ T ) ( P ) = ( T ^ ∘ ρ ) ( P ) Expanding out the right-hand side of (34)
( T ^ ∘ ρ ) ( P ) = T ^ ( ρ ( P ) ) = T ^ ( P 1 ) . \left( \hat{T} \circ \rho \right) \left( P \right)
= \hat{T} \left( \rho \left( P \right) \right)
= \hat{T} \begin{pmatrix} P \\ 1 \end{pmatrix}. ( T ^ ∘ ρ ) ( P ) = T ^ ( ρ ( P ) ) = T ^ ( P 1 ) . More interestingly, expanding out the left-hand side of (34) gives
g ( P ) ( ρ ∘ T ) ( P ) = g ( P ) ( T ( P ) 1 ) = ( g ( P ) T ( P ) g ( P ) ) = ( A ( P ) g ( P ) ) = ( L ( P ) + t g ( P ) ) = ( L ( P ) + t c ⋅ P + h ) = [ L t c T h ] ( P 1 ) \begin{align*}
g\left( P \right) \left( \rho \circ T \right) \left( P \right)
&= g\left( P \right) \begin{pmatrix} T(P) \\ 1 \end{pmatrix} \\
&= \begin{pmatrix} g\left( P \right) T(P) \\ g\left( P \right) \end{pmatrix} \\
&= \begin{pmatrix} A(P) \\ g\left( P \right) \end{pmatrix} \\
&= \begin{pmatrix} L(P) + \mathbf{t} \\ g\left( P \right) \end{pmatrix} \\
&= \begin{pmatrix} L(P) + \mathbf{t} \\ \mathbf{c} \cdot P + h \end{pmatrix} \\
&= \begin{bmatrix} L & \mathbf{t} \\ \mathbf{c}^{T} & h \\ \end{bmatrix} \begin{pmatrix} P \\ 1 \\ \end{pmatrix}
\end{align*} g ( P ) ( ρ ∘ T ) ( P ) = g ( P ) ( T ( P ) 1 ) = ( g ( P ) T ( P ) g ( P ) ) = ( A ( P ) g ( P ) ) = ( L ( P ) + t g ( P ) ) = ( L ( P ) + t c ⋅ P + h ) = [ L c T t h ] ( P 1 ) where the third equality follows from the definition of the projective transformation. Combining
(35) and (36) back into (34) yields
T ^ ( P 1 ) = [ L t c T h ] ( P 1 ) \hat{T} \begin{pmatrix} P \\ 1 \end{pmatrix}
= \begin{bmatrix} L & \mathbf{t} \\ \mathbf{c}^{T} & h \\ \end{bmatrix} \begin{pmatrix} P \\ 1 \\ \end{pmatrix} T ^ ( P 1 ) = [ L c T t h ] ( P 1 ) and therefore
T ^ = [ L t c T h ] . \hat{T} = \begin{bmatrix} L & \mathbf{t} \\ \mathbf{c}^{T} & h \\ \end{bmatrix}. T ^ = [ L c T t h ] . This is a unique representation of the projective transformation T T T lifted over to R P 3 \mathbb{RP}^{3} RP 3 .
Here is a wonderful discovery: in R P 3 \mathbb{RP}^{3} RP 3 where all coordinate scales are treated as equivalent,
we can work with linear, affine, and projective transformations in a unified setting by
going one dimension higher in our representation from T : R 3 → R 3 T : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} T : R 3 → R 3
to its lifted counterpart T ^ : R P 3 → R P 3 \hat{T} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} T ^ : RP 3 → RP 3 .
The punchline is that we can lift the Euclidean space E 3 \mathbb{E}^{3} E 3 into real projective space, in such
a way that each point in E 3 \mathbb{E}^{3} E 3 has a corresponding unique point in the affine subspace of
R P 3 \mathbb{RP}^{3} RP 3 under any coordinate chart. This lift allows us to construct our projections between
different coordinate systems in real projective space in a coherent and well-defined manner. Via the embedding
π ∘ ρ \pi \circ \rho π ∘ ρ , the manifold structure of R P 3 \mathbb{RP}^{3} RP 3 allows us to scale our coordinates in
any way we like, because in projective coordinates we don’t care about scaling. We can also lift transformations
from E 3 \mathbb{E}^{3} E 3 to R P 3 \mathbb{RP}^{3} RP 3 as a consequence of the embedding π ∘ ρ \pi \circ \rho π ∘ ρ too.
This setting makes it convenient to construct perspective and orthographic projections, because at the end, we are
back in the affine portion of R P 3 \mathbb{RP}^{3} RP 3 after normalization, so we can map back out of
R P 3 \mathbb{RP}^{3} RP 3 again by choosing a chart on R P 3 \mathbb{RP}^{3} RP 3 and applying it.
We have shown how to map Euclidean space to real projective space, and how to represent linear, affine,
and projective transformations as linear transformations in linear projective space. It remains to apply
these developments to our primary goal: constructing orthographic and perspective projection matrices
in homogeneous coordinates.
A linear transformation L : R 3 → R 3 L : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} L : R 3 → R 3 lifted over to
R P 3 \mathbb{RP}^{3} RP 3 is a linear map L ^ : R P 3 → R P 3 \hat{L} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} L ^ : RP 3 → RP 3 with
the matrix representation
L ^ = [ L 0 0 T 1 ] . \hat{L} = \begin{bmatrix} L & \mathbf{0} \\ \mathbf{0}^{T} & 1 \\ \end{bmatrix}. L ^ = [ L 0 T 0 1 ] . An affine transformation A : R 3 → R 3 A : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} A : R 3 → R 3 lifted over to
R P 3 \mathbb{RP}^{3} RP 3 is a linear map A ^ : R P 3 → R P 3 \hat{A} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} A ^ : RP 3 → RP 3 with
the matrix representation
A ^ = [ L t 0 T 1 ] . \hat{A} = \begin{bmatrix} L & \mathbf{t} \\ \mathbf{0}^{T} & 1 \\ \end{bmatrix}. A ^ = [ L 0 T t 1 ] . A projective transformation T : R 3 → R 3 T : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} T : R 3 → R 3 lifted over to
R P 3 \mathbb{RP}^{3} RP 3 is a linear map T ^ : R P 3 → R P 3 \hat{T} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} T ^ : RP 3 → RP 3 with
the matrix representation
T ^ = [ L t c T h ] . \hat{T} = \begin{bmatrix} L & \mathbf{t} \\ \mathbf{c}^{T} & h \\ \end{bmatrix}. T ^ = [ L c T t h ] . Specifying Projection Matrices ¶ To define a projection matrix, we need two coordinate systems: the view coordinate system, and the
normalized device coordinate system. The view coordinate system is where the view volume is defined.
The normalized device coordinate system is where the canonical view volume is defined. The task of
the projection transformation is to map the view volume to the canonical view volume.
To understand what the projection matrices do, we must understand the coordinate systems that
we map between at each step in the pipeline leading from the view space to the canonical view
volume. The transformations stem from choosing a convenient coordinate system
in which to render computer graphics. The convenient coordinate system we choose is often called
normalized device coordinates , defined in the following. The canonical coordinate system differs
from platform to platform. The other coordinates systems exist to articulate a clear path from projective
view coordinates to normalized device coordinates. First we must define the view space and the view coordinates.
The view coordinate system for Euclidean space E 3 \mathbb{E}^{3} E 3 is given by the
orthonormal frame ( O ~ v i e w , B v i e w ) (\tilde{O}_{view}, \mathcal{B}_{view}) ( O ~ v i e w , B v i e w ) where (1) the origin of the orthonormal frame is
the point O ~ v i e w ∈ E 3 \tilde{O}_{view} \in \mathbb{E}^{3} O ~ v i e w ∈ E 3 ; (2) the basis of the orthonormal frame is
B v i e w = ( u ^ h , u ^ v , u ^ d ) \mathcal{B}_{view} = (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d}) B v i e w = ( u ^ h , u ^ v , u ^ d ) where
the basis vector u ^ h \mathbf{\hat{u}}_{h} u ^ h points to the right, the basis vector u ^ v \mathbf{\hat{u}}_{v} u ^ v
points up, and the basis vector u ^ d \mathbf{\hat{u}}_{d} u ^ d points into the view volume or out of the
view volume, depending on the choice of orientation; (3) the view volume in this coordinate system is
called the view volume (or in the case of perspective projection, the perspective view volume ).
The projected coordinate system for Euclidean space E 3 \mathbb{E}^{3} E 3 is given by the
orthonormal frame ( O ~ p r o j , B p r o j ) (\tilde{O}_{proj}, \mathcal{B}_{proj}) ( O ~ p ro j , B p ro j ) where (1) the origin of the orthonormal frame is
the point O ~ p r o j ∈ E 3 \tilde{O}_{proj} \in \mathbb{E}^{3} O ~ p ro j ∈ E 3 ; (2) the basis of the orthonormal frame is
B p r o j = ( u ^ p r o j , h , u ^ p r o j , v , u ^ p r o j , d ) \mathcal{B}_{proj} = (\mathbf{\hat{u}}_{proj,h}, \mathbf{\hat{u}}_{proj,v}, \mathbf{\hat{u}}_{proj,d}) B p ro j = ( u ^ p ro j , h , u ^ p ro j , v , u ^ p ro j , d ) where
the basis vector u ^ p r o j , h \mathbf{\hat{u}}_{proj,h} u ^ p ro j , h points to the right, the basis vector u ^ p r o j , v \mathbf{\hat{u}}_{proj,v} u ^ p ro j , v
points up, and the basis vector u ^ p r o j , d \mathbf{\hat{u}}_{proj,d} u ^ p ro j , d points into the view volume or out of the
view volume, depending on the choice of orientation; (3) the view volume in this coordinate system is
called the projected view volume (or in the case of perspective projection, the
perspective projected view volume ).
The clip coordinate system for Euclidean space E 3 \mathbb{E}^{3} E 3 is given by the orthonormal frame
( O ~ c l i p , B c l i p ) (\tilde{O}_{clip}, \mathcal{B}_{clip}) ( O ~ c l i p , B c l i p ) defined on E 3 \mathbb{E}^{3} E 3 where (1) the origin of
the orthonormal frame ( O ~ c l i p , B c l i p ) (\tilde{O}_{clip}, \mathcal{B}_{clip}) ( O ~ c l i p , B c l i p ) is the point O ~ c l i p ∈ E 3 \tilde{O}_{clip} \in \mathbb{E}^{3} O ~ c l i p ∈ E 3 ;
(2) the basis of the orthonormal frame is
B c l i p = ( u ^ c l i p , h , u ^ c l i p , v , u ^ c l i p , d ) \mathcal{B}_{clip} = (\mathbf{\hat{u}}_{clip,h}, \mathbf{\hat{u}}_{clip,v}, \mathbf{\hat{u}}_{clip,d}) B c l i p = ( u ^ c l i p , h , u ^ c l i p , v , u ^ c l i p , d )
where the basis vector u ^ c l i p , h \mathbf{\hat{u}}_{clip,h} u ^ c l i p , h points to the right, the basis vector
u ^ c l i p , v \mathbf{\hat{u}}_{clip,v} u ^ c l i p , v points up, and the basis vector u ^ c l i p , d \mathbf{\hat{u}}_{clip,d} u ^ c l i p , d points into the
view volume, or out of the view volume depending on the choice or orientation; (3) the view volume in this
coordinate system is called the orthographic view volume .
The normalized device coordinate system for Euclidean space E 3 \mathbb{E}^{3} E 3 is given by the
orthonormal frame ( O ~ n d c , B n d c ) (\tilde{O}_{ndc}, \mathcal{B}_{ndc}) ( O ~ n d c , B n d c ) defined on E 3 \mathbb{E}^{3} E 3 where
(1) The origin of the orthonormal frame ( O ~ n d c , B n d c ) (\tilde{O}_{ndc}, \mathcal{B}_{ndc}) ( O ~ n d c , B n d c ) is the point
O ~ n d c ∈ E 3 \tilde{O}_{ndc} \in \mathbb{E}^{3} O ~ n d c ∈ E 3 ; (2) The basis of the orthonormal frame is
B n d c = ( u ^ n d c , h , u ^ n d c , v , u ^ n d c , d ) \mathcal{B}_{ndc} = (\mathbf{\hat{u}}_{ndc,h}, \mathbf{\hat{u}}_{ndc,v}, \mathbf{\hat{u}}_{ndc,d}) B n d c = ( u ^ n d c , h , u ^ n d c , v , u ^ n d c , d )
where the basis vector u ^ n d c , h \mathbf{\hat{u}}_{ndc,h} u ^ n d c , h points to the right, the basis vector
u ^ n d c , v \mathbf{\hat{u}}_{ndc,v} u ^ n d c , v points up, and the basis vector u ^ n d c , d \mathbf{\hat{u}}_{ndc,d} u ^ n d c , d points into the
view volume, or out of the view volume depending on the choice or orientation; (3) The view volume in this
coordinate system is called the canonical view volume .
The view coordinate system, projected coordinate system, clip coordinate system, and normalized device
coordinate system induce coordinate charts via φ v i e w ( P ~ ) = P ~ − O ~ v i e w \varphi_{view}(\tilde{P}) = \tilde{P} - \tilde{O}_{view} φ v i e w ( P ~ ) = P ~ − O ~ v i e w ,
φ p r o j ( P ~ ) = P ~ − O ~ p r o j \varphi_{proj}(\tilde{P}) = \tilde{P} - \tilde{O}_{proj} φ p ro j ( P ~ ) = P ~ − O ~ p ro j ,
φ c l i p ( P ~ ) = P ~ − O ~ c l i p \varphi_{clip}(\tilde{P}) = \tilde{P} - \tilde{O}_{clip} φ c l i p ( P ~ ) = P ~ − O ~ c l i p ,
and φ n d c ( P ~ ) = P ~ − O ~ n d c \varphi_{ndc}(\tilde{P}) = \tilde{P} - \tilde{O}_{ndc} φ n d c ( P ~ ) = P ~ − O ~ n d c , respectively.
The projection transformations are parametrized by two set of parameters. The first one is the view volume
parameters l l l , r r r , b b b , t t t , n n n , f f f where l > 0 l > 0 l > 0 , r > 0 r > 0 r > 0 ,
b > 0 b > 0 b > 0 , t > 0 t > 0 t > 0 , and f > n > 0 f > n > 0 f > n > 0 such that the view volume is parametrized by
[ − l , r ] × [ − b , t ] × [ n , f ] [-l, r] \times [-b, t] \times [n, f] [ − l , r ] × [ − b , t ] × [ n , f ] . The second one is the canonical view volume parametrized by
[ α m i n , α m a x ] × [ β m i n , β m a x ] × [ γ m i n , γ m a x ] [\alpha_{min}, \alpha_{max}] \times [\beta_{min}, \beta_{max}] \times [\gamma_{min}, \gamma_{max}] [ α min , α ma x ] × [ β min , β ma x ] × [ γ min , γ ma x ] .
where α m a x > α m i n \alpha_{max} > \alpha_{min} α ma x > α min , β m a x > β m i n \beta_{max} > \beta_{min} β ma x > β min , and
γ m a x > γ m i n \gamma_{max} > \gamma_{min} γ ma x > γ min .
A projection matrix is a projective transformation T : E 3 → E 3 T : \mathbb{E}^{3} \rightarrow \mathbb{E}^{3} T : E 3 → E 3
lifted over to R P 3 \mathbb{RP}^{3} RP 3 as T ^ : R P 3 → R P 3 \hat{T} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} T ^ : RP 3 → RP 3 specified
by the following data:
The view coordinate system, defined by an orthonormal frame
F v i e w = ( O ~ v i e w , B v i e w ) \mathcal{F}_{view} = (\tilde{O}_{view}, \mathcal{B}_{view}) F v i e w = ( O ~ v i e w , B v i e w ) . The clip coordinate system, defined by an orthonormal frame
F c l i p = ( O ~ c l i p , B c l i p ) \mathcal{F}_{clip} = (\tilde{O}_{clip}, \mathcal{B}_{clip}) F c l i p = ( O ~ c l i p , B c l i p ) . The normalized device coordinate system, defined by an orthonormal frame
F n d c = ( O ~ n d c , B n d c ) \mathcal{F}_{ndc} = (\tilde{O}_{ndc}, \mathcal{B}_{ndc}) F n d c = ( O ~ n d c , B n d c ) . The view volume , parametrized by [ − l , r ] × [ − b , r ] × [ n , f ] [-l, r] \times [-b, r] \times [n, f] [ − l , r ] × [ − b , r ] × [ n , f ] where
l > 0 l > 0 l > 0 , r > 0 r > 0 r > 0 , b > 0 b > 0 b > 0 , t > 0 t > 0 t > 0 , and f > n > 0 f > n > 0 f > n > 0 . The canonical view volume , parametrized by
[ α m i n , α m a x ] × [ β m i n , β m a x ] × [ γ m i n , γ m a x ] [\alpha_{min}, \alpha_{max}] \times [\beta_{min}, \beta_{max}] \times [\gamma_{min}, \gamma_{max}] [ α min , α ma x ] × [ β min , β ma x ] × [ γ min , γ ma x ]
where α m a x > α m i n \alpha_{max} > \alpha_{min} α ma x > α min , β m a x > β m i n \beta_{max} > \beta_{min} β ma x > β min , and γ m a x > γ m i n \gamma_{max} > \gamma_{min} γ ma x > γ min . The projection matrix maps the view volume to the canonical view volume.
The Canonical Projection Matrices ¶ In this section, we construct the canonical projection matrices. We call them canonical because each of the
projections has the same output coordinate system as the input coordinate system. So it is particularly
convenient to work with.
The Canonical Coordinate System ¶ We choose a canonical set of coordinate systems to construct the canonical projective transformations
that will be used to derive the projective transformations in specific settings.
The canonical view coordinates is the view space coordinate system with orthonormal frame
( O ~ v i e w , B v i e w ) (\tilde{O}_{view}, \mathcal{B}_{view}) ( O ~ v i e w , B v i e w ) where
B v i e w = ( u ^ h , u ^ v , u ^ d ) \mathcal{B}_{view} = (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d}) B v i e w = ( u ^ h , u ^ v , u ^ d ) such that the depth
frame vector u ^ d \mathbf{\hat{u}}_{d} u ^ d points into the view volume. This gives the canonical view space a
left-handed orientation. The canonical projected coordinates coordinate system is the projected coordinate system
with the same orthonormal frame as the canonical view coordinates. The canonical clip coordinates coordinate
system is the clip coordinate system with the same orthonormal frame as the canonical view coordinate system. The
canonical normalized device coordinates coordinate system is the normalized device coordinate system with the same
orthonormal frame as in canonical view coordinates. In particular, each coordinate system uses the same orthonormal
frame, and has a left-handed orientation.
It is not strictly required that each space have the same orthonormal frame, but using the same coordinate
system in each step makes it easier to see what is going on in the transformation pipeline. Since we derive
each transformation between the coordinate systems above, we can always transform any one of them with a
combination of orthogonal transformations and changes of orientation to get the desired ones. It is also much
less error-prone with fewer pesky signs to deal with.
The Canonical Perspective Projection Matrix ¶ With these considerations, we construct the canonical perspective projection matrix for
the frame ( O ~ v i e w , ( u ^ h , u ^ v , u ^ d ) ) (\tilde{O}_{view}, (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d})) ( O ~ v i e w , ( u ^ h , u ^ v , u ^ d )) with the
perspective view volume parametrized by [ − l , r ] × [ − b , t ] × [ n , f ] [-l, r] \times [-b, t] \times [n, f] [ − l , r ] × [ − b , t ] × [ n , f ] and
the canonical view volume parametrized by
[ α m i n , α m a x ] × [ β m i n , β m a x ] × [ γ m i n , γ m a x ] [\alpha_{min}, \alpha_{max}] \times [\beta_{min}, \beta_{max}] \times [\gamma_{min}, \gamma_{max}] [ α min , α ma x ] × [ β min , β ma x ] × [ γ min , γ ma x ] .
Let P ∈ R 3 P \in \mathbb{R}^{3} P ∈ R 3 be a point given by
P = P h u ^ h + P v u ^ v + P d u ^ d P = P_{h} \mathbf{\hat{u}}_{h} + P_{v} \mathbf{\hat{u}}_{v} + P_{d} \mathbf{\hat{u}}_{d} P = P h u ^ h + P v u ^ v + P d u ^ d . We
derive the perspective projected horizontal and vertical components.
Using similar triangles for the horizontal component, we have
P h P d = P ⋅ u ^ h P ⋅ u ^ d = P p r o j ′ ⋅ u ^ h n = P p r o j , h ′ n \frac{P_{h}}{P_{d}} = \frac{P \cdot \mathbf{\hat{u}}_{h}}{P \cdot \mathbf{\hat{u}}_{d}}
= \frac{P^{\prime}_{proj} \cdot \mathbf{\hat{u}}_{h}}{n}
= \frac{P^{\prime}_{proj,h}}{n} P d P h = P ⋅ u ^ d P ⋅ u ^ h = n P p ro j ′ ⋅ u ^ h = n P p ro j , h ′ which yields
P p r o j , h ′ = n P h ( 1 P d ) . P^{\prime}_{proj,h} = n P_{h} \left( \frac{1}{P_{d}} \right). P p ro j , h ′ = n P h ( P d 1 ) . Analagously for the vertical component, applying similar triangles gives us
P v P d = P ⋅ u ^ v P ⋅ u ^ d = P p r o j ′ ⋅ u ^ v n = P p r o j , v ′ n \frac{P_{v}}{P_{d}}
= \frac{P \cdot \mathbf{\hat{u}}_{v}}{P \cdot \mathbf{\hat{u}}_{d}}
= \frac{P^{\prime}_{proj} \cdot \mathbf{\hat{u}}_{v}}{n}
= \frac{P^{\prime}_{proj,v}}{n} P d P v = P ⋅ u ^ d P ⋅ u ^ v = n P p ro j ′ ⋅ u ^ v = n P p ro j , v ′ implying that
P p r o j , v ′ = n P v ( 1 P d ) . P^{\prime}_{proj,v} = n P_{v} \left( \frac{1}{P_{d}} \right). P p ro j , v ′ = n P v ( P d 1 ) . Observe that the horizontal and vertical components both transform as projective transformations. Indeed,
the perspective projection transformation is a projective transformation where the affine function is
given by P d P_{d} P d . In other words, the perspective projection is dividing by depth. Using our reasoning
about representing projective transformations that lead to the matrix representation (38) , we
can deduce the lifted mapping by rearranging the perspective equations
P d P p r o j , h ′ = n P h P d P p r o j , v ′ = n P v P_{d} P^{\prime}_{proj,h} = n P_{h} \\
P_{d} P^{\prime}_{proj,v} = n P_{v} \\ P d P p ro j , h ′ = n P h P d P p ro j , v ′ = n P v suggestively. The right hand side in both cases are affine transformations. This suggests to form
of the transformation for the depth component. We define our projected coordinate system components as follows.
Let P p r o j , h = P d P p r o j , h ′ P_{proj,h} = P_{d} P^{\prime}_{proj,h} P p ro j , h = P d P p ro j , h ′ and P p r o j , v = P d P p r o j , v ′ P_{proj,v} = P_{d} P^{\prime}_{proj,v} P p ro j , v = P d P p ro j , v ′ .
Since the affine scalar function is perspective division, we immediately see that P p r o j , w = P d P_{proj,w} = P_{d} P p ro j , w = P d . This
leaves the depth component. The depth component does not directly participate in depth normalization, and
since our coordinate system is orthogonal, so P p r o j , d P_{proj,d} P p ro j , d cannot depend on P h P_{h} P h or P v P_{v} P v .
This implies that P p r o j , d P_{proj,d} P p ro j , d must be a function of P d P_{d} P d and P w P_{w} P w . Since the
transformation is projective, the depth component must transform affinely. Since P w = 1 P_{w} = 1 P w = 1 . This leaves
P p r o j , d = θ ( P d ) = A ′ P d + B ′ . P_{proj,d} = \theta \left( P_{d} \right) = A^{\prime} P_{d} + B^{\prime}. P p ro j , d = θ ( P d ) = A ′ P d + B ′ . Taken together, the projected coordinates components of the perspective transformation are
P p r o j , h = n P h P p r o j , v = n P v P p r o j , d = θ ( P d ) = A ′ P d + B ′ P p r o j , w = P d \begin{align*}
P_{proj,h} &= n P_{h} \\
P_{proj,v} &= n P_{v} \\
P_{proj,d} &= \theta \left ( P_{d} \right) = A^{\prime} P_{d} + B^{\prime} \\
P_{proj,w} &= P_{d} \\
\end{align*} P p ro j , h P p ro j , v P p ro j , d P p ro j , w = n P h = n P v = θ ( P d ) = A ′ P d + B ′ = P d where we solve for the constants A ′ A^{\prime} A ′ and B ′ B^{\prime} B ′ later.
After projection, we must map the projected coordinates to clip coordinates. To obtain the right
clip coordinates, we need to consider normalized device coordinates. This is necessary since the
mapping from projected coordinates to clip coordinates depends on the choice of parametrization
of the canonical view volume. The resulting transformation is an orthographic transformation that
maps the orthographic view volume [ − l , r ] × [ − b , t ] × [ n , f ] [-l, r] \times [-b, t] \times [n, f] [ − l , r ] × [ − b , t ] × [ n , f ] to the canonical view volume
[ α m i n , α m a x ] × [ β m i n , β m a x ] × [ γ m i n , γ m a x ] [\alpha_{min}, \alpha_{max}] \times [\beta_{min}, \beta_{max}] \times [\gamma_{min}, \gamma_{max}] [ α min , α ma x ] × [ β min , β ma x ] × [ γ min , γ ma x ] .
The map from projected coordinates to clip coordinates is a linear map in R P 3 \mathbb{RP}^{3} RP 3 , so
the coordinates must transform affinely.
We need a set of maps ϕ h , ϕ v , ϕ d , ϕ w : R 3 → R \phi_{h}, \phi_{v}, \phi_{d}, \phi_{w} : \mathbb{R}^{3} \rightarrow \mathbb{R} ϕ h , ϕ v , ϕ d , ϕ w : R 3 → R such that
P n d c , h = P c l i p , h P c l i p , w = ( H w ∘ ϕ h ) ( P p r o j ) = ϕ h ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) ≡ ξ h ( P ) P n d c , v = P c l i p , v P c l i p , w = ( H w ∘ ϕ v ) ( P p r o j ) = ϕ v ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) ≡ ξ v ( P ) P n d c , d = P c l i p , d P c l i p , w = ( H w ∘ ϕ d ) ( P p r o j ) = ϕ d ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) ≡ ξ d ( P ) P n d c , w = P c l i p , w P c l i p , w = ( H w ∘ ϕ w ) ( P p r o j ) = ϕ w ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) = 1 \begin{align*}
P_{ndc,h} &= \frac{P_{clip,h}}{P_{clip,w}}
&&= \left( H_{w} \circ \phi_{h} \right) \left( P_{proj} \right)
&&= \phi_{h} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right) } \right)
&&\equiv \xi_{h} \left( P \right) \\
P_{ndc,v} &= \frac{P_{clip,v}}{P_{clip,w}}
&&= \left( H_{w} \circ \phi_{v} \right) \left( P_{proj} \right)
&&= \phi_{v} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right) } \right)
&&\equiv \xi_{v} \left( P \right) \\
P_{ndc,d} &= \frac{P_{clip,d}}{P_{clip,w}}
&&= \left( H_{w} \circ \phi_{d} \right) \left( P_{proj} \right)
&&= \phi_{d} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right) } \right)
&&\equiv \xi_{d} \left( P \right) \\
P_{ndc,w} &= \frac{P_{clip,w}}{P_{clip,w}}
&&= \left( H_{w} \circ \phi_{w} \right) \left( P_{proj} \right)
&&= \phi_{w} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right)} \right)
&&= 1 \\
\end{align*} P n d c , h P n d c , v P n d c , d P n d c , w = P c l i p , w P c l i p , h = P c l i p , w P c l i p , v = P c l i p , w P c l i p , d = P c l i p , w P c l i p , w = ( H w ∘ ϕ h ) ( P p ro j ) = ( H w ∘ ϕ v ) ( P p ro j ) = ( H w ∘ ϕ d ) ( P p ro j ) = ( H w ∘ ϕ w ) ( P p ro j ) = ϕ h ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) = ϕ v ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) = ϕ d ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) = ϕ w ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) ≡ ξ h ( P ) ≡ ξ v ( P ) ≡ ξ d ( P ) = 1 where P p r o j P_{proj} P p ro j denotes a point P ∈ R 3 P \in \mathbb{R}^{3} P ∈ R 3 in projected coordinates,
P c l i p , w = ϕ w ( P p r o j ) P_{clip,w} = \phi_{w}(P_{proj}) P c l i p , w = ϕ w ( P p ro j ) is an affine scalar function, and
H w : R 4 → R 4 H_{w} : \mathbb{R}^{4} \rightarrow \mathbb{R}^{4} H w : R 4 → R 4 denotes homogenization by the w w w component.
Observe that the functions ξ h , ξ v , ξ d : R 3 → R \xi_{h}, \xi_{v}, \xi_{d} : \mathbb{R}^{3} \rightarrow \mathbb{R} ξ h , ξ v , ξ d : R 3 → R
on the right-hand side of (49) are projective functions of the view space point P P P .
This implies that the clip coordinates must be affine functions of P p r o j P_{proj} P p ro j . In particular,
P c l i p , h = ϕ h ( P p r o j ) P c l i p , v = ϕ v ( P p r o j ) P c l i p , d = ϕ d ( P p r o j ) P c l i p , w = ϕ w ( P p r o j ) \begin{align*}
P_{clip,h} &= \phi_{h} \left( P_{proj} \right) \\
P_{clip,v} &= \phi_{v} \left( P_{proj} \right) \\
P_{clip,d} &= \phi_{d} \left( P_{proj} \right) \\
P_{clip,w} &= \phi_{w} \left( P_{proj} \right) \\
\end{align*} P c l i p , h P c l i p , v P c l i p , d P c l i p , w = ϕ h ( P p ro j ) = ϕ v ( P p ro j ) = ϕ d ( P p ro j ) = ϕ w ( P p ro j ) is the form of the clip components. Since the purpose of the w w w coordinate is to perform perspective
division, this implies that
ϕ w ( P p r o j ) = P d \phi_{w} \left( P_{proj} \right) = P_{d} ϕ w ( P p ro j ) = P d so that the equations in (49) become
P n d c , h = ξ h ( P ) = ϕ h ( P p r o j ) ( 1 P d ) P n d c , v = ξ v ( P ) = ϕ v ( P p r o j ) ( 1 P d ) P n d c , d = ξ d ( P ) = ϕ d ( P p r o j ) ( 1 P d ) \begin{align*}
P_{ndc,h} &= \xi_{h} \left( P \right) = \phi_{h} \left( P_{proj} \right) \left( \frac{1}{ P_{d} } \right) \\
P_{ndc,v} &= \xi_{v} \left( P \right) = \phi_{v} \left( P_{proj} \right) \left( \frac{1}{ P_{d} } \right) \\
P_{ndc,d} &= \xi_{d} \left( P \right) = \phi_{d} \left( P_{proj} \right) \left( \frac{1}{ P_{d} } \right) \\
\end{align*} P n d c , h P n d c , v P n d c , d = ξ h ( P ) = ϕ h ( P p ro j ) ( P d 1 ) = ξ v ( P ) = ϕ v ( P p ro j ) ( P d 1 ) = ξ d ( P ) = ϕ d ( P p ro j ) ( P d 1 ) To derive the perspective projection matrix, we solve for the clip coordinate functions ϕ h , ϕ v , ϕ d \phi_{h}, \phi_{v}, \phi_{d} ϕ h , ϕ v , ϕ d
indirectly using the auxiliary functions ξ h , ξ v , ξ d \xi_{h}, \xi_{v}, \xi_{d} ξ h , ξ v , ξ d in (52) , and
use the constraints on the orthographic view volume to compute the auxiliary functions. To establish constraints, we
need to talk about some well chosen points. We need to construct the maps ξ h , ξ v , ξ d \xi_{h}, \xi_{v}, \xi_{d} ξ h , ξ v , ξ d such that
the parametrization of the orthographic view volume maps to the parametrization of the canonical view volume.
That it, such that coordinates map as
− l ↦ α m i n , r ↦ α m a x , − b ↦ β m i n , t ↦ β m a x , n ↦ γ m i n , f ↦ γ m a x -l \mapsto \alpha_{min}, r \mapsto \alpha_{max}, -b \mapsto \beta_{min}, t \mapsto \beta_{max}, n \mapsto \gamma_{min}, f \mapsto \gamma_{max} − l ↦ α min , r ↦ α ma x , − b ↦ β min , t ↦ β ma x , n ↦ γ min , f ↦ γ ma x .
Consider the points in view coordinates
Q l e f t = − l u ^ h + n u ^ d Q r i g h t = r u ^ h + n u ^ d Q b o t t o m = − b u ^ v + n u ^ d Q t o p = t u ^ v + n u ^ d Q n e a r = n u ^ d Q f a r = f u ^ d \begin{align*}
Q_{left} &= -l \mathbf{\hat{u}}_{h} + n \mathbf{\hat{u}}_{d} \\
Q_{right} &= r \mathbf{\hat{u}}_{h} + n \mathbf{\hat{u}}_{d} \\
Q_{bottom} &= -b \mathbf{\hat{u}}_{v} + n \mathbf{\hat{u}}_{d} \\
Q_{top} &= t \mathbf{\hat{u}}_{v} + n \mathbf{\hat{u}}_{d} \\
Q_{near} &= n \mathbf{\hat{u}}_{d} \\
Q_{far} &= f \mathbf{\hat{u}}_{d} \\
\end{align*} Q l e f t Q r i g h t Q b o tt o m Q t o p Q n e a r Q f a r = − l u ^ h + n u ^ d = r u ^ h + n u ^ d = − b u ^ v + n u ^ d = t u ^ v + n u ^ d = n u ^ d = f u ^ d The points Q n e a r Q_{near} Q n e a r and Q f a r Q_{far} Q f a r are the points along the viewing axis
that intersect the near plane and the far plane, respectively, of the perspective view volume. The
point Q l e f t Q_{left} Q l e f t represents the point of intersection of the left plane, near plane, and the
horizontal-vertical plane of the view volume. The point Q r i g h t Q_{right} Q r i g h t represents the point of
intersection of the right plane, near plane, and the horizontal-vertical plane of the view volume.
The point Q b o t t o m Q_{bottom} Q b o tt o m represents the point of intersection of the bottom plane, near plane,
and depth-vertical plane of the view volume. The point Q t o p Q_{top} Q t o p represents the point of
intersection of the top plane, near plane, and the depth-vertical plane of the view volume. In short,
the points Q n e a r Q_{near} Q n e a r and Q f a r Q_{far} Q f a r are the origins of the near and far planes, respectively.
The other four points and points chosen along the edge of the viewport in the near plane that allow us
to easily set up the boundary conditions to compute the functions ξ h , ξ v , ξ d \xi_{h}, \xi_{v}, \xi_{d} ξ h , ξ v , ξ d .
We now calculate the auxiliary functions. Consider the map ξ h \xi_{h} ξ h , where
ξ h ( P ) = ( A P p r o j , h + B P p r o j , v + C ′ P p r o j , d + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ θ ( P d ) + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ ( A ′ P d + B ′ ) + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ A ′ P d + C ′ B ′ + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + ( C ′ A ′ ) P d + ( C ′ B ′ + D ′ ) ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C P d + D ) ( 1 P d ) = ( A n P h + B n P v + C P d + D ) ( 1 P d ) = A n P h ( 1 P d ) + B n P v ( 1 P d ) + C + D ( 1 P d ) \begin{align*}
\xi_{h} \left( P \right)
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} P_{proj,d} + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} \theta \left( P_{d} \right) + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} \left( A^{\prime} P_{d} + B^{\prime} \right) + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} A^{\prime} P_{d} + C^{\prime} B^{\prime} + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + \left( C^{\prime} A^{\prime} \right) P_{d} + \left( C^{\prime} B^{\prime} + D^{\prime} \right) \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C P_{d} + D \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A n P_{h} + B n P_{v} + C P_{d} + D \right) \left( \frac{1}{P_{d}} \right) \\
&= A n P_{h} \left( \frac{1}{P_{d}} \right) + B n P_{v} \left( \frac{1}{P_{d}} \right) + C + D \left( \frac{1}{P_{d}} \right) \\
\end{align*} ξ h ( P ) = ( A P p ro j , h + B P p ro j , v + C ′ P p ro j , d + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ θ ( P d ) + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ ( A ′ P d + B ′ ) + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ A ′ P d + C ′ B ′ + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + ( C ′ A ′ ) P d + ( C ′ B ′ + D ′ ) ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C P d + D ) ( P d 1 ) = ( A n P h + B n P v + C P d + D ) ( P d 1 ) = A n P h ( P d 1 ) + B n P v ( P d 1 ) + C + D ( P d 1 ) where C = C ′ A ′ C = C^{\prime} A^{\prime} C = C ′ A ′ and D = C ′ B ′ + D ′ D = C^{\prime} B^{\prime} + D^{\prime} D = C ′ B ′ + D ′ , so that
ξ h ( P ) = A n P h ( 1 P d ) + B n P v ( 1 P d ) + C + D ( 1 P d ) . \xi_{h} \left( P \right) = A n P_{h} \left( \frac{1}{P_{d}} \right) + B n P_{v} \left( \frac{1}{P_{d}} \right) + C + D \left( \frac{1}{P_{d}} \right). ξ h ( P ) = A n P h ( P d 1 ) + B n P v ( P d 1 ) + C + D ( P d 1 ) . Define the boundary conditions for our chosen points
ξ h ( Q l e f t ) = α m i n ξ h ( Q r i g h t ) = α m a x ξ h ( Q b o t t o m ) = 0 ξ h ( Q t o p ) = 0 ξ h ( Q n e a r ) = 0 ξ h ( Q f a r ) = 0 \begin{align*}
\xi_{h} \left( Q_{left} \right) &= \alpha_{min} \\
\xi_{h} \left( Q_{right} \right) &= \alpha_{max} \\
\xi_{h} \left( Q_{bottom} \right) &= 0 \\
\xi_{h} \left( Q_{top} \right) &= 0 \\
\xi_{h} \left( Q_{near} \right) &= 0 \\
\xi_{h} \left( Q_{far} \right) &= 0 \\
\end{align*} ξ h ( Q l e f t ) ξ h ( Q r i g h t ) ξ h ( Q b o tt o m ) ξ h ( Q t o p ) ξ h ( Q n e a r ) ξ h ( Q f a r ) = α min = α ma x = 0 = 0 = 0 = 0 which we need to justify. The view coordinates are orthogonal to each other, and the normalized device
coordinates are also orthogonal to each other. This means that ξ h \xi_{h} ξ h should only be a function
of the horizontal component and not the vertical component. The points
Q b o t t o m , Q t o p , Q n e a r , Q f a r Q_{bottom}, Q_{top}, Q_{near}, Q_{far} Q b o tt o m , Q t o p , Q n e a r , Q f a r lie on the depth-vertical plane, which have a zero horizontal
component, so they should keep a zero horizontal component after transformation.
Applying the boundary conditions, we have
ξ h ( Q l e f t ) = A n ⋅ ( − l ) ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = − A l + C + D ( 1 n ) = α m i n ξ h ( Q r i g h t ) = A n ⋅ r ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = A r + C + D ( 1 n ) = α m a x ξ h ( Q b o t t o m ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ ( − b ) ⋅ ( 1 n ) + C + D ( 1 n ) = − B b + C + D ( 1 n ) = 0 ξ h ( Q t o p ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ t ⋅ ( 1 n ) + C + D ( 1 n ) = B t + C + D ( 1 n ) = 0 ξ h ( Q n e a r ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = C + D ( 1 n ) = 0 ξ h ( Q f a r ) = A n ⋅ 0 ⋅ ( 1 f ) + B n ⋅ 0 ⋅ ( 1 f ) + C + D ( 1 f ) = C + D ( 1 f ) = 0 \begin{align*}
\xi_{h} \left( Q_{left} \right)
&= A n \cdot \left( -l \right) \cdot\left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= -A l + C + D \left( \frac{1}{n} \right) \\
&= \alpha_{min} \\
\xi_{h} \left( Q_{right} \right)
&= A n \cdot r \cdot \left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= A r + C + D \left( \frac{1}{n} \right) \\
&= \alpha_{max} \\
\xi_{h} \left( Q_{bottom} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot \left( -b \right) \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= -B b + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{h} \left( Q_{top} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot t \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= B t + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{h} \left( Q_{near} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{h} \left( Q_{far} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{f} \right) + B n \cdot 0 \cdot \left( \frac{1}{f} \right) + C + D \left( \frac{1}{f} \right) \\
&= C + D \left( \frac{1}{f} \right) \\
&= 0 \\
\end{align*} ξ h ( Q l e f t ) ξ h ( Q r i g h t ) ξ h ( Q b o tt o m ) ξ h ( Q t o p ) ξ h ( Q n e a r ) ξ h ( Q f a r ) = A n ⋅ ( − l ) ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = − A l + C + D ( n 1 ) = α min = A n ⋅ r ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = A r + C + D ( n 1 ) = α ma x = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ ( − b ) ⋅ ( n 1 ) + C + D ( n 1 ) = − B b + C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ t ⋅ ( n 1 ) + C + D ( n 1 ) = Bt + C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( f 1 ) + B n ⋅ 0 ⋅ ( f 1 ) + C + D ( f 1 ) = C + D ( f 1 ) = 0 so that
ξ h ( Q l e f t ) = − A l + C + D ( 1 n ) = α m i n ξ h ( Q r i g h t ) = A r + C + D ( 1 n ) = α m a x ξ h ( Q b o t t o m ) = − B b + C + D ( 1 n ) = 0 ξ h ( Q t o p ) = B t + C + D ( 1 n ) = 0 ξ h ( Q n e a r ) = C + D ( 1 n ) = 0 ξ h ( Q f a r ) = C + D ( 1 f ) = 0 \begin{align*}
\xi_{h} \left( Q_{left} \right)
&= -A l + C + D \left( \frac{1}{n} \right)
&&= \alpha_{min} \\
\xi_{h} \left( Q_{right} \right)
&= A r + C + D \left( \frac{1}{n} \right)
&&= \alpha_{max} \\
\xi_{h} \left( Q_{bottom} \right)
&= -B b + C + D \left( \frac{1}{n} \right)
&&= 0 \\
\xi_{h} \left( Q_{top} \right)
&= B t + C + D \left( \frac{1}{n} \right)
&&= 0 \\
\xi_{h} \left( Q_{near} \right)
&= C + D \left( \frac{1}{n} \right)
&&= 0 \\
\xi_{h} \left( Q_{far} \right)
&= C + D \left( \frac{1}{f} \right)
&&= 0 \\
\end{align*} ξ h ( Q l e f t ) ξ h ( Q r i g h t ) ξ h ( Q b o tt o m ) ξ h ( Q t o p ) ξ h ( Q n e a r ) ξ h ( Q f a r ) = − A l + C + D ( n 1 ) = A r + C + D ( n 1 ) = − B b + C + D ( n 1 ) = Bt + C + D ( n 1 ) = C + D ( n 1 ) = C + D ( f 1 ) = α min = α ma x = 0 = 0 = 0 = 0 and now we compute the constants. Subtracting ξ h ( Q r i g h t ) \xi_{h} \left( Q_{right} \right) ξ h ( Q r i g h t ) from
ξ h ( Q l e f t ) \xi_{h} \left( Q_{left} \right) ξ h ( Q l e f t ) in (58) yields
ξ h ( Q r i g h t ) − ξ h ( Q l e f t ) = [ A r + C + D ( 1 n ) ] − [ − A l + C + D ( 1 n ) ] = A r − ( − A l ) = A ( r − ( − l ) ) = α m a x − α m i n . \begin{align*}
\xi_{h} \left( Q_{right} \right) - \xi_{h} \left( Q_{left} \right)
&= \left[ A r + C + D \left( \frac{1}{n} \right) \right] - \left[ -A l + C + D \left( \frac{1}{n} \right) \right] \\
&= A r - \left( - A l \right) \\
&= A \left( r - \left( -l \right) \right) \\
&= \alpha_{max} - \alpha_{min}.
\end{align*} ξ h ( Q r i g h t ) − ξ h ( Q l e f t ) = [ A r + C + D ( n 1 ) ] − [ − A l + C + D ( n 1 ) ] = A r − ( − A l ) = A ( r − ( − l ) ) = α ma x − α min . Solving for A A A , we see that
A = α m a x − α m i n r − ( − l ) . A = \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)}. A = r − ( − l ) α ma x − α min . Subtracting ξ h ( Q t o p ) \xi_{h} \left( Q_{top} \right) ξ h ( Q t o p ) from ξ h ( Q b o t t o m ) \xi_{h} \left( Q_{bottom} \right) ξ h ( Q b o tt o m )
in (58) yields
ξ h ( Q t o p ) − ξ h ( Q b o t t o m ) = [ B t + C + D ( 1 n ) ] − [ − B b + C + D ( 1 n ) ] = B t − B ( − b ) = B ( t − ( − b ) ) = 0. \begin{align*}
\xi_{h} \left( Q_{top} \right) - \xi_{h} \left( Q_{bottom} \right)
&= \left[ B t + C + D \left( \frac{1}{n} \right) \right] - \left[ -B b + C + D \left( \frac{1}{n} \right) \right] \\
&= B t - B \left( -b \right) \\
&= B \left( t - \left( -b \right) \right) \\
&= 0.
\end{align*} ξ h ( Q t o p ) − ξ h ( Q b o tt o m ) = [ Bt + C + D ( n 1 ) ] − [ − B b + C + D ( n 1 ) ] = Bt − B ( − b ) = B ( t − ( − b ) ) = 0. Solving for B B B , we see that
since t − ( − b ) = t + b ≠ 0 t - (-b) = t + b \neq 0 t − ( − b ) = t + b = 0 . Subtracting ξ h ( Q f a r ) \xi_{h} \left( Q_{far} \right) ξ h ( Q f a r ) from
ξ h ( Q n e a r ) \xi_{h} \left( Q_{near} \right) ξ h ( Q n e a r ) in (58) yields
ξ h ( Q f a r ) − ξ h ( Q n e a r ) = [ C + D ( 1 f ) ] − [ C + D ( 1 n ) ] = D ( 1 f − 1 n ) = 0. \begin{align*}
\xi_{h} \left( Q_{far} \right) - \xi_{h} \left( Q_{near} \right)
&= \left[ C + D \left( \frac{1}{f} \right) \right] - \left[ C + D \left( \frac{1}{n} \right) \right] \\
&= D \left( \frac{1}{f} - \frac{1}{n} \right) \\
&= 0.
\end{align*} ξ h ( Q f a r ) − ξ h ( Q n e a r ) = [ C + D ( f 1 ) ] − [ C + D ( n 1 ) ] = D ( f 1 − n 1 ) = 0. Solving for D D D , we see that
since 1 f − 1 n ≠ 0 \frac{1}{f} - \frac{1}{n} \neq 0 f 1 − n 1 = 0 . Substituting the constants (60) ,
(62) , and (64) back into ξ h ( Q r i g h t ) \xi_{h}(Q_{right}) ξ h ( Q r i g h t ) in
(58) gives us
ξ h ( Q r i g h t ) = A r + C + D ( 1 n ) = A r + C = ( α m a x − α m i n r − ( − l ) ) r + C = α m a x . \xi_{h} \left( Q_{right} \right)
= A r + C + D \left( \frac{1}{n} \right)
= A r + C
= \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) r + C
= \alpha_{max}. ξ h ( Q r i g h t ) = A r + C + D ( n 1 ) = A r + C = ( r − ( − l ) α ma x − α min ) r + C = α ma x . Solving for C C C , we see that
C = α m a x − ( α m a x − α m i n r − ( − l ) ) r = α m a x − ( α m a x − α m i n r + l ) r = α m a x ( r + l ) − ( α m a x − α m i n ) r r + l = α m a x r + α m a x l − α m a x r + α m i n r r + l = α m a x r + α m a x l − α m a x r + α m i n r r + l = α m a x l + α m i n r r + l = α m i n r − α m a x ( − l ) r − ( − l ) \begin{align*}
C &= \alpha_{max} - \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) r \\
&= \alpha_{max} - \left( \frac{\alpha_{max} - \alpha_{min}}{r + l} \right) r \\
&= \frac{\alpha_{max} \left( r + l \right) - \left( \alpha_{max} - \alpha_{min} \right) r}{r + l} \\
&= \frac{\alpha_{max} r + \alpha_{max} l - \alpha_{max} r + \alpha_{min} r}{r + l} \\
&= \frac{\alpha_{max} r + \alpha_{max} l - \alpha_{max} r + \alpha_{min} r}{r + l} \\
&= \frac{\alpha_{max} l + \alpha_{min} r}{r + l} \\
&= \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)} \\
\end{align*} C = α ma x − ( r − ( − l ) α ma x − α min ) r = α ma x − ( r + l α ma x − α min ) r = r + l α ma x ( r + l ) − ( α ma x − α min ) r = r + l α ma x r + α ma x l − α ma x r + α min r = r + l α ma x r + α ma x l − α ma x r + α min r = r + l α ma x l + α min r = r − ( − l ) α min r − α ma x ( − l ) therefore
C = α m i n r − α m a x ( − l ) r − ( − l ) . C = \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}. C = r − ( − l ) α min r − α ma x ( − l ) . Assembling the constants (60) , (62) , (67) ,
(64) back into (55) we have the complete formula for the
auxiliary function ξ h \xi_{h} ξ h
ξ h ( P ) = ( ( α m a x − α m i n ) n r − ( − l ) ) P h ( 1 P d ) + α m i n r − α m a x ( − l ) r − ( − l ) . \xi_{h} \left( P \right)
= \left( \frac{ \left( \alpha_{max} - \alpha_{min} \right) n }{ r - \left( -l \right)} \right) P_{h} \left( \frac{1}{P_{d}} \right)
+ \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}. ξ h ( P ) = ( r − ( − l ) ( α ma x − α min ) n ) P h ( P d 1 ) + r − ( − l ) α min r − α ma x ( − l ) . Consider the map ξ v \xi_{v} ξ v , where
ξ v ( P ) = ( A P p r o j , h + B P p r o j , v + C ′ P p r o j , d + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ θ ( P d ) + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ ( A ′ P d + B ′ ) + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ A ′ P d + C ′ B ′ + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + ( C ′ A ′ ) P d + ( C ′ B ′ + D ′ ) ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C P d + D ) ( 1 P d ) = ( A n P h + B n P v + C P d + D ) ( 1 P d ) = A n P h ( 1 P d ) + B n P v ( 1 P d ) + C + D ( 1 P d ) \begin{align*}
\xi_{v} \left( P \right)
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} P_{proj,d} + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} \theta \left( P_{d} \right) + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} \left( A^{\prime} P_{d} + B^{\prime} \right) + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} A^{\prime} P_{d} + C^{\prime} B^{\prime} + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + \left( C^{\prime} A^{\prime} \right) P_{d} + \left( C^{\prime} B^{\prime} + D^{\prime} \right) \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C P_{d} + D \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A n P_{h} + B n P_{v} + C P_{d} + D \right) \left( \frac{1}{P_{d}} \right) \\
&= A n P_{h} \left( \frac{1}{P_{d}} \right) + B n P_{v} \left( \frac{1}{P_{d}} \right) + C + D \left( \frac{1}{P_{d}} \right) \\
\end{align*} ξ v ( P ) = ( A P p ro j , h + B P p ro j , v + C ′ P p ro j , d + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ θ ( P d ) + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ ( A ′ P d + B ′ ) + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ A ′ P d + C ′ B ′ + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + ( C ′ A ′ ) P d + ( C ′ B ′ + D ′ ) ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C P d + D ) ( P d 1 ) = ( A n P h + B n P v + C P d + D ) ( P d 1 ) = A n P h ( P d 1 ) + B n P v ( P d 1 ) + C + D ( P d 1 ) where C = C ′ A ′ C = C^{\prime} A^{\prime} C = C ′ A ′ and D = C ′ B ′ + D ′ D = C^{\prime} B^{\prime} + D^{\prime} D = C ′ B ′ + D ′ , so that
ξ v ( P ) = A n P h ( 1 P d ) + B n P v ( 1 P d ) + C + D ( 1 P d ) . \xi_{v} \left( P \right) = A n P_{h} \left( \frac{1}{P_{d}} \right) + B n P_{v} \left( \frac{1}{P_{d}} \right) + C + D \left( \frac{1}{P_{d}} \right). ξ v ( P ) = A n P h ( P d 1 ) + B n P v ( P d 1 ) + C + D ( P d 1 ) . Define the boundary conditions for our chosen points
ξ v ( Q l e f t ) = 0 ξ v ( Q r i g h t ) = 0 ξ v ( Q b o t t o m ) = β m i n ξ v ( Q t o p ) = β m a x ξ v ( Q n e a r ) = 0 ξ v ( Q f a r ) = 0 \begin{align*}
\xi_{v} \left( Q_{left} \right) &= 0 \\
\xi_{v} \left( Q_{right} \right) &= 0 \\
\xi_{v} \left( Q_{bottom} \right) &= \beta_{min} \\
\xi_{v} \left( Q_{top} \right) &= \beta_{max} \\
\xi_{v} \left( Q_{near} \right) &= 0 \\
\xi_{v} \left( Q_{far} \right) &= 0 \\
\end{align*} ξ v ( Q l e f t ) ξ v ( Q r i g h t ) ξ v ( Q b o tt o m ) ξ v ( Q t o p ) ξ v ( Q n e a r ) ξ v ( Q f a r ) = 0 = 0 = β min = β ma x = 0 = 0 which we need to justify. The view coordinates are orthogonal to each other, and the normalized device
coordinates are also orthogonal to each other. This means that ξ v \xi_{v} ξ v should only be a function
of the vertical component and not the horizontal component. The points
Q l e f t , Q r i g h t , Q n e a r , Q f a r Q_{left}, Q_{right}, Q_{near}, Q_{far} Q l e f t , Q r i g h t , Q n e a r , Q f a r lie on the depth-horizontal plane, which have a zero vertical
component, so they should keep a zero vertical component after transformation.
Applying the boundary conditions, we have
ξ v ( Q l e f t ) = A n ⋅ ( − l ) ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = − A l + C + D ( 1 n ) = 0 ξ v ( Q r i g h t ) = A n ⋅ r ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = A r + C + D ( 1 n ) = 0 ξ v ( Q b o t t o m ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ ( − b ) ⋅ ( 1 n ) + C + D ( 1 n ) = − B b + C + D ( 1 n ) = β m i n ξ v ( Q t o p ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ t ⋅ ( 1 n ) + C + D ( 1 n ) = B t + C + D ( 1 n ) = β m a x ξ v ( Q n e a r ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = C + D ( 1 n ) = 0 ξ v ( Q f a r ) = A n ⋅ 0 ⋅ ( 1 f ) + B n ⋅ 0 ⋅ ( 1 f ) + C + D ( 1 f ) = C + D ( 1 f ) = 0 \begin{align*}
\xi_{v} \left( Q_{left} \right)
&= A n \cdot \left( -l \right) \cdot\left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= -A l + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{v} \left( Q_{right} \right)
&= A n \cdot r \cdot \left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= A r + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{v} \left( Q_{bottom} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot \left( -b \right) \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= -B b + C + D \left( \frac{1}{n} \right) \\
&= \beta_{min} \\
\xi_{v} \left( Q_{top} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot t \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= B t + C + D \left( \frac{1}{n} \right) \\
&= \beta_{max} \\
\xi_{v} \left( Q_{near} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{v} \left( Q_{far} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{f} \right) + B n \cdot 0 \cdot \left( \frac{1}{f} \right) + C + D \left( \frac{1}{f} \right) \\
&= C + D \left( \frac{1}{f} \right) \\
&= 0 \\
\end{align*} ξ v ( Q l e f t ) ξ v ( Q r i g h t ) ξ v ( Q b o tt o m ) ξ v ( Q t o p ) ξ v ( Q n e a r ) ξ v ( Q f a r ) = A n ⋅ ( − l ) ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = − A l + C + D ( n 1 ) = 0 = A n ⋅ r ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = A r + C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ ( − b ) ⋅ ( n 1 ) + C + D ( n 1 ) = − B b + C + D ( n 1 ) = β min = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ t ⋅ ( n 1 ) + C + D ( n 1 ) = Bt + C + D ( n 1 ) = β ma x = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( f 1 ) + B n ⋅ 0 ⋅ ( f 1 ) + C + D ( f 1 ) = C + D ( f 1 ) = 0 so that
ξ v ( Q l e f t ) = − A l + C + D ( 1 n ) = 0 ξ v ( Q r i g h t ) = A r + C + D ( 1 n ) = 0 ξ v ( Q b o t t o m ) = − B b + C + D ( 1 n ) = β m i n ξ v ( Q t o p ) = B t + C + D ( 1 n ) = β m a x ξ v ( Q n e a r ) = C + D ( 1 n ) = 0 ξ v ( Q f a r ) = C + D ( 1 f ) = 0 \begin{align*}
\xi_{v} \left( Q_{left} \right)
&= -A l + C + D \left( \frac{1}{n} \right)
&&= 0 \\
\xi_{v} \left( Q_{right} \right)
&= A r + C + D \left( \frac{1}{n} \right)
&&= 0 \\
\xi_{v} \left( Q_{bottom} \right)
&= -B b + C + D \left( \frac{1}{n} \right)
&&= \beta_{min} \\
\xi_{v} \left( Q_{top} \right)
&= B t + C + D \left( \frac{1}{n} \right)
&&= \beta_{max} \\
\xi_{v} \left( Q_{near} \right)
&= C + D \left( \frac{1}{n} \right)
&&= 0 \\
\xi_{v} \left( Q_{far} \right)
&= C + D \left( \frac{1}{f} \right)
&&= 0 \\
\end{align*} ξ v ( Q l e f t ) ξ v ( Q r i g h t ) ξ v ( Q b o tt o m ) ξ v ( Q t o p ) ξ v ( Q n e a r ) ξ v ( Q f a r ) = − A l + C + D ( n 1 ) = A r + C + D ( n 1 ) = − B b + C + D ( n 1 ) = Bt + C + D ( n 1 ) = C + D ( n 1 ) = C + D ( f 1 ) = 0 = 0 = β min = β ma x = 0 = 0 and now we compute the constants. Subtracting ξ v ( Q r i g h t ) \xi_{v} \left( Q_{right} \right) ξ v ( Q r i g h t ) from
ξ v ( Q l e f t ) \xi_{v} \left( Q_{left} \right) ξ v ( Q l e f t ) in (73) yields
ξ v ( Q r i g h t ) − ξ v ( Q l e f t ) = [ A r + C + D ( 1 n ) ] − [ − A l + C + D ( 1 n ) ] = A r − ( − A l ) = A ( r − ( − l ) ) = 0. \begin{align*}
\xi_{v} \left( Q_{right} \right) - \xi_{v} \left( Q_{left} \right)
&= \left[ A r + C + D \left( \frac{1}{n} \right) \right] - \left[ -A l + C + D \left( \frac{1}{n} \right) \right] \\
&= A r - \left( - A l \right) \\
&= A \left( r - \left( -l \right) \right) \\
&= 0.
\end{align*} ξ v ( Q r i g h t ) − ξ v ( Q l e f t ) = [ A r + C + D ( n 1 ) ] − [ − A l + C + D ( n 1 ) ] = A r − ( − A l ) = A ( r − ( − l ) ) = 0. Solving for A A A , we see that
since r − ( − l ) = r + l ≠ 0 r - (-l) = r + l \neq 0 r − ( − l ) = r + l = 0 . Subtracting ξ v ( Q t o p ) \xi_{v} \left( Q_{top} \right) ξ v ( Q t o p ) from
ξ v ( Q b o t t o m ) \xi_{v} \left( Q_{bottom} \right) ξ v ( Q b o tt o m ) in (73) yields
ξ v ( Q t o p ) − ξ v ( Q b o t t o m ) = [ B t + C + D ( 1 n ) ] − [ − B b + C + D ( 1 n ) ] = B t − B ( − b ) = B ( t − ( − b ) ) = β m a x − β m i n . \begin{align*}
\xi_{v} \left( Q_{top} \right) - \xi_{v} \left( Q_{bottom} \right)
&= \left[ B t + C + D \left( \frac{1}{n} \right) \right] - \left[ -B b + C + D \left( \frac{1}{n} \right) \right] \\
&= B t - B \left( -b \right) \\
&= B \left( t - \left( -b \right) \right) \\
&= \beta_{max} - \beta_{min}.
\end{align*} ξ v ( Q t o p ) − ξ v ( Q b o tt o m ) = [ Bt + C + D ( n 1 ) ] − [ − B b + C + D ( n 1 ) ] = Bt − B ( − b ) = B ( t − ( − b ) ) = β ma x − β min . Solving for B B B , we have
B = β m a x − β m i n t − ( − b ) . B = \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)}. B = t − ( − b ) β ma x − β min . Subtracting ξ v ( Q f a r ) \xi_{v} \left( Q_{far} \right) ξ v ( Q f a r ) from
ξ v ( Q n e a r ) \xi_{v} \left( Q_{near} \right) ξ v ( Q n e a r ) in (73) yields
ξ v ( Q f a r ) − ξ v ( Q n e a r ) = [ C + D ( 1 f ) ] − [ C + D ( 1 n ) ] = D ( 1 f − 1 n ) = 0. \begin{align*}
\xi_{v} \left( Q_{far} \right) - \xi_{v} \left( Q_{near} \right)
&= \left[ C + D \left( \frac{1}{f} \right) \right] - \left[ C + D \left( \frac{1}{n} \right) \right] \\
&= D \left( \frac{1}{f} - \frac{1}{n} \right) \\
&= 0.
\end{align*} ξ v ( Q f a r ) − ξ v ( Q n e a r ) = [ C + D ( f 1 ) ] − [ C + D ( n 1 ) ] = D ( f 1 − n 1 ) = 0. Solving for D D D , we see that
since 1 f − 1 n ≠ 0 \frac{1}{f} - \frac{1}{n} \neq 0 f 1 − n 1 = 0 . Substituting the constants (75) ,
(77) , and (79) back into ξ v ( Q r i g h t ) \xi_{v}(Q_{right}) ξ v ( Q r i g h t ) in
(73) gives us
ξ v ( Q t o p ) = B t + C + D ( 1 n ) = B t + C = ( β m a x − β m i n t − ( − b ) ) t + C = β m a x . \xi_{v} \left( Q_{top} \right)
= B t + C + D \left( \frac{1}{n} \right)
= B t + C
= \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) t + C
= \beta_{max}. ξ v ( Q t o p ) = Bt + C + D ( n 1 ) = Bt + C = ( t − ( − b ) β ma x − β min ) t + C = β ma x . Solving for C C C , we see that
C = β m a x − ( β m a x − β m i n t − ( − b ) ) t = β m a x − ( β m a x − β m i n t + b ) t = β m a x ( t + b ) − ( β m a x − β m i n ) t t + b = β m a x t + β m a x b − β m a x t + β m i n t t + b = β m a x t + β m a x b − β m a x t + β m i n t t + b = β m a x b + β m i n t t + b = β m i n t − β m a x ( − b ) t − ( − b ) \begin{align*}
C &= \beta_{max} - \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) t \\
&= \beta_{max} - \left( \frac{\beta_{max} - \beta_{min}}{t + b} \right) t \\
&= \frac{\beta_{max} \left( t + b \right) - \left( \beta_{max} - \beta_{min} \right) t}{t + b} \\
&= \frac{\beta_{max} t + \beta_{max} b - \beta_{max} t + \beta_{min} t}{t + b} \\
&= \frac{\beta_{max} t + \beta_{max} b - \beta_{max} t + \beta_{min} t}{t + b} \\
&= \frac{\beta_{max} b + \beta_{min} t}{t + b} \\
&= \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)} \\
\end{align*} C = β ma x − ( t − ( − b ) β ma x − β min ) t = β ma x − ( t + b β ma x − β min ) t = t + b β ma x ( t + b ) − ( β ma x − β min ) t = t + b β ma x t + β ma x b − β ma x t + β min t = t + b β ma x t + β ma x b − β ma x t + β min t = t + b β ma x b + β min t = t − ( − b ) β min t − β ma x ( − b ) therefore
C = β m i n t − β m a x ( − b ) t − ( − b ) . C = \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}. C = t − ( − b ) β min t − β ma x ( − b ) . Assembling the constants (75) , (77) , (82) ,
(79) back into (70) we have the complete formula for the
auxiliary function ξ v \xi_{v} ξ v
ξ v ( P ) = ( ( β m a x − β m i n ) n t − ( − b ) ) P v ( 1 P d ) + β m i n t − β m a x ( − b ) t − ( − b ) . \xi_{v} \left( P \right)
= \left( \frac{ \left( \beta_{max} - \beta_{min} \right) n }{ t - \left( -b \right)} \right) P_{v} \left( \frac{1}{P_{d}} \right)
+ \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}. ξ v ( P ) = ( t − ( − b ) ( β ma x − β min ) n ) P v ( P d 1 ) + t − ( − b ) β min t − β ma x ( − b ) . Consider the map ξ d \xi_{d} ξ d , where
ξ d ( P ) = ( A P p r o j , h + B P p r o j , v + C ′ P p r o j , d + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ θ ( P d ) + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ ( A ′ P d + B ′ ) + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C ′ A ′ P d + C ′ B ′ + D ′ ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + ( C ′ A ′ ) P d + ( C ′ B ′ + D ′ ) ) ( 1 P d ) = ( A P p r o j , h + B P p r o j , v + C P d + D ) ( 1 P d ) = ( A n P h + B n P v + C P d + D ) ( 1 P d ) = A n P h ( 1 P d ) + B n P v ( 1 P d ) + C + D ( 1 P d ) \begin{align*}
\xi_{d} \left( P \right)
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} P_{proj,d} + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} \theta \left( P_{d} \right) + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} \left( A^{\prime} P_{d} + B^{\prime} \right) + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C^{\prime} A^{\prime} P_{d} + C^{\prime} B^{\prime} + D^{\prime} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + \left( C^{\prime} A^{\prime} \right) P_{d} + \left( C^{\prime} B^{\prime} + D^{\prime} \right) \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A P_{proj,h} + B P_{proj,v} + C P_{d} + D \right) \left( \frac{1}{P_{d}} \right) \\
&= \left( A n P_{h} + B n P_{v} + C P_{d} + D \right) \left( \frac{1}{P_{d}} \right) \\
&= A n P_{h} \left( \frac{1}{P_{d}} \right) + B n P_{v} \left( \frac{1}{P_{d}} \right) + C + D \left( \frac{1}{P_{d}} \right) \\
\end{align*} ξ d ( P ) = ( A P p ro j , h + B P p ro j , v + C ′ P p ro j , d + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ θ ( P d ) + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ ( A ′ P d + B ′ ) + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C ′ A ′ P d + C ′ B ′ + D ′ ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + ( C ′ A ′ ) P d + ( C ′ B ′ + D ′ ) ) ( P d 1 ) = ( A P p ro j , h + B P p ro j , v + C P d + D ) ( P d 1 ) = ( A n P h + B n P v + C P d + D ) ( P d 1 ) = A n P h ( P d 1 ) + B n P v ( P d 1 ) + C + D ( P d 1 ) where C = C ′ A ′ C = C^{\prime} A^{\prime} C = C ′ A ′ and D = C ′ B ′ + D ′ D = C^{\prime} B^{\prime} + D^{\prime} D = C ′ B ′ + D ′ , so that
ξ d ( P ) = A n P h ( 1 P d ) + B n P v ( 1 P d ) + C + D ( 1 P d ) . \xi_{d} \left( P \right) = A n P_{h} \left( \frac{1}{P_{d}} \right) + B n P_{v} \left( \frac{1}{P_{d}} \right) + C + D \left( \frac{1}{P_{d}} \right). ξ d ( P ) = A n P h ( P d 1 ) + B n P v ( P d 1 ) + C + D ( P d 1 ) . Define the boundary conditions for our chosen points
ξ d ( Q l e f t ) = 0 ξ d ( Q r i g h t ) = 0 ξ d ( Q b o t t o m ) = 0 ξ d ( Q t o p ) = 0 ξ d ( Q n e a r ) = γ m i n ξ d ( Q f a r ) = γ m a x \begin{align*}
\xi_{d} \left( Q_{left} \right) &= 0 \\
\xi_{d} \left( Q_{right} \right) &= 0 \\
\xi_{d} \left( Q_{bottom} \right) &= 0 \\
\xi_{d} \left( Q_{top} \right) &= 0 \\
\xi_{d} \left( Q_{near} \right) &= \gamma_{min} \\
\xi_{d} \left( Q_{far} \right) &= \gamma_{max} \\
\end{align*} ξ d ( Q l e f t ) ξ d ( Q r i g h t ) ξ d ( Q b o tt o m ) ξ d ( Q t o p ) ξ d ( Q n e a r ) ξ d ( Q f a r ) = 0 = 0 = 0 = 0 = γ min = γ ma x which we need to justify. The view coordinates are orthogonal to each other, and the normalized device coordinates
are also orthogonal to each other. This means that ξ d \xi_{d} ξ d should only be a function of the depth component
and not the horizontal or vertical components. The points Q l e f t , Q r i g h t , Q b o t t o m , Q t o p Q_{left}, Q_{right}, Q_{bottom}, Q_{top} Q l e f t , Q r i g h t , Q b o tt o m , Q t o p lie on
the near plane, which have a depth component of n n n . Since perspective projection projects depth components
onto the near plane, points already on the near plane should stay on the near plane. Similarly, points on the far
plane should stay on the far plane. Consequently, the depth component should have no dependence on the horizontal
or vertical components, only a depth term and an affine translation term.
Applying the boundary conditions, we have
ξ d ( Q l e f t ) = A n ⋅ ( − l ) ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = − A l + C + D ( 1 n ) = 0 ξ d ( Q r i g h t ) = A n ⋅ r ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = A r + C + D ( 1 n ) = 0 ξ d ( Q b o t t o m ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ ( − b ) ⋅ ( 1 n ) + C + D ( 1 n ) = − B b + C + D ( 1 n ) = 0 ξ d ( Q t o p ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ t ⋅ ( 1 n ) + C + D ( 1 n ) = B t + C + D ( 1 n ) = 0 ξ d ( Q n e a r ) = A n ⋅ 0 ⋅ ( 1 n ) + B n ⋅ 0 ⋅ ( 1 n ) + C + D ( 1 n ) = C + D ( 1 n ) = γ m i n ξ d ( Q f a r ) = A n ⋅ 0 ⋅ ( 1 f ) + B n ⋅ 0 ⋅ ( 1 f ) + C + D ( 1 f ) = C + D ( 1 f ) = γ m a x \begin{align*}
\xi_{d} \left( Q_{left} \right)
&= A n \cdot \left( -l \right) \cdot\left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= -A l + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{d} \left( Q_{right} \right)
&= A n \cdot r \cdot \left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= A r + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{d} \left( Q_{bottom} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot \left( -b \right) \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= -B b + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{d} \left( Q_{top} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot t \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= B t + C + D \left( \frac{1}{n} \right) \\
&= 0 \\
\xi_{d} \left( Q_{near} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{n} \right) + B n \cdot 0 \cdot \left( \frac{1}{n} \right) + C + D \left( \frac{1}{n} \right) \\
&= C + D \left( \frac{1}{n} \right) \\
&= \gamma_{min} \\
\xi_{d} \left( Q_{far} \right)
&= A n \cdot 0 \cdot \left( \frac{1}{f} \right) + B n \cdot 0 \cdot \left( \frac{1}{f} \right) + C + D \left( \frac{1}{f} \right) \\
&= C + D \left( \frac{1}{f} \right) \\
&= \gamma_{max} \\
\end{align*} ξ d ( Q l e f t ) ξ d ( Q r i g h t ) ξ d ( Q b o tt o m ) ξ d ( Q t o p ) ξ d ( Q n e a r ) ξ d ( Q f a r ) = A n ⋅ ( − l ) ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = − A l + C + D ( n 1 ) = 0 = A n ⋅ r ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = A r + C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ ( − b ) ⋅ ( n 1 ) + C + D ( n 1 ) = − B b + C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ t ⋅ ( n 1 ) + C + D ( n 1 ) = Bt + C + D ( n 1 ) = 0 = A n ⋅ 0 ⋅ ( n 1 ) + B n ⋅ 0 ⋅ ( n 1 ) + C + D ( n 1 ) = C + D ( n 1 ) = γ min = A n ⋅ 0 ⋅ ( f 1 ) + B n ⋅ 0 ⋅ ( f 1 ) + C + D ( f 1 ) = C + D ( f 1 ) = γ ma x so that
ξ d ( Q l e f t ) = − A l + C + D ( 1 n ) = γ m i n ξ d ( Q r i g h t ) = A r + C + D ( 1 n ) = γ m i n ξ d ( Q b o t t o m ) = − B b + C + D ( 1 n ) = γ m i n ξ d ( Q t o p ) = B t + C + D ( 1 n ) = γ m i n ξ d ( Q n e a r ) = C + D ( 1 n ) = γ m i n ξ d ( Q f a r ) = C + D ( 1 f ) = γ m a x \begin{align*}
\xi_{d} \left( Q_{left} \right)
&= -A l + C + D \left( \frac{1}{n} \right)
&&= \gamma_{min} \\
\xi_{d} \left( Q_{right} \right)
&= A r + C + D \left( \frac{1}{n} \right)
&&= \gamma_{min} \\
\xi_{d} \left( Q_{bottom} \right)
&= -B b + C + D \left( \frac{1}{n} \right)
&&= \gamma_{min} \\
\xi_{d} \left( Q_{top} \right)
&= B t + C + D \left( \frac{1}{n} \right)
&&= \gamma_{min} \\
\xi_{d} \left( Q_{near} \right)
&= C + D \left( \frac{1}{n} \right)
&&= \gamma_{min} \\
\xi_{d} \left( Q_{far} \right)
&= C + D \left( \frac{1}{f} \right)
&&= \gamma_{max} \\
\end{align*} ξ d ( Q l e f t ) ξ d ( Q r i g h t ) ξ d ( Q b o tt o m ) ξ d ( Q t o p ) ξ d ( Q n e a r ) ξ d ( Q f a r ) = − A l + C + D ( n 1 ) = A r + C + D ( n 1 ) = − B b + C + D ( n 1 ) = Bt + C + D ( n 1 ) = C + D ( n 1 ) = C + D ( f 1 ) = γ min = γ min = γ min = γ min = γ min = γ ma x and now we compute the constants. and now we compute the constants. Subtracting ξ d ( Q r i g h t ) \xi_{d} \left( Q_{right} \right) ξ d ( Q r i g h t ) from
ξ d ( Q l e f t ) \xi_{d} \left( Q_{left} \right) ξ d ( Q l e f t ) in (88) yields
ξ d ( Q r i g h t ) − ξ d ( Q l e f t ) = [ A r + C + D ( 1 n ) ] − [ − A l + C + D ( 1 n ) ] = A r − ( − A l ) = A ( r − ( − l ) ) = γ m i n − γ m i n = 0. \begin{align*}
\xi_{d} \left( Q_{right} \right) - \xi_{d} \left( Q_{left} \right)
&= \left[ A r + C + D \left( \frac{1}{n} \right) \right] - \left[ -A l + C + D \left( \frac{1}{n} \right) \right] \\
&= A r - \left( - A l \right) \\
&= A \left( r - \left( -l \right) \right) \\
&= \gamma_{min} - \gamma_{min} \\
&= 0.
\end{align*} ξ d ( Q r i g h t ) − ξ d ( Q l e f t ) = [ A r + C + D ( n 1 ) ] − [ − A l + C + D ( n 1 ) ] = A r − ( − A l ) = A ( r − ( − l ) ) = γ min − γ min = 0. Solving for A A A , we see that
since r − ( − l ) = r + l ≠ 0 r - (-l) = r + l \neq 0 r − ( − l ) = r + l = 0 . Subtracting ξ d ( Q t o p ) \xi_{d} \left( Q_{top} \right) ξ d ( Q t o p ) from
ξ d ( Q b o t t o m ) \xi_{d} \left( Q_{bottom} \right) ξ d ( Q b o tt o m ) in (58) yields
ξ d ( Q t o p ) − ξ d ( Q b o t t o m ) = [ B t + C + D ( 1 n ) ] − [ − B b + C + D ( 1 n ) ] = B t − B ( − b ) = B ( t − ( − b ) ) = γ m i n − γ m i n = 0. \begin{align*}
\xi_{d} \left( Q_{top} \right) - \xi_{d} \left( Q_{bottom} \right)
&= \left[ B t + C + D \left( \frac{1}{n} \right) \right] - \left[ -B b + C + D \left( \frac{1}{n} \right) \right] \\
&= B t - B \left( -b \right) \\
&= B \left( t - \left( -b \right) \right) \\
&= \gamma_{min} - \gamma_{min} \\
&= 0.
\end{align*} ξ d ( Q t o p ) − ξ d ( Q b o tt o m ) = [ Bt + C + D ( n 1 ) ] − [ − B b + C + D ( n 1 ) ] = Bt − B ( − b ) = B ( t − ( − b ) ) = γ min − γ min = 0. Solving for B B B , we see that
since t − ( − b ) = t + b ≠ 0 t - (-b) = t + b \neq 0 t − ( − b ) = t + b = 0 . Subtracting ξ d ( Q f a r ) \xi_{d} \left( Q_{far} \right) ξ d ( Q f a r ) from
ξ d ( Q n e a r ) \xi_{d} \left( Q_{near} \right) ξ d ( Q n e a r ) in (88) yields
ξ d ( Q f a r ) − ξ d ( Q n e a r ) = [ C + D ( 1 f ) ] − [ C + D ( 1 n ) ] = D ( 1 f − 1 n ) = D ( n − f f n ) = D ( − f − n f n ) = γ m a x − γ m i n . \begin{align*}
\xi_{d} \left( Q_{far} \right) - \xi_{d} \left( Q_{near} \right)
&= \left[ C + D \left( \frac{1}{f} \right) \right] - \left[ C + D \left( \frac{1}{n} \right) \right] \\
&= D \left( \frac{1}{f} - \frac{1}{n} \right) \\
&= D \left( \frac{n - f}{f n} \right) \\
&= D \left( -\frac{f - n}{f n} \right) \\
&= \gamma_{max} - \gamma_{min}.
\end{align*} ξ d ( Q f a r ) − ξ d ( Q n e a r ) = [ C + D ( f 1 ) ] − [ C + D ( n 1 ) ] = D ( f 1 − n 1 ) = D ( f n n − f ) = D ( − f n f − n ) = γ ma x − γ min . Solving for D D D , we see that
D = − ( γ m a x − γ m i n ) f n f − n . D = -\frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{f - n}. D = − f − n ( γ ma x − γ min ) f n . Substituting the constants (90) , (92) , and
(94) back into ξ d ( Q f a r ) \xi_{d}(Q_{far}) ξ d ( Q f a r ) in (88) gives us
ξ d ( Q f a r ) = C + D ( 1 f ) = C + ( − ( γ m a x − γ m i n ) f n f − n ) ( 1 f ) = C + ( − ( γ m a x − γ m i n ) n f − n ) = γ m a x . \begin{align*}
\xi_{d} \left( Q_{far} \right)
&= C + D \left( \frac{1}{f} \right) \\
&= C + \left( -\frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{f - n} \right) \left( \frac{1}{f} \right) \\
&= C + \left( -\frac{ \left( \gamma_{max} - \gamma_{min} \right) n }{f - n} \right) \\
&= \gamma_{max}.
\end{align*} ξ d ( Q f a r ) = C + D ( f 1 ) = C + ( − f − n ( γ ma x − γ min ) f n ) ( f 1 ) = C + ( − f − n ( γ ma x − γ min ) n ) = γ ma x . Solving for C C C
C = γ m a x + ( ( γ m a x − γ m i n ) n f − n ) = γ m a x ( f − n ) + ( γ m a x − γ m i n ) n f − n = γ m a x f − γ m a x n + γ m a x n − γ m i n n f − n = γ m a x f − γ m i n n f − n \begin{align*}
C &= \gamma_{max} + \left( \frac{ \left( \gamma_{max} - \gamma_{min} \right) n }{f - n} \right) \\
&= \frac{\gamma_{max} \left( f - n \right) + \left( \gamma_{max} - \gamma_{min} \right) n}{f - n} \\
&= \frac{\gamma_{max} f - \gamma_{max} n + \gamma_{max} n - \gamma_{min} n}{f - n} \\
&= \frac{\gamma_{max} f - \gamma_{min} n}{f - n} \\
\end{align*} C = γ ma x + ( f − n ( γ ma x − γ min ) n ) = f − n γ ma x ( f − n ) + ( γ ma x − γ min ) n = f − n γ ma x f − γ ma x n + γ ma x n − γ min n = f − n γ ma x f − γ min n we have
C = γ m a x f − γ m i n n f − n . C = \frac{\gamma_{max} f - \gamma_{min} n}{f - n}. C = f − n γ ma x f − γ min n . Assembling the constants (90) , (92) , (97) ,
(94) back into (85) we have the complete formula for the
auxiliary function ξ d \xi_{d} ξ d
ξ d ( P ) = γ m a x f − γ m i n n f − n − ( ( γ m a x − γ m i n ) f n f − n ) ( 1 P d ) . \xi_{d} \left( P \right)
= \frac{\gamma_{max} f - \gamma_{min} n}{f - n}
- \left( \frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{f - n} \right) \left( \frac{1}{P_{d}} \right). ξ d ( P ) = f − n γ ma x f − γ min n − ( f − n ( γ ma x − γ min ) f n ) ( P d 1 ) . Now we return to the definitions for the clip space functions. Recall from (49) that
P n d c , h ≡ ξ h ( P ) ≡ ϕ h ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) = P c l i p , h P c l i p , w P n d c , v ≡ ξ v ( P ) ≡ ϕ v ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) = P c l i p , v P c l i p , w P n d c , d ≡ ξ d ( P ) ≡ ϕ d ( P p r o j ) ( 1 ϕ w ( P p r o j ) ) = P c l i p , d P c l i p , w \begin{align*}
P_{ndc,h} \equiv \xi_{h} \left( P \right)
&\equiv \phi_{h} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right) } \right)
= \frac{P_{clip,h}}{P_{clip,w}} \\
P_{ndc,v} \equiv \xi_{v} \left( P \right)
&\equiv \phi_{v} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right) } \right)
= \frac{P_{clip,v}}{P_{clip,w}} \\
P_{ndc,d} \equiv \xi_{d} \left( P \right)
&\equiv \phi_{d} \left( P_{proj} \right) \left( \frac{1}{\phi_{w} \left( P_{proj} \right) } \right)
= \frac{P_{clip,d}}{P_{clip,w}} \\
\end{align*} P n d c , h ≡ ξ h ( P ) P n d c , v ≡ ξ v ( P ) P n d c , d ≡ ξ d ( P ) ≡ ϕ h ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) = P c l i p , w P c l i p , h ≡ ϕ v ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) = P c l i p , w P c l i p , v ≡ ϕ d ( P p ro j ) ( ϕ w ( P p ro j ) 1 ) = P c l i p , w P c l i p , d where P p r o j P_{proj} P p ro j denotes a point P ∈ R 3 P \in \mathbb{R}^{3} P ∈ R 3 in projected coordinates, and
P c l i p , w = ϕ w ( P p r o j ) = P d P_{clip,w} = \phi_{w}(P_{proj}) = P_{d} P c l i p , w = ϕ w ( P p ro j ) = P d is an affine scalar function. We now derive the clip
coordinate functions ϕ h , ϕ v , ϕ d \phi_{h}, \phi_{v}, \phi_{d} ϕ h , ϕ v , ϕ d given by
P c l i p , h = ϕ h ( P p r o j ) P c l i p , v = ϕ v ( P p r o j ) P c l i p , d = ϕ d ( P p r o j ) \begin{align*}
P_{clip,h} &= \phi_{h} \left( P_{proj} \right) \\
P_{clip,v} &= \phi_{v} \left( P_{proj} \right) \\
P_{clip,d} &= \phi_{d} \left( P_{proj} \right) \\
\end{align*} P c l i p , h P c l i p , v P c l i p , d = ϕ h ( P p ro j ) = ϕ v ( P p ro j ) = ϕ d ( P p ro j ) by comparing the equations in (52) with (68) , (83) , and
(98) . Consider the affine map ϕ h \phi_{h} ϕ h . Rearranging terms in (68) ,
we have
P n d c , h = ( α m a x − α m i n r − ( − l ) ) P p r o j , h + α m i n r − α m i n ( − l ) r − ( − l ) = ( α m a x − α m i n r − ( − l ) ) n P h ( 1 P d ) + α m i n r − α m i n ( − l ) r − ( − l ) = ( α m a x − α m i n r − ( − l ) ) n P h ( 1 P d ) + ( α m i n r − α m i n ( − l ) r − ( − l ) ) P d ( 1 P d ) = ( ( α m a x − α m i n ) n r − ( − l ) ) P h ( 1 P d ) + ( α m i n r − α m i n ( − l ) r − ( − l ) ) P d ( 1 P d ) = [ ( ( α m a x − α m i n ) n r − ( − l ) ) P h + ( α m i n r − α m i n ( − l ) r − ( − l ) ) P d ] ( 1 P d ) . \begin{align*}
P_{ndc,h}
&= \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) P_{proj,h}
+ \frac{\alpha_{min} r - \alpha_{min} \left( -l \right)}{r - \left( -l \right)} \\
&= \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) n P_{h} \left( \frac{1}{P_{d}} \right)
+ \frac{\alpha_{min} r - \alpha_{min} \left( -l \right)}{r - \left( -l \right)} \\
&= \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) n P_{h} \left( \frac{1}{P_{d}} \right)
+ \left( \frac{ \alpha_{min} r - \alpha_{min} \left( -l \right) }{r - \left( -l \right)} \right) P_{d} \left( \frac{1}{P_{d}} \right) \\
&= \left( \frac{ \left( \alpha_{max} - \alpha_{min} \right) n }{r - \left( -l \right)} \right) P_{h} \left( \frac{1}{P_{d}} \right)
+ \left( \frac{ \alpha_{min} r - \alpha_{min} \left( -l \right) }{r - \left( -l \right)} \right) P_{d} \left( \frac{1}{P_{d}} \right) \\
&= \left[ \left( \frac{ \left( \alpha_{max} - \alpha_{min} \right) n }{r - \left( -l \right)} \right) P_{h}
+ \left( \frac{ \alpha_{min} r - \alpha_{min} \left( -l \right) }{r - \left( -l \right)} \right) P_{d} \right] \left( \frac{1}{P_{d}} \right).
\end{align*} P n d c , h = ( r − ( − l ) α ma x − α min ) P p ro j , h + r − ( − l ) α min r − α min ( − l ) = ( r − ( − l ) α ma x − α min ) n P h ( P d 1 ) + r − ( − l ) α min r − α min ( − l ) = ( r − ( − l ) α ma x − α min ) n P h ( P d 1 ) + ( r − ( − l ) α min r − α min ( − l ) ) P d ( P d 1 ) = ( r − ( − l ) ( α ma x − α min ) n ) P h ( P d 1 ) + ( r − ( − l ) α min r − α min ( − l ) ) P d ( P d 1 ) = [ ( r − ( − l ) ( α ma x − α min ) n ) P h + ( r − ( − l ) α min r − α min ( − l ) ) P d ] ( P d 1 ) . Comparing (101) with (52) , we see that
P c l i p , h = ϕ h ( P p r o j ) = ( ( α m a x − α m i n ) n r − ( − l ) ) P h + ( α m i n r − α m i n ( − l ) r − ( − l ) ) P d . P_{clip,h} = \phi_{h} \left( P_{proj} \right) = \left( \frac{ \left( \alpha_{max} - \alpha_{min} \right) n }{r - \left( -l \right)} \right) P_{h}
+ \left( \frac{ \alpha_{min} r - \alpha_{min} \left( -l \right) }{r - \left( -l \right)} \right) P_{d}. P c l i p , h = ϕ h ( P p ro j ) = ( r − ( − l ) ( α ma x − α min ) n ) P h + ( r − ( − l ) α min r − α min ( − l ) ) P d . Consider the affine map ϕ v \phi_{v} ϕ v . Rearranging terms in (83) we have
P n d c , v = ( β m a x − β m i n t − ( − b ) ) P p r o j , v + β m i n t − β m i n ( − b ) t − ( − b ) = ( β m a x − β m i n t − ( − b ) ) n P v ( 1 P d ) + β m i n t − β m i n ( − b ) t − ( − b ) = ( β m a x − β m i n t − ( − b ) ) n P v ( 1 P d ) + ( β m i n t − β m i n ( − b ) t − ( − b ) ) P d ( 1 P d ) = ( ( β m a x − β m i n ) n t − ( − b ) ) P v ( 1 P d ) + ( β m i n t − β m i n ( − b ) t − ( − b ) ) P d ( 1 P d ) = [ ( ( β m a x − β m i n ) n t − ( − b ) ) P v + ( β m i n t − β m i n ( − b ) t − ( − b ) ) P d ] ( 1 P d ) . \begin{align*}
P_{ndc,v}
&= \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) P_{proj,v}
+ \frac{\beta_{min} t - \beta_{min} \left( -b \right)}{t - \left( -b \right)} \\
&= \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) n P_{v} \left( \frac{1}{P_{d}} \right)
+ \frac{\beta_{min} t - \beta_{min} \left( -b \right)}{t - \left( -b \right)} \\
&= \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) n P_{v} \left( \frac{1}{P_{d}} \right)
+ \left( \frac{ \beta_{min} t - \beta_{min} \left( -b \right) }{t - \left( -b \right)} \right) P_{d} \left( \frac{1}{P_{d}} \right) \\
&= \left( \frac{ \left( \beta_{max} - \beta_{min} \right) n }{t - \left( -b \right)} \right) P_{v} \left( \frac{1}{P_{d}} \right)
+ \left( \frac{ \beta_{min} t - \beta_{min} \left( -b \right) }{t - \left( -b \right)} \right) P_{d} \left( \frac{1}{P_{d}} \right) \\
&= \left[ \left( \frac{ \left( \beta_{max} - \beta_{min} \right) n }{t - \left( -b \right)} \right) P_{v}
+ \left( \frac{ \beta_{min} t - \beta_{min} \left( -b \right) }{t - \left( -b \right)} \right) P_{d} \right] \left( \frac{1}{P_{d}} \right).
\end{align*} P n d c , v = ( t − ( − b ) β ma x − β min ) P p ro j , v + t − ( − b ) β min t − β min ( − b ) = ( t − ( − b ) β ma x − β min ) n P v ( P d 1 ) + t − ( − b ) β min t − β min ( − b ) = ( t − ( − b ) β ma x − β min ) n P v ( P d 1 ) + ( t − ( − b ) β min t − β min ( − b ) ) P d ( P d 1 ) = ( t − ( − b ) ( β ma x − β min ) n ) P v ( P d 1 ) + ( t − ( − b ) β min t − β min ( − b ) ) P d ( P d 1 ) = [ ( t − ( − b ) ( β ma x − β min ) n ) P v + ( t − ( − b ) β min t − β min ( − b ) ) P d ] ( P d 1 ) . Comparing (103) with (52) we see that
P c l i p , v = ϕ v ( P p r o j ) = ( ( β m a x − β m i n ) n t − ( − b ) ) P v + ( β m i n t − β m i n ( − b ) t − ( − b ) ) P d . P_{clip,v} = \phi_{v} \left( P_{proj} \right) = \left( \frac{ \left( \beta_{max} - \beta_{min} \right) n }{t - \left( -b \right)} \right) P_{v}
+ \left( \frac{ \beta_{min} t - \beta_{min} \left( -b \right) }{t - \left( -b \right)} \right) P_{d}. P c l i p , v = ϕ v ( P p ro j ) = ( t − ( − b ) ( β ma x − β min ) n ) P v + ( t − ( − b ) β min t − β min ( − b ) ) P d . Finally, consider the affine map ϕ d \phi_{d} ϕ d . Rearranging terms in (98) we have
P n d c , d = γ m a x f − γ m i n n f − n − ( ( γ m a x − γ m i n ) f n f − n ) ( 1 P d ) = [ ( γ m a x f − γ m i n n f − n ) P d − ( γ m a x − γ m i n ) f n f − n ] ( 1 P d ) \begin{align*}
P_{ndc,d}
&= \frac{\gamma_{max} f - \gamma_{min} n}{f - n}
- \left( \frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{f - n} \right) \left( \frac{1}{P_{d}} \right) \\
&= \left[
\left( \frac{\gamma_{max} f - \gamma_{min} n}{f - n} \right) P_{d}
- \frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{ f - n }
\right]
\left( \frac{1}{P_{d}} \right)
\\
\end{align*} P n d c , d = f − n γ ma x f − γ min n − ( f − n ( γ ma x − γ min ) f n ) ( P d 1 ) = [ ( f − n γ ma x f − γ min n ) P d − f − n ( γ ma x − γ min ) f n ] ( P d 1 ) Comparing (105) with (52) we see that
P c l i p , d = ϕ d ( P p r o j ) = ( γ m a x f − γ m i n n f − n ) P d − ( γ m a x − γ m i n ) f n f − n . P_{clip,d}
= \phi_{d} \left( P_{proj} \right)
= \left( \frac{\gamma_{max} f - \gamma_{min} n}{f - n} \right) P_{d}
- \frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{ f - n }. P c l i p , d = ϕ d ( P p ro j ) = ( f − n γ ma x f − γ min n ) P d − f − n ( γ ma x − γ min ) f n . Since ϕ h \phi_{h} ϕ h , ϕ v \phi_{v} ϕ v , and ϕ d \phi_{d} ϕ d are the components of an affine
transformation, and normalized device coordinates are a projective function of the view coordinates
with ϕ w ( P p r o j ) = P d \phi_{w}(P_{proj}) = P_{d} ϕ w ( P p ro j ) = P d as the denominator, the perspective projection transformation
has the form of the matrix in (38) lifted into R P 3 \mathbb{RP}^{3} RP 3 . The
resulting matrix equation for the matrix representation is then
[ P c l i p , h P c l i p , v P c l i p , d P c l i p , w ] = [ ( α m a x − α m i n ) n r − ( − l ) 0 α m i n r − α m a x ( − l ) r − ( − l ) 0 0 ( β m a x − β m i n ) n t − ( − b ) β m i n t − β m a x ( − b ) t − ( − b ) 0 0 0 γ m a x f − γ m i n n f − n − ( γ m a x − γ m i n ) f n f − n 0 0 1 0 ] [ P h P v P d P w ] . \begin{bmatrix}
P_{clip,h} \\
P_{clip,v} \\
P_{clip,d} \\
P_{clip,w} \\
\end{bmatrix}
=
\begin{bmatrix}
\frac{\left( \alpha_{max} - \alpha_{min} \right) n }{r - \left( -l \right)}
& 0
& \frac{\alpha_{min}r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}
& 0
\\
0
& \frac{\left( \beta_{max} - \beta_{min} \right) n }{t - \left( -b \right)}
& \frac{\beta_{min}t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}
& 0
\\
0
& 0
& \frac{\gamma_{max}f - \gamma_{min}n}{f - n}
& -\frac{\left( \gamma_{max} - \gamma_{min} \right) f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\begin{bmatrix}
P_{h} \\
P_{v} \\
P_{d} \\
P_{w} \\
\end{bmatrix}. ⎣ ⎡ P c l i p , h P c l i p , v P c l i p , d P c l i p , w ⎦ ⎤ = ⎣ ⎡ r − ( − l ) ( α ma x − α min ) n 0 0 0 0 t − ( − b ) ( β ma x − β min ) n 0 0 r − ( − l ) α min r − α ma x ( − l ) t − ( − b ) β min t − β ma x ( − b ) f − n γ ma x f − γ min n 1 0 0 − f − n ( γ ma x − γ min ) f n 0 ⎦ ⎤ ⎣ ⎡ P h P v P d P w ⎦ ⎤ . This yields the first major result, the canonical perspective projection matrix M p e r C M^{C}_{per} M p er C .
Let F c a n = ( O ~ c a n , B c a n ) \mathcal{F}_{can} = (\tilde{O}_{can}, \mathcal{B}_{can}) F c an = ( O ~ c an , B c an ) be a canonical coordinate frame on
E 3 \mathbb{E}^{3} E 3 , where
B c a n = ( u ^ h , u ^ v , u ^ d ) \mathcal{B}_{can} = (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_v, \mathbf{\hat{u}}_{d}) B c an = ( u ^ h , u ^ v , u ^ d ) is the basis
for the frame. The canonical perspective projection matrix for F c a n \mathcal{F}_{can} F c an is given by
M p e r C = [ ( α m a x − α m i n ) n r − ( − l ) 0 α m i n r − α m a x ( − l ) r − ( − l ) 0 0 ( β m a x − β m i n ) n t − ( − b ) β m i n t − β m a x ( − b ) t − ( − b ) 0 0 0 γ m a x f − γ m i n n f − n − ( γ m a x − γ m i n ) f n f − n 0 0 1 0 ] . M^{C}_{per} =
\begin{bmatrix}
\frac{\left( \alpha_{max} - \alpha_{min} \right) n }{r - \left( -l \right)}
& 0
& \frac{\alpha_{min}r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}
& 0
\\
0
& \frac{\left( \beta_{max} - \beta_{min} \right) n }{t - \left( -b \right)}
& \frac{\beta_{min}t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}
& 0
\\
0
& 0
& \frac{\gamma_{max}f - \gamma_{min}n}{f - n}
& -\frac{\left( \gamma_{max} - \gamma_{min} \right) f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er C = ⎣ ⎡ r − ( − l ) ( α ma x − α min ) n 0 0 0 0 t − ( − b ) ( β ma x − β min ) n 0 0 r − ( − l ) α min r − α ma x ( − l ) t − ( − b ) β min t − β ma x ( − b ) f − n γ ma x f − γ min n 1 0 0 − f − n ( γ ma x − γ min ) f n 0 ⎦ ⎤ . This completes the derivation of the perspective projection matrix.
The Canonical Orthographic Projection Matrix ¶ We now construct the canonical orthographic projection matrix for
the frame ( O ~ v i e w , ( u ^ h , u ^ v , u ^ d ) ) (\tilde{O}_{view}, (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d})) ( O ~ v i e w , ( u ^ h , u ^ v , u ^ d )) with
the orthographic view volume parametrized by [ − l , r ] × [ − b , t ] × [ n , f ] [-l, r] \times [-b, t] \times [n, f] [ − l , r ] × [ − b , t ] × [ n , f ] and
the canonical view volume parametrized by
[ α m i n , α m a x ] × [ β m i n , β m a x ] × [ γ m i n , γ m a x ] [\alpha_{min}, \alpha_{max}] \times [\beta_{min}, \beta_{max}] \times [\gamma_{min}, \gamma_{max}] [ α min , α ma x ] × [ β min , β ma x ] × [ γ min , γ ma x ] .
An orthographic projection works by removing the component parallel to the direction normal
to the plane of projection in three dimensions. Orthographic projections preserve
the lengths of lines parallel to the projection plane. It produces the component of a geometric
figure that is parallel to the plane of projection. Unlike perspective projection, there
is no depth distortion. In terms of our orthonormal frame, an orthographic projection removes the
depth component from a vector. Let P ~ ∈ E 3 \tilde{P} \in \mathbb{E}^{3} P ~ ∈ E 3 be a point. The orthographic projection
is a map T o r t h ′ : E 3 → E 3 T^{\prime}_{orth} : \mathbb{E}^{3} \rightarrow \mathbb{E}^{3} T or t h ′ : E 3 → E 3 given by
T o r t h ′ ( P ~ ) = P ~ − ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ . T^{\prime}_{orth} \left( \tilde{P} \right) = \tilde{P} - \left( \left( \tilde{P} - \tilde{O}_{view} \right) \cdot \mathbf{\hat{n}} \right) \mathbf{\hat{n}}. T or t h ′ ( P ~ ) = P ~ − ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ . In the coordinate frame
( O ~ v i e w , ( u ^ h , u ^ v , u ^ d ) ) (\tilde{O}_{view}, (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_{v}, \mathbf{\hat{u}}_{d})) ( O ~ v i e w , ( u ^ h , u ^ v , u ^ d ))
let P = P ~ − O ~ v i e w P = \tilde{P} - \tilde{O}_{view} P = P ~ − O ~ v i e w be a representation of the point P P P
given by P = P h u ^ h + P v u ^ v + P d u ^ d P = P_{h} \mathbf{\hat{u}}_{h} + P_{v} \mathbf{\hat{u}}_{v} + P_{d} \mathbf{\hat{u}}_{d} P = P h u ^ h + P v u ^ v + P d u ^ d .
The orthographic projection has the form
T o r t h ′ ( P ) = P − ( P ⋅ u ^ d ) u ^ d = P − P d u ^ d = P h u ^ h + P v u ^ v T^{\prime}_{orth} \left( P \right)
= P - \left( P \cdot \mathbf{\hat{u}}_{d} \right) \mathbf{\hat{u}}_{d}
= P - P_{d} \mathbf{\hat{u}}_{d}
= P_{h} \mathbf{\hat{u}}_{h} + P_{v} \mathbf{\hat{u}}_{v} T or t h ′ ( P ) = P − ( P ⋅ u ^ d ) u ^ d = P − P d u ^ d = P h u ^ h + P v u ^ v so that T o r t h ′ T^{\prime}_{orth} T or t h ′ indeed projects out the depth component as claimed. This is the
usual definition of orthographic projection. The problem is that we still need depth information for
rendering, so this information must be preserved in our true projection. Since orthographic projection
does not distort depth in any way, and indeed has no denominator, it is an affine transformation. Thus the
orthographic projection needs to carry depth information. We need to add the depth information
along the normal vector to the projection plane into the transformation to get our projected coordinates.
Let T o r t h : E 3 → E 3 T_{orth} : \mathbb{E}^{3} \rightarrow \mathbb{E}^{3} T or t h : E 3 → E 3 be the transformation given by
T o r t h ( P ~ ) = T o r t h ′ ( P ~ ) + ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ . T_{orth} \left( \tilde{P} \right)
= T^{\prime}_{orth} \left( \tilde{P} \right)
+ \left( \left( \tilde{P} - \tilde{O}_{view} \right) \cdot \mathbf{\hat{n}} \right) \mathbf{\hat{n}}. T or t h ( P ~ ) = T or t h ′ ( P ~ ) + ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ . Expanding out the definition
T o r t h ( P ~ ) = P ~ − ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ + ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ = P ~ = I ( P ) T_{orth} \left( \tilde{P} \right)
= \tilde{P}
- \left( \left( \tilde{P} - \tilde{O}_{view} \right) \cdot \mathbf{\hat{n}} \right) \mathbf{\hat{n}}
+ \left( \left( \tilde{P} - \tilde{O}_{view} \right) \cdot \mathbf{\hat{n}} \right) \mathbf{\hat{n}}
= \tilde{P}
= I \left( P \right) T or t h ( P ~ ) = P ~ − ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ + ( ( P ~ − O ~ v i e w ) ⋅ n ^ ) n ^ = P ~ = I ( P ) where I I I denotes the identity map I : E 3 → E 3 I : \mathbb{E}^{3} \rightarrow \mathbb{E}^{3} I : E 3 → E 3 . We see
that the orthographic projection is simply the identity map when the depth information if factored
back in. In components,
T o r t h ( P ) = I ( P ) = P T_{orth} \left( P \right) = I \left( P \right) = P T or t h ( P ) = I ( P ) = P so that
P p r o j , h = P h P p r o j , v = P v P p r o j , d = P d P p r o j , w = 1 \begin{align*}
P_{proj,h} &= P_{h} \\
P_{proj,v} &= P_{v} \\
P_{proj,d} &= P_{d} \\
P_{proj,w} &= 1 \\
\end{align*} P p ro j , h P p ro j , v P p ro j , d P p ro j , w = P h = P v = P d = 1 gives our projected coordinates. Thus we map directly to clip coordinates from view coordinates. To
complete the orthographic projection transformation, we need an affine transformation that maps the
orthographic view volume to the canonical view volume in normalized device coordinates. Just like the
perspective projection earlier, we infer the orthographic projection matrix indirectly using constraints
on how the orthographic view volume transforms into the canonical view volume. We require affine maps
ϕ h , ϕ v , ϕ d , ϕ w : R 3 → R \phi_{h}, \phi_{v}, \phi_{d}, \phi_{w} : \mathbb{R^{3}} \rightarrow \mathbb{R} ϕ h , ϕ v , ϕ d , ϕ w : R 3 → R such that
P c l i p , h = ϕ h ( P p r o j ) P c l i p , v = ϕ v ( P p r o j ) P c l i p , d = ϕ d ( P p r o j ) P c l i p , w = ϕ w ( P p r o j ) \begin{align*}
P_{clip,h} &= \phi_{h} \left( P_{proj} \right) \\
P_{clip,v} &= \phi_{v} \left( P_{proj} \right) \\
P_{clip,d} &= \phi_{d} \left( P_{proj} \right) \\
P_{clip,w} &= \phi_{w} \left( P_{proj} \right) \\
\end{align*} P c l i p , h P c l i p , v P c l i p , d P c l i p , w = ϕ h ( P p ro j ) = ϕ v ( P p ro j ) = ϕ d ( P p ro j ) = ϕ w ( P p ro j ) where we get ϕ w \phi_{w} ϕ w immediately because orthographic projections are affine maps. That is
ϕ w ( P ) = 1. \phi_{w} \left( P \right) = 1. ϕ w ( P ) = 1. where we use the fact that P p r o j = P P_{proj} = P P p ro j = P . Since affine transformations do not perform depth
normalization, we see that
P n d c , h = P c l i p , h P n d c , v = P c l i p , v P n d c , d = P c l i p , d P n d c , w = P c l i p , w \begin{align*}
P_{ndc,h} &= P_{clip,h} \\
P_{ndc,v} &= P_{clip,v} \\
P_{ndc,d} &= P_{clip,d} \\
P_{ndc,w} &= P_{clip,w} \\
\end{align*} P n d c , h P n d c , v P n d c , d P n d c , w = P c l i p , h = P c l i p , v = P c l i p , d = P c l i p , w therefore
P n d c , h = ϕ h ( P p r o j ) = ϕ h ( P ) P n d c , v = ϕ v ( P p r o j ) = ϕ v ( P ) P n d c , d = ϕ d ( P p r o j ) = ϕ d ( P ) \begin{align*}
P_{ndc,h} &= \phi_{h} \left( P_{proj} \right) &= \phi_{h} \left( P \right) \\
P_{ndc,v} &= \phi_{v} \left( P_{proj} \right) &= \phi_{v} \left( P \right) \\
P_{ndc,d} &= \phi_{d} \left( P_{proj} \right) &= \phi_{d} \left( P \right) \\
\end{align*} P n d c , h P n d c , v P n d c , d = ϕ h ( P p ro j ) = ϕ v ( P p ro j ) = ϕ d ( P p ro j ) = ϕ h ( P ) = ϕ v ( P ) = ϕ d ( P ) are the equations we need to solve for. As with the perspective projection transformation, we
use the constraints on the orthographic view volume to compute the functions. To establish constraints, we
need to talk about some well chosen points. We need to construct the maps
ϕ h , ϕ v , ϕ d \phi_{h}, \phi_{v}, \phi_{d} ϕ h , ϕ v , ϕ d such that the parametrization of the orthographic view volume maps to
the parametrization of the canonical view volume. That it, such that coordinates map as
− l ↦ α m i n -l \mapsto \alpha_{min} − l ↦ α min , r ↦ α m a x r \mapsto \alpha_{max} r ↦ α ma x , − b ↦ β m i n -b \mapsto \beta_{min} − b ↦ β min ,
t ↦ β m a x t \mapsto \beta_{max} t ↦ β ma x , n ↦ γ m i n n \mapsto \gamma_{min} n ↦ γ min , f ↦ γ m a x f \mapsto \gamma_{max} f ↦ γ ma x . Consider the
points in view coordinates
Q l e f t = − l u ^ h + n u ^ d Q r i g h t = r u ^ h + n u ^ d Q b o t t o m = − b u ^ v + n u ^ d Q t o p = t u ^ v + n u ^ d Q n e a r = n u ^ d Q f a r = f u ^ d \begin{align*}
Q_{left} &= -l \mathbf{\hat{u}}_{h} + n \mathbf{\hat{u}}_{d} \\
Q_{right} &= r \mathbf{\hat{u}}_{h} + n \mathbf{\hat{u}}_{d} \\
Q_{bottom} &= -b \mathbf{\hat{u}}_{v} + n \mathbf{\hat{u}}_{d} \\
Q_{top} &= t \mathbf{\hat{u}}_{v} + n \mathbf{\hat{u}}_{d} \\
Q_{near} &= n \mathbf{\hat{u}}_{d} \\
Q_{far} &= f \mathbf{\hat{u}}_{d} \\
\end{align*} Q l e f t Q r i g h t Q b o tt o m Q t o p Q n e a r Q f a r = − l u ^ h + n u ^ d = r u ^ h + n u ^ d = − b u ^ v + n u ^ d = t u ^ v + n u ^ d = n u ^ d = f u ^ d The points Q n e a r Q_{near} Q n e a r and Q f a r Q_{far} Q f a r are the points along the viewing axis
that intersect the near plane and the far plane, respectively, of the orthographic view volume. The
point Q l e f t Q_{left} Q l e f t represents the point of intersection of the left plane, near plane, and the
horizontal-vertical plane of the view volume. The point Q r i g h t Q_{right} Q r i g h t represents the point of
intersection of the right plane, near plane, and the horizontal-vertical plane of the view volume.
The point Q b o t t o m Q_{bottom} Q b o tt o m represents the point of intersection of the bottom plane, near plane,
and depth-vertical plane of the view volume. The point Q t o p Q_{top} Q t o p represents the point of
intersection of the top plane, near plane, and the depth-vertical plane of the view volume. In short,
the points Q n e a r Q_{near} Q n e a r and Q f a r Q_{far} Q f a r are the origins of the near and far planes, respectively.
The other four points and points chosen along the edge of the viewport in the near plane that allow us
to easily set up the boundary conditions to compute the functions ϕ h , ϕ v , ϕ d \phi_{h}, \phi_{v}, \phi_{d} ϕ h , ϕ v , ϕ d .
Consider the map ϕ h \phi_{h} ϕ h , where
ϕ h ( P ) = A P h + B P v + C P d + D \phi_{h} \left( P \right) = A P_{h} + B P_{v} + C P_{d} + D ϕ h ( P ) = A P h + B P v + C P d + D Define the boundary conditions for our chosen points
ϕ h ( Q l e f t ) = α m i n ϕ h ( Q r i g h t ) = α m a x ϕ h ( Q b o t t o m ) = 0 ϕ h ( Q t o p ) = 0 ϕ h ( Q n e a r ) = 0 ϕ h ( Q f a r ) = 0 \begin{align*}
\phi_{h} \left( Q_{left} \right) &= \alpha_{min} \\
\phi_{h} \left( Q_{right} \right) &= \alpha_{max} \\
\phi_{h} \left( Q_{bottom} \right) &= 0 \\
\phi_{h} \left( Q_{top} \right) &= 0 \\
\phi_{h} \left( Q_{near} \right) &= 0 \\
\phi_{h} \left( Q_{far} \right) &= 0 \\
\end{align*} ϕ h ( Q l e f t ) ϕ h ( Q r i g h t ) ϕ h ( Q b o tt o m ) ϕ h ( Q t o p ) ϕ h ( Q n e a r ) ϕ h ( Q f a r ) = α min = α ma x = 0 = 0 = 0 = 0 which we need to justify. The view coordinates are orthogonal to each other, and the normalized device
coordinates are also orthogonal to each other. This means that ϕ h \phi_{h} ϕ h should only be a function
of the horizontal component and not the vertical component. The points
Q b o t t o m , Q t o p , Q n e a r , Q f a r Q_{bottom}, Q_{top}, Q_{near}, Q_{far} Q b o tt o m , Q t o p , Q n e a r , Q f a r lie on the depth-vertical plane, which have a zero horizontal
component, so they should keep a zero horizontal component after transformation.
Applying the boundary conditions, we have
ϕ h ( Q l e f t ) = A ⋅ ( − l ) + B ⋅ 0 + C n + D = − A l + C n + D = α m i n ϕ h ( Q r i g h t ) = A ⋅ r + B ⋅ 0 + C n + D = A r + C n + D = α m a x ϕ h ( Q b o t t o m ) = A ⋅ 0 + B ⋅ ( − b ) + C n + D = − B b + C n + D = 0 ϕ h ( Q t o p ) = A ⋅ 0 + B ⋅ t + C n + D = B t + C n + D = 0 ϕ h ( Q n e a r ) = A ⋅ 0 + B ⋅ 0 + C n + D = C n + D = 0 ϕ h ( Q f a r ) = A ⋅ 0 + B ⋅ 0 + C f + D = C f + D = 0 \begin{align*}
\phi_{h} \left( Q_{left} \right)
&= A \cdot \left( -l \right) + B \cdot 0 + C n + D
&&= -A l + C n + D
&&= \alpha_{min} \\
\phi_{h} \left( Q_{right} \right)
&= A \cdot r + B \cdot 0 + C n + D
&&= A r + C n + D
&&= \alpha_{max} \\
\phi_{h} \left( Q_{bottom} \right)
&= A \cdot 0 + B \cdot \left( -b \right) + C n + D
&&= -B b + C n + D
&&= 0 \\
\phi_{h} \left( Q_{top} \right)
&= A \cdot 0 + B \cdot t + C n + D
&&= B t + C n + D
&&= 0 \\
\phi_{h} \left( Q_{near} \right)
&= A \cdot 0 + B \cdot 0 + C n + D
&&= C n + D
&&= 0 \\
\phi_{h} \left( Q_{far} \right)
&= A \cdot 0 + B \cdot 0 + C f + D
&&= C f + D
&&= 0 \\
\end{align*} ϕ h ( Q l e f t ) ϕ h ( Q r i g h t ) ϕ h ( Q b o tt o m ) ϕ h ( Q t o p ) ϕ h ( Q n e a r ) ϕ h ( Q f a r ) = A ⋅ ( − l ) + B ⋅ 0 + C n + D = A ⋅ r + B ⋅ 0 + C n + D = A ⋅ 0 + B ⋅ ( − b ) + C n + D = A ⋅ 0 + B ⋅ t + C n + D = A ⋅ 0 + B ⋅ 0 + C n + D = A ⋅ 0 + B ⋅ 0 + C f + D = − A l + C n + D = A r + C n + D = − B b + C n + D = Bt + C n + D = C n + D = C f + D = α min = α ma x = 0 = 0 = 0 = 0 so that
ϕ h ( Q l e f t ) = − A l + C n + D = α m i n ϕ h ( Q r i g h t ) = A r + C n + D = α m a x ϕ h ( Q b o t t o m ) = − B b + C n + D = 0 ϕ h ( Q t o p ) = B t + C n + D = 0 ϕ h ( Q n e a r ) = C n + D = 0 ϕ h ( Q f a r ) = C f + D = 0 \begin{align*}
\phi_{h} \left( Q_{left} \right) &= -A l + C n + D &&= \alpha_{min} \\
\phi_{h} \left( Q_{right} \right) &= A r + C n + D &&= \alpha_{max} \\
\phi_{h} \left( Q_{bottom} \right) &= -B b + C n + D &&= 0 \\
\phi_{h} \left( Q_{top} \right) &= B t + C n + D &&= 0 \\
\phi_{h} \left( Q_{near} \right) &= C n + D &&= 0 \\
\phi_{h} \left( Q_{far} \right) &= C f + D &&= 0 \\
\end{align*} ϕ h ( Q l e f t ) ϕ h ( Q r i g h t ) ϕ h ( Q b o tt o m ) ϕ h ( Q t o p ) ϕ h ( Q n e a r ) ϕ h ( Q f a r ) = − A l + C n + D = A r + C n + D = − B b + C n + D = Bt + C n + D = C n + D = C f + D = α min = α ma x = 0 = 0 = 0 = 0 and now we compute the constants. Subtracting ϕ h ( Q r i g h t ) \phi_{h} \left( Q_{right} \right) ϕ h ( Q r i g h t ) from
ϕ h ( Q l e f t ) \phi_{h} \left( Q_{left} \right) ϕ h ( Q l e f t ) in (123) yields
ϕ h ( Q r i g h t ) − ϕ h ( Q l e f t ) = [ A r + C n + D ] − [ − A l + C n + D ] = A r − ( − A l ) = A ( r − ( − l ) ) = α m a x − α m i n . \begin{align*}
\phi_{h} \left( Q_{right} \right) - \phi_{h} \left( Q_{left} \right)
&= \left[ A r + C n + D \right] - \left[ -A l + C n + D \right] \\
&= A r - \left( - A l \right) \\
&= A \left( r - \left( -l \right) \right) \\
&= \alpha_{max} - \alpha_{min}.
\end{align*} ϕ h ( Q r i g h t ) − ϕ h ( Q l e f t ) = [ A r + C n + D ] − [ − A l + C n + D ] = A r − ( − A l ) = A ( r − ( − l ) ) = α ma x − α min . Solving for A A A , we see that
A = α m a x − α m i n r − ( − l ) . A = \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)}. A = r − ( − l ) α ma x − α min . Subtracting ϕ h ( Q t o p ) \phi_{h} \left( Q_{top} \right) ϕ h ( Q t o p ) from
ϕ h ( Q b o t t o m ) \phi_{h} \left( Q_{bottom} \right) ϕ h ( Q b o tt o m ) in (123) yields
ϕ h ( Q t o p ) − ϕ h ( Q b o t t o m ) = [ B t + C n + D ] − [ − B b + C n + D ] = B t − B ( − b ) = B ( t − ( − b ) ) = 0. \begin{align*}
\phi_{h} \left( Q_{top} \right) - \phi_{h} \left( Q_{bottom} \right)
&= \left[ B t + C n + D \right] - \left[ -B b + C n + D \right] \\
&= B t - B \left( -b \right) \\
&= B \left( t - \left( -b \right) \right) \\
&= 0.
\end{align*} ϕ h ( Q t o p ) − ϕ h ( Q b o tt o m ) = [ Bt + C n + D ] − [ − B b + C n + D ] = Bt − B ( − b ) = B ( t − ( − b ) ) = 0. Solving for B B B , we see that
since t − ( − b ) = t + b ≠ 0 t - (-b) = t + b \neq 0 t − ( − b ) = t + b = 0 . Subtracting ϕ h ( Q f a r ) \phi_{h} \left( Q_{far} \right) ϕ h ( Q f a r ) from
ϕ h ( Q n e a r ) \phi_{h} \left( Q_{near} \right) ϕ h ( Q n e a r ) in (123) yields
ϕ h ( Q f a r ) − ϕ h ( Q n e a r ) = [ C f + D ] − [ C n + D ] = C f − C n = C ( f − n ) = 0. \begin{align*}
\phi_{h} \left( Q_{far} \right) - \phi_{h} \left( Q_{near} \right)
&= \left[ C f + D \right] - \left[ C n + D \right] \\
&= C f - C n \\
&= C \left( f - n \right) \\
&= 0.
\end{align*} ϕ h ( Q f a r ) − ϕ h ( Q n e a r ) = [ C f + D ] − [ C n + D ] = C f − C n = C ( f − n ) = 0. Solving for C C C , we see that
since f − n ≠ 0 f - n \neq 0 f − n = 0 . Substituting the constants (125) ,
(127) , and (129) back into ϕ h ( Q r i g h t ) \phi_{h}(Q_{right}) ϕ h ( Q r i g h t ) in
(123) gives us
ϕ h ( Q r i g h t ) = A r + C n + D = A r + D = ( α m a x − α m i n r − ( − l ) ) r + D = α m a x . \phi_{h} \left( Q_{right} \right)
= A r + C n + D
= A r + D
= \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) r + D
= \alpha_{max}. ϕ h ( Q r i g h t ) = A r + C n + D = A r + D = ( r − ( − l ) α ma x − α min ) r + D = α ma x . Solving for D D D
D = α m a x − ( α m a x − α m i n r − ( − l ) ) r = α m a x − ( α m a x − α m i n r + l ) r = α m a x ( r + l ) − ( α m a x − α m i n ) r r + l = α m a x r + α m a x l − α m a x r + α m i n r r + l = α m a x r + α m a x l − α m a x r + α m i n r r + l = α m a x l + α m i n r r + l = α m i n r − α m a x ( − l ) r − ( − l ) \begin{align*}
D &= \alpha_{max} - \left( \frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)} \right) r \\
&= \alpha_{max} - \left( \frac{\alpha_{max} - \alpha_{min}}{r + l} \right) r \\
&= \frac{\alpha_{max} \left( r + l \right) - \left( \alpha_{max} - \alpha_{min} \right) r}{r + l} \\
&= \frac{\alpha_{max} r + \alpha_{max} l - \alpha_{max} r + \alpha_{min} r}{r + l} \\
&= \frac{\alpha_{max} r + \alpha_{max} l - \alpha_{max} r + \alpha_{min} r}{r + l} \\
&= \frac{\alpha_{max} l + \alpha_{min} r}{r + l} \\
&= \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)} \\
\end{align*} D = α ma x − ( r − ( − l ) α ma x − α min ) r = α ma x − ( r + l α ma x − α min ) r = r + l α ma x ( r + l ) − ( α ma x − α min ) r = r + l α ma x r + α ma x l − α ma x r + α min r = r + l α ma x r + α ma x l − α ma x r + α min r = r + l α ma x l + α min r = r − ( − l ) α min r − α ma x ( − l ) we have
D = α m i n r − α m a x ( − l ) r − ( − l ) . D = \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}. D = r − ( − l ) α min r − α ma x ( − l ) . Assembling the constants (125) , (127) , (129) ,
(132) back into (120) we have the complete formula for the
function ϕ h \phi_{h} ϕ h
ϕ h ( P ) = ( α m a x − α m i n r − ( − l ) ) P h + α m i n r − α m a x ( − l ) r − ( − l ) . \phi_{h} \left( P \right)
= \left( \frac{ \alpha_{max} - \alpha_{min} }{ r - \left( -l \right)} \right) P_{h}
+ \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}. ϕ h ( P ) = ( r − ( − l ) α ma x − α min ) P h + r − ( − l ) α min r − α ma x ( − l ) . Consider the map ϕ v \phi_{v} ϕ v , where
ϕ v ( P ) = A P h + B P v + C P d + D \phi_{v} \left( P \right) = A P_{h} + B P_{v} + C P_{d} + D ϕ v ( P ) = A P h + B P v + C P d + D Define the boundary conditions for our chosen points
ϕ v ( Q l e f t ) = 0 ϕ v ( Q r i g h t ) = 0 ϕ v ( Q b o t t o m ) = β m i n ϕ v ( Q t o p ) = β m a x ϕ v ( Q n e a r ) = 0 ϕ v ( Q f a r ) = 0 \begin{align*}
\phi_{v} \left( Q_{left} \right) &= 0 \\
\phi_{v} \left( Q_{right} \right) &= 0 \\
\phi_{v} \left( Q_{bottom} \right) &= \beta_{min} \\
\phi_{v} \left( Q_{top} \right) &= \beta_{max} \\
\phi_{v} \left( Q_{near} \right) &= 0 \\
\phi_{v} \left( Q_{far} \right) &= 0 \\
\end{align*} ϕ v ( Q l e f t ) ϕ v ( Q r i g h t ) ϕ v ( Q b o tt o m ) ϕ v ( Q t o p ) ϕ v ( Q n e a r ) ϕ v ( Q f a r ) = 0 = 0 = β min = β ma x = 0 = 0 which we need to justify. The view coordinates are orthogonal to each other, and the normalized
device coordinates are also orthogonal to each other. This means that ϕ v \phi_{v} ϕ v should only
be a function of the vertical component and not the horizontal component. The points
Q l e f t , Q r i g h t , Q n e a r , Q f a r Q_{left}, Q_{right}, Q_{near}, Q_{far} Q l e f t , Q r i g h t , Q n e a r , Q f a r lie on the depth-horizontal plane, which
have a zero vertical component, so they should keep a zero vertical component after transformation.
Applying the boundary conditions, we have
ϕ v ( Q l e f t ) = A ⋅ ( − l ) + B ⋅ 0 + C n + D = − A l + C n + D = 0 ϕ v ( Q r i g h t ) = A ⋅ r + B ⋅ 0 + C n + D = A r + C n + D = 0 ϕ v ( Q b o t t o m ) = A ⋅ 0 + B ⋅ ( − b ) + C n + D = − B b + C n + D = β m i n ϕ v ( Q t o p ) = A ⋅ 0 + B ⋅ t + C n + D = B t + C n + D = β m a x ϕ v ( Q n e a r ) = A ⋅ 0 + B ⋅ 0 + C n + D = C n + D = 0 ϕ v ( Q f a r ) = A ⋅ 0 + B ⋅ 0 + C f + D = C f + D = 0 \begin{align*}
\phi_{v} \left( Q_{left} \right)
&= A \cdot \left( -l \right) + B \cdot 0 + C n + D
&&= -A l + C n + D
&&= 0 \\
\phi_{v} \left( Q_{right} \right)
&= A \cdot r + B \cdot 0 + C n + D
&&= A r + C n + D
&&= 0 \\
\phi_{v} \left( Q_{bottom} \right)
&= A \cdot 0 + B \cdot \left( -b \right) + C n + D
&&= -B b + C n + D
&&= \beta_{min} \\
\phi_{v} \left( Q_{top} \right)
&= A \cdot 0 + B \cdot t + C n + D
&&= B t + C n + D
&&= \beta_{max} \\
\phi_{v} \left( Q_{near} \right)
&= A \cdot 0 + B \cdot 0 + C n + D
&&= C n + D
&&= 0 \\
\phi_{v} \left( Q_{far} \right)
&= A \cdot 0 + B \cdot 0 + C f + D
&&= C f + D
&&= 0 \\
\end{align*} ϕ v ( Q l e f t ) ϕ v ( Q r i g h t ) ϕ v ( Q b o tt o m ) ϕ v ( Q t o p ) ϕ v ( Q n e a r ) ϕ v ( Q f a r ) = A ⋅ ( − l ) + B ⋅ 0 + C n + D = A ⋅ r + B ⋅ 0 + C n + D = A ⋅ 0 + B ⋅ ( − b ) + C n + D = A ⋅ 0 + B ⋅ t + C n + D = A ⋅ 0 + B ⋅ 0 + C n + D = A ⋅ 0 + B ⋅ 0 + C f + D = − A l + C n + D = A r + C n + D = − B b + C n + D = Bt + C n + D = C n + D = C f + D = 0 = 0 = β min = β ma x = 0 = 0 so that
ϕ v ( Q l e f t ) = − A l + C n + D = 0 ϕ v ( Q r i g h t ) = A r + C n + D = 0 ϕ v ( Q b o t t o m ) = − B b + C n + D = β m i n ϕ v ( Q t o p ) = B t + C n + D = β m a x ϕ v ( Q n e a r ) = C n + D = 0 ϕ v ( Q f a r ) = C f + D = 0 \begin{align*}
\phi_{v} \left( Q_{left} \right) &= -A l + C n + D &&= 0 \\
\phi_{v} \left( Q_{right} \right) &= A r + C n + D &&= 0 \\
\phi_{v} \left( Q_{bottom} \right) &= -B b + C n + D &&= \beta_{min} \\
\phi_{v} \left( Q_{top} \right) &= B t + C n + D &&= \beta_{max} \\
\phi_{v} \left( Q_{near} \right) &= C n + D &&= 0 \\
\phi_{v} \left( Q_{far} \right) &= C f + D &&= 0 \\
\end{align*} ϕ v ( Q l e f t ) ϕ v ( Q r i g h t ) ϕ v ( Q b o tt o m ) ϕ v ( Q t o p ) ϕ v ( Q n e a r ) ϕ v ( Q f a r ) = − A l + C n + D = A r + C n + D = − B b + C n + D = Bt + C n + D = C n + D = C f + D = 0 = 0 = β min = β ma x = 0 = 0 and now we compute the constants. Subtracting ϕ v ( Q r i g h t ) \phi_{v} \left( Q_{right} \right) ϕ v ( Q r i g h t ) from
ϕ v ( Q l e f t ) \phi_{v} \left( Q_{left} \right) ϕ v ( Q l e f t ) in (137) yields
ϕ v ( Q r i g h t ) − ϕ v ( Q l e f t ) = [ A r + C n + D ] − [ − A l + C n + D ] = A r − ( − A l ) = A ( r − ( − l ) ) = 0. \begin{align*}
\phi_{v} \left( Q_{right} \right) - \phi_{v} \left( Q_{left} \right)
&= \left[ A r + C n + D \right] - \left[ -A l + C n + D \right] \\
&= A r - \left( - A l \right) \\
&= A \left( r - \left( -l \right) \right) \\
&= 0.
\end{align*} ϕ v ( Q r i g h t ) − ϕ v ( Q l e f t ) = [ A r + C n + D ] − [ − A l + C n + D ] = A r − ( − A l ) = A ( r − ( − l ) ) = 0. Solving for A A A , we see that
since r − ( − l ) = r + l ≠ 0 r - (-l) = r + l \neq 0 r − ( − l ) = r + l = 0 . Subtracting ϕ v ( Q t o p ) \phi_{v} \left( Q_{top} \right) ϕ v ( Q t o p ) from
ϕ v ( Q b o t t o m ) \phi_{v} \left( Q_{bottom} \right) ϕ v ( Q b o tt o m ) in (137) yields
ϕ v ( Q t o p ) − ϕ v ( Q b o t t o m ) = [ B t + C n + D ] − [ − B b + C n + D ] = B t − B ( − b ) = B ( t − ( − b ) ) = β m a x − β m i n . \begin{align*}
\phi_{v} \left( Q_{top} \right) - \phi_{v} \left( Q_{bottom} \right)
&= \left[ B t + C n + D \right] - \left[ -B b + C n + D \right] \\
&= B t - B \left( -b \right) \\
&= B \left( t - \left( -b \right) \right) \\
&= \beta_{max} - \beta_{min}.
\end{align*} ϕ v ( Q t o p ) − ϕ v ( Q b o tt o m ) = [ Bt + C n + D ] − [ − B b + C n + D ] = Bt − B ( − b ) = B ( t − ( − b ) ) = β ma x − β min . Solving for B B B , we see that
B = β m a x − β m i n t − ( − b ) . B = \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)}. B = t − ( − b ) β ma x − β min . Subtracting ϕ v ( Q f a r ) \phi_{v} \left( Q_{far} \right) ϕ v ( Q f a r ) from ϕ v ( Q n e a r ) \phi_{v} \left( Q_{near} \right) ϕ v ( Q n e a r ) in
(137) yields
ϕ v ( Q f a r ) − ϕ v ( Q n e a r ) = [ C f + D ] − [ C n + D ] = C f − C n = C ( f − n ) = 0. \begin{align*}
\phi_{v} \left( Q_{far} \right) - \phi_{v} \left( Q_{near} \right)
&= \left[ C f + D \right] - \left[ C n + D \right] \\
&= C f - C n \\
&= C \left( f - n \right) \\
&= 0.
\end{align*} ϕ v ( Q f a r ) − ϕ v ( Q n e a r ) = [ C f + D ] − [ C n + D ] = C f − C n = C ( f − n ) = 0. Solving for C C C , we see that
since f − n ≠ 0 f - n \neq 0 f − n = 0 . Substituting the constants (139) ,
(141) , and (143) back into ϕ v ( Q t o p ) \phi_{v}(Q_{top}) ϕ v ( Q t o p ) in
(137) gives us
ϕ v ( Q t o p ) = B t + C n + D = B t + D = ( β m a x − β m i n t − ( − b ) ) t + D = β m a x . \phi_{v} \left( Q_{top} \right)
= B t + C n + D
= B t + D
= \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) t + D
= \beta_{max}. ϕ v ( Q t o p ) = Bt + C n + D = Bt + D = ( t − ( − b ) β ma x − β min ) t + D = β ma x . Solving for D D D
D = β m a x − ( β m a x − β m i n t − ( − b ) ) t = β m a x − ( β m a x − β m i n t + b ) t = β m a x ( t + b ) − ( β m a x − β m i n ) t t + b = β m a x t + β m a x b − β m a x t + β m i n t t + b = β m a x t + β m a x b − β m a x t + β m i n t t + b = β m a x b + β m i n t t + b = β m i n t − β m a x ( − b ) t − ( − b ) \begin{align*}
D &= \beta_{max} - \left( \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)} \right) t \\
&= \beta_{max} - \left( \frac{\beta_{max} - \beta_{min}}{t + b} \right) t \\
&= \frac{\beta_{max} \left( t + b \right) - \left( \beta_{max} - \beta_{min} \right) t}{t + b} \\
&= \frac{\beta_{max} t + \beta_{max} b - \beta_{max} t + \beta_{min} t}{t + b} \\
&= \frac{\beta_{max} t + \beta_{max} b - \beta_{max} t + \beta_{min} t}{t + b} \\
&= \frac{\beta_{max} b + \beta_{min} t}{t + b} \\
&= \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)} \\
\end{align*} D = β ma x − ( t − ( − b ) β ma x − β min ) t = β ma x − ( t + b β ma x − β min ) t = t + b β ma x ( t + b ) − ( β ma x − β min ) t = t + b β ma x t + β ma x b − β ma x t + β min t = t + b β ma x t + β ma x b − β ma x t + β min t = t + b β ma x b + β min t = t − ( − b ) β min t − β ma x ( − b ) we have
D = β m i n t − β m a x ( − b ) t − ( − b ) . D = \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}. D = t − ( − b ) β min t − β ma x ( − b ) . Assembling the constants (139) , (141) , (143) ,
(146) back into (134) we have the complete formula for the
function ϕ v \phi_{v} ϕ v
ϕ v ( P ) = ( β m a x − β m i n t − ( − b ) ) P v + β m i n t − β m a x ( − b ) t − ( − b ) . \phi_{v} \left( P \right)
= \left( \frac{ \beta_{max} - \beta_{min} }{ t - \left( -b \right)} \right) P_{v}
+ \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}. ϕ v ( P ) = ( t − ( − b ) β ma x − β min ) P v + t − ( − b ) β min t − β ma x ( − b ) . Consider the map ϕ d \phi_{d} ϕ d , where
ϕ d ( P ) = A P h + B P v + C P d + D \phi_{d} \left( P \right) = A P_{h} + B P_{v} + C P_{d} + D ϕ d ( P ) = A P h + B P v + C P d + D Define the boundary conditions for our chosen points
ϕ d ( Q l e f t ) = γ m i n ϕ d ( Q r i g h t ) = γ m i n ϕ d ( Q b o t t o m ) = γ m i n ϕ d ( Q t o p ) = γ m i n ϕ d ( Q n e a r ) = γ m i n ϕ d ( Q f a r ) = γ m a x \begin{align*}
\phi_{d} \left( Q_{left} \right) &= \gamma_{min} \\
\phi_{d} \left( Q_{right} \right) &= \gamma_{min} \\
\phi_{d} \left( Q_{bottom} \right) &= \gamma_{min} \\
\phi_{d} \left( Q_{top} \right) &= \gamma_{min} \\
\phi_{d} \left( Q_{near} \right) &= \gamma_{min} \\
\phi_{d} \left( Q_{far} \right) &= \gamma_{max} \\
\end{align*} ϕ d ( Q l e f t ) ϕ d ( Q r i g h t ) ϕ d ( Q b o tt o m ) ϕ d ( Q t o p ) ϕ d ( Q n e a r ) ϕ d ( Q f a r ) = γ min = γ min = γ min = γ min = γ min = γ ma x which we need to justify. The view coordinates are orthogonal to each other, and the normalized device coordinates
are also orthogonal to each other. This means that ϕ d \phi_{d} ϕ d should only be a function of the depth component
and not the horizontal or vertical components. The points Q l e f t , Q r i g h t , Q b o t t o m , Q t o p Q_{left}, Q_{right}, Q_{bottom}, Q_{top} Q l e f t , Q r i g h t , Q b o tt o m , Q t o p lie on the
near plane, which have a depth component of n n n . Since orthographic projection is just the identity,
points already on the near plane should stay on the near plane. Similarly, points on the far plane should stay on the
far plane. Consequently, the depth component should have no dependence on the horizontal or vertical components, only
a depth term and an affine translation term.
Applying the boundary conditions, we have
ϕ d ( Q l e f t ) = A ⋅ ( − l ) + B ⋅ 0 + C n + D = − A l + C n + D = γ m i n ϕ d ( Q r i g h t ) = A ⋅ r + B ⋅ 0 + C n + D = A r + C n + D = γ m i n ϕ d ( Q b o t t o m ) = A ⋅ 0 + B ⋅ ( − b ) + C n + D = − B b + C n + D = 0 ϕ d ( Q t o p ) = A ⋅ 0 + B ⋅ t + C n + D = B t + C n + D = 0 ϕ d ( Q n e a r ) = A ⋅ 0 + B ⋅ 0 + C n + D = C n + D = γ m i n ϕ d ( Q f a r ) = A ⋅ 0 + B ⋅ 0 + C f + D = C f + D = γ m a x \begin{align*}
\phi_{d} \left( Q_{left} \right)
&= A \cdot \left( -l \right) + B \cdot 0 + C n + D
&&= -A l + C n + D
&&= \gamma_{min} \\
\phi_{d} \left( Q_{right} \right)
&= A \cdot r + B \cdot 0 + C n + D
&&= A r + C n + D
&&= \gamma_{min} \\
\phi_{d} \left( Q_{bottom} \right)
&= A \cdot 0 + B \cdot \left( -b \right) + C n + D
&&= -B b + C n + D
&&= 0 \\
\phi_{d} \left( Q_{top} \right)
&= A \cdot 0 + B \cdot t + C n + D
&&= B t + C n + D
&&= 0 \\
\phi_{d} \left( Q_{near} \right)
&= A \cdot 0 + B \cdot 0 + C n + D
&&= C n + D
&&= \gamma_{min} \\
\phi_{d} \left( Q_{far} \right)
&= A \cdot 0 + B \cdot 0 + C f + D
&&= C f + D
&&= \gamma_{max} \\
\end{align*} ϕ d ( Q l e f t ) ϕ d ( Q r i g h t ) ϕ d ( Q b o tt o m ) ϕ d ( Q t o p ) ϕ d ( Q n e a r ) ϕ d ( Q f a r ) = A ⋅ ( − l ) + B ⋅ 0 + C n + D = A ⋅ r + B ⋅ 0 + C n + D = A ⋅ 0 + B ⋅ ( − b ) + C n + D = A ⋅ 0 + B ⋅ t + C n + D = A ⋅ 0 + B ⋅ 0 + C n + D = A ⋅ 0 + B ⋅ 0 + C f + D = − A l + C n + D = A r + C n + D = − B b + C n + D = Bt + C n + D = C n + D = C f + D = γ min = γ min = 0 = 0 = γ min = γ ma x so that
ϕ d ( Q l e f t ) = − A l + C n + D = γ m i n ϕ d ( Q r i g h t ) = A r + C n + D = γ m i n ϕ d ( Q b o t t o m ) = − B b + C n + D = γ m i n ϕ d ( Q t o p ) = B t + C n + D = γ m i n ϕ d ( Q n e a r ) = C n + D = γ m i n ϕ d ( Q f a r ) = C f + D = γ m a x \begin{align*}
\phi_{d} \left( Q_{left} \right) &= -A l + C n + D &&= \gamma_{min} \\
\phi_{d} \left( Q_{right} \right) &= A r + C n + D &&= \gamma_{min} \\
\phi_{d} \left( Q_{bottom} \right) &= -B b + C n + D &&= \gamma_{min} \\
\phi_{d} \left( Q_{top} \right) &= B t + C n + D &&= \gamma_{min} \\
\phi_{d} \left( Q_{near} \right) &= C n + D &&= \gamma_{min} \\
\phi_{d} \left( Q_{far} \right) &= C f + D &&= \gamma_{max} \\
\end{align*} ϕ d ( Q l e f t ) ϕ d ( Q r i g h t ) ϕ d ( Q b o tt o m ) ϕ d ( Q t o p ) ϕ d ( Q n e a r ) ϕ d ( Q f a r ) = − A l + C n + D = A r + C n + D = − B b + C n + D = Bt + C n + D = C n + D = C f + D = γ min = γ min = γ min = γ min = γ min = γ ma x and now we compute the constants. Subtracting ϕ d ( Q r i g h t ) \phi_{d} \left( Q_{right} \right) ϕ d ( Q r i g h t ) from
ϕ d ( Q l e f t ) \phi_{d} \left( Q_{left} \right) ϕ d ( Q l e f t ) in (151) yields
ϕ d ( Q r i g h t ) − ϕ d ( Q l e f t ) = [ A r + C n + D ] − [ − A l + C n + D ] = A r − ( − A l ) = A ( r − ( − l ) ) = γ m i n − γ m i n = 0. \begin{align*}
\phi_{d} \left( Q_{right} \right) - \phi_{d} \left( Q_{left} \right)
&= \left[ A r + C n + D \right] - \left[ -A l + C n + D \right] \\
&= A r - \left( - A l \right) \\
&= A \left( r - \left( -l \right) \right) \\
&= \gamma_{min} - \gamma_{min} \\
&= 0.
\end{align*} ϕ d ( Q r i g h t ) − ϕ d ( Q l e f t ) = [ A r + C n + D ] − [ − A l + C n + D ] = A r − ( − A l ) = A ( r − ( − l ) ) = γ min − γ min = 0. Solving for A A A , we see that
since r − ( − l ) = r + l ≠ 0 r - (-l) = r + l \neq 0 r − ( − l ) = r + l = 0 . Subtracting ϕ d ( Q t o p ) \phi_{d} \left( Q_{top} \right) ϕ d ( Q t o p ) from
ϕ d ( Q b o t t o m ) \phi_{d} \left( Q_{bottom} \right) ϕ d ( Q b o tt o m ) in (151) yields
ϕ d ( Q t o p ) − ϕ d ( Q b o t t o m ) = [ B t + C n + D ] − [ − B b + C n + D ] = B t − B ( − b ) = B ( t − ( − b ) ) = γ m i n − γ m i n = 0. \begin{align*}
\phi_{d} \left( Q_{top} \right) - \phi_{d} \left( Q_{bottom} \right)
&= \left[ B t + C n + D \right] - \left[ -B b + C n + D \right] \\
&= B t - B \left( -b \right) \\
&= B \left( t - \left( -b \right) \right) \\
&= \gamma_{min} - \gamma_{min} \\
&= 0.
\end{align*} ϕ d ( Q t o p ) − ϕ d ( Q b o tt o m ) = [ Bt + C n + D ] − [ − B b + C n + D ] = Bt − B ( − b ) = B ( t − ( − b ) ) = γ min − γ min = 0. Solving for B B B , we see that
since t − ( − b ) = t + b ≠ 0 t - (-b) = t + b \neq 0 t − ( − b ) = t + b = 0 . Subtracting ϕ d ( Q f a r ) \phi_{d} \left( Q_{far} \right) ϕ d ( Q f a r ) from
ϕ d ( Q n e a r ) \phi_{d} \left( Q_{near} \right) ϕ d ( Q n e a r ) in (151) yields
ϕ d ( Q f a r ) − ϕ d ( Q n e a r ) = [ C f + D ] − [ C n + D ] = C f − C n = C ( f − n ) = γ m a x − γ m i n . \begin{align*}
\phi_{d} \left( Q_{far} \right) - \phi_{d} \left( Q_{near} \right)
&= \left[ C f + D \right] - \left[ C n + D \right] \\
&= C f - C n \\
&= C \left( f - n \right) \\
&= \gamma_{max} - \gamma_{min}.
\end{align*} ϕ d ( Q f a r ) − ϕ d ( Q n e a r ) = [ C f + D ] − [ C n + D ] = C f − C n = C ( f − n ) = γ ma x − γ min . Solving for C C C , we see that
C = γ m a x − γ m i n f − n C = \frac{ \gamma_{max} - \gamma_{min} }{f - n} C = f − n γ ma x − γ min Substituting the constants (153) ,
(155) , and (157) back into ϕ d ( Q f a r ) \phi_{d}(Q_{far}) ϕ d ( Q f a r ) in
(151) gives us
ϕ d ( Q f a r ) = C f + D = ( γ m a x − γ m i n f − n ) f + D = γ m a x . \begin{align*}
\phi_{d} \left( Q_{far} \right)
&= C f + D
&= \left( \frac{\gamma_{max} - \gamma_{min}}{f - n} \right) f + D
&= \gamma_{max}.
\end{align*} ϕ d ( Q f a r ) = C f + D = ( f − n γ ma x − γ min ) f + D = γ ma x . Solving for D D D
D = γ m a x − ( γ m a x − γ m i n f − n ) f = γ m a x ( f − n ) − ( γ m a x − γ m i n ) f f − n = γ m a x f − γ m a x n − γ m a x f + γ m i n f f − n = γ m i n f − γ m a x n f − n \begin{align*}
D &= \gamma_{max} - \left( \frac{\gamma_{max} - \gamma_{min}}{f - n} \right) f \\
&= \frac{\gamma_{max} \left( f - n \right) - \left( \gamma_{max} - \gamma_{min} \right) f}{f - n} \\
&= \frac{\gamma_{max} f - \gamma_{max} n - \gamma_{max} f + \gamma_{min}f}{f - n} \\
&= \frac{\gamma_{min} f - \gamma_{max} n}{f - n} \\
\end{align*} D = γ ma x − ( f − n γ ma x − γ min ) f = f − n γ ma x ( f − n ) − ( γ ma x − γ min ) f = f − n γ ma x f − γ ma x n − γ ma x f + γ min f = f − n γ min f − γ ma x n we have
D = γ m i n f − γ m a x n f − n . D = \frac{\gamma_{min} f - \gamma_{max} n}{f - n}. D = f − n γ min f − γ ma x n . Assembling the constants (153) , (155) , (157) ,
(160) back into (148) we have the complete formula for the
function ϕ d \phi_{d} ϕ d
ϕ d ( P ) = ( γ m a x − γ m i n f − n ) P d + γ m i n f − γ m a x n f − n . \phi_{d} \left( P \right)
= \left( \frac{\gamma_{max} - \gamma_{min}}{f - n} \right) P_{d}
+ \frac{ \gamma_{min} f - \gamma_{max} n }{f - n}. ϕ d ( P ) = ( f − n γ ma x − γ min ) P d + f − n γ min f − γ ma x n . Finally, we substitute (133) , (147) , and (161)
back into (115) to get
P c l i p , h = ϕ h ( P ) = ( α m a x − α m i n r − ( − l ) ) P h + α m i n r − α m a x ( − l ) r − ( − l ) P c l i p , v = ϕ v ( P ) = ( β m a x − β m i n t − ( − b ) ) P v + β m i n t − β m a x ( − b ) t − ( − b ) P c l i p , d = ϕ d ( P ) = ( γ m a x − γ m i n f − n ) P d + γ m i n f − γ m a x n f − n P c l i p , w = ϕ w ( P ) = 1 \begin{align*}
P_{clip,h}
&= \phi_{h} \left( P \right)
&&= \left( \frac{ \alpha_{max} - \alpha_{min} }{ r - \left( -l \right)} \right) P_{h}
+ \frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)} \\
P_{clip,v}
&= \phi_{v} \left( P \right)
&&= \left( \frac{ \beta_{max} - \beta_{min} }{ t - \left( -b \right)} \right) P_{v}
+ \frac{\beta_{min} t - \beta_{max} \left( -b \right)}{t - \left( -b \right)} \\
P_{clip,d}
&= \phi_{d} \left( P \right)
&&= \left( \frac{\gamma_{max} - \gamma_{min}}{f - n} \right) P_{d}
+ \frac{ \gamma_{min} f - \gamma_{max} n }{f - n} \\
P_{clip,w}
&= \phi_{w} \left( P \right)
&&= 1 \\
\end{align*} P c l i p , h P c l i p , v P c l i p , d P c l i p , w = ϕ h ( P ) = ϕ v ( P ) = ϕ d ( P ) = ϕ w ( P ) = ( r − ( − l ) α ma x − α min ) P h + r − ( − l ) α min r − α ma x ( − l ) = ( t − ( − b ) β ma x − β min ) P v + t − ( − b ) β min t − β ma x ( − b ) = ( f − n γ ma x − γ min ) P d + f − n γ min f − γ ma x n = 1 Assembling the clip space components into the resulting matrix equation, we have
[ P c l i p , h P c l i p , v P c l i p , d P c l i p , w ] = [ α m a x − α m i n r − ( − l ) 0 0 α m i n r − α m a x ( − l ) r − ( − l ) 0 β m a x − β m i n t − ( − b ) 0 β m i n t − β m a x ( − b ) t − ( − b ) 0 0 γ m a x − γ m i n f − n γ m i n f − γ m a x n f − n 0 0 0 1 ] [ P h P v P d P w ] . \begin{bmatrix}
P_{clip,h} \\
P_{clip,v} \\
P_{clip,d} \\
P_{clip,w} \\
\end{bmatrix}
=
\begin{bmatrix}
\frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)}
& 0
& 0
& \frac{\alpha_{min}r - \alpha_{max} \left(-l \right) }{r - \left( -l \right)}
\\
0
& \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)}
& 0
& \frac{\beta_{min}t - \beta_{max}\left( -b \right) }{t - \left(-b \right)}
\\
0
& 0
& \frac{\gamma_{max} - \gamma_{min} }{f - n}
& \frac{\gamma_{min}f - \gamma_{max}n}{f - n}
\\
0
& 0
& 0
& 1
\\
\end{bmatrix}
\begin{bmatrix}
P_{h} \\
P_{v} \\
P_{d} \\
P_{w} \\
\end{bmatrix}. ⎣ ⎡ P c l i p , h P c l i p , v P c l i p , d P c l i p , w ⎦ ⎤ = ⎣ ⎡ r − ( − l ) α ma x − α min 0 0 0 0 t − ( − b ) β ma x − β min 0 0 0 0 f − n γ ma x − γ min 0 r − ( − l ) α min r − α ma x ( − l ) t − ( − b ) β min t − β ma x ( − b ) f − n γ min f − γ ma x n 1 ⎦ ⎤ ⎣ ⎡ P h P v P d P w ⎦ ⎤ . This yields the second major result, the canonical orthographic projection matrix M o r t h C M^{C}_{orth} M or t h C .
Let F c a n = ( O ~ c a n , B c a n ) \mathcal{F}_{can} = (\tilde{O}_{can}, \mathcal{B}_{can}) F c an = ( O ~ c an , B c an ) be a canonical coordinate frame on
E 3 \mathbb{E}^{3} E 3 , where
B c a n = ( u ^ h , u ^ v , u ^ d ) \mathcal{B}_{can} = (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_v, \mathbf{\hat{u}}_{d}) B c an = ( u ^ h , u ^ v , u ^ d ) is the basis for
the frame. The canonical orthographic projection matrix for F c a n \mathcal{F}_{can} F c an is given by
M o r t h C = [ α m a x − α m i n r − ( − l ) 0 0 α m i n r − α m a x ( − l ) r − ( − l ) 0 β m a x − β m i n t − ( − b ) 0 β m i n t − β m a x ( − b ) t − ( − b ) 0 0 γ m a x − γ m i n f − n γ m i n f − γ m a x n f − n 0 0 0 1 ] . M^{C}_{orth} =
\begin{bmatrix}
\frac{\alpha_{max} - \alpha_{min}}{r - \left( -l \right)}
& 0
& 0
& \frac{\alpha_{min}r - \alpha_{max} \left(-l \right) }{r - \left( -l \right)}
\\
0
& \frac{\beta_{max} - \beta_{min}}{t - \left( -b \right)}
& 0
& \frac{\beta_{min}t - \beta_{max}\left( -b \right) }{t - \left(-b \right)}
\\
0
& 0
& \frac{\gamma_{max} - \gamma_{min} }{f - n}
& \frac{\gamma_{min}f - \gamma_{max}n}{f - n}
\\
0
& 0
& 0
& 1
\\
\end{bmatrix}. M or t h C = ⎣ ⎡ r − ( − l ) α ma x − α min 0 0 0 0 t − ( − b ) β ma x − β min 0 0 0 0 f − n γ ma x − γ min 0 r − ( − l ) α min r − α ma x ( − l ) t − ( − b ) β min t − β ma x ( − b ) f − n γ min f − γ ma x n 1 ⎦ ⎤ . This completes the derivation of the canonical orthographic projection matrix.
The Canonical Perspective Matrix ¶ Now that we have the canonical perspective projection matrix and the canonical orthographic projection matrix,
we can work out the canonical perspective matrix. The canonical perspective matrix maps from view coordinates
to projected coordinates. We show that the perspective projection transformation consists of a perspective
transformation multiplied by an orthographic projection, we can get the perspective matrix by premultiplying
(108) by ( M o r t h C ) − 1 (M^{C}_{orth})^{-1} ( M or t h C ) − 1 given by
( M o r t h C ) − 1 = [ r + l α m a x − α m i n 0 0 − α m i n r − α m a x ( − l ) α m a x − α m i n 0 t + b β m a x − β m i n 0 − β m i n t − β m a x ( − b ) β m a x − β m i n 0 0 f − n γ m a x − γ m i n − γ m i n f − γ m a x n γ m a x − γ m i n 0 0 0 1 ] . \left(M^{C}_{orth}\right)^{-1} =
\begin{bmatrix}
\frac{r + l}{\alpha_{max} - \alpha_{min}}
& 0
& 0
& -\frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{\alpha_{max} - \alpha_{min}}
\\
0
& \frac{t + b}{\beta_{max} - \beta_{min}}
& 0
& -\frac{\beta_{min} t - \beta_{max} \left( -b \right)}{\beta_{max} - \beta_{min}}
\\
0
& 0
& \frac{f - n}{\gamma_{max} - \gamma_{min}}
& -\frac{\gamma_{min} f - \gamma_{max} n}{\gamma_{max} - \gamma_{min}}
\\
0
& 0
& 0
& 1
\\
\end{bmatrix}. ( M or t h C ) − 1 = ⎣ ⎡ α ma x − α min r + l 0 0 0 0 β ma x − β min t + b 0 0 0 0 γ ma x − γ min f − n 0 − α ma x − α min α min r − α ma x ( − l ) − β ma x − β min β min t − β ma x ( − b ) − γ ma x − γ min γ min f − γ ma x n 1 ⎦ ⎤ . Premultiplying M p e r C M^{C}_{per} M p er C by ( M o r t h C ) − 1 (M^{C}_{orth})^{-1} ( M or t h C ) − 1 gives
M p r o j C = ( M o r t h C ) − 1 M p e r C = [ r + l α m a x − α m i n 0 0 − α m i n r − α m a x ( − l ) α m a x − α m i n 0 t + b β m a x − β m i n 0 − β m i n t − β m a x ( − b ) β m a x − β m i n 0 0 f − n γ m a x − γ m i n − γ m i n f − γ m a x n γ m a x − γ m i n 0 0 0 1 ] [ ( α m a x − α m i n ) n r − ( − l ) 0 α m i n r − α m a x ( − l ) r − ( − l ) 0 0 ( β m a x − β m i n ) n t − ( − b ) β m i n t − β m a x ( − b ) t − ( − b ) 0 0 0 γ m a x f − γ m i n n f − n − ( γ m a x − γ m i n ) f n f − n 0 0 1 0 ] = [ r + l α m a x − α m i n 0 0 − α m i n r + α m a x l α m a x − α m i n 0 t + b β m a x − β m i n 0 − β m i n t + β m a x b β m a x − β m i n 0 0 f − n γ m a x − γ m i n − γ m i n f − γ m a x n γ m a x − γ m i n 0 0 0 1 ] [ ( α m a x − α m i n ) n r + l 0 α m i n r + α m a x l r + l 0 0 ( β m a x − β m i n ) n t + b β m i n t + β m a x b t + b 0 0 0 γ m a x f − γ m i n n f − n − ( γ m a x − γ m i n ) f n f − n 0 0 1 0 ] = [ n 0 0 0 0 n 0 0 0 0 f + n − f n 0 0 1 0 ] \begin{align*}
M^{C}_{proj} &= \left(M^{C}_{orth}\right)^{-1} M^{C}_{per} \\
&= \begin{bmatrix}
\frac{r + l}{\alpha_{max} - \alpha_{min}}
& 0
& 0
& -\frac{\alpha_{min} r - \alpha_{max} \left( -l \right)}{\alpha_{max} - \alpha_{min}}
\\
0
& \frac{t + b}{\beta_{max} - \beta_{min}}
& 0
& -\frac{\beta_{min} t - \beta_{max} \left( -b \right)}{\beta_{max} - \beta_{min}}
\\
0
& 0
& \frac{f - n}{\gamma_{max} - \gamma_{min}}
& -\frac{\gamma_{min} f - \gamma_{max} n}{\gamma_{max} - \gamma_{min}}
\\
0
& 0
& 0
& 1
\\
\end{bmatrix}
\begin{bmatrix}
\frac{\left( \alpha_{max} - \alpha_{min} \right) n }{r - \left( -l \right)}
& 0
& \frac{\alpha_{min}r - \alpha_{max} \left( -l \right)}{r - \left( -l \right)}
& 0
\\
0
& \frac{\left( \beta_{max} - \beta_{min} \right) n }{t - \left( -b \right)}
& \frac{\beta_{min}t - \beta_{max} \left( -b \right)}{t - \left( -b \right)}
& 0
\\
0
& 0
& \frac{\gamma_{max}f - \gamma_{min}n}{f - n}
& -\frac{\left( \gamma_{max} - \gamma_{min} \right) f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{r + l}{\alpha_{max} - \alpha_{min}}
& 0
& 0
& -\frac{ \alpha_{min} r + \alpha_{max} l }{ \alpha_{max} - \alpha_{min} }
\\
0
& \frac{t + b}{\beta_{max} - \beta_{min}}
& 0
& -\frac{ \beta_{min} t + \beta_{max} b }{ \beta_{max} - \beta_{min} }
\\
0
& 0
& \frac{ f - n }{ \gamma_{max} - \gamma_{min} }
& -\frac{ \gamma_{min} f - \gamma_{max} n }{ \gamma_{max} - \gamma_{min} }
\\
0
& 0
& 0
& 1
\\
\end{bmatrix}
\begin{bmatrix}
\frac{ \left( \alpha_{max} - \alpha_{min} \right) n }{ r + l }
& 0
& \frac{ \alpha_{min} r + \alpha_{max} l }{ r + l }
& 0
\\
0
& \frac{ \left( \beta_{max} - \beta_{min} \right) n }{ t + b }
& \frac{ \beta_{min} t + \beta_{max} b }{ t + b }
& 0
\\
0
& 0
& \frac{ \gamma_{max} f - \gamma_{min} n }{ f - n }
& -\frac{ \left( \gamma_{max} - \gamma_{min} \right) f n }{ f - n }
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\\
&= \begin{bmatrix}
n & 0 & 0 & 0 \\
0 & n & 0 & 0 \\
0 & 0 & f + n & -f n \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\end{align*} M p ro j C = ( M or t h C ) − 1 M p er C = ⎣ ⎡ α ma x − α min r + l 0 0 0 0 β ma x − β min t + b 0 0 0 0 γ ma x − γ min f − n 0 − α ma x − α min α min r − α ma x ( − l ) − β ma x − β min β min t − β ma x ( − b ) − γ ma x − γ min γ min f − γ ma x n 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) ( α ma x − α min ) n 0 0 0 0 t − ( − b ) ( β ma x − β min ) n 0 0 r − ( − l ) α min r − α ma x ( − l ) t − ( − b ) β min t − β ma x ( − b ) f − n γ ma x f − γ min n 1 0 0 − f − n ( γ ma x − γ min ) f n 0 ⎦ ⎤ = ⎣ ⎡ α ma x − α min r + l 0 0 0 0 β ma x − β min t + b 0 0 0 0 γ ma x − γ min f − n 0 − α ma x − α min α min r + α ma x l − β ma x − β min β min t + β ma x b − γ ma x − γ min γ min f − γ ma x n 1 ⎦ ⎤ ⎣ ⎡ r + l ( α ma x − α min ) n 0 0 0 0 t + b ( β ma x − β min ) n 0 0 r + l α min r + α ma x l t + b β min t + β ma x b f − n γ ma x f − γ min n 1 0 0 − f − n ( γ ma x − γ min ) f n 0 ⎦ ⎤ = ⎣ ⎡ n 0 0 0 0 n 0 0 0 0 f + n 1 0 0 − f n 0 ⎦ ⎤ which yields the third major result, the perspective matrix.
Let F c a n = ( O ~ c a n , B c a n ) \mathcal{F}_{can} = (\tilde{O}_{can}, \mathcal{B}_{can}) F c an = ( O ~ c an , B c an ) be a canonical coordinate frame on
E 3 \mathbb{E}^{3} E 3 , where
B c a n = ( u ^ h , u ^ v , u ^ d ) \mathcal{B}_{can} = (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_v, \mathbf{\hat{u}}_{d}) B c an = ( u ^ h , u ^ v , u ^ d ) is the basis
for the frame. The canonical perspective matrix for F c a n \mathcal{F}_{can} F c an is given by
M p r o j C = [ n 0 0 0 0 n 0 0 0 0 f + n − f n 0 0 1 0 ] . M^{C}_{proj} =
\begin{bmatrix}
n & 0 & 0 & 0 \\
0 & n & 0 & 0 \\
0 & 0 & f + n & -f n \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p ro j C = ⎣ ⎡ n 0 0 0 0 n 0 0 0 0 f + n 1 0 0 − f n 0 ⎦ ⎤ . This shows that the perspective projection matrix M p e r C M^{C}_{per} M p er C is indeed the product of
a projective transformation and an orthographic transformation
M p e r C = M o r t h C M p r o j C . M^{C}_{per} = M^{C}_{orth} M^{C}_{proj}. M p er C = M or t h C M p ro j C . Notice that the perspective matrix passes along the input depth coordinate undistorted via the
w w w component, but nonlinearly distorts the output depth component. Finally, recall the equation
(48) for the perspective projection matrix where we deduced that the depth component was an
affine transformation. We see from the (167) that
θ ( P d ) = A ′ P d + B ′ = ( f + n ) P d − f n \theta(P_{d}) = A^{\prime} P_{d} + B^{\prime} = (f + n) P_{d} - f n θ ( P d ) = A ′ P d + B ′ = ( f + n ) P d − f n so that the projected coordinate
components from (48) become
P p r o j , h = n P h P p r o j , v = n P v P p r o j , d = ( f + n ) P d − f n P p r o j , w = P d \begin{align*}
P_{proj,h} &= n P_{h} \\
P_{proj,v} &= n P_{v} \\
P_{proj,d} &= \left ( f + n \right) P_{d} - f n \\
P_{proj,w} &= P_{d} \\
\end{align*} P p ro j , h P p ro j , v P p ro j , d P p ro j , w = n P h = n P v = ( f + n ) P d − f n = P d which completes the derivation of the unknown constants A ′ A^{\prime} A ′ and B ′ B^{\prime} B ′ as promised.
This completes the derivation of the perspective matrix.
The Canonical Symmetric Vertical Field Of View Perspective Projection Matrix ¶ In the symmetric case, r = l r = l r = l and t = b t = b t = b . The width of the viewport is
width = r − ( − l ) = r + l \text{width} = r - (-l) = r + l width = r − ( − l ) = r + l . The height of the viewport is
height = t − ( − b ) = t + b \text{height} = t - (-b) = t + b height = t − ( − b ) = t + b . The aspect ratio , denoted aspect \text{aspect} aspect , is given by
aspect ≡ width height = r − ( − l ) t − ( − b ) = r + l t + b = r + r t + t = 2 r 2 t = r t \text{aspect} \equiv \frac{\text{width}}{\text{height}}
= \frac{r - \left( -l \right)}{t - \left( -b \right)}
= \frac{r + l}{t + b}
= \frac{r + r}{t + t}
= \frac{2 r}{2 t}
= \frac{r}{t} aspect ≡ height width = t − ( − b ) r − ( − l ) = t + b r + l = t + t r + r = 2 t 2 r = t r which implies that r = aspect ⋅ t r = \text{aspect} \cdot t r = aspect ⋅ t . Since the view volume is symmetric, the tangent
of θ v f o v / 2 \theta_{vfov} / 2 θ v f o v /2 is tan ( θ v f o v / 2 ) = t / n \tan\left( \theta_{vfov} / 2 \right) = t / n tan ( θ v f o v /2 ) = t / n . From these facts we
see that
t = b = n tan ( θ v f o v 2 ) r = l = aspect ⋅ t = aspect ⋅ n tan ( θ v f o v 2 ) t = b = n \tan\left( \frac{\theta_{vfov}}{2} \right) \\
r = l = \text{aspect} \cdot t = \text{aspect} \cdot n \tan\left( \frac{\theta_{vfov}}{2} \right) t = b = n tan ( 2 θ v f o v ) r = l = aspect ⋅ t = aspect ⋅ n tan ( 2 θ v f o v ) We now use (171) inside the general perspective projection
matrix (108) to derive the symmetric vertical field of view perspective matrix.
Consider the elements of the matrix M p e r C M^{C}_{per} M p er C . The nonzero elements of M p e r C M^{C}_{per} M p er C
become
M p e r C [ 0 , 0 ] = ( α m a x − α m i n ) n r − ( − l ) = ( α m a x − α m i n ) n r + l = ( α m a x − α m i n ) n 2 r = ( α m a x − α m i n 2 ) n r = ( α m a x − α m i n 2 ) n aspect ⋅ n tan ( θ v f o v 2 ) = ( α m a x − α m i n 2 ) 1 aspect ⋅ tan ( θ v f o v 2 ) M p e r C [ 1 , 1 ] = ( β m a x − β m i n ) n t − ( − b ) = ( β m a x − β m i n ) n t + b = ( β m a x − β m i n ) n 2 t = ( β m a x − β m i n 2 ) n t = ( β m a x − β m i n 2 ) n n tan ( θ v f o v 2 ) = ( β m a x − β m i n 2 ) 1 tan ( θ v f o v 2 ) M p e r C [ 0 , 2 ] = α m i n r − α m a x ( − l ) r − ( − l ) = α m i n r + α m a x l r + l = α m i n r + α m a x r 2 r = α m i n + α m a x 2 M p e r C [ 1 , 2 ] = β m i n t − β m a x ( − b ) t − ( − b ) = β m i n t + β m a x b t + b = β m i n t + β m a x t 2 t = β m i n + β m a x 2 M p e r C [ 2 , 2 ] = γ m a x f − γ m i n n f − n M p e r C [ 2 , 3 ] = − ( γ m a x − γ m i n ) f n f − n \begin{align*}
M^{C}_{per}\left[0, 0 \right] = \frac{\left( \alpha_{max} - \alpha_{min} \right) n}{r - \left( -l \right)}
&= \frac{\left( \alpha_{max} - \alpha_{min} \right) n}{r + l} \\
&= \frac{\left( \alpha_{max} - \alpha_{min} \right) n}{2 r} \\
&= \left( \frac{\alpha_{max} - \alpha_{min}}{2} \right) \frac{n}{r} \\
&= \left( \frac{\alpha_{max} - \alpha_{min}}{2} \right) \frac{n}{\text{aspect} \cdot n \tan\left( \frac{\theta_{vfov}}{2} \right)} \\
&= \left( \frac{\alpha_{max} - \alpha_{min}}{2} \right) \frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)} \\
M^{C}_{per}\left[1, 1 \right] = \frac{\left( \beta_{max} - \beta_{min} \right) n}{t - \left( -b \right)}
&= \frac{\left( \beta_{max} - \beta_{min} \right) n}{t + b} \\
&= \frac{\left( \beta_{max} - \beta_{min} \right) n}{2 t} \\
&= \left( \frac{\beta_{max} - \beta_{min}}{2} \right) \frac{n}{t} \\
&= \left( \frac{\beta_{max} - \beta_{min}}{2} \right) \frac{n}{n \tan\left( \frac{\theta_{vfov}}{2} \right)} \\
&= \left( \frac{\beta_{max} - \beta_{min}}{2} \right) \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)} \\
M^{C}_{per}\left[0, 2 \right] = \frac{\alpha_{min} r - \alpha_{max}\left( -l \right)}{r - \left( -l \right)}
&= \frac{\alpha_{min} r + \alpha_{max} l}{r + l} \\
&= \frac{\alpha_{min} r + \alpha_{max} r}{2 r} \\
&= \frac{\alpha_{min} + \alpha_{max}}{2} \\
M^{C}_{per}\left[1, 2 \right] = \frac{\beta_{min} t - \beta_{max}\left( -b \right)}{t - \left( -b \right)}
&= \frac{\beta_{min} t + \beta_{max} b}{t + b} \\
&= \frac{\beta_{min} t + \beta_{max} t}{2 t} \\
&= \frac{\beta_{min} + \beta_{max}}{2} \\
M^{C}_{per}\left[2, 2 \right] &= \frac{\gamma_{max} f - \gamma_{min} n}{f - n} \\
M^{C}_{per}\left[2, 3 \right] &= -\frac{\left(\gamma_{max} - \gamma_{min} \right) f n}{f - n}
\end{align*} M p er C [ 0 , 0 ] = r − ( − l ) ( α ma x − α min ) n M p er C [ 1 , 1 ] = t − ( − b ) ( β ma x − β min ) n M p er C [ 0 , 2 ] = r − ( − l ) α min r − α ma x ( − l ) M p er C [ 1 , 2 ] = t − ( − b ) β min t − β ma x ( − b ) M p er C [ 2 , 2 ] M p er C [ 2 , 3 ] = r + l ( α ma x − α min ) n = 2 r ( α ma x − α min ) n = ( 2 α ma x − α min ) r n = ( 2 α ma x − α min ) aspect ⋅ n tan ( 2 θ v f o v ) n = ( 2 α ma x − α min ) aspect ⋅ tan ( 2 θ v f o v ) 1 = t + b ( β ma x − β min ) n = 2 t ( β ma x − β min ) n = ( 2 β ma x − β min ) t n = ( 2 β ma x − β min ) n tan ( 2 θ v f o v ) n = ( 2 β ma x − β min ) tan ( 2 θ v f o v ) 1 = r + l α min r + α ma x l = 2 r α min r + α ma x r = 2 α min + α ma x = t + b β min t + β ma x b = 2 t β min t + β ma x t = 2 β min + β ma x = f − n γ ma x f − γ min n = − f − n ( γ ma x − γ min ) f n Substituting (172) back into (108) the matrix
M p e r C M^{C}_{per} M p er C takes the form
M p e r , v f o v C = [ ( α m a x − α m i n 2 ) 1 aspect ⋅ tan ( θ v f o v 2 ) 0 α m i n + α m a x 2 0 0 ( β m a x − β m i n 2 ) 1 tan ( θ v f o v 2 ) β m i n + β m a x 2 0 0 0 γ m a x f − γ m i n n f − n − ( γ m a x − γ m i n ) f n f − n 0 0 1 0 ] M^{C}_{per,vfov} =
\begin{bmatrix}
\left( \frac{\alpha_{max} - \alpha_{min}}{2} \right) \frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& \frac{\alpha_{min} + \alpha_{max}}{2}
& 0
\\
0
& \left( \frac{\beta_{max} - \beta_{min}}{2} \right) \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& \frac{\beta_{min} + \beta_{max}}{2}
& 0
\\
0
& 0
& \frac{\gamma_{max}f - \gamma_{min}n}{f - n}
& -\frac{\left( \gamma_{max} - \gamma_{min} \right) f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix} M p er , v f o v C = ⎣ ⎡ ( 2 α ma x − α min ) aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 ( 2 β ma x − β min ) t a n ( 2 θ v f o v ) 1 0 0 2 α min + α ma x 2 β min + β ma x f − n γ ma x f − γ min n 1 0 0 − f − n ( γ ma x − γ min ) f n 0 ⎦ ⎤ which is the desired formula. This is the fourth major result, the canonical symmetric vertical field of
view perspective projection matrix.
Let F c a n = ( O ~ c a n , B c a n ) \mathcal{F}_{can} = (\tilde{O}_{can}, \mathcal{B}_{can}) F c an = ( O ~ c an , B c an ) be a canonical coordinate frame on
E 3 \mathbb{E}^{3} E 3 , where
B c a n = ( u ^ h , u ^ v , u ^ d ) \mathcal{B}_{can} = (\mathbf{\hat{u}}_{h}, \mathbf{\hat{u}}_v, \mathbf{\hat{u}}_{d}) B c an = ( u ^ h , u ^ v , u ^ d ) is the basis
for the frame. Let the perspective view volume be parametrized by the vertical field of view angle
θ v f o v \theta_{vfov} θ v f o v , the near plane n n n , the far plane f f f and the aspect ratio
aspect \text{aspect} aspect such that n > 0 n > 0 n > 0 , f > 0 f > 0 f > 0 , 0 < θ v f o v < π 0 < \theta_{vfov} < \pi 0 < θ v f o v < π , and
aspect > 0 \text{aspect} > 0 aspect > 0 . The canonical symmetric vertical field of view perspective projection matrix is
given by
M p e r , v f o v C = [ ( α m a x − α m i n 2 ) 1 aspect ⋅ tan ( θ v f o v 2 ) 0 α m i n + α m a x 2 0 0 ( β m a x − β m i n 2 ) 1 tan ( θ v f o v 2 ) β m i n + β m a x 2 0 0 0 γ m a x f − γ m i n n f − n − ( γ m a x − γ m i n ) f n f − n 0 0 1 0 ] . M^{C}_{per, vfov} =
\begin{bmatrix}
\left( \frac{\alpha_{max} - \alpha_{min}}{2} \right) \frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& \frac{\alpha_{min} + \alpha_{max}}{2}
& 0
\\
0
& \left( \frac{\beta_{max} - \beta_{min}}{2} \right) \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& \frac{\beta_{min} + \beta_{max}}{2}
& 0
\\
0
& 0
& \frac{\gamma_{max}f - \gamma_{min}n}{f - n}
& -\frac{\left( \gamma_{max} - \gamma_{min} \right) f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v C = ⎣ ⎡ ( 2 α ma x − α min ) aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 ( 2 β ma x − β min ) t a n ( 2 θ v f o v ) 1 0 0 2 α min + α ma x 2 β min + β ma x f − n γ ma x f − γ min n 1 0 0 − f − n ( γ ma x − γ min ) f n 0 ⎦ ⎤ . For any given view coordinate system and clip coordinate system, there exists a perspective
projection matrix that can be expressed as M p e r = T c l i p − 1 M p e r C T v i e w M_{per} = T^{-1}_{clip} M^{C}_{per} T_{view} M p er = T c l i p − 1 M p er C T v i e w where
M p e r C M^{C}_{per} M p er C is the canonical perspective projection matrix. Let [ Q ] [Q] [ Q ] be a homogeneous
point in R P 3 \mathbb{RP}^3 RP 3 . Let Q v i e w Q_{view} Q v i e w be a representive of [ Q ] [Q] [ Q ] in view coordinates,
Q c l i p Q_{clip} Q c l i p be a representative of [ Q ] [Q] [ Q ] in clip coordinates, Q v i e w C Q^{C}_{view} Q v i e w C be a
representive of [ Q ] [Q] [ Q ] in the canonically chosen view coordinate system, Q c l i p C Q^{C}_{clip} Q c l i p C be
a representive of [ Q ] [Q] [ Q ] in the canonically chosen clip coordinates, such that
Q c l i p C = M p e r C Q v i e w C . Q^{C}_{clip} = M^{C}_{per} Q^{C}_{view}. Q c l i p C = M p er C Q v i e w C . That is, Q c l i p C Q^{C}_{clip} Q c l i p C represents the perspective projected point Q Q Q .
Let T v i e w : R P 3 → R P 3 T_{view} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} T v i e w : RP 3 → RP 3 denote the coordinate transformation
from view coordinates to the canonical view coordinates. Let
T c l i p : R P 3 → R P 3 T_{clip} : \mathbb{RP}^{3} \rightarrow \mathbb{RP}^{3} T c l i p : RP 3 → RP 3 denote the coordinate transformation
from clip coordinates to canonical clip coordinates. The coordinate relations are given by
Q v i e w C = T v i e w Q v i e w C Q^{C}_{view} = T_{view} Q^{C}_{view} Q v i e w C = T v i e w Q v i e w C and Q c l i p C = T c l i p Q c l i p C Q^{C}_{clip} = T_{clip} Q^{C}_{clip} Q c l i p C = T c l i p Q c l i p C . Applying
these relationships in (175)
T c l i p Q c l i p = M p e r C T v i e w Q v i e w T_{clip} Q_{clip} = M^{C}_{per} T_{view} Q_{view} T c l i p Q c l i p = M p er C T v i e w Q v i e w or equivalently
Q c l i p = T c l i p − 1 M p e r C T v i e w Q v i e w = ( T c l i p − 1 M p e r C T v i e w ) Q v i e w Q_{clip}
= T^{-1}_{clip} M^{C}_{per} T_{view} Q_{view}
= \left( T^{-1}_{clip} M^{C}_{per} T_{view} \right) Q_{view} Q c l i p = T c l i p − 1 M p er C T v i e w Q v i e w = ( T c l i p − 1 M p er C T v i e w ) Q v i e w therefore we identify
M p e r ≡ T c l i p − 1 M p e r C T v i e w . M_{per} \equiv T^{-1}_{clip} M^{C}_{per} T_{view}. M p er ≡ T c l i p − 1 M p er C T v i e w . This proves the existence of a perspective projection matrix for any source view
coordinate system, and any target clip coordinate system. To show uniqueness, suppose that
M p e r ′ M^{\prime}_{per} M p er ′ is another transformation that maps view coordinates to clip
coordinates, such that Q c l i p = M p e r ′ Q v i e w Q_{clip} = M^{\prime}_{per} Q_{view} Q c l i p = M p er ′ Q v i e w . Using the coordinate
transformations again, we can write Q c l i p C = T c l i p Q c l i p Q^{C}_{clip} = T_{clip} Q_{clip} Q c l i p C = T c l i p Q c l i p and
Q v i e w C = T v i e w Q v i e w Q^{C}_{view} = T_{view} Q_{view} Q v i e w C = T v i e w Q v i e w . Inverting these relations, we get
Q v i e w C = T v i e w − 1 Q v i e w Q^{C}_{view} = T^{-1}_{view} Q_{view} Q v i e w C = T v i e w − 1 Q v i e w and
Q c l i p C = T c l i p − 1 Q c l i p Q^{C}_{clip} = T^{-1}_{clip} Q_{clip} Q c l i p C = T c l i p − 1 Q c l i p . Using the relation for
M p e r ′ M^{\prime}_{per} M p er ′ in equation (178) implies
T c l i p − 1 Q c l i p C = M p e r ′ T v i e w − 1 Q v i e w C T^{-1}_{clip} Q^{C}_{clip} = M^{\prime}_{per} T^{-1}_{view} Q^{C}_{view} T c l i p − 1 Q c l i p C = M p er ′ T v i e w − 1 Q v i e w C or equivalently
Q c l i p C = T c l i p M p e r ′ T v i e w − 1 Q v i e w C = ( T c l i p M p e r ′ T v i e w − 1 ) Q v i e w C . Q^{C}_{clip}
= T_{clip} M^{\prime}_{per} T^{-1}_{view} Q^{C}_{view}
= \left( T_{clip} M^{\prime}_{per} T^{-1}_{view} \right) Q^{C}_{view}. Q c l i p C = T c l i p M p er ′ T v i e w − 1 Q v i e w C = ( T c l i p M p er ′ T v i e w − 1 ) Q v i e w C . Applying the relation for the canonical perspective projection matrix
Q c l i p C = M p e r C Q v i e w C = ( T c l i p M p e r ′ T v i e w − 1 ) Q v i e w C Q^{C}_{clip}
= M^{C}_{per} Q^{C}_{view}
= \left( T_{clip} M^{\prime}_{per} T^{-1}_{view} \right) Q^{C}_{view} Q c l i p C = M p er C Q v i e w C = ( T c l i p M p er ′ T v i e w − 1 ) Q v i e w C which imples that
M p e r C = T c l i p M p e r ′ T v i e w − 1 M^{C}_{per} = T_{clip} M^{\prime}_{per} T^{-1}_{view} M p er C = T c l i p M p er ′ T v i e w − 1 or equivalently
M p e r ′ = T c l i p − 1 M p e r C T v i e w = M p e r M^{\prime}_{per} = T^{-1}_{clip} M^{C}_{per} T_{view} = M_{per} M p er ′ = T c l i p − 1 M p er C T v i e w = M p er where the last equality in (183) follows from (178) .
This proves uniqueness for the perspective projection matrix.
To show that any perspective projection is well-defined, let [ Q ] ∈ R P 3 [Q] \in \mathbb{RP}^{3} [ Q ] ∈ RP 3 be
a point and let Q 1 ∼ Q 2 Q_{1} \sim Q_{2} Q 1 ∼ Q 2 be representatives of [ Q ] [Q] [ Q ] .
Then there exists λ ∈ R − { 0 } \lambda \in \mathbb{R} - \{ 0 \} λ ∈ R − { 0 } such that Q 2 = λ Q 1 Q_{2} = \lambda Q_{1} Q 2 = λ Q 1 .
By linearity of the canonical perspective projection,
λ M p e r C Q 1 = M p e r C ( λ Q 1 ) = M p e r C Q 2 \lambda M^{C}_{per} Q_{1} = M^{C}_{per} ( \lambda Q_{1} ) = M^{C}_{per} Q_{2} λ M p er C Q 1 = M p er C ( λ Q 1 ) = M p er C Q 2
which shows that M p e r C M^{C}_{per} M p er C is well-defined. By the linearity of homogeneous orthogonal transformations
λ M p e r Q 1 = λ T c l i p − 1 M p e r C T v i e w Q 1 = ( T c l i p − 1 M p e r C T v i e w ) ( λ Q 1 ) = ( T c l i p − 1 M p e r C T v i e w ) Q 2 = M p e r Q 2 = M p e r ( λ Q 1 ) \begin{align*}
\lambda M_{per} Q_{1}
&= \lambda T^{-1}_{clip} M^{C}_{per} T_{view} Q_{1} \\
&= \left( T^{-1}_{clip} M^{C}_{per} T_{view} \right) \left( \lambda Q_{1} \right) \\
&= \left( T^{-1}_{clip} M^{C}_{per} T_{view} \right) Q_{2} \\
&= M_{per} Q_{2} \\
&= M_{per} \left( \lambda Q_{1} \right) \\
\end{align*} λ M p er Q 1 = λ T c l i p − 1 M p er C T v i e w Q 1 = ( T c l i p − 1 M p er C T v i e w ) ( λ Q 1 ) = ( T c l i p − 1 M p er C T v i e w ) Q 2 = M p er Q 2 = M p er ( λ Q 1 ) which shows that M p e r M_{per} M p er is well-defined. The same argument shows that we can ge the same
result for any projective matrix represented in canonical coordinates, leading to our formulas for
constructing a perspective matrix, perspective projection matrix, or orthographic projection matrix
from any source coordinate system to any target coordinate system which are the formulas we will use
to compute the matrices for specific platforms.
Let F c a n = ( O ~ c a n , B c a n ) \mathcal{F}_{can} = (\tilde{O}_{can}, \mathcal{B}_{can}) F c an = ( O ~ c an , B c an ) be a canonical coordinate frame on
E 3 \mathbb{E}^{3} E 3 . Let F v i e w = ( O ~ v i e w , B v i e w ) \mathcal{F}_{view} = (\tilde{O}_{view}, \mathcal{B}_{view}) F v i e w = ( O ~ v i e w , B v i e w ) be the
orthonormal frame for the view coordinate system. Let
F c l i p = ( O ~ c l i p B c l i p ) \mathcal{F}_{clip} = (\tilde{O}_{clip} \mathcal{B}_{clip}) F c l i p = ( O ~ c l i p B c l i p ) be the orthonormal frame for the clip
coordinate system. Let T v i e w : R 3 → R 3 T_{view} : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} T v i e w : R 3 → R 3 be the coordinate
transformation from the view coordinate frame F v i e w \mathcal{F}_{view} F v i e w to the canonical coordinate frame
F c a n \mathbb{F}_{can} F c an . Let T c l i p : R 3 → R 3 T_{clip} : \mathbb{R}^{3} \rightarrow \mathbb{R}^{3} T c l i p : R 3 → R 3 be the coordinate
transformation from the clip space frame F c l i p \mathcal{F}_{clip} F c l i p to the canonical coordinate frame
F c a n \mathcal{F}_{can} F c an .
Let M p e r C M^{C}_{per} M p er C be the canonical perspective projection matrix for F c a n \mathcal{F}_{can} F c an .
The perspective projection matrix is given by
M p e r ≡ T c l i p − 1 M p e r C T v i e w . M_{per} \equiv T^{-1}_{clip} M^{C}_{per} T_{view}. M p er ≡ T c l i p − 1 M p er C T v i e w . Let M o r t h C M^{C}_{orth} M or t h C be the canonical orthographic projection matrix for F c a n \mathcal{F}_{can} F c an .
The orthographic projection matrix is given by
M o r t h ≡ T c l i p − 1 M o r t h C T v i e w . M_{orth} \equiv T^{-1}_{clip} M^{C}_{orth} T_{view}. M or t h ≡ T c l i p − 1 M or t h C T v i e w . Let M p r o j C M^{C}_{proj} M p ro j C be the canonical perspective matrix for F c a n \mathcal{F}_{can} F c an .
The perspective matrix is given by
M p r o j ≡ T c l i p − 1 M p r o j C T v i e w . M_{proj} \equiv T^{-1}_{clip} M^{C}_{proj} T_{view}. M p ro j ≡ T c l i p − 1 M p ro j C T v i e w . We apply the results of the previous sections to calculate the projection matrices for specific software platforms.
OpenGL ¶ We compute the perspective and orthographic transformation matrices for OpenGL.
The Canonical Projection Matrices ¶ The canonical view coordinate system for OpenGL is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T , where z ^ \mathbf{\hat{z}} z ^ points into the view volume.
The canonical view volume in normalized device coordinates is parametrized by
[ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] [-1, 1] \times [-1, 1] \times [-1, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] . The canonical perspective projection matrix for
this parametrization is given by
M p e r C , O p e n G L = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] . M^{C, OpenGL}_{per} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p er C , Op e n G L = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ . The canonical orthographic projection matrix is given by
M o r t h C , O p e n G L = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 2 f − n − f + n f − n 0 0 0 1 ] . M^{C, OpenGL}_{orth} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h C , Op e n G L = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ . The canonical symmetric vertical field of view perspective projection matrix is given by
M p e r , v f o v C , O p e n G L = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] . M^{C,OpenGL}_{per,vfov} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v C , Op e n G L = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ . This finishes the statement of the canonical matrices for OpenGL.
Right-Handed View Space ¶ The right-handed view coordinate system for OpenGL is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points out of the view volume towards
the viewer. This is a right-handed coordinate system. The clip coordinate system for OpenGL is the canonical
left-handed one. The orthogonal transformations are given by
Q l h O p e n G L = Q r h O p e n G L = I Q^{OpenGL}_{lh} = Q^{OpenGL}_{rh} = I Q l h Op e n G L = Q r h Op e n G L = I where I I I is the identity matrix. The change of orientation matrices are given by
Ω r h → l h = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] , Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] . \Omega_{rh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
,
\hspace{4 pt}
\Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω r h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ , Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , r h → l h O p e n G L = Ω l h → l h Q l h O p e n G L M p e r C , O p e n G L Ω r h → l h Q r h O p e n G L = ( Ω l h → l h Q l h O p e n G L ) M p e r C , O p e n G L ( Ω r h → l h Q r h O p e n G L ) = ( Ω l h → l h I ) M p e r C , O p e n G L ( Ω r h → l h I ) = Ω l h → l h M p e r C , O p e n G L Ω r h → l h = I M p e r C , O p e n G L Ω r h → l h = M p e r C , O p e n G L Ω r h → l h = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] \begin{align*}
M^{OpenGL}_{per,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} M^{C,OpenGL}_{per} \Omega_{rh \rightarrow lh} Q^{OpenGL}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) M^{C,OpenGL}_{per} \left( \Omega_{rh \rightarrow lh} Q^{OpenGL}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,OpenGL}_{per} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,OpenGL}_{per} \Omega_{rh \rightarrow lh} \\
&= I M^{C,OpenGL}_{per} \Omega_{rh \rightarrow lh} \\
&= M^{C,OpenGL}_{per} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\end{align*} M p er , r h → l h Op e n G L = Ω l h → l h Q l h Op e n G L M p er C , Op e n G L Ω r h → l h Q r h Op e n G L = ( Ω l h → l h Q l h Op e n G L ) M p er C , Op e n G L ( Ω r h → l h Q r h Op e n G L ) = ( Ω l h → l h I ) M p er C , Op e n G L ( Ω r h → l h I ) = Ω l h → l h M p er C , Op e n G L Ω r h → l h = I M p er C , Op e n G L Ω r h → l h = M p er C , Op e n G L Ω r h → l h = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ therefore
M p e r , r h → l h O p e n G L = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] . M^{OpenGL}_{per,rh \rightarrow lh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}. M p er , r h → l h Op e n G L = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , r h → l h O p e n G L = Ω l h → l h Q l h O p e n G L M o r t h C , O p e n G L Ω r h → l h Q r h O p e n G L = ( Ω l h → l h Q l h O p e n G L ) M o r t h C , O p e n G L ( Ω r h → l h Q r h O p e n G L ) = ( Ω l h → l h I ) M o r t h C , O p e n G L ( Ω r h → l h I ) = Ω l h → l h M o r t h C , O p e n G L Ω r h → l h = I M o r t h C , O p e n G L Ω r h → l h = M o r t h C , O p e n G L Ω r h → l h = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 2 f − n − f + n f − n 0 0 0 1 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 2 f − n − f + n f − n 0 0 0 1 ] \begin{align*}
M^{OpenGL}_{orth,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} M^{C, OpenGL}_{orth} \Omega_{rh \rightarrow lh} Q^{OpenGL}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) M^{C, OpenGL}_{orth} \left( \Omega_{rh \rightarrow lh} Q^{OpenGL}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C, OpenGL}_{orth} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C, OpenGL}_{orth} \Omega_{rh \rightarrow lh} \\
&= I M^{C, OpenGL}_{orth} \Omega_{rh \rightarrow lh} \\
&= M^{C, OpenGL}_{orth} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{align*} M or t h , r h → l h Op e n G L = Ω l h → l h Q l h Op e n G L M or t h C , Op e n G L Ω r h → l h Q r h Op e n G L = ( Ω l h → l h Q l h Op e n G L ) M or t h C , Op e n G L ( Ω r h → l h Q r h Op e n G L ) = ( Ω l h → l h I ) M or t h C , Op e n G L ( Ω r h → l h I ) = Ω l h → l h M or t h C , Op e n G L Ω r h → l h = I M or t h C , Op e n G L Ω r h → l h = M or t h C , Op e n G L Ω r h → l h = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ therefore
M o r t h , r h → l h O p e n G L = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 2 f − n − f + n f − n 0 0 0 1 ] . M^{OpenGL}_{orth,rh \rightarrow lh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h , r h → l h Op e n G L = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , r h → l h O p e n G L = Ω l h → l h Q l h O p e n G L M p e r , v f o v C , O p e n G L Ω r h → l h Q r h O p e n G L = ( Ω l h → l h Q l h O p e n G L ) M p e r , v f o v C , O p e n G L ( Ω r h → l h Q r h O p e n G L ) = ( Ω l h → l h I ) M p e r , v f o v C , O p e n G L ( Ω r h → l h I ) = Ω l h → l h M p e r , v f o v C , O p e n G L Ω r h → l h = I M p e r , v f o v C , O p e n G L Ω r h → l h = M p e r , v f o v C , O p e n G L Ω r h → l h = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] \begin{align*}
M^{OpenGL}_{per,vfov,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} M^{C,OpenGL}_{per,vfov} \Omega_{rh \rightarrow lh} Q^{OpenGL}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) M^{C,OpenGL}_{per,vfov} \left( \Omega_{rh \rightarrow lh} Q^{OpenGL}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,OpenGL}_{per,vfov} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,OpenGL}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= I M^{C,OpenGL}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= M^{C,OpenGL}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , r h → l h Op e n G L = Ω l h → l h Q l h Op e n G L M p er , v f o v C , Op e n G L Ω r h → l h Q r h Op e n G L = ( Ω l h → l h Q l h Op e n G L ) M p er , v f o v C , Op e n G L ( Ω r h → l h Q r h Op e n G L ) = ( Ω l h → l h I ) M p er , v f o v C , Op e n G L ( Ω r h → l h I ) = Ω l h → l h M p er , v f o v C , Op e n G L Ω r h → l h = I M p er , v f o v C , Op e n G L Ω r h → l h = M p er , v f o v C , Op e n G L Ω r h → l h = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ therefore
M p e r , v f o v , r h → l h O p e n G L = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] . M^{OpenGL}_{per,vfov,rh \rightarrow lh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}. M p er , v f o v , r h → l h Op e n G L = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ . This completes the calculation of the matrices for the right-handed OpenGL view coordinates.
View Coordinate Frame (Right-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points to the right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points out of the view volume towards the viewerClip Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] [-1, 1] \times [-1, 1] \times [-1, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] M p e r , r h → l h O p e n G L = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] M p e r , r h → l h O p e n G L = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] M p e r , v f o v , r h → l h O p e n G L = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f + n f − n − 2 f n f − n 0 0 − 1 0 ] \begin{align*}
M^{OpenGL}_{per,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix} \\
M^{OpenGL}_{per,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix} \\
M^{OpenGL}_{per,vfov,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , r h → l h Op e n G L M p er , r h → l h Op e n G L M p er , v f o v , r h → l h Op e n G L = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f + n − 1 0 0 − f − n 2 f n 0 ⎦ ⎤ Left-Handed View Space ¶ The left-handed view space coordinate system for OpenGL is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points into the view volume away from
the viewer. This is a left-handed coordinate system. The clip coordinate system is the canonical left-handed one.
The orthogonal transformation is given by
Q l h O p e n G L = I Q^{OpenGL}_{lh} = I Q l h Op e n G L = I where I I I is the identity matrix. The change of orientation matrix are given by
Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] . \Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , l h → l h O p e n G L = Ω l h → l h Q l h O p e n G L M p e r C , O p e n G L Ω l h → l h Q l h O p e n G L = ( Ω l h → l h Q l h O p e n G L ) M p e r C , O p e n G L ( Ω l h → l h Q l h O p e n G L ) = ( Ω l h → l h I ) M p e r C , O p e n G L ( Ω l h → l h I ) = Ω l h → l h M p e r C , O p e n G L Ω l h → l h = I M p e r C , O p e n G L I = M p e r C , O p e n G L = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] \begin{align*}
M^{OpenGL}_{per,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} M^{C,OpenGL}_{per} \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) M^{C,OpenGL}_{per} \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,OpenGL}_{per} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,OpenGL}_{per} \Omega_{lh \rightarrow lh} \\
&= I M^{C,OpenGL}_{per} I \\
&= M^{C,OpenGL}_{per} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\end{align*} M p er , l h → l h Op e n G L = Ω l h → l h Q l h Op e n G L M p er C , Op e n G L Ω l h → l h Q l h Op e n G L = ( Ω l h → l h Q l h Op e n G L ) M p er C , Op e n G L ( Ω l h → l h Q l h Op e n G L ) = ( Ω l h → l h I ) M p er C , Op e n G L ( Ω l h → l h I ) = Ω l h → l h M p er C , Op e n G L Ω l h → l h = I M p er C , Op e n G L I = M p er C , Op e n G L = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ therefore
M p e r , l h → l h O p e n G L = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] . M^{OpenGL}_{per,lh \rightarrow lh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p er , l h → l h Op e n G L = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , l h → l h O p e n G L = Ω l h → l h Q l h O p e n G L M o r t h C , O p e n G L Ω l h → l h Q l h O p e n G L = ( Ω l h → l h Q l h O p e n G L ) M o r t h C , O p e n G L ( Ω l h → l h Q l h O p e n G L ) = ( Ω l h → l h I ) M o r t h C , O p e n G L ( Ω l h → l h I ) = Ω l h → l h M o r t h C , O p e n G L Ω l h → l h = I M o r t h C , O p e n G L I = M o r t h C , O p e n G L = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 2 f − n − f + n f − n 0 0 0 1 ] \begin{align*}
M^{OpenGL}_{orth,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} M^{C, OpenGL}_{orth} \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) M^{C, OpenGL}_{orth} \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C, OpenGL}_{orth} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C, OpenGL}_{orth} \Omega_{lh \rightarrow lh} \\
&= I M^{C, OpenGL}_{orth} I \\
&= M^{C, OpenGL}_{orth} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{align*} M or t h , l h → l h Op e n G L = Ω l h → l h Q l h Op e n G L M or t h C , Op e n G L Ω l h → l h Q l h Op e n G L = ( Ω l h → l h Q l h Op e n G L ) M or t h C , Op e n G L ( Ω l h → l h Q l h Op e n G L ) = ( Ω l h → l h I ) M or t h C , Op e n G L ( Ω l h → l h I ) = Ω l h → l h M or t h C , Op e n G L Ω l h → l h = I M or t h C , Op e n G L I = M or t h C , Op e n G L = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ therefore
M o r t h , l h → l h O p e n G L = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 2 f − n − f + n f − n 0 0 0 1 ] . M^{OpenGL}_{orth,lh \rightarrow lh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h , l h → l h Op e n G L = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , l h → l h O p e n G L = Ω l h → l h Q l h O p e n G L M p e r , v f o v C , O p e n G L Ω l h → l h Q l h O p e n G L = ( Ω l h → l h Q l h O p e n G L ) M p e r , v f o v C , O p e n G L ( Ω l h → l h Q l h O p e n G L ) = ( Ω l h → l h I ) M p e r , v f o v C , O p e n G L ( Ω l h → l h I ) = Ω l h → l h M p e r , v f o v C , O p e n G L Ω l h → l h = I M p e r , v f o v C , O p e n G L I = M p e r , v f o v C , O p e n G L = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] \begin{align*}
M^{OpenGL}_{per,vfov,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} M^{C,OpenGL}_{per,vfov} \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) M^{C,OpenGL}_{per,vfov} \left( \Omega_{lh \rightarrow lh} Q^{OpenGL}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,OpenGL}_{per,vfov} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,OpenGL}_{per,vfov} \Omega_{lh \rightarrow lh} \\
&= I M^{C,OpenGL}_{per,vfov} I \\
&= M^{C,OpenGL}_{per,vfov} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , l h → l h Op e n G L = Ω l h → l h Q l h Op e n G L M p er , v f o v C , Op e n G L Ω l h → l h Q l h Op e n G L = ( Ω l h → l h Q l h Op e n G L ) M p er , v f o v C , Op e n G L ( Ω l h → l h Q l h Op e n G L ) = ( Ω l h → l h I ) M p er , v f o v C , Op e n G L ( Ω l h → l h I ) = Ω l h → l h M p er , v f o v C , Op e n G L Ω l h → l h = I M p er , v f o v C , Op e n G L I = M p er , v f o v C , Op e n G L = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ therefore
M p e r , v f o v , l h → l h O p e n G L = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] . M^{OpenGL}_{per,vfov,lh \rightarrow lh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v , l h → l h Op e n G L = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ . This completes the computation of the matrices for the left-handed OpenGL view coordinates.
View Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerClip Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] [-1, 1] \times [-1, 1] \times [-1, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ − 1 , 1 ] M p e r , l h → l h O p e n G L = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] M o r t h , l h → l h O p e n G L = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 2 f − n − f + n f − n 0 0 0 1 ] M p e r , v f o v , l h → l h O p e n G L = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f + n f − n − 2 f n f − n 0 0 1 0 ] \begin{align*}
M^{OpenGL}_{per,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f + n}{f - n} & -\frac{2 f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix} \\
M^{OpenGL}_{orth,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{2}{f - n} & -\frac{f + n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
M^{OpenGL}_{per,vfov,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f + n}{f - n}
& -\frac{ 2 f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\end{align*} M p er , l h → l h Op e n G L M or t h , l h → l h Op e n G L M p er , v f o v , l h → l h Op e n G L = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 2 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n f + n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f + n 1 0 0 − f − n 2 f n 0 ⎦ ⎤ Comparing Coordinate System Orientations ¶ Let us illustrate why the coordinate systems in this section have a left-handed orientation or right-handed orientation.
By convention, the standard basis on R 3 \mathbb{R}^{3} R 3 has a right-handed orientation. Recall that the standard
basis on R 3 \mathbb{R}^{3} R 3 is the tuple of vectors ( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ )
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T , and
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T are the standard basis vectors. In this basis, OpenGL’s left-handed
view coordinates and clip coordinates have the determinant
det [ x ^ y ^ − z ^ ] = det [ 1 0 0 0 1 0 0 0 − 1 ] = 1 ⋅ 1 ⋅ − 1 = − 1 \det \begin{bmatrix} \mathbf{\hat{x}} & \mathbf{\hat{y}} & -\mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}
= 1 \cdot 1 \cdot -1
= -1 det [ x ^ y ^ − z ^ ] = det ⎣ ⎡ 1 0 0 0 1 0 0 0 − 1 ⎦ ⎤ = 1 ⋅ 1 ⋅ − 1 = − 1 and OpenGL’s right-handed view coordinates have the determinant
det [ x ^ y ^ z ^ ] = det [ 1 0 0 0 1 0 0 0 1 ] = 1 ⋅ 1 ⋅ 1 = 1 \det \begin{bmatrix} \mathbf{\hat{x}} & \mathbf{\hat{y}} & \mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
= 1 \cdot 1 \cdot 1
= 1 det [ x ^ y ^ z ^ ] = det ⎣ ⎡ 1 0 0 0 1 0 0 0 1 ⎦ ⎤ = 1 ⋅ 1 ⋅ 1 = 1 so the right-handed OpenGL view coordinate system indeed has a right-handed orientation,
and the left-handed view coordinate system and clip coordinate system have a left-handed orientation.
DirectX ¶ We compute the perspective and orthographic transformation matrices for DirectX.
The Canonical Matrices ¶ The canonical view space coordinate system for DirectX is the frame
( 0 , ( x ^ , y ^ , z ^ ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( 0 , ( x ^ , y ^ , z ^ ) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T , where z ^ \mathbf{\hat{z}} z ^ points into the view volume.
The canonical view volume in normalized device coordinates is parametrized by
[ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] . The canonical perspective projection matrix for this
parametrization is given by
M p e r C , D i r e c t X = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{C, DirectX}_{per} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p er C , D i rec tX = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . The canonical orthographic projection matrix for DirectX is given by
M o r t h C , D i r e c t X = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] . M^{C, DirectX}_{orth} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h C , D i rec tX = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . The canonical symmetric vertical field of view perspective projection matrix for DirectX is given by
M p e r , v f o v C , D i r e c t X = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{C,DirectX}_{per,vfov} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v C , D i rec tX = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . This finishes the statement of the canonical matrices for DirectX.
Right-Handed View Space ¶ The right-handed view coordinate system for DirectX is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points out of the view volume towards
the viewer. This is a right-handed coordinate system. The clip coordinate system for DirectX is the canonical
left-handed one. The orthogonal transformations are given by
Q l h D i r e c t X = Q r h D i r e c t X = I Q^{DirectX}_{lh} = Q^{DirectX}_{rh} = I Q l h D i rec tX = Q r h D i rec tX = I where I I I is the identity matrix. The change of orientation matrices are given by
Ω r h → l h = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] , Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] . \Omega_{rh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
,
\hspace{4 pt}
\Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω r h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ , Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , r h → l h D i r e c t X = Ω l h → l h Q l h D i r e c t X M p e r C , D i r e c t X Ω r h → l h Q r h D i r e c t X = ( Ω l h → l h Q l h D i r e c t X ) M p e r C , D i r e c t X ( Ω r h → l h Q r h D i r e c t X ) = ( Ω l h → l h I ) M p e r C , D i r e c t X ( Ω r h → l h I ) = Ω l h → l h M p e r C , D i r e c t X Ω r h → l h = I M p e r C , D i r e c t X Ω r h → l h = M p e r C , D i r e c t X Ω r h → l h = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{DirectX}_{per,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} M^{C,DirectX}_{per} \Omega_{rh \rightarrow lh} Q^{DirectX}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) M^{C,DirectX}_{per} \left( \Omega_{rh \rightarrow lh} Q^{DirectX}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,DirectX}_{per} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,DirectX}_{per} \Omega_{rh \rightarrow lh} \\
&= I M^{C,DirectX}_{per} \Omega_{rh \rightarrow lh} \\
&= M^{C,DirectX}_{per} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{ f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\end{align*} M p er , r h → l h D i rec tX = Ω l h → l h Q l h D i rec tX M p er C , D i rec tX Ω r h → l h Q r h D i rec tX = ( Ω l h → l h Q l h D i rec tX ) M p er C , D i rec tX ( Ω r h → l h Q r h D i rec tX ) = ( Ω l h → l h I ) M p er C , D i rec tX ( Ω r h → l h I ) = Ω l h → l h M p er C , D i rec tX Ω r h → l h = I M p er C , D i rec tX Ω r h → l h = M p er C , D i rec tX Ω r h → l h = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , r h → l h D i r e c t X = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] . M^{DirectX}_{per,rh \rightarrow lh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{ f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}. M p er , r h → l h D i rec tX = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , r h → l h D i r e c t X = Ω l h → l h Q l h D i r e c t X M o r t h C , D i r e c t X Ω r h → l h Q r h D i r e c t X = ( Ω l h → l h Q l h D i r e c t X ) M o r t h C , D i r e c t X ( Ω r h → l h Q r h D i r e c t X ) = ( Ω l h → l h I ) M o r t h C , D i r e c t X ( Ω r h → l h I ) = Ω l h → l h M o r t h C , D i r e c t X Ω r h → l h = I M o r t h C , D i r e c t X Ω r h → l h = M o r t h C , D i r e c t X Ω r h → l h = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] \begin{align*}
M^{DirectX}_{orth,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} M^{C, DirectX}_{orth} \Omega_{rh \rightarrow lh} Q^{DirectX}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) M^{C, DirectX}_{orth} \left( \Omega_{rh \rightarrow lh} Q^{DirectX}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C, DirectX}_{orth} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C, DirectX}_{orth} \Omega_{rh \rightarrow lh} \\
&= I M^{C, DirectX}_{orth} \Omega_{rh \rightarrow lh} \\
&= M^{C, DirectX}_{orth} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{align*} M or t h , r h → l h D i rec tX = Ω l h → l h Q l h D i rec tX M or t h C , D i rec tX Ω r h → l h Q r h D i rec tX = ( Ω l h → l h Q l h D i rec tX ) M or t h C , D i rec tX ( Ω r h → l h Q r h D i rec tX ) = ( Ω l h → l h I ) M or t h C , D i rec tX ( Ω r h → l h I ) = Ω l h → l h M or t h C , D i rec tX Ω r h → l h = I M or t h C , D i rec tX Ω r h → l h = M or t h C , D i rec tX Ω r h → l h = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ therefore
M o r t h , r h → l h D i r e c t X = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] . M^{DirectX}_{orth,rh \rightarrow lh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h , r h → l h D i rec tX = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , r h → l h D i r e c t X = Ω l h → l h Q l h D i r e c t X M p e r , v f o v C , D i r e c t X Ω r h → l h Q r h D i r e c t X = ( Ω l h → l h Q l h D i r e c t X ) M p e r , v f o v C , D i r e c t X ( Ω r h → l h Q r h D i r e c t X ) = ( Ω l h → l h I ) M p e r , v f o v C , D i r e c t X ( Ω r h → l h I ) = Ω l h → l h M p e r , v f o v C , D i r e c t X Ω r h → l h = I M p e r , v f o v C , D i r e c t X Ω r h → l h = M p e r , v f o v C , D i r e c t X Ω r h → l h = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{DirectX}_{per,vfov,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} M^{C,DirectX}_{per,vfov} \Omega_{rh \rightarrow lh} Q^{DirectX}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) M^{C,DirectX}_{per,vfov} \left( \Omega_{rh \rightarrow lh} Q^{DirectX}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,DirectX}_{per,vfov} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,DirectX}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= I M^{C,DirectX}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= M^{C,DirectX}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , r h → l h D i rec tX = Ω l h → l h Q l h D i rec tX M p er , v f o v C , D i rec tX Ω r h → l h Q r h D i rec tX = ( Ω l h → l h Q l h D i rec tX ) M p er , v f o v C , D i rec tX ( Ω r h → l h Q r h D i rec tX ) = ( Ω l h → l h I ) M p er , v f o v C , D i rec tX ( Ω r h → l h I ) = Ω l h → l h M p er , v f o v C , D i rec tX Ω r h → l h = I M p er , v f o v C , D i rec tX Ω r h → l h = M p er , v f o v C , D i rec tX Ω r h → l h = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , v f o v , r h → l h D i r e c t X = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] . M^{DirectX}_{per,vfov,rh \rightarrow lh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}. M p er , v f o v , r h → l h D i rec tX = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ . This completes the computation of the matrices for the right-handed DirectX view coordinates.
View Coordinate Frame (Right-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points to the right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points out of the view volume towards the viewerClip Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] M p e r , r h → l h D i r e c t X = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] M o r t h , r h → l h D i r e c t X = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] M p e r , v f o v , r h → l h D i r e c t X = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{DirectX}_{per,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{ f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix} \\
M^{DirectX}_{orth,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
M^{DirectX}_{per,vfov,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , r h → l h D i rec tX M or t h , r h → l h D i rec tX M p er , v f o v , r h → l h D i rec tX = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ Left-Handed View Space ¶ The left-handed view coordinate system for OpenGL is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points into the view volume away from
the viewer. This is a right-handed coordinate system. The clip coordinate system is the canonical left-handed one.
The orthogonal transformation is given by
Q l h D i r e c t X = I Q^{DirectX}_{lh} = I Q l h D i rec tX = I where I I I is the identity matrix. The change of orientation matrix are given by
Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] . \Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , l h → l h D i r e c t X = Ω l h → l h Q l h D i r e c t X M p e r C , D i r e c t X Ω l h → l h Q l h D i r e c t X = ( Ω l h → l h Q l h D i r e c t X ) M p e r C , D i r e c t X ( Ω l h → l h Q l h D i r e c t X ) = ( Ω l h → l h I ) M p e r C , D i r e c t X ( Ω r l → l h I ) = Ω l h → l h M p e r C , D i r e c t X Ω l h → l h = I M p e r C , D i r e c t X I = M p e r C , D i r e c t X = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{DirectX}_{per,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} M^{C,DirectX}_{per} \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) M^{C,DirectX}_{per} \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,DirectX}_{per} \left( \Omega_{rl \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,DirectX}_{per} \Omega_{lh \rightarrow lh} \\
&= I M^{C,DirectX}_{per} I \\
&= M^{C,DirectX}_{per} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\end{align*} M p er , l h → l h D i rec tX = Ω l h → l h Q l h D i rec tX M p er C , D i rec tX Ω l h → l h Q l h D i rec tX = ( Ω l h → l h Q l h D i rec tX ) M p er C , D i rec tX ( Ω l h → l h Q l h D i rec tX ) = ( Ω l h → l h I ) M p er C , D i rec tX ( Ω r l → l h I ) = Ω l h → l h M p er C , D i rec tX Ω l h → l h = I M p er C , D i rec tX I = M p er C , D i rec tX = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , l h → l h D i r e c t X = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{DirectX}_{per,lh \rightarrow lh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p er , l h → l h D i rec tX = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , l h → l h D i r e c t X = Ω l h → l h Q l h D i r e c t X M o r t h C , D i r e c t X Ω l h → l h Q l h D i r e c t X = ( Ω l h → l h Q l h D i r e c t X ) M o r t h C , D i r e c t X ( Ω l h → l h Q l h D i r e c t X ) = ( Ω l h → l h I ) M o r t h C , D i r e c t X ( Ω l h → l h I ) = Ω l h → l h M o r t h C , D i r e c t X Ω l h → l h = I M o r t h C , D i r e c t X I = M o r t h C , D i r e c t X = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] \begin{align*}
M^{DirectX}_{orth,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} M^{C, DirectX}_{orth} \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) M^{C, DirectX}_{orth} \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C, DirectX}_{orth} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C, DirectX}_{orth} \Omega_{lh \rightarrow lh} \\
&= I M^{C, DirectX}_{orth} I \\
&= M^{C, DirectX}_{orth} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{align*} M or t h , l h → l h D i rec tX = Ω l h → l h Q l h D i rec tX M or t h C , D i rec tX Ω l h → l h Q l h D i rec tX = ( Ω l h → l h Q l h D i rec tX ) M or t h C , D i rec tX ( Ω l h → l h Q l h D i rec tX ) = ( Ω l h → l h I ) M or t h C , D i rec tX ( Ω l h → l h I ) = Ω l h → l h M or t h C , D i rec tX Ω l h → l h = I M or t h C , D i rec tX I = M or t h C , D i rec tX = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ therefore
M o r t h , l h → l h D i r e c t X = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] . M^{DirectX}_{orth,lh \rightarrow lh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h , l h → l h D i rec tX = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , l h → l h D i r e c t X = Ω l h → l h Q l h D i r e c t X M p e r , v f o v C , D i r e c t X Ω l h → l h Q l h D i r e c t X = ( Ω l h → l h Q l h D i r e c t X ) M p e r , v f o v C , D i r e c t X ( Ω l h → l h Q l h D i r e c t X ) = ( Ω l h → l h I ) M p e r , v f o v C , D i r e c t X ( Ω l h → l h I ) = Ω l h → l h M p e r , v f o v C , D i r e c t X Ω l h → l h = I M p e r , v f o v C , D i r e c t X I = M p e r , v f o v C , D i r e c t X = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{DirectX}_{per,vfov,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} M^{C,DirectX}_{per,vfov} \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) M^{C,DirectX}_{per,vfov} \left( \Omega_{lh \rightarrow lh} Q^{DirectX}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,DirectX}_{per,vfov} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,DirectX}_{per,vfov} \Omega_{lh \rightarrow lh} \\
&= I M^{C,DirectX}_{per,vfov} I \\
&= M^{C,DirectX}_{per,vfov} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , l h → l h D i rec tX = Ω l h → l h Q l h D i rec tX M p er , v f o v C , D i rec tX Ω l h → l h Q l h D i rec tX = ( Ω l h → l h Q l h D i rec tX ) M p er , v f o v C , D i rec tX ( Ω l h → l h Q l h D i rec tX ) = ( Ω l h → l h I ) M p er , v f o v C , D i rec tX ( Ω l h → l h I ) = Ω l h → l h M p er , v f o v C , D i rec tX Ω l h → l h = I M p er , v f o v C , D i rec tX I = M p er , v f o v C , D i rec tX = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , v f o v , l h → l h D i r e c t X = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{DirectX}_{per,vfov,lh \rightarrow lh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v , l h → l h D i rec tX = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . This completes the computation of the matrices for the left-handed DirectX view coordinates.
View Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerClip Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] M p e r , l h → l h D i r e c t X = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] M o r t h , l h → l h D i r e c t X = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] M p e r , v f o v , l h → l h D i r e c t X = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{DirectX}_{per,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix} \\
M^{DirectX}_{orth,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
M^{DirectX}_{per,vfov,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , l h → l h D i rec tX M or t h , l h → l h D i rec tX M p er , v f o v , l h → l h D i rec tX = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ Comparing Coordinate System Orientations ¶ Let us illustrate why the coordinate systems in this section have a left-handed orientation or right-handed orientation.
By convention, the standard basis on R 3 \mathbb{R}^{3} R 3 has a right-handed orientation. Recall that the standard
basis on R 3 \mathbb{R}^{3} R 3 is the tuple of vectors ( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ )
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T , and
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T are the standard basis vectors. In this basis, DirectX’s left-handed
view coordinates and clip coordinates have the determinant
det [ x ^ y ^ − z ^ ] = det [ 1 0 0 0 1 0 0 0 − 1 ] = 1 ⋅ 1 ⋅ − 1 = − 1 \det \begin{bmatrix} \mathbf{\hat{x}} & \mathbf{\hat{y}} & -\mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}
= 1 \cdot 1 \cdot -1
= -1 det [ x ^ y ^ − z ^ ] = det ⎣ ⎡ 1 0 0 0 1 0 0 0 − 1 ⎦ ⎤ = 1 ⋅ 1 ⋅ − 1 = − 1 and DirectX’s right-handed view coordinates have the determinant
det [ x ^ y ^ z ^ ] = det [ 1 0 0 0 1 0 0 0 1 ] = 1 ⋅ 1 ⋅ 1 = 1 \det \begin{bmatrix} \mathbf{\hat{x}} & \mathbf{\hat{y}} & \mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
= 1 \cdot 1 \cdot 1
= 1 det [ x ^ y ^ z ^ ] = det ⎣ ⎡ 1 0 0 0 1 0 0 0 1 ⎦ ⎤ = 1 ⋅ 1 ⋅ 1 = 1 so the right-handed DirectX view coordinate system indeed has a right-handed orientation,
and the left-handed view coordinate system and clip coordinate system have a left-handed orientation.
We compute the perspective and orthographic transformation matrices for Metal.
The Canonical Matrices ¶ The canonical view space coordinate system for Metal is the frame
( 0 , ( x ^ , y ^ , z ^ ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( 0 , ( x ^ , y ^ , z ^ ) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T , where z ^ \mathbf{\hat{z}} z ^ points into the view volume.
The canonical view volume for for Metal in normalized device coordinates is parametrized by
[ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] . The canonical perspective projection matrix for
Metal is given by
M p e r C , M e t a l = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{C, Metal}_{per} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
. M p er C , M e t a l = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . The canonical orthographic projection matrix for Metal is given by
M o r t h C , M e t a l = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] . M^{C, Metal}_{orth} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
. M or t h C , M e t a l = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . The canonical symmetric vertical field of view perspective projection matrix for Metal is given by
M p e r , v f o v C , M e t a l = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{C,Metal}_{per,vfov} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v C , M e t a l = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . This finishes the statement of the canonical matrices for Metal.
Right-Handed View Space ¶ The right-handed view space coordinate system for Metal is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points out of the view volume towards
the viewer. This is a right-handed coordinate system. The clip coordinate system for Metal is the canonical
left-handed one. The orthogonal transformations are given by
Q l h M e t a l = Q r h M e t a l = I Q^{Metal}_{lh} = Q^{Metal}_{rh} = I Q l h M e t a l = Q r h M e t a l = I where I I I is the identity matrix. The change of orientation matrices are given by
Ω r h → l h = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] , Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] . \Omega_{rh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
,
\hspace{4 pt}
\Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω r h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ , Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , r h → l h M e t a l = Ω l h → l h Q l h M e t a l M p e r C , M e t a l Ω r h → l h Q r h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p e r C , M e t a l ( Ω r h → l h Q r h M e t a l ) = ( Ω l h → l h I ) M p e r C , M e t a l ( Ω r h → l h I ) = Ω l h → l h M p e r C , M e t a l Ω r h → l h = I M p e r C , M e t a l Ω r h → l h = M p e r C , M e t a l Ω r h → l h = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{Metal}_{per,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} M^{C,Metal}_{per} \Omega_{rh \rightarrow lh} Q^{Metal}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) M^{C,Metal}_{per} \left( \Omega_{rh \rightarrow lh} Q^{Metal}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,Metal}_{per} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,Metal}_{per} \Omega_{rh \rightarrow lh} \\
&= I M^{C,Metal}_{per} \Omega_{rh \rightarrow lh} \\
&= M^{C,Metal}_{per} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{ f n }{f - n} \\
0 & 0 & -1 & 0
\end{bmatrix}
\end{align*} M p er , r h → l h M e t a l = Ω l h → l h Q l h M e t a l M p er C , M e t a l Ω r h → l h Q r h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p er C , M e t a l ( Ω r h → l h Q r h M e t a l ) = ( Ω l h → l h I ) M p er C , M e t a l ( Ω r h → l h I ) = Ω l h → l h M p er C , M e t a l Ω r h → l h = I M p er C , M e t a l Ω r h → l h = M p er C , M e t a l Ω r h → l h = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , r h → l h M e t a l = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] . M^{Metal}_{per,rh \rightarrow lh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{ f n }{f - n} \\
0 & 0 & -1 & 0
\end{bmatrix}. M p er , r h → l h M e t a l = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , r h → l h M e t a l = Ω l h → l h Q l h M e t a l M o r t h C , M e t a l Ω r h → l h Q r h M e t a l = ( Ω l h → l h Q l h M e t a l ) M o r t h C , M e t a l ( Ω r h → l h Q r h M e t a l ) = ( Ω l h → l h I ) M o r t h C , M e t a l ( Ω r h → l h I ) = Ω l h → l h M o r t h C , M e t a l Ω r h → l h = I M o r t h C , M e t a l Ω r h → l h = M o r t h C , M e t a l Ω r h → l h = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] \begin{align*}
M^{Metal}_{orth,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} M^{C, Metal}_{orth} \Omega_{rh \rightarrow lh} Q^{Metal}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) M^{C, Metal}_{orth} \left( \Omega_{rh \rightarrow lh} Q^{Metal}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C, Metal}_{orth} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C, Metal}_{orth} \Omega_{rh \rightarrow lh} \\
&= I M^{C, Metal}_{orth} \Omega_{rh \rightarrow lh} \\
&= M^{C, Metal}_{orth} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1
\end{bmatrix}
\end{align*} M or t h , r h → l h M e t a l = Ω l h → l h Q l h M e t a l M or t h C , M e t a l Ω r h → l h Q r h M e t a l = ( Ω l h → l h Q l h M e t a l ) M or t h C , M e t a l ( Ω r h → l h Q r h M e t a l ) = ( Ω l h → l h I ) M or t h C , M e t a l ( Ω r h → l h I ) = Ω l h → l h M or t h C , M e t a l Ω r h → l h = I M or t h C , M e t a l Ω r h → l h = M or t h C , M e t a l Ω r h → l h = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ therefore
M o r t h , r h → l h M e t a l = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] . M^{Metal}_{orth,rh \rightarrow lh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1
\end{bmatrix}. M or t h , r h → l h M e t a l = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , r h → l h M e t a l = Ω l h → l h Q l h M e t a l M p e r , v f o v C , M e t a l Ω r h → l h Q r h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p e r , v f o v C , M e t a l ( Ω r h → l h Q r h M e t a l ) = ( Ω l h → l h I ) M p e r , v f o v C , M e t a l ( Ω r h → l h I ) = Ω l h → l h M p e r , v f o v C , M e t a l Ω r h → l h = I M p e r , v f o v C , M e t a l Ω r h → l h = M p e r , v f o v C , M e t a l Ω r h → l h = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{Metal}_{per,vfov,rh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} M^{C,Metal}_{per,vfov} \Omega_{rh \rightarrow lh} Q^{Metal}_{rh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) M^{C,Metal}_{per,vfov} \left( \Omega_{rh \rightarrow lh} Q^{Metal}_{rh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,Metal}_{per,vfov} \left( \Omega_{rh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,Metal}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= I M^{C,Metal}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= M^{C,Metal}_{per,vfov} \Omega_{rh \rightarrow lh} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , r h → l h M e t a l = Ω l h → l h Q l h M e t a l M p er , v f o v C , M e t a l Ω r h → l h Q r h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p er , v f o v C , M e t a l ( Ω r h → l h Q r h M e t a l ) = ( Ω l h → l h I ) M p er , v f o v C , M e t a l ( Ω r h → l h I ) = Ω l h → l h M p er , v f o v C , M e t a l Ω r h → l h = I M p er , v f o v C , M e t a l Ω r h → l h = M p er , v f o v C , M e t a l Ω r h → l h = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , v f o v , r h → l h M e t a l = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] . M^{Metal}_{per,vfov,rh \rightarrow lh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}. M p er , v f o v , r h → l h M e t a l = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ . This completes the computation of the matrices for the right-handed Metal view coordinates.
View Coordinate Frame (Right-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points to the right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points out of the view volume towards the viewerClip Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] M p e r , r h → l h M e t a l = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] M o r t h , r h → l h M e t a l = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] M p e r , v f o v , r h → l h M e t a l = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{Metal}_{per,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{ f n }{f - n} \\
0 & 0 & -1 & 0
\end{bmatrix} \\
M^{Metal}_{orth,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1
\end{bmatrix} \\
M^{Metal}_{per,vfov,rh \rightarrow lh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , r h → l h M e t a l M or t h , r h → l h M e t a l M p er , v f o v , r h → l h M e t a l = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ Left-Handed View Space ¶ The left-handed view space coordinate system for Metal is the frame
( 0 , ( x ^ , y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points into the view volume away from
the viewer. This is a right-handed coordinate system. The clip coordinate system is the canonical left-handed one.
The orthogonal transformation is given by
Q l h M e t a l = I Q^{Metal}_{lh} = I Q l h M e t a l = I where I I I is the identity matrix. The change of orientation matrix are given by
Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] . \Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , l h → l h M e t a l = Ω l h → l h Q l h M e t a l M p e r C , M e t a l Ω l h → l h Q l h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p e r C , M e t a l ( Ω l h → l h Q l h M e t a l ) = ( Ω l h → l h I ) M p e r C , M e t a l ( Ω r l → l h I ) = Ω l h → l h M p e r C , M e t a l Ω l h → l h = I M p e r C , M e t a l I = M p e r C , M e t a l = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{Metal}_{per,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} M^{C,Metal}_{per} \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) M^{C,Metal}_{per} \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,Metal}_{per} \left( \Omega_{rl \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,Metal}_{per} \Omega_{lh \rightarrow lh} \\
&= I M^{C,Metal}_{per} I \\
&= M^{C,Metal}_{per} \\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0
\end{bmatrix}
\end{align*} M p er , l h → l h M e t a l = Ω l h → l h Q l h M e t a l M p er C , M e t a l Ω l h → l h Q l h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p er C , M e t a l ( Ω l h → l h Q l h M e t a l ) = ( Ω l h → l h I ) M p er C , M e t a l ( Ω r l → l h I ) = Ω l h → l h M p er C , M e t a l Ω l h → l h = I M p er C , M e t a l I = M p er C , M e t a l = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , l h → l h M e t a l = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{Metal}_{per,lh \rightarrow lh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0
\end{bmatrix}. M p er , l h → l h M e t a l = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , l h → l h M e t a l = Ω l h → l h Q l h M e t a l M o r t h C , M e t a l Ω l h → l h Q l h M e t a l = ( Ω l h → l h Q l h M e t a l ) M o r t h C , M e t a l ( Ω l h → l h Q l h M e t a l ) = ( Ω l h → l h I ) M o r t h C , M e t a l ( Ω l h → l h I ) = Ω l h → l h M o r t h C , M e t a l Ω l h → l h = I M o r t h C , M e t a l I = M o r t h C , M e t a l = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] \begin{align*}
M^{Metal}_{orth,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} M^{C, Metal}_{orth} \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) M^{C, Metal}_{orth} \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C, Metal}_{orth} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C, Metal}_{orth} \Omega_{lh \rightarrow lh} \\
&= I M^{C, Metal}_{orth} I \\
&= M^{C, Metal}_{orth} \\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1
\end{bmatrix}
\end{align*} M or t h , l h → l h M e t a l = Ω l h → l h Q l h M e t a l M or t h C , M e t a l Ω l h → l h Q l h M e t a l = ( Ω l h → l h Q l h M e t a l ) M or t h C , M e t a l ( Ω l h → l h Q l h M e t a l ) = ( Ω l h → l h I ) M or t h C , M e t a l ( Ω l h → l h I ) = Ω l h → l h M or t h C , M e t a l Ω l h → l h = I M or t h C , M e t a l I = M or t h C , M e t a l = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ therefore
M o r t h , l h → l h M e t a l = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] . M^{Metal}_{orth,lh \rightarrow lh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1
\end{bmatrix}. M or t h , l h → l h M e t a l = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , l h → l h M e t a l = Ω l h → l h Q l h M e t a l M p e r , v f o v C , M e t a l Ω l h → l h Q l h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p e r , v f o v C , M e t a l ( Ω l h → l h Q l h M e t a l ) = ( Ω l h → l h I ) M p e r , v f o v C , M e t a l ( Ω l h → l h I ) = Ω l h → l h M p e r , v f o v C , M e t a l Ω l h → l h = I M p e r , v f o v C , M e t a l I = M p e r , v f o v C , M e t a l = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{Metal}_{per,vfov,lh \rightarrow lh}
&= \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} M^{C,Metal}_{per,vfov} \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \\
&= \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) M^{C,Metal}_{per,vfov} \left( \Omega_{lh \rightarrow lh} Q^{Metal}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow lh} I \right) M^{C,Metal}_{per,vfov} \left( \Omega_{lh \rightarrow lh} I \right) \\
&= \Omega_{lh \rightarrow lh} M^{C,Metal}_{per,vfov} \Omega_{lh \rightarrow lh} \\
&= I M^{C,Metal}_{per,vfov} I \\
&= M^{C,Metal}_{per,vfov} \\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0 \\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0 \\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n} \\
0
& 0
& 1
& 0
\end{bmatrix}
\end{align*} M p er , v f o v , l h → l h M e t a l = Ω l h → l h Q l h M e t a l M p er , v f o v C , M e t a l Ω l h → l h Q l h M e t a l = ( Ω l h → l h Q l h M e t a l ) M p er , v f o v C , M e t a l ( Ω l h → l h Q l h M e t a l ) = ( Ω l h → l h I ) M p er , v f o v C , M e t a l ( Ω l h → l h I ) = Ω l h → l h M p er , v f o v C , M e t a l Ω l h → l h = I M p er , v f o v C , M e t a l I = M p er , v f o v C , M e t a l = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , v f o v , l h → l h M e t a l = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{Metal}_{per,vfov,lh \rightarrow lh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0 \\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0 \\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n} \\
0
& 0
& 1
& 0
\end{bmatrix}. M p er , v f o v , l h → l h M e t a l = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . This completes the computation of the matrices for the left-handed Metal view coordinates.
View Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerClip Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
y ^ \mathbf{\hat{y}} y ^ points up,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] M p e r , l h → l h M e t a l = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] M o r t h , l h → l h M e t a l = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] M p e r , v f o v , l h → l h M e t a l = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{Metal}_{per,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix} \\
M^{Metal}_{orth,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
M^{Metal}_{per,vfov,lh \rightarrow lh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , l h → l h M e t a l M or t h , l h → l h M e t a l M p er , v f o v , l h → l h M e t a l = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ Comparing Coordinate System Orientations ¶ Let us illustrate why the coordinate systems in this section have a left-handed orientation or right-handed orientation.
By convention, the standard basis on R 3 \mathbb{R}^{3} R 3 has a right-handed orientation. Recall that the standard
basis on R 3 \mathbb{R}^{3} R 3 is the tuple of vectors ( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ )
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T , and
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T are the standard basis vectors. In this basis, Metal’s left-handed
view coordinates and clip coordinates have the determinant
det [ x ^ y ^ − z ^ ] = det [ 1 0 0 0 1 0 0 0 − 1 ] = 1 ⋅ 1 ⋅ − 1 = − 1 \det \begin{bmatrix} \mathbf{\hat{x}} & \mathbf{\hat{y}} & -\mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}
= 1 \cdot 1 \cdot -1
= -1 det [ x ^ y ^ − z ^ ] = det ⎣ ⎡ 1 0 0 0 1 0 0 0 − 1 ⎦ ⎤ = 1 ⋅ 1 ⋅ − 1 = − 1 and Metal’s right-handed view coordinates have the determinant
det [ x ^ y ^ z ^ ] = det [ 1 0 0 0 1 0 0 0 1 ] = 1 ⋅ 1 ⋅ 1 = 1 \det \begin{bmatrix} \mathbf{\hat{x}} & \mathbf{\hat{y}} & \mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
= 1 \cdot 1 \cdot 1
= 1 det [ x ^ y ^ z ^ ] = det ⎣ ⎡ 1 0 0 0 1 0 0 0 1 ⎦ ⎤ = 1 ⋅ 1 ⋅ 1 = 1 so the right-handed Metal view coordinate system indeed has a right-handed orientation,
and the left-handed view coordinate system and clip coordinate system have a left-handed orientation.
Vulkan ¶ We compute the perspective and orthographic transformation matrices for Vulkan.
The Canonical Matrices ¶ The canonical view coordinate system for Vulkan is the frame
( 0 , ( x ^ , y ^ , z ^ ) (\mathbf{0}, (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( 0 , ( x ^ , y ^ , z ^ ) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T , where z ^ \mathbf{\hat{z}} z ^ points into the view volume.
The canonical view volume for for Vulkan in normalized device coordinates is parametrized by
[ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] . The canonical perspective projection matrix for
Vulkan is given by
M p e r C , V u l k a n = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{C, Vulkan}_{per} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p er C , V u l kan = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . The canonical orthographic projection matrix for Vulkan is given by
M o r t h C , V u l k a n = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] . M^{C, Vulkan}_{orth} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h C , V u l kan = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ . The canonical symmetric vertical field of view perspective projection matrix for Vulkan is given by
M p e r , v f o v C , V u l k a n = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] M^{C, Vulkan}_{per,vfov} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix} M p er , v f o v C , V u l kan = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ This finishes the statement of the canonical matrices for Vulkan.
Right-Handed View Space ¶ The right-handed view coordinate system for Vulkan is the frame
( 0 , ( x ^ , − y ^ , z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, -\mathbf{\hat{y}}, \mathbf{\hat{z}})) ( 0 , ( x ^ , − y ^ , z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where z ^ \mathbf{\hat{z}} z ^ points into the view volume away from
the viewer. Notice that the vertical axis points down in this frame. This is a right-handed coordinate system.
The clip coordinate system for Vulkan is the same as the right-handed view coordinate
system. A homogeneous rotation about the x-axis is defined as
R x ( θ ) = [ 1 0 0 0 0 cos ( θ ) − sin ( θ ) 0 0 sin ( θ ) cos ( θ ) 0 0 0 0 1 ] . R_{x}\left( \theta \right) =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \cos\left( \theta \right) & -\sin\left( \theta \right) & 0 \\
0 & \sin\left( \theta \right) & \cos\left( \theta \right) & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. R x ( θ ) = ⎣ ⎡ 1 0 0 0 0 cos ( θ ) sin ( θ ) 0 0 − sin ( θ ) cos ( θ ) 0 0 0 0 1 ⎦ ⎤ . The orthogonal transformations for the right-handed Vulkan view coordinates are given by
Q r h V u l k a n = R x ( π ) = [ 1 0 0 0 0 cos ( π ) − sin ( π ) 0 0 sin ( π ) cos ( π ) 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] Q l h V u l k a n = R x ( − π ) = [ 1 0 0 0 0 cos ( − π ) − sin ( − π ) 0 0 sin ( − π ) cos ( − π ) 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] . Q^{Vulkan}_{rh}
= R_{x}\left( \pi \right)
= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \cos\left( \pi \right) & -\sin\left( \pi \right) & 0 \\
0 & \sin\left( \pi \right) & \cos\left( \pi \right) & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
Q^{Vulkan}_{lh}
= R_{x}\left( -\pi \right)
= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \cos\left( -\pi \right) & -\sin\left( -\pi \right) & 0 \\
0 & \sin\left( -\pi \right) & \cos\left( -\pi \right) & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Q r h V u l kan = R x ( π ) = ⎣ ⎡ 1 0 0 0 0 cos ( π ) sin ( π ) 0 0 − sin ( π ) cos ( π ) 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ Q l h V u l kan = R x ( − π ) = ⎣ ⎡ 1 0 0 0 0 cos ( − π ) sin ( − π ) 0 0 − sin ( − π ) cos ( − π ) 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ . The change of orientation matrices are given by
Ω r h → l h = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] , Ω l h → r h = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] . \Omega_{rh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
,
\hspace{4 pt}
\Omega_{lh \rightarrow rh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω r h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ , Ω l h → r h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , r h → r h V u l k a n = Ω l h → r h ( Q l h V u l k a n ) − 1 M p e r C , V u l k a n Ω r h → l h Q r h V u l k a n = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r C , V u l k a n ( Ω r h → l h Q r h V u l k a n ) = ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) M p e r C , V u l k a n ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] M p e r C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 − 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r + l 0 − r − l r + l 0 0 − 2 n t + b − t − b t + b 0 0 0 f f − n − f n f − n 0 0 1 0 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r + l 0 − r − l r + l 0 0 − 2 n b + t b − t b + t 0 0 0 f f − n − f n f − n 0 0 1 0 ] = [ 2 n r + l 0 − r − l r + l 0 0 2 n b + t − b − t b + t 0 0 0 f f − n − f n f − n 0 0 1 0 ] = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n b − ( − t ) − b + ( − t ) b − ( − t ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{Vulkan}_{per, rh \rightarrow rh}
&= \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} M^{C,Vulkan}_{per} \Omega_{rh \rightarrow lh} Q^{Vulkan}_{rh} \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per} \left( \Omega_{rh \rightarrow lh} Q^{Vulkan}_{rh} \right) \\
&= \left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
M^{C,Vulkan}_{per}
\left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
M^{C,Vulkan}_{per}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & -\frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r + l} & 0 & -\frac{r - l}{r + l} & 0 \\
0 & -\frac{ 2 n }{t + b} & -\frac{t - b}{t + b} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r + l} & 0 & -\frac{r - l}{r + l} & 0 \\
0 & -\frac{ 2 n }{b + t} & \frac{b - t}{b + t} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{ 2 n }{r + l} & 0 & -\frac{r - l}{r + l} & 0 \\
0 & \frac{ 2 n }{b + t} & -\frac{b - t}{b + t} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{b - \left( -t \right)} & -\frac{b + \left( -t \right)}{b - \left( -t \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\end{align*} M p er , r h → r h V u l kan = Ω l h → r h ( Q l h V u l kan ) − 1 M p er C , V u l kan Ω r h → l h Q r h V u l kan = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er C , V u l kan ( Ω r h → l h Q r h V u l kan ) = ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ M p er C , V u l kan ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ M p er C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 − t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 n 0 0 0 0 − t + b 2 n 0 0 − r + l r − l − t + b t − b f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 n 0 0 0 0 − b + t 2 n 0 0 − r + l r − l b + t b − t f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r + l 2 n 0 0 0 0 b + t 2 n 0 0 − r + l r − l − b + t b − t f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 b − ( − t ) 2 n 0 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , r h → r h V u l k a n = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n b − ( − t ) − b + ( − t ) b − ( − t ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{Vulkan}_{per, rh \rightarrow rh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{b - \left( -t \right)} & -\frac{b + \left( -t \right)}{b - \left( -t \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}. M p er , r h → r h V u l kan = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 b − ( − t ) 2 n 0 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , r h → r h V u l k a n = Ω l h → r h ( Q l h V u l k a n ) − 1 M o r t h C , V u l k a n Ω r h → l h Q r h V u l k a n = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M o r t h C , V u l k a n ( Ω r h → l h Q r h V u l k a n ) = ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) M o r t h C , V u l k a n ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] M o r t h C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 − 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r + l 0 0 − r − l r + l 0 − 2 t + b 0 − t − b t + b 0 0 1 f − n − n f − n 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r + l 0 0 − r − l r + l 0 − 2 b + t 0 b − t b + t 0 0 1 f − n − n f − n 0 0 0 1 ] = [ 2 r + l 0 0 − r − l r + l 0 2 b + t 0 − b − t b + t 0 0 1 f − n − n f − n 0 0 0 1 ] = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 b − ( − t ) 0 − b + ( − t ) b − ( − t ) 0 0 1 f − n − n f − n 0 0 0 1 ] \begin{align*}
M^{Vulkan}_{orth, rh \rightarrow rh}
&= \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} M^{C,Vulkan}_{orth} \Omega_{rh \rightarrow lh} Q^{Vulkan}_{rh} \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{orth} \left( \Omega_{rh \rightarrow lh} Q^{Vulkan}_{rh} \right) \\
&= \left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
M^{C,Vulkan}_{orth}
\left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
M^{C,Vulkan}_{orth}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & -\frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r + l} & 0 & 0 & -\frac{r - l}{r + l} \\
0 & -\frac{2}{t + b} & 0 & -\frac{t - b}{t + b} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r + l} & 0 & 0 & -\frac{r - l}{r + l} \\
0 & -\frac{2}{b + t} & 0 & \frac{b - t}{b + t} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{2}{r + l} & 0 & 0 & -\frac{r - l}{r + l} \\
0 & \frac{2}{b + t} & 0 & -\frac{b - t}{b + t} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{b - \left( -t \right)} & 0 & -\frac{b + \left( -t \right)}{b - \left( -t \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{align*} M or t h , r h → r h V u l kan = Ω l h → r h ( Q l h V u l kan ) − 1 M or t h C , V u l kan Ω r h → l h Q r h V u l kan = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M or t h C , V u l kan ( Ω r h → l h Q r h V u l kan ) = ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ M or t h C , V u l kan ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ M or t h C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 0 0 0 0 − t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 0 0 0 0 − t + b 2 0 0 0 0 f − n 1 0 − r + l r − l − t + b t − b − f − n n 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 0 0 0 0 − b + t 2 0 0 0 0 f − n 1 0 − r + l r − l b + t b − t − f − n n 1 ⎦ ⎤ = ⎣ ⎡ r + l 2 0 0 0 0 b + t 2 0 0 0 0 f − n 1 0 − r + l r − l − b + t b − t − f − n n 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 b − ( − t ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) − f − n n 1 ⎦ ⎤ therefore
M o r t h , r h → r h V u l k a n = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 b − ( − t ) 0 − b + ( − t ) b − ( − t ) 0 0 1 f − n − n f − n 0 0 0 1 ] . M^{Vulkan}_{orth, rh \rightarrow rh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{b - \left( -t \right)} & 0 & -\frac{b + \left( -t \right)}{b - \left( -t \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h , r h → r h V u l kan = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 b − ( − t ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) − f − n n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , r h → r h V u l k a n = Ω l h → r h ( Q l h V u l k a n ) − 1 M p e r , v f o v C , V u l k a n Ω r h → l h Q r h V u l k a n = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r , v f o v C , V u l k a n ( Ω r h → l h Q r h V u l k a n ) = ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) M p e r , v f o v C , V u l k a n ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] M p e r , v f o v C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 − 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{Vulkan}_{per,vfov,rh \rightarrow rh}
&= \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} M^{C,Vulkan}_{per,vfov} \Omega_{rh \rightarrow lh} Q^{Vulkan}_{rh} \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per,vfov} \left( \Omega_{rh \rightarrow lh} Q^{Vulkan}_{rh} \right) \\
&= \left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
M^{C,Vulkan}_{per,vfov}
\left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
M^{C,Vulkan}_{per,vfov}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& -\frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , r h → r h V u l kan = Ω l h → r h ( Q l h V u l kan ) − 1 M p er , v f o v C , V u l kan Ω r h → l h Q r h V u l kan = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er , v f o v C , V u l kan ( Ω r h → l h Q r h V u l kan ) = ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ M p er , v f o v C , V u l kan ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ M p er , v f o v C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 − t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , v f o v , r h → r h V u l k a n = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] . M^{Vulkan}_{per,vfov,rh \rightarrow rh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}. M p er , v f o v , r h → r h V u l kan = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ . This completes the computation of the matrices for the right-handed Vulkan view coordinates.
View Coordinate Frame (Right-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , − y ^ , z ^ ) (\mathbf{\hat{x}}, -\mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , − y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
− y ^ -\mathbf{\hat{y}} − y ^ points down,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerClip Coordinate Frame (Right-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , − y ^ , z ^ ) (\mathbf{\hat{x}}, -\mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , − y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
− y ^ -\mathbf{\hat{y}} − y ^ points down,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] M p e r , r h → r h V u l k a n = [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n b − ( − t ) − b + ( − t ) b − ( − t ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] M o r t h , r h → r h V u l k a n = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 b − ( − t ) 0 − b + ( − t ) b − ( − t ) 0 0 1 f − n − n f − n 0 0 0 1 ] M p e r , v f o v , r h → r h V u l k a n = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] \begin{align*}
M^{Vulkan}_{per, rh \rightarrow rh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{b - \left( -t \right)} & -\frac{b + \left( -t \right)}{b - \left( -t \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix} \\
M^{Vulkan}_{orth, rh \rightarrow rh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{b - \left( -t \right)} & 0 & -\frac{b + \left( -t \right)}{b - \left( -t \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
M^{Vulkan}_{per,vfov,rh \rightarrow rh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , r h → r h V u l kan M or t h , r h → r h V u l kan M p er , v f o v , r h → r h V u l kan = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 b − ( − t ) 2 n 0 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 b − ( − t ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ Left-Handed View Space ¶ The right-handed view space coordinate system for Vulkan is the frame
( 0 , ( x ^ , − y ^ , − z ^ ) ) (\mathbf{0}, (\mathbf{\hat{x}}, -\mathbf{\hat{y}}, -\mathbf{\hat{z}})) ( 0 , ( x ^ , − y ^ , − z ^ )) in R 3 \mathbb{R}^{3} R 3 ,
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T where − z ^ -\mathbf{\hat{z}} − z ^ points out of the view volume towards
the viewer. Notice that the vertical axis points down in this frame. This is a left-handed coordinate system.
The clip coordinate system for Vulkan is the same as the right-handed view coordinate
system. A homogeneous rotation about the x-axis is defined as
R x ( θ ) = [ 1 0 0 0 0 cos ( θ ) − sin ( θ ) 0 0 sin ( θ ) cos ( θ ) 0 0 0 0 1 ] . R_{x}\left( \theta \right) =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \cos\left( \theta \right) & -\sin\left( \theta \right) & 0 \\
0 & \sin\left( \theta \right) & \cos\left( \theta \right) & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. R x ( θ ) = ⎣ ⎡ 1 0 0 0 0 cos ( θ ) sin ( θ ) 0 0 − sin ( θ ) cos ( θ ) 0 0 0 0 1 ⎦ ⎤ . The orthogonal transformations for the left-handed Vulkan view coordinates are given by
Q l h V u l k a n = R x ( π ) = [ 1 0 0 0 0 cos ( π ) − sin ( π ) 0 0 sin ( π ) cos ( π ) 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] . Q^{Vulkan}_{lh}
= R_{x}\left( \pi \right)
= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \cos\left( \pi \right) & -\sin\left( \pi \right) & 0 \\
0 & \sin\left( \pi \right) & \cos\left( \pi \right) & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Q l h V u l kan = R x ( π ) = ⎣ ⎡ 1 0 0 0 0 cos ( π ) sin ( π ) 0 0 − sin ( π ) cos ( π ) 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ . The change of orientation matrices are given by
Ω l h → l h = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] , Ω l h → r h = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] . \Omega_{lh \rightarrow lh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
,
\hspace{4 pt}
\Omega_{lh \rightarrow rh} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. Ω l h → l h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ , Ω l h → r h = ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ . To compute the projections, we need to transform from the chosen view coordinates to the canonical view
coordinates, apply the canonical projection, and then transform from the canonical clip coordinates to the
target clip coordinates. We can map any view coordinates to any clip coordinates using the same process.
Each coordinate transformation is the product of an orthogonal transform and a change of orientation matrix.
Let us calculate the perspective projection
M p e r , l h → r h V u l k a n = Ω l h → r h ( Q l h V u l k a n ) − 1 M p e r C , V u l k a n Ω l h → l h Q l h V u l k a n = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r C , V u l k a n ( Ω l h → l h Q l h V u l k a n ) = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r C , V u l k a n ( I Q l h V u l k a n ) = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r C , V u l k a n Q l h V u l k a n = ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) M p e r C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] M p e r C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r − ( − l ) 0 − r + ( − l ) r − ( − l ) 0 0 2 n t − ( − b ) − t + ( − b ) t − ( − b ) 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 − 2 n t − ( − b ) t + ( − b ) t − ( − b ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r + l 0 r − l r + l 0 0 − 2 n t + b t − b t + b 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 n r + l 0 r − l r + l 0 0 − 2 n b + t − b − t b + t 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] = [ 2 n r + l 0 r − l r + l 0 0 2 n b + t b − t b + t 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n b − ( − t ) b + ( − t ) b − ( − t ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{Vulkan}_{per, lh \rightarrow rh}
&= \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} M^{C,Vulkan}_{per} \Omega_{lh \rightarrow lh} Q^{Vulkan}_{lh} \\
&= \left( \Omega_{lh \rightarrow rh} \left( Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per} \left( \Omega_{lh \rightarrow lh} Q^{Vulkan}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow rh} \left( Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per} \left( I Q^{Vulkan}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow rh} \left( Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per} Q^{Vulkan}_{lh} \\
&= \left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
M^{C,Vulkan}_{per}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
M^{C,Vulkan}_{per}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{t - \left( -b \right)} & -\frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & \frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & -\frac{ 2 n }{t - \left( -b \right)} & \frac{t + \left( -b \right)}{t - \left( -b \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r + l} & 0 & \frac{r - l}{r + l} & 0 \\
0 & -\frac{ 2 n }{t + b} & \frac{t - b}{t + b} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{ 2 n }{r + l} & 0 & \frac{r - l}{r + l} & 0 \\
0 & -\frac{ 2 n }{b + t} & -\frac{b - t}{b + t} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{ 2 n }{r + l} & 0 & \frac{r - l}{r + l} & 0 \\
0 & \frac{ 2 n }{b + t} & \frac{b - t}{b + t} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{b - \left( -t \right)} & \frac{b + \left( -t \right)}{b - \left( -t \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}
\end{align*} M p er , l h → r h V u l kan = Ω l h → r h ( Q l h V u l kan ) − 1 M p er C , V u l kan Ω l h → l h Q l h V u l kan = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er C , V u l kan ( Ω l h → l h Q l h V u l kan ) = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er C , V u l kan ( I Q l h V u l kan ) = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er C , V u l kan Q l h V u l kan = ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ M p er C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ M p er C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 t − ( − b ) 2 n 0 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 − t − ( − b ) 2 n 0 0 r − ( − l ) r + ( − l ) t − ( − b ) t + ( − b ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 n 0 0 0 0 − t + b 2 n 0 0 r + l r − l t + b t − b − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 n 0 0 0 0 − b + t 2 n 0 0 r + l r − l − b + t b − t − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r + l 2 n 0 0 0 0 b + t 2 n 0 0 r + l r − l b + t b − t − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 b − ( − t ) 2 n 0 0 r − ( − l ) r + ( − l ) b − ( − t ) b + ( − t ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , l h → r h V u l k a n = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n b − ( − t ) b + ( − t ) b − ( − t ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] . M^{Vulkan}_{per, lh \rightarrow rh} =
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{b - \left( -t \right)} & \frac{b + \left( -t \right)}{b - \left( -t \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix}. M p er , l h → r h V u l kan = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 b − ( − t ) 2 n 0 0 r − ( − l ) r + ( − l ) b − ( − t ) b + ( − t ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ . Here is the calculation for the orthographic matrix
M o r t h , l h → r h V u l k a n = Ω l h → r h ( Q l h V u l k a n ) − 1 M o r t h C , V u l k a n Ω l h → l h Q l h V u l k a n = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M o r t h C , V u l k a n ( Ω l h → l h Q l h V u l k a n ) = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M o r t h C , V u l k a n ( I Q l h V u l k a n ) = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M o r t h C , V u l k a n Q l h V u l k a n = ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) M o r t h C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] M o r t h C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 1 f − n − n f − n 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 − 2 t − ( − b ) 0 − t + ( − b ) t − ( − b ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r + l 0 0 − r − l r + l 0 − 2 t + b 0 − t − b t + b 0 0 − 1 f − n − n f − n 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 2 r + l 0 0 − r − l r + l 0 − 2 b + t 0 b − t b + t 0 0 − 1 f − n − n f − n 0 0 0 1 ] = [ 2 r + l 0 0 − r − l r + l 0 2 b + t 0 − b − t b + t 0 0 − 1 f − n − n f − n 0 0 0 1 ] = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 b − ( − t ) 0 − b + ( − t ) b − ( − t ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] \begin{align*}
M^{Vulkan}_{orth, lh \rightarrow rh}
&= \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} M^{C,Vulkan}_{orth} \Omega_{lh \rightarrow lh} Q^{Vulkan}_{lh} \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{orth} \left( \Omega_{lh \rightarrow lh} Q^{Vulkan}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{orth} \left( I Q^{Vulkan}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{orth} Q^{Vulkan}_{lh} \\
&= \left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
M^{C,Vulkan}_{orth}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
M^{C,Vulkan}_{orth}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & \frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & -\frac{2}{t - \left( -b \right)} & 0 & -\frac{t + \left( -b \right)}{t - \left( -b \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r + l} & 0 & 0 & -\frac{r - l}{r + l} \\
0 & -\frac{2}{t + b} & 0 & -\frac{t - b}{t + b} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{2}{r + l} & 0 & 0 & -\frac{r - l}{r + l} \\
0 & -\frac{2}{b + t} & 0 & \frac{b - t}{b + t} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{2}{r + l} & 0 & 0 & -\frac{r - l}{r + l} \\
0 & \frac{2}{b + t} & 0 & -\frac{b - t}{b + t} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{b - \left( -t \right)} & 0 & -\frac{b + \left( -t \right)}{b - \left( -t \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\end{align*} M or t h , l h → r h V u l kan = Ω l h → r h ( Q l h V u l kan ) − 1 M or t h C , V u l kan Ω l h → l h Q l h V u l kan = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M or t h C , V u l kan ( Ω l h → l h Q l h V u l kan ) = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M or t h C , V u l kan ( I Q l h V u l kan ) = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M or t h C , V u l kan Q l h V u l kan = ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ M or t h C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ M or t h C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 0 0 0 0 t − ( − b ) 2 0 0 0 0 f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r − ( − l ) 2 0 0 0 0 − t − ( − b ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − t − ( − b ) t + ( − b ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 0 0 0 0 − t + b 2 0 0 0 0 − f − n 1 0 − r + l r − l − t + b t − b − f − n n 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ r + l 2 0 0 0 0 − b + t 2 0 0 0 0 − f − n 1 0 − r + l r − l b + t b − t − f − n n 1 ⎦ ⎤ = ⎣ ⎡ r + l 2 0 0 0 0 b + t 2 0 0 0 0 − f − n 1 0 − r + l r − l − b + t b − t − f − n n 1 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 b − ( − t ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) − f − n n 1 ⎦ ⎤ therefore
M o r t h , l h → r h V u l k a n = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 b − ( − t ) 0 − b + ( − t ) b − ( − t ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] . M^{Vulkan}_{orth, lh \rightarrow rh} =
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{b - \left( -t \right)} & 0 & -\frac{b + \left( -t \right)}{b - \left( -t \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix}. M or t h , l h → r h V u l kan = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 b − ( − t ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) − f − n n 1 ⎦ ⎤ . Finally, we calculate the matrix for the symmetric vertical field of view perspective projection
M p e r , v f o v , l h → r h V u l k a n = Ω l h → r h ( Q l h V u l k a n ) − 1 M p e r , v f o v C , V u l k a n Ω l h → l h Q l h V u l k a n = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r , v f o v C , V u l k a n ( Ω l h → l h Q l h V u l k a n ) = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r , v f o v C , V u l k a n ( I Q l h V u l k a n ) = ( Ω l h → r h ( Q l h V u l k a n ) − 1 ) M p e r , v f o v C , V u l k a n Q l h V u l k a n = ( [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] ) M p e r , v f o v C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] M p e r , v f o v C , V u l k a n [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 f f − n − f n f − n 0 0 1 0 ] [ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ] = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 − 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{Vulkan}_{per,vfov,lh \rightarrow rh}
&= \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} M^{C,Vulkan}_{per,vfov} \Omega_{lh \rightarrow lh} Q^{Vulkan}_{lh} \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per,vfov} \left( \Omega_{lh \rightarrow lh} Q^{Vulkan}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per,vfov} \left( I Q^{Vulkan}_{lh} \right) \\
&= \left( \Omega_{lh \rightarrow rh} \left(Q^{Vulkan}_{lh}\right)^{-1} \right) M^{C,Vulkan}_{per,vfov} Q^{Vulkan}_{lh} \\
&= \left(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\right)
M^{C,Vulkan}_{per,vfov}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
M^{C,Vulkan}_{per,vfov}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& \frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& 1
& 0
\\
\end{bmatrix}
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\\
&= \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix}
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& -\frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}
\\
&= \begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}
\end{align*} M p er , v f o v , l h → r h V u l kan = Ω l h → r h ( Q l h V u l kan ) − 1 M p er , v f o v C , V u l kan Ω l h → l h Q l h V u l kan = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er , v f o v C , V u l kan ( Ω l h → l h Q l h V u l kan ) = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er , v f o v C , V u l kan ( I Q l h V u l kan ) = ( Ω l h → r h ( Q l h V u l kan ) − 1 ) M p er , v f o v C , V u l kan Q l h V u l kan = ⎝ ⎛ ⎣ ⎡ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ ⎠ ⎞ M p er , v f o v C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ M p er , v f o v C , V u l kan ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 f − n f 1 0 0 − f − n f n 0 ⎦ ⎤ ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 − 1 0 0 0 0 1 ⎦ ⎤ = ⎣ ⎡ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ⎦ ⎤ ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 − t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ therefore
M p e r , v f o v , l h → r h V u l k a n = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] . M^{Vulkan}_{per,vfov,lh \rightarrow rh} =
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix}. M p er , v f o v , l h → r h V u l kan = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ . This completes the derivation of the matrices for the left-handed Vulkan view coordinates.
View Coordinate Frame (Left-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , − y ^ , − z ^ ) (\mathbf{\hat{x}}, -\mathbf{\hat{y}}, -\mathbf{\hat{z}}) ( x ^ , − y ^ , − z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
− y ^ -\mathbf{\hat{y}} − y ^ points down,
− z ^ -\mathbf{\hat{z}} − z ^ points out of the view volume towards the viewerClip Coordinate Frame (Right-Handed Orientation) Origin : 0 = [ 0 , 0 , 0 ] T \mathbf{0} = [0, 0, 0]^{T} 0 = [ 0 , 0 , 0 ] T Basis :
( x ^ , − y ^ , z ^ ) (\mathbf{\hat{x}}, -\mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , − y ^ , z ^ ) where
x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T ,
y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T ,
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T
where
x ^ \mathbf{\hat{x}} x ^ points right,
− y ^ -\mathbf{\hat{y}} − y ^ points down,
z ^ \mathbf{\hat{z}} z ^ points into the view volume away from the viewerCanonical View Volume : [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] [-1, 1] \times [-1, 1] \times [0, 1] [ − 1 , 1 ] × [ − 1 , 1 ] × [ 0 , 1 ] M p e r , l h → r h V u l k a n = [ 2 n r − ( − l ) 0 r + ( − l ) r − ( − l ) 0 0 2 n b − ( − t ) b + ( − t ) b − ( − t ) 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] M o r t h , l h → r h V u l k a n = [ 2 r − ( − l ) 0 0 − r + ( − l ) r − ( − l ) 0 2 b − ( − t ) 0 − b + ( − t ) b − ( − t ) 0 0 − 1 f − n − n f − n 0 0 0 1 ] M p e r , v f o v , l h → r h V u l k a n = [ 1 aspect ⋅ tan ( θ v f o v 2 ) 0 0 0 0 1 tan ( θ v f o v 2 ) 0 0 0 0 − f f − n − f n f − n 0 0 − 1 0 ] \begin{align*}
M^{Vulkan}_{per, lh \rightarrow rh} &=
\begin{bmatrix}
\frac{ 2 n }{r - \left( -l \right)} & 0 & \frac{r + \left( -l \right)}{r - \left( -l \right)} & 0 \\
0 & \frac{ 2 n }{b - \left( -t \right)} & \frac{b + \left( -t \right)}{b - \left( -t \right)} & 0 \\
0 & 0 & -\frac{f}{f - n} & -\frac{f n }{f - n} \\
0 & 0 & -1 & 0 \\
\end{bmatrix} \\
M^{Vulkan}_{orth, lh \rightarrow rh} &=
\begin{bmatrix}
\frac{2}{r - \left( -l \right)} & 0 & 0 & -\frac{r + \left( -l \right)}{r - \left( -l \right)} \\
0 & \frac{2}{b - \left( -t \right)} & 0 & -\frac{b + \left( -t \right)}{b - \left( -t \right)} \\
0 & 0 & -\frac{1}{f - n} & -\frac{n}{f - n} \\
0 & 0 & 0 & 1 \\
\end{bmatrix} \\
M^{Vulkan}_{per,vfov,lh \rightarrow rh} &=
\begin{bmatrix}
\frac{1}{\text{aspect} \cdot \tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
& 0
\\
0
& \frac{1}{\tan\left( \frac{\theta_{vfov}}{2} \right)}
& 0
& 0
\\
0
& 0
& -\frac{f}{f - n}
& -\frac{ f n }{f - n}
\\
0
& 0
& -1
& 0
\\
\end{bmatrix} \\
\end{align*} M p er , l h → r h V u l kan M or t h , l h → r h V u l kan M p er , v f o v , l h → r h V u l kan = ⎣ ⎡ r − ( − l ) 2 n 0 0 0 0 b − ( − t ) 2 n 0 0 r − ( − l ) r + ( − l ) b − ( − t ) b + ( − t ) − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ = ⎣ ⎡ r − ( − l ) 2 0 0 0 0 b − ( − t ) 2 0 0 0 0 − f − n 1 0 − r − ( − l ) r + ( − l ) − b − ( − t ) b + ( − t ) − f − n n 1 ⎦ ⎤ = ⎣ ⎡ aspect ⋅ t a n ( 2 θ v f o v ) 1 0 0 0 0 t a n ( 2 θ v f o v ) 1 0 0 0 0 − f − n f − 1 0 0 − f − n f n 0 ⎦ ⎤ Comparing Coordinate System Orientations ¶ Let us illustrate why the coordinate systems in this section have a left-handed orientation or right-handed orientation.
By convention, the standard basis on R 3 \mathbb{R}^{3} R 3 has a right-handed orientation. Recall that the standard
basis on R 3 \mathbb{R}^{3} R 3 is the tuple of vectors ( x ^ , y ^ , z ^ ) (\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}) ( x ^ , y ^ , z ^ )
where x ^ = [ 1 , 0 , 0 ] T \mathbf{\hat{x}} = [1, 0, 0]^{T} x ^ = [ 1 , 0 , 0 ] T , y ^ = [ 0 , 1 , 0 ] T \mathbf{\hat{y}} = [0, 1, 0]^{T} y ^ = [ 0 , 1 , 0 ] T , and
z ^ = [ 0 , 0 , 1 ] T \mathbf{\hat{z}} = [0, 0, 1]^{T} z ^ = [ 0 , 0 , 1 ] T are the standard basis vectors. In this basis, Vulkans’s left-handed
view coordinate system has the determinant
det [ x ^ − y ^ z ^ ] = det [ 1 0 0 0 − 1 0 0 0 1 ] = 1 ⋅ − 1 ⋅ 1 = − 1 \det \begin{bmatrix} \mathbf{\hat{x}} & -\mathbf{\hat{y}} & \mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
= 1 \cdot -1 \cdot 1
= -1 det [ x ^ − y ^ z ^ ] = det ⎣ ⎡ 1 0 0 0 − 1 0 0 0 1 ⎦ ⎤ = 1 ⋅ − 1 ⋅ 1 = − 1 and Vulkan’s right-handed view coordinates and clip coordinates have the determinant
det [ x ^ − y ^ − z ^ ] = det [ 1 0 0 0 − 1 0 0 0 − 1 ] = 1 ⋅ − 1 ⋅ − 1 = 1 \det \begin{bmatrix} \mathbf{\hat{x}} & -\mathbf{\hat{y}} & -\mathbf{\hat{z}} \end{bmatrix}
= \det \begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & -1 \\
\end{bmatrix}
= 1 \cdot -1 \cdot -1
= 1 det [ x ^ − y ^ − z ^ ] = det ⎣ ⎡ 1 0 0 0 − 1 0 0 0 − 1 ⎦ ⎤ = 1 ⋅ − 1 ⋅ − 1 = 1 so the right-handed Vulkan view coordinate system and clip coordinate system indeed have a right-handed
orientation, and the left-handed view coordinate system has a left-handed orientation.
Summary ¶ We develop the manifold structure of real projective space R P 3 \mathbb{RP}^{3} RP 3 from scratch, then
use that information to show how we can represent linear, affine, and projective transformations as
matrices. We demonstrate why real projective space R P 3 \mathbb{RP}^{3} RP 3 is a convenient manifold for
solving problems in computer graphics, geometric modeling, robotics, computer vision, and other spatial
computing domains formulated in the setting E 3 \mathbb{E}^{3} E 3 . We use this knowledge to construct
homogeneous projection matrices.
We construct a set of projection matrices using a canonically chosen set of coordinates which makes
it easy to derive any other projection matrix using coordinate transformations in conjunction with
the relevant coordinate transformations to create the final result. We chose a view coordinate
system where the horizontal axis points to the right, the vertical axis points up, and the depth
axis points into the view volume. This has the benefit of keeping all of the computations in the same
orthonormal frame, which makes the behavior of the projection more obvious. Operating in real projective
space allows us to express our rendering problems in a coordinate system and scale independent way, such
that the choice of coordinate system is a degree of freedom for the problem at hand. Moreover, the
coordinate system independent formulation is a low-key form of separation of concerns in software
engineering for spatial computing domains.
We show how to construct perspective and orthographic projection transformations in R P 3 \mathbb{RP}^{3} RP 3
from any view space orthonormal frame to any clip coordinate frame by first defining the matrix
in a specially chosen coordinate chart, and then show that one can construct any other one by
using the appropriate orthogonal transformations and changes of orientation to map from the
desired view coordinate system to the canonical one on one side, and mapping from the canonical
clip coordinate system to the desired clip coordinate system using the same process. This
result shows that perspective and orthographic projections are indeed coordinate independent
transformations.
References ¶ Lee, John M. 2011. Introduction to Topological Manifolds . (2nd ed.). Springer Science+Business Media, LLC.
Lee (2011) . Marschner, Steve, et al. 2021. Fundamentals of Computer Graphics . 5th ed., A K Peters/CRC Press.
Marschner et al. (2021) . Munkres, James R. 2000. Topology . (2nd ed.). Pearson, Upper Saddle River, NJ.
Lee, J. M. (2011). Introduction to Topological Manifolds. In Graduate Texts in Mathematics . Springer New York. 10.1007/978-1-4419-7940-7 Marschner, S., Shirley, P., Ashikhmin, M., Gleicher, M., Hoffman, N., Johnson, G., Munzner, T., Reinhard, E., Thompson, W. B., Willemsen, P., & Wyvill, B. (2021). Fundamentals of Computer Graphics . A K Peters/CRC Press. 10.1201/9781003050339