Interactive physically based GPU path tracer from scratch written in C++ using CUDA and OpenGL.
- 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.
Nexus is a CMake-based project and requires the following dependencies:
- CUDA Toolkit (from NVIDIA)
- CMake version 3.22 or higher
The project has been tested on both Windows (with Visual Studio) and Ubuntu.
-
Clone the repository with submodules:
git clone --recurse-submodules https://github.com/StokastX/Nexus
-
Generate the solution via cmake:
mkdir build cd build cmake .. -
Build the project:
-
On Linux: Use
makeon 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.
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.
- 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.
- The Cherno’s YouTube Series — Great for beginners to understand the basics of ray tracing step by step.
- Ray Tracing in One Weekend Series — A classic starting point for building a ray tracer in C++.
- Scratchapixel — Excellent explanations of computer graphics fundamentals with code examples.
- Accelerated Ray Tracing in One Weekend in CUDA — A hands-on introduction to GPU-based ray tracing.
- 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.
- Crash Course in BRDF Implementation — A clear overview of diffuse and microfacet BRDFs, both theory and implementation.
- Walter et al. 2007 — Basis for my implementation of rough dielectric BSDFs.
- Weidlich & Wilkie 2007 — Explores layered BSDFs (planned for future use in my rough plastic BSDF).
- TU Wien Computer Graphics Lectures — Great explanation of next event estimation and multiple importance sampling.
- 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.
I also studied existing production and hobby renderers for reference and inspiration:
This project relies on the following libraries and frameworks:
- GLFW and GLEW — Window and OpenGL context management.
- CUDA 12.4 — For GPU acceleration.
- CUDA Helper Math — Common operations for CUDA vector types.
- Assimp — Model import and loading.
- Dear ImGui — User interface.
- stb — Image import/export utilities.
- tinyfiledialogs — Simple cross-platform file dialogs.
- LuxCore example scenes
- Blender demo scenes
- Camera from LuisaRender
- Stormtrooper by ScottGraham
- Ford mustang by Pooya_dh
- Bedroom by SlykDrako
- Bathroom by nacimus








