Skip to content

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

License

Notifications You must be signed in to change notification settings

Patoche692/Nexus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nexus Renderer

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

Screenshots

cannelle_et_fromage8 stormtrooper water2 kitchen mustang danish_mood bedroom spider bathroom5 piano3

24spp_MIS_IS_Comparison

Left: multiple importance sampling. Right: naive render (BSDF importance sampling). Image rendered at 24 spp.

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.
  • 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.

Prerequisites

Nexus requires the following:

Build

  • Clone the repository

    git clone --recurse-submodules https://github.com/Patoche692/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

Usage

  • 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

Resources

Here are the main resources I used for this project.

Path tracing in general

Getting started on ray tracing

BVH

  • 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.

PBR materials

Sampling

GPU optimization

I also had a look at other renderer implementations such as Blender's cycles, Tungsten renderer, and Jan van Bergen's CUDA ray tracer.

Dependencies

Models