Skip to content

Tone map the output ​

If your shader produces values above 1 — bright lights, additive particles, a bloom pyramid — add a tone mapping effect at the end of the chain to compress them into displayable colors.

ts
import { acesToneMapping, bloom, glCanvas } from "@radiancejs/gl";

glCanvas({
  canvas: "#glCanvas",
  fragment,
  uniforms: { uTime: ({ time }) => time / 500 },
  postEffects: [
    bloom(),
    acesToneMapping({ exposure: 1.5 }), // last: HDR → display
  ],
});

Without it, values above 1 clamp to white and highlights turn into flat discs.

Pick an operator ​

All operators take { exposure, outputColorSpace } and differ in how they roll off the highlights.

OperatorLookWhen to reach for it
linearToneMappingMultiplies by exposure, then clampsDebugging; scenes already in [0, 1]
reinhardToneMappingGentle x / (1 + x) compressionNeutral default, soft highlights
hableToneMappingFilmic Uncharted 2 curve, strong contrastPunchy, cinematic looks
acesToneMappingCinema standard, warm highlightsMatching a film / game pipeline
neutralToneMappingKhronos neutral, preserves hueAccurate color with extended range
cineonToneMappingFilm-scan lookSoft, slightly washed film emulation
agxToneMappingModern filmic, highlight detail and color fidelityThe current all-rounder

They are swappable one line at a time. Try them side by side on your scene before committing — Bloom has a live exposure control to play with.

Extra knob on Reinhard ​

reinhardToneMapping takes whitePoint: the luminance mapped to 1. Values above 1 enable the extended curve, which keeps small highlights from washing out.

ts
reinhardToneMapping({ exposure: 1, whitePoint: 4 });

Exposure ​

exposure multiplies the image before the curve. It is a plain uniform (uExposure), so it animates and binds to UI like anything else:

ts
const toneMapping = hableToneMapping({ exposure: 1 });
glCanvas({ canvas: "#glCanvas", fragment, postEffects: [toneMapping] });

toneMapping.uniforms.uExposure = 2.5; // a flash, a fade, a slider…

Output color space ​

By default the operators end with a linear → sRGB transfer (outputColorSpace: "sRGB"), which is what a normal canvas expects. If the drawing buffer is already in linear space (or you chain another transfer yourself), keep the values linear:

ts
acesToneMapping({ exposure: 1, outputColorSpace: "linear" });

For wide-gamut output, set the drawing buffer when creating the canvas:

ts
glCanvas({
  canvas: "#glCanvas",
  fragment,
  colorSpace: "display-p3", // or "srgb"
  postEffects: [acesToneMapping()],
});

See About color management for how the pieces fit — texture color spaces in, tone mapping and colorSpace out.

Where it goes in the chain ​

Last — or at least after every effect that feeds on brightness. Chain and order post effects has the full ordering rules.

ts
postEffects: [
  trails(), // accumulates bright motion
  bloom(), // glows on it
  acesToneMapping({ exposure: 1.2 }), // then compress
  fxaa(), // anti-alias the final pixels
],

See also ​

Released under the MIT License.