GAMES202 Lecture 03 - Real-Time Shadows 1

GAMES202_Lecture_03 (ucsb.edu)

image-20230728211702865

I. Shadow Mapping

Reference: Real-Time Rendering, 4th Edition

The idea of shadow mapping is to render the scene, using the z-buffer, from the position of the light source that is to cast shadows. Whatever the light sees is illuminated, and the rest is in shadow.

To use the shadow mapping, the scene is rendered a second time (Pass 2), but this time with respect to the viewer. As each drawing primitive is rendered, its location at each pixel is compared to the shadow mapping. If a rendered point is farther away from the light source than the corresponding value in the shadow mapping, that point is in shadow. Otherwise, it is not.

Recap

Shadow Mapping is:

 

Pass 1Pass 2APass 2B
image-20230728161919985image-20230728161944563image-20230728161959964
Depth ViewEye's View (Depth)
image-20230728163359092image-20230728163419528

 

image-20230728162145321

Cautions

The definitions of z value used in shadow mapping and in depth-test must be consistent.

 

Common Issues and Solutions

Self Occlusion

image-20230728164647761

 

Adding a (variable) bias to reduce self occlusion

Now the shadow occurs only if the difference exceeds certain threshold:

ΔdThreshold

image-20230728164740245

 

Second-Depth Shadow Mapping

Store the second-minimum depth when generating the shadow map.

image-20230728165033670

Assume the light source is directly above.

 

Aliasing

image-20230728165118670

 

II. The Math behind Shadow Mapping

Approximating the Rendering Equation

In real-time rendering, we care about fast and accurate approximation. (Approximately equal)

An important approximation throughout RTR:

Ωf(x)g(x)dxΩf(x)dxΩdxThe average valueof f(x) over the intervalΩg(x)dx

 

The rendering equation with term V(p,ωi) for explicit visibility

(1)Lo(p,ωo)=Le(p,ωo)+Ω+Li(p,ωi)fr(p,ωi,ωo)(nωi)V(p,ωi)dωi

can be approximated as, if not considering term regarding to self-emittance,

Lo(p,ωo)Ω+V(p,ωi)dωiΩ+dωiΩ+Li(p,ωi)fr(p,ωi,ωo)cosθidωiDo shading directly without considering visibility

Will be reviewed again when discussing Ambient Occlusions.

 

III. Percentage Closer Filtering (PCF) and Percentage Closer Soft Shadows (PCSS)

image-20230728180618799

 

Percentage Closer Filtering

 

The Algorithm

Compute the visibility term in the rendering equation:

  1. Instead of performing a single query, perform multiple (e.g., 7×7) depth comparisons for each fragment:

    • Method: In the shadow map (figure below), query the neighboring region of point P on the shadow map

    • Querying the fragment: the farther the fragment is to the light source, the blurrier its corresponding shadow will be.

  1. Then, averages the results of comparisons.

For example:

image-20230728181322513

image-20230728181503347

Wrong example: filtering on the result

image-20230731170653958

Problems

 

Percentage Closer Soft Shadows

image-20230728182327005

image-20230728182053622

 

PCSS - The Complete Algorithm

  1. Blocker Search:

    • Get the average blocker depth in a certain region inside the shadow map:

      • In a region, what is the average depth of the area that covers the shading point?

  2. Penumbra Estimation:

    • Use the average blocker depth to determine filter size

  3. Percentage Closer Filtering

 

Problems

image-20230731172655220

Video Game: Dying Light