Game Engine Architecture

(Ben Green) #1

438 10. The Rendering Engine


Division by Z
Perspective projection results in each vertex’s x- and y-coordinates being di-
vided by its z-coordinate. This is what produces perspective foreshortening.
To understand why this happens, consider multiplying a view-space point
pV expressed in four-element homogeneous coordinates by the OpenGL per-
spective projection matrix:

2


0 0 0


2


0 0 0


[1].


1


2


00 0


H V VH

Vx Vy Vz

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

= →


⎡⎤⎛⎞


⎢⎥⎜⎟⎝⎠


⎢⎥−


⎢⎥⎛⎞


⎢⎥⎜⎟⎝⎠


⎢⎥−


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


⎢⎥⎜ ⎟⎜ ⎟⎜⎟−−


⎢⎥⎝−−⎠⎝ ⎠⎝⎠−


⎢⎥⎛⎞


⎢⎥⎜⎟−


⎢⎥⎣⎦⎝⎠−


p pM

The result of this multiplication takes the form
pHV=−⎣⎦⎡⎤abc pz. (10.1)
When we convert any homogeneous vector into three dimensional coor-
dinates, the x-, y-, and z-components are divided by the w-component:

.

xzy
xyzw
www

⎡⎤≡⎡⎤


⎣⎦⎢⎥⎣⎦^


So, aft er dividing Equation (10.1) by the homogeneous w-component, which is
really just the negative view-space z-coordinate −pVz, we have:

[].


H
Vz Vz Vz

Hx Hy Hz

abc
ppp

ppp

⎡⎤


=⎢⎥


⎣⎦−−−


=


p

Thus the homogeneous clip space coordinates have been divided by the view-
space z-coordinate, which is what causes perspective foreshortening.

Perspective-Correct Vertex Attribute Interpolation
In Section 10.1.2.4, we learned that vertex att ributes are interpolated in order to
determine appropriate values for them within the interior of a triangle. Att ri-
bute interpolation is performed in screen space. We iterate over each pixel of the
screen and att empt to determine the value of each att ribute at the correspond-
ing location on the surface of the triangle. When rendering a scene with a perspec-
Free download pdf