An irradiance map in GLSL is a precomputed texture (typically a cube map) used in computer graphics to efficiently approximate indirect ambient lighting for a scene. It is a key component of Physically Based Rendering (PBR) and image-based lighting (IBL) techniques. Here's a detailed breakdown:
What is an Irradiance Map?
- Purpose: Stores precomputed irradiance values, which represent the total incoming light (both intensity and color) from all directions at a specific point in the environment. This mimics indirect lighting (light bouncing off surfaces) without real-time ray tracing.
- Storage: Usually stored as a cube map, where each face represents a direction in 3D space. The value at each pixel ( texel ) encodes the integrated light arriving from that direction over a small solid angle.
- Resolution: Typically low-resolution (e.g., 32×32 per face) since it captures only the diffuse, low-frequency component of indirect lighting.
How It Works
-
Precomputation:
- Generated by integrating the environment lighting (from an HDR environment map) over a hemisphere around a point, considering the surface's orientation.
- The result is baked into a cube map, where each face corresponds to a direction (e.g., +X, -X, +Y, etc.).
-
Shader Usage:
Key Features
- Static Scenes: Best suited for static or slowly changing environments since it is precomputed.
- Efficiency: Avoids the computational cost of real-time global illumination calculations.
- Combination with Other Lighting:
- Often used alongside direct lighting (e.g., point lights, directional lights) and prefiltered environment maps (for specular reflections).
- Part of the IBL pipeline for realistic lighting in PBR.
Why Use an Irradiance Map?
- Realism: Captures the diffuse, indirect light scattered from the environment, adding depth and realism.
- Performance: Reduces the need for expensive real-time calculations, making it viable for real-time applications like games.
- Compatibility: Works with static geometry, complementing dynamic objects lit by direct sources.
Limitations
- Resolution: Low resolution means it may miss fine details in the environment's indirect lighting.
- Dynamic Scenes: Not ideal for dynamic environments unless the irradiance map is updated frequently, which can negate performance gains.
Example Workflow
- Capture Environment: Use an HDR environment map (e.g., a panoramic photo).
- Precompute Irradiance:
- For each cube map face, render the environment from a viewpoint and integrate light over a hemisphere.
- Apply in Shaders:
- Sample the irradiance map using the surface normal during rendering.
- Combine with direct lighting and material properties for the final color.
Code Snippet (GLSL)
// Uniform sampler for the irradiance cube map
uniform samplerCube irradianceMap;
// Vertex shader passes the normal to the fragment shader
in vec3 fragNormal;
void main() {
// Normalize the normal (if not already done)
vec3 N = normalize(fragNormal);
// Sample irradiance map using the normal as the direction
vec3 irradiance = texture(irradianceMap, N).rgb;
// Compute ambient contribution (multiply by albedo)
vec3 ambient = irradiance * material.albedo;
// Combine with other lighting terms (direct, specular, etc.)
vec3 finalColor = ambient + directLighting + specularLighting;
// ...
}
In summary, an irradiance map is a precomputed cube map that stores ambient lighting information, enabling efficient and realistic indirect lighting in GLSL-based rendering pipelines.