THE DEVIL IS IN THE DETAILS
Initial Requirements










Anatomy of a Frame
Frame Cost










Data Structure for Lighting & Shading









Preparing Clustered Structure




 𝑍𝑆𝑙𝑖𝑐𝑒 = 𝑁𝑒𝑎𝑟𝑧 × (
𝐹𝑎𝑟𝑧
𝑁𝑒𝑎𝑟𝑧
)
𝑠𝑙𝑖𝑐𝑒
𝑛𝑢𝑚 𝑠𝑙𝑖𝑐𝑒𝑠




Preparing Clustered Structure






//Pseudo-code - 1 job per depth slice ( if any item )
for ( y = MinY; y < MaxY; ++y ) {
for ( x = MinX; x < MaxX; ++x ) {
intersects = N planes vs cell AABB
if ( intersects ) {
Register item
}
}
}
Preparing Clustered Structure













Preparing Clustered Structure
Preparing Clustered Structure
Detailing the World









Detailing the World












Detailing the World

 𝑒0 𝑒1


const float4 albedo = tex2Dgrad( decalsAtlas, uv.xy * scaleBias.xy + scaleBias.zw, uvDDX, uvDDY );
𝑒
𝑒 𝑒
𝑒0 𝑥
𝑒1 𝑥 2 𝑥 𝑥
𝑒0 𝑦
𝑒1 𝑦 2 𝑦 𝑦
𝑒0 𝑧
𝑒1 𝑧 2 𝑧 𝑧
0 0 0 1
0.5
𝑠𝑖𝑧𝑒𝑋
0 0 0.5
0
0.5
𝑠𝑖𝑧𝑒𝑌
0 0.5
0 0
0.5
𝑠𝑖𝑧𝑒𝑍
0.5
0 0 0 1
∙
Detailing the World










Detailing the World
Detailing the World
Detailing the World
Detailing the World
Detailing the World
Detailing the World
Lighting










Lighting
//Pseudocode
ComputeLighting( inputs, outputs ) {
Read & Pack base textures
for each decal in cell {
early out fragment check
Read textures
Blend results
}
for each light in cell {
early out fragment check
Compute BRDF / Apply Shadows
Accumulate lighting
}
}
Lighting












Lighting










Lighting


Lighting

 




 



Transparents






Particle Lighting










Decoupled Particle Lighting










Decoupled Particle Lighting
//Pseudocode – Particle shading becomes something like this
Particles( inputs, outputs ) {
…
const float3 lighting = tex2D( particleAtlas, inputs.texcoord );
result = lighting * inputs.albedo;
…
}
Decoupled Particle Lighting









Particle Light Atlas
Decoupled Particle Lighting

Post-Process
Optimizing Data Fetching ( GCN )








Clustered Lighting Access Patterns
Clustered Lighting Access Patterns
Clustered Lighting Access Patterns
Clustered Lighting Access Patterns
Analyzing the Data







Leveraging Access Patterns










Thread X A B D
Thread Y B C E
Thread Z A C D E
Scalar A B C D E
Special Paths











Dynamic Resolution Scaling









Async Post Processing









GCN Wave Limits Tuning







GCN Register Usage









What’s next ?







Special Thanks








We are Hiring !
Thank you





References














Bonus Slides
Lighting















Deferred Passes









Siggraph2016 - The Devil is in the Details: idTech 666