390 likes | 593 Views
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. We must know the direction.
E N D
Parallel LightingDirectional LightingDistant 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
We must know the direction • The position is NOT relevant, as we can assume the surface is precisely meters away
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
Dividing light sources into four groups • Ambient Lights • Parallel Lights • Point Lights • Spot Lights
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
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)
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
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
That’s the last evil lighting function Now we need to start creating some lighting finesse....
Basic Lighting Pixel Shader in HLSL FX Take in Vertex Compute WVP and W coordinates For Each Light; Select Type; Call Function Spotlight Calculate Dir Calculate Reflection Calculate Dist Attenuation Calculate Cone Attenuation Parallel Use Dir Calculate Reflection Point Calculate Dir Calculate Reflection Calculate Dist Attenuation Add Ambient Light Factor Pixel Colour Out
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
Virtual Attenuation • I(d) = I0 / a0 + a1 d+ a2 d2 This equation can mimik real attenuation a0 = 0, a1 = 0, a2 = 1.0
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
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
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
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)
Rendering Many Lights History Deferred Shading / Rendering Render opaque objects Transparent objects Normals Specular /Motion Vec Albedo /Shadow Depth Buffer DeferredLighting Switch off depth write Forward Rendering Sort Back-To-Front
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
Light Pre-Pass • Light Pre-Pass / Deferred Lighting
2 Versions of Lighting Pre-Pass • V1 • Geometry • Light • Geometry • V2 • Geometry • Light • Ambient + MSAA (Multi Sample AA)
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
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
The lighting is done using 4x quad buffers, instead of the full accuracy 6x quad buffers
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)
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)
3 Different Optimisations Dx9 Dx10 PS3
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 Distance from Camera
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
Light Pre-Pass Implementation • Memory Bandwidth Optimizations (PS3) • Full GPU solution [Lee]: like DirectX9 with depth buffer access and depth bounds testing + batched light support • SPE (Synergistic Processing Element) + GPU solution [Palestra] : divide light buffer in tiles: • Cull tile frustum against light frustum on SPE and keep track of which light goes into which tile • Render lights in batches per tile on GPU into light buffer • Full SPE solution [Swoboda][Tovey]: like 2 a) but render lights in batches on the SPE into the light buffer
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.
Light Pre-Pass Implementation UnchartedTM in-game screenshot
MSAA Multisample Anti-Aliasing (courtesy of Nicolas Thibieroz)
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 …
Future • Compute Shader Implementation Johan Andersson, DICE -> check out the Beyond Programmable Shading course
Also: Bungie Publications http://www.bungie.net/Inside/publications.aspx