1 / 39

Parallel Lighting Directional Lighting Distant Lighting (take your pick)

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.

morrie
Télécharger la présentation

Parallel Lighting Directional Lighting Distant Lighting (take your pick)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parallel LightingDirectional LightingDistant 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/lighting.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 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

  12. 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

  13. Virtual Attenuation • I(d) = I0 / a0 + a1 d+ a2 d2 This equation can mimik real attenuation a0 = 0, a1 = 0, a2 = 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/publications/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. 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)

  20. 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

  21. 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

  22. Light Pre-Pass • Light Pre-Pass / Deferred Lighting

  23. 2 Versions of Lighting Pre-Pass • V1 • Geometry • Light • Geometry • V2 • Geometry • Light • Ambient + MSAA (Multi Sample AA)

  24. 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

  25. 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

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

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

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

  29. 3 Different Optimisations Dx9 Dx10 PS3

  30. 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

  31. 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

  32. 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

  33. 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.

  34. Light Pre-Pass Implementation UnchartedTM in-game screenshot

  35. MSAA Multisample Anti-Aliasing (courtesy of Nicolas Thibieroz)

  36. 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 …

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

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

More Related