Game Engine Architecture

(Ben Green) #1
437

dinate system “clip space” because the view volume planes are axis-aligned,
making it convenient to clip triangles to the view volume in this space (even
when a perspective projection is being used). The canonical clip-space view
volume for OpenGL is depicted in Figure 10.34. Notice that the z-axis of clip
space goes into the screen, with y up and x to the right. In other words, homo-
geneous clip space is usually left -handed.


Perspective Projection


An excellent explanation of perspective projection is given in Section 4.5.1 of
[28], so we won’t repeat it here. Instead, we’ll simply present the perspective
projection matrix MVH→ below. (The subscript V→H indicates that this ma-
trix transforms vertices from view space into homogeneous clip space.) If we
take view space to be right-handed, then the near plane intersects the z-axis
at z = –n, and the far plane intersects it at z = –f. The virtual screen’s left , right,
bott om, and top edges lie at x = l, x = r, y = b, and y = t on the near plane, respec-
tively. (Typically the virtual screen is centered on the camera-space z-axis, in
which case l = –r and b = –t, but this isn’t always the case.) Using these defi ni-
tions, the perspective projection matrix for OpenGL is as follows:


(^)
(^20) 0 0


02 0 0


.


1


2


00 0


VH

n
rl
n
tb
rl tb fn
rl tb f n
nf
fn


⎡⎤⎛⎞


⎢⎥⎜⎟⎝⎠


⎢⎥−


⎢⎥⎛⎞


⎢⎥⎜⎟⎝⎠


⎢⎥−


=⎢⎥⎛++⎞⎛ ⎞⎛⎞+


⎢⎥⎜⎝ ⎟⎜⎠⎝ ⎟⎠⎜⎟−−


⎢⎥−−⎝⎠−


⎢⎥⎛⎞


⎢⎥⎜⎟−


⎢⎥⎣⎦⎝⎠−


M^


DirectX defi nes the z-axis extents of the clip-space view volume to lie in
the range [0, 1] rather thanin the range [–1, 1] as OpenGL does. We can easily
adjust the perspective projection matrix to account for DirectX’s conventions
as follows:


()DirectX^


2


0 0 0


2


0 0 0


.


1


00 0


VH

n
rl
n
tb
rl tb f
rl tb f n
nf
fn


⎡⎤⎛⎞


⎢⎥⎜⎟⎝⎠


⎢⎥−


⎢⎥⎛⎞


⎢⎥⎜⎟⎝⎠


⎢⎥−


=⎢⎥⎛++⎞⎛ ⎞⎛⎞


⎢⎥⎜ ⎟⎜ ⎟⎜⎟−−


⎢⎥⎝−−⎠⎝ ⎠⎝⎠−


⎢⎥⎛⎞


⎢⎥⎜⎟−


⎢⎥⎣⎦⎝⎠−


M


10.1. Foundations of Depth-Buffered Triangle Rasterization

Free download pdf