The project implements a discrete C++ raytracer from scratch, using only PNG library for saving the image.
You can build two source files in order to explore the functionality. The following script builds the executables on Linux:
sudo apt-get install libpng-dev cmake
cd </path/to/raytracer>
mkdir build
cd build
cmake ..
makeOne can render all examples stored in the objects folder:
./raytracerOne can use the raytracer with custom options and .obj files. Check the API:
./raytracer_customThe executable will read provided .obj file and render the image using specified options. For example,
you can render a deer in depth mode (see modes in section
./raytracer_custom --obj objects/deer/CERF_Free.obj --out objects/deer/deer_normal.png --mode normal --width 500 --height 500 --from 100 200 150 --to 0 100 0 --depth 1A scene with many reflections from mirrors (depth of
./raytracer_custom --obj ../objects/mirrors/scene.obj --out ../objects/mirrors/mirrors_custom.png --mode full --width 800 --height 600 --from 2.0 1.5 -0.1 --to 1.0 1.2 -2.8 --depth 14The raytracer consists of three major parts.
Phong Model is used for light modelling. The geometry is built using std::array - vectors of size
The parser for .obj and corresponding .mtl files. All polygons are automatically cut into triangles.
The recursive ray tracing procedure. Closest objects are found in linear manner, with potential improvement to implement BVH trees.
The raytracer supports three rendering options:
-
$\textbf{Full}$ . The mode implements standard recursive ray tracing. -
$\textbf{Depth}$ . This mode is used only with depth of$1$ . The farther the scene is from the lookup point, the darker the corresponding pixel is. -
$\textbf{Normal}$ . This mode is used only with depth of$1$ . If a ray going through pixel intersects with the scene, it gets an RGB value corresponding to normalized direction vector of normal to the surface at intersection point.

