44/45

Perspective matrix

Perspective space : Allows perspective projection expressed as matrix.

Common constraints (in OpenGL)

  • - Wrap a frustum (\(z_{near}, z_{far}, \theta)\) to a unit cube.

    • - \(\theta\): angle of view

    • - \(p=(x,y,z,1)\in\) frustum \(\Rightarrow p'=(x',y',z',1) \in [-1,1]^3\).

  • - Set \(z'\) to be more precise for close-by objects, than further one (Z-buffer precision limitation).

projection

\[ \small \mathrm{M} = \left( \begin{array}{cccc} f & 0 & 0 & 0 \\ 0 & f & 0 & 0 \\ 0 & 0 & C & D \\ 0 & 0 & -1 & 0 \end{array} \right) \;\;\; \begin{array}{l} f = 1/\tan(\theta/2) \\ L = z_{near}-z_{far} \\ C = (z_{far}+z_{near})/L \\ D = 2 \, z_{far} \, z_{near}/L \\ \end{array} \]

In practice

  • ⇒ You must define \(z_{near}\), \(z_{far}\)

  • ⇒ \(z_{far}-z_{near}\) should be as small as possible for maximum depth precision.

\(\color{blue}{\theta}\)