![Page 1: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/1.jpg)
Percentage-Closer Soft ShadowsPercentage-Closer Soft Shadows
Randima (Randy) FernandoNVIDIA Corporation
![Page 2: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/2.jpg)
DemoDemo
Recorded in Real Time on a GeForce 7800 GTX
![Page 3: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/3.jpg)
Previous WorkPrevious Work
• Fundamentally based on [Williams1978] and [Reeves1987]
• Lots of previous work in this area
• Recent survey of real-time algorithms:
– http://artis.inrialpes.fr/Publications/2003/HLHS03a/
• Related background and references in:
– http://www.randima.com/MastersThesis.pdf
![Page 4: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/4.jpg)
• Shadows harden on contact
• Aliasing is hidden
• Always hard
• Noticeable Aliasing
• Always soft
• Aliasing is hidden
Perceptually-Correct Soft Shadows
Uniform Soft ShadowsRegular Shadow Maps
Algorithm ComparisonAlgorithm Comparison
![Page 5: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/5.jpg)
FeaturesFeatures
• Perceptually-correct soft shadows (good visual cues)
• Runs at real-time rates
• Artifacts vary smoothly (no popping)
• Benefits from shadow mapping features– Independent of geometric complexity
– Works with alpha testing, displacement mapping, etc…
• Integrates easily– Single floating-point shadow map and one shader
– No special steps, preprocessing, etc…
![Page 6: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/6.jpg)
A Simple SceneA Simple Scene
Light
Receiver
Blocker
![Page 7: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/7.jpg)
Point Light vs. Area LightPoint Light vs. Area Light
Point Light Area Light
Umbra UmbraPenumbra
![Page 8: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/8.jpg)
• Extension to shadow mapping
• How Percentage-Closer Filtering (PCF) works:
Percentage-Closer FilteringPercentage-Closer Filtering
Pixel to be Shaded
4-Sample PCF
Perform 4 Depth Tests
Typical Shadow Map Test
Shaded Pixel(Black or White)
Shaded Pixel(0, 0.25, 0.50, 0.75, 1.0)
![Page 9: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/9.jpg)
Basic IdeaBasic Idea
• Control shadow softness with PCF kernel width
Large Kernel(Wide Filter)
Small Kernel(Narrow Filter)
![Page 10: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/10.jpg)
Penumbra EstimationPenumbra Estimation
• Vary amount of softening– Based on penumbra size
• Penumbra size estimate based on:– Blocker depth
– Receiver depth
– Light size
![Page 11: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/11.jpg)
• Equation comes from similar triangles
• Assumes that blocker, receiver, and light are parallel
wPenumbra = (dReceiver – dBlocker) ⋅ wLight
dBlocker
Penumbra Size EstimationPenumbra Size Estimation
![Page 12: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/12.jpg)
• We need:– Distance from receiver to light source
Depth of the point we’re shading
– Light size Uniform input to the shader
– Distance from blocker to light source Don’t know this… yet.
wPenumbra = (dReceiver – dBlocker) ⋅ wLight
dBlocker
Penumbra Size EstimationPenumbra Size Estimation
![Page 13: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/13.jpg)
Main AlgorithmMain Algorithm
• Generate a shadow map from center of light source (as usual)
• When shading each pixel on the screen:– Blocker Search
– Penumbra Size Estimation
– Variable Percentage-Closer Filtering
![Page 14: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/14.jpg)
Blocker SearchBlocker Search
• Search region depends on light size and distance to light
Light
Shadow Map
Scene
![Page 15: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/15.jpg)
Blocker SearchBlocker Search
• Sample the texels in the search region
• Do something with the depth values…
Shadow Map
![Page 16: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/16.jpg)
What to do with Blockers?What to do with Blockers?
• Take minimum?– Artifacts when transitioning between blockers
• Need some kind of average– Average all blockers (depth < receiver)
– Flag the case if no blockers were found• Fully lit – no need to perform filtering
– Gives good results
![Page 17: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/17.jpg)
• We now have what we need:– Distance from receiver to light source
Depth of the point we’re shading
– Light size Uniform input to the shader
– Distance from blocker to light source Result of blocker search
• Estimate penumbra per pixel:
• Change PCF kernel based on the result
Penumbra Size EstimationPenumbra Size Estimation
wPenumbra = (dReceiver – dBlocker) ⋅ wLight
dBlocker
wPenumbra = (dReceiver – dBlocker) ⋅ wLight
dBlocker
![Page 18: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/18.jpg)
Variable PCFVariable PCF
• Use a flexible PCF kernel that can vary:– Filter width
– Number of samples
• Vary kernel parameters based on penumbra estimate– Actually, projection of penumbra in
screen space (but not yet implemented)
![Page 19: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/19.jpg)
Blocker Search ResultsBlocker Search Results
![Page 20: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/20.jpg)
Penumbra EstimatesPenumbra Estimates
![Page 21: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/21.jpg)
After Percentage-Closer FilteringAfter Percentage-Closer Filtering
![Page 22: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/22.jpg)
PerformancePerformance
• Up to 191 fps @ 640 x 480in a standalone application
• <10% hit to add 4xAA, 8xAF on GeForce 7800 GTX
• 292 texture fetches/pixel = ~900 cycles/pixel = 60 fps!
6800 7800 GTX 7800 GTX SLISearch PCF Total 12 pipes 24 pipes 48 pipes
36 + 36 = 72 49 104 191
36 + 64 = 100 35 75 141
36 + 256 = 292 13 31 60# SA
MPL
ES
FPS
![Page 23: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/23.jpg)
Performance CharacteristicsPerformance Characteristics
• Scales very well with number of pipes
• Each blocker search sample is ~30% more expensive than each PCF sample
• 36 search samples works well for most scenes
• 64 PCF samples works great with a reasonably complex texture
![Page 24: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/24.jpg)
Performance ImprovementsPerformance Improvements
• Mask out umbras and fully-lit regions– Pass 1: Estimate penumbras– Pass 2: Perform PCF only where penumbra exists
• Vectorize– Much of the code is very scalar– Can try to work on 4 texels simultaneously
• Profiling/tuning
![Page 25: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/25.jpg)
Quality ImprovementsQuality Improvements
• Better blocker search heuristics– 5 shadow maps (4 corners + center of light)– Estimate penumbra using all five– Filter using center shadow map only
• Better filtering to remove banding in large penumbras– Add offset jitter for samples– Screen-space blur to save on PCF work– Combine filtering from several resolutions of shadow maps?
![Page 26: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/26.jpg)
Quality ImprovementsQuality Improvements
• Take advantage of NVIDIA’s hardware PCF– 32-bit floating-point shadow map for analysis
– 24-bit integer shadow map for filtering
– Small performance hit for large quality improvement
With HW Filtering Without HW Filtering
![Page 27: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/27.jpg)
Parting ThoughtsParting Thoughts
• Algorithm is completely encapsulated in one shader file for easy integration
• Try it out – please let me know what you find
• Tweak “Near Plane Distance” (in world units) and “Shadow Map Bias” to match your scene
• Applications: DCC/CAD applications, pre-visualization, future games
![Page 28: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/28.jpg)
Thanks to…Thanks to…
• Kevin Bjorke, whose basic PCF shader I started with
• Chris Maughan and the FX Composer team for making shader development so easy
• Various folks at NVIDIA, and especially Matthias Wloka, for comments and suggestions
![Page 29: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/29.jpg)
Suggestions/Questions WelcomeSuggestions/Questions Welcome• Slides, short whitepaper, code, and video for this FX
Composer effect are in the NVIDIA SDK: http://download.developer.nvidia.com/developer/SDK/Individual_Samples/featured_effects.html#PCSS
• A standalone code sample is coming soon
• E-mail: [email protected]
![Page 30: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/30.jpg)
Percentage-Closer Soft ShadowsPercentage-Closer Soft Shadows
Randima (Randy) FernandoNVIDIA Corporation
![Page 31: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/31.jpg)
ExtrasExtras
![Page 32: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/32.jpg)
A Simple SceneA Simple Scene
![Page 33: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/33.jpg)
Shadows from a Point LightShadows from a Point Light
Umbra
![Page 34: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/34.jpg)
Shadows from an Area LightShadows from an Area Light
![Page 35: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/35.jpg)
Shadows from an Area LightShadows from an Area Light
Umbra
![Page 36: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/36.jpg)
Shadows from an Area LightShadows from an Area Light
Penumbra Penumbra
![Page 37: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/37.jpg)
Shadows from an Area LightShadows from an Area Light
Fully Lit Fully Lit
![Page 38: Percentage-Closer Soft Shadowsdownload.nvidia.com/.../Percentage_Closer_Soft_Shadows.pdf · 2017-04-28 · Features • Perceptually-correct soft shadows (good visual cues) • Runs](https://reader030.vdocument.in/reader030/viewer/2022040823/5e6e562dc773b3021c625fe6/html5/thumbnails/38.jpg)
Point Light vs. Area LightPoint Light vs. Area Light
Point Light Area Light
Umbra UmbraPenumbra