three.js Materials and PBR

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

A material tells the renderer what a surface is made of: which colour it has, how shiny it is, whether it glows, whether light passes through it. In three.js a Mesh is a geometry plus a material, and almost every visual decision that is not about shape lives in the material. This page covers the built-in mesh materials, the physically based (PBR) ones in depth, how maps and channels feed them, how one mesh can use several materials, and how transparency works. The textures that go into the maps, and the colour management that decides how their values are read, are on the next page, three.js Textures and Colour Management; the lights that make PBR materials visible are on three.js Lights and Shadows.

The general concepts behind this page are in Lighting & Shading Models.

The facts were checked in November 2026 against three.js r187 (three@0.187.0, the current npm release at that date) and its API documentation. The examples are ES modules built with Vite, as in three.js: Getting Started, and use WebGLRenderer, which runs on WebGL 2 in every evergreen browser (three.js dropped WebGL 1 support in r163). The classes described here also exist in the node-material form used by WebGPURenderer, which is introduced in three.js: WebGPURenderer and TSL; the property names are the same.

In the Bookshelf running example this page is the "PBR materials" step of the three.js track: the GLB shelf and books loaded from bookshelf.glb get their wood, cover, spine and page materials checked, tuned and lit by an environment. The next steps (controls, picking, the falling-books game) reuse these materials unchanged.

What a material does

Rendering a mesh needs a shader program and a set of values for that program. A three.js material is the high-level description that WebGLRenderer turns into both: choosing MeshStandardMaterial selects the standard PBR shader, and setting roughness, map or normalMap fills in uniforms and switches on #define branches in the generated GLSL. Two consequences matter in practice:

  • Changing a number is cheap, changing the shape of the shader is not. Setting material.roughness = 0.4 updates a uniform. Assigning a map where there was none, turning transparent on or enabling flatShading changes the program, so the renderer needs to compile a new variant and the material must be flagged with material.needsUpdate = true.

  • Materials are shared by reference. Hundreds of meshes can point at one material object, which costs one program and one set of uniforms. Cloning a material per mesh is only needed when each mesh must change a value independently.

The built-in mesh materials

Six cards for MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshToonMaterial, MeshStandardMaterial and MeshPhysicalMaterial, with typical use and a relative cost bar
Figure 1. The mesh materials from unlit to physically based
Material Lighting model Typical use

MeshBasicMaterial

None. Output is color times map, plus fog. Not affected by lights.

HUD planes, skyboxes, helpers, video screens, debugging UVs.

MeshLambertMaterial

Diffuse only (no specular highlight).

Matte surfaces where the highlight is not wanted; cheap scenes.

MeshPhongMaterial

Diffuse plus Blinn-Phong specular controlled by shininess and specular.

The look most older tutorials and the three books produce; still available for stylised work.

MeshToonMaterial

Diffuse quantised into bands by an optional gradientMap.

Cartoon or cel looks.

MeshStandardMaterial

Physically based metallic-roughness model with image-based lighting from scene.environment.

The default choice for models; the glTF base material.

MeshPhysicalMaterial

Standard plus clearcoat, sheen, transmission, iridescence, anisotropy, dispersion, volume and specular controls.

Glass, car paint, cloth, gems, anything that needs a second layer.

MeshMatcapMaterial

No lights: the normal looks up a colour in a "matcap" image.

Sculpt viewers and fast stylised previews.

MeshNormalMaterial, MeshDepthMaterial, MeshDistanceMaterial

Output the normal, depth or distance as colour.

Debugging, depth passes and the internals of shadows.

ShadowMaterial, PointsMaterial, LineBasicMaterial, SpriteMaterial

Special purpose: shadow catcher, points, lines, billboards.

Used with Points, Line, Sprite and as shadow receivers.

ShaderMaterial, RawShaderMaterial

Your own GLSL.

See three.js Custom Shaders in GLSL; WebGLRenderer only.

The decision most projects face is shown below. When in doubt, use MeshStandardMaterial: it is what glTF files describe, it reacts correctly to every light type, and the extra cost over Phong is small on any GPU from the last decade.

flowchart TD A["What should the surface do?"] --> B{"Must react to lights?"} B -- no --> C["MeshBasicMaterial"] B -- yes --> D{"Stylised, banded look?"} D -- yes --> E["MeshToonMaterial"] D -- no --> F{"Needs clearcoat, glass, cloth, iridescence?"} F -- yes --> G["MeshPhysicalMaterial"] F -- no --> H["MeshStandardMaterial"] H --> I{"Thousands of identical meshes?"} I -- yes --> J["Share one material, use InstancedMesh"] I -- no --> K["One material per surface type"]
Figure 2. Choosing a material

Metalness and roughness

MeshStandardMaterial implements the metallic-roughness workflow also used by glTF 2.0 and by most game engines. The surface is described by three base quantities:

  • color (and the map that multiplies it) is the base colour: the diffuse colour of a non-metal, or the tint of the reflection of a metal.

  • metalness from 0.0 to 1.0 says how much the surface behaves as a conductor. Real surfaces are almost always 0 or 1; values in between represent a mix, such as a rusty or dusty metal, and are mostly used where a texture blends the two.

  • roughness from 0.0 to 1.0 says how blurred the specular reflection is. Internally the microfacet width is the square of the roughness, so the visual change is roughly even across the range. The default is 1.0, which is why a plain MeshStandardMaterial looks matte and a little dull until you lower it.

Non-metals reflect light with a colourless highlight of about 4 percent at normal incidence (an index of refraction of 1.5) and show the base colour as diffuse light. Metals have no diffuse light: their reflection takes the base colour, and the specular response is the whole look. That is why a metal with no environment to reflect looks black: it needs scene.environment or an envMap (see the next page) or lights with a specular response.

Three rows of five spheres with metalness 0.0, 0.5 and 1.0 and roughness from 0.00 to 1.00 showing sharper and broader highlights
Figure 3. Roughness and metalness on one base colour

The figure is a schematic drawing in the style of the sphere grid on the three.js material documentation pages. Building the real one takes a dozen lines and is a good first test of any new environment map:

import * as THREE from 'three';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
document.body.appendChild(renderer.domElement);

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

const camera = new THREE.PerspectiveCamera(35, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 0, 14);

const geometry = new THREE.SphereGeometry(0.8, 48, 32);
const roughnessSteps = [0, 0.25, 0.5, 0.75, 1];
const metalnessSteps = [0, 0.5, 1];

metalnessSteps.forEach((metalness, row) => {
  roughnessSteps.forEach((roughness, col) => {
    const material = new THREE.MeshStandardMaterial({
      color: 0x9b2c2c,        // the cover red; the colour constructor argument is read as sRGB
      metalness,
      roughness,
    });
    const sphere = new THREE.Mesh(geometry, material);
    sphere.position.set((col - 2) * 2, (1 - row) * 2, 0);
    scene.add(sphere);
  });
});

renderer.setAnimationLoop(() => renderer.render(scene, camera));
addEventListener('resize', () => {
  camera.aspect = innerWidth / innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(innerWidth, innerHeight);
});

RoomEnvironment is a small procedural scene shipped with the examples; PMREMGenerator.fromScene(scene, sigma) renders it into a prefiltered environment texture. Using it avoids downloading an HDR file while you experiment (the HDR route is on the next page).

Reading the maps: which channel is which

Every slot that holds data rather than colour reads specific channels of the texture. This is the part that most often goes wrong when textures are exported from another tool, so the table lists them all.

Slot Channel read Effect Colour space of the texture

map

RGB (and A with transparent or alphaTest)

Base colour, multiplied by color.

SRGBColorSpace

normalMap

RGB as a tangent-space vector

Perturbs the shading normal; normalScale (a Vector2) scales it. Negate its y for maps authored with the other handedness convention.

NoColorSpace

bumpMap

One channel as height

Cheaper relief from a greyscale image; ignored when a normalMap exists. bumpScale scales it.

NoColorSpace

roughnessMap

Green

Multiplied with roughness.

NoColorSpace

metalnessMap

Blue

Multiplied with metalness.

NoColorSpace

aoMap

Red

Baked ambient occlusion on the indirect light; aoMapIntensity scales it. Uses the UV set named by aoMap.channel.

NoColorSpace

lightMap

RGB

Baked illuminance added to the indirect light; lightMapIntensity scales it. Also needs a second UV set.

LinearSRGBColorSpace (it stores light, not colour)

emissiveMap

RGB

Self-illumination, multiplied by emissive and emissiveIntensity. Set emissive to white when using the map.

SRGBColorSpace

alphaMap

Green

Opacity; only effective with transparent or alphaTest.

NoColorSpace

displacementMap

One channel as height

Moves the vertices (displacementScale, displacementBias); needs enough triangles. It changes geometry, so it casts and receives shadows correctly.

NoColorSpace

envMap

Cube or equirectangular, prefiltered

Overrides scene.environment for this material; envMapIntensity and envMapRotation adjust it.

Linear for HDR files, see the next page

The ambient-occlusion, roughness and metalness maps share a convention that glTF uses: occlusion in red, roughness in green, metalness in blue, often called an ORM texture. One image then feeds three slots, which saves two texture uploads and two samplers per material:

A texture split into red, green and blue channels, with arrows to aoMap, roughnessMap and metalnessMap
Figure 4. One packed texture feeding aoMap, roughnessMap and metalnessMap
import * as THREE from 'three';

const loader = new THREE.TextureLoader();
const color = loader.load('/textures/book-color.png');
const normal = loader.load('/textures/book-normal.png');
const orm = loader.load('/textures/book-orm.png');

color.colorSpace = THREE.SRGBColorSpace;   // base colour is colour data
// normal and orm stay NoColorSpace: they are numbers, not colours

for (const t of [color, normal, orm]) {
  t.anisotropy = 8;                         // sharper at grazing angles; see the next page
}

const cover = new THREE.MeshStandardMaterial({
  map: color,
  normalMap: normal,
  normalScale: new THREE.Vector2(0.8, 0.8),
  aoMap: orm,
  roughnessMap: orm,
  metalnessMap: orm,
  roughness: 1,       // the maps multiply these, so keep them at 1 to use the full range
  metalness: 1,
});

When a map is present the scalar multiplies it. A common mistake is to leave metalness: 0 and wonder why a metalnessMap has no effect: 0 times anything is 0. Set the scalars to 1 and let the textures decide.

The shelf wood, a normal map and the Bookshelf textures

The shared Bookshelf textures (bookshelf-wood.png, bookshelf-cover.png, bookshelf-spine.png and bookshelf-pages.png, all sRGB colour images, 256 by 256 or 64 by 256 pixels) are already embedded in the GLB, and GLTFLoader assigns their colour space for you. The example below loads the GLB and then adjusts what a game would adjust: the wood becomes rougher and non-metallic, the cover gets a slight sheen and a low roughness, and everything is lit by an environment. This is a complete Vite project step; copy bookshelf.glb into the public folder first.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Bookshelf: PBR</title>
    <style>html, body { margin: 0; height: 100%; overflow: hidden; background: #111; }</style>
  </head>
  <body>
    <script type="module" src="/main.js"></script>
  </body>
</html>
// main.js
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.0;
document.body.appendChild(renderer.domElement);

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x1f2937);
const pmrem = new THREE.PMREMGenerator(renderer);
const envTexture = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
scene.environment = envTexture;
scene.environmentIntensity = 0.8;

const camera = new THREE.PerspectiveCamera(40, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 1.4, 6);

const key = new THREE.DirectionalLight(0xffffff, 2);
key.position.set(3, 5, 4);
scene.add(key);

const gltf = await new GLTFLoader().loadAsync('/bookshelf.glb');
const shelf = gltf.scene;
scene.add(shelf);

const seen = new Set();
shelf.traverse((object) => {
  if (!object.isMesh) return;
  const materials = Array.isArray(object.material) ? object.material : [object.material];
  for (const material of materials) {
    if (seen.has(material)) continue;          // materials are shared by many meshes
    seen.add(material);
    console.log(object.name, material.name, material.type, material.roughness, material.metalness);
    if (material.name === 'Wood') {
      material.roughness = 0.75;
      material.metalness = 0;
    }
    if (material.name === 'Cover') {
      material.roughness = 0.45;               // the cover is cloth or leather, not glossy
    }
    if (material.map) material.map.anisotropy = renderer.capabilities.getMaxAnisotropy();
  }
});

renderer.setAnimationLoop((time) => {
  shelf.rotation.y = Math.sin(time * 0.0004) * 0.4;
  renderer.render(scene, camera);
});

addEventListener('resize', () => {
  camera.aspect = innerWidth / innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(innerWidth, innerHeight);
});

The loop callback receives a timestamp in milliseconds. The console.log line is worth keeping while you learn a model: it prints the material names that the exporter wrote (Wood, Cover, Spine, Pages for this file), which is how you find the ones to tweak. The name check is the standard way to reach a material inside a loaded model.

MeshPhysicalMaterial: the second layer and beyond

MeshPhysicalMaterial extends MeshStandardMaterial with parameters for things a single metallic-roughness layer cannot do. Each one is off by default (its value is zero) and costs shader time only when it is switched on, because the renderer adds the matching code to the program only when the value is greater than zero.

Feature Properties Look

Clearcoat

clearcoat, clearcoatRoughness, clearcoatMap, clearcoatRoughnessMap, clearcoatNormalMap, clearcoatNormalScale

A thin glossy lacquer over the base: car paint, varnished wood, a laminated book cover.

Sheen

sheen, sheenColor, sheenRoughness, sheenColorMap, sheenRoughnessMap

A soft, grazing-angle rim for fabric, velvet and dust.

Transmission and volume

transmission, transmissionMap, thickness, thicknessMap, attenuationColor, attenuationDistance, ior

Glass and liquids: light passes through, refracts and is tinted over a distance.

Specular control

specularIntensity, specularColor, specularIntensityMap, specularColorMap, reflectivity

Fine control of the non-metal highlight; reflectivity is another way of writing ior.

Iridescence

iridescence, iridescenceIOR, iridescenceThicknessRange, iridescenceMap, iridescenceThicknessMap

Thin-film colour shifts: soap bubble, oil slick, beetle shell.

Anisotropy

anisotropy, anisotropyRotation, anisotropyMap

Stretched highlights on brushed metal, hair and satin.

Dispersion

dispersion

Splits colours in thick transmissive objects such as gemstones (needs transmission and a thick volume).

Diffuse roughness

diffuseRoughness, diffuseRoughnessMap

Rough diffuse response for very matte materials such as clay or chalk.

ior ranges from 1.0 to 2.333 and defaults to 1.5; reflectivity is a derived alias (0.5 corresponds to an ior of 1.5), so setting one changes the other. These parameters correspond to the glTF KHR_materials_* extensions (clearcoat, sheen, transmission, volume, ior, specular, iridescence, anisotropy, dispersion and others), and GLTFLoader creates a MeshPhysicalMaterial automatically when a file uses one. That is the usual way to get them: author the effect in Blender, export it, and let the loader do the mapping.

Stack of layers clearcoat, sheen, iridescence, base and transmission, with incoming reflected and refracted light rays
Figure 5. Layers of a physical material

A small gallery on the Bookshelf scale: a varnished cover, a velvet bookmark, a brass bookend, a glass paperweight and a soap-film bubble. Everything is created in code, so it runs without assets:

import * as THREE from 'three';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.toneMapping = THREE.ACESFilmicToneMapping;
document.body.appendChild(renderer.domElement);

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x30343b);
scene.environment = new THREE.PMREMGenerator(renderer)
  .fromScene(new RoomEnvironment(), 0.04).texture;

const camera = new THREE.PerspectiveCamera(35, innerWidth / innerHeight, 0.1, 50);
camera.position.set(0, 1.2, 9);

const gallery = {
  varnishedCover: new THREE.MeshPhysicalMaterial({
    color: 0x9b2c2c, roughness: 0.55, clearcoat: 1, clearcoatRoughness: 0.08,
  }),
  velvet: new THREE.MeshPhysicalMaterial({
    color: 0x3b1d6b, roughness: 0.9, sheen: 1, sheenRoughness: 0.4, sheenColor: new THREE.Color(0xd8b4fe),
  }),
  brass: new THREE.MeshPhysicalMaterial({
    color: 0xc9a227, metalness: 1, roughness: 0.28, anisotropy: 0.7,
  }),
  glass: new THREE.MeshPhysicalMaterial({
    color: 0xffffff, metalness: 0, roughness: 0.04, transmission: 1,
    thickness: 0.6, ior: 1.5, attenuationColor: new THREE.Color(0x9ae6b4), attenuationDistance: 1.5,
  }),
  bubble: new THREE.MeshPhysicalMaterial({
    color: 0xffffff, roughness: 0.05, iridescence: 1, iridescenceIOR: 1.3,
    iridescenceThicknessRange: [100, 400], transmission: 0.9, thickness: 0.05,
  }),
};

const geometry = new THREE.SphereGeometry(0.9, 64, 48);
Object.values(gallery).forEach((material, i) => {
  const mesh = new THREE.Mesh(geometry, material);
  mesh.position.x = (i - 2) * 2.2;
  scene.add(mesh);
});

renderer.setAnimationLoop((time) => {
  scene.children.forEach((child) => { if (child.isMesh) child.rotation.y = time * 0.0004; });
  renderer.render(scene, camera);
});

Performance notes for the physical material:

  • Transmission is the expensive one. Objects with transmission > 0 need to see the rest of the scene, so the renderer first draws the opaque objects into an off-screen render target, which it reuses for every transmissive mesh in that frame. Keep the number of transmissive meshes small and the transmission render target resolution reasonable.

  • Clearcoat, sheen and iridescence add texture reads and arithmetic per fragment. They are fine for hero objects and costly when applied to every instance of a crowd.

  • The shader program count matters more than the arithmetic. Each distinct combination of features is a separate compiled program; on a slow machine a first frame with many variants can stall for hundreds of milliseconds (see three.js Performance and Disposal for compileAsync).

Several materials on one mesh

A Mesh accepts either one material or an array of materials. With an array, the geometry must carry groups: ranges of its index (or of its vertices, for non-indexed geometry) tagged with the array slot to use. BoxGeometry creates six groups, one per face, with material indices 0 to 5; SphereGeometry has a single group; BufferGeometry.addGroup(start, count, materialIndex) creates your own.

Six BoxGeometry groups with start and count, each pointing to the Pages, Spine or Cover material slot
Figure 6. Index ranges mapped to material slots

Every group is a separate draw call. A box with six groups is six draw calls even if three of them use the same material, so for a book the best structure is one group per material: reorder the index ranges so that faces with the same material are adjacent, and replace the six groups with three (or merge geometry, see three.js Geometry). The example below builds a book with three materials and does exactly that, so the book costs three draw calls instead of six:

import * as THREE from 'three';

function makeBook(textures) {
  // width (x), height (y), thickness (z): the large faces are +z and -z
  const geometry = new THREE.BoxGeometry(0.8, 1.2, 0.25);

  const pages = new THREE.MeshStandardMaterial({ name: 'Pages', map: textures.pages, roughness: 0.9 });
  const spine = new THREE.MeshStandardMaterial({ name: 'Spine', map: textures.spine, roughness: 0.6 });
  const cover = new THREE.MeshStandardMaterial({ name: 'Cover', map: textures.cover, roughness: 0.5 });

  // BoxGeometry creates one group per face, in the order +x, -x, +y, -y, +z, -z, six indices each.
  // Slot 0 = pages (faces +x, +y, -y), slot 1 = spine (-x), slot 2 = cover (+z, -z).
  const facesPerMaterial = [[0, 2, 3], [1], [4, 5]];

  const oldIndex = geometry.index.array;
  const newIndex = new oldIndex.constructor(oldIndex.length);
  let cursor = 0;
  geometry.clearGroups();
  facesPerMaterial.forEach((faces, materialIndex) => {
    const start = cursor;
    for (const face of faces) {
      newIndex.set(oldIndex.subarray(face * 6, face * 6 + 6), cursor);
      cursor += 6;
    }
    geometry.addGroup(start, cursor - start, materialIndex);
  });
  geometry.setIndex(new THREE.BufferAttribute(newIndex, 1));

  return new THREE.Mesh(geometry, [pages, spine, cover]);
}

GLB files do the same thing differently: a glTF mesh is a list of primitives, each with one material, and GLTFLoader turns a mesh with several primitives into a Group with one child Mesh per primitive, so the shared book of the Bookshelf model arrives as a handful of small meshes that use three materials. Material arrays are the older idiom (the three books used MeshFaceMaterial, a wrapper that three.js replaced with plain arrays in r85); both produce the same number of draw calls.

Transparency, alpha and render order

Transparency in a rasteriser is an ordering problem. Opaque surfaces can be drawn in any order because the depth buffer keeps the nearest; a blended surface must be drawn after everything behind it, and blending does not write colour to the depth buffer in a way that lets the next surface sort itself out. WebGLRenderer therefore keeps separate lists:

Three stages, opaque then transmissive then transparent, and two overlapping quads drawn in either order
Figure 7. How the renderer orders the lists
Setting What it does When to use it

transparent: true

Puts the mesh in the transparent list and enables blending with the material’s opacity, the alpha of map and the alphaMap.

Fading things, smoke, glass without refraction, ghosts.

opacity

Overall alpha from 0 to 1; only effective when transparent is true.

Fades and highlights.

alphaTest

Discards fragments whose alpha is below the threshold; the mesh stays in the opaque list and writes depth.

Leaves, chain-link fences, cut-out labels; no sorting problem at all.

alphaToCoverage: true

Turns the alpha into a multisample coverage mask, which smooths alphaTest edges when the framebuffer is multisampled.

Foliage and hair with antialias: true.

depthWrite: false

Blended surface does not write depth, so surfaces behind it drawn later still appear.

Particles, glows, sprites; avoids the dark halo around soft sprites.

side

FrontSide (default), BackSide, DoubleSide. Transparent double-sided meshes are drawn back faces first, then front faces.

Open meshes such as leaves; closed transparent bottles.

blending

NormalBlending (default), AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending.

Fire and sparks (additive); dark decals (multiply).

renderOrder

An integer on objects (and groups) that overrides the automatic sorting inside each list.

Force a glow behind another transparent mesh; draw a HUD last.

transmission (physical)

Moves the mesh to the transmissive list and refracts the opaque scene.

Real glass, water, gems.

The transparent list is sorted back to front by the position of each object’s bounding-sphere centre, one sort key per object, not per triangle. Two large intersecting quads, or a mesh that wraps around another, therefore cannot be ordered correctly from every viewpoint. The remedies, in order of preference, are: use alphaTest (or alphaToCoverage) instead of blending whenever the alpha is mostly 0 or 1; split big transparent meshes into pieces; set depthWrite: false for soft effects; set renderOrder by hand; and, for glass, use transmission, which renders glass after the opaque scene without relying on blending against the sorted list.

The glass door of the Bookshelf cabinet shows the three ways side by side:

import * as THREE from 'three';

// 1. Physically based glass: transmission, drawn after the opaque scene
const glass = new THREE.MeshPhysicalMaterial({
  color: 0xffffff,
  roughness: 0.03,
  transmission: 1,
  thickness: 0.05,
  ior: 1.5,
});

// 2. Plain alpha blending: a dusty film over the shelf, no refraction
const dust = new THREE.MeshBasicMaterial({
  color: 0xd1d5db,
  transparent: true,
  opacity: 0.18,
  depthWrite: false,        // never hide what is behind the film
});

// 3. Cut-out: a lace bookmark; alpha is 0 or 1, so no sorting is needed
const lace = new THREE.MeshStandardMaterial({
  map: new THREE.TextureLoader().load('/textures/lace.png'),
  alphaTest: 0.5,
  alphaToCoverage: true,    // only matters when the canvas is multisampled
  side: THREE.DoubleSide,
});
// The lace texture must be an sRGB colour texture:
lace.map.colorSpace = THREE.SRGBColorSpace;

const door = new THREE.Mesh(new THREE.PlaneGeometry(1.8, 1.4), glass);
const film = new THREE.Mesh(new THREE.PlaneGeometry(1.8, 1.4), dust);
film.position.z = 0.01;
film.renderOrder = 2;       // after the glass

Sharing, changing and disposing materials

  • Share by reference. All books of the same kind should use one material. Cloning (material.clone()) copies every property and shares the textures, so it is the right tool when two meshes must differ in one value.

  • Per-instance colour on an InstancedMesh does not need a clone: instancedMesh.setColorAt(index, color) multiplies the material colour per instance, which is how the instanced shelf gives each book its own hue.

  • needsUpdate. After changing something that alters the shader (assigning or removing a map, transparent, flatShading, vertexColors, side in some cases), set material.needsUpdate = true. Changing numeric values and colours needs nothing.

  • dispose(). A material owns GPU program state; textures are separate objects. When a material is no longer needed call material.dispose(), and dispose its textures too if nothing else uses them. The full lifecycle and what renderer.info reports are in three.js Performance and Disposal.

  • toneMapped. Set toneMapped: false on materials that must not be tone mapped (UI panels, exact colour swatches).

  • onBeforeCompile lets you edit a standard material’s shader source without rewriting it, and is covered in three.js Custom Shaders in GLSL (WebGLRenderer only).

Common mistakes

Symptom Cause Fix

Metals look black

Nothing to reflect: no scene.environment and no envMap.

Add an environment (see the next page) or use MeshStandardMaterial with metalness below 1.

Everything looks dull and plastic

roughness left at the default 1.0.

Lower it; use a roughnessMap or glTF values.

A roughness or metalness map has no effect

The scalar is 0 (metalness) or the wrong channel was packed.

Set the scalar to 1; pack roughness in green and metalness in blue.

Cover colour looks washed out

map.colorSpace was not set to SRGBColorSpace.

Set it on every colour texture; see the next page.

Normal map looks inverted

Map authored for the opposite green-channel convention.

material.normalScale.y = -1 or re-export the map.

Transparent objects pop or overlap wrongly

One sort key per object.

alphaTest, split the mesh, depthWrite: false or renderOrder.

Frame stalls when a new material first appears

Shader compile for a new program variant.

Create and pre-warm materials during loading with renderer.compileAsync(scene, camera).

Material changes are not visible

A shader-affecting change without needsUpdate.

Set material.needsUpdate = true.

What the books say, and what changed

The three books were written for r49 (PAR) and r69 (LTJ and TCB) and use materials in a pre-PBR vocabulary. Their ideas still help, but most of the code needs translating.

Book statement Today

PAR ch. 3, LTJ ch. 3 and 4, TCB ch. 4 and 5 build scenes with MeshLambertMaterial and MeshPhongMaterial, tuned by ambient, specular and shininess.

Both still exist. New work uses MeshStandardMaterial, and ambient light comes from an AmbientLight, a hemisphere light or an environment.

LTJ ch. 4, TCB ch. 4 use MeshFaceMaterial (later MultiMaterial) to give faces different materials.

A plain array of materials plus geometry groups (r85). MultiMaterial no longer exists.

All three books use renderer.gammaInput and gammaOutput and the THREE.Geometry face API for per-face colours.

Replaced by colour management and outputColorSpace (r152 defaults); Geometry and Face3 were removed in r125 and r126, so face colours are now a vertex colour attribute on a BufferGeometry.

LTJ ch. 9 and TCB ch. 7 enable the skinning, morphTargets and morphNormals flags on materials.

Removed in r129 to r130: skinning and morph targets are detected from the mesh.

LTJ ch. 10 and TCB ch. 4 set material.bumpMap and normalMap from plain image loads.

Same slots, but the textures now carry a colorSpace and normal maps stay NoColorSpace.

TCB ch. 4 and 5 adjust light intensities against Phong materials.

Light intensity units changed (physical units are the default since r155, and the legacy mode has since been removed), so old numbers look different.

The authoritative list is the three.js migration guide: Migration Guide.

Recent changes

Version Change

r152

Colour management and outputColorSpace become the default; texture.encoding replaced by texture.colorSpace.

r155

Physical light units become the default (legacy lighting mode off).

r163

MeshPhysicalMaterial.dispersion added; WebGLRenderer drops WebGL 1.

r180

RGBELoader deprecated in favour of HDRLoader (the same class under a new name).