deferred shading - tume-maailm.pri.eetume-maailm.pri.ee/ylikool/computergraphicsseminar... ·...
TRANSCRIPT
Deferred ShadingRasmus Vahtra, Andres Traks
Forward rendering
(non-deferred shading)
Forward rendering
(non-deferred shading)
Forward rendering
(non-deferred shading)
Forward rendering
(non-deferred shading)
Depth culling
Forward rendering
(non-deferred shading)
Forward shader: Vertex Shader (VS)
VS PS
Forward shader: Pixel Shader (PS)
VS PS
Complexity of forward rendering
For each light:
For each object:
Render()
Blend results together
Deferred shading
Shading done in a separate rendering pass
Pass 1: Render object data into buffers
Pass 2: Do lighting/shading
VS PS
VS
PS
Deferred shading:
1) collect data into intermediate textures
Deferred shading:
1) collect data into intermediate textures
Deferred shading:
1) collect data into intermediate textures
Depth culling
Deferred shading:
1) collect data into intermediate textures, done
Don’t care about geometry anymore
Deferred shader: Vertex Shader (pass 1)
VS PS
Deferred shader: Pixel Shader (pass 1)
VS PS
Deferred shading:
1) collect data into intermediate textures, done
Deferred shading:
2) Draw a full-screen quad
UV = (0, 0)
(0, 1) (1, 1)
(1, 0)
Deferred shader: Pixel Shader (pass 2)
Review
VS PS
VS PS
VS
PS
Forward rendering:
Deferred shading:
Complexity of deferred rendering
For each object:
Render geometry data
Then shade each pixel on screen exactly once
Deferred shading: VS
Pass 2) Draw a full-screen quad
ID TexCoord Position
0 (0, 0) (-1, 1, 0, 1)
1 (1, 0) (1, 1, 0, 1)
2 (0, 1) (-1, -1, 0, 1)
3 (1, 1) (1, -1, 0, 1)
VS
PS
Full screen triangle
UV = (0, 0)
(0, 1)
(1, 0)
(1, 1)
(0, 2)
(2, 0)
A bit faster than a quad
G-buffer
R G B A
Diffuse RGB -
Normal XYZ -
Depth (32-bit)
• 1920 x 1080 x 3 x 32 bits = 24 MB
G-buffer: extra attributes
Battlefield 3
Killzone 2
Packing normals
http://aras-p.info/texts/CompactNormalStorage.html
𝑛. 𝑥2 + 𝑛. 𝑦2 + 𝑛. 𝑧2 = 1
Works only with normalized view-space normals!
Anti-aliasing
Edge-detect
Blur if edge detected
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html
Transparent objects?
Render them after the deferred pass
using forward shading
Deferred lighting
Modifying the G-buffer for
deferred lighting
R G B A
Diffuse RGB -
Normal XYZ -
Depth (32-bit)
Light Accumulation RGB -
Deferred lighting: G-Buffer
Light Stencil Volumes
Each point light area is bounded by a sphere (approximate)
Light Stencil Volumes
Each point light area is bounded by a sphere (approximate)
Light Stencil Volumes
Each point light area is bounded by a sphere (approximate)
Stencil shapes of lights
Fullscreen quad Fullscreen quad
Sphere Cone
http://www.okino.com/new/toolkit/1-14.htm
Other effects: Screen Space Ambient Occlusion
(SSAO)
http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html