”It Just Works”: Ra Ray-Trace Traced d Re Refl flect ctio ions ns in in ’Battlefield V’
Johannes Deligiannis Jan Schmid EA DICE
Ra Ray-Trace Traced d Re Refl flect ctio ions ns in in - - PowerPoint PPT Presentation
It Just Works: Ra Ray-Trace Traced d Re Refl flect ctio ions ns in in Battlefield V Johannes Deligiannis Jan Schmid EA DICE *PL ACEHOL DER* * PLAY GAMESCOM TRAILER OR SIMILAR * TODAY we present Raytracing Project
Johannes Deligiannis Jan Schmid EA DICE
*PL ACEHOL DER*
* PLAY GAMESCOM TRAILER OR SIMILAR *
TODAY we present Raytracing
Battlefield V
Project Background
Main Challanges
10
11 Generate Rays Intersect/Material Data Light Rays Light Combine
12 G Buffer
Lookup Texture
*Tomasz Stachowiak and Yasin Uludag, Siggraph 2015. “Stochasti hastic c Screen en-Space Space Reflect ection ions”
13
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); … }
15 Lit Raster result
Lookup Texture
Bad bad bad, very sad crying faces
16 Very Noisy Rays Contribute Less Sloooow
Improving raytracing pipeline
17 Generate Rays Intersect/Material Data Light Rays Light Combine Variable Rate Tracing
18 .5 .5 .5 1 1 .5 .5 .5 Max Ratio Normalize .1 .1 .1 .2 .2 .1 .1 .1 Classify
128 128 128 256 256 128 128 128
19 256 rays 128 rays 64 rays 32 rays
20
Success!
angles
21
Improving raytracing pipeline
22 Generate Rays Intersect/Material Data Light Rays Light Combine Variable Rate Tracing Ray Binning
23 Bin Index
Screen Offset Angle
24
25 Bin 3011 Bin 3013 Bin 3011 Rays 1 Local Offsets 2 1 Bin 3011 Bin 3012 Bin 3013 Atomic Increment Ray 1000 Ray 1001 Ray 1002
26 2 1 Bin 3011 Bin 3012 Bin 3013 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”
27 1 Local Offsets 1000 1002 1002 Bin 3011 Bin 3012 Bin 3013 Ray 1000 Ray 1002 Ray 1001 Rays Lookup Add Add Add
28
Improving raytracing pipeline
29 Generate Rays Intersect/Material Data Light Rays Light Combine Variable Rate Tracing Ray Binning SSR Hybridization
30
Rays
Hierarchical Screen Space Trace Miss Give Up Rejected Intersect/Material Data Material Data Light Material
Radiance
Material Data [Stachowiak et al 15] "Stochastic Screen-Space Reflections"
31
32
33 Hit Miss Hit Miss Raytrace Hit Hit Hit Hit Hit Hit Miss Miss Miss Miss Miss Miss Busy Idle Busy Idle Light Shader Wavefront Busy Busy Busy Busy Busy Busy Idle Idle Idle Idle Idle Idle
Improving raytracing pipeline
34 Generate Rays Intersect/Material Data Light Rays Light Combine Variable Rate Tracing Defrag Ray Binning SSR Hybridization
35 1 1 1 1 1 1 Hit Hit Hit Hit Hit Hit 1 1 2 2 3 4 2 4 5 6 5 Exclusive Parallel Sum * *Mark Harris, Shubhabrata Sengupta, and John Owens. “Parallel Prefix Sum (Scan) with CUDA”
36 Light Shader Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy Busy
Improving raytracing pipeline
37 Generate Rays Intersect/Material Data Per Cell Light List Lighting Light Combine Variable Rate Tracing Defrag Ray Binning SSR Hybridization Light Rays
38 Light 3 Next Light 2 Next Light 3 Next Light 1 Next Light 0 Next
39
Improving raytracing pipeline
40 Generate Rays Intersect/Material Data Per Cell Light List Lighting Light Combine Variable Rate Tracing Defrag Denoise Ray Binning SSR Hybridization
41
BRDF Filter Temporal Filter
Reuse Spatial Information Reuse Temporal Information
[Stachowiak et al 15] "Stochastic Screen-Space Reflections"
42 Kernel Size???? 𝑀0 ≈ 𝐺𝐻 σ𝑙=1
𝑂
𝑀𝑗 𝑚𝑙 𝑔
𝑡 𝑚𝑙 → 𝑤 cos Θ𝑚𝑙
𝑞𝑙 σ𝑙=1
𝑂
𝑔
𝑡 𝑚𝑙 → 𝑤 cos Θ𝑚𝑙
𝑞𝑙
43
?????
44
45 Frame N Frame N -1
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 Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad Pad
Actual: 6 Actual: 6 Actual: 16 Actual: up to 13
47
48 Is it a good sample? If only... BRDF Denoiser!
49
50 Generate LUT { angle, roughness } to { width, height } for unit length ray
51
52
53
54 Variable Rate Tracing 0.37ms Generate Rays 0.19ms Ray Binning 0.15ms Screen Space Hybrid 0.36ms Intersect/ Material Data 1.98ms
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
56
D XR – a.k .a ” BLAC K BO X”
Intersection Shading No DXR
DXR b asi cs
Acceleration Structure
Acceleration Structure
𝑑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 B C A A D
CS
BLAS
D B C A A D
ACCEL ERATI ON STRUCTURE
Accel erati on structure – F I RST P A SS
W hat to do?
Cul l i ng HEURI STI C
Cul l i ng
𝑠 𝑒
𝜄 𝑒 𝑠
𝜄 = 15°
cul l i ng
𝜄 = 4° 𝑠𝑓𝑔𝑓𝑠𝑓𝑜𝑑𝑓 − 𝑜𝑝 𝑑𝑣𝑚𝑚𝑗𝑜
cul l i ng
𝜄 = 4° 𝑠𝑓𝑔𝑓𝑠𝑓𝑜𝑑𝑓 − 𝑜𝑝 𝑑𝑣𝑚𝑚𝑗𝑜 Culled Objects
CUL L I NG - RESUL TS
77
B l as update
1. Stagger full and incremental BLAS rebuild
2. D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_BUILD 3. Avoid redundant rebuilds
78
resul ts
SH AD IN G ( OPAQU E)
RT ON | SHADING OFF RT ON | SHADING ON
Raytraci ng Requi rements
80 Raster Raytrace Same?
Shaders i n F ROSTB I TE
81
PS - ShaderGraph
[shader(”closesthit")] void chMain() { }
Hi t shader templ ate
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 – VertexFragment World Space Normal Vertex buffer UV, Normal
#define ddx(x) x #define ddy(x) x
... ¯ \_(ツ)_/¯
#define Sample(s, uv) SampleLevel(s, uv, 0) ... ddx/ddy?
Texture MIP?
AL PHA TESTi ng
84
IgnoreHit();
AL PHA TEST
86 ANY HIT OFF ANY HIT ON
AL PHA TEST
87
Al pha testi ng vi deo
89
Summary opaque
RAY PAYL OAD
struct GbufferPayloadPacked { uint data0; // R10G10B10A2_UNORM uint data1; // R8G8B8A8_SRGB uint data2; // R8G8B8A8_UNORM uint data3; // R11G11B10_FLOAT float hitT; // Ray length };
Veri f yi ng correctness
92
Reference Raytraced (BaseColor) Primary Rays
Delta
=
97
Shader compi l ati on
Color coded Closest Hit Shaders
P so generati on
milliseconds
Parti cl es
101 Smoke, Fire and Exposions. Important elements in BFV!
102
Parti cl es
(Max ray length from Opaque)
103
THE Prob l em w i th Parti cl es
Billboards visible when viewed from the side.
104 R o t a t e d b i l l b o a r d s Before: Billboards visible in reflection After: Rotating odd quads produces a more volumetric look
105 P e r f o r m a n c e
*... 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
106 T H E ( s e c o 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
107 O p t i m i z i n g p a r t i c l e s
alpha)
... 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 Shader
struct 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 tp:/ ://jcg /jcgt.or t.org/p g/publish lished/ ed/00 0002/0 02/02/09/ 2/09/
109 P a r t i c l e s - R E S U L T S ’Naive’ Closest Hit 0.96ms Slow but accurate Order Independent AnyHit 0.34ms Really fast, but slightly different look
1 1
...Any Questions?