1 / 31

Chapter I Modeling in Game Production

Chapter I Modeling in Game Production. 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

Télécharger la présentation

Chapter I Modeling in Game Production

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter I Modeling in Game Production

  2. 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 • 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

  3. Game Production Pipeline • This class is devoted to the production stage, which is often characterized as the following pipeline. • The pipeline is defined from the graphics viewpoint, and therefore graphic artists and programmers are the key players. • 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.

  4. 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. Shown below are the triangle mesh examples. • 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. texture image

  5. Animation • Consider a soldier model. Unlike static objects such as 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. skeleton skeleton embedded into the mesh

  6. Animation (cont’d) • A rigged model is animated by artists such that 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.

  7. Rendering • Computer games generate an illusion of movement on the screen by quickly displaying a sequence of changing images, called frames. • For each frame, the scene needs to be updated. • Distinct shape and pose of each animated object are computed. • Run-time dynamics caused by external forces and collisions among the game objects is handled, and the states of the involved objects are updated. • Lighting conditions and camera pose that can be changed per frame are considered. • Textures are applied to the object surfaces, and lighting is computed. • Rendering is the process of generating a 2D image (frame) from a 3D scene.

  8. 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 a processor specialized for graphics, named GPU (Graphics Processing Unit). • 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.

  9. Polygon Mesh • In real-time applications such as games, the polygon mesh representation dominates. It is not an accurate representation but an approximate one, where the mesh vertices are the points sampling the smooth surface.

  10. Polygon Mesh (cont’d) • In OpenGL, the polygons should be convex and planar. • Direct3D supports only triangles. Note that the simplest polygon is a triangle, and triangles are both convex and planar. trianglemesh quad mesh

  11. Polygon Mesh (cont’d) • Levels of detail (LOD) • 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. refinement simplification

  12. 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 renders it at run time.) • Let’s see an example in 3ds Max.

  13. Polygon Mesh Creation (cont’d)

  14. Polygon Mesh Creation (cont’d)

  15. Polygon Mesh Creation (cont’d)

  16. Polygon Mesh Representation – Non-indexed Triangle List • 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 inefficient because the vertex buffer contains redundant data.

  17. Polygon Mesh Representation – Indexed Triangle List • 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. Surface Normal • For now, let’s jump to Section 1.2.3. • Surface normals play a key role in computer graphics. • Given triangle p1, p2, p3, let v1 denote the vector connecting the first vertex (p1) and the second (p2). Similarly, the vector connecting the first vertex (p1) and the third (p3) is denoted by v2. Then, the triangle normalis computed using the cross product based on the right-hand rule. • When v1 andv2 are represented in (x1 y1 z1) and (x2 y2 z2), respectively, v1×v2 is defined as (y1z2-z1y2 z1x2-x1z2 x1y2-y1x2). • Every normal vector is made to be a unit vector by default. • Note that p1, p2, and p3 are ordered counter-clockwise (CCW).

  19. Surface Normal (cont’d) • What if the vertices are ordered clockwise(CW), i.e., p1, p3, p2? • The vector connecting the first vertex (p1) and the second (p3) and that connecting the first vertex (p1) and the third (p2) define the triangle normal. • The normal is in the opposite direction! • The normal direction depends on the vertex order, i.e., whether p1, p2, p3 or p1, p3, p2. • In computer graphics, surface normals are supposed to point out of the polyhedron. For this, we need CCW ordering of the vertices, i.e., p1, p2, p3, instead of p1, p3, p2.

  20. Surface Normal (cont’d) • In the index buffer, the vertices are ordered CCW. • Later, we will discuss more on this!

  21. Surface Normal (cont’d) • 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.

  22. Export and Import • Export: process of outputting the data in a format suitable for other applications • For exporting, scripts are often used, which are run by the host program (such as 3ds Max). • 3ds Max provides MAXScript, and an exporter can be written using MAXScript. export import modeler game program file 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 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 …

  23. Drawcall in Direct3D • IDirect3DDevice9 interface is the software controller of the graphics device hardware. • To create the vertex and index buffers within GPU, we call the following: • IDirect3DDevice9::CreateVertexBuffer • IDirect3DDevice9::CreateIndexBuffer • The vertex/index data stored in the CPU arrays may then be copied to the vertex/index buffers using memcpy, for example. • The polygon mesh represented in the vertex/index buffers is drawn by invoking IDirect3DDevice9::DrawIndexedPrimitive. • Drawcall for non-indexed triangle lists is IDirect3DDevice9::DrawPrimitive. • Not only triangles but also line segments and points can be rendered as independent entities. They are collectively called primitives.

  24. Post-transform Cache • Let’s return to p.12 of the book. • Upon a drawcall, each vertex is processed by the 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.) • Obviously, the vertex index is used when searching the cache for the vertex referenced by a triangle.

  25. Post-transform Cache (cont’d) • Assuming a small-size cache (say, containing 4 vertices), compare the two orderings. l e k d f j c g a i b h

  26. Post-transform Cache (cont’d) • 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). 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. • Best and worst cases • The best-case happens when no vertex is processed multiple times, and then the 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.

  27. Polygon Mesh Representation – Triangle Strip • 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.

  28. Coordinate System’s Handedness and Vertex Ordering • Right-hand system vs. left-hand system • So far, we implicitly assumed RHS and used the right hand for defining the triangle normals. 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.

  29. Conversion between RHS and LHS • Porting an application between RHS and LHS needs two tasks. • The order of triangle vertices has to be changed: p1, p2, p3  p1, p3, p2 • The z-coordinate should be negated.

  30. Conversion between RHS and LHS (cont’d) • 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.

  31. Conversion between RHS and LHS (cont’d) • 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.

More Related