2. Outline
Why(Why not) deferred shading
History of deferred shading
Basic of deferred shading
Shadow in deferred shading
Extension of deferred shading
◦ Light Pre-Pass deferred shading
◦ Anti-aliasing in deferred shading
◦ Inferred shading
◦ Tile-based deferred shading
3. What is deferred shading?
Instead of intermediately calculate the
color and write to frame buffer, we divide
the information into smaller parts and
write them into intermediate buffer (i.e.
G(eometric)-buffer). Then combine and
calculate color later.
Video from source 15
6. Why deferred shading?
Decouple the scene geometry complexity
and light complexity
◦ Going from O( #Light * #Triangle ) to
O( #Light ) + O( #Triangle )
Only do the BRDF calculation on the
visible surfaces
Simplify the rendering process
◦ Few passes on G-buffer V.S. Switching shaders
G-buffer is useful for post-processing
7. Comparison with Forward
Rendering
Single pass lighting:
For each object
Render object
Apply all the lights in shader
Why this is not good?
◦ Boated shader if we do code generation for all
the light sources
◦ Wasteful ( We are throwing away fully shaded
fragment in depth test !)
From source 4, slide 3
8. Comparison with Forward
Rendering
Multi-pass lighting:
For each light
For each object affected by light
Framebuffer += BRDF( object, light )
Why this is not good?
◦ Repetitive vertex transformation for the same
object
◦ Wasteful ( We are “still” throwing away fully
shaded fragment in depth test !)
From source 4, slide 4
9. Deferred Shading
For each object
Render the lighting(material) property
into G-buffer
For each light
Framebuffer += BRDF( G-buffer, light )
Simplify the lighting process
O(1) depth complexity for lighting
From source 4, slide 5
10. Why “not” deferred shading?
Memory intensive
◦ Multiple buffer ( Multiple render target )
◦ Buffer read-back
◦ Limited material type
Cannot apply hardware assisted anti-aliasing
◦ MSAA(Multi-sample anti-aliasing) is for pixel
already shaded
Cannot handle translucent object
◦ We only have the information of the object with
smallest depth value
11. History
Deering, M., et al. “The Triangle
Processor and Normal Vector Shader:
A VLSI System for High Performance
Graphics”, Proceedings of SIGGRAPH
‘88
◦ Only shading once after depth resolution
T. Saito and T. Takahashi.
“Comprehensible rendering of 3d
shapes”, Proceedings of SIGGRAPH ’90
◦ It is designed for contour rendering
◦ The first time the term of G-Buffer
appears
Image from source 6, 7
12. Multiple Render target
A feature that allows programmable
rendering pipeline to render images to
multiple render target texture at the
same time.
Introduced by OpenGL 2.0 and DirectX
9.0
Supported by Xbox360 and Playstation 3
13. Multiple Render target
We can do deferred shading without
Multiple render target.
◦ But the performance is going to be a problem
Image from source 6, 8
15. What kind of G-buffer do we need?
Going from the SSAO assignment we did
16. Say we want something like this
From source 9, slide 9
17. What kind of G-buffer do we need?
From source 9, slide 10
18. What kind of G-buffer do we need?
From source 9, slide 11
19. What kind of G-buffer do we need?
From source 9, slide 12
20. What kind of G-buffer do we need?
From source 9, slide 13
21. What kind of G-buffer do we need?
From source 9, slide 14
22. What kind of G-buffer do we need?
From source 9, slide 15
23. What kind of G-buffer do we need?
From source 9, slide 16
24. What kind of G-buffer do we need?
From source 9, slide 17
25. The G-Buffer of Killzone 2
4 X R8G8B8 + 24Depth + 8Stencil ~= 36 MB
◦ We only got 256 MB RAM and 256 MB VRAM on
PS3
No Normal.z term
◦ Normal.z = sqrt( 1.0 – Normal.x^2 – Normal.y^2 )
◦ Trade memory space with computation time
From source 9, slide 19
26. The G-buffer of Battlefield 3
Material ID is a common way to manage
material
R8 G8 B8 A8
GB0 Normal .xyz Spec. Smoothness
GB1 Diffuse albedo .rgb Specular albedo
GB2 Sky visibility Custom envmap ID Material Param. Material ID
GB3 Irradiance (dynamic radiosity)
Image from source 9, slide 12 and source 10
29. That’s cool. But where is my shadow?
1000 lights without shadow is easy, but
100 lights with shadow is impossible now
Shadow map
◦ A good fit with deferred shading
◦ Need more memory
Shadow volume
◦ Render light as geometry volume
◦ Depth test to determine whether the object is
inside the volume or not
30. Shadow map
Create a depth map in the perspective of light
source.
Compare the position of the geometry
surface with the depth map of light source.
Position = Screen space position + depth
Image from source 14
32. Shadow Volume
Only apply the light to the pixel enclose by
the shadow volume
Depth test needs to be handle carefully
Image from source 4, slide 12 Image from source 17
36. Light Pre-pass / Deferred Lighting
Two pass deferred
shading
1st pass
◦ Only render depth
and normal
◦ Do not need MRT!
Image from source 17
37. Light Pre-pass / Deferred Lighting
Write LightColor * N dot L * Attenuation
in RGB, specular in A channel
Image from source 17
38. Light Pre-pass / Deferred Lighting
2nd geometry pass
◦ Fetch the material property
◦ Combine with light buffer
Image from source 17
39. Light Pre-pass / Deferred Lighting
Pro
◦ Less memory required
◦ Doesn’t not require MRT feature
= Enable programmer to turn on MSAA in
DirectX9
◦ Only one material fetch regardless number of
light
Con
◦ “Two” geometry passes
41. Anti-aliasing
Super-sampling one framebuffer is painful,
super-sampling 5 MRT is 5X painful
Hardware supported MSAA is incompatible
with deferred shading
◦ MSAA cannot apply to MRT in DirectX 9
◦ Super-sampling and averaging normal or depth
might cause wired result
Imaged based approach of anti-aliasing
We have depth and normal information
42. Basic Edge-detection Anti-aliasing
Do the 2D edge detection algorithm on
frame buffer
Apply low-pass filter across the edge
The discontinuities of normal and depth
are better features to locate edges
45. Morphological Anti-aliasing
Connect the mid-points of the L, Z, and U
shape segments.
The blending weight is based on the triangle
area enclosed by mid points
Image from source 18
55. Alpha blending
How do we get transparent/transculant
effect in deferred shading
◦ One more forward rendering pass
◦ Depth peeling
So expensive
Limited layer of transculant material
56. Depth Peeling
Multiple pass of depth buffer generation
from front to back
Peel the fragments away after depth
buffer generated
Render image form back to front
Image from source 22
58. Inferred Shading
3-pass algorithm based on the 2-pass
Light Pre-pass deferred shading
Can create
transparent effect
in deferred shading
scheme
◦ Even multiple
layer of
transparency!
Image from source 23
59. Inferred Shading
Geometry Pass
◦ RT1 : Normal.X / Normal.Y
◦ RT2 : Depth / Object ID
◦ The resolution is lower than target
Light Pass
◦ Apply lighting to the G-buffer to create L-buffer
◦ The resolution is also lower that target
Material Pass
◦ Material fetch
◦ Combine material with L-buffer information
60. Inferred Shading
Discontinuity Sensitive Filtering
◦ Sample lighting information based on the
object ID information stored in G-buffer
◦ If the sample is not from the same object,
then ignore the sample
Image from source 23
61. Lighting Alpha Polygons
Render the transparent objects last in the
geometry pass and render them into
stipple pattern
Special sampling rule parse over the
stipple pattern in the material pass
Image from source 23
68. Tile-based Deferred Shading
Introduced into Frostbite 2 engine
Divide the screen in screen-space tiles
Cull analytical lights (point, cone, line), per
tile
Compute lighting for all contributing lights,
per tile
Slide from source 25
72. Tile-based Deferred Shading
• The screen is divided in 920 tiles of
32x32 pixels
• Downsample and classify the
scene from 720p to 40x23
(1 pixel == 1 tile)
• Find each tile’s Min/Max depth
• Find each tile’s material permutations
• Downsampling is done in multi-pass
and via MRTs
Slide from source 25
76. Tile-based Deferred Shading
Build mini-frustas for each tile
Cull lights against sky-free tiles in a shader
Store the culling results in a texture:
◦ Column == Light ID
◦ Row == Tile ID
Actually, 4 lights can be processed at once
(A-R-G-B)
Read back the contribution results on the
CPU and prepare for lighting!
Slide from source 25
77. Tile-based Deferred Shading
Parse the culling results texture on CPU
For each light type
For each tile
For each material permutation,
Regroup & set the light parameters for
the pixel shader constants
Setup the shader loop counter
(Limited number of light passed)
Additively render lights with a single draw
call (to the final HDR lighting buffer)
Slide from source 25
89. Source
1. John Chapman, “Deferred Rendering, Transparency & Alpha Blending Tutorial”,
Available at:
http://john-chapman.net/content.php?id=13
2. Guerrilla Games, “Killzone 2 Behind the Bullet for PlayStation 3”, Available at:
http://www.youtube.com/watch?v=tzx_JfujYT4
3. Shawn Hargreaves, “Deferred Shading”, Available at:
http://www.shawnhargreaves.com/DeferredShading.pdf
4. Shawn Hargreaves, “Deferred Shading : 6800 Leagues Under The Sea”,
Available at:
http://http.download.nvidia.com/developer/presentations/2004/6800_Leagues/
6800_Leagues_Deferred_Shading.pdf
5. Rich Geldreich, “Deferred Lighting and Shading”, Available at:
https://sites.google.com/site/richgel99/
6. Deering, M., et al. “The Triangle Processor and Normal Vector Shader: A VLSI
System for High Performance Graphics”, Proceedings of SIGGRAPH ‘88 ,
Available at:
http://dl.acm.org/citation.cfm?id=378468
90. Source
7. T. Saito and T. Takahashi. “Comprehensible rendering of 3d shapes”, Proceedings
of SIGGRAPH ’90, Available at:
http://dl.acm.org/citation.cfm?id=97901
8. Filion, D. and McNaughton, R. (Blizzard Entertainment), “ StarCraft II: Effects &
Techniques”, slide available at:
http://developer.amd.com/gpu_assets/S2008-Filion-McNaughton-StarCraftII.pdf
Course note available at:
http://developer.amd.com/documentation/presentations/legacy/Chapter05-
Filion-StarCraftII.pdf
9. Michal Valient (Guerrilla), “Deferred Rendering in Killzone 2 “, Available at:
http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf
10. Christina Coffin (DICE), “SPU-based Deferred Shading for Battlefield 3 on
Playstation 3”, Available at:
http://publications.dice.se/publications.asp?show_category=yes&which_categor
y=Rendering
11. Colin Barré-Brisebois (DICE), “Approximating Translucency for a Fast, Cheap and
Convincing Subsurface Scattering Look”, Available at:
http://zigguratvertigo.com/tag/deferred-shading/
91. Source
12. Michal Valient (Guerrilla), “The Rendering Technology of Killzone 2”, Available at:
http://www.slideshare.net/guerrillagames/the-rendering-technology-of-killzone-
2
13. Michiel van der Leeuw (Guerrilla), “The PlayStation®3’s SPUs in the Real World: A
KILLZONE 2 Case Study “, Available at:
http://www.slideshare.net/guerrillagames/the-playstation3s-spus-in-the-real-
world-a-killzone-2-case-study-9886224
14. Wikipedia : Shadow Mapping
http://en.wikipedia.org/wiki/Shadow_mapping
15. Wikipedia : Deferred Shading
http://en.wikipedia.org/wiki/Deferred_shading
16. Johan Andersson (DICE), “5 Major Challenges in Interactive Rendering”,
Available at:
http://publications.dice.se/publications.asp?show_category=yes&which_categor
y=Rendering
17. Nicolas Thibieroz, “Deferred Shading Optimizations” ,
Available at:
http://developer.amd.com/gpu_assets/Deferred%20Shading%20Optimizations.p
ps
92. Source
18. Alexander Reshetov (Intel Labs ), “Morphological Antialiasing” , Available at:
http://visual-computing.intel-
research.net/publications/papers/2009/mlaa/mlaa.pdf
19. Alexandre De Pereyra (Intel), “MLAA: Efficiently Moving Antialiasing from the
GPU to the CPU”, Available at:
http://software.intel.com/en-us/articles/mlaa-efficiently-moving-antialiasing-
from-the-gpu-to-the-cpu/
20. Chajdas, McGuire, and Luebke, Subpixel Reconstruction Antialiasing, ACM
Symposium on Interactive 3D Graphics and Games (I3D 2011 proceedings),
February 2011, Available at:
http://graphics.cs.williams.edu/papers/SRAAI3D11/
21. Johan Andersson (DICE), “DirectX 11 Rendering in Battlefield 3”, Available at:
http://publications.dice.se/publications.asp?show_category=yes&which_categor
y=Rendering
22. Cass Everitt (Nvidia), “Interactive Order-Independent Transparency”, Available at:
http://developer.nvidia.com/content/interactive-order-independent-
transparency
93. Source
23. Scott Kircher and Alan Lawrance. 2009. Inferred lighting: fast dynamic lighting
and shadows for opaque and translucent objects. In Proceedings of the 2009
ACM SIGGRAPH Symposium on Video Games (Sandbox '09), Stephen N. Spencer
(Ed.). ACM, New York, NY, USA, 39-45. Available at:
http://dl.acm.org/citation.cfm?id=1581080
24. ENGEL, W., 2008. Diary of a graphics programmer: Light pre-pass renderer.
Online, accessed Jan. 27th, 2009. Available at:
http://diaryofagraphicsprogrammer.blogspot.com/2008/03/light-pre-pass-
renderer.html.
25. John White (Black Box), Colin Barré-Brisebois (DICE)“More Performance! Five
Rendering Ideas from Battlefield 3 and Need For Speed The Run”, Available at:
http://publications.dice.se/
26. Kenny Magnusson (DICE),“Lighting you up in Battlefield 3”
http://publications.dice.se/
94. Indirect Reference Source
1. Oles Shishkovtsov (GSC Game World), "GPU Gems 2 Chapter 9. Deferred Shading
in S.T.A.L.K.E.R.", Available at:
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html
2. Rusty Koonce (NCsoft Corporation), "GPU Gems 3 chapter 19. Deferred Shading
in Tabula Rasa", Available at:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch19.html
3. Tiago Sousa(Crytek), "GPU Gems 3 chapter 16. Vegetation Procedural Animation
and Shading in Crysis", Available at:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html
4. Wolfgang Engel, “ShaderX2 : introductions and tutorials with DirectX 9”,
Available at:
http://tog.acm.org/resources/shaderx/Introductions_and_Tutorials_with_Direct
X_9.pdf
5. Wolfgang Engel, “Light Pre-Pass -Deferred Lighting: Latest Development”,
Available at:
http://www.bungie.net/images/Inside/publications/siggraph/Engel/LightPrePass.
ppt
95. Indirect Reference Source
6. Mark Lee(Insomniac games), “Pre-lighting, Available at:
http://www.insomniacgames.com/tech/articles/0209/files/prelighting.pdf
7. Mark Lee(Insomniac games), “Pre-lighting in Resistance 2”, Available at:
http://www.insomniacgames.com/gdc09-resistance-2-prelighting/
8. Rouslan Dimitrov(Nvidia), “Cascaded Shadow Maps”, Available at:
http://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_
maps/doc/cascaded_shadow_maps.pdf
9. Damian Trebilco, “Light Indexed Deferred Lighting”, Available at:
http://code.google.com/p/lightindexed-deferredrender/
10. Andrew Lauritzen(Intel), "Deferred Rendering for Current and Future Rendering
Pipelines", Available at:
http://visual-computing.intel-research.net/art/publications/deferred_rendering/
11. B. Segovia, J. C. Iehl, R. Mitanchey, and B. Péroche. 2006. Non-interleaved
deferred shading of interleaved sample patterns. In Proceedings of the 21st ACM
SIGGRAPH/EUROGRAPHICS symposium on Graphics hardware (GH '06). ACM,
New York, NY, USA, 53-60.
http://dl.acm.org/citation.cfm?id=1283909
96. Indirect Reference Source
12. John Tsiombikas, “Volume Shadows Tutorial”, Available at:
http://nuclear.mutantstargoat.com/
13. Stefan Brabec , Thomas Annen , Hans-peter Seidel, ” Shadow Mapping for
Hemispherical and Omnidirectional Light Sources”, Available at:
http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.3540
14. Emil Persson (AMD), “Depth In-depth “, Available at:
http://developer.amd.com/media/gpu_assets/Depth_in-depth.pdf
15. Sam Martin, Per Einarsson(Geomerics), “A Real Time Radiosity Architecture”
http://www.geomerics.com/downloads/radiosity_architecture.pdf
16. Martin Mittring(Crytek), “A bit more deferred – CryEngine3”, Available at:
http://www.crytek.com/cryengine/presentations&page=2
17. Anton Kaplanyan(Crytek), “CryENGINE 3: reaching the speed of light”
http://www.crytek.com/cryengine/presentations/CryENGINE3-reaching-the-
speed-of-light
18. Nickolay Kasyan, Nicolas Schulz, Tiago Sousa(Crytek), ”Secrets of CryENGINE 3
Graphics Technology”, Available at:
http://www.crytek.com/cryengine/presentations/secrets-of-cryengine-3-
graphics-technology
97. Indirect Reference Source
19. Martin Mittring(Epic games), Bryan Dudash(Nvidia), “The Technology Behind the
DirectX 11 Unreal Engine "Samaritan" Demo”, Available at:
http://www.nvidia.com/content/PDF/GDC2011/Epic.pdf
20. Dean Calver , “Photo-realistic Deferred Lighting”
http://www.beyond3d.com/content/articles/19/1
21. Anton Kaplanyan (Crytek) ,”Light Propagation Volumes in CryEngine 3” ,
Available at:
http://www.crytek.com/cryengine/cryengine3/presentations/light-propagation-
volumes-in-cryengine-3
22. Aths, “Multisampling Anti-Aliasing: A Closeup View “, Available at:
http://alt.3dcenter.org/artikel/multisampling_anti-aliasing/index3_e.php
23. Fabio Policarpo, Francisco Fonseca(CheckMate Games), “ Deferred Shading Tutorial”,
Available at:
http://www710.univ-
lyon1.fr/~jciehl/Public/educ/GAMA/2007/Deferred_Shading_Tutorial_SBGAMES2005.
pdf
24. Josh Klint (CEO, Leadwerks Corporation ), “Deferred Rendering in Leadwerks Engine “,
Available at:
http://leadwerks.com/files/Deferred_Rendering_in_Leadwerks_Engine.pdf
98. Previous Presentation
[Spring 2011] Sean Thomas
http://smt565.blogspot.com/
[Spring 2010] Ian Perera
http://www.seas.upenn.edu/~cis565/LEC
TURE2010/Deferred%20RenderingMacro.
pptm