Color Grading, Tone Mapping and Vignette
The last pass of every frame decides how the game looks. The same lit scene can feel warm and nostalgic, cold and hostile, or washed-out and desperate, purely from the final color pass. This pass is also where the renderer's HDR light (values from 0 to thousands) becomes the 0–255 per channel a monitor accepts. It has three jobs, usually in one shader:
- Exposure and tone mapping: map unbounded HDR light into 0..1 without ugly clipping.
- Color grading: white balance, contrast, saturation, lift/gamma/gain, or a lookup table, chosen by an artist.
- Output: vignette, film grain, and the final sRGB (or HDR10) encoding.
Tone mapping curves
The simplest tone map is to clamp at 1, and it looks terrible: everything bright becomes the same flat white, and colors turn into cyan, yellow and magenta as single channels clip. A tone mapping curve compresses the highlights gradually instead. Compare three common ones, applied to linear scene values and then encoded to sRGB bytes:
// Three tone-mapping curves applied to scene luminance values (linear light).
const clamp01 = (x) => Math.min(Math.max(x, 0), 1);
const curves = {
clamp: (x) => clamp01(x),
reinhard: (x) => x / (1 + x),
aces: (x) => clamp01((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14)), // Narkowicz fit
};
// sRGB encoding: what the monitor finally receives (0..255)
const srgb = (x) => (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
const byte = (x) => String(Math.round(srgb(x) * 255)).padStart(5);
console.log('scene clamp reinhard aces (sRGB byte values)');
for (const x of [0.05, 0.18, 0.5, 1, 2, 4, 8, 16]) {
console.log(`${x.toFixed(2).padStart(5)} ${byte(curves.clamp(x))} ${byte(curves.reinhard(x))} ${byte(curves.aces(x))}`);
}scene clamp reinhard aces (sRGB byte values)
0.05 63 62 59
0.18 118 109 141
0.50 188 156 206
1.00 255 188 232
2.00 255 213 245
4.00 255 231 252
8.00 255 242 255
16.00 255 248 255
- clamp: perfect up to 1, then a wall. A sun of 16 and a sky of 1 are identical.
- Reinhard
x / (1 + x): never clips, but it also never reaches white, and it darkens mid-grey (0.18 → 109). Images look flat and grey. - ACES (fitted): an S-curve with a toe (slightly crushed shadows), punchy mid-tones, and a soft shoulder that reaches white around 8–10. This "filmic" look is the default in Unreal Engine and an option in Unity, Godot and Three.js. The fit from Krzysztof Narkowicz used here is brighter than the full ACES transform, so implementations often scale the input (by 0.6 or so) first.
Newer curves such as AgX (Blender's default since 4.0, available in Three.js and Godot) and Khronos' PBR Neutral keep saturated colors from shifting hue as they get brighter. Bright red lights in ACES tend to drift toward orange and yellow; in AgX they desaturate toward white like film.
The shader below plots the three curves for scene values 0 to 6 (white = clamp, orange = Reinhard, cyan = ACES fit). The three bands at the bottom show an orange light growing from 0 to 6 through each curve: clamp on top, Reinhard in the middle, ACES at the bottom.
float aces(float x) { return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }
float reinhard(float x) { return x / (1.0 + x); }
float srgb(float x) { return x <= 0.0031308 ? 12.92 * x : 1.055 * pow(x, 1.0 / 2.4) - 0.055; }
float curve(int i, float x) { return i == 0 ? clamp(x, 0.0, 1.0) : (i == 1 ? reinhard(x) : aces(x)); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
float x = uv.x * 6.0; // scene value 0..6
vec3 col = vec3(0.08);
vec3 colors[3] = vec3[3](vec3(1.0), vec3(1.0, 0.6, 0.2), vec3(0.3, 0.9, 1.0));
if (uv.y < 0.3) { // three gradient bands
int band = 2 - int(uv.y / 0.1);
vec3 hdr = vec3(1.0, 0.55, 0.3) * x; // an orange light getting brighter
col = vec3(srgb(curve(band, hdr.r)), srgb(curve(band, hdr.g)), srgb(curve(band, hdr.b)));
} else {
float y = (uv.y - 0.33) / 0.62; // graph area: output 0..1
if (abs(fract(x) - 0.0) < 0.005 * 6.0 || abs(y - 1.0) < 0.004) col = vec3(0.2); // grid
float px = 1.5 / iResolution.y / 0.62; // line thickness in graph units
for (int i = 0; i < 3; i++) {
float d = abs(curve(i, x) - y);
col = mix(col, colors[i], smoothstep(px * 2.0, px, d));
}
}
fragColor = vec4(col, 1.0);
}Look at the bands: clamp turns the orange light yellow and then flat white-yellow (the red channel clips first, so the hue shifts); Reinhard stays dull; the ACES band keeps contrast and fades into a bright highlight.
Grading controls
Grading operations act on color after (or around) tone mapping. The standard set, and the formula behind each:
| Control | What it does | Shader |
|---|---|---|
| exposure | brightness in stops, before tone mapping | c *= exp2(ev) |
| white balance / temperature | warm or cool the image | multiply by a per-channel gain, e.g. vec3(1.05, 1.0, 0.92) (engines convert a Kelvin value to it) |
| saturation | toward or away from grey | mix(vec3(luma), c, s) |
| contrast | spread values away from a pivot | (c - 0.5) * k + 0.5 in a log or display space |
| lift / gamma / gain | shadows / mid-tones / highlights, often per channel | pow(max(c * gain + lift * (1 - c), 0), 1 / gamma) (one common form) |
| vignette | darken toward the corners | c *= smoothstep(r1, r0, length(uv - 0.5)) |
Sliders are good for tuning; for shipping, many games bake the whole grade into a 3D lookup table (LUT). An artist takes a screenshot with a neutral LUT embedded, grades it in DaVinci Resolve or Photoshop, and the tool's changes are copied into the LUT. At runtime the shader does one 3D texture fetch per pixel, whatever the grade's complexity:
uniform sampler3D uLut; // e.g. 32x32x32, RGB in, RGB out
const float LUT_SIZE = 32.0;
vec3 applyLut(vec3 c) { // c: tone-mapped, display-referred 0..1
// map 0..1 to texel centers so the ends are not half-blended with the border
vec3 uvw = c * ((LUT_SIZE - 1.0) / LUT_SIZE) + 0.5 / LUT_SIZE;
return texture(uLut, uvw).rgb;
}Unity URP (Color Lookup override), Unreal (Color Grading LUT in the Post Process Volume) and Godot 4 (Environment.adjustment_color_correction, which takes a 3D texture or a gradient) all support LUTs next to their sliders.
The whole final pass, live
This example renders an HDR scene into a HalfFloatType target and grades it in one pass. Use the sliders; switch the tone mapping to see the curves from above on a real scene.
<style>
body { margin: 0; background: #000; font: 12px system-ui, sans-serif; color: #eee }
canvas { display: block }
#ui { position: fixed; top: 6px; left: 6px; background: rgba(0,0,0,.55); padding: 6px 8px; border-radius: 6px; display: grid; grid-template-columns: auto 110px; gap: 2px 8px; align-items: center }
input { width: 110px }
</style>
<div id="ui">
<label>tone map</label><select id="tm"><option value="0">clamp</option><option value="1">Reinhard</option><option value="2" selected>ACES fit</option></select>
<label>exposure</label><input id="exposure" type="range" min="-3" max="3" step="0.1" value="0">
<label>temperature</label><input id="temperature" type="range" min="-1" max="1" step="0.05" value="0">
<label>saturation</label><input id="saturation" type="range" min="0" max="2" step="0.05" value="1">
<label>contrast</label><input id="contrast" type="range" min="0.5" max="1.5" step="0.05" value="1">
<label>vignette</label><input id="vignette" type="range" min="0" max="1" step="0.05" value="0.4">
</div>
<script type="module">
import * as THREE from 'three';
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const size = renderer.getDrawingBufferSize(new THREE.Vector2());
// HDR scene: a bright sun lamp, colored lights, a sky far above 1
const scene = new THREE.Scene();
scene.background = new THREE.Color(0.6, 0.8, 1.6);
const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight, 0.1, 100);
camera.position.set(0, 1.6, 7);
camera.lookAt(0, 0.4, 0);
scene.add(new THREE.HemisphereLight(0xaaccff, 0x553322, 1.0));
const sun = new THREE.DirectionalLight(0xfff0dd, 6);
sun.position.set(4, 6, 3);
scene.add(sun);
const ground = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), new THREE.MeshStandardMaterial({ color: 0x7a8a5a }));
ground.rotation.x = -Math.PI / 2;
scene.add(ground);
const objects = [];
[0xd04040, 0xe0c060, 0x4080e0, 0xf0f0f0, 0x40c080].forEach((c, i) => {
const m = new THREE.Mesh(i % 2 ? new THREE.SphereGeometry(0.55, 48, 24) : new THREE.BoxGeometry(0.9, 0.9, 0.9),
new THREE.MeshStandardMaterial({ color: c, roughness: 0.3 }));
m.position.set((i - 2) * 1.5, 0.55, 0);
scene.add(m);
objects.push(m);
});
const lamp = new THREE.Mesh(new THREE.SphereGeometry(0.15, 16, 8), new THREE.MeshBasicMaterial({ color: new THREE.Color(8, 3, 1) }));
lamp.position.set(0, 2.2, 0.5);
scene.add(lamp);
const sceneRT = new THREE.WebGLRenderTarget(size.x, size.y, { type: THREE.HalfFloatType, samples: 4 });
const grade = new THREE.ShaderMaterial({
uniforms: {
tScene: { value: sceneRT.texture }, uToneMap: { value: 2 }, uExposure: { value: 0 },
uTemperature: { value: 0 }, uSaturation: { value: 1 }, uContrast: { value: 1 }, uVignette: { value: 0.4 },
},
vertexShader: `varying vec2 vUv; void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }`,
fragmentShader: /* glsl */ `
uniform sampler2D tScene;
uniform int uToneMap;
uniform float uExposure, uTemperature, uSaturation, uContrast, uVignette;
varying vec2 vUv;
vec3 aces(vec3 x) { return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }
void main() {
vec3 c = texture2D(tScene, vUv).rgb; // linear HDR
c *= exp2(uExposure); // exposure (stops)
c *= vec3(1.0 + 0.1 * uTemperature, 1.0, 1.0 - 0.1 * uTemperature); // white balance
float luma = dot(c, vec3(0.2126, 0.7152, 0.0722));
c = max(mix(vec3(luma), c, uSaturation), 0.0); // saturation
float v = smoothstep(0.8, 0.2, length(vUv - 0.5)); // vignette in linear light
c *= mix(1.0, v, uVignette);
if (uToneMap == 0) c = clamp(c, 0.0, 1.0); // tone mapping
else if (uToneMap == 1) c = c / (1.0 + c);
else c = aces(c * 0.6);
c = clamp((c - 0.5) * uContrast + 0.5, 0.0, 1.0); // contrast around mid-grey
gl_FragColor = vec4(c, 1.0);
#include <colorspace_fragment>
}`,
});
const postScene = new THREE.Scene();
postScene.add(new THREE.Mesh(new THREE.PlaneGeometry(2, 2), grade));
const postCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
const bind = (id, name, parse = Number) => document.getElementById(id).addEventListener('input', (e) => { grade.uniforms[name].value = parse(e.target.value); });
bind('tm', 'uToneMap', (v) => parseInt(v, 10));
bind('exposure', 'uExposure'); bind('temperature', 'uTemperature'); bind('saturation', 'uSaturation');
bind('contrast', 'uContrast'); bind('vignette', 'uVignette');
renderer.setAnimationLoop((ms) => {
objects.forEach((o, i) => { o.rotation.y = ms / 2000 + i; });
renderer.setRenderTarget(sceneRT);
renderer.render(scene, camera);
renderer.setRenderTarget(null);
renderer.render(postScene, postCamera);
});
</script>Things to try: set tone mapping to clamp and watch the sky and the lamp turn into flat patches; raise exposure by 2 stops with ACES and see the highlights roll off instead of clipping; push saturation to 2 and notice that ACES still keeps the brightest areas from turning neon.
Order and color spaces
Where each step happens changes the result:
- Exposure and white balance belong in linear HDR, before tone mapping, because they model the light and the camera.
- Tone mapping converts scene-referred light into display-referred 0..1.
- Contrast, lift/gamma/gain and LUTs usually act on display-referred or log-encoded values; engines grade in a log space (ACEScc-like) so controls behave the same in shadows and highlights.
- sRGB encoding comes last, exactly once. In Three.js the
colorspace_fragmentinclude does it, in engines the final blit does it. HDR displays need a different output transform (PQ/HDR10), which is why engines keep grading and output separate. - Vignette and film grain are usually applied late; grain is added after tone mapping so its strength does not depend on scene brightness.
Test yourself
What is the main problem with clamping HDR values at 1.0 instead of tone mapping?
- It is slower
- All highlights above 1 become the same flat value and hues shift as single channels clip
- It makes shadows brighter
- It requires float textures
Where should exposure be applied?
- After the sRGB encode
- In linear HDR, before tone mapping
- Only in the vertex shader
- Inside the LUT
Why do games bake a color grade into a 3D LUT?
- LUTs add HDR support
- Any combination of grading operations costs one texture fetch at runtime
- LUTs replace tone mapping
- They avoid the sRGB conversion