Shadow acne is an artifact that occurs in computer graphics when rendering shadows. It's a type of erroneous self-shadowing that appears as a pattern of dark spots or splotches on the surfaces of objects. This problem specifically arises when using techniques like shadow mapping.
Understanding the Issue
When a scene is rendered, shadows are often created using a process that involves comparing the depth of a pixel from the camera's perspective with its corresponding depth from the light source's perspective. This involves generating a "shadow map," which stores the depth of the scene as seen by the light.
The problem of shadow acne arises because when the system naively compares the depth of the scene with that in the shadow map, small variations or inaccuracies in these depths lead to incorrect decisions about whether a surface point is in shadow. Even points that should be lit can incorrectly be marked as being in shadow due to these discrepancies.
How Shadow Acne Occurs
Here's a breakdown of how shadow acne occurs:
- Shadow Map Creation: A shadow map is created from the perspective of the light source, storing the distance to the nearest object for each pixel.
- Depth Comparison: When rendering the scene from the camera’s viewpoint, each pixel’s depth from the camera is compared to its corresponding value in the shadow map, transformed to the light's coordinates.
- Erroneous Self-Shadowing: Because of the resolution limits of the shadow map and float-point errors during calculations, some surfaces may appear to be behind other surfaces when they shouldn’t. This leads to self-shadowing, even in cases where surfaces are fully visible to the light source. These are often observed as distinct and irregular shapes on surfaces that shouldn't be in shadow.
Solutions for Shadow Acne
Several techniques can minimize shadow acne:
- Bias: Adding a small "bias" value to the depth value during comparisons effectively shifts the points slightly away from the light.
- This prevents very small differences from causing a point to incorrectly appear in shadow.
- Back-Face Culling: Rendering the back face of a primitive will avoid the 'shadow acne' effect
- Depth Smoothing: Blurring or averaging the depth values in the shadow map can also reduce discrepancies between pixel depths.
- Higher-Resolution Shadow Maps: Increasing the resolution of the shadow map results in a more accurate representation of the scene, which can reduce shadow acne.
- Percentage Closer Filtering (PCF): Implementing PCF can smooth the edges between shadowed and lit areas.
- Normal Offset: Offsetting depth based on surface normals can significantly reduce shadow acne. This approach is especially useful when dealing with angled surfaces.
Example
Imagine a flat plane illuminated by a light source, with the light source and the viewing camera positioned above the plane. Without mitigation strategies, the shadow map might have slight inconsistencies across that flat surface. These inconsistencies can lead some pixels to be mistakenly identified as being in shadow, which results in a dark, patchy pattern (shadow acne) being rendered on the plane's surface.
In Conclusion
Shadow acne is an unwanted artifact resulting from naive depth comparison during shadow rendering, causing incorrect self-shadowing. Solutions like bias, depth smoothing, higher-resolution maps, PCF, and normal offset help mitigate this issue to improve the quality of rendered scenes.