Skip to content
StokastXPublic

About

An interactive GPU path tracer from scratch written in C++ using CUDA and OpenGL

Topics

Resources

Stars

26 stars

Watchers

3 watching

Forks

Latest commit

 

History

544 Commits

Folders and files

Repository files navigation

Nexus Renderer

Interactive physically based GPU path tracer from scratch written in C++ using CUDA and OpenGL.

Screenshots

cannelle_et_fromage camera6 glass_of_water stormtrooper kitchen ford_mustang bedroom spider bathroom

Features

  • Interactive camera with thin lens approximation: FOV, defocus blur.
  • Wavefront path tracing, see Laine et al. 2013. The path tracing algorithm is divided into specialized CUDA kernels accessing global work queues to get more coherent workloads and to reduce the amount of inactive threads. Kernel launches are optimized using CUDA graphs.
  • Persistent threads with dynamic ray fetching, see Aila and Laine 2009. The trace kernel is launched with just enough threads to fill the device. During traversal, inactive threads will fetch new rays in the global trace queue to avoid wasting resources.
  • BVH:
    • Standard SAH-based BVH (BVH2) using binned building
    • Compressed-wide BVH (BVH8), see Ylitie et al. 2017. BVH2 is collapsed into an 8-ary BVH. Nodes are compressed to 80 bytes encoding the child nodes' bounding boxes to limit memory bandwidth on the GPU.
    • GPU builder: implements the H-PLOC algorithm proposed by Benthin et al. 2024, a high-performance GPU-oriented BVH construction method. H-PLOC builds high-quality BVHs through hierarchical clustering of spatially nearby primitives. The full algorithm is implemented in my NexusBVH library.
  • The BVH is split into two parts: a top level structure (TLAS) and a bottom level structure (BLAS). This allows for multiple instances of the same mesh as well as dynamic scenes using object transforms.
  • Model loader: obj, ply, fbx, gltf with Assimp
  • The material system is based on the OpenPBR model and supports both dielectric and metallic bases. Both bases use the GGX microfacet distribution, see Walter et al. 2007.
    • Dielectric base:

      • Glossy-diffuse BRDF (non-physical mix between diffuse and specular).
      • Translucent BSDF (no volumetric scattering).
    • Metallic base: Rough conductor BSDF with the F82-tint model of Kutz et al. 2021.

  • Importance sampling: cosine weighted for diffuse BSDFs, VNDF sampling for microfacet BSDFs (see Heitz 2014 and Dupuy and Benyoub 2023).
  • Multiple importance sampling, see Veach 1997. BSDF sampling is combined with next event estimation (direct light sampling) and the results from both sampling strategies are weighted using the power heuristic to get low-variance results.
  • Texture mapping (albedo, emissive, normal, metallic, roughness).
  • HDR environment maps.

Prerequisites

Nexus is a CMake-based project and requires the following dependencies:

The project has been tested on both Windows (with Visual Studio) and Ubuntu.

Build

  1. Clone the repository with submodules:

    git clone --recurse-submodules https://github.com/StokastX/Nexus
  2. Generate the solution via cmake:

    mkdir build
    cd build
    cmake ..
  3. Build the project:

  • On Linux: Use make on your preferred build system:

    make -j
  • On Windows (Visual Studio): Open the generated solution file in Visual Studio. Right-click on the Nexus target, set it as the startup project, and press F5 to build and run.

Resources

These are the main references I relied on while building this project. They range from theoretical foundations to practical guides, and I highly recommend them if you’re interested in ray tracing and physically based rendering.

Path Tracing (General)

  • Eric Veach’s PhD Thesis — The definitive resource on the theory of Monte Carlo path tracing. Although quite theoretical and code-agnostic, it helped me a lot to implement importance sampling, next event estimation, and multiple importance sampling.
  • Physically Based Rendering: From Theory to Implementation — This is the go-to reference for implementing a complete path tracer from the ground up.
  • Ray Tracing Gems II — A collection of modern techniques for real-time ray tracing using DXR, Vulkan, and OptiX.

Getting Started with Ray Tracing

BVH (Bounding Volume Hierarchies)

  • Jacco Bikker’s BVH Guides — A practical introduction to SAH-based BVHs, which helped me implement my first GPU BVH builder and traversal (surprisingly fast!).
  • Stich et al. 2009 — Detailed explanation of binned building and spatial splits for BVH2.
  • Ylitie et al. 2017 — Reference for compressed wide BVHs, useful for GPU acceleration.

Physically Based Materials

Sampling

GPU Optimization

  • Aila & Laine 2009 — Key insights into GPU architecture, traversal efficiency, and persistent threads.
  • Laine et al. 2013 — About wavefront path tracing and why megakernels can be problematic.

Renderer Implementations

I also studied existing production and hobby renderers for reference and inspiration:

Dependencies

This project relies on the following libraries and frameworks:

Models

About

An interactive GPU path tracer from scratch written in C++ using CUDA and OpenGL

Topics

Resources

Stars

26 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages