Variance Shadow Maps (VSM) is a modern method of generating shadows in 3D graphics that allows you to create soft, realistic shadows with minimal artifacts characteristic of traditional shadow maps. Classic shadow maps use a depth test to determine whether a point is in shadow, which often results in hard edges, aliasing, and the “shadow acne” effect. VSM solves these problems by applying a statistical approach: instead of storing a single depth in the map, two values are stored — the average and the square of the depth. These values allow the depth variance in each pixel to be calculated and the probability that a point is in shadow to be estimated using Chebyshev’s inequality.
The advantage of Variance Shadow Maps is the ability to blur shadows directly in the shadow map without the need for multiple selective filtering, as is done in Percentage Closer Filtering (PCF). This provides smoother shadows at long distances, reduces visual noise, and simplifies hardware implementation on the GPU. VSMs are particularly effective for dynamic scenes where objects and light sources move, as the method is resistant to aliasing when the viewing angle and distance to shadows change.
However, the Variance Shadow Maps method has its limitations. The main problem is light bleeding, when shadows become too soft or artifacts appear at the edges of objects. This is due to the peculiarities of statistical approximation and may require additional adjustments, such as clamp filtering or the use of Multiplied VSM to reduce dispersion overflow. It is also important to note that the accuracy of VSM depends on the resolution of the shadow map: low resolution results in blurry and less accurate shadows.
The practical implementation of VSM usually involves generating a depth map with the calculation of the mean value and variance, storing this data in a two-component texture, and using it in a pixel shader to calculate the probability of a point being in shadow. To improve shadow quality, Gaussian blur or separable filters are often applied directly to the variance map, making shadows smooth and realistic without significantly reducing performance.
Overall, Variance Shadow Maps are a powerful tool for 3D graphics and game developers, allowing them to create soft and stable shadows with minimal artifacts and high performance. When properly configured and combined with other lighting methods, VSM provides visually appealing scenes, enhancing the realism and quality of graphics in interactive applications and game engines.