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, glb, gltf, 3ds, blend with Assimp
- Materials:
- Diffuse BSDF (Lambertian)
- Rough dielectric BSDF (Beckmann microfacet model, see Walter et al. 2007).
- Rough plastic BSDF (mix between diffuse and rough specular).
- Rough conductor BSDF.
- Importance sampling: cosine weighted for diffuse materials, VNDF sampling for rough materials.
- Multiple importance sampling, see Veach 1997. BSDF importance 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 (diffuse, emissive).
- 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
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.
Here are the main resources I used for this project.
- Eric Veach's thesis. The best resource to understand all the theory behind Monte Carlo path tracing. It is code agnostic and fairly theorical but it helped me a lot to implement importance sampling, next event estimation and multiple importance sampling.
- Physically based rendering book, the reference book for path tracing detailing a complete path tracer implementation.
- Ray Tracing Gems II: Next Generation Real-Time Rendering with DXR, Vulkan, and OptiX
- The Cherno's Ray tracing series
- Ray Tracing in one weekend book series
- ScratchPixel website
- To get started with CUDA ray tracing: Accelerated Ray Tracing in one weekend in CUDA
- Jacco Bikker's guides on SAH-based BVHs really helped me implement my first BVH and traversal on the GPU which was surprisingly fast.
- Stich et al. 2009 explain in details binned building and spatial splits for BVH2.
- Ylitie et al. 2017 for compressed wide BVHs.
- Crash Course in BRDF Implementation detailing the theory and implementation for diffuse and microfacet models.
- Walter et al. 2007. I used this paper to implement my rough dielectric BSDF.
- Weidlich and Wilkie 2007 for layered BSDFs (not yet implemented in my path tracer, but I will use it for my rough plastic BSDF).
- Computer Graphics at TU Wien videos for next event estimation and multiple importance sampling.
- Aila and Laine 2009 to understand GPU architecture, traversal optimization and persistent threads.
- Laine et al. 2013 for wavefront path tracing.
I also had a look at other renderer implementations such as Blender's cycles, Tungsten renderer, and Jan van Bergen's CUDA ray tracer.
- GLFW and GLEW
- CUDA 12.4
- CUDA math helper for common operations on CUDA vector types
- Assimp for model loading
- ImGui for user interface
- stb for importing and exporting images
- tinyfiledialogs
- LuxCore example scenes
- Blender demo scenes
- Camera from LuisaRender
- Stormtrooper by ScottGraham
- Ford mustang by Pooya_dh
- Bedroom by SlykDrako
- Bathroom by nacimus
- Piano by Roy