Global Illumination using the Flood Fill Algorithm
Lionel Pigou / January 2021
Disclaimer: The text in this post is generated by an AI chatbot based on a few bullet points.
By harnessing the flood fill algorithm on the GPU, we can achieve impressive global illumination effects in real-time. We propagate three types of light to achieve realistic global illumination: sunlight, ambient light, and point lights. Each type of light is treated separately within the flood fill algorithm, ensuring accurate and convincing lighting effects throughout the game world.
The Flood Fill Algorithm
The flood fill algorithm is a well-known technique used in computer graphics and image processing. Its purpose is to determine connected regions within a given area, starting from a specific seed point. This algorithm explores neighboring cells or pixels, spreading a property or value until it reaches its boundaries.
In the context of global illumination, the flood fill algorithm allows us to efficiently propagate light across the game world. By treating each cell as a potential source or receiver of light, we can iteratively calculate the lighting values for every point in the scene.
To store the lighting information efficiently, Meor utilizes cascading clipmap Level of Detail (LOD) grids. These grids allow for the representation of varying levels of lighting detail, depending on the distance from the viewer. This approach strikes a balance between visual fidelity and performance.
Sunlight
Sunlight plays a crucial role in outdoor environments, casting realistic shadows and providing directional lighting. To determine the intensity of sunlight in each cell, we sample the lighting value once at a small step away in the direction of the sun. This technique captures the directionality of sunlight, allowing for accurate shading and shadowing of objects.
Ambient Light
Ambient light contributes to the overall illumination of the scene and is calculated using the flood fill algorithm. It takes into account the lighting values of the six nearest neighbors and the sunlight present in the current cell. By considering the surrounding light sources, we achieve a smooth and natural blending of ambient illumination, enhancing the visual quality of the game world.
Point Lights
Point lights in Meor are not only limited to providing color but also emit light in specific directions. These lights utilize three color channels to create a vibrant and dynamic lighting atmosphere. Additionally, a direction vector is propagated to determine the correct angle of the light. This information is crucial for accurately shading the surfaces near the point lights, ensuring realistic lighting interactions.