Game Engine Architecture

(Ben Green) #1

410 10. The Rendering Engine


A mesh instance contains a reference to its shared mesh data and also
includes a transformation matrix that converts the mesh’s vertices from model
space to world space, within the context of that particular instance. This ma-
trix is called the model-to-world matrix, or sometimes just the world matrix. Us-
ing the notation from Section 4.3.10.2, this matrix can be writt en as follows:
()
1 ,

MW
MW M



⎡⎤


=⎢⎥


⎣⎦


RS 0


M t

where the upper 3 × 3 matrix ()RSMW→ rotates and scales model-space ver-
tices into world space, and tM is the translation of the model space axes ex-
pressed in world space. If we have the unit model space basis vectors iM, jM,
and kM, expressed in world space coordinates, this matrix can also be writt en
as follows:
0
0
0.
1

M
M
MW M

M


⎡⎤


⎢⎥


=⎢⎥


⎢⎥


⎢⎥


⎢⎥⎣⎦


i
j
M k

t

Given a vertex expressed in model-space coordinates, the rendering en-
gine calculates its world-space equivalent as follows:
vW=vMM MW→.
We can think of the matrix MM→W as a description of the position and orienta-
tion of the model space axes themselves, expressed in world space coordi-
nates. Or we can think of it as a matrix that transforms vertices from model
space to world space.
When rendering a mesh, the model-to-world matrix is also applied to the
surface normals of the mesh (see Section 10.1.2.1). Recall from Section 4.3.11,
that in order to transform normal vectors properly, we must multiply them
by the inverse transpose of the model-to-world matrix. If our matrix does not
contain any scale or shear, we can transform our normal vectors correctly by
simply sett ing their w components to zero prior to multiplication by the mod-
el-to-world matrix, as described in Section 4.3.6.1.
Some meshes like buildings, terrain, and other background elements are
entirely static and unique. The vertices of these meshes are oft en expressed in
world space, so their model-to-world matrices are identity and can be ignored.

10.1.2. Describing the Visual Properties of a Surface
In order to properly render and light a surface, we need a description of its
visual properties. Surface properties include geometric information, such as the
Free download pdf