Page 25: Lighting with HDRI
Spring 2026 Sample Solution
The mechanism of environment maps provides a method for implementing lighting. The light that comes from the environment just needs to be bright enough that we see it in the reflections of non-shiny objects. It also means that even non-shiny objects need to access the environment map.
The use of a picture of the lighting in a scene to achieve lighting is known as Image-Based Lighting (IBL). The technique can improve the realism of a scene. Instead of relying solely on a few artificial, infinitely small point lights or directional lights, IBL uses a 360-degree picture to surround the 3D world. The graphics engine treats every single pixel of that image as an individual light source beaming inward. This allows objects to be illuminated by the complex, nuanced ambient light of a real-world location—such as the soft bounce light of a forest floor or the harsh fluorescent glare of a factory—while also providing highly accurate reflections of that space.
To make Image-Based Lighting work correctly, the environment map must be a High Dynamic Range (HDR) image, typically stored in formats like .exr or .hdr. Standard 8-bit images (like JPGs or PNGs) cap color values at 255, meaning the engine cannot distinguish between a white piece of paper and the actual blinding surface of the sun; they both just register as “white.” HDR images store true floating-point values, allowing them to record the extreme, real-world intensity of light sources. When a renderer uses an HDR environment map, the bright pixels (like the sun or a studio lamp) actually emit significantly more energy into the 3D scene, resulting in accurate illumination and correct contrast.
However, using environment maps for lighting introduces significant mathematical challenges, particularly regarding texture filtering. When a material is highly polished, the engine only needs to look up a single distinct pixel to draw a sharp mirror reflection. But for rough materials (like brushed metal or wood), the light scatters. To simulate this blurry reflection, the engine must average together a large patch of the environment map. Because environment maps are flat 2D representations of 3D spheres (like equirectangular projections or cubemaps), they contain severe geometric distortions at the poles or edges. Standard GPU filtering cannot natively handle these distortions, and if left uncorrected, the blurry reflections will expose ugly seams or pinched artifacts.
Fortunately, Three.js handles these complex challenges well under the hood. When you assign an HDR texture to scene.environment, Three.js processes the image to calculate the complex irradiance (ambient bounce light) and generates specialized, pre-filtered mipmaps that mathematically correct for the distortions of the projection. This means that by simply loading an EXR file and assigning it to the scene, any Physically Based Rendering (PBR) materials (MeshStandardMaterial or MeshPhysicalMaterial) will automatically react to physically accurate ambient lighting and provide blurred reflections, with little effort.