Interactive physically based GPU path tracer from scratch written in C++ using CUDA and OpenGL.
Left: multiple importance sampling. Right: naive render (BSDF importance sampling). Image rendered at 24 spp.
- 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.
- 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 requires the following:
- Microsoft Visual Studio
- Nvidia's CUDA Toolkit
- CMake 3.22 or higher
-
Clone the repository
git clone --recurse-submodules https://github.com/StokastX/Nexus
-
Launch the setup.bat script. It will generate a Visual Studio solution in the build folder
Alternatively, you can generate the solution via cmake:
mkdir build cd build cmake ..
-
Open the Visual Studio solution. Right click on the Nexus solution and set it as startup project. Press F5 to build the project
- Go to file -> open to load a new scene. The model loading is not multithreaded and the BVH construction might take some time depending on the model size
- Controls: hold right click and use WASD keys to move and the mouse to change the camera orientation
- You can change the meshes and camera properties in the UI
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.