Shadow Techniques For Voxel Engines
Header Image

Shadowing Techniques in Voxel Engines

Accurate and visually appealing shadows are essential in voxel engines to enhance depth perception and realism. Voxel engines, however, pose unique challenges when it comes to implementing shadows due to their blocky nature and vast, procedurally generated worlds. This article covers several common shadowing techniques used in voxel engines, discussing the pros and cons of each approach and exploring common pitfalls and implementation details.

Shadow Mapping

Shadow mapping is one of the most widely used techniques for real-time shadow generation in both traditional and voxel-based engines. It involves rendering the scene from the perspective of the light source and storing the depth of the objects in a shadow map. This depth information is then used to determine whether a given pixel is in shadow or illuminated when rendered from the player's perspective.

In voxel engines, shadow mapping can be implemented similarly, but there are additional challenges due to the blocky nature of voxels. One common pitfall is aliasing, which occurs when the shadow map resolution is too low compared to the voxel size. This can result in jagged or pixelated shadows. To mitigate this, developers can increase the shadow map resolution or use techniques like Percentage-Closer Filtering (PCF) to smooth out the edges of shadows.

The main advantage of shadow mapping is its efficiency and compatibility with most graphics pipelines. However, it struggles with large, open worlds, as shadow maps cover limited areas and can lead to low resolution in distant areas. Techniques like Cascaded Shadow Maps (CSM), discussed later, help address this limitation. Despite its pitfalls, shadow mapping remains a versatile choice for voxel engines.

Voxel Cone Tracing

Voxel Cone Tracing is an advanced shadowing and global illumination technique that traces cones through the voxelized representation of the scene. In voxel engines, this technique is particularly relevant because it naturally fits with the voxel structure. The idea is to create a 3D grid of voxels that stores light information, then trace cones to compute the light interaction for each point in the scene.

The benefit of voxel cone tracing is that it allows for not just shadows but also indirect lighting and soft shadows, making it suitable for more realistic lighting scenarios. However, its implementation is computationally expensive. It requires generating a voxel grid with accurate lighting information, which can be difficult to maintain in real-time, especially for large, procedurally generated worlds. Moreover, the memory requirements for storing a high-resolution voxel grid are significant.

One common pitfall is managing the balance between performance and quality. Since the technique uses cones (rather than rays), approximations are made, which can result in inaccurate shadows or light bleeding. The trade-off between speed and precision makes voxel cone tracing less practical for real-time applications on lower-end hardware, but it is a powerful technique for achieving realistic, soft shadows in voxel engines.

Ray-Traced Shadows

Ray tracing is a powerful technique for generating realistic shadows by simulating the path of light as it interacts with objects in the scene. In voxel engines, ray-traced shadows can be particularly effective due to the geometric simplicity of voxels. Each voxel can serve as an intersection point for light rays, making it easier to compute accurate shadows compared to more complex geometries.

Implementing ray-traced shadows involves tracing rays from the light source to each pixel in the scene, determining whether any voxels block the light. This produces accurate, hard shadows that match the sharp edges of voxel blocks. Ray-traced shadows are often seen as the gold standard in shadow quality, as they can precisely simulate complex lighting interactions, including reflections and refractions.

The main drawback of ray tracing is its computational cost. Even with the advancements in real-time ray tracing via technologies like NVIDIA's RTX, ray tracing remains demanding, particularly in large voxel worlds. Additionally, ray-traced shadows may appear unnaturally sharp without techniques to soften them, such as sampling multiple rays or integrating global illumination. Ray tracing is best suited for high-end hardware or engines where visual fidelity is prioritized over performance.

Cascaded Shadow Maps (CSM)

Cascaded Shadow Maps (CSM) are an extension of traditional shadow mapping that divides the scene into multiple "cascades," each with its own shadow map. This allows the engine to use higher-resolution shadow maps for closer objects while using lower-resolution maps for distant ones, thus optimizing the balance between shadow quality and performance. CSM is particularly useful in large voxel worlds where the player can move between vastly different regions of the scene.

In voxel engines, CSM works by splitting the view frustum into several sections (cascades) and assigning a shadow map to each section. This ensures that shadows close to the player remain detailed, while those farther away can be rendered with fewer resources. However, CSM introduces complexity in terms of managing multiple shadow maps and blending between them to avoid noticeable seams or transitions between cascades.

The main advantage of CSM is its scalability. As the player moves, the cascades adjust dynamically, ensuring that high-quality shadows are always visible near the player. However, the technique can suffer from "popping" issues when the player moves between cascades, leading to sudden changes in shadow detail. Additionally, maintaining multiple shadow maps requires careful management of performance and memory, particularly in voxel worlds where large distances and vast terrains are common.

Ambient Occlusion

Ambient Occlusion (AO) is a technique used to simulate the soft shadows that occur in crevices or areas where light is occluded by nearby objects. While not a traditional shadowing technique, AO is often used in conjunction with other shadowing methods to improve the overall realism of the lighting in voxel engines. It enhances the depth of the scene by darkening areas that would naturally receive less light.

In voxel engines, AO can be implemented by approximating how much ambient light reaches a given voxel based on the surrounding geometry. Techniques like Screen Space Ambient Occlusion (SSAO) or voxel-based AO are commonly used. However, one common pitfall is that AO does not account for dynamic lighting, meaning it does not change with the position of the light source. This can make AO look unrealistic in scenes with dynamic or moving lights.

The advantage of AO is that it adds a sense of depth and realism to the scene with relatively low computational cost. It’s particularly useful in voxel environments, where the blocky geometry can sometimes make scenes look too flat or artificial. However, it should be used as a supplement to other shadowing techniques rather than a replacement for more detailed, dynamic shadows.

Latest Voxel Engine Tutorials