Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 39 ยท Lights and Shadows

Environment Lighting, HDR and Skies

Light Three.js scenes with environment maps: PMREMGenerator, RoomEnvironment, HDR images, the procedural Sky add-on, background blur and environment intensity.

Lights from the last lessons are small, local sources. Real surfaces are lit by the whole surroundings: sky, walls, the ground bouncing light back. Environment lighting captures that. You give Three.js a picture of the world around the scene, and every PBR material uses it for both diffuse light and reflections. A single environment often replaces all other lights and is the quickest path to a realistic look, which is why product viewers use it.

Where an environment comes from

An environment is a cube map or an equirectangular (360 degree panorama) image. Three.js converts it into a special pre-filtered form with PMREMGenerator, because rough materials need blurred versions of the reflections and doing that blur once, up front, is cheap.

Sources of an environment

RoomEnvironment Built-in studio, no download
HDR image A real 360 photo with huge brightness range
Sky add-on Procedural sky controlled by sun position
Your own scene Render any scene with PMREM fromScene

All of them end up as scene.environment.

1 / 2

The quickest studio: RoomEnvironment

JavaScript
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";

const pmrem = new THREE.PMREMGenerator(renderer);
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;

The second argument is a blur sigma. After creating textures you can free the generator with pmrem.dispose().

Environment versus background

scene.environment lights objects. scene.background is what the camera sees behind them. They can be different, or the same texture. Three.js has controls for both:

JavaScript
scene.environment = envTexture;
scene.background = envTexture;          // show the panorama behind the scene
scene.backgroundBlurriness = 0.3;       // 0..1, blur the visible background only
scene.backgroundIntensity = 0.8;        // brightness of the visible background
scene.environmentIntensity = 1.2;       // brightness of the lighting from it
scene.backgroundRotation.y = 1.0;       // rotate the panorama (Euler)
scene.environmentRotation.y = 1.0;

A common recipe is a sharp HDR for reflections plus a blurred copy as the background so the photo does not distract from the model.

HDR images

A normal JPEG stores brightness up to "white". Real skies and lamps are thousands of times brighter than white, and reflections of a sun disk look right only if that energy is kept. HDR (high dynamic range) images store those values, usually in .hdr or .exr files. You load them with RGBELoader or EXRLoader from the add-ons and tell Three.js they are 360 degree equirectangular maps:

JavaScript
import { RGBELoader } from "three/addons/loaders/RGBELoader.js";

new RGBELoader().load("/textures/studio_small.hdr", (texture) => {
  texture.mapping = THREE.EquirectangularReflectionMapping;
  scene.environment = texture;
  scene.background = texture;
});

With an equirectangular mapping Three.js runs the PMREM step for you. Free HDRIs are available from sites such as Poly Haven; keep them modest in size (1k or 2k) because an 8k file is tens of megabytes and decompresses into a huge texture. Loading files is covered in the next chapter, so here we use sources that need no download.

A procedural sky

The Sky add-on draws a physically inspired sky dome from the sun's position. Feed the sky into PMREMGenerator.fromScene and it becomes an environment too. Move the sun with the sliders and watch the sphere's reflections change color, from white noon to orange sunset.

Procedural sky as environment

Lower the elevation toward the horizon: the sky turns orange, the knot gets a warm tint and the mirror ball shows the gradient. Below 0 the sun sets and the world goes dark. There are no Light objects in this scene at all; every bit of lighting comes from scene.environment.

Sky shaders and PMREM generation can be expensive on weak devices. Generate the environment once when the sun changes, not every frame, exactly as the demo does.

An environment from your own scene

Because fromScene accepts any scene, you can build a fake studio from a few emissive planes. This is how RoomEnvironment works internally, and it gives you complete control, such as two bright softboxes and a warm fill.

A custom softbox environment

The three bright panels appear as crisp highlights on the metal. Change their positions and sizes and the reflection follows. This is exactly how photographers think about lighting a product.

Environment on a single material

A material can have its own envMap, overriding scene.environment, and envMapIntensity scales its strength. Use it to give one object a different reflection, or to make a glass window reflect a sky while the rest uses a studio. In current versions prefer scene.environmentIntensity for the whole scene and material.envMapIntensity for individual objects.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does PMREMGenerator do?

    It produces a prefiltered mipmapped radiance environment map that PBR materials sample efficiently.
  2. 2. Which materials respond to scene.environment?

    PBR materials use environment lighting. Basic and Normal materials ignore it.
  3. 3. How can you blur the visible panorama without blurring reflections?

    backgroundBlurriness only affects how the background looks, not the lighting.
  4. 4. Why use HDR images for environments?

    Real light sources are much brighter than a display's white. HDR keeps that range.

Summary

  • Environment lighting uses a picture of the surroundings for diffuse light and reflections on PBR materials.
  • PMREMGenerator prepares equirectangular HDRs, skies or any scene as scene.environment.
  • RoomEnvironment is a built-in studio; Sky is a procedural sky; RGBELoader loads HDR files.
  • Background and environment are separate: use backgroundBlurriness, environmentIntensity and rotation properties.
  • Generate environments once, not every frame, and dispose old render targets.

Next: Lighting Recipes and Practice