How DXR Integrates Ray Tracing with Rasterization

DirectX Raytracing (DXR) brings real-time ray traversal to modern graphics by augmenting, rather than replacing, the traditional rasterization pipeline through a hybrid rendering architecture. In this approach, rasterization handles fast primary visibility, while DXR dispatches rays to calculate physically accurate lighting effects such as reflections, ambient occlusion, global illumination, and shadows. By standardizing acceleration structures and introducing specialized ray tracing shaders alongside inline ray queries, DXR allows developers to interleave rasterized geometry passes with hardware-accelerated ray traversal within a single frame.

The Hybrid Rendering Model

Modern real-time engines use rasterization for what it does best: projecting millions of polygons to screen-space in a fraction of a millisecond. In a standard DXR hybrid pipeline, the graphics hardware executes a traditional geometry pass to generate a G-buffer (containing depth, normals, albedo, and material properties) via rasterization.

Once primary surface visibility is established, the application transitions to DXR. Instead of tracing expensive primary camera rays through the scene to find visible pixels, the pipeline reads the rasterized G-buffer data to spawn secondary rays directly from visible surfaces, drastically reducing the total number of ray traversals required.

Bounding Volume Hierarchy (BVH)

To make hardware traversal possible, DXR relies on a two-level Bounding Volume Hierarchy (BVH) built and updated on the GPU:

  • Bottom-Level Acceleration Structure (BLAS): Holds the raw vertex and index data for individual meshes in object space.
  • Top-Level Acceleration Structure (TLAS): Contains instances of BLAS objects with corresponding world-space transformation matrices, instance masks, and material flags.

During runtime, the rasterizer renders instances directly from standard vertex buffers, while the ray tracing hardware references the TLAS and BLAS to test ray-box and ray-triangle intersections.

DispatchRays and the Ray Tracing Pipeline

DXR introduces a dedicated state object—the Ray Tracing Pipeline State Object (RTPSO)—executed via the DispatchRays() API call. This initiates a compute-like workload that navigates ray traversal using five specialized shader stages:

  1. Ray Generation Shader: Reads from the rasterized buffers (e.g., G-buffer or depth buffer) and invokes TraceRay() with an origin, direction, and ray payload.
  2. Intersection Shader: Defines custom intersection algorithms for non-triangular primitives.
  3. Any-Hit Shader: Executes on potential intersections, commonly used for alpha-testing or transparency without terminating the ray search.
  4. Closest-Hit Shader: Executes once the hardware traversal finds the nearest valid intersection, performing lighting calculations and potentially shooting secondary bounce rays.
  5. Miss Shader: Executes when a ray fails to hit geometry within a specified maximum distance, typically sampling skyboxes or environment maps.

Inline Ray Tracing (Ray Queries)

In addition to full pipeline dispatches, DXR 1.1 introduced Inline Ray Tracing via RayQuery objects. This mechanism integrates ray traversal directly into existing shader stages—such as Compute, Pixel, or Vertex shaders—without the overhead of context switches or the RTPSO.

A standard pixel shader can rasterize a triangle, access local registers, and immediately initiate an inline ray query to determine whether that specific pixel is occluded from a light source. This eliminates the need for separate ray tracing state dispatches for lightweight tasks like directional hard shadows or ambient occlusion.

Compositing and Post-Processing

The output of DXR passes typically populates intermediate render targets containing noisy, raw lighting data. Because real-time budgets limit ray counts to one or two rays per pixel, these textures are routed through spatial and temporal denoising filters implemented via compute shaders. Once filtered, the ray-traced lighting components are blended into the final color buffer alongside rasterized effects, tone-mapped, and presented to the display.