11. Bloom

Making bright things glow — thresholding, blur, and HDR post-processing

Point a camera at a bright light and the glow bleeds beyond the light's actual boundary. That's not a flaw — it's how real lenses behave. Light scatters inside the lens, producing a soft halo around any intense source. Bloom is the post-processing effect that recreates this in a renderer.

It's one of the simplest effects to implement, but getting it to look good — bright without washing out the image — takes some care.

Why Bloom Matters

Without bloom, a 1000-lumen light source and a 10-lumen surface might look almost the same once they're both clamped to the [0, 1] display range. Bloom makes bright things feel bright by letting their light spill into neighboring pixels. It's a perceptual cue that sells the difference between "bright" and "very bright."

This only works properly with High Dynamic Range (HDR) rendering — if your color values are already clamped to [0, 1] before bloom, everything above white looks the same and there's nothing meaningful to extract.

The Bloom Pipeline

The classic approach has four steps:

1. Render scene to HDR buffer
2. Extract bright pixels (threshold)
3. Blur the bright pixels
4. Composite the blurred result back onto the original

Step 1: HDR Rendering

Render the scene to a floating-point framebuffer (e.g., RGBA16F). Fragment colors can exceed 1.0 — a sun might output (50.0, 48.0, 40.0), a sky might be (2.0, 2.5, 3.0), and a wall in shade might be (0.3, 0.25, 0.2).

Without HDR, all three would be clamped to (1.0, 1.0, 1.0) or below. With HDR, the full range is preserved for post-processing.

Step 2: Brightness Threshold

Extract the parts of the image that should glow. Sample the HDR buffer and keep only fragments above a brightness threshold:

color = texture(hdr_buffer, uv)
brightness = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722))  // luminance

if brightness > threshold:
    bright_color = color
else:
    bright_color = vec3(0.0)

The dot with those specific weights converts RGB to perceptual luminance (ITU-R BT.709 coefficients — the same ones used in HDTV). This matches how humans perceive brightness far better than a simple average.

Hard vs. Soft Threshold

A hard cutoff creates visible edges where bloom starts. A soft knee — a smooth transition around the threshold — produces much more natural results. The standard approach: linearly ramp from no contribution at threshold - knee to full contribution at threshold + knee.

Interactive

Brightness threshold extraction

Adjust the threshold to see which parts of the HDR scene are extracted for bloom. Lower thresholds extract more of the image.

With a soft knee:

x = brightness - threshold + knee
bright_color = color * clamp(x / (2.0 * knee), 0.0, 1.0)

Step 3: Blur

The extracted bright pixels need to be spread outward. A Gaussian blur is the standard choice because it produces a natural, bell-curve falloff.

The Separable Trick

A 2D Gaussian blur with a kernel of size N requires N² texture samples per pixel. But the Gaussian is separable — a 2D Gaussian is the product of two 1D Gaussians. So instead of one N² pass, do two N passes: blur horizontally, then blur vertically. The result is identical.

// Horizontal pass
for each pixel:
    sum = 0
    for i in -radius to +radius:
        sum += texture(input, uv + vec2(i * texel_w, 0)) * weight[i]
    output = sum

// Vertical pass (on the result of the horizontal pass)
for each pixel:
    sum = 0
    for i in -radius to +radius:
        sum += texture(h_blurred, uv + vec2(0, i * texel_h)) * weight[i]
    output = sum

A radius of 5 means 11 samples per pass × 2 passes = 22 samples. A non-separable 11x11 kernel would need 121 samples. The savings grow quadratically with kernel size.

Downsampling for Wider Bloom

A small blur radius produces a tight halo — useful but not the wide, cinematic glow you see in film. To get a wider bloom without exploding the sample count, downsample the bright image first:

Full res (1920x1080) → threshold
  ↓ downsample (960x540) → blur
    ↓ downsample (480x270) → blur
      ↓ downsample (240x135) → blur

Each downsample step halves the resolution and effectively doubles the blur radius in screen space. The blur at each level stays cheap (small kernel), but the combined result covers a large area.

This multi-scale approach is sometimes called a blur pyramid or mip chain blur.

Step 4: Composite

Add the blurred bloom texture back onto the original HDR image:

final_hdr = hdr_scene + bloom_intensity * blurred_bloom

The bloom_intensity parameter (typically 0.5–1.5) controls how strong the glow is. After compositing, apply tone mapping to bring the HDR values back into displayable [0, 1] range.

Tone Mapping

Bloom happens in HDR space, but displays are LDR (Low Dynamic Range). Tone mapping compresses the wide range of HDR values into [0, 1]. Without it, the bloom addition pushes already-bright pixels past 1.0 and they clip to white.

Reinhard

The simplest tone mapper:

mapped = hdr / (hdr + 1.0)

This maps 0 → 0, 1 → 0.5, infinity → 1.0. It never clips but can look washed out because it compresses mid-tones.

ACES (Academy Color Encoding System)

The film-industry standard. It has a characteristic S-curve that darkens shadows, saturates mid-tones, and rolls off highlights:

mapped = (hdr * (2.51 * hdr + 0.03)) / (hdr * (2.43 * hdr + 0.59) + 0.14)

ACES is widely used in games (Unreal Engine, Unity) because it produces a cinematic, contrasty look out of the box.

Exposure Control

Before tone mapping, multiply the HDR image by an exposure value:

exposed = hdr * exposure
mapped = tone_map(exposed)

This is the digital equivalent of a camera's exposure setting. Automatic exposure (averaging screen luminance and adjusting per frame) simulates the eye adapting to bright and dark environments.

Progressive Upsampling (The Modern Approach)

The naive "downsample → blur → composite" approach sums all mip levels at once. A better technique, popularized by the Call of Duty presentation at SIGGRAPH 2014, uses progressive upsampling:

Downsample chain:
  mip0 → mip1 → mip2 → mip3 → mip4

Upsample chain (accumulating):
  mip4 → upsample + mip3 → upsample + mip2 → upsample + mip1 → upsample + mip0

At each upsample step, the result of the previous level is bilinearly upsampled and added to the current level. This produces a smooth, multi-scale bloom with no visible banding between mip levels.

Each upsample uses a tent filter (3x3 bilinear) rather than a box filter, which further reduces artifacts.

Interactive

Bloom intensity

Bloom adds a glow around bright areas, selling the perception of HDR intensity.

Common Pitfalls

Bloom on everything. If the threshold is too low, the entire image glows. Bloom should be reserved for genuinely bright areas — light sources, specular highlights, emissive materials.

Firefly artifacts. A single extremely bright pixel (from a specular highlight or numerical error) produces a visible bright spot in the bloom. Fix by clamping the maximum brightness before the blur, or by using a weighted average in the downsample that suppresses outliers.

Color shift. Aggressive tone mapping after bloom can shift hues. The sun might go from warm yellow to desaturated white. If this is a problem, apply bloom in a luminance-only mode: extract and blur only the luminance channel, then multiply the original color by the bloom factor.

Performance. Bloom is cheap compared to shadows or global illumination, but the multiple downsample/upsample passes add up. On mobile GPUs, limit the number of mip levels and use half-resolution buffers.

The Full Pipeline

1. Render scene → HDR framebuffer (RGBA16F)
2. Threshold pass → extract bright pixels (soft knee)
3. Downsample chain → mip1 ... mipN (each half resolution)
4. Upsample chain → progressively blend mip levels back up
5. Composite → add bloom to HDR scene
6. Tone map → ACES / Reinhard / custom curve
7. Gamma correct → output to screen

All of this runs as a series of full-screen shader passes. On a modern GPU, the entire bloom pipeline typically takes under 1 ms at 1080p.

What's Next

Bloom makes bright surfaces glow, but in the real world, light doesn't just travel in straight lines from source to surface — it bounces. A red wall illuminates a nearby white ceiling with a pink tint. Sunlight flooding through a window brightens the entire room, not just the floor it hits. Simulating this indirect illumination is the domain of global illumination.