67535 Computer Games Programming Week 7 Light and

  • Slides: 30
Download presentation
67535: Computer Games Programming • Week 7: Light and Shadows – Motion blur –

67535: Computer Games Programming • Week 7: Light and Shadows – Motion blur – Deferred shading – Shadows – Exercise 4

Motion blur http: //http. developer. nvidia. com/GPUGems 3/gpugems 3_ch 27. html

Motion blur http: //http. developer. nvidia. com/GPUGems 3/gpugems 3_ch 27. html

Motion-Blur: Idea Smearing object in the direction of movement is a strong hint of

Motion-Blur: Idea Smearing object in the direction of movement is a strong hint of fast movement Easier for camera movement than for object movement

Camera Motion Blur: howto 1. Use depth as texture in fragment postprocessing stage 2.

Camera Motion Blur: howto 1. Use depth as texture in fragment postprocessing stage 2. Calculate velocity vector for each fragment – Transform current UV+Z to world coordinates using current frame VP matrix Calculate previous frame's UV+Z using previous frame's VP matrix 3. Sample colours along that vector

Object Motion Blur: howto Pass 1: Store velocity vector (in UVZ) for each fragment

Object Motion Blur: howto Pass 1: Store velocity vector (in UVZ) for each fragment in a separate buffer Use current and previous frame WVP per object Calculate velocity vector per vertex Trust rasterization Pass 2: sample colours along velocity vector

Deferred shading and deferred lighting http: //www. realtimerendering. com/blog/deferred-lighting-approaches/ http: //www. insomniacgames. com/tech/articles/0209/files/prelighting. pdf

Deferred shading and deferred lighting http: //www. realtimerendering. com/blog/deferred-lighting-approaches/ http: //www. insomniacgames. com/tech/articles/0209/files/prelighting. pdf

Deferred shading Idea: Calculate lighting only for visible fragments – Defer light calculations to

Deferred shading Idea: Calculate lighting only for visible fragments – Defer light calculations to the fragment shader stage – Each lightsource effect is calculated only for the fragments it affects – good for many weak lights O(n. Vertices)+O(n. Lights), not O(n. Lights*n. Vertices)

Deferred Lighting: howto 1. Render ambient lighting 2. For every fragment, calculate: normal vector,

Deferred Lighting: howto 1. Render ambient lighting 2. For every fragment, calculate: normal vector, diffuse color, specular color, and specular spread factor; keep those is a separate G-buffer • That won’t fit into one buffer; requires MRT (multiple rendering target) capabilities 3. Render light-sources using G-buffer as a texture • Most lightsources have a finite area of effect – render that as an object • Whole-screen quad for infinite AOE lights • Calculate light in UV+Z coordinates using depth buffer • Use alpha-blending to combine contributions of different light sources to a fragment

Stages in deferred shading (Shadows added separately)

Stages in deferred shading (Shadows added separately)

Problem I: memory requirements Deferred shading requires lots of data to be stored from

Problem I: memory requirements Deferred shading requires lots of data to be stored from a single pass; does not fit into a single buffer Solution 1: MRT Solution 2: (Deferred Lighting) separate lighting calculations into sequential stages so each stage can fit into one buffer and can run in a rendering pass

Deferred Lighting 1. Render objects, storing depth, normal vector and specular spread factor per

Deferred Lighting 1. Render objects, storing depth, normal vector and specular spread factor per fragment • Focus on shape, not material (except for shininess) 2. Render lights, accumulating light contribution per fragment in 3 D • Diffuse and specular component are stored separately 3. Render objects, modulating accumulated light with material properties

Problem: antialiasing in deferred shading http: //visual-computing. intel-research. net/publications/papers/2009/mlaa. pdf Anti-aliasing deferred buffers is

Problem: antialiasing in deferred shading http: //visual-computing. intel-research. net/publications/papers/2009/mlaa. pdf Anti-aliasing deferred buffers is wrong Multi-sampling final buffer does not work Solution: blurring only the problematic bits: L-edges Identify local L-edges and blur them accurately

Shadows How important are they really? http: //www. sandlotscience. com/Distortions/Ball_and_Shadow. htm

Shadows How important are they really? http: //www. sandlotscience. com/Distortions/Ball_and_Shadow. htm

Simple approach: planar shadows Shadow of an object on a plane= object as seen

Simple approach: planar shadows Shadow of an object on a plane= object as seen from the POV of light source Shadow is a transform Depends on light and plane Can be represented as a matrix

Planar shadows Plane given as norm and distance from origin Light source given as

Planar shadows Plane given as norm and distance from origin Light source given as position in homogenous coords Infinity for directional lights Finite for point lights Shadow matrix S ‘flattens’ object onto plane View * S : transforms from object in world coords to object’s shadow as seen by camera

Planar shadow: problems Does not work on curved surfaces Gets complicated very quickly -

Planar shadow: problems Does not work on curved surfaces Gets complicated very quickly - more than one object in way of light, - more than one light source - more than one plane

Shadow mapping “Be the light, and thou shalt see no shadow” -MS 1. Render

Shadow mapping “Be the light, and thou shalt see no shadow” -MS 1. Render the scene from the light POV; 2. keep z-buffer as a texture 3. calculate position in light space (per vertex) 4. interpolate 4. test z in light space (per fragment) If z > texture: shadow If z == texture: light

Shadow mapping example

Shadow mapping example

Problem: hard shadows Approximate soft shadows, e. g. using auxiliary Smoothie objects http: //people.

Problem: hard shadows Approximate soft shadows, e. g. using auxiliary Smoothie objects http: //people. csail. mit. edu/ericchan/papers/smoothie. pdf

Problem: jagged shadow Discrete shadow map, jagged square edges for shadows Solution: Cascaded Shadow

Problem: jagged shadow Discrete shadow map, jagged square edges for shadows Solution: Cascaded Shadow Maps (CSM) etc. http: //developer. download. nvidia. com/SDK/10. 5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps. pdf http: //http. developer. nvidia. com/GPUGems 3/gpugems 3_ch 10. html

Shadow volume http: //http. developer. nvidia. com/GPUGems 3/gpugems 3_ch 11. html A geometry describing

Shadow volume http: //http. developer. nvidia. com/GPUGems 3/gpugems 3_ch 11. html A geometry describing what is in shadow and what is in the light used in Doom 3 Images from http: //www. gamedev. net/reference/articles/article 1873. asp

Creating shadow volume Find silhouette from POV of light source Silhouette is a set

Creating shadow volume Find silhouette from POV of light source Silhouette is a set of edges that connect triangles with normals in opposing directions relative to the light Extend to infinity Add front cap

Filling shadow buffer Render scene in ambient light (for depth buffer) Render shadow volume

Filling shadow buffer Render scene in ambient light (for depth buffer) Render shadow volume to stencil buffer Increase/decrease value when in/out of shadow

Rendering lit areas Use stencil buffer (0 where no shadow) Render lit objects https:

Rendering lit areas Use stencil buffer (0 where no shadow) Render lit objects https: //www. youtube. com/watch? v=yt 2 y. CYKPBuw

Problem 1 Shadow volume clipped by far-plane Solution: infinitely far placed polygons using homogenous

Problem 1 Shadow volume clipped by far-plane Solution: infinitely far placed polygons using homogenous coordinates

Problem 2 Eye in shadow Note: Eye position does not affect where the shadows

Problem 2 Eye in shadow Note: Eye position does not affect where the shadows are Solution: count from infinity to fragment, not from eye (Carmack reverse aka z-fail)

Problem 3 Hard vs. soft shadows No good solution. Can be approximated by clustered

Problem 3 Hard vs. soft shadows No good solution. Can be approximated by clustered lights

Exercise 4: Use the Force Add sphere physics (no rotation) to Exercise 3: spherical

Exercise 4: Use the Force Add sphere physics (no rotation) to Exercise 3: spherical asteroids hit a spherical shield around ship, throwing it off course. Asteroids have random mass and size Add thrust to ship: WASD rotates the ship, SPACE applies thrust in current ship direction. Add collision detection and bouncing collision resolution between asteroids and ship, and asteroids between themselves

Black holes Add at least two black holes and one beacon at random positions.

Black holes Add at least two black holes and one beacon at random positions. Black holes and beacons don’t move. Black holes apply gravity to asteroids and the ship. On getting too close to a black hole, asteroids disappear (generate new) and ship is destroyed (game over). To win, ship must get close to a beacon.

Optional: fuel mechanics There is a limited amount of fuel; thrust uses up some,

Optional: fuel mechanics There is a limited amount of fuel; thrust uses up some, collisions use up less, turning uses up even less. No fuel = game over Optional: add fuel recharge barrels Optional: fuel has mass, full tank is 80% of ship’s mass