Color Spaces & Tone Mapping
"Everything looks washed out" and "my colors are too dark" are the two most common complaints about Three.js scenes, and both usually come from color management. The rules are short once you see why they exist.
Two kinds of numbers
Screens and image files store colors in sRGB, a non-linear encoding that spends more of its 256 levels on dark tones, where our eyes are most sensitive. Lighting maths, on the other hand, must work on linear values, proportional to the amount of light: two lamps give twice the light, and that is only true in linear space.
So a renderer has to:
- convert input colors (color pickers, hex codes, color textures) from sRGB to linear,
- do all lighting in linear space,
- convert the result back to sRGB for the screen.
Three.js does all three automatically (THREE.ColorManagement.enabled is true, the working space is linear sRGB, and renderer.outputColorSpace is THREE.SRGBColorSpace), with one exception you must handle yourself: it can't know what a texture's pixels mean. A base-color texture is sRGB; a normal map or roughness map is linear data. That's why you set texture.colorSpace = THREE.SRGBColorSpace on color textures only.
This model shows the conversion and why the difference matters:
// sRGB <-> linear conversion (the standard sRGB transfer function), values 0..1.
const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
const toSRGB = (l) => (l <= 0.0031308 ? l * 12.92 : 1.055 * l ** (1 / 2.4) - 0.055);
const byte = (x) => Math.round(x * 255);
for (const v of [0.1, 0.25, 0.5, 0.75]) {
console.log(`sRGB ${v.toFixed(2)} (byte ${String(byte(v)).padStart(3)}) = linear ${toLinear(v).toFixed(3)}`);
}
// Mixing black and white 50/50 (e.g. a blurred checkerboard):
const naive = (0 + 1) / 2; // averaged sRGB numbers
const correct = toSRGB((toLinear(0) + toLinear(1)) / 2); // averaged light, then encoded
console.log(`50% mix: naive sRGB byte ${byte(naive)}, physically correct byte ${byte(correct)}`);
// What happens if an sRGB texture is NOT converted (treated as linear) and then encoded for output:
const texel = 0.5;
console.log(`texel 0.5 shown as byte ${byte(toSRGB(toLinear(texel)))} when correct, ${byte(toSRGB(texel))} when the colorSpace is missing`);sRGB 0.10 (byte 26) = linear 0.010
sRGB 0.25 (byte 64) = linear 0.051
sRGB 0.50 (byte 128) = linear 0.214
sRGB 0.75 (byte 191) = linear 0.523
50% mix: naive sRGB byte 128, physically correct byte 188
texel 0.5 shown as byte 128 when correct, 188 when the colorSpace is missing
The last line is the "washed out" bug in numbers: a mid-grey texel (128) is displayed as 188, because the output conversion brightens a value that was never darkened on the way in. Every color in the texture shifts toward white and loses saturation.
The checklist
| Thing | Setting | Default in r186 |
|---|---|---|
| Output to the screen | renderer.outputColorSpace = THREE.SRGBColorSpace |
already sRGB |
Colors in code (new THREE.Color('#ff8800'), material.color.set(0xff8800)) |
treated as sRGB and converted | automatic |
Color textures you load or create (map, emissiveMap, sprites, UI) |
texture.colorSpace = THREE.SRGBColorSpace |
not set (NoColorSpace) |
Data textures (normalMap, roughnessMap, metalnessMap, aoMap, height) |
leave as is | linear |
| Textures inside glTF models | set by GLTFLoader |
automatic |
Vertex colors written into a color attribute |
must be linear; Color.set('#…') then color.r/g/b gives linear values |
your job |
Colors for 2D canvas/CSS from a THREE.Color |
color.getHexString() / getStyle() return sRGB |
automatic |
Note: Code from before r152 used
renderer.outputEncoding = THREE.sRGBEncodingandtexture.encoding. Those were replaced byoutputColorSpaceandcolorSpace, and the old names have been removed.
Tone mapping
Lighting easily produces values above 1.0: the sun on a white wall, a bright sky, an emissive lamp. A screen can't show more than 1.0, so without tone mapping those pixels simply clip to flat white, and bright colors lose their hue. A tone mapping curve compresses the whole range smoothly into 0–1, like a film or a camera sensor does.
// Three tone curves applied to linear HDR values (per channel).
const none = (x) => Math.min(x, 1); // clip
const reinhard = (x) => x / (1 + x);
const aces = (x) => { // Narkowicz's fit of the ACES filmic curve
const a = 2.51, b = 0.03, c = 2.43, d = 0.59, e = 0.14;
return Math.min(1, Math.max(0, (x * (a * x + b)) / (x * (c * x + d) + e)));
};
console.log('linear in | none | Reinhard | ACES fit');
for (const x of [0.1, 0.5, 1, 2, 4, 16]) {
console.log(`${x.toFixed(1).padStart(9)} | ${none(x).toFixed(3)} | ${reinhard(x).toFixed(3)} | ${aces(x).toFixed(3)}`);
}linear in | none | Reinhard | ACES fit
0.1 | 0.100 | 0.091 | 0.126
0.5 | 0.500 | 0.333 | 0.616
1.0 | 1.000 | 0.500 | 0.804
2.0 | 1.000 | 0.667 | 0.915
4.0 | 1.000 | 0.800 | 0.973
16.0 | 1.000 | 0.941 | 1.000
Without a curve, 1, 2, 4 and 16 all become the same white. The curves keep them distinguishable. (Three.js's own ACES implementation differs in detail from this simple fit, but the shape is the same.)
Compare the tone mappers on a scene with a very bright sun and an emissive lamp:
<style>html, body { margin: 0; height: 100%; overflow: hidden } canvas { display: block }
#ui { position: fixed; left: 8px; top: 8px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; color: #fff; font: 12px system-ui, sans-serif }
button { font: 12px system-ui, sans-serif } button.on { outline: 2px solid #4fc3f7 }</style>
<div id="ui"></div>
<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);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color('#5a7aa0');
scene.environment = new THREE.PMREMGenerator(renderer).fromScene(new RoomEnvironment(), 0.04).texture;
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 2, 7);
camera.lookAt(0, 0.8, 0);
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
const sun = new THREE.DirectionalLight('#fff3dc', 8); // deliberately strong: HDR highlights
sun.position.set(3, 5, 2);
scene.add(sun);
const floor = new THREE.Mesh(new THREE.PlaneGeometry(20, 20), new THREE.MeshStandardMaterial({ color: '#c8c0b0' }));
floor.rotation.x = -Math.PI / 2;
scene.add(floor);
const colors = ['#e53935', '#fdd835', '#43a047', '#1e88e5'];
colors.forEach((c, i) => {
const m = new THREE.Mesh(new THREE.SphereGeometry(0.6, 48, 24), new THREE.MeshStandardMaterial({ color: c, roughness: 0.35 }));
m.position.set((i - 1.5) * 1.6, 0.6, 0);
scene.add(m);
});
const lamp = new THREE.Mesh(new THREE.BoxGeometry(0.6, 0.6, 0.6), new THREE.MeshStandardMaterial({ color: '#000', emissive: '#ff7a1a', emissiveIntensity: 6 }));
lamp.position.set(0, 2.2, -1.5);
scene.add(lamp);
const modes = { None: THREE.NoToneMapping, Reinhard: THREE.ReinhardToneMapping, ACESFilmic: THREE.ACESFilmicToneMapping, AgX: THREE.AgXToneMapping, Neutral: THREE.NeutralToneMapping };
const ui = document.getElementById('ui');
for (const [name, mode] of Object.entries(modes)) {
const b = document.createElement('button');
b.textContent = name;
b.onclick = () => {
renderer.toneMapping = mode; // materials pick up the change on the next render
ui.querySelectorAll('button').forEach((x) => x.classList.toggle('on', x === b));
};
ui.appendChild(b);
}
const exp = document.createElement('label');
exp.innerHTML = 'exposure <input type="range" min="0.2" max="2" step="0.05" value="1">';
exp.querySelector('input').oninput = (e) => { renderer.toneMappingExposure = +e.target.value; };
ui.appendChild(exp);
ui.querySelectorAll('button')[3].click(); // start with AgX
renderer.setAnimationLoop(() => renderer.render(scene, camera));
</script>With None, the lit sides of the spheres burn out to flat, hue-less patches. ACESFilmic gives the punchy, slightly saturated "film" look many games use; AgX (added in r160) handles very bright saturated colors more gracefully, desaturating toward white like a real camera; Neutral (Khronos PBR Neutral) keeps base colors closest to how they were authored, which suits product and UI-heavy scenes. Exposure (renderer.toneMappingExposure) scales the light before the curve, like a camera's exposure setting.
Rules of thumb
- Leave
outputColorSpaceat sRGB. SetcolorSpace = SRGBColorSpaceon every color texture you create or load yourself. - Pick a tone mapper early (AgX or ACESFilmic for games) and light the scene with it on. Switching later changes every color in the game.
- Tone mapping is applied when rendering to the screen. With a post-processing chain (
EffectComposer), it moves into the finalOutputPass. - Materials such as UI sprites or HUD planes that should keep their exact colors can opt out with
material.toneMapped = false. - Judge colors on more than one screen; a phone's display can look very different from your monitor.
Test yourself
You create a CanvasTexture from a 2D canvas painting and the result looks pale and washed out. What is the fix?
renderer.outputColorSpace = THREE.LinearSRGBColorSpacetexture.colorSpace = THREE.SRGBColorSpacerenderer.toneMapping = THREE.NoToneMappingmaterial.toneMapped = false
Which of these textures should NOT be tagged as sRGB?
- The base color map
- The emissive map
- The normal map
- A sprite's image
What problem does tone mapping solve?
- Converting textures to sRGB
- Compressing lighting values above 1.0 into the displayable range so highlights don't clip to flat white
- Reducing draw calls
- Removing shadow acne