Game Engine Architecture

(Ben Green) #1
439

tive projection, we must do this very carefully so as to account for perspective
foreshortening. This is known as perspective-correct att ribute interpolation.
A derivation of perspective-correct interpolation is beyond our scope, but
suffi ce it to say that we must divide our interpolated att ribute values by the
corresponding z-coordinates (depths) at each vertex. For any pair of vertex at-
tributes A 1 and A 2 , we can write the interpolated att ribute at a percentage t of
the distance between them as follows:


1 2 12
1 2 12

(1 ) LERP , ,.


z z z zz

A A A AA


t
p p p pp

⎛⎞


=− + = ⎜⎟


⎝⎠


t t

Refer to [28] for an excellent derivation of the math behind perspective-correct
att ribute interpolation.


Orthographic Projection


An orthographic projection is performed by the following matrix :


()ortho

(^2000)


002 0


2.


00 0


1


VH

rl

tb

fn
rl tb fn
rl tb f n


⎡⎤⎛⎞


⎢⎥⎜⎟⎝⎠−


⎢⎥


⎢⎥⎛⎞⎜⎟


⎢⎥⎝⎠−


⎢⎥


=⎢⎥⎛⎞


⎢⎥⎜⎟−


⎢⎥⎝⎠−


⎢⎥⎛⎞


⎢⎥⎛ ++⎞⎛ ⎞⎜⎟+


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


⎣⎦−− −⎝⎠


M


This is just an everyday scale-and-translate matrix. (The upper-left 3 × 3
contains a diagonal nonuniform scaling matrix, and the lower row contains
the translation.) Since the view volume is a rectangular prism in both view
space and clip space, we need only scale and translate our vertices to convert
from one space to the other.


10.1.4.5. Screen Space and Aspect Ratios


Screen space is a two-dimensional coordinate system whose axes are mea-
sured in terms of screen pixels. The x-axis typically points to the right, with
the origin at the top-left corner of the screen and y pointing down. (The reason
for the inverted y-axis is that CRT monitors scan the screen from top to bot-
tom.) The ratio of screen width to screen height is known as the aspect ratio.
The most common aspect ratios are 4:3 (the aspect ratio of a traditional tele-
vision screen) and 16:9 (the aspect ratio of a movie screen or HDTV). These
aspect ratios are illustrated in Figure 10.35.


10.1. Foundations of Depth-Buffered Triangle Rasterization

Free download pdf