”it just works”...project background • ~10 months dev time • use dxr in battlefield v • ao...

87
”It Just Works”: Ray-Traced Reflections in ’Battlefield V’ Johannes Deligiannis Jan Schmid EA DICE

Upload: others

Post on 12-Apr-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

”It Just Works”: Ray-Traced Reflections in

’Battlefield V’

Johannes DeligiannisJan Schmid

EA DICE

Page 2: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

* P LACEHOLDER *

* P L A Y G A M E S C O M T R A I L E R O R S I M I L A R *

Page 3: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

TODAY wepresentRaytracing

• Project background

• GPU Raytracing Pipeline

• Engine integration of DXR

• GPU Performance

Page 4: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Battlef ield V

• FPS set in WWII

• Released Nov 2018

• Raytracing work began Dec 2017

• First DXR game released!

Page 5: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

ProjectBackground

• ~10 months dev time

• Use DXR in Battlefield V

• AO

• GI

• Shadows

• Reflect ions

• Engineering

• Yasin Uludag (EA DICE)

• Johannes Del ig iannis (EA DICE)

• Jiho Choi (NVIDIA)

• Pawel Kozlowski (NVIDIA)

• And a bunch of other people! ☺

Page 6: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

MainChallanges

• Not a Tech Demo

• Content is set

• Game in full production

• Scope of Engine changes

• Performance

• Denoising vs Ray Count

• No RTX cards

• Early adopter tax

• API not f ina l

• Dr iver hang/bugs

• BSoD

• No capture too l (Ns ight , P ix )

• But we shipped it☺

Page 7: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

10

Page 8: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

(simple) raytracing pipeline

11

Generate RaysIntersect/Material

DataLight Rays Light Combine

Page 9: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Generate Rays

12

G Buffer

Lookup Texture

*Tomasz Stachowiak and Yasin Uludag, Siggraph 2015. “Stochastic Screen-Space Reflections”

Page 10: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Raytracing

MAGIC

13

Page 11: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Light Rays

14

float4 light(MaterialData surfaceInfo, float3 rayDir) {

foreach (light : pointLights)radiance += calcPoint(surfaceInfo, rayDir, light);

foreach (light : spotLights)radiance += calcSpot(surfaceInfo, rayDir, light);

foreach (light : reflectionVolumes)radiance += calcReflVol(surfaceInfo, rayDir, light);

…}

Page 12: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Light Combine

15

Lit Raster result

Lookup Texture

Page 13: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

unhappy

B a d b a d b a d , v e r y s a d c r y i n g f a c e s

16

Very Noisy

Rays Contribute Less

Sloooow

Page 14: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Improving raytracing pipeline

17

Generate RaysIntersect/Material

DataLight Rays Light Combine

Variable Rate Tracing

Page 15: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Variable Rate Tracing

18

0 .5 .5 0

.5 1 1 .5

0 .5 .5 0

Max Ratio

Normalize

0 .1 .1 0

.1 .2 .2 .1

0 .1 .1 0

Classify

0 128 128 0

128 256 256 128

0 128 128 0

Page 16: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Variable Rate Tracing

19

256 rays 128 rays 64 rays 32 rays

Page 17: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Variable Rate Tracing

20

Success!

- More Rays on Water

- More Rays on grazing

angles

Page 18: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Problem

21

Page 19: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Improving raytracing pipeline

22

Generate RaysIntersect/Material

DataLight Rays Light Combine

Variable Rate Tracing

Ray Binning

Page 20: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Ray Binning

23

Bin Index3Screen Offset

Angle

012

Page 21: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Ray Binning

24

Page 22: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Ray Binning

25

Bin 3011

Bin 3013

Bin 3011

Rays

0

0

1

Local Offsets

2 0 1

Bin 3011 Bin 3012 Bin 3013

AtomicIncrement

Ray 1000

Ray 1001

Ray 1002

Page 23: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Ray Binning

26

2 0 1

Bin 3011 Bin 3012 Bin 3013

0

0

1

Local Offsets

1000 1002 1002

Bin 3011 Bin 3012 Bin 3013

Exclusive Parallel Sum *

*Mark Harris, Shubhabrata Sengupta, and John Owens. “Parallel Prefix Sum (Scan) with CUDA”

Page 24: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Ray Binning

27

0

0

1

Local Offsets

1000 1002 1002

Bin 3011 Bin 3012 Bin 3013

Ray 1000

Ray 1002

Ray 1001

Rays Lookup

Add

Add

Add

Page 25: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Problem

28

Page 26: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Improving raytracing pipeline

29

Generate RaysIntersect/Material

DataLight Rays Light Combine

Variable Rate Tracing

Ray Binning

SSR Hybridization

Page 27: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

SS-Hybridization

30

Rays Hierarchical Screen Space Trace

Miss

Give Up

Rejected

Intersect/Material Data

Material Data

Light Material RadianceMaterial Data

[Stachowiak et al 15] "Stochastic Screen-Space Reflections"

Page 28: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

SS-Hybridization

31

Page 29: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

SS-Hybridization

32

Page 30: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Problem

33

Hit Miss Hit Miss

Raytrace

Hit Hit

Hit Hit

HitHit

Miss

Miss

Miss

Miss

MissMiss

Busy Idle Busy Idle

Light Shader Wavefront

Busy Busy

Busy Busy

BusyBusy

Idle

Idle

Idle

Idle

IdleIdle

Page 31: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Improving raytracing pipeline

34

Generate RaysIntersect/Material

DataLight Rays Light Combine

Variable Rate Tracing

DefragRay Binning

SSR Hybridization

Page 32: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Defrag

35

1 0 1 0 1 1 00 1 1 00

Hit Hit Hit Hit Hit Hit

0 1 1 2 2 3 42 4 5 65

Exclusive Parallel Sum *

*Mark Harris, Shubhabrata Sengupta, and John Owens. “Parallel Prefix Sum (Scan) with CUDA”

Page 33: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Problem

36

Light Shader

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

Busy

2.0ms

Page 34: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Improving raytracing pipeline

37

Generate RaysIntersect/Material

DataPer Cell Light List

LightingLight Combine

Variable Rate Tracing

DefragRay Binning

SSR Hybridization

Light Rays

Page 35: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Per Cell Light Lists

38

Light 3Next

Light 2Next

Light 3Next

Light 1Next

Light 0Next

Page 36: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Problem

39

Page 37: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Improving raytracing pipeline

40

Generate RaysIntersect/Material

DataPer Cell Light List

LightingLight Combine

Variable Rate Tracing

Defrag

Denoise

Ray Binning

SSR Hybridization

Page 38: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Denoising

41

BRDF FilterTemporal

Filter

Reuse Spatial Information

Reuse Temporal

Information

[Stachowiak et al 15] "Stochastic Screen-Space Reflections"

Page 39: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

BRDF Denoise Filter

42

Kernel Size????𝐿0 ≈ 𝐹𝐺σ𝑘=1𝑁 𝐿𝑖 𝑙𝑘 𝑓𝑠 𝑙𝑘 → 𝑣 cosΘ𝑙𝑘

𝑝𝑘

σ𝑘=1𝑁

𝑓𝑠 𝑙𝑘 → 𝑣 cosΘ𝑙𝑘𝑝𝑘

Page 40: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

BRDF Denoise Filter

43

?????

Page 41: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

BRDF Denoise Filter

44

Page 42: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

BRDF Denoise Filter

45

Frame N

Frame N -1

Page 43: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

BRDF Denoise Filter

46

Thread Thread

Thread

Thread

Thread

Thread

Thread

Thread Thread

Thread

Thread

Thread

Thread

Thread

Thread

Thread

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad

Pad Pad Pad Pad Pad PadPad Pad

Pad Pad Pad Pad Pad PadPad Pad

Pad Pad Pad Pad Pad PadPad Pad

Pad Pad Pad Pad Pad PadPad Pad

Actual: 6

Actual: 6

Actual: 16

Actual: up to 13

Page 44: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

BRDF Denoise Filter

47

Page 45: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Temporal Denoise Filter

48

Is it a good sample?

If only...BRDF Denoiser!

Page 46: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

temporal Denoise Filter

49

Still Noisy

Page 47: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Image Denoise Filter

50

Generate LUT { angle, roughness }

to{ width, height }

for unit length ray

Page 48: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Image Denoise Filter

51

∗ =

Page 49: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Image Denoise Filter

52

∗ =1

2

1

2

Page 50: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Image Denoise Filter

53

Page 51: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

New Pipeline

54

Variable Rate Tracing

0.37ms

Generate Rays

0.19ms

Ray Binning

0.15ms

Screen Space Hybrid

0.36ms

Intersect/ Material Data

1.98ms

Page 52: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

New Pipeline

55

Intersect/ Material Data

1.98ms

Defrag

0.08ms

‘Improved’Lighting

0.46ms

Spatial Filter

1.45ms

Temporal Filter

0.24ms

Image Filter

1.00ms

6.29ms total

Page 53: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

56

Page 54: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

D X R – a . k . a ” B L A C K B O X ”

Intersection ShadingNo DXR

Page 55: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

DXR bas ics

• BLAS - Bot tom Leve l

Acce le ra t ion S t ruc ture

• TLAS - Top Leve l

Acce le ra t ion S t ruc ture

• CS

• S k i n n i n g , D e s t r u c t i o n

• C o m p u t e s h a d e r

• U p d a t e e a c h f r a m e

• B l a s c a n u p d a t e i n c r e m e n t a l l y

𝑐1,1 ⋯ 𝑐4,1⋮ ⋱ ⋮

𝑎1,4 ⋯ 𝑐4,4𝑏1,1 ⋯ 𝑏4,1⋮ ⋱ ⋮

𝑎1,4 ⋯ 𝑏4,4

𝑎1,1 ⋯ 𝑎4,1⋮ ⋱ ⋮

𝑎1,4 ⋯ 𝑎4,4

𝑑1,1 ⋯ 𝑑4,1⋮ ⋱ ⋮

𝑑1,4 ⋯ 𝑑4,4

x

x

TLAS

A

D BC A

A

D CS

BLAS

D BC A

A

D

Page 56: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

ACCELERAT ION STRUCTURE

• Which objects?

• Frustum Cul l ing

• Occlusion Cul l ing

• Easy.. . no cul l ing!

Page 57: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Accelerat ion structure – F IRST PASS

• Rotterdam

• 20200 TLAS instances. . .

• 5000 BLAS rebu i lds . . .

• GPU rebu i ld 64 ms ( ! )

Page 58: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

What to do?

• Idea: Reduce instance count

• Use a cul l ing heurist ic

• Accept (some) minor art i facts

Page 59: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Cull ing HEUR IST IC

• Assumtion:

• Far away ob jects not important

• Except for large objects

• Bridge, bu i ld ing etc

• Need some kind of measurement. . .

Page 60: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Cull ing

• Project bounding sphere

• 𝜃 = 𝑡𝑎𝑛𝑟

𝑑

• I f 𝜃°< 𝑇ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 ° : Cul l

𝜃

𝑑

𝑟

Page 61: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

𝜃 = 15°

cull ing

𝜃 = 4°𝑟𝑒𝑓𝑒𝑟𝑒𝑛𝑐𝑒 − 𝑛𝑜 𝑐𝑢𝑙𝑙𝑖𝑛𝑔

Page 62: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

cull ing

𝜃 = 4°𝑟𝑒𝑓𝑒𝑟𝑒𝑛𝑐𝑒 − 𝑛𝑜 𝑐𝑢𝑙𝑙𝑖𝑛𝑔

Culled Objects

Page 63: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

CULL ING - RESULTS

• 4 deg cu l l ing

• 5000 -> 400 BLAS rebu i lds each f rame

• 20000 -> 2800 TLAS instances

• TLAS + BLAS bu i ld (GPU) : 64 ms -> 14 .5 ms

• Pros

• F a s te r

• Cons

• Occas ional popp ing

• Miss ing ob jec ts

Page 64: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

77

Blas updateopt im izat ions

• Still expensive! More ideas:

1. Stagger full and incremental BLAS rebuild

• N f r a m e s i nc r e m e nta l be f o r e f u l l r e bu i l d

2. D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_BUILD

3. Avoid redundant rebuilds

• C he c k C S i np u t ( bo ne m a t r i x )

• 4 0 0 - > 5 0

• Overlap BLAS update with GFX

• G bu f f e r , s ha d o w m a ps

Page 65: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

78

results

• TLAS + BLAS build (GPU): 14.5 ms -> 1.15 ms

• RayGen (GPU): 0.71 ms -> 0.81 ms (staggered refit + flags)

• Much better ☺

Page 66: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

S H A D I N G ( O PA Q U E )

RT ON | SHADING OFF RT ON | SHADING ON

Page 67: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Raytrac ingRequ irements

• Shader output must match!

• ClosestHit Shader

• AnyHit Shader

80

Raster Raytrace

Same?

Page 68: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Shaders in FROSTB ITE

• VS – Handwritten

• PS - Shader Graphs

• Graph -> . h l s l

• Manual conversion... no

• 1000s o f shaders

• Auto VS + PS to HitGroup

81

Page 69: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

PS - ShaderGraph

[shader(”closesthit")]void chMain(){

}

H it shader template

V0 = vsMain(IA0)

V1 = vsMain(IA1)

V2 = vsMain(IA2)

V = lerp(V0, V1, V2, U, V, W)

P = psMain(V)

writePayload(P)

IA2 = iaMain(id + 2)

IA1 = iaMain(id + 1)

IA0 = iaMain(id + 0)

VS – VertexFragmentWorld Space Normal

Vertex bufferUV, Normal

#define ddx(x) x#define ddy(x) x... ¯\_(ツ)_/¯

#define Sample(s, uv) SampleLevel(s, uv, 0)

... ddx/ddy?

...clip?Texture MIP?

Page 70: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

ALPHA TEST ing

84

• AnyH i t Shader :

• I f (A lphaTest (a lphaValue) )

IgnoreHi t ( ) ;

Page 71: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

ALPHA TEST

86

ANY HIT OFF ANY HIT ON

Page 72: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

ALPHA TEST

87

Page 73: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Alpha test ing v ideo

Page 74: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

89

Summary opaque

• Closest Hit Shader

• Always

• Any Hit Shader (Optional)

• Alpha tested

• Compute Shader (Optional)

• Skinn ing, destruct ion etc

Page 75: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

RAY PAYLOAD

struct GbufferPayloadPacked

{

uint data0; // R10G10B10A2_UNORM

uint data1; // R8G8B8A8_SRGB

uint data2; // R8G8B8A8_UNORM

uint data3; // R11G11B10_FLOAT

float hitT; // Ray length

};

• Payload: re turned on ray in tersect ion

• Same format as Gbuffer RTV

• Conta ins Mater ia l Data

• Norma l

• Base Co lo r

• Smoothness

• …e tc

Page 76: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Ver i fy ing correctness

1. Rasterizer output

2. Shoot primary rays in to scene

3. Compare Payload with Gbuffer

4. Non zero output? Bug!

5. Fix bug

92

-

Gbuffer (BaseColor) Reference

Raytraced (BaseColor) Primary Rays

Delta

=

Page 77: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

97

Shader comp i lat ion

• All shaders generated ☺

• ~3000 per level

• ~250 per frame

• Single RT PSO

• Runtime compile times?

Color coded Closest Hit Shaders

Page 78: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Pso generat ion

• Dx12 GFX PSO. . .

• . . . DXR 3000 shaders

• Compi le t imes?

• M a j o r i t y > 1 0 0 m s

• Co ld cache

• 7 m i n 3 0 s e c t h r e a d t i m e

• 6 t h r e a d s : 1 m i n 3 0 s e c

• Warm cache

• 1 m i n 3 0 s e c t h r e a d t i m e

• 6 t h r e a d s : 1 5 s e c

milliseconds

Page 79: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

Part icles

101

Smoke, Fire and Exposions. Important elements in BFV!

Page 80: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

102

Part icles

• Particle = Transparent+Billboard

• Basic algorithm

1. Shoot ray in Opaque TLAS

2. Shoot aga in in Part ic le TLAS

(Max ray length f rom Opaque)

3 . B lend part ic les wi th opaque h i t

Page 81: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

103

• Camera aligned billboards

• Rotate odd particles 90 deg around Y?

THE Problem with Part icles

Billboards visible when viewed from the side.

Page 82: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

104

Ro t at ed b i l l bo ard s

Before: Billboards visible in reflection After: Rotating odd quads produces a more volumetric look

Page 83: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

105

P e r f o r m a n ce

• Accumulate intersections along ray

• 1 rpp => N rpp

• RayGen loop

• Sounds... expensive?

*... init ray using opaqueHitT and currT*

for (hitCount = 0; hitCount < MaxIntersectionCount; ++hitCount)

{

...

ForwardPayloadPacked forwardPayloadPacked;

initForwardPayloadPacked(forwardPayloadPacked);

TraceRay(g_tlasPartices, 0, 0xFF, 0, 1, 0, ray, forwardPayloadPacked);

ForwardPayload forwardPayload = unpackForwardPayload(forwardPayloadPacked);

if (forwardPayload.hitT <= 0.0f) // Miss, tracing done

break;

* ... update ray using forwardPayload.hitT, accumulate color, alpha *

}

RayGen Shader

Page 84: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

106

T H E ( s e co n d ) P r o b l e m w i t h P a r t i c l e s

RayGen loop 0.96ms

Page 85: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

107

O p t i m i z i n g p art i c l es

• Loop Idea: AnyHit shader?

• Same... but different

• Inspired by WBOIT*

• Weight = max( luminance,r ,g,b

alpha)

• Emissive, f i re

... init ray using maxT and currT

TraceRay(g_tlasPartices, 0, 0xFF, 0 , 1, 0, ray, forwardPayloadPacked);

* ... process payload and calculate weighted average *

RayGen Shader

Any Hit Shaderstruct Attributes { float2 barycentrics; };

[shader("anyhit")]

void main(inout ForwardPayloadPacked payloadPacked, in Attributes attributes)

{

*... Calculate color, transparency *

payloadPacked.alpha += alpha * weight

payloadPacked.color += color * weight;

payloadPacked.weight += weight;

IgnoreHit();

}

*Weighted Blended Order-Independent Tranparency: http://jcgt.org/published/0002/02/09/

Page 86: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

109

P art i c l es - RES UL T S

’Naive’ Closest Hit 0.96msSlow but accurate

Order Independent AnyHit 0.34msReally fast, but slightly different look

Page 87: ”It Just Works”...Project Background • ~10 months dev time • Use DXR in Battlefield V • AO • GI • Shadows • Reflections • Engineering • Yasin Uludag (EA DICE) Main

110

THANK YOU!. . .Any Questions?