Output Merger Stage

The output merger stage is responsible for combining the results of the rasterization stage with the contents of the render targets and depth-stencil buffer. It performs operations such as depth testing, stencil testing, blending, and writing pixel data to the output buffers.

Overview

The output merger (OM) stage is the final programmable stage in the DirectX graphics pipeline before the pixel data is written to the back buffer. It controls how pixel shaders output their results and how these results are combined with existing frame buffer contents.

Key functions of the output merger stage include:

Input and Output

The output merger stage receives:

The output merger stage writes to:

Core Operations

Depth Testing (Z-Buffering)

Depth testing is a fundamental operation that ensures objects closer to the camera occlude objects farther away. The depth value of a new pixel is compared to the depth value already stored in the depth buffer. If the new pixel is farther away than the existing pixel, it is discarded.

This can be configured using various comparison functions (e.g., D3D11_COMPARISON_LESS_EQUAL).

Stencil Testing

Stencil testing provides a more complex way to control pixel writes. It uses a separate stencil buffer, where each pixel stores a stencil value. This value can be used to mask drawing operations, create effects like shadows, or implement reflection techniques.

Operations include:

Blending

Blending allows for the combination of a new pixel's color with the existing color in a render target. This is crucial for effects like transparency (alpha blending), fog, and anti-aliasing.

Blending involves:

Example: Alpha Blending

ResultColor = SourceColor * SourceAlpha + DestinationColor * (1 - SourceAlpha)

Render Target and Depth-Stencil State

The behavior of the output merger stage is controlled by the blend state, depth-stencil state, and rasterizer state objects. These objects are created and bound to the GPU by the application.

Key Structures and Enums

The output merger stage is heavily configured through specific DirectX structures and enumerations:

Structure/Enum Description
D3D11_BLEND_DESC Describes the blend state for the output merger stage.
D3D11_DEPTH_STENCIL_DESC Describes the depth-stencil state, including depth and stencil test parameters.
D3D11_RASTERIZER_DESC While primarily a rasterizer state, it affects how primitives are processed before reaching the output merger (e.g., culling).
D3D11_RENDER_TARGET_BLEND_DESC Configuration for blending a single render target.
D3D11_DEPTH_STENCIL_VIEW_DESC Describes how a depth-stencil buffer is accessed.
D3D11_UNORDERED_ACCESS_VIEW_DESC Describes how an unordered access view (which can be used for writing by OM) is accessed.
D3D11_VIEWPORT Defines the viewport, which clips geometry to a screen region and influences rasterization.

Programmable Stages vs. Fixed-Function

While the output merger has many fixed-function aspects (like depth-testing logic), it also interacts closely with the pixel shader. The pixel shader generates the data (color, depth) that the output merger then processes and writes.

Related Topics