59
Advanced Programming for 3D Advanced Programming for 3D Applications Applications CE00383-3 CE00383-3 Game Architecture Game Architecture

Advanced Programming for 3D Applications CE00383-3

Embed Size (px)

DESCRIPTION

Advanced Programming for 3D Applications CE00383-3. Game Architecture. Program Flow. Standard framework. main() {. begin. resources. Models, textures, sounds, etc. acquire. setup state. Camera, Alpha, Lighting, etc. update. Apply changes to your world. render. render. - PowerPoint PPT Presentation

Citation preview

Page 1: Advanced Programming for 3D Applications  CE00383-3

Advanced Programming for 3D Advanced Programming for 3D ApplicationsApplications CE00383-3 CE00383-3

Game ArchitectureGame Architecture

Page 2: Advanced Programming for 3D Applications  CE00383-3

Program FlowProgram Flow

• Standard framework Standard framework

begin

acquire

render

release

resources

setup state

fin

resources

update

render

main() {

Models, textures, sounds, etc.

Camera, Alpha, Lighting, etc.

Apply changes to your world.

Project your world onto the screen.

Free resources previously acquired.

return 0; }

Page 3: Advanced Programming for 3D Applications  CE00383-3

Program FlowProgram Flow

Resources

Infrequent loop when important changes (popup, change resolution, monitor, etc)

begin

acquire

render

release

resources

setup state

fin

resources

update

render

Main loop

Loops once per frame

Page 4: Advanced Programming for 3D Applications  CE00383-3

int main(void)int main(void){{

CGame Game;CGame Game;

if(Game.Start())if(Game.Start()){{

printf("\nGame started\n");printf("\nGame started\n");

while(Game.GetRunningStatus())while(Game.GetRunningStatus()){{

Game.GameLoop();Game.GameLoop();}}

}}

else printf("Startup Failed\n");else printf("Startup Failed\n");

printf("\nGame stopping\n\n");printf("\nGame stopping\n\n");

Game.Stop();Game.Stop();

return 0;return 0;}}

Page 5: Advanced Programming for 3D Applications  CE00383-3

Game ClassGame Class

• There is a single instance of the game There is a single instance of the game class, CGame containing methodsclass, CGame containing methods– CGame::Start() executes all of the required star-CGame::Start() executes all of the required star-

up code while CGame::Stop() performs any up code while CGame::Stop() performs any necessary clean-up at the end of the game necessary clean-up at the end of the game execution.execution.

– CGame::GameLoop() is the game loop code that CGame::GameLoop() is the game loop code that is executed every frame and this contains the is executed every frame and this contains the state machine implementation.state machine implementation.

– CGame::GetRunningStatus() returns a Boolean CGame::GetRunningStatus() returns a Boolean to indicate whether the game is running (true) to indicate whether the game is running (true) or has ended (false).or has ended (false).

Page 6: Advanced Programming for 3D Applications  CE00383-3

Basic FrameworkBasic Frameworkenum GAMESTATE {SPLASH, MENU, LEVEL1, enum GAMESTATE {SPLASH, MENU, LEVEL1,

EXIT};EXIT};  class CGameclass CGame{{public:public:          CGame(void);CGame(void);          ~CGame(void);~CGame(void);            bool Start(void);bool Start(void);          void GameLoop(void);void GameLoop(void);          void GameSplash(void);void GameSplash(void);          void GameMenu(void);void GameMenu(void);          void GameLevel1(void);void GameLevel1(void);          void GameExit(void);void GameExit(void);          void Stop(void);void Stop(void);                    static void SignalHandler(int Signal);static void SignalHandler(int Signal);            inline bool GetRunningStatus(void)inline bool GetRunningStatus(void)                    {return m_bRunning;}{return m_bRunning;}            static inline void SetRunningStatus(bool static inline void SetRunningStatus(bool

Status)Status)                    {m_bRunning = Status;}{m_bRunning = Status;}  

protected:protected:          static bool m_bRunning;static bool m_bRunning;          PS2SpriteT Sprite;PS2SpriteT Sprite;          CTexture Game;CTexture Game;          CFont Font;CFont Font;          CTexture FontTex;CTexture FontTex;          enum GAMESTATE GameState;    enum GAMESTATE GameState;    };};

Page 7: Advanced Programming for 3D Applications  CE00383-3

• The CGame::Start() method allocated The CGame::Start() method allocated memory, configures the signal memory, configures the signal handler, configures the control pads, handler, configures the control pads, initialises the screen clear colour, initialises the screen clear colour, loads the font textures the loads the loads the font textures the loads the game textures. game textures.

• Game::Start() returns true if all of the Game::Start() returns true if all of the initialisation code is successful.initialisation code is successful.

• CGame::GameLoop() contains the CGame::GameLoop() contains the state machine implementation.state machine implementation.

Page 8: Advanced Programming for 3D Applications  CE00383-3

void CGame::GameLoop()void CGame::GameLoop(){{          pad_update(PAD_0);pad_update(PAD_0);          if((pad[0].buttons & PAD_START)&&(pad[0].buttons & PAD_SELECT)) if((pad[0].buttons & PAD_START)&&(pad[0].buttons & PAD_SELECT))

SetRunningStatus(false);SetRunningStatus(false);            switch (GameState)switch (GameState)          {{                    case SPLASH:case SPLASH:                            GameSplash();GameSplash();                            break;break;                      case MENU:case MENU:                            GameMenu();GameMenu();                            break;break;                      case LEVEL1:case LEVEL1:                            GameLevel1();GameLevel1();                            break;break;                      case EXIT:case EXIT:                            GameExit();GameExit();                            break;break;                      default:default:                            printf("Undefined Game State\n");printf("Undefined Game State\n");                            SetRunningStatus(false);SetRunningStatus(false);                            break;break;          }}}}

Page 9: Advanced Programming for 3D Applications  CE00383-3

Game LoopGame Loop

• CGame::GameLoop() is used to switch CGame::GameLoop() is used to switch between the various game states based on between the various game states based on the enumerated variable GameState. the enumerated variable GameState.

• The organisation of the state machine can The organisation of the state machine can be adapted to meet the requirements of be adapted to meet the requirements of the application. the application.

• The CGame::GameLoop() also contains The CGame::GameLoop() also contains exit code by pressing start and select exit code by pressing start and select together on controller pad 0 – this is very together on controller pad 0 – this is very useful for debugging code where the useful for debugging code where the developer does not wish to always have to developer does not wish to always have to work through a menu system. work through a menu system.

Page 10: Advanced Programming for 3D Applications  CE00383-3

Core Library

GeometryManagement

Animation andSimulation

SoundScript

Interpreter

Game Content

Network

• Control the presentation of game contentControl the presentation of game content– Geometry and TextureGeometry and Texture– ScriptScript– SoundSound– Simulation (i.e. Physics)Simulation (i.e. Physics)– AIAI

AI

Game Engine ArchitectureGame Engine Architecture

Page 11: Advanced Programming for 3D Applications  CE00383-3

3D Rendering systems3D Rendering systems

• The modeling-rendering paradigmThe modeling-rendering paradigm

• Graphics pipelineGraphics pipeline

Page 12: Advanced Programming for 3D Applications  CE00383-3

Geometry ManagementGeometry Management• Move as many polygons as possible as quickly as possibleMove as many polygons as possible as quickly as possible

– Apply Texture (usually multiple textures)Apply Texture (usually multiple textures)– LightingLighting– Color and BlendingColor and Blending– Depth sort (ZBuffer, BSP tree)Depth sort (ZBuffer, BSP tree)– Bind shader programs (DX9)Bind shader programs (DX9)– ……

• Control each rendering passControl each rendering pass• Cull out invisible geometryCull out invisible geometry• Meshes are exported from the art toolMeshes are exported from the art tool

– Usually 3D Studio MAX or MayaUsually 3D Studio MAX or Maya• Some additional processing is doneSome additional processing is done

– Level-of-detail simplificationLevel-of-detail simplification– Polygons organized into engine-friendly structuresPolygons organized into engine-friendly structures

• Vertex arraysVertex arrays• Triangle stripsTriangle strips• Scene graphScene graph

– Texture compressionTexture compression– Colors checked for “illegal” valuesColors checked for “illegal” values

Page 13: Advanced Programming for 3D Applications  CE00383-3

Vertex ArraysVertex Arrays• Vertex Buffers (DX) / Vertex Arrays (OGL)Vertex Buffers (DX) / Vertex Arrays (OGL)

– An array of per-vertex informationAn array of per-vertex information• x, y, z: positionx, y, z: position• r, g, b: colorr, g, b: color• i, j, k: normal (for lighting and physics)i, j, k: normal (for lighting and physics)• u, v, w: texture (w optional)u, v, w: texture (w optional)• Multitexturing would append other (u, v, w) coordinatesMultitexturing would append other (u, v, w) coordinates• Other stuff (tangent, binormal for bump mapping; other application-specific per-vertex Other stuff (tangent, binormal for bump mapping; other application-specific per-vertex

information)information)

• Each array has a primitive typeEach array has a primitive type– PointsPoints– LinesLines– TrianglesTriangles– Triangle Strip or FanTriangle Strip or Fan– QuadrilateralsQuadrilaterals– Quad stripQuad strip– PolygonsPolygons

Page 14: Advanced Programming for 3D Applications  CE00383-3

Vector operationsVector operations

• Vectors can specify location and Vectors can specify location and direction.direction.

• Vectors can be modified by being Vectors can be modified by being multiplied by matrices, using affine multiplied by matrices, using affine transformations (rotation, transformations (rotation, translation, scaling and shear).translation, scaling and shear).

• The steps in our graphics pipeline are The steps in our graphics pipeline are matrix multiplications.matrix multiplications.

Page 15: Advanced Programming for 3D Applications  CE00383-3

3D Primitives3D Primitives

• Collections of vertices that form a single Collections of vertices that form a single 3-D entity3-D entity

• Simplest primitive: collection of points, Simplest primitive: collection of points, or point list.or point list.

• Usually polygons, of which the simplest Usually polygons, of which the simplest is a triangle.is a triangle.

•All three vertices in a triangle are All three vertices in a triangle are guaranteed to be coplanar. Rendering guaranteed to be coplanar. Rendering nonplanar vertices is inefficient. You can nonplanar vertices is inefficient. You can combine triangles to form complex combine triangles to form complex polygons and meshes.polygons and meshes.

Page 16: Advanced Programming for 3D Applications  CE00383-3

3D Primitives3D Primitives

• 3-dimensional shapes can be composed of 3-dimensional shapes can be composed of 2D (coplanar) primitives in space (usually 2D (coplanar) primitives in space (usually triangles).triangles).

• Each triangle (or coplanar polygon) on a Each triangle (or coplanar polygon) on a 3D shape is called a “face”.3D shape is called a “face”.

• Smooth surfaces can be achieved by Smooth surfaces can be achieved by enough primitives and correct use of enough primitives and correct use of shading.shading.

Page 17: Advanced Programming for 3D Applications  CE00383-3

ViewingViewing

• We need to project 3D objects on a 2D We need to project 3D objects on a 2D surface.surface.

• This is done by a series of matrix This is done by a series of matrix multiplications (transforms) in our multiplications (transforms) in our graphics pipeline.graphics pipeline.

• We need to specify what part of the We need to specify what part of the world we want to see. Various camera world we want to see. Various camera operations all affect the “Viewing operations all affect the “Viewing Frustum”Frustum”

Page 18: Advanced Programming for 3D Applications  CE00383-3

The Viewing FrustumThe Viewing Frustum

Page 19: Advanced Programming for 3D Applications  CE00383-3

Normal VectorsNormal Vectors

• Every face has a perpendicular (normal) vector Every face has a perpendicular (normal) vector that defines the front of the face.that defines the front of the face.– The direction depends on the order on which vectors are The direction depends on the order on which vectors are

traversed, CCW for a right-handed system, and CW for a traversed, CCW for a right-handed system, and CW for a left-handed system (like Direct3D)left-handed system (like Direct3D)

Page 20: Advanced Programming for 3D Applications  CE00383-3

Normal VectorsNormal Vectors

• Normal vectors are used for shading, lighting, and Normal vectors are used for shading, lighting, and texturing.texturing.

• Direct3D uses the Direct3D uses the vertexvertex normals (Gouraud normals (Gouraud shading)shading)

Page 21: Advanced Programming for 3D Applications  CE00383-3

The Phong Light ModelThe Phong Light Model

• Light in a real-time 3D system is Light in a real-time 3D system is only a rough approximation of only a rough approximation of reality.reality.

• We have a few light sources that We have a few light sources that interact directly with each surface interact directly with each surface mathematically.mathematically.

• Lights are ambient lights or direct Lights are ambient lights or direct lights (which come in point lights, lights (which come in point lights, directional lights, and spotlights).directional lights, and spotlights).

Page 22: Advanced Programming for 3D Applications  CE00383-3

LightingLighting

• Global Illumination = Ambient Light + Global Illumination = Ambient Light + Diffuse Light + Specular Light + Emissive Diffuse Light + Specular Light + Emissive LightLight

Object ColorObject Color + Ambient + Ambient LightLight+ Diffuse Light+ Diffuse Light Ambient + Ambient + DiffuseDiffuse+ Specular Light+ Specular Light Ambient + Ambient + Diffuse + Diffuse + SpecularSpecular

+ Emissive Light+ Emissive LightGlobalGlobal

Page 23: Advanced Programming for 3D Applications  CE00383-3

MaterialsMaterials

• Materials describe how polygons Materials describe how polygons reflect light or appear to emit light in reflect light or appear to emit light in a 3-D scene. a 3-D scene. – How they reflect ambient and diffuse How they reflect ambient and diffuse

light light – What their specular highlights look like What their specular highlights look like – Whether the polygons appear to emit Whether the polygons appear to emit

light light

Page 24: Advanced Programming for 3D Applications  CE00383-3

Texture MappingTexture Mapping

• Adds a new level of realism by adding Adds a new level of realism by adding bitmaps to your objectsbitmaps to your objects

• Each color element in a texture is called a Each color element in a texture is called a texeltexel, and the last stage of the rendering , and the last stage of the rendering pipeline maps texels directly to pixels.pipeline maps texels directly to pixels.

• Texels rarely correspond to pixels, so Texels rarely correspond to pixels, so texture filtering is used to approximate texture filtering is used to approximate pixel values.pixel values.

Page 25: Advanced Programming for 3D Applications  CE00383-3

Texture FilteringTexture Filtering

• More complex filters give better results More complex filters give better results but take more time:but take more time:– Nearest-point: no filtering, the closest texel Nearest-point: no filtering, the closest texel

is copied.is copied.– Linear filtering: texels around the current Linear filtering: texels around the current

pixels are averaged.pixels are averaged.– Anisotropic filtering: uses pixel elongation to Anisotropic filtering: uses pixel elongation to

map deformations better.map deformations better.– Mipmaps: create smaller versions of your Mipmaps: create smaller versions of your

texture to be used at different resolutions. texture to be used at different resolutions. Can be used in conjunction with the above.Can be used in conjunction with the above.

Page 26: Advanced Programming for 3D Applications  CE00383-3

MeshesMeshes

• Meshes are data structures that hold Meshes are data structures that hold several primitives to create complex several primitives to create complex shapesshapes

• You can associate vertices, faces, You can associate vertices, faces, materials, textures, and more to a meshmaterials, textures, and more to a mesh

• Meshes can be created with a modeling Meshes can be created with a modeling software (like 3D Studio) and then software (like 3D Studio) and then exported to X file format and loadedexported to X file format and loaded

Page 27: Advanced Programming for 3D Applications  CE00383-3

• Models use the most polygons in a typical video gameModels use the most polygons in a typical video game• Method 1: store low, medium and high polygon versions Method 1: store low, medium and high polygon versions

of a model, choose model version depending on the of a model, choose model version depending on the distance the model is from the viewerdistance the model is from the viewer– Used in virtually all modern gamesUsed in virtually all modern games– Models can “pop” when they change levelsModels can “pop” when they change levels

• Method 2: smoothly morph between high polygon and Method 2: smoothly morph between high polygon and low polygon versionslow polygon versions– Progressive MeshesProgressive Meshes

Level of Detail (LOD)

Page 28: Advanced Programming for 3D Applications  CE00383-3

• For action games you need spatial subdivision For action games you need spatial subdivision to quickly figure out what objects are to quickly figure out what objects are interacting with each other and what objects interacting with each other and what objects are visible to the viewerare visible to the viewer

• One of the most important aspects of a video One of the most important aspects of a video game engine is how fast it can operate with game engine is how fast it can operate with huge numbers of polygons and interacting huge numbers of polygons and interacting objectsobjects

• For strategy games the number of objects and For strategy games the number of objects and the camera location may be more restrictedthe camera location may be more restricted– Subdivide world into a 2D gridSubdivide world into a 2D grid

Spatial Subdivision (1/3)

Page 29: Advanced Programming for 3D Applications  CE00383-3

• Typical techniques:Typical techniques:– OctreesOctrees: put a cube around the world, then split that : put a cube around the world, then split that

cube into eight pieces. Recursively split sections that cube into eight pieces. Recursively split sections that have many objects in them have many objects in them

– BSPBSP Trees: pick a plane. Everything on one side of the Trees: pick a plane. Everything on one side of the plane goes in the left node, everything on the right plane goes in the left node, everything on the right goes in the right node, keep splitting nodes that have goes in the right node, keep splitting nodes that have many objects (generalization of the octree)many objects (generalization of the octree)

– PortalsPortals: divide the level into sectors, sectors are : divide the level into sectors, sectors are connected by portals (such as a door)connected by portals (such as a door)

• Potential Viewing Set:Potential Viewing Set:– If all of the level geometry is static then we can solve If all of the level geometry is static then we can solve

the visibility problem when we create the levelthe visibility problem when we create the level– When you compile a level for Quake III it creates a BSP When you compile a level for Quake III it creates a BSP

Tree for the level and then figures out which BSP nodes Tree for the level and then figures out which BSP nodes can see each othercan see each other

Spatial Subdivision (2/3)

Page 30: Advanced Programming for 3D Applications  CE00383-3

• Occlusion Culling:Occlusion Culling:– In new graphics cards you can query the depth buffer to ask In new graphics cards you can query the depth buffer to ask

if an object (or entire BSP node) is completely occludedif an object (or entire BSP node) is completely occluded– Great for scenes such as a forest where many trees combine Great for scenes such as a forest where many trees combine

to occlude objects but no single tree occludes a large areato occlude objects but no single tree occludes a large area– This can be used at run time so there is no need to compile This can be used at run time so there is no need to compile

static geometrystatic geometry– Some hints that this is used in Doom IIISome hints that this is used in Doom III

• General rules of thumb:General rules of thumb:– Most current engines will stop subdividing level geometry Most current engines will stop subdividing level geometry

after there are about 5000 polygons in one leaf nodeafter there are about 5000 polygons in one leaf node– Spatial subdivision for dynamic models is facilitated by Spatial subdivision for dynamic models is facilitated by

keeping track of a models bounding sphere or bounding boxkeeping track of a models bounding sphere or bounding box– Level geometry is getting to be much less of an issue Level geometry is getting to be much less of an issue

compared to highly tesselated modelscompared to highly tesselated models

Spatial Subdivision (3/3)

Page 31: Advanced Programming for 3D Applications  CE00383-3

• Standard Lighting:Standard Lighting:– Uses the fixed function pipeline that API provides Uses the fixed function pipeline that API provides

by default; light is calculated at vertices and by default; light is calculated at vertices and interpolated across the polygoninterpolated across the polygon

– This only looks decent with highly tesselated This only looks decent with highly tesselated modelsmodels

– Need to do something else for low tesselated Need to do something else for low tesselated modelsmodels

Illumination (1/3)

Page 32: Advanced Programming for 3D Applications  CE00383-3

• Light Maps:Light Maps:– For low tesselated models lighting is done using For low tesselated models lighting is done using

texture maps instead of using vertex-based lightingtexture maps instead of using vertex-based lighting– Coarsely tesselated geometry often includes static Coarsely tesselated geometry often includes static

geometry like walls and floorsgeometry like walls and floors– Quake II uses a radiosity engine to compute light Quake II uses a radiosity engine to compute light

maps when you compile a levelmaps when you compile a level– Light maps are multiplied with base texture (ie a Light maps are multiplied with base texture (ie a

brick texture) to create convincing imagerybrick texture) to create convincing imagery– Only useful with static geometryOnly useful with static geometry

Illumination (2/3)

Page 33: Advanced Programming for 3D Applications  CE00383-3

• Per-Pixel Lighting:Per-Pixel Lighting:– If we compute a lighting calculation per-If we compute a lighting calculation per-

pixel then we don’t need light maps pixel then we don’t need light maps – We can get pixels that are close to the We can get pixels that are close to the

quality of ray tracing by using pixel shaders quality of ray tracing by using pixel shaders – To do the calculations per-pixel we not only To do the calculations per-pixel we not only

need a texture map (diffuse color), but a need a texture map (diffuse color), but a specular map (shininess) and normal map specular map (shininess) and normal map (normals)(normals)

– To calculate these models Doom III uses To calculate these models Doom III uses 1,000,000 polygon models and then 1,000,000 polygon models and then reduces that to a 5,000 polygon model with reduces that to a 5,000 polygon model with texture, specular and normal maptexture, specular and normal map

Illumination (3/3)

Page 34: Advanced Programming for 3D Applications  CE00383-3

• With new hardware shadows can be calculated in With new hardware shadows can be calculated in real-timereal-time

• Shadow MapsShadow Maps– Render scene from lights point of view, then use projective Render scene from lights point of view, then use projective

texture trick to see if the current pixel is seen by the lighttexture trick to see if the current pixel is seen by the light– Can have aliases, used in HaloCan have aliases, used in Halo

Shadows (1/2)

Page 35: Advanced Programming for 3D Applications  CE00383-3

• Stencil ShadowsStencil Shadows– Find silhouette edges for all models and create new Find silhouette edges for all models and create new

geometry that represents the volume shadowed by that geometry that represents the volume shadowed by that model (called shadow volume)model (called shadow volume)

– New geometry can require big fill rateNew geometry can require big fill rate– Used in Halo 2, Doom IIIUsed in Halo 2, Doom III

Shadows (2/2)

Page 36: Advanced Programming for 3D Applications  CE00383-3

• First-person games often have the camera fixed at First-person games often have the camera fixed at the eye pointthe eye point– Games like Metroid Prime switch to third-person in certain Games like Metroid Prime switch to third-person in certain

situationssituations

• Third-person sports games often have a fixed Third-person sports games often have a fixed camera in one position for playing and then let you camera in one position for playing and then let you move the camera around for instant replaysmove the camera around for instant replays

• Third-person action games often have camera follow Third-person action games often have camera follow over the shoulder of your characterover the shoulder of your character– Resident Evil fixes the camera for a given room, creating Resident Evil fixes the camera for a given room, creating

more cinematic camera anglesmore cinematic camera angles– Games like Devil May Cry mix floating camera movement Games like Devil May Cry mix floating camera movement

with more cinematic control by restricting the camera to with more cinematic control by restricting the camera to travel along a dolly in certain areastravel along a dolly in certain areas

Camera Motion

Page 37: Advanced Programming for 3D Applications  CE00383-3

• Strategy games often keep camera fairly high Strategy games often keep camera fairly high above the world looking down at a fixed angleabove the world looking down at a fixed angle– This allows for many visibility simplificationsThis allows for many visibility simplifications

• Camera movement is critical to keeping the Camera movement is critical to keeping the player engrossed in the gameplayer engrossed in the game– Bad camera movement can make a video game Bad camera movement can make a video game

unplayableunplayable

• To smoothly turn between camera orientations To smoothly turn between camera orientations you need to use quaternionsyou need to use quaternions– Quaternions are 4 element vectors that are good for Quaternions are 4 element vectors that are good for

representing rotationsrepresenting rotations– Interpolating between rotation matrices leads to Interpolating between rotation matrices leads to

strange artifacts, including gimbal lockstrange artifacts, including gimbal lock

Camera Motion

Page 38: Advanced Programming for 3D Applications  CE00383-3

• Keyframed animationKeyframed animation– Interpolate between different poses of a model, Interpolate between different poses of a model,

gives exact control to artistsgives exact control to artists– Very fast, but requires a lot of space to store the Very fast, but requires a lot of space to store the

entire model for every frame of an animationentire model for every frame of an animation– Used in Quake IIIUsed in Quake III

Animation

Page 39: Advanced Programming for 3D Applications  CE00383-3

• Skeletal AnimationSkeletal Animation– We store animations for the skeleton of the model, not the We store animations for the skeleton of the model, not the

entire skinentire skin– Each vertex on the “skin” of the model is connected to one or Each vertex on the “skin” of the model is connected to one or

more bonesmore bones– Difficult to get to look just right as some animations will make Difficult to get to look just right as some animations will make

certain patches of skin (like elbows) pop out at weird anglescertain patches of skin (like elbows) pop out at weird angles– Consumes much less memory, especially for highly Consumes much less memory, especially for highly

tesselated modelstesselated models– Easier to do next-generation kinematic effectsEasier to do next-generation kinematic effects

• Allow models to “balance”Allow models to “balance”• Allow models to react “correctly” to physical impulsesAllow models to react “correctly” to physical impulses

– Used in Doom IIIUsed in Doom III

Animation

Page 40: Advanced Programming for 3D Applications  CE00383-3

• Smoke, Fire:Smoke, Fire:– After the world is rendered a flat quad polygon is drawn, After the world is rendered a flat quad polygon is drawn,

centered around the fire or smoke and facing towards the centered around the fire or smoke and facing towards the eye pointeye point

– Polygons that always face the viewer are called billboardsPolygons that always face the viewer are called billboards– The quad is textured using an appropriate animated The quad is textured using an appropriate animated

texture that has a transparent backgroundtexture that has a transparent background

• Bullet Holes:Bullet Holes:– Small billboards drawn on top of static geometrySmall billboards drawn on top of static geometry– Be careful that your bullet holes do not stick out past the Be careful that your bullet holes do not stick out past the

side of the wall (tricky)side of the wall (tricky)

• Sparks:Sparks:– Uses a particle system, useful for many small objects that Uses a particle system, useful for many small objects that

need to move but don’t need to interact with other need to move but don’t need to interact with other objectsobjects

SFX

Page 41: Advanced Programming for 3D Applications  CE00383-3

• Trail of Smoke:Trail of Smoke:– A combination of the two previous effects: for each A combination of the two previous effects: for each

particle in the particle system render a small smoke particle in the particle system render a small smoke billboardbillboard

• Sky Box:Sky Box:– Gives the impression of an infinitely far away horizon or Gives the impression of an infinitely far away horizon or

skysky– Surprisingly simpleSurprisingly simple

• Draw sky box before any other world geometry:Draw sky box before any other world geometry:• Temporarily set camera at the originTemporarily set camera at the origin• Temporarily disable writing to z-bufferTemporarily disable writing to z-buffer• Draw a textured box around the origin (because the z-buffer Draw a textured box around the origin (because the z-buffer

is disabled it doesn’t really matter what size box you chose)is disabled it doesn’t really matter what size box you chose)– If you have a box around your head you can’t tell how big If you have a box around your head you can’t tell how big

the box is. Since it doesn’t move when the character the box is. Since it doesn’t move when the character translates, it appears infinitely large.translates, it appears infinitely large.

SFX

Page 42: Advanced Programming for 3D Applications  CE00383-3

• Heads Up Display (HUD):Heads Up Display (HUD):– Often drawn using an orthographic projection, Often drawn using an orthographic projection,

often uses transparency to look keenoften uses transparency to look keen

• Light Halos:Light Halos:– If a light (like a street light) is visible draw a If a light (like a street light) is visible draw a

billboard around the light that represents the glow billboard around the light that represents the glow or halo emanating from the light sourceor halo emanating from the light source

SFX

Page 43: Advanced Programming for 3D Applications  CE00383-3

• Usually very hackedUsually very hacked– no neural networks around hereno neural networks around here– many tweaks to get characters to act believably many tweaks to get characters to act believably

according to a host of different variablesaccording to a host of different variables

• Character actions are often a very tenuous Character actions are often a very tenuous balance between scripted events and actual balance between scripted events and actual artificial intelligenceartificial intelligence

• A* path planning algorithm is used to go from A* path planning algorithm is used to go from point A to point B quickly while avoiding obstaclespoint A to point B quickly while avoiding obstacles

• Group behavior (such as flocking) can add realismGroup behavior (such as flocking) can add realism

• Black and White has creatures that learn from Black and White has creatures that learn from you, probably the most sophisticated AI to dateyou, probably the most sophisticated AI to date

AI

Page 44: Advanced Programming for 3D Applications  CE00383-3

• Physics is toughPhysics is tough– Usually very hacky in video games, games often use a Usually very hacky in video games, games often use a

bounding cylinder for the player to see if they hit walls or bounding cylinder for the player to see if they hit walls or floorfloor

– Two problems: detection of physical events (i.e., “the Two problems: detection of physical events (i.e., “the missile hits Tank-NPC”), and appropriate response missile hits Tank-NPC”), and appropriate response (celebrate destruction of irritating boss)(celebrate destruction of irritating boss)

– Exploding buildings or flying barrels are almost always Exploding buildings or flying barrels are almost always scripted eventsscripted events

• Physics Done RightPhysics Done Right– Grand Theft Auto 3Grand Theft Auto 3– Flying cars off of ramps, taking turns at 40 mph, and Flying cars off of ramps, taking turns at 40 mph, and

hitting pedestrians feels just like it does in real lifehitting pedestrians feels just like it does in real life• Physics Done Too Right (aka Wrong)Physics Done Too Right (aka Wrong)

– Tresspasser (1998)Tresspasser (1998)– Physics engine so advanced that you would slip and fall Physics engine so advanced that you would slip and fall

while walking across a room, your weapon would fly out while walking across a room, your weapon would fly out of your hand if you walked next to a doorof your hand if you walked next to a door

– Good physics doesn’t make a good gameGood physics doesn’t make a good game

Physics

Page 45: Advanced Programming for 3D Applications  CE00383-3

• Physics ResearchPhysics Research– rigid body physics right (very rigid body physics right (very

complicated)complicated)– Timewarp rigid body physics (even more Timewarp rigid body physics (even more

complicated but faster to calculate)complicated but faster to calculate)– Plausible Animation (how things often Plausible Animation (how things often

look more real if they differ slightly from look more real if they differ slightly from the exact solution)the exact solution)

Physics

Page 46: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

Metroid PrimeMetroid Prime

• Heads Up Display (including 3D Map in the upper Heads Up Display (including 3D Map in the upper right)right)

• Standard first person view (hence the genre of first Standard first person view (hence the genre of first person shooters)person shooters)

Page 47: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

Metroid PrimeMetroid Prime

• Metroid Prime transitions to third person Metroid Prime transitions to third person view in some scenarios (even has strange view in some scenarios (even has strange 2D point of view for some puzzle areas)2D point of view for some puzzle areas)

Page 48: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• Cinematic point of viewCinematic point of view

• The light maps (such as the light coming from the The light maps (such as the light coming from the window on the floor) will turn off and on depending on window on the floor) will turn off and on depending on lightninglightning

Resident EvilResident Evil

Page 49: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

Quake IIIQuake III

• This shows the extensive use of light maps; shadows This shows the extensive use of light maps; shadows are computed when compiling the level’s static are computed when compiling the level’s static geometrygeometry– players that walk over shadows on the floor are not shadowedplayers that walk over shadows on the floor are not shadowed

Page 50: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

HaloHalo

• Billboard used for laser beamBillboard used for laser beam

• Billboard used for gun muzzle flashBillboard used for gun muzzle flash

• Particle system used for laser sparksParticle system used for laser sparks

Page 51: Advanced Programming for 3D Applications  CE00383-3

• Sky box in backgroundSky box in background

Examples in Games

HaloHalo

Page 52: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• Particle System for dirt chunks and smokeParticle System for dirt chunks and smoke

• Rigid Body Simulation for the spinning jeepRigid Body Simulation for the spinning jeep

• Sky Box in backgroundSky Box in background

• Lens Flare from sunLens Flare from sun

• Halos from the lights on the windshieldHalos from the lights on the windshield

• Shadow on ground (using shadow map)Shadow on ground (using shadow map)

HaloHalo

Page 53: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• Halos around street lights (billboards)Halos around street lights (billboards)Grand Theft Auto 3Grand Theft Auto 3

Page 54: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• Specular map gives red flesh that nice Specular map gives red flesh that nice glossy lookglossy look

Doom IIIDoom III

Page 55: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• Environment map on gogglesEnvironment map on goggles– ??? seems pretty expensive??? seems pretty expensive

• Fine detail on helmet shows normal maps (normal Fine detail on helmet shows normal maps (normal maps serve the same purpose as bump maps)maps serve the same purpose as bump maps)

Doom IIIDoom III

Page 56: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• The soft shadow grill effect is projectively textured The soft shadow grill effect is projectively textured onto the roomonto the room

• The shadows cast by the monster are different (notice The shadows cast by the monster are different (notice how they are sharp: Doom III uses stencil shadows)how they are sharp: Doom III uses stencil shadows)

Doom IIIDoom III

Page 57: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• ??? (glowing around elbow)??? (glowing around elbow)

• Possibly a combination of many small light Possibly a combination of many small light haloshalos

Tron 2.0Tron 2.0

Page 58: Advanced Programming for 3D Applications  CE00383-3

Examples in Games

• ??? (light bleeding around leg and arm)??? (light bleeding around leg and arm)

• Interaction of the light in the background with the Interaction of the light in the background with the foreground cannot be done easily in vertex/pixel foreground cannot be done easily in vertex/pixel shader, seems to be some type of post-processing shader, seems to be some type of post-processing effecteffect

Halo 2Halo 2

Page 59: Advanced Programming for 3D Applications  CE00383-3

ConclusionConclusion

• We have quickly overviewed all the We have quickly overviewed all the basic techniques for 3D graphics in basic techniques for 3D graphics in any system.any system.

• Use the SPS2 tutorials and Use the SPS2 tutorials and documentation to familiarize yourself documentation to familiarize yourself with the API used on the Playstation.with the API used on the Playstation.