39
Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Embed Size (px)

DESCRIPTION

We must know the direction The position is NOT relevant, as we can assume the surface is precisely  meters away

Citation preview

Page 1: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Parallel LightingDirectional Lighting

Distant Lighting(take your pick)

Paul Taylor 2010

Page 2: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Simulation of the Sun, Moon and other big fat distant light sources

http://www.toymaker.info/Games/html/lighting.html

Page 3: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

We must know the direction

• The position is NOT relevant, as we can assume the surface is precisely meters away

Page 4: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

But it’s Similar to diffuse and Specular

• Yes it is• We are not concerned with where the light

comes from, only its direction.• Diffuse light can utilise attenuation, it’s a

waste on a parallel light

Page 5: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Dividing light sources into four groups

• Ambient Lights• Parallel Lights• Point Lights• Spot Lights

Page 6: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Dividing light sources into four groups

• Ambient Lights– You’re good with this!– We only need one ambient source to use on all

our surfaces

Page 7: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Dividing light sources into four groups

• Parallel Lights– We don’t calculate the light direction– This is provided by the light– Both Specular and diffuse light are easily performed

• Point Lights– We always recalculate the light direction, as it

changes quickly with position– For this we must have the light location– Attenuation is also valuable (we cover this next)

Page 8: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Dividing light sources into four groups

• Spot Lights– These are the ugly ones– We need both the light direction and position– Multiple forms of attenuation• Light distance• Angle from Light Direction

– A very similar calculation to Specular Reflection (except the light vector is reversed)

• Angle from Surface Normal

Page 9: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

The last Complication: A Shader Based on Light Type

We will need four helper functions, and call each based on the type of light present

So:If light is Parallel Parallel(....)Else if (....)....Then add Ambient

Page 10: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

That’s the last evil lighting function

Now we need to start creating some lighting

finesse....

Page 11: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Basic Lighting Pixel Shader in HLSL FX

Take in VertexCompute WVP and W coordinates

For Each Light; Select Type; Call Function

ParallelUse Dir

Calculate Reflection

PointCalculate Dir

Calculate ReflectionCalculate Dist Attenuation

SpotlightCalculate Dir

Calculate ReflectionCalculate Dist Attenuation

Calculate Cone Attenuation

Add Ambient Light Factor Pixel Colour

Out

Page 12: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Attenuation

• In the real world:I(d) = I0 / d2

This would be great.... If we had realistic surfaces and light sources

But we don’t, so we have to fake it yet again

Page 13: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Virtual Attenuation

• I(d) = I0 / a0 + a1 d+ a2 d2

This equation can mimik real attenuationa0 = 0, a1 = 0, a2 = 1.0

Page 14: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Virtual Attenuation Graphs

Page 15: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Range

• One extra variable that cuts the light regardless of attenuation

• This can help reduce the shader workload– Can also be used to create a bounding volume for

dynamic lighting calculations• You could also create a strange / sudden

effect

Page 16: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

The End

Page 17: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Deferred Lighting

• Subset of a presentation on the AGT forum.– All about handling dynamic lighting

• Stolen from:http://www.bungie.net/images/Inside/

publications/siggraph/Engel/LightPrePass.ppt

Page 18: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Rendering Many Lights History

• Forward / Z Pre-Pass rendering– Re-render geometry for each light -> lots of

geometry throughput (still an option on older hardware)

– Write pixel shader with four or eight lights -> draw lights per-object -> need to split up geometry following light distribution

– Store light properties in textures and index into this texture -> dependent texture look-up and lights are not fully dynamic

Page 19: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010
Page 20: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Killzone 2

• Deferred Shading / RenderingSplit up rendering into a geometry pass and a lighting pass -> makes lights independent from geometry

• Geometry pass stores all material and light properties

Killzone 2’s G-Buffer Layout (courtesy of Michal Valient)

Page 21: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Rendering Many Lights HistoryDeferred Shading / Rendering

Depth Buffer

DeferredLighting

Forward Rendering

Switch off depth write

Specular /Motion VecNormals Albedo /

Shadow

Sort Back-To-Front

Render opaque objects Transparent objects

Page 22: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Rendering Many Lights History• Advantages:

– Only one geometry pass for the main view (probably more than a dozen for other views like shadows, reflections, transparent objects etc.)

– Lights are blit and therefore only limited by memory bandwidth

• Disadvantages:– Memory bandwidth (reading four render targets for each light)– Recalculate full lighting equation for every light– Limited material representation in G-Buffer– MSAA difficult compared to Forward Renderer

Page 23: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass

• Light Pre-Pass / Deferred Lighting

NormalsSpecular Power Depth

Light Buffer

Frame Buffer

Render opaque Geometry sorted front-to-back

Blit Lights into Light Buffer (sorted front-to-back)

Render opaque Geometry sorted front-to-backorBlit ambient term and other lighting terms into final image

Color

Page 24: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

2 Versions of Lighting Pre-Pass

• V1– Geometry– Light– Geometry

• V2– Geometry– Light– Ambient + MSAA (Multi Sample AA)

Page 25: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass

• Version A:– Geometry pass: fill up normal and depth buffer– Lighting pass: store light properties in light buffer– 2. Geometry pass: fetch light buffer and apply

different material terms per surface by re-constructing the lighting equation

Page 26: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass

• Version B (similar to S.T.A.L.K.E.R: Clear Skies [Lobanchikov]):– Geometry pass: fill up normal + spec. power and

depth buffer and a color buffer for the ambient pass– Lighting pass: store light properties in light buffer– Ambient + Resolve (MSAA) pass: fetch light buffer

use its content as diffuse and specular content and add the ambient term while resolving into the main buffer

Page 27: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

• The lighting is done using 4x quad buffers, instead of the full accuracy 6x quad buffers

Page 28: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass

CryEngine 3: On the right the approx. specular term of the light buffer and on the lefta correct specular term with its own specular color (courtesy of Martin Mittring)

Page 29: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass

CryEngine 3: On the right the approx. specular term of the light buffer and on the leftthe final image (courtesy of Martin Mittring)

Page 30: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

3 Different Optimisations

Dx9Dx10PS3

Page 31: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass Implementation

• Memory Bandwidth Optimizations (DirectX 9)– Depth-fail Stencil lights: render light volume in stencil and

then blit light [Hargreaves][Valient]– Geometry lights: render bounding geometry -> never get

inside light -> avoid depth func change [Thibieroz04]– Scissor lights: construct scissor rectangle from bounding

volume and set it [Placeres] (PS3: depth bound testing ~ scissor in 3D)

– Batched lights: sort lights by size, x and y position in screenspace. Render close lights in batches of 4, 8, 16

Dist

ance

from

Cam

era

Page 32: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass Implementation

• Memory Bandwidth Optimizations (DirectX 10, 10.1, 11)– GS bounding box: construct bounding box in

geometry shader– Implement lighting with the compute shader

• Memory Bandwidth Optimizations (DirectX 8)– Same as DirectX 9 if supported– Re-render geometry per light as alternative

Page 33: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass Implementation

• Memory Bandwidth Optimizations (PS3)1. Full GPU solution [Lee]: like DirectX9 with depth buffer

access and depth bounds testing + batched light support2. SPE (Synergistic Processing Element) + GPU solution

[Palestra] : divide light buffer in tiles: a) Cull tile frustum against light frustum on SPE and keep

track of which light goes into which tileb) Render lights in batches per tile on GPU into light buffer

3. Full SPE solution [Swoboda][Tovey]: like 2 a) but render lights in batches on the SPE into the light buffer

Page 34: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass Implementation

Resistance 2TM in-game screenshot; first row on the left is the depth buffer, on the right is the normal buffer; in the second row is the diffuse light buffer and on the right is the specular light buffer; in the last row is the final result.

Page 35: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Light Pre-Pass Implementation

UnchartedTM in-game screenshot

Page 36: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

MSAA

Multisample Anti-Aliasing (courtesy of Nicolas Thibieroz)

Page 37: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Future

• The story of the Light Pre-Pass / Deferred Lighting is still not fully written and there are many things waiting to be discovered in the future …

Page 38: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Future

• Compute Shader Implementation

Johan Andersson, DICE -> check out the Beyond Programmable Shading course

Page 39: Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010

Also: Bungie Publications

http://www.bungie.net/Inside/publications.aspx