VSM Doc

What is virtual shadow map

Shadow mapping is a technique that begins by generating a depth map from the light's point of view. It then calculates the shadow mask by comparing the pixel depth in the light camera space against the value in the shadow map. However, when it comes to supporting large areas with fine details, traditional shadow maps have a problem due to limitations in VRAM sizes available on modern GPUs. A shadow map that is big enough to cover the whole visible area requires more memory. To address this issue, the virtual shadow map divides the shadow maps into clipmaps. The nearest objects are rendered into clipmaps with higher detail, while objects in the distance are rendered into clipmaps with lower detail. The clipmaps are divided into fixed-size pages, and pages are only allocated when inside the camera frustum. Please refer to Figure 1 for more details. Note that only clipmap areas with checkerboard patterns allocate memory.

How to integrate it into your project

  1. Import Virtual shadow map package into the project.
  1. Set all shadow reciever object shader to Resources/VSMLit

3. Add virtual shadow render feature to renderer settings.

4. In volume settings, add Shadow/Virtual shadow map setting.

  1. In volume settings, check Enable Vsm. Virtual shadow map should work in Forward render path now.

Deferred Render Path To support deferred render path you will have to modify URP source code.

  1. Find ShaderLibrary/Shadows.hlsl in URP package.
  1. Add the vsm resource definition code to Shadows.hlsl:

3. Find MainLightShadow function in Shadows.hlsl and add vsm sampling code:

Parameters

Render feature parameters First Level: Log2 size of the smallest clipmap in world space. Last Level: Log2 size of the biggest clipmap in world space. IsForward: Check this if forward render path is used. Otherwise please uncheck it.

Volume parameters Enable Vsm: If virtual shadow map is enabled. Shadow Softness: Softness of the shadow. Shadow Min View Range: Minimal view range of the clipmap shadow camera. Shadow Bias: Bias for solving float point precision bug in shadow map algorithms. Enable page debug: Shadow page debug view.

Advanced topics

Use your own material shaders Instead of using Resources/VSMLit, you can use your own shaders for Vsm shadow receiver objects. However you will need to copy VSMDepth pass into your own shader. The code can be found in Resources/VSMLit

Note that VSMLit is just a sample shader and not required for core VSM features, it’s also URP version dependent. https://github.com/IceCode2016/VSM_Shaders provides VSMLit shaders for different versions of URP. I will keep that repository updated.