This project implements a ray tracing assignment with an extensible acceleration layer:
- Loads geometry from Wavefront OBJ (
v,vt,f) and MTL (Kd,Ks,Ns,d/Tr,map_Kd) - Supports texture sampling with generated mip levels and trilinear filtering
- Supports two acceleration backends:
- Embree backend
- Custom backend (currently baseline traversal, prepared for KD-tree evolution)
- Includes OpenGL scene viewer with fly camera controls
- Uses GLM for camera/vector math
- Writes output as JPG via
stb_image_write
On Arch Linux:
sudo pacman -S embree glm stb cmake
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -jOn Ubuntu/Debian-like systems:
sudo apt install libembree-dev libglm-dev libstb-dev cmake
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -jThis creates executable build/raytracer (compile-time Embree backend).
Raytracing loops are parallelized with OpenMP. You can control thread count with:
OMP_NUM_THREADS=8 ./build/raytracer ...To build both backend-specific binaries:
cmake --build build --target backends -jThis creates:
build/raytracer-embreebuild/raytracer-kdtree
Build OpenGL viewer target:
cmake --build build --target raytracer-viewer -jThis creates:
build/raytracer-viewer
Build interactive raytraced viewer target:
cmake --build build --target raytracer-rtviewer -jThis creates:
build/raytracer-rtviewer
The interactive raytraced viewer also uses OpenMP for per-frame pixel traversal.
Run automated Embree vs KD benchmark cases:
cmake --build build --target benchmark -jThis generates:
- renders in
renders/bench/ - CSV metrics in
report/benchmark_results.csv
CSV columns:
- scene path
- backend
- resolution
- build/trace times
- total/shadow ray counts
- rays/s metrics
./build/raytracer <input.obj> <output.jpg> [options]
./build/raytracer <input.obj> -o <output.jpg> [options]Assignment-style options:
-vp <x y z>camera position-vd <x y z>camera viewing direction-up <x y z>camera up vector-fovy <deg>vertical field of view in degrees-ltcol <r g b>current light color-ltpos <x y z>add point light (uses last-ltcol)-r <n>recursion depth (0primary only,1adds shadow rays,>=2adds reflections)-normals <default|invert|auto>normal orientation mode (autotries to detect inward-facing winding)-res <width height>output resolution-o <path>output image path-accel embree|kdtreeruntime backend switch (only in non-forced builds)
Legacy aliases (still available):
--width,--height,--fov,--eye,--target,--up,--lightdir,--background
The eye/target/up/fov parameters map directly to an OpenGL-style camera setup.
./build/raytracer scenes/single_triangle.obj -o out_triangle.jpg \
-vp 0.0 1.0 3.0 -vd 0.0 -0.2 -1.0 -up 0 1 0 \
-fovy 55 -ltcol 1 1 1 -ltpos 4 6 2 -r 2 -res 1280 720./build/raytracer scenes/pyramid_room.obj out_room.jpg \
-vp 2.8 1.7 3.2 -vd -2.8 -0.9 -3.2 -up 0 1 0 \
-fovy 52 -ltcol 1 1 1 -ltpos 5 7 2 -r 2 -res 1600 900Generate all bundled scene renders:
cmake --build build --target render-all -jGenerate a single scene render:
cmake --build build --target render-single-triangle -jcmake --build build --target render-pyramid-room -jOutputs are written to renders/.
The program prints required stats at the end:
- acceleration structure build time
- ray tracing time
- total computed rays
- number of shadow rays
- throughput in rays/second (with and without build time)
To download additional internet scenes for experiments:
cmake --build build --target fetch-scenesDownloaded files are placed in scenes/external/.
Track attribution and license notes in scenes/external/SOURCES.md before submission.
Run:
./build/raytracer-viewer scenes/pyramid_room.objControls:
W/S: forward/backwardA/D: strafe left/rightQ/E: down/upShift: speed boost- hold right mouse button and move mouse: look around
P: print camera as-vp/-vd/-uparguments for offline raytracingEsc: quit
Run:
./build/raytracer-rtviewer scenes/external/spider.obj \
-vp -19.01 23.4072 109.266 -vd 0.0207327 -0.29089 -0.956532 -up 0 1 0 \
-res 640 360 -r 1 -normals autoControls:
W/S: forward/backwardA/D: strafe left/rightQ/E: down/upShift: speed boost- hold right mouse button and move mouse: look around
P: print camera as-vp/-vd/-upargumentsEsc: quit
src/main.cppthin executable entrypointsrc/raytracer_app.cpprender orchestration and tracing loopsrc/raytracer_app.hpppublic entrypoint declaration for raytracer modulesrc/raytracer_types.hppshared domain types (scene/material/ray/camera/stats)src/raytracer_io.hpp/src/raytracer_io.cppCLI and OBJ/MTL loadingsrc/raytracer_accel.hpp/src/raytracer_accel.cppacceleration backends (Embree + custom KD-tree)src/raytracer_texture.cpptexture loading and mipmap generationsrc/viewer.cppOpenGL viewer applicationscenes/*.objexample scenesCMakeLists.txtbuild configuration