Material Types
A material decides the color of every pixel a mesh covers. Three.js has a family of ready-made materials that range from "paint it one color" to physically based models of clear-coated car paint and glass. Choosing one is a trade between look and cost: the fancier the material, the more work the GPU does for every pixel of it.
The lineup
The spheres below use (left to right) MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshStandardMaterial, MeshPhysicalMaterial (with clearcoat) and MeshToonMaterial, all with the same base color under the same two lights:
<style>html, body { margin: 0; height: 100%; overflow: hidden } canvas { display: block }
#names { position: fixed; bottom: 10px; left: 0; right: 0; display: flex; justify-content: space-around; color: #ddd; font: 12px system-ui, sans-serif }</style>
<div id="names"><span>Basic</span><span>Lambert</span><span>Phong</span><span>Standard</span><span>Physical</span><span>Toon</span></div>
<script type="module">
import * as THREE from 'three';
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color('#14171f');
const camera = new THREE.OrthographicCamera(-6.6, 6.6, 6.6 * innerHeight / innerWidth, -6.6 * innerHeight / innerWidth, 0.1, 50);
camera.position.set(0, 0, 10);
addEventListener('resize', () => {
renderer.setSize(innerWidth, innerHeight);
camera.top = 6.6 * innerHeight / innerWidth;
camera.bottom = -camera.top;
camera.updateProjectionMatrix();
renderer.render(scene, camera);
});
scene.add(new THREE.AmbientLight('#ffffff', 0.25));
const key = new THREE.DirectionalLight('#ffffff', 2.5);
key.position.set(-3, 4, 5);
const rim = new THREE.PointLight('#88aaff', 30);
rim.position.set(4, -2, 3);
scene.add(key, rim);
const color = '#d0503c';
const materials = [
new THREE.MeshBasicMaterial({ color }),
new THREE.MeshLambertMaterial({ color }),
new THREE.MeshPhongMaterial({ color, shininess: 80 }),
new THREE.MeshStandardMaterial({ color, roughness: 0.35, metalness: 0 }),
new THREE.MeshPhysicalMaterial({ color, roughness: 0.6, clearcoat: 1, clearcoatRoughness: 0.05 }),
new THREE.MeshToonMaterial({ color }),
];
const geo = new THREE.SphereGeometry(0.95, 48, 24);
materials.forEach((m, i) => {
const s = new THREE.Mesh(geo, m);
s.position.x = (i - 2.5) * 2.2;
scene.add(s);
});
renderer.render(scene, camera); // a still image: render once
</script>| Material | Lighting model | Notes |
|---|---|---|
MeshBasicMaterial |
none | flat color or texture; ignores lights (cheapest) |
MeshLambertMaterial |
diffuse only | matte; lighting is computed per pixel in current releases, but with no specular highlight |
MeshPhongMaterial |
diffuse + Blinn-Phong highlight | shininess, specular; not energy-conserving, looks "plastic" |
MeshStandardMaterial |
PBR, metalness/roughness | the default choice; matches glTF's material model |
MeshPhysicalMaterial |
PBR + extras | clearcoat, transmission (glass), sheen (cloth), iridescence, ior … each adds cost |
MeshToonMaterial |
banded (cel) shading | gradientMap controls the bands |
MeshMatcapMaterial |
none (baked look from a "matcap" image) | very cheap stylised shading, no lights needed |
PBR: metalness and roughness
MeshStandardMaterial describes a surface with physical parameters instead of artistic "shininess":
color(albedo): the surface's own color.metalness0–1: 0 for dielectrics (plastic, wood, stone, skin), 1 for bare metal. Real materials are almost always one or the other; values in between are for transitions such as rusty or dusty metal.roughness0–1: 0 is a mirror-smooth surface with sharp reflections, 1 is fully rough and matte.emissive+emissiveIntensity: light the surface gives off by itself (screens, lava, glowing gems). It doesn't light other objects.
Metals get almost all their look from reflecting their surroundings. With only direct lights, a metal sphere looks dark except for a highlight. Give the scene an environment map and it comes alive. This grid varies metalness (rows) and roughness (columns) with a generated room environment:
<style>html, body { margin: 0; height: 100%; overflow: hidden } canvas { display: block }</style>
<script type="module">
import * as THREE from 'three';
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;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color('#202430');
// Image-based lighting: a procedural room, pre-filtered for every roughness level.
const pmrem = new THREE.PMREMGenerator(renderer);
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
const camera = new THREE.PerspectiveCamera(30, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 0, 10);
const geo = new THREE.SphereGeometry(0.55, 48, 24);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 6; col++) {
const mat = new THREE.MeshStandardMaterial({ color: row ? '#e8c26a' : '#3f7fd6', metalness: row, roughness: col / 5 });
const s = new THREE.Mesh(geo, mat);
s.position.set((col - 2.5) * 1.35, row ? -0.75 : 0.75, 0);
scene.add(s);
}
}
console.log('top row: metalness 0 (blue plastic), bottom row: metalness 1 (gold)');
console.log('roughness left to right: 0, 0.2, 0.4, 0.6, 0.8, 1');
renderer.setAnimationLoop(() => renderer.render(scene, camera));
</script>The Environment Maps & PBR lesson covers where environment maps come from; RoomEnvironment is an addon that builds a simple studio-like room in code, which is handy when you have no HDR image.
Texture maps on materials
Every PBR parameter can also come from a texture, so one mesh can be partly rusty and partly shiny:
| Map | Controls | Color space |
|---|---|---|
map |
base color | sRGB |
normalMap |
fake surface detail (bumps, scratches) via per-pixel normals | linear (no change) |
roughnessMap, metalnessMap |
per-pixel roughness / metalness (glTF packs them in the G and B channels of one texture) | linear |
aoMap |
ambient occlusion: dark creases (uses the uv set, or another set chosen with texture.channel) |
linear |
emissiveMap |
where the surface glows | sRGB |
alphaMap |
per-pixel opacity (with transparent or alphaTest) |
linear |
Only color textures (map, emissiveMap) get texture.colorSpace = THREE.SRGBColorSpace; data textures stay linear. The Textures & UVs lesson builds such textures in code.
Transparency without the pain
Transparent materials (transparent: true with opacity or an alpha channel) are drawn after opaque ones, sorted back to front per object, not per triangle. Two common problems and fixes:
- Foliage, fences, hair cards: use
alphaTest: 0.5instead oftransparent. Pixels below the threshold are discarded, the rest are opaque and write depth, so sorting no longer matters and it's cheaper. - Intersecting transparent objects flicker or vanish: sorting can't solve them. Set
depthWrite: falseon soft effects (smoke, glows), or split the meshes.
Choosing for a game
- Start with
MeshStandardMaterialeverywhere. It is what glTF models load as, and it looks right under any lighting. - Use
MeshBasicMaterialfor unlit things: skyboxes, UI in 3D, effects, pixel-art billboards. - On weak mobile GPUs,
MeshLambertMaterial(or Basic with baked lighting in the texture) is a big saving for large surfaces such as terrain. - Reach for
MeshPhysicalMaterialonly where its features show (the hero car, a glass bottle).transmissionin particular renders the scene an extra time. - Every distinct material is (at least) one shader program and one draw call per mesh using it. Share materials between meshes wherever possible (see Draw Calls).
Test yourself
A gold coin made with MeshStandardMaterial({ metalness: 1, roughness: 0.2 }) looks almost black. What is missing?
- A higher
emissiveIntensity - Something to reflect: an environment map (
scene.environment) transparent: true- Flat shading
Which texture should have colorSpace = THREE.SRGBColorSpace?
- normalMap
- roughnessMap
- map (base color)
- aoMap
Leaves with transparent edges sort incorrectly and flicker. What is the usual fix?
- Use
MeshPhysicalMaterial - Use
alphaTest(alpha clipping) instead oftransparent - Increase the camera's
near - Disable shadows