Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 39 ยท Textures and Loading Models

Environment Maps and PBR Texture Maps

Make Three.js materials look real: image-based lighting with PMREMGenerator and RoomEnvironment, roughness, metalness, normal and bump maps, and CubeCamera reflections.

A texture does not have to be a picture you glue on. In physically based rendering (PBR) the main material, MeshStandardMaterial, takes several maps, each controlling one physical property of the surface: how rough it is, whether it is metal, how bumpy it is. Together with an environment map that tells the material what surrounds it, these maps are what make a renderer's output look like a photograph instead of plastic.

In this lesson you will light a scene with an environment, learn which map does what, build maps procedurally so the examples need no downloads, and create live reflections with CubeCamera.

Why metal looks black without an environment

A perfectly metallic surface has no diffuse color: all it does is reflect its surroundings. If the only things in a scene are a few lights, a metal ball has almost nothing to reflect, so it looks dark. Fixing this does not need more lights. It needs an environment: an image (usually a 360-degree panorama) that Three.js uses both as a reflection source and as soft light from every direction. This technique is called image-based lighting (IBL).

PBR material inputs

map Base color
roughnessMap Mirror or matte
metalnessMap Metal or plastic
normalMap Fake tiny bumps

Color maps use sRGB. Every other map is plain data.

1 / 2

Using RoomEnvironment and PMREMGenerator

Three.js ships a small procedural studio called RoomEnvironment. You do not download anything: it is a little scene of boxes and lights. To use any environment for lighting, the renderer first converts it to a special pre-filtered format with PMREMGenerator, which blurs the image at several levels so rough surfaces can pick a blurry reflection.

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

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

Setting scene.environment applies it to every MeshStandardMaterial and MeshPhysicalMaterial in the scene. For a real HDR file you would load it with RGBELoader (or EXRLoader), set texture.mapping = THREE.EquirectangularReflectionMapping, and assign it to scene.environment and optionally scene.background.

Roughness and metalness with an environment

The top row goes from mirror (roughness 0) to brushed (roughness 1). The bottom row shows plastic: the color stays visible and only a highlight changes. No lights were added; the environment did all the work.

The PBR maps, one by one

Map What it stores Color space
map Base color (albedo) sRGB
roughnessMap Roughness in the green channel none
metalnessMap Metalness in the blue channel none
normalMap A direction per pixel (fake bumps) none
bumpMap A height per pixel (grayscale) none
aoMap Pre-baked ambient shadow in the red channel none
emissiveMap Self-lit color (screens, neon) sRGB
alphaMap Transparency (needs transparent: true) none
displacementMap Real vertex displacement (needs many vertices) none

The map's value is multiplied by the matching number on the material. A roughnessMap combined with roughness: 1 uses the map as is; with roughness: 0.5 everything is half as rough. Artists often pack roughness, metalness and AO into one image (the "ORM" texture), which is why glTF files sample different channels of one image.

A normal map stores, in RGB, a direction for each pixel. The shader uses it to bend the lighting as if the surface had bumps, without adding triangles. A bump map is the cheaper cousin: a grayscale height image from which Three.js estimates slopes. Neither changes the silhouette; only displacementMap moves vertices.

Building maps in code

Dedicated texture sites sell these maps, but you can generate simple ones. The next example paints a height field on a canvas, then reuses it as a bump map and as a roughness map so the shiny parts are also the smooth ones.

Procedural bump and roughness maps

Watch the highlights slide across the mortar lines as the light moves: that is relief created with only two triangles.

Dynamic reflections with CubeCamera

An environment map is static; it cannot show the other objects in your scene. When one object must mirror the others, render the scene six times from its position into a cube render target with CubeCamera, then use that texture as envMap.

JavaScript
const rt = new THREE.WebGLCubeRenderTarget(256);
const cubeCamera = new THREE.CubeCamera(0.1, 50, rt);
mirror.material.envMap = rt.texture;

// each frame (hide the mirror itself first, so it does not see itself)
mirror.visible = false;
cubeCamera.position.copy(mirror.position);
cubeCamera.update(renderer, scene);
mirror.visible = true;

This costs six extra renders. Use a small target (128 to 256 px), update it every few frames, or only once, and keep it to the one hero object.

A mirror ball that reflects moving objects

Tips

  • Keep scene.environmentIntensity and the individual light intensities balanced; a bright environment hides your lights.
  • Use scene.background = texture and scene.backgroundBlurriness to show the environment as a sky.
  • Normal maps from different tools disagree on the green channel (OpenGL vs DirectX). If bumps look inverted, flip them with material.normalScale.set(1, -1).
  • aoMap reads a second UV set in many pipelines; check texture.channel when the baked shadows look wrong.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does a fully metallic sphere look nearly black in a scene lit only by a point light?

    Metal has almost no diffuse color; it mirrors its environment. An environment map (IBL) supplies something to reflect.
  2. 2. What is PMREMGenerator for?

    PMREMGenerator turns an environment into a mip-blurred cube texture that PBR materials can sample by roughness.
  3. 3. What is the difference between a bump map and a displacement map?

    Bump (and normal) maps fake relief in the shading; the silhouette stays flat. Displacement maps really move vertices and need enough geometry.
  4. 4. Why hide the mirror mesh before calling cubeCamera.update()?

    The cube camera sits at the mirror's center. Without hiding it, every face would see the inside of the mirror itself.

Summary

  • PBR materials combine base color, roughness, metalness, normal/bump, AO, emissive and alpha maps.
  • An environment (PMREMGenerator + RoomEnvironment or an HDR image) provides reflections and soft light through scene.environment.
  • Only color maps use SRGBColorSpace; the rest are data.
  • Bump and normal maps fake relief; displacement maps move real vertices.
  • CubeCamera gives live reflections of the scene at the cost of six renders.

Next: Loading glTF Models