Fast Cascade VSM By Zhang Jian Dynamic Shadow
Fast Cascade VSM By Zhang Jian
Dynamic Shadow Tech Basic Algorithm Shadow Volume Shadow Map Soft Shadow PCF VSM Perspective Alias PSM Li. PSM Cascade Selection Rendering Stage PSSM CSM TSM 2 D CSM Per Object Shadow ESM CSM 3 D CSM Deferred Shadow
Outline 1. Basic Shadow Map and problems 2. Variance Shadow Map 3. Cascade Shadow Map In Our Engine 4. Shadow Mask
1. Shadow Map • Basic Idea: If a light can see a point, the point will be lit by the light.
1. Shadow Map 1. Render a texture by using light as a camera, that’s shadow map, the pixel value is depth value. 2. Transform the current position into shadow map space (light space), test if it’s occluded by corresponding shadow map pixel. 3. Done! ?
1. Shadow Map Peter panning Perspective Alias
1. Shadow Map Peter panning Self-shadow Acne
1. Shadow Map Peter Panning
1. Shadow Map Hard Edge
1. Shadow Map Dynamic Alias: • Unstable resolution( PSM) • Edge swimming effect
2. Variance Shadow Map Soft Shadow
2. Variance Shadow Map • Probability theory • dr is the current receiver depth • d 0 is the random variable to represent the occluder depth. Our goal : define some states between shadow and lit.
2. Variance Shadow Map • Chebyshev’s inequality (when dr > μ)
2. Variance Shadow Map • Understand VSM by your way. float d = ( v. Light. Space. Pos. z ) - Depth; float p_Shadow = 1; if (d > 0) { float variance = ( Depth. Square ) - ( Depth * Depth ); p_Shadow = variance / ( variance + d*d ); }
VSM In Our Engine • Render Z and Z 2 into a 2 channels render target – G 16 R 16 ( hardware filter, 1 cycle) – 4 x MSAA on Xenon ( Free, No predict-tilling) – RGBA 8 on PC ( may provide multiple solutions for difference GPU) • Prefilter: 2 pass Gaussian blur • Generate Mipmaps on Xenon. • VSM shadow testing.
2. Variance Shadow Map • The good: – Very cheap Soft shadow: Support Prefilter, Blur == PCF. – Much Better self shadow quality ( solve the shadow bias perfectly) – The ability to use high quality texture filter( trilinear, anistropic filter)
2. Variance Shadow Map • The Bad: Light leaking.
2. Variance Shadow Map • Light leaking. – Reduce Geometry complexity, use Low Lod for shadow caster. – Tune parameters. (remapping the result)
3. Cascaded Shadow Map Resolution problem
Cascaded Shadow Map
Cacade Alignment
Parallel Split Shadow Map
2 D CSM
Z precision problem 3 D CSM
Cacade Coverage Optimization
Cacade Transition
Interlace updating
4. Shadow Mask Just an optimization
4. Shadow Mask
Shadow Mask • Why? – Shadow calculation can increase shader complexity a lot. – For most case, it can avoid overdraw. • More aggressive, Postprocess shadow multiply
Shadow solution
Result • Memory: ~5 M( 3 M Vsm + 2 M shadow mask) • Performance(Shadow. Map+shadow. Mask): – 4 cascade: 2. 3 -4. 5 ms – 3 cascade: 1. 7 -3. 5 ms – 2 cascade: 1. 4 -2. 5 ms – 1 cascade: 1. 0~2. 0 ms
Future Works • Optimization – Special Mesh LOD for shadow. – Unshadow sky Early out. – Shader optimization – Transparency shadow (e. g. . Smoke shadow)
Q&A
Declaration • This is from one of my internal presentations. I implemented the shadow tech in our game engine, and shared tips and explanations here. It’s not an official paper, So I don’t have a reference docs list here,
- Slides: 36