Skip to content

Latest commit

 

History

709 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Royal Tracer DX

License Platform API Language

Real time path tracer in DirectX 12 with SHARC radiance caching, path guiding, optimized ReSTIR spatial reuse, a four lobe layered BXDF, light tree importance sampling with learned light cuts, and NVIDIA DLSS for upscaling and denoising.

Studio interior

Table of Contents

Features

Rendering Pipeline

SHARC trains and resolves the cache. Path tracing uses learned light cuts, path guiding, and cached radiance. ReSTIR spatial reuse combines samples through texture-defined pixel pairs.

The path tracer uses the DXR HitObject API with Shader Execution Reordering (SER). The regular pipeline consists of three main stages:

  1. SHARC: Sparse update paths, radiance cache resolve, and path guiding updates.
  2. Path tracing: Multi-bounce tracing with light tree NEE, learned light cuts, guided BSDF sampling, and SHARC queries.
  3. ReSTIR spatial reuse: Texture-based partner selection, reconnection and visibility evaluation, followed by pairwise MIS merging.

SHARC training and rendering share the light sampler and material model. Training also updates the directional guide. Spatial reuse operates on the resulting render samples within the current frame.

Light Trees and Learned Light Cuts

A light tree over the scene's emissive triangles provides importance sampling for scenes with many lights. The tree uses a TLAS/BLAS hierarchy with geometric importance weights based on emitted power, distance, and orientation.

Learned light cuts adapt emitter selection using visibility-weighted contribution feedback. Spatial cells store cuts of up to 32 clusters, with online splitting and merging. Cells are separated by surface orientation and retain history during camera movement. The learned sampler is used in both path tracing and SHARC training.

SHARC

Interior rendered with SHARC

SHARC example: interior illumination.

Spatially Hashed Radiance Caching with a sparse world-space hash grid, distance-adaptive cell spacing, and temporal accumulation. A rotating subset of pixels supplies cache updates. Entries store material-demodulated radiance and statistical confidence.

Cache queries replace eligible diffuse and rough reflection contributions at secondary surfaces. Surface identity, normal and plane compatibility, confidence, and path footprint control acceptance. Direct lighting at primary surfaces remains traced, and rejected queries continue normally. Cache termination introduces spatial and temporal approximation error.

Path Guiding

Path guiding off Path guiding on
Path guiding disabled Path guiding enabled

Path guiding uses up to eight directional lobes per spatial cell, fitted from SHARC training paths. Lobes store direction, angular extent, weight, and a distance estimate for parallax correction. Stale lobes decay, with fallback to coarser cells when local support is unavailable.

Guided directions are mixed with diffuse and rough reflection BSDF sampling. The matching mixture PDF is used for path weighting and MIS.

ReSTIR Spatial Reuse

ReSTIR spatial resampling for diffuse and rough reflection contributions using 32-byte reservoirs. Three precomputed, self-inverting reuse textures provide reciprocal pixel partners, following ReSTIR PT Enhanced.

Separate shift and merge passes cache reconnected contributions and visibility for pairwise MIS. Reciprocal pairing makes both pixels' evaluations available to the merge. Repeated samples reuse visibility results, and full neighbor payloads are loaded only on reservoir selection. Material and geometric checks reject incompatible pairs. The regular pipeline uses spatial reuse only.

The ReSTIR PT hybrid shift mode is deprecated.

Technology Comparison

Cumulative comparison: base path tracing, learned light cuts, SHARC, then path guiding and ReSTIR spatial reuse.

1 · Base path tracing 2 · + Learned light cuts
Base path tracing Base path tracing with learned light cuts
3 · + SHARC 4 · + Path guiding and ReSTIR
Learned light cuts with SHARC Learned light cuts, SHARC, path guiding, and ReSTIR spatial reuse

Material Model

Dragon material Sheen material Metal material Clearcoat material Dragon with subsurface scattering
Transmission Sheen Metal Clearcoat SSS

Material examples, including subsurface scattering (SSS).

Layered scattering: sheen, clearcoat, GGX reflection and transmission, then diffuse. Emission is separate.

A four lobe BXDF with layered evaluation:

  • Sheen: Charlie NDF for fabric-like surfaces.
  • Clearcoat: Dielectric GGX with independent roughness and Fresnel.
  • GGX Specular/Transmission: Anisotropic microfacet model with VNDF importance sampling. Nested dielectrics use per-bounce IOR stack tracking.
  • Lambertian Diffuse: Cosine-weighted base layer.

Subsurface scattering uses volumetric random walks. Emission is evaluated separately from the scattering lobes.

Model Loading

Supports OBJ and glTF/GLB via tinyobjloader and tinygltf. Textures use stb_image with DDS decompression through DirectXTex. Models, materials, and per-instance transforms share a unified scene representation.

Opacity Micromaps

Alpha-tested geometry uses Opacity Micromaps, built with the NVIDIA OMM SDK. Opacity is encoded per microtriangle in the BVH, allowing hardware traversal to skip transparent regions without any-hit shader invocations.

Denoiser

NVIDIA DLSS Ray Reconstruction provides denoising and upscaling through Streamline.

Minecraft Chunk Rendering

Minecraft worlds are supported with chunk streaming, adaptive LOD, and asynchronous geometry builds. Emissive block geometry is sampled through the light tree.

Example statistics from a recorded Greenfield v0.5.4 run:

Metric Count
Rendered triangles 86.13 million
Emissive triangles in the active light tree 1.29 million
World chunks 295,936 across 356 regions
Materials 10,451
Textures 5,253

Geometry and light counts vary with camera position and LOD.

Minecraft city rendered from chunks

Background

What started as a port of the RoyalTracer university project to DirectX became a standalone rendering engine. In my Bachelor's Thesis, I implemented and optimized ReSTIR to improve real time rendering. Current work focuses on learned sampling, radiance caching, and spatial reuse.

Build

Requires Windows 11, an NVIDIA RTX 40 series GPU or newer, Visual Studio 2022 with C++ build tools and Windows SDK 10.0.22621.0, and CMake 3.25.2 or newer.

Run from the repository root:

cmake -S Pathtracer -B Pathtracer/build -G "Visual Studio 17 2022" -A x64
cmake --build Pathtracer/build --config Release

Controls

Input Action
W / A / S / D Move
Space / Left Ctrl Ascend / descend
Left mouse drag Look around

Acknowledgments

Gallery

Bistro exterior

Bistro.

Sponza interior

Sponza.

Harbor panorama Harbor at night
Harbor Harbor at night
Ship in the harbor City skyline
Ship Skyline

Island scene

Island.

About

A state-of-the-art DirectX12 based pathtracer

Topics

Resources

Stars

76 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages