How DirectX Handles Render Target Blending

DirectX manages blending operations between source and destination render targets through its Output Merger (OM) stage using configurable blend state descriptions. This article explains how the API processes pixel shader outputs alongside existing render target data, covering the mathematical blending equation, channel separation, state configuration, and support for Multiple Render Targets (MRT).

The Output Merger Stage

In the DirectX rendering pipeline (Direct3D 11 and Direct3D 12), blending occurs at the Output Merger stage. The Output Merger receives two primary color inputs:

  • Source (RGB/A): The raw color output evaluated and emitted by the pixel shader.
  • Destination (RGB/A): The color value currently stored in the memory buffer of the bound render target at the corresponding pixel coordinate.

When blending is disabled, the source pixel directly overwrites the destination pixel, subject to depth and stencil testing. When blending is enabled, DirectX executes a mathematical formula to combine the two colors before writing the result to the destination buffer.

The Blending Formula

DirectX calculates the final pixel color using an algebraic formula split into two distinct, parallel evaluations: one for RGB color channels and one for the Alpha channel.

The standard blending equation is defined as:

FinalColor = (SourceColor * SourceBlendFactor) BlendOp (DestinationColor * DestinationBlendFactor)

FinalAlpha = (SourceAlpha * SourceBlendFactorAlpha) BlendOpAlpha (DestinationAlpha * DestinationBlendFactorAlpha)

  • Blend Factors (D3D12_BLEND or D3D11_BLEND): Multipliers applied to the input colors. Common options include ZERO, ONE, SRC_ALPHA, INV_SRC_ALPHA, DEST_COLOR, and BLEND_FACTOR (a constant color set programmatically).
  • Blend Operations (D3D12_BLEND_OP or D3D11_BLEND_OP): The arithmetic operator that merges the scaled inputs. Supported operations include:
    • ADD: Adds source and destination terms (Result = Source + Destination).
    • SUBTRACT: Subtracts the destination term from the source term (Result = Source - Destination).
    • REV_SUBTRACT: Subtracts the source term from the destination term (Result = Destination - Source).
    • MIN / MAX: Ignores blend factors entirely and takes the minimum or maximum value between the source and destination.

Configuration via Blend State

Developers configure blending behavior using blend state descriptors (D3D11_BLEND_DESC or D3D12_BLEND_DESC). In modern DirectX, this descriptor is compiled directly into a Pipeline State Object (PSO) for low-overhead execution on the GPU.

Key elements configured per render target include:

  • BlendEnable: A boolean toggle that activates or deactivates the blend math.
  • SrcBlend / DestBlend: The factors for the RGB components.
  • SrcBlendAlpha / DestBlendAlpha: The factors for the Alpha component.
  • BlendOp / BlendOpAlpha: The arithmetic operations applied.
  • RenderTargetWriteMask: A bitmask (such as D3D12_COLOR_WRITE_ENABLE_ALL) that selectively allows or blocks updates to the individual R, G, B, and A channels in the target texture.

Multiple Render Targets and Advanced Features

DirectX supports up to eight simultaneous render targets. Using the IndependentBlendEnable flag, developers can either apply a uniform blend setting across all bound render targets or provide a unique blend configuration for each individual target slot.

Additionally, DirectX supports Dual-Source Color Blending. By returning two distinct color values from a single pixel shader (SV_Target0 and SV_Target1), the blending hardware can use the secondary color output as an additional blend factor (SRC1_COLOR or SRC1_ALPHA), enabling advanced rendering techniques such as subpixel font antialiasing or order-independent transparency.