Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aaron Schultz. Idea: Objects close to a light shadow those far away. Anything we can see from the light’s POV is lit. Everything hidden is dark. Distance.

Similar presentations


Presentation on theme: "Aaron Schultz. Idea: Objects close to a light shadow those far away. Anything we can see from the light’s POV is lit. Everything hidden is dark. Distance."— Presentation transcript:

1 Aaron Schultz

2 Idea: Objects close to a light shadow those far away. Anything we can see from the light’s POV is lit. Everything hidden is dark. Distance from light = Depth Render a depth map! How to render shadows?

3 Pass 1: From light’s POV, render scene into a texture. Each pixel stores depth information. Pass 2: From camera POV, render scene to screen. For each pixel, compute position in light space. Compare stored depth (from pass 1) to current depth. if( distanceToLight > storedDistance ) //Hidden by occluder In Shadow = true What is shadow mapping?

4 Light Space Camera Space

5 It’s never that easy…

6 Aliasing = Really bad jaggies Shadow map texels  Not 1:1  camera pixels Poor Precision = Banding, speckles, noise How do we store depth? 16-bit? 32-bit? Floating-point? Fixed- point? Different depths mapped to same value Rounding errors What’s so difficult?

7 Blur the shadow map or use hardware filtering Still doing a binary compare = hard edges Constant depth bias Helps prevent “shadow acne” caused by precision errors Doesn’t work well with the stretched shadow map (different bias needed at different points) Causes Peter Panning Naïve Solutions From Common Techniques to Improve Shadow Depth Maps, MSDN

8 Getting Smarter…

9 Cascaded Shadow Maps Put precision where we need it: close to the camera Split camera frustum into pieces Render separate shadow map for each sub-frustum Really Smart… Cascaded Shadow Maps, MSDN

10 What I Want: RG32 (2 channel, 16-bit per channel), HW filterable, for VSM R32F (1 channel, 32-bit), HW filterable, for Basic and ESM What I Get: Hardware filtering on floating-point formats disabled in XNA 4.0 (because actual support is only on Nvidia 8-series cards and up) RG32 format (for VSM) unsupported on my machine Access to… RGBA1010102 Color (4 8-bit channels) All floating-point formats Requires encoding VSM and ESM into Color to permit HW filtering (which is then mathematically wrong)  Implementation Notes

11 Normalize all depth values to [0,1] in the shader. Makes everything easier. Remember the DirectX9 ½ pixel offset So many places to mess up Lots of converting between coordinate systems Viewport settings, texture wrapping Check hardware capabilities! Get it to work first. Then optimize. ESM not widely documented on the web Most people do PCF wrong. Interpolation required! XNA lets you focus on the algorithms (most of the time) Implementation Notes

12 (Demo) Let’s see the goods


Download ppt "Aaron Schultz. Idea: Objects close to a light shadow those far away. Anything we can see from the light’s POV is lit. Everything hidden is dark. Distance."

Similar presentations


Ads by Google