How DirectX Bloom and Downsampling Create Glow Highlights
This article explains how real-time rendering pipelines in DirectX use bloom thresholding and downsampling to produce realistic glow highlights. By isolating luminous areas through a bright-pass filter and progressively downscaling the result through a texture chain, graphics programmers can simulate lens scattering efficiently without overloading the GPU.
The Purpose of Bloom
Standard displays have a limited dynamic range and cannot physically output the intense brightness of the sun, lasers, or glowing neon lights. In the real world, intense light scatters inside the human eye or camera lenses, causing a noticeable halo around bright objects. The bloom post-processing effect mimics this optical phenomenon in game engines by bleeding bright pixels into adjacent darker regions.
Phase 1: Bright-Pass Thresholding
Bloom begins after the main scene is rendered into a High Dynamic
Range (HDR) render target (such as
DXGI_FORMAT_R11G11B10_FLOAT or
DXGI_FORMAT_R16G16B16A16_FLOAT). Because only high-energy
light should bleed, the pipeline must filter out standard-lit
surfaces.
- Luminance Calculation: In a DirectX pixel shader (HLSL), each pixel’s color is converted into relative luminance using standard color weights: \[\text{Luminance} = 0.2126R + 0.7152G + 0.0722B\]
- Applying the Threshold: The shader compares the pixel's luminance against an artist-defined threshold (often values greater than \(1.0\) in HDR).
- Hard vs. Soft Knee: A hard threshold cuts off light sharply, which causes flickering or temporal aliasing when objects move. Most modern DirectX implementations apply a "soft knee" curve, which gradually ramps up brightness past the threshold to create smooth transitions.
- Output Target: Pixels below the threshold are discarded or output as black, producing an isolated black-and-bright texture mask of glowing highlights.
Phase 2: Downsampling and Multi-Scale Blurring
To create an expansive glow, the extracted highlights must be spread over hundreds of pixels. Blurring a full-resolution 4K or 1080p texture directly with a large Gaussian kernel is computationally expensive, requiring hundreds of texture samples per pixel. Downsampling solves this performance bottleneck.
- Mipchain Allocation: DirectX allocates a series of smaller render target textures, each half the width and height of the previous stage (e.g., \(1/2\), \(1/4\), \(1/8\), \(1/16\), and \(1/32\) resolution).
- Hardware Bilinear Filtering: When downsampling between stages, HLSL pixel or compute shaders sample between texels. This relies on the GPU's fixed-function texture hardware to perform 4-tap bilinear filtering automatically, reducing the number of texture reads needed.
- Optimized Kernels: Modern pipelines often use 13-tap downsampling filters (such as the standard Karis downsample filter). These filters sample surrounding pixels in overlapping patterns to eliminate boxy artifacts, temporal shimmering, and energy loss as the image shrinks.
- Natural Diffusion: As the highlight texture is pushed to lower and lower resolutions, the sharp edges of the isolated highlights naturally soften and expand across screen space with virtually zero performance penalty.
Phase 3: Upsampling and Final Composition
After reaching the lowest mip level, the pipeline reverses the process through progressive upsampling:
- Additive Blending: The pipeline steps back up the chain, sampling the smaller, blurry mips and adding them to the higher-resolution mips using a tent filter to smooth the edges.
- Composite Pass: Once the glow reaches the
full-resolution target, it is combined with the original scene color
texture using additive blending
(
FinalColor = SceneColor + BloomColor). - Tonemapping: Finally, the blended HDR image passes through a tonemapper (such as ACES) to map the extreme values back into a displayable LDR range, turning extreme highlights into vivid, glowing flares.