- Unity 2021.3 or later
- GPU with compute shader support (DX11+, Vulkan, Metal)
- Basic understanding of Unity and C#
File > New Scene > 3D (URP or Built-in)
- Select Main Camera
- Add Component:
Virtual Shadow Map Manager - Add Component:
Simple Controller(for movement)
- Create Directional Light (if not exists)
- Drag into
Directional Lightfield on VSM Manager - Rotate to desired angle (e.g., 45 degrees)
In VSM Manager component, assign:
- Free Invalidated Pages:
VSMFreeInvalidatedPages.compute - Mark Visible Pages:
VSMMarkVisiblePages.compute - Allocate Pages:
VSMAllocatePages.compute - Clear Pages:
VSMClearPages.compute - Build HPB:
VSMBuildHPB.compute - VSM Depth Shader:
VSMDepthRender.shader
GameObject > 3D Object > Plane
Scale: (10, 1, 10)
Material: Create new material with VSM/ShadowReceiver shader
GameObject > 3D Object > Cube
Position: (0, 0.5, 0)
Material: Create new material with VSM/ShadowReceiver shader
GameObject > 3D Object > Sphere
Position: (2, 1, 0)
Material: Use same VSM shadow receiver material
For each material using VSM shadows:
- Shader:
VSM/ShadowReceiver - Set base color/texture
- Adjust Shadow Strength (0.5 default)
- Press Play
- Use WASD to move, QE for up/down
- Hold right mouse button and move mouse to look around
- Observe real-time shadows updating
✓ Smooth, high-quality shadows ✓ No visible cascades (seamless transition) ✓ Minimal aliasing artifacts ✓ Good performance (3-7ms overhead)
Problem: Scene is lit but no shadows appear
Solutions:
- Check Directional Light is assigned in VSM Manager
- Ensure materials use
VSM/ShadowReceivershader - Verify all compute shaders are assigned
- Check Console for errors
Problem: Objects render as black or pink
Solutions:
- Verify shader compiles without errors
- Check all texture samplers are correctly named
- Ensure compute shaders have required kernels
- Try reimporting shaders
Problem: Frame rate drops significantly
Solutions:
- Reduce cascade count in
VSMConstants.cs - Increase page size (256×256 instead of 128×128)
- Reduce physical page pool size
- Check GPU compute capability
Problem: Flickering or incorrect shadows
Solutions:
- Increase shadow bias in sampling (default 0.001)
- Adjust first cascade size (try 1.0 or 4.0)
- Enable debug visualization to check cascade selection
- Verify page allocation is working correctly
- W/A/S/D: Move forward/left/back/right
- Q/E: Move down/up
- Right Mouse + Move: Look around
- Left Shift: Sprint (faster movement)
-
First Cascade Size (VSM Manager):
- Smaller (0.5-1.0): Better close-up detail
- Larger (4.0-8.0): Better distant shadows
-
Shadow Strength (Material):
- 0.0: No shadows
- 1.0: Fully black shadows
- 0.5: Realistic soft shadows
-
Filter Size (Edit
VSMSampling.hlsl):- Increase for softer shadows
- Decrease for sharper shadows
- Create objects with Rigidbodies
- Watch shadows update in real-time
- Observe page caching efficiency
- Enable
Debug Visualizationin VSM Manager - See memory usage and cascade info
- Create custom visualizations:
- Cascade selection overlay
- Page state heatmap
- Physical memory view
Edit VSMConstants.cs:
public const int CASCADE_COUNT = 8; // Reduce from 16
public const int PAGE_SIZE = 256; // Increase from 128
public const int MAX_PHYSICAL_PAGES = 1024; // Reduce from 2048Edit VSMConstants.cs:
public const int PAGE_TABLE_RESOLUTION = 64; // Increase from 32
public const int FIRST_CASCADE_SIZE = 1.0f; // Decrease for more detailIn VSMShadowReceiver.shader:
// Replace shadow attenuation line with:
float3 shadowColor = float3(0.3, 0.3, 0.5); // Blueish shadows
float shadowAttenuation = lerp(shadowColor, 1.0, shadow);Combine VSM with screen-space AO for enhanced depth perception.
Use VSM for primary directional light, traditional shadow maps for additional lights.
VirtualShadowMapManager (Main Component)
├── VSMPageTable (Virtual page tracking)
├── VSMPhysicalPageTable (Physical page tracking)
├── VSMPhysicalMemory (Shadow depth storage)
└── VSMHierarchicalPageBuffer (Culling optimization)
Pipeline:
1. Bookkeeping → Mark visible pages, allocate memory
2. Drawing → Render depth to allocated pages
3. Sampling → Read shadows in materials
- Read
README.mdfor complete technical details - Study
IMPLEMENTATION_NOTES.mdfor paper analysis - Examine shader code for low-level implementation
- Check GPU Zen 3 book for original algorithm
For issues with this implementation:
- Check console for errors
- Verify all assets are properly assigned
- Review shader compilation logs
- Test on different hardware if possible
For questions about the algorithm:
- Refer to GPU Zen 3 paper
- Check Unreal Engine 5 documentation
- Study cascaded shadow map techniques
Implementation based on GPU Zen 3 "Virtual Shadow Maps" paper by:
- Matej Sakmary
- Jake Ryan
- Justin Hall
- Alessio Lustri
Inspired by Unreal Engine 5's VSM implementation.
Ready to explore Virtual Shadow Maps? Press Play and enjoy high-quality real-time shadows!