Ambient Lighting & Hemi Lights
In real-time rendering, light defines form, depth, and mood. While direct lighting (such as Lambertian or Blinn-Phong) handles illumination from explicit sources, the world also needs Ambient and Hemi (hemispheric) lighting to simulate the contribution of the environment.
Ambient light ensures surfaces in shadow are never completely black, while Hemi lights provide a smooth gradient between the ground and the sky, enriching the sense of directionality even without strong light sources.
Visual demo¶
Complete per-vertex and per-pixel implementations, with detailed comments, are available on Patreon.
// Pseudo-code (Complete per-vertex and per-pixel implementations, with detailed comments, are available in the related Patreon post)
// Inputs: surface normal in world space
float3 normalWS = normalize(surfaceNormalWS)
// Base color
float3 colorBase = texture(BaseMap, uv) * Tint
// Initialize lighting contribution
float3 colorLighting = 0
// Sample Spherical Harmonics (SH) baked into the scene
float3 ambient = SampleSH(normalWS)
colorLighting += ambient
// Use the Y component of the normal to blend between ground and sky
half mask = remap(normalWS.y, -1, 1, 0, 1)
mask = pow(abs(mask), HemiContrast)
float3 hemi = lerp(TintGround, TintSky, mask) * HemiPower
colorLighting += hemi
// Final color
float4 colorOutput = float4(colorBase * saturate(colorLighting), 1.0)
Basic idea¶
Ambient lighting represents global light coming from the environment, regardless of direction. It ensures all objects are lit to some degree, preventing harsh black shadows. In modern rendering, ambient light is often provided via spherical harmonics (SH), which captures low-frequency environment lighting.
Hemi lighting is a simplified model for directional environmental light. It blends between two colors: sky and ground, based on the surface’s upward or downward orientation. Surfaces facing up receive more of the sky tint, while downward-facing surfaces receive more of the ground tint. This provides a natural gradient and emphasizes orientation relative to the environment.
Equation¶
Ambient Lighting:
L_ambient = SH(n)
where n is the surface normal and SH(n) is the evaluation of spherical harmonics.
Hemi Lighting:
L_hemi = ((1 - m) x C_ground + m x C_sky) * P
where: - m = remap(n.y, -1, 1, 0, 1) ^ contrast - n.y: Y-component of the surface normal - C_ground, C_sky: sky/ground tint colors - P: global intensity
Final Color:
C_out = C_base * saturate(L_ambient + L_hemi)
Keep in mind that Ambient and Hemi lighting are not complete lighting models. They only approximate how the environment influences surfaces.
🔗 Related Functions¶
❤️ Support Shader Story¶
If this article helped you, consider supporting the project on Patreon: you’ll get access to the related source files and reference cheat-sheets.
Your support helps keep this library open and free for everyone.