Download presentation
Presentation is loading. Please wait.
Published byJordan Grant Modified over 8 years ago
1
3D Graphics for Game Programming Chapter I Modeling in Game Production
2
3D Graphics for Game Programming Stages in Game Production Pre-production Sketching the game characters Composing the storyline Creating storyboards (visual representations of the storyline) Writing the design document Production Modeling, animation, and rendering The output of the production stage is a game program and a bunch of game assets to be consumed by the game program. The assets include 3D models, images, and animation data. Post-production Debugging Optimization 2 1-2
3
3D Graphics for Game Programming Game Production Pipeline This class is devoted to the production stage. The artists create graphics assets, and are in charge of modeling and ‘half’ of animation. The programmers are in charge of the other half of animation and rendering. Roughly speaking, the animation step is partitioned into off-line tasks and run-time tasks, which are handled by artists and programmers, respectively. 3 1-3
4
3D Graphics for Game Programming Production Stage – Modeling A model is referred to as a computer representation of an object, and modeling is the process of creating the components of the virtual environment. The most popular modeling method in games is using polygons, and the model is called polygon meshes. The scope of modeling is not limited to constructing 3D models, but includes creating textures that are added to the 3D models to increase their realism. 4 1-4 texture image
5
3D Graphics for Game Programming Production Stage – Animation Consider a soldier model. Unlike the terrain, it should be able to walk, run, and crawl. For the purpose, we usually specify the skeletal structure of the soldier and define how the skeletal motion deforms the soldier's polygon mesh. For example, the polygons around the thigh will move if the thigh-bone moves. This process is referred to as rigging. 5 1-5 skeletonskeleton embedded into the mesh
6
3D Graphics for Game Programming Production Stage – Animation (cont’d) A rigged model is animated by artists. (The animations are replayed at run time.) Dedicated programs such as 3ds Max and 3ds Maya are popularly used for modeling and off-line animation. 6 1-6
7
3D Graphics for Game Programming Production Stage – Rendering Computer games generate an illusion of movement on the screen by quickly displaying a sequence of changing images, called frames. Rendering is the process of generating a 2D image (frame) from a 3D scene. A specific pose of an animated character is defined per frame. Run-time dynamics caused by collisions among the game objects is handled, and the resulting configuration is defined per frame. Lighting conditions and camera pose that can be changed per frame are considered. Texture is applied to the object surface, and lighting is computed. 7 1-7
8
3D Graphics for Game Programming Production Stage – Rendering (cont’d) Unlike modeling and off-line animation conducted by artists, run-time animation and rendering are executed by a game program. A game program is usually built upon graphics APIs such as Direct3D and OpenGL. Direct3D is part of Microsoft's DirectX API, and is available only for Microsoft platforms. OpenGL (Open Graphics Library) is managed by a non-profit consortium, the Khronos Group, and is a cross-platform standard API. Graphics APIs They provide application programmers with essential graphics functions. Today, such functions are implemented in hardware, named GPU (Graphics Processing Unit), which is a processor specialized for graphics. A graphics API can be taken as a software interface of the GPU. The API translates the application's graphics command to instructions that can be executed by the GPU. 8 1-8
9
3D Graphics for Game Programming Polygon Mesh In the real-time applications such as games, the polygon mesh representation dominates. It is not an accurate representation but an approximate one. 9 1-9
10
3D Graphics for Game Programming Polygon Mesh (cont’d) OpenGL supports convex planar polygons. The simplest polygon is a triangle, and the polygons supported by Direct3D are limited to triangles. Note that triangles are both convex and planar. 10 1-10
11
3D Graphics for Game Programming Polygon Mesh (cont’d) Levels of detail Tradeoff between accuracy and efficiency - As the resolution is increased, the mesh becomes closer to the original curved surface, but the time needed for processing the mesh is increased. 11 1-11 simplification refinement
12
3D Graphics for Game Programming Polygon Mesh Creation In most cases, the polygon mesh of a game object is interactively created using graphics packages such as 3ds Max. (The object is stored in a file, and then input to the game engine which animates and renderers it at run time.) Let’s see an example in 3ds Max. 12 1-12
13
3D Graphics for Game Programming Polygon Mesh Creation (cont’d) 13 1-13
14
3D Graphics for Game Programming Polygon Mesh Creation (cont’d) 14 1-14
15
3D Graphics for Game Programming Polygon Mesh Creation (cont’d) 15 1-15
16
3D Graphics for Game Programming Polygon Mesh Representation – Non-indexed Triangle List 16 1-16 Non-indexed triangle list The vertices are enumerated in a memory space, named vertex buffer. Three vertices are read in linear order to make up a triangle. It is intuitive but inefficient because the vertex buffer contains redundant data.
17
3D Graphics for Game Programming Polygon Mesh Representation – Indexed Triangle List 17 1-17 A better method is using a separate index buffer. A vertex appears only once in the vertex buffer. Three indices per triangle are stored in the index buffer. This representation is called an indexed triangle list. The vertex data stored in the vertex buffer include not only positions but also normals, texture coordinates, and many more. Therefore, the vertex buffer storage saved by removing the duplicate data outweighs the additional storage needed for the index buffer.
18
3D Graphics for Game Programming Post-transform Cache 18 1-18 Each vertex is processed by the so-called vertex processing stage of the GPU (presented in Chapter 2), and is stored in a post-transform cache. If a triangle references a vertex located in the cache, the vertex is simply fetched from the cache instead of being transformed again by the vertex processing stage. (The triangle formed by assembling three vertices of the cache is further processed for rendering.) When searching the cache for the vertex referenced by a triangle, the vertex index is used. Use the example to see how the post-transform cache works.
19
3D Graphics for Game Programming Post-transform Cache (cont’d) 19 1-19 Assuming a small-size cache (say, containing 4 vertices), compare the two orderings. a c b d e f g h i j k l
20
3D Graphics for Game Programming Post-transform Cache (cont’d) 20 1-20 Let’s count the number of the processed (transformed) vertices per triangle. Only when the cache is missed, the vertex is processed. Therefore, counting the number of the processed vertices per triangle corresponds to counting the cache misses per triangle. The average number of the processed vertices per triangle is called the average cache miss ratio (ACMR), and is often used to measure the rendering performance. The smaller ACMR, the more efficient. ACMR depends on the triangle order! In a typical closed mesh, the number of triangles is approximately twice the number of vertices, i.e., given n vertices, we have about 2n triangles. The best-case ACMR approximates 0.5, i.e., n/2n. (This surely happens if the post- transform cache is large enough to contain all vertices of the mesh.) The worst-case ACMR is 3. There have been efforts for reducing ACMR by reordering the triangles. An example is ID3DXMesh::Optimize. With such an effort to provide a triangle mesh with high locality, ACMR can be usually maintained between 0.5 and 1.
21
3D Graphics for Game Programming Polygon Mesh Representation – Triangle Strip 21 1-21 Each triangle shares two vertices with the previous triangle (except the first triangle). In the ideal case, three vertices are processed for the first triangle, and then a single vertex is processed for each of the remaining triangles. Then, rendering n triangles requires (n+2) vertices to be processed, i.e., ACMR is (n+2)/n.
22
3D Graphics for Game Programming Surface Normal 22 1-22 Vertex positions are not enough for rendering, but we need vertex normals. The vertex normals are usually defined using the triangle normals. Consider triangle p 1, p 2, p 3 , where the vertices are ordered counter-clockwise (CCW). Its normal is computed using the cross product based on the right- hand rule: For clockwise(CW)-ordered vertices, i.e., p 1, p 3, p 2 , the normal is Surface normals are supposed to point out of the polyhedron. For this, we need CCW ordering of the vertices, i.e., p 1, p 2, p 3 , instead of p 1, p 3, p 2 .
23
3D Graphics for Game Programming Surface Normal (cont’d) 23 1-23 In the index buffer, the vertices are ordered CCW. Later, we will discuss more on this!
24
3D Graphics for Game Programming Vertex Normal 24 1-24 As will be also discussed later, what is really important is the vertex normal. Recall that the polygon mesh is an approximation of a smooth surface. Then, the mesh vertices are the points sampling the smooth surface. So, the vertex normal should approximate the normal of the smooth surface at the vertex position. A vertex normal is usually computed by averaging the normals of all polygons sharing the vertex.
25
3D Graphics for Game Programming Export and Import 25 1-25 Export: process of outputting the data in a format suitable for other applications Two ways for export Plug-in: compiled and run by CPU Script: interpreted and run by the host program (such as 3ds Max) Specify Out as the output file foreach polygon mesh Write the number of vertices to Out foreach vertex Write its positions and normals to Out endforeach Write the number of polygons to Out foreach polygon Write its three indices to Out endforeach vertices 530 49.2721 0.809525 85.6266 -0.966742 0.0 0.255752 48.5752 0.809525 88.2606 -0.966824 0.0 0.255444 49.3836 0.809525 89.1386 -0.092052 0.0 0.995754 … faces 1024 0 5 6 6 1 0 … file export import modeler game program
26
3D Graphics for Game Programming Coordinate System’s Handedness and Vertex Ordering 26 1-26 Right-hand system vs. left-hand system So far, we implicitly assumed RHS and used the right hand for defining the triangle normal. In LHS, the triangle normal is defined using the left hand. To make the normals point out of the object, RHS adopts CCW ordering whereas LHS adopts CW ordering.
27
3D Graphics for Game Programming Conversion between RHS and LHS 27 1-27 Porting an application between RHS and LHS needs two tasks. The order of triangle vertices has to be changed: p 1, p 2, p 3 p 1, p 3, p 2 The z-coordinate should be negated.
28
3D Graphics for Game Programming Conversion between RHS and LHS (cont’d) 28 1-28 In order to avoid the reflected image shown in the previous page, the z- coordinates of both the objects and view parameters should be negated. Note that z-negation is equivalent to the z-axis inversion.
29
3D Graphics for Game Programming Conversion between RHS and LHS (cont’d) 29 1-29 Whereas the z-negation is required, the vertex order change is optional. There exists a roundabout way. See Chapter 3. RHS is the default coordinate system of OpenGL, and LHS is that of Direct3D. Therefore, porting between RHS and LHS needs to be clearly understood. The difference constructed a barrier hard to cross over for inexperienced programmers. However, the barrier has crumbled away, and we can run an RHS-based application on top of Direct3D, for example. It has been due to GPU's programmability. This book uses RHS by default because it is much more familiar to the ordinary readers. Therefore, the triangle vertices are listed in the CCW order unless specified otherwise.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.