Simulation Engines TDA571|DIT030 3D Graphics - Part 2 Tommaso - - PowerPoint PPT Presentation

simulation engines tda571 dit030 3d graphics part 2
SMART_READER_LITE
LIVE PREVIEW

Simulation Engines TDA571|DIT030 3D Graphics - Part 2 Tommaso - - PowerPoint PPT Presentation

Simulation Engines TDA571|DIT030 3D Graphics - Part 2 Tommaso Piazza 1 Administrative stuff Today 3D Graphics presentation Meet me in front of Grace Hopper Have you started coding? Where are your repositories? Pssst...


slide-1
SLIDE 1

Simulation Engines TDA571|DIT030 3D Graphics - Part 2

Tommaso Piazza

1

slide-2
SLIDE 2

IDC | Interaction Design Collegium

Administrative stuff

  • Today 3D Graphics presentation
  • Meet me in front of Grace Hopper
  • Have you started coding?
  • Where are your repositories?

Pssst... Wikipedia is accepting donations. Wikipedia is a nonprofit project that exists for one reason: the free and open sharing of knowledge. Your donations keep Wikipedia going.

2

slide-3
SLIDE 3

IDC | Interaction Design Collegium

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

3

slide-4
SLIDE 4

IDC | Interaction Design Collegium

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

4

slide-5
SLIDE 5

IDC | Interaction Design Collegium

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

5

slide-6
SLIDE 6

IDC | Interaction Design Collegium

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

6

slide-7
SLIDE 7

IDC | Interaction Design Collegium

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

7

slide-8
SLIDE 8

IDC | Interaction Design Collegium

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 the important one

8

slide-9
SLIDE 9

IDC | Interaction Design Collegium

Shader types

  • Vertex shader
  • Called for every vertex in a 3D primitive (modifies color, lightning, position...)
  • Allows for effects such as hardware skinning, perturbation of water surface, etc
  • http://www.youtube.com/watch?v=QHXjhfxAns0
  • 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
  • http://www.youtube.com/watch?v=91gjSmfSIgw
  • 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
  • http://www.youtube.com/watch?v=IRzAxtBWtV8
  • Unified Shader Model in DirectX 10 (Shader Model 4.0)

9

slide-10
SLIDE 10

IDC | Interaction Design Collegium

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

10

slide-11
SLIDE 11

IDC | Interaction Design Collegium

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

  • Can also be used for advanced lighting

11

slide-12
SLIDE 12

IDC | Interaction Design Collegium

Reflective surfaces: Cube maps

  • Cubic environment maps
  • Cube map consisting of six

textures unfolded on to a cube

  • The most used format on

modern hardware

  • The texture coordinate is a

vector that specifies which way to look from the center

  • f the cube mapped cube to

get the desired texel

http://en.wikipedia.org/wiki/File:Panorama_cube_map.png 12

slide-13
SLIDE 13

IDC | Interaction Design Collegium

Particle systems

  • One of the most useful tools available
  • Smoke, water, fire, etc
  • http://www.youtube.com/watch?v=nmd6hIjgexs
  • 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

13

slide-14
SLIDE 14

IDC | Interaction Design Collegium

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

14

slide-15
SLIDE 15

IDC | Interaction Design Collegium

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

15

slide-16
SLIDE 16

IDC | Interaction Design Collegium

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

  • r particles
  • Nowadays, often actual models are

used which is moved by the physics engine

16

slide-17
SLIDE 17

IDC | Interaction Design Collegium

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

17

slide-18
SLIDE 18

IDC | Interaction Design Collegium

Stencil shadows (shadows as volumes)

  • 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

18

slide-19
SLIDE 19

IDC | Interaction Design Collegium

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

19

slide-20
SLIDE 20

IDC | Interaction Design Collegium

Shadow maps

  • Texture based shadows
  • Renders the scene from the light's point
  • f 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

20

slide-21
SLIDE 21

IDC | Interaction Design Collegium

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

21

slide-22
SLIDE 22

IDC | Interaction Design Collegium

Textures

  • Texture coordinates (U,V)
  • Unfolds the model
  • Paint directly on the

model with software such as BodyPaint, Zbrush, etc

  • Texturespace/

Tangentspace can be interesting for advanced effects such as Normal mapping

22

slide-23
SLIDE 23

IDC | Interaction Design Collegium

Displacement mapping

  • Commonly used technique in

raytracers

  • Not possible on DirectX 9

hardware

  • Can not move vertexes that do

not exist

  • Can be hacked for certain uses

by doing texture lookups in the vertex shader

  • Possible for real on DirectX 10

hardware

  • Geometry shaders allow tessellation of
  • bjects without CPU intervention

23

slide-24
SLIDE 24

IDC | Interaction Design Collegium

Normal maps

  • High-poly surfaces are transferred to

models by storing normals in textures

  • Normals are normally stored in tangent space
  • Can produce extremely good results with

fairly low computational costs

  • Works well on most types
  • f objects lit with dynamic

lights

  • Often, tools like Zbrush

are used to create high-poly objects, but normal maps can also be created from heightmaps

24

slide-25
SLIDE 25

IDC | Interaction Design Collegium

Parallax mapping

  • Also know as offset mapping

as it offsets the texture coordinates

  • Very cheap and fairly

convincing on flat surfaces

  • High quality versions requires

iterative process, which is more expensive, but produce extremely good results (where applicable)

25

slide-26
SLIDE 26

IDC | Interaction Design Collegium

Cel shading

  • Non photo-realistic technique
  • Can be done either by drawing multiple passes
  • r in a shader by examining the scalar product
  • f the normal and view direction
  • Check the sample in the Ogre SDK

26

slide-27
SLIDE 27

IDC | Interaction Design Collegium

High Dynamic Range rendering

  • Often done by cheating
  • Can be done for real on Shader Model 3.0

hardware

  • Render to a target with higher precision than can be

drawn

  • Then scale the values in a second pass to simulate

different levels of exposure

27

slide-28
SLIDE 28

IDC | Interaction Design Collegium

PRT

  • Precomputed radiance transfer can be used to simulate

soft shadows, interreflections and subsurface scattering

  • Uses spherical harmonics to

encode and approximate the light transfer function

  • Decoded in a programmable

shader

  • Only works on low frequency effects

with a reasonable number of parameters

  • Lights can move, but objects can not

move relative to each other

  • Check the DirectX SDK

28

slide-29
SLIDE 29

IDC | Interaction Design Collegium

Post processing

  • Generally done by first rendering the scene

to a texture and then applying that texture to a full-screen quad which is drawn with a pixel shader applied to it

  • Multiple post-processing effects can be

combined either in sequence or by blending between them

29

slide-30
SLIDE 30

IDC | Interaction Design Collegium

Bloom

  • Can be done best when combined with HDR

rendering

  • In essence: apply gaussian blur on areas with

intense light

  • A cheap substitute for

actual blur is to downsample the image a few times and then combining the original image with the downsampled versions

30

slide-31
SLIDE 31

IDC | Interaction Design Collegium

Depth of Field

  • DOF is extremely important in real world photography

and film

  • The modern approach (Thorsten Sheuermann, 2004)
  • Downsample and pre-blur

the image

  • Use variable size filter

kernel to approximate circle of confusion

  • Blend between original

and pre-blurred image for better image quality

  • Take measures to prevent

“leaking” sharp foreground into blurry background

31

slide-32
SLIDE 32

IDC | Interaction Design Collegium

Motion blur

  • The lack of motion blur is mostly why

25-30fps in a game seems stuttering but works with film

  • The simplest form of motion blur is

done by using the accumulation buffer and combining previous frames with the current

  • Does not work well without very

high framerates

  • When used on meshes directly, a vertex shader stretches some

vertices along the direction of motion and fades their transparency

  • Can be done in post processing by first drawing the scene to a

velocity buffer which determines how much to blur the scene in the post processing pass

32

slide-33
SLIDE 33

IDC | Interaction Design Collegium

Materials in Ogre

material Material/SOLID/TEX/sandstone.jpg { technique { pass { diffuse 0.8 0.8 0.8 specular 0.5 0.5 0.5 12.5 texture_unit { texture sandstone.jpg } } } }

33

slide-34
SLIDE 34

IDC | Interaction Design Collegium

Post processing in Ogre

  • There are plenty of pre-defined post

processing effects

  • Compositor allows for easy access to the

effects

  • Use compositor scripts to add effects or

combine multiple effects

  • Check the Ogre SDK for demos

34

slide-35
SLIDE 35

IDC | Interaction Design Collegium

Shadows in Ogre

  • Extremely easy
  • mSceneMgr->setShadowTechnique(“techniquename”);
  • Stencil shadows
  • SHADOWTYPE_STENCIL_MODULATIVE
  • SHADOWTYPE_STENCIL_ADDITIVE
  • Shadow maps
  • SHADOWTYPE_TEXTURE_MODULATIVE
  • SHADOWTYPE_TEXTURE_ADDITIVE
  • There are also more advanced methods
  • Check the example in the SDK

35

slide-36
SLIDE 36

IDC | Interaction Design Collegium

All together

36