A GPU-accelerated ray tracer implemented in CUDA C++, featuring an octree acceleration structure for optimized scene traversal.
Based on: Ray Tracing in One Weekend by Roger Allan.
Project work for DD2360 Applied GPU Programming at KTH Stockholm.
- Open the notebook
raytracing.ipynb
in Google Colab - Follow the steps there
- CUDA Toolkit 11.0+
- CMake 3.18+
- C++17 compatible compiler
- GLFW3 and GLEW (only if using OpenGL display)
- CUDA-capable GPU with compute capability 7.5+
$./RayTracing [mode]
- 0: Output image to stdout (default)
- 1: Disable image output
- 2: Render in OpenGL window (if compiled with USE_OPENGL)
- 3: Output image to file (creates output.ppm)
#define USE_OCTREE
: Comment/uncomment for octree acceleration structure (main.cu)NUM_SPHERES
: adjust number of spheres in scene (main.cu)- When changing the number of spheres, one might have to adjust
SPHERES_PER_LEAF
to increase the tree's capacity. This value is limited by memory availability (acceleration_structure.h) #define USE_FP16
: Comment/uncomment for reduced 16bit precicion (precision_types.h)
Use $ cmake -DUSE_OPENGL=OFF
to disable the live preview window. This option is necessary when running in Colab or anywhere else where OpenGL is not supported.
- main.cu: Entry point and rendering logic
- acceleration_structure.h: Octree implementation for spatial partitioning
- precision_types.h: Precision control (FP32/FP16)
- camera.h: Camera model with depth of field support
- hitable.h: Abstract base class for ray-intersectable objects
- material.h: Material definitions (Lambertian, metal, dielectric)
- sphere.h: Sphere primitive implementation
- vec3.h: Vector mathematics
Only the first three files contain changes relevant to this project. The rest remains the same as in the base implementation.
The analysis of the application and its results are stored in the folder analysis
.
- run_experiment.sh: A shell script that executes
ncu
profiling on all executables listed in theexecutables
array. It stores the following profile sections: LaunchStats, SpeedOfLight, MemoryWorkloadAnalysis, ComputeWorkloadAnalysis, Occupancy and stores it in.csv
and.ncu-rep
format. Additionally, the memory usage is collected in.csv
format. It renames the output picture and stores each experiment inside its own subfolder of theexperiments
directory. Each executable/experiment is run five times. - evaluations.ipynb: Takes the data gathered and produces the plots and accompanying data used in the report.
- Christiane Kobalt
- Nicolas Müller
- Maximilian Ranzinger
- Robin Sieber