From BreakEnderNerd Alert

Nerd Alert: Tone Mapping and Auto Exposure, or How Games Fit the Sun Onto Your Screen

By the BreakEnder newsroom ยท

The sun is millions of times brighter than a cave, but your monitor only has so much range. Tone mapping and eye adaptation are how games squash reality into pixels.

Walk out of a dark tunnel in a modern game and the world blazes white for a second, then settles as your "eyes" adjust. Walk back in and everything is pitch black until it slowly opens up. That is not just atmosphere. It is the visible edge of a pipeline every 3D game runs on every frame: high dynamic range rendering, exposure, and tone mapping.

The range problem

Dynamic range is the ratio between the brightest and darkest things in a scene. Reality has enormous range: direct sunlight on snow is many thousands of times brighter than a shaded forest floor, and a light bulb filament is far brighter still. A typical SDR (standard dynamic range) monitor can show a range of maybe a thousand to one. Even HDR TVs are nowhere near the real world.

Modern games solve this the same way cameras do. First, they compute lighting in physical-ish units with no upper limit. A pixel of sky might be 20,000, a pixel of dark cave 0.5. This is called HDR rendering, and the image is stored with floating-point numbers so very big and very small values both survive. Then, at the end of the frame, they squash that huge range down into the 0-to-1 range the screen accepts. That squashing has two steps: exposure and tone mapping.

Step 1: exposure

Exposure is a single multiplier for the whole image, like a camera's shutter and aperture combined. Bright scene, small multiplier. Dark scene, big multiplier.

color = hdrColor * exposure;

Photographers measure exposure in "stops" (EV, exposure value), where each stop doubles or halves the light. Engines often expose the same thing, so artists can say "this interior is 3 stops darker than outside".

Auto exposure, or eye adaptation

Hand-setting exposure works for cutscenes, but in an open world the camera wanders from sunlight into caves. So games measure the frame and pick exposure automatically.

The usual method computes the average brightness of the frame. Averaging plain brightness lets one bright sky dominate, so engines average the logarithm of brightness instead, which treats "twice as bright" equally whether it goes from 1 to 2 or from 1,000 to 2,000. Many engines build a histogram (a count of how many pixels fall into each brightness bucket) and ignore the brightest and darkest few percent, so a single lamp or a black shadow does not swing the whole picture.

Then, instead of jumping straight to the new exposure, the game eases toward it over time:

exposure = lerp(exposure, targetExposure, 1 - exp(-deltaTime * adaptSpeed));

"lerp" means blend between two values. That smoothing is the eye adaptation you notice leaving the tunnel. Designers often make adaptation from dark to bright faster than bright to dark, because human eyes behave roughly that way.

Step 2: tone mapping

After exposure, many pixels are still above 1.0: the sun, sky, sparks, lamps. If you just cut everything above 1.0 off (called clipping), bright areas become flat white blobs and saturated colors turn into ugly flat patches.

A tone mapping curve fixes that. It is a function that takes any brightness from zero to infinity and smoothly bends it into 0 to 1. Dark and middle values stay roughly the same, while bright values are gently compressed so they approach white without slamming into it.

The simplest is the Reinhard operator:

mapped = color / (1 + color);

A value of 1 becomes 0.5, a value of 10 becomes about 0.91, and nothing ever quite reaches 1. It is smooth but tends to look washed out.

Games wanted the look of film, which has a characteristic S-shaped response: a gentle "toe" in the darks that deepens blacks, a straight middle, and a soft "shoulder" that rolls off highlights. John Hable, who worked on Uncharted 2, wrote a well-known explanation of filmic tone mapping curves and shared the curve he used (Hable: Filmic Tonemapping Operators). That post is still a rite of passage for graphics programmers.

Today many games use curves based on ACES, a color standard from the film industry, or engine-specific curves that handle very saturated lights more gracefully, such as Blender's AgX view or the Khronos PBR Neutral curve aimed at showing product colors accurately. Each has a different personality: punchy, neutral, warm.

Why bright colors go weird

A subtle point. If you apply the curve to red, green and blue separately, a very bright saturated orange flame drifts toward yellow and then white as each channel saturates at a different rate. Sometimes that looks great (fire really does look yellow-white at its core). Sometimes it is wrong, like a blue neon sign turning purple. Newer curves try to keep hue steady while still desaturating extreme highlights, which is a big topic in engine circles right now.

HDR displays

On an HDR TV, the game still tone maps, but to a much larger target range, measured in nits (a unit of screen brightness). The game asks the system how bright the display can go and shapes its curve to fit. That is why HDR games have calibration screens asking you to adjust until a logo just disappears: they are finding your screen's limits.

Where color grading fits

After tone mapping, many games apply color grading, often with a lookup table, to give the image its mood. That is the subject of our next Nerd Alert.

Spot it yourself

  • Exit a dark building in daylight and time the adaptation. That is the exposure smoothing speed.
  • Look at the sun or a bright explosion. Do highlights roll off softly to white or clip to flat blobs?
  • Check a game's HDR settings for "paper white" or "peak brightness". Those set the tone mapping target.

Glossary

  • Dynamic range: the ratio between the brightest and darkest values.
  • HDR rendering: computing light with no upper limit before display.
  • Exposure: one overall brightness multiplier.
  • Histogram: a count of pixels per brightness bucket.
  • Tone mapping: a curve that squeezes unlimited brightness into displayable range.
  • Nit: a unit of display brightness.

For a deeper dive, Real-Time Rendering, Fourth Edition covers this technique and its neighbors in detail, with references to the original papers.

As an Amazon Associate, BreakEnder earns from qualifying purchases.