Game Engine Architecture

(Ben Green) #1

406 10. The Rendering Engine


rect3D (D3DRS_CULL) to D3DCULLMODE_CW, then any triangle whose vertices
wind in a clockwise fashion in screen space will be treated as a back-facing
triangle and will not be drawn.
Back face culling is important because we generally don’t want to waste
time drawing triangles that aren’t going to be visible anyway. Also, rendering
the back faces of transparent objects can actually cause visual anomalies. The
choice of winding order is an arbitrary one, but of course it must be consistent
across all assets in the entire game. Inconsistent winding order is a common
error among junior 3D modelers.

Triangle Lists
The easiest way to defi ne a mesh is simply to list the vertices in groups of
three, each triple corresponding to a single triangle. This data structure is
known as a triangle list ; it is illustrated in Figure 10.6.

Figure 10.6. A triangle list.

V 0

V 1

V 2

V 3

V 4

V 5

V 6

V 7

V 0 V 1 V 3 V 1 V 2 V 3 V 0 V 5 V 1 ... V 5 V 7 V 6

Indexed Triangle Lists
You probably noticed that many of the vertices in the triangle list shown in
Figure 10.6 were duplicated, oft en multiple times. As we’ll see in Section
10.1.2.1, we oft en store quite a lot of metadata with each vertex, so repeating
this data in a triangle list wastes memory. It also wastes GPU bandwidth, be-
cause a duplicated vertex will be transformed and lit multiple times.
For these reasons, most rendering engines make use of a more effi cient
data structure known as an indexed triangle list. The basic idea is to list the
vertices once with no duplication and then to use light-weight vertex indi-
ces (usually occupying only 16 bits each) to defi ne the triples of vertices that
constitute the triangles. The vertices are stored in an array known as a vertex
Free download pdf