Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010."— Presentation transcript:

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

2 Simulation of the Sun, Moon and other big fat distant light sources http://www.toymaker.info/Games/html/lightin g.html

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

4 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

5 Dividing light sources into four groups Ambient Lights Parallel Lights Point Lights Spot Lights

6 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

7 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)

8 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

9 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

10 That’s the last evil lighting function Now we need to start creating some lighting finesse....

11 Basic Lighting Pixel Shader in HLSL FX Take in Vertex Compute WVP and W coordinates For Each Light; Select Type; Call Function Parallel Use Dir Calculate Reflection Point Calculate Dir Calculate Reflection Calculate Dist Attenuation Spotlight Calculate Dir Calculate Reflection Calculate Dist Attenuation Calculate Cone Attenuation Add Ambient Light Factor Pixel Colour Out

12 Attenuation In the real world: I(d) = I 0 / d 2 This would be great.... If we had realistic surfaces and light sources But we don’t, so we have to fake it yet again

13 Virtual Attenuation I(d) = I 0 / a 0 + a 1 d+ a 2 d 2 This equation can mimik real attenuation a 0 = 0, a 1 = 0, a 2 = 1.0

14 Virtual Attenuation Graphs

15 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

16 The End

17 Deferred Lighting Subset of a presentation on the AGT forum. – All about handling dynamic lighting Stolen from: http://www.bungie.net/images/Inside/publicati ons/siggraph/Engel/LightPrePass.ppt

18 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

19

20 Killzone 2 Deferred Shading / Rendering Split 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)

21 Rendering Many Lights History Deferred Shading / Rendering Depth Buffer Deferred Lighting Forward Rendering Switch off depth write Specular / Motion Vec Normals Albedo / Shadow Sort Back-To-Front Render opaque objectsTransparent objects

22 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

23 Light Pre-Pass Light Pre-Pass / Deferred Lighting

24 2 Versions of Lighting Pre-Pass V1 – Geometry – Light – Geometry V2 – Geometry – Light – Ambient + MSAA (Multi Sample AA)

25 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

26 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

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

28 Light Pre-Pass CryEngine 3: On the right the approx. specular term of the light buffer and on the left a correct specular term with its own specular color (courtesy of Martin Mittring)

29 Light Pre-Pass CryEngine 3: On the right the approx. specular term of the light buffer and on the left the final image (courtesy of Martin Mittring)

30 3 Different Optimisations Dx9 Dx10 PS3

31 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

32 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

33 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 support 2.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 tile b)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

34 Light Pre-Pass Implementation Resistance 2 TM 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.

35 Light Pre-Pass Implementation Uncharted TM in-game screenshot

36 MSAA Multisample Anti-Aliasing (courtesy of Nicolas Thibieroz)

37 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 …

38 Future Compute Shader Implementation Johan Andersson, DICE -> check out the Beyond Programmable Shading course

39 Also: Bungie Publications http://www.bungie.net/Inside/publications.aspx


Download ppt "Parallel Lighting Directional Lighting Distant Lighting (take your pick) Paul Taylor 2010."

Similar presentations


Ads by Google