41
FREESTYLE PROJECT – GRAPHICS PROGRAMMING LAB – CHAIR OF COMPUTER GRAPHICS – WINTER TERM 2013 / 2014 Deferred Shading & Screen Space Effects State of the Art Rendering Techniques used in the 3D Games Industry Sebastian Lehmann | 11. Februar 2014 KIT – University of the State of Baden-Wuerttemberg and National Laboratory of the Helmholtz Association www.kit.edu

Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

  • Upload
    others

  • View
    19

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

FREESTYLE PROJECT – GRAPHICS PROGRAMMING LAB – CHAIR OF COMPUTER GRAPHICS – WINTER TERM 2013 / 2014

Deferred Shading & Screen Space EffectsState of the Art Rendering Techniques used in the 3D Games IndustrySebastian Lehmann | 11. Februar 2014

KIT – University of the State of Baden-Wuerttemberg and

National Laboratory of the Helmholtz Association

www.kit.edu

Page 2: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Rendering a Complex Scene

Render time depends on:

Number of objects N (scene complexity)

Number of lights L

Number of screen fragments R (resolution)

Trend: increasing!

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 2/23

Page 3: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Rendering a Complex Scene

Render time depends on:

Number of objects N (scene complexity)

Number of lights L

Number of screen fragments R (resolution)

Trend: increasing!

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 2/23

Page 4: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Conventional Rendering Method

for each objectfor each fragment

for each lightcompute lighting

⇒ requires time O(N · L · R)Not reasonable in modern games

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 3/23

Page 5: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Conventional Rendering Method

for each objectfor each fragment

for each lightcompute lighting

⇒ requires time O(N · L · R)Not reasonable in modern games

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 3/23

Page 6: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Deferred Shading: Two Passes

for each objectfor each fragment

store surface material properties in offscreen buffer

for each lightfor each fragment

fetch surface material properties from offscreen buffercompute lightingadd to screen color

⇒ requires time O((N + L) · R)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 4/23

Page 7: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Deferred Shading: Two Passes

for each objectfor each fragment

store surface material properties in offscreen buffer

for each lightfor each fragment

fetch surface material properties from offscreen buffercompute lightingadd to screen color

⇒ requires time O((N + L) · R)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 4/23

Page 8: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Motivation

Deferred Shading: Two Passes

for each objectfor each fragment

store surface material properties in offscreen buffer

for each lightfor each fragment

fetch surface material properties from offscreen buffercompute lightingadd to screen color

⇒ requires time O((N + L) · R)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 4/23

Page 9: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Rendering Pipeline

(Conventional method for comparison)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 5/23

Page 10: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 5/23

Page 11: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Demo

Demo

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 6/23

Page 12: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Translucent Objects

Problem: Translucent objects

User sees multiple objects at same pixel

Need to evaluate lighting model multiple times

G-Buffer can’t store this information

Solution: Render them separately

Two methods:

Multiple Layers: render each layer with Deferred Shading(Complex and costly)

Forward Shading: render these objects using conventional method(But restrict the set of lights!) My choice

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 7/23

Page 13: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Translucent Objects

Problem: Translucent objects

User sees multiple objects at same pixel

Need to evaluate lighting model multiple times

G-Buffer can’t store this information

Solution: Render them separately

Two methods:

Multiple Layers: render each layer with Deferred Shading(Complex and costly)

Forward Shading: render these objects using conventional method(But restrict the set of lights!) My choice

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 7/23

Page 14: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 8/23

Page 15: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 8/23

Page 16: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Deferred Shading – Demo

Demo

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 9/23

Page 17: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – Motivation

Ambient Illumination

Indirect light (“bounce”) also illuminates the scene

Usually: Add constant illumination (∼ 5. . . 10 %) everywhere(But unrealistic ⇒ need to reduce at occluded points)

Ambient Occlusion

Do not add the same global illumination everywhere(Have another factor influencing global illumination)

Compute factor depending on local environment(“How much light can reach this point?”)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 10/23

Page 18: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – Motivation

Ambient Illumination

Indirect light (“bounce”) also illuminates the scene

Usually: Add constant illumination (∼ 5. . . 10 %) everywhere(But unrealistic ⇒ need to reduce at occluded points)

Ambient Occlusion

Do not add the same global illumination everywhere(Have another factor influencing global illumination)

Compute factor depending on local environment(“How much light can reach this point?”)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 10/23

Page 19: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – Example

Starcraft 2

Ambient Occlusion Disabled Ambient Occlusion Enabled

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 11/23

Page 20: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – Techniques

Per-Object Ambient Occlusion

Precompute occlusion map (texture) per object(Assumes static object mesh)

Cheap technique

But no inter-object ambient occlusion, bad for highly dynamic scenes(But for some games almost perfect, e.g. RTS)

Screen-Space Ambient Occlusion (SSAO)

Approximate “reachability” per pixel using rendered image

Used in almost all modern games(or variations of SSAO)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 12/23

Page 21: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – Techniques

Per-Object Ambient Occlusion

Precompute occlusion map (texture) per object(Assumes static object mesh)

Cheap technique

But no inter-object ambient occlusion, bad for highly dynamic scenes(But for some games almost perfect, e.g. RTS)

Screen-Space Ambient Occlusion (SSAO)

Approximate “reachability” per pixel using rendered image

Used in almost all modern games(or variations of SSAO)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 12/23

Page 22: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO

Idea

For each pixel, cast rays to look for occlusions

The more rays hit objects, the less light comes in

Use depth buffer

Problems

Many rays per pixel are inefficient(Use only few and blur the result, but how?)

Objects in the front: Are they occluding the scene in the back?(Information missing)

What about the screen border?(Information missing)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 13/23

Page 23: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO

Idea

For each pixel, cast rays to look for occlusions

The more rays hit objects, the less light comes in

Use depth buffer

Problems

Many rays per pixel are inefficient(Use only few and blur the result, but how?)

Objects in the front: Are they occluding the scene in the back?(Information missing)

What about the screen border?(Information missing)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 13/23

Page 24: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Generating Rays

How many rays, in which direction?

Rays with random direction within hemisphere (2 to 8 per pixel)

Different set of directions for each pixel(Repeating pattern of size 4x4 to 8x8)

Post-process: blur with filter radius = pattern size(Effectively kills noise almost entirely)

Per ray: only 2 or 3 marching steps are enough, random initial offset

Wait... rand() on the GPU?

Precompute noise texture

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 14/23

Page 25: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Generating Rays

How many rays, in which direction?

Rays with random direction within hemisphere (2 to 8 per pixel)

Different set of directions for each pixel(Repeating pattern of size 4x4 to 8x8)

Post-process: blur with filter radius = pattern size(Effectively kills noise almost entirely)

Per ray: only 2 or 3 marching steps are enough, random initial offset

Wait... rand() on the GPU?

Precompute noise texture

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 14/23

Page 26: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Problems

Objects in the front

They hide the scene behind them

Information missing!

Range check: If ray hits an object too far in the front⇒ ignore ray

Configurable threshold

This Buddah is flying infront of the background:

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 15/23

Page 27: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Problems

Screen border

Information missing!(Unless we rendered into enlarged framebuffer)

Border check: If ray shoots outside screen⇒ ignore ray

Effectively fades out the effect at screen borders(Almost unnoticable)

Blurring might remove details

Don’t blur over edges / stay within same surface

Compare depth and normal at source and target

Known as geometry-aware / bilateral filter

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 16/23

Page 28: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Problems

Screen border

Information missing!(Unless we rendered into enlarged framebuffer)

Border check: If ray shoots outside screen⇒ ignore ray

Effectively fades out the effect at screen borders(Almost unnoticable)

Blurring might remove details

Don’t blur over edges / stay within same surface

Compare depth and normal at source and target

Known as geometry-aware / bilateral filter

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 16/23

Page 29: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 17/23

Page 30: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 17/23

Page 31: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Ambient Occlusion – SSAO – Demo

Demo

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 18/23

Page 32: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local ReflectionsHow can we render (non-recursive) reflections?

Planar mirrors: duplicate scene(Doesn’t scale. OK for single mirror like ocean.)

Single curved reflectors: cube maps(Doesn’t scale either. Cool for cars.)

Complex scene / general: screen space(Scales well, but information missing. Good for short distance (“local”) reflections)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 19/23

Page 33: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in Screen Space

Idea

Again ray casting, now along reflection vector (∼ 8 to 60 steps)

When intersection found⇒ duplicate that color

Non-perfect reflectors: add random jitter to ray direction

Problems, problems, problems . . .

What if (real) intersection is behind occluder or outside screen?(Information missing)

Too large step size: we miss the intersection!(Did we only miss it, or is something in front?)

What if the intersection is a back face (and thus invisible)?(Information missing)

Should we reflect the whole color or only diffuse part?(Remember: specular lighting is view-dependent!)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 20/23

Page 34: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in Screen Space

Idea

Again ray casting, now along reflection vector (∼ 8 to 60 steps)

When intersection found⇒ duplicate that color

Non-perfect reflectors: add random jitter to ray direction

Problems, problems, problems . . .

What if (real) intersection is behind occluder or outside screen?(Information missing)

Too large step size: we miss the intersection!(Did we only miss it, or is something in front?)

What if the intersection is a back face (and thus invisible)?(Information missing)

Should we reflect the whole color or only diffuse part?(Remember: specular lighting is view-dependent!)

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 20/23

Page 35: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in Screen Space

Finding the “best” intersection

Proceed ray casting until we find pixel with lower depth

Cancel ray casting after k steps or when outside of the screen

For each sample which has lower depth and is front face:Remember the sample with smallest depth errorIf depth way too small (configurable tolerance):

Assume there is an occluderOptional: “recover” from small ocluders by counting these cases

Final result is sample with smallest depth error, butfade out effect when error too largefade out effect when almost at screen borderfade out effect when almost a back face

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 21/23

Page 36: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in Screen Space

Finding the “best” intersection

Proceed ray casting until we find pixel with lower depth

Cancel ray casting after k steps or when outside of the screenFor each sample which has lower depth and is front face:

Remember the sample with smallest depth errorIf depth way too small (configurable tolerance):

Assume there is an occluderOptional: “recover” from small ocluders by counting these cases

Final result is sample with smallest depth error, butfade out effect when error too largefade out effect when almost at screen borderfade out effect when almost a back face

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 21/23

Page 37: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in Screen Space

Finding the “best” intersection

Proceed ray casting until we find pixel with lower depth

Cancel ray casting after k steps or when outside of the screenFor each sample which has lower depth and is front face:

Remember the sample with smallest depth errorIf depth way too small (configurable tolerance):

Assume there is an occluderOptional: “recover” from small ocluders by counting these cases

Final result is sample with smallest depth error, butfade out effect when error too largefade out effect when almost at screen borderfade out effect when almost a back face

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 21/23

Page 38: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in SS – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 22/23

Page 39: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in SS – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 22/23

Page 40: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in SS – Rendering Pipeline

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 22/23

Page 41: Deferred Shading & Screen Space Effects - Entropia...Deferred Shading – Motivation Rendering a Complex Scene Render time depends on: Number of objects N (scene complexity) Number

Local Reflections in SS – Demo

Demo

Sebastian Lehmann – Deferred Shading & Screen Space Effects 11. Februar 2014 23/23