Screen-Space Classification for  Efficient Deferred Shading                        cafe.naver.com/shader                  ...
Screen-Space Classification forTile based Deferred Shading   Efficient
Overview !        GPU side     G-buffer renderDepth related classification    Pixel classification             CPU side   ...
4x4Pixel tiles
1280x720(HD) 57,600(320x180) tiles
classify 1. Solid shadow  2. Soft shadow 3. Shadow fade4. Light scattering       5. Sky    6. Sun light  7. Antialiasing
classify  1. Solid shadowDepth-Related   2. Soft shadowClassification  3. Shadow fade 4. Light scattering        5. Sky   ...
classify  1. Solid shadowDepth-Related   2. Soft shadowClassification  3. Shadow fade 4. Light scattering        5. Sky   ...
classify  1. Solid shadowDepth-Related   2. Soft shadowClassification  3. Shadow fade 4. Light scattering        5. Sky   ...
Shadow Maps            Screen Depths Screen space shadow edge(1/4 size) Screen space shadow edge(1/16 size)    Screen spac...
Shadow Maps               Screen Depthspass. 1   Shadow type, Light Scattering, Shadow fade           Screen space shadow ...
float shadowType = CalcShadowType(worldPos, depth);float lightScattering = (depth > scatteringStartDist) ? 1.0 : 0.0;float...
Shadow Maps           Screen Depths           Screen space shadow edge(1/4 size)pass. 2      Depth-related classification ...
// Read 4 texels from 1st pass with sample offsets of 1 texel#define OFFSET_X (1.0/640.0)#define OFFSET_Y (1.0/320.0)float...
classify 1. Solid shadow  2. Soft shadow 3. Shadow fade4. Light scattering       5. Sky       Pixel    6. Sun lightClassif...
// Separate motion IDs and MSAA edge fragments from normals.float2 edgeAndID_frags = float2(gb1_frag0.w, gb1_frag1.w);// C...
combineDepth-Related       Pixel
combine         32   32   64   645         32   32   96   96         …
combine  +   OR
index buffer         Pass. 1각 타일별 사용하는 shader의 수를 구한다
index buffer  [0]   0         0   1      3      1       …  [1]   0                                   …  [2]   0           ...
index buffer  [0] 1           0   1   3   1   …  [1]   0                         …  [2]   0                         …     ...
index buffer  [0]   1         0   1   3   1   …  [1] 1                           …  [2]   0                         …     ...
index buffer  [0]   1         0   1   3   1   …  [1]   1                         …  [2]   0                         …     ...
index buffer  [0]   1         0   1   3   1   …  [1] 2                           …  [2]   0                         …     ...
index buffer               Pass. 2각 shader별 index buffer의 크기를 구한다
index buffer  [0]                                            …  [1]                                            …  [2]     ...
index buffer  [0] 0     *                    …  [1]                            …  [2]                            …        ...
index buffer  [0]   0   *                    …  [1] n     *                    …  [2]                            …        ...
index buffer            Pass. 3index buffer에 index값을 넣는다
Render !  Pixel tiles
끝(?)
Optimize#1. Reduce shader count
128→32 Before & After
7bit→5bitSolid Shadow ↔ Soft Shadow          Sky ↔ Sun Light
Optimize#2. Tile Coalescing
10   10   18   1034   34   34   3434   18   10   1010   10   10   10
10   10        18   10          3434   18        10   10          10
PerformanceTask                PS3     PS3              Xbox360   Xbox360                    Naive   Classification   Naiv...
PerformanceTask                PS3      PS3              Xbox360   Xbox360                    Naive    Classification   Na...
PerformanceTask                PS3     PS3              Xbox360    Xbox360                    Naive   Classification   Nai...
Upcoming SlideShare
Loading in …5
×

[GEG2] 4. Screen-Space Classification for Efficient Deferred Shading

1,464 views
1,324 views

Published on

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,464
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

[GEG2] 4. Screen-Space Classification for Efficient Deferred Shading

  1. 1. Screen-Space Classification for Efficient Deferred Shading cafe.naver.com/shader 인성민
  2. 2. Screen-Space Classification forTile based Deferred Shading Efficient
  3. 3. Overview ! GPU side G-buffer renderDepth related classification Pixel classification CPU side GPU callback Wake Index buffer generation Wait on signal Signal Tile render Sleep
  4. 4. 4x4Pixel tiles
  5. 5. 1280x720(HD) 57,600(320x180) tiles
  6. 6. classify 1. Solid shadow 2. Soft shadow 3. Shadow fade4. Light scattering 5. Sky 6. Sun light 7. Antialiasing
  7. 7. classify 1. Solid shadowDepth-Related 2. Soft shadowClassification 3. Shadow fade 4. Light scattering 5. Sky 6. Sun light 7. Antialiasing
  8. 8. classify 1. Solid shadowDepth-Related 2. Soft shadowClassification 3. Shadow fade 4. Light scattering 5. Sky Pixel 6. Sun lightClassification 7. Antialiasing
  9. 9. classify 1. Solid shadowDepth-Related 2. Soft shadowClassification 3. Shadow fade 4. Light scattering 5. Sky 6. Sun light 7. Antialiasing
  10. 10. Shadow Maps Screen Depths Screen space shadow edge(1/4 size) Screen space shadow edge(1/16 size) Screen space shadow mask
  11. 11. Shadow Maps Screen Depthspass. 1 Shadow type, Light Scattering, Shadow fade Screen space shadow edge(1/16 size) Screen space shadow mask
  12. 12. float shadowType = CalcShadowType(worldPos, depth);float lightScattering = (depth > scatteringStartDist) ? 1.0 : 0.0;float shadowFade = (depth > shadowFadeStartDist) ? 1.0 : 0.0;output.color = float4(shadowType, lightScattering, shadowFade, 0.0); Codes page 59. Listing 4.1
  13. 13. Shadow Maps Screen Depths Screen space shadow edge(1/4 size)pass. 2 Depth-related classification Screen space shadow mask
  14. 14. // Read 4 texels from 1st pass with sample offsets of 1 texel#define OFFSET_X (1.0/640.0)#define OFFSET_Y (1.0/320.0)float3 rgb = tex2D(tex, uv, float2(-OFFSET_X, -OFFSET_Y).rgb;rgb += tex2D(tex, uv, float2( OFFSET_X, -OFFSET_Y).rgb;rgb += tex2D(tex, uv, float2(-OFFSET_X, OFFSET_Y).rgb;rgb += tex2D(tex, uv, float2( OFFSET_X, OFFSET_Y).rgb;// Pack classification bits together Codes#define RAW_SHADOW_SOLID(1 << 0)#define RAW_SHADOW_SOFT(1 << 1)#define RAW_SHADOW_FADE(1 << 2)#define RAW_SHADOW_SCATTERING(1 << 3) page 59-60. Listing 4.2float bits = 0.0;if (rgb.r == 0.0) bits += RAW_SHADOW_SOLID / 255.0;else if (rgb.r == 4.0) bits += RAW_SHADOW_SOFT / 255.0;if (rgb.b != 0.0) bits += RAW_SHADOW_FADE / 255.0;if (rgb.g != 0.0) bits += RAW_SHADOW_SCATTERING / 255.0;output.color = float4(bits, 0.0, 0.0, 0.0);
  15. 15. classify 1. Solid shadow 2. Soft shadow 3. Shadow fade4. Light scattering 5. Sky Pixel 6. Sun lightClassification 7. Antialiasing
  16. 16. // Separate motion IDs and MSAA edge fragments from normals.float2 edgeAndID_frags = float2(gb1_frag0.w, gb1_frag1.w);// Classify MSAA edge (marked in high bit).float2 msaaEdge_frags = (edgeAndID_frags > (128.0 / 255.0));float msaaEdge = any(msaaEdge_frags);float3 normalDiff = gb1_frag0.xyz - gb1_frag1.xyz;msaaEdge += any(normalDiff);// Classify sky (marked with motion ID of 0 - MSAA edge bit will also be 0. Codesfloat2 sky_frags = (edgeAndID_frags == 0.0);float sky = any(sky_frags);// Classify sunlight (except in sky).float2 sunlight_frags;sunlight_frags.x = sky_frags.x ? 0.0 : -dot(normal_frags0, 4.3 page 61. Listing sunDir);sunlight_frags.y = sky_frags.y ? 0.0 : -dot(normal_frags1, sunDir);float sunlight = any(sunlight_frags);// Pack classification bits together.#define RAW_MSAA_EDGE (1 << 4)#define RAW_SKY (1 << 5)#define RAW_SUN_LIGHT (1 << 6)float bits = msaaEdge ? (RAW_MSAA_EDGE / 255.0) : 0.0;bits += sky ? (RAW_SKY / 255.0) : 0.0;bits += sunlight ? (RAW_SUN_LIGHT / 255.0) : 0.0;
  17. 17. combineDepth-Related Pixel
  18. 18. combine 32 32 64 645 32 32 96 96 …
  19. 19. combine + OR
  20. 20. index buffer Pass. 1각 타일별 사용하는 shader의 수를 구한다
  21. 21. index buffer [0] 0 0 1 3 1 … [1] 0 … [2] 0 … … … … … … …[127] 0 …ShaderTileCount Tiles (320x180)
  22. 22. index buffer [0] 1 0 1 3 1 … [1] 0 … [2] 0 … … … … … … …[127] 0 …
  23. 23. index buffer [0] 1 0 1 3 1 … [1] 1 … [2] 0 … … … … … … …[127] 0 …
  24. 24. index buffer [0] 1 0 1 3 1 … [1] 1 … [2] 0 … … … … … … …[127] 0 …
  25. 25. index buffer [0] 1 0 1 3 1 … [1] 2 … [2] 0 … … … … … … …[127] 0 …
  26. 26. index buffer Pass. 2각 shader별 index buffer의 크기를 구한다
  27. 27. index buffer [0] … [1] … [2] … … … … … … … …[127] … IBOffsets (left) Index Buffer IBPointers (right) (320x180xINDICES_PER_PRIM)
  28. 28. index buffer [0] 0 * … [1] … [2] … … … … … … … …[127] …
  29. 29. index buffer [0] 0 * … [1] n * … [2] … … … … … … … …[127] …
  30. 30. index buffer Pass. 3index buffer에 index값을 넣는다
  31. 31. Render ! Pixel tiles
  32. 32. 끝(?)
  33. 33. Optimize#1. Reduce shader count
  34. 34. 128→32 Before & After
  35. 35. 7bit→5bitSolid Shadow ↔ Soft Shadow Sky ↔ Sun Light
  36. 36. Optimize#2. Tile Coalescing
  37. 37. 10 10 18 1034 34 34 3434 18 10 1010 10 10 10
  38. 38. 10 10 18 10 3434 18 10 10 10
  39. 39. PerformanceTask PS3 PS3 Xbox360 Xbox360 Naive Classification Naive ClassificationDepth-related 0.00 1.29 0.00 0.70Pixel 0.00 ~0.00 0.00 0.69Global light pass 13.93 4.82 8.30 2.69Total(ms) 13.93 6.11 8.30 4.08
  40. 40. PerformanceTask PS3 PS3 Xbox360 Xbox360 Naive Classification Naive ClassificationDepth-related 0.00 1.29 0.00 0.70Pixel 0.00 ~0.00 0.00 0.69Global light pass 13.93 4.82 8.30 2.69Total(ms) 13.93 -7.82 6.11 8.30 4.08
  41. 41. PerformanceTask PS3 PS3 Xbox360 Xbox360 Naive Classification Naive ClassificationDepth-related 0.00 1.29 0.00 0.70Pixel 0.00 ~0.00 0.00 0.69Global light pass 13.93 4.82 8.30 2.69Total(ms) 13.93 6.11 8.30 -4.22 4.08

×