Showcase » Raytracer

This is an implementation of an accelerated raytracer using a kd-tree with a SAH loosely based on [1]. This was a project for an advanced computer graphics course during my master’s studies, implemented in C++ using GLM, SDL2 and Assimp.

Cornell box

A simple scene based on the Cornell box. It contains 9 primitives and has 49 point lights in an area to provide smooth shadows and is rendered using a resolution of 1024 by 1024.

Image showing a raytraced Cornell box containing three spheres with different materials
Raytraced image of the Cornell box

As the number of primitives is very low the usage of a kd-tree did not have any impact on the number of computed intersections. However, the runtime is greatly affected, with the additional overhead of the kd-tree search adding extensive computational effort.

476.97 million intersections 476.03 million intersections 0 100 200 300 400 500 million intersections with kd-tree without kd-tree Number of intersections
0.13 ± 0.008 s 0.14 ± 0.01 s 31.8 ± 0.4 s 8.88 ± 0.051 s 0 5 10 15 20 25 30 s with kd-tree without kd-tree Runtime (init, render)

House

This is a more complicated scene with 12211 primitives representing a house and 4 spread out lights. The house was modelled in Blender, exported as a binary GLTF file and rendered at a resolution of 2048 by 2048.

Image showing a raytraced house model
Raytraced image of a house model

Compared to before, this scenario is reversed. As can be seen, the number of intersections and runtime improvements profit substantially from the kd-tree optimization. While the construction of the kd-tree adds about 0.6 seconds to the initialization time, the impact on the overall runtime is inconsiderable.

2.993 billion intersections 167.82 billion intersections 0 20 40 60 80 100 120 140 160 billion intersections with kd-tree without kd-tree Number of intersections
0.013 ± 0.001 min 0.003 ± 0.0 min 0.965 ± 0.003 min 39.953 ± 0.073 min 0 5 10 15 20 25 30 35 40 min with kd-tree without kd-tree Runtime (init, render)

References