3d graphics 2
play

3D Graphics 2 Simulation Engines 2008 Chalmers University of - PowerPoint PPT Presentation

3D Graphics 2 Simulation Engines 2008 Chalmers University of Technology Markus Larsson markus.larsson@slxgames.com 08-11-19 Simulation Engines 2008, Markus Larsson 1 Camera management Three basic kinds of cameras in games


  1. 3D Graphics 2 Simulation Engines 2008 Chalmers University of Technology Markus Larsson markus.larsson@slxgames.com 08-11-19 Simulation Engines 2008, Markus Larsson 1

  2. Camera management  Three basic kinds of cameras in games  First-person  Camera attached to the player and inherits the exact motion of the player  Examples: Farcry, Doom, Quake, etc  Scripted  Camera moves along pre-defined paths  Examples: Alone in the dark, Resident Evil  Third person  The camera is located outside the body of the player and shows both the avatar and the environment  Examples: Super Mario 64, Gears of War 08-11-19 Simulation Engines 2008, Markus Larsson 2

  3. Third-person camera: Constraints The camera should never be closer to a wall than the near plane  It should never go outside a level  It should translate and rotate smoothly to always try to stay at a specific  point in relation to the player character It should smooth out discontinuities in the character's movement  It should be tested for collision detection  It should be able to enter the character when needed  08-11-19 Simulation Engines 2008, Markus Larsson 3

  4. Third-person camera: Algorithm Calculate the destination point for the camera from the character's position  The destination point is calculated by applying a displacement and  rotation from the position of the player character. Different camera views can have different displacements, and it may be possible to switch between them. Check the validity of the destination point (it could be on the wrong side of a  wall) Perform a ray intersect between character and destination point (there  should be no intersection with the world geometry) If the point is invalid, move the camera back towards the character so  that it is positioned on the correct side of the wall Calculate approximate translation and rotation motion and animate it over a  series of frames (animation speed is a tweakable constant) Check for collision using the bounding box of the camera during the  motion 08-11-19 Simulation Engines 2008, Markus Larsson 4

  5. Shaders and shader languages  1990s  Development of hardware for rendering of textured 3D primitives  Hardware T&L introduced  Dynamic lighting done using Gouraud shading  2000s  Per-pixel shading  Real-time procedural textures  Advanced texture mapping techniques 08-11-19 Simulation Engines 2008, Markus Larsson 5

  6. In pursuit of realism  Traditionally, research on realistic computer graphics has focused on global illumination methods such as ray tracing and radiosity  Do not work in real time  Pixar introduced the concept of shaders in RenderMan and showed that GI is not strictly necessary for realistic images  Instead, shader-based methods based on local reflections can be used 08-11-19 Simulation Engines 2008, Markus Larsson 6

  7. What is a shader?  Three different interpretations from Watt & Policarpo, 2003  C-style module in the RenderMan API used for high- level control of rendering components (surface, volume and light shaders)  A combination of render states and texture maps for a multi-pass or multi-texture render of an object on fixed- pipeline GPUs  New hardware functionality for controlling the rendering of primitives on a per-pixel or per-vertex level on programmable-pipeline GPUs; these are called pixel shaders and vertex shaders, respectively  The last one is important one 08-11-19 Simulation Engines 2008, Markus Larsson 7

  8. Shader types Vertex shader  Called for every vertex in a 3D primitive  Allows for effects such as hardware skinning, perturbation of water  surface, etc Pixel (fragment) shader  Called once for every fragment in a 3D primitive (not pixel, because a  fragment in a 3D primitive could correspond to one or several pixels depending on filtering settings, etc) Can be used for procedural texture, normal maps, etc  Geometry shader  Can add to and remove vertices from a mesh and be used for adding  geometry too costly to process on the CPU Allows displacement mapping, etc  Unified Shader Model in DirectX 10 (Shader Model 4.0)  08-11-19 Simulation Engines 2008, Markus Larsson 8

  9. Shader languages  OpenGL Shading Language (GLSL)  Part of the OpenGL specification since OpenGL 1.4  High-level language similar to C/C++  Cg (C for Graphics)  Nvidia's proprietary shader language  Extremely similar to HLSL, but works on both OpenGL and DirectX  Microsoft HLSL  Works on DirectX 9 and 10  Nvidia and Microsoft collaborated on its development 08-11-19 Simulation Engines 2008, Markus Larsson 9

  10. Reflective surfaces: Environment maps  Commonly used for reflections  Precomputed textures  Standard environment maps  Single texture representing the scene in one texture as if reflected from a steel ball  Cubic environment maps  Cube map consisting of six textures unfolded on to a cube  The most used format on modern hardware  Can also be used for advanced lighting 08-11-19 Simulation Engines 2008, Markus Larsson 10

  11. Particle systems  One of the most useful tools available  Smoke, water, fire, etc  Each individual particle has a small or zero geometrical extent, but together form cloud-like objects  Each particle system can contain thousands or even tens of thousands of particles  Be extremely cautious of multiple render states 08-11-19 Simulation Engines 2008, Markus Larsson 11

  12. Particle systems Consists of one or several emitters and a number of particles  Each emitter is responsible for spawning new particles every  time update according to some distribution Each particle contains information about its current position,  size, velocity, shape and lifetime Each update   Emitters generate new particles  New particles are assigned initial attributes  All new particles are injected into the particle system  Any particles that have exceeded their lifetime are extinguished (and usually recycled)  The current particles are updated according to their scripts  The current particles are rendered 08-11-19 Simulation Engines 2008, Markus Larsson 12

  13. Water Ideally based on fluid simulations   Way to costly for real-time use Mostly represented by a simple  plane/quad  In more advanced scenarios represented by a displaced grid Reflections are either entirely faked or by using a planar mirror   The scene is inverted and the reflection is rendered to a texture which is then rendered using projective texturing onto the water mesh 08-11-19 Simulation Engines 2008, Markus Larsson 13

  14. Explosions There is no universal method  Usually a combination of effects are used in combination until it  “looks good” Often animated billboards of prerecorded explosions are  combined with debris that is either actual geometry or particles Nowadays, often actual models are used which is moved by the  physics engine 08-11-19 Simulation Engines 2008, Markus Larsson 14

  15. Lightmaps  Precomputed lighting and shadows on static geometry in the scene  Advantages  Allows for baking advanced lighting such as radiosity  Extremely fast  Disadvantages  Only works on static geometry  Requires a lot of pre- computing for good quality  May require a lot of memory 08-11-19 Simulation Engines 2008, Markus Larsson 15

  16. Stencil shadows Used with dynamic shadows  Uses the stencil buffer  Advantages   Creates crisp shadows without aliasing artifacts  Stable and potentially very fast algorithm Disadvantages   Difficult to get soft shadows (but possible)  Extruding the shadow volumes on hardware is cumbersome and requires modifications to the meshes  Requires multiple render passes  Patent problems with Carmack's reverse 08-11-19 Simulation Engines 2008, Markus Larsson 16

  17. Stencil shadows Empty the stencil buffer  Draw the whole scene with ambient lighting   The z-buffer is filled and the color buffer is filled with the color of surfaces in shadow Turn off updates to the z-buffer and color buffer and draw the  front-facing polygons of the shadow volumes  Increments the stencil buffer; all pixels in or behind shadow volumes receive a positive value Repeat for back-facing polygons   Decrement the stencil buffer; the values in the stencil buffer will decrease where we leave the shadow volumes Draw the diffuse and specular materials in the scene where the  value of the stencil buffer is zero 08-11-19 Simulation Engines 2008, Markus Larsson 17

  18. Shadow maps Texture based shadows  Renders the scene from the light's point of view  For each fragment, checks if it is the the closest  one to the light Advantages  Can be done almost entirely on the GPU  Works very similar to drawing the scene  regularly and allows reuse of frustum check code, etc Good candidate for soft shadow algorithms  Disadvantages  Precision problems and aliasing artifacts  Good for directional and spot lights but omni  lights may require up to six individual textures per light 08-11-19 Simulation Engines 2008, Markus Larsson 18

  19. Soft shadows  There are lots of techniques, but usually shadow maps with multiple samples per texel are used  Often extremely expensive to compute  “Free” in lightmaps 08-11-19 Simulation Engines 2008, Markus Larsson 19

Recommend


More recommend