67
Jon Story, 16 March 2016 Advanced Geometrically Correct Shadows for Modern Game Engines

Advanced Geometrically Correct Shadows for Modern Game …

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Advanced Geometrically Correct Shadows for Modern Game …

Jon Story, 16 March 2016

Advanced Geometrically Correct Shadows for Modern Game Engines

Page 2: Advanced Geometrically Correct Shadows for Modern Game …

2 gameworks.nvidia.com

Agenda

•Problems with Shadows?

•Frustum Tracing

• Irregular Z-Buffer

•Dynamic Reprojection

•Conservative Rasterization

•Anti-Aliasing

•Hybrid Frustum Traced Shadows

•Comparison Screenshots

•Performance

•GFSDK Shadow Lib v3.0

– Don’t do this…

» Or this

Page 3: Advanced Geometrically Correct Shadows for Modern Game …

3 gameworks.nvidia.com

Problems with Shadows?

Page 4: Advanced Geometrically Correct Shadows for Modern Game …

4 gameworks.nvidia.com

Aliasing due to

insufficient

shadow map

texels

Page 5: Advanced Geometrically Correct Shadows for Modern Game …

5 gameworks.nvidia.com

Filter

interferance

from

overlapping

blockers

Detachment

due to z-bias

factor

Page 6: Advanced Geometrically Correct Shadows for Modern Game …

6 gameworks.nvidia.com

Are these shadows realistic?

Page 7: Advanced Geometrically Correct Shadows for Modern Game …

7 gameworks.nvidia.com

Hybrid Frustum Traced

Shadows

(HFTS)

Page 8: Advanced Geometrically Correct Shadows for Modern Game …

8 gameworks.nvidia.com

Demo: Tom Clancy‘s The Division

Page 9: Advanced Geometrically Correct Shadows for Modern Game …

9 gameworks.nvidia.com

Frustum Tracing

Page 10: Advanced Geometrically Correct Shadows for Modern Game …

10 gameworks.nvidia.com

What‘s the difference between ray tracing and frustum tracing?

Page 11: Advanced Geometrically Correct Shadows for Modern Game …

11 gameworks.nvidia.com

Ray Tracing

•Store primitives in some structure

•Perform ray triangle intersection test for all appropriate triangles

Page 12: Advanced Geometrically Correct Shadows for Modern Game …

12 gameworks.nvidia.com

Frustum Tracing

•Construct 4 planes for each light space primitive

•Perform point-in-frustum test for the list of screen pixels mapped to a given light space texel

* [Chris Wyman - i3D 2015]

Page 13: Advanced Geometrically Correct Shadows for Modern Game …

13 gameworks.nvidia.com

Irregular Z-Buffer

Page 14: Advanced Geometrically Correct Shadows for Modern Game …

14 gameworks.nvidia.com

Irregular Z-Buffer

•Mapping light space to screen space...

One to many mapping!

Page 15: Advanced Geometrically Correct Shadows for Modern Game …

15 gameworks.nvidia.com

Constructing the Irregular Z-Buffer

Screen Space List Nodes

Light Space List Head

Fixed memory footprint!

* [Chris Wyman - i3D 2015]

Page 16: Advanced Geometrically Correct Shadows for Modern Game …

16 gameworks.nvidia.com

Visualizing the Irregular Z-Buffer

List length that each screen

pixel is a member of List head pointer

* [Chris Wyman - i3D 2015]

Page 17: Advanced Geometrically Correct Shadows for Modern Game …

17 gameworks.nvidia.com

Pipeline Stage: Irregular Z-Buffer

Irregular Z-Buffer

[PS]

Depth

List Nodes

List Head

Page 18: Advanced Geometrically Correct Shadows for Modern Game …

18 gameworks.nvidia.com

Pipeline Stage: Frustum Tracing

Frustum Trace

[GS + PS]

List Nodes

List Head

Hard Shadow

Depth

Page 19: Advanced Geometrically Correct Shadows for Modern Game …

19 gameworks.nvidia.com

Dynamic Reprojection

Page 20: Advanced Geometrically Correct Shadows for Modern Game …

20 gameworks.nvidia.com

Very long lists?

•A major problem with the irregular z-buffer approach

•Causes very low occupancy

•A single light texel can map to a very large area of the screen

•SDSM can certainly be used to help alleviate this, but:

•Requires a CPU read back

•Frustum / occlusion culling needs to be done at render time

•Stability issues

•A more targeted approach would be to directly detect long lists

•Dynamically reproject those problem areas

Page 21: Advanced Geometrically Correct Shadows for Modern Game …

21 gameworks.nvidia.com

Pipeline Stage: Heat Map

Heat Map

[CS]

Depth Heat Map

Page 22: Advanced Geometrically Correct Shadows for Modern Game …

22 gameworks.nvidia.com

Pipeline Stage: Dynamic Reprojection

Dynamic

Reprojection

[CS]

Heat Map

Projection

Matrix Buffer

Page 23: Advanced Geometrically Correct Shadows for Modern Game …

23 gameworks.nvidia.com

Pipeline Stage: Irregular Z-Buffer

Irregular Z-Buffer

[PS]

Depth

List Head 0 List Head 1

List Nodes

Projection

Matrix Buffer

Page 24: Advanced Geometrically Correct Shadows for Modern Game …

24 gameworks.nvidia.com

Pipeline Stage: Frustum Tracing

Frustum Trace

[GS + PS]

Hard Shadow

List Head 0

List Head 1

List Nodes

Depth

Projection

Matrix

Buffer

Page 25: Advanced Geometrically Correct Shadows for Modern Game …

25 gameworks.nvidia.com

Full screen pass counts number

of screen pixels mapped to a

given light space texel

Visualized here as a heat map! Reprojected area that contained

long lists

Reprojected area of non zero list

length – chops out all redundant

area in light space

Page 26: Advanced Geometrically Correct Shadows for Modern Game …

26 gameworks.nvidia.com

Benefits of Dynamic Reprojection

• Improves existing light space mapping for frustum tracing

•Could be used to improve standard shadow maps?

•Reprojection is computed on the GPU

•No CPU read back is required

•Easy to integrate with existing cascades

•Reprojection only occurs when long lists are detected

•Drastically improves baseline performance of frustum tracing

Page 27: Advanced Geometrically Correct Shadows for Modern Game …

27 gameworks.nvidia.com

Conservative Rasterization

Page 28: Advanced Geometrically Correct Shadows for Modern Game …

28 gameworks.nvidia.com

Requires Conservative Rasterization

•Ensures that every pixel touched by a primitive is rasterizered

•Enabled in DirectX 12 and in DirectX 11 at FEATURE_LEVEL_11_3

•D3D11_RASTERIZER_DESC2

•D3D12_RASTERIZER_DESC

•Also through NvAPI – it works on Windows 7 and above!

•Supported by Maxwell and above

Off On

Page 29: Advanced Geometrically Correct Shadows for Modern Game …

29 gameworks.nvidia.com

Software Conservative Rasterization

•Use the GS to dilate a triangle in clip space

•Generate AABB to clip the triangle in the PS

•See GPU Gems 2 - Chapter 42

Page 30: Advanced Geometrically Correct Shadows for Modern Game …

30 gameworks.nvidia.com

Anti-Aliasing

Page 31: Advanced Geometrically Correct Shadows for Modern Game …

31 gameworks.nvidia.com

Anti-Aliasing?

•Perform sub-pixel accurate frustum tests?

•Perfectly possible to achieve

•Yields really stable results

•But comes at an additional cost

•Simple trick – apply a screen space AA technique

•FXAA

•Great results

•Very cheap

•Possibly free – if you already use screen space AA

Page 32: Advanced Geometrically Correct Shadows for Modern Game …

32 gameworks.nvidia.com

Anti-Aliasing

FXAA

Page 33: Advanced Geometrically Correct Shadows for Modern Game …

33 gameworks.nvidia.com 33

Shadow Map

Page 34: Advanced Geometrically Correct Shadows for Modern Game …

34 gameworks.nvidia.com 34

Frustum Traced

Page 35: Advanced Geometrically Correct Shadows for Modern Game …

35 gameworks.nvidia.com

Hybrid Frustum Traced Shadows (HFTS)

Page 36: Advanced Geometrically Correct Shadows for Modern Game …

36 gameworks.nvidia.com

Hybrid Approach

•Combine frustum traced shadow with PCSS

•Blocker distance can be used as an interpolation factor

•As blocker distance approaches zero, frustum traced result is prevalent

•Only first cascade has frustum tracing applied

Page 37: Advanced Geometrically Correct Shadows for Modern Game …

37 gameworks.nvidia.com

L = saturate( BD / WSS * PHS ) L: Lerp factor BD: Blocker Distance WSS: World Space Scale PHS: Percentage of Hard Shadow HFTS = lerp( FT, PCSS, L ) HFTS: Hybrid Shadow FT: Frustum Traced Hard Shadow (0 or 1) PCSS: PCSS Soft Shadow (0 to 1)

Blocker distance = 0

Lerp factor

* [Jon Story – GDC 2015]

Page 38: Advanced Geometrically Correct Shadows for Modern Game …

38 gameworks.nvidia.com 38

HFTS - Standard Filter

Page 39: Advanced Geometrically Correct Shadows for Modern Game …

39 gameworks.nvidia.com

Needs a Shifted Penumbra Filter

•Shadow map result would not be contained within the frustum traced result

•Would lead to ugly artifacts during interpolation

Fully Lit

Fully Shadowed

Standard Filter

Fully Lit

Fully Shadowed

Shrinking Filter

* [Jon Story – GDC 2015]

Page 40: Advanced Geometrically Correct Shadows for Modern Game …

40 gameworks.nvidia.com 40

HFTS - Shifted Penumbra Filter

Page 41: Advanced Geometrically Correct Shadows for Modern Game …

41 gameworks.nvidia.com

HFTS

Page 42: Advanced Geometrically Correct Shadows for Modern Game …

42 gameworks.nvidia.com

Pipeline Stage: HFTS

HFTS

[PS]

Depth

Hard Shadow

Shadow Map

Final Image

Page 43: Advanced Geometrically Correct Shadows for Modern Game …

43 gameworks.nvidia.com

Comparison Screenshots

Page 44: Advanced Geometrically Correct Shadows for Modern Game …

44 gameworks.nvidia.com

Too soft

Detachment

Too hard

Quality: High

Page 45: Advanced Geometrically Correct Shadows for Modern Game …

45 gameworks.nvidia.com

Too soft

Detachment

Quality: PCSS

Page 46: Advanced Geometrically Correct Shadows for Modern Game …

46 gameworks.nvidia.com

Quality: HFTS

Page 47: Advanced Geometrically Correct Shadows for Modern Game …

47 gameworks.nvidia.com

Too soft

Detachment

Too hard

Quality: High

Page 48: Advanced Geometrically Correct Shadows for Modern Game …

48 gameworks.nvidia.com

Filter

interferance

Detachment

Quality: PCSS

Page 49: Advanced Geometrically Correct Shadows for Modern Game …

49 gameworks.nvidia.com

Quality: HFTS

Page 50: Advanced Geometrically Correct Shadows for Modern Game …

50 gameworks.nvidia.com

Detachment

Quality: High

Page 51: Advanced Geometrically Correct Shadows for Modern Game …

51 gameworks.nvidia.com

Detachment

Quality: PCSS

Page 52: Advanced Geometrically Correct Shadows for Modern Game …

52 gameworks.nvidia.com

Quality: HFTS

Page 53: Advanced Geometrically Correct Shadows for Modern Game …

53 gameworks.nvidia.com

Detachment

Aliasing

Too soft

Too hard

Quality: High

Page 54: Advanced Geometrically Correct Shadows for Modern Game …

54 gameworks.nvidia.com

Detachment

Aliasing

Too soft

Quality: PCSS

Page 55: Advanced Geometrically Correct Shadows for Modern Game …

55 gameworks.nvidia.com

Quality: HFTS

Page 56: Advanced Geometrically Correct Shadows for Modern Game …

56 gameworks.nvidia.com

Detachment

Aliasing Too soft

Quality: High

Page 57: Advanced Geometrically Correct Shadows for Modern Game …

57 gameworks.nvidia.com

Detachment

Aliasing Too soft

Quality: PCSS

Page 58: Advanced Geometrically Correct Shadows for Modern Game …

58 gameworks.nvidia.com

Quality: HFTS

Page 59: Advanced Geometrically Correct Shadows for Modern Game …

59 gameworks.nvidia.com

Performance

Page 60: Advanced Geometrically Correct Shadows for Modern Game …

60 gameworks.nvidia.com

0 1 2 3 4 5 6 7

PCSS

FT

HFTS

ms

GTX Titan X Resolution: 1920x1080

Page 61: Advanced Geometrically Correct Shadows for Modern Game …

61 gameworks.nvidia.com

0 1 2 3 4 5

PCSS

FT

HFTS

ms

GTX Titan X Resolution: 1920x1080

Page 62: Advanced Geometrically Correct Shadows for Modern Game …

62 gameworks.nvidia.com

0 1 2 3 4 5 6 7

PCSS

FT

HFTS

ms

GTX Titan X Resolution: 1920x1080

Page 63: Advanced Geometrically Correct Shadows for Modern Game …

63 gameworks.nvidia.com

0 1 2 3 4 5

PCSS

FT

HFTS

ms

GTX Titan X Resolution: 1920x1080

Page 64: Advanced Geometrically Correct Shadows for Modern Game …

64 gameworks.nvidia.com

GFSDK Shadow Lib v3.0

Page 65: Advanced Geometrically Correct Shadows for Modern Game …

65 gameworks.nvidia.com

GFSDK Shadow Lib v3.0

•Lots of shadow techniques (PCF, PCSS, RT, HRTS, FT, HFTS)

•Handles spot and directional lights with cascades

•Offers SDSM or user defined cascades

• Industry leading shadow quality

•Why not HFTS your game...?

Page 66: Advanced Geometrically Correct Shadows for Modern Game …

66 gameworks.nvidia.com

References

•“Frustum-Traced Raster Shadows: Revisiting Irregular Z-Buffers” – i3D 2015 Chris Wyman, Aaron Lefohn, Rama Hoetzlein

•“Hybrid Ray Traced Shadows” - GDC 2015 Jon Story

•“Sub-Pixel Shadow Mapping” - ACM i3D 2014 Pascal Lecocq, Jean-Eudes Marvie, Gael Sourimant, Pascal Gautron

•“GPU Gems 2: Conservative Rasterization” Jon Hasselgren, Tomas Akenine-Möller, Lennart Ohlsson

Special Thanks •Anders Holmquist and team at MASSIVE

Page 67: Advanced Geometrically Correct Shadows for Modern Game …

67 gameworks.nvidia.com

Questions?

[email protected]