This is the final project submission for the CS201 (Data Structure) Course.
This project aims to improve the efficiency of ray intersection tests in ray tracing by building upon a bounding volume hierarchy (BVH) structure for storing the scene primitives. Further Surface Area Heuristics (SAH) is used for efficient building of the BVH. The raytracer is just using CPU as of now. A naive implementation of microfacet model is used for material properties. Only diffuse materials are added for now with predefined values. Other material properties are not included for simplicity.
- SDL2: Cross platform header only Multimedia library for rendering the calculated frames and event handling features like user input
- Gnuplot: Graph plotting library in c
- Homebrew: Package manager for macOS, used to install dependencies.
- SDL2 and Gnuplot: SDL2 for rendering, and Gnuplot for benchmarking plots.
- Gnuplot: Required for benchmark data plot.
- SDL2: SDL2 headers and DLLs are included in the project, so no additional setup is required.
- Install Homebrew if you haven’t already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install SDL2 and Gnuplot via Homebrew:
brew install sdl2 sdl2_image gnuplot
- Clone the Repository:
git clone https://github.com/ShivangNagta/CS201_SAH-BVH_Ray_Tracer.git
cd CS201_SAH-BVH_Ray_Tracer
- Build the project (make should be pre-installed with Xcode, if not do install it first)
make
- Run the Raytracer
./raytracer
-
Install Gnuplot:
Download the Gnuplot installer from SourceForge and ensure that the option to add Gnuplot to your system path is selected during installation. -
Install MinGW: Install MinGW from the MinGW website if not installed. During installation, select
mingw32-make
and add it to your system path. -
Clone the Repository:
git clone https://github.com/ShivangNagta/CS201_SAH-BVH_Ray_Tracer.git
cd CS201_SAH-BVH_Ray_Tracer
-
Build the project
make
-
Run the Raytracer
.\raytracer
Upon launching, the program will display options to choose the desired mode:
Press '1' for benchmark testing with graph plot.
Press '2' for real-time CPU ray tracing.
Option 1: Benchmark Testing with Graph Plot
- Type 1 and press Enter: The program will run a benchmark test to measure the intersection performance of rays with randomly generated spheres, both with and without a bounding volume hierarchy (BVH). Results are plotted using gnuplot, saved as benchmark_results.png, and displayed in an SDL window. To close the plot, press the ESC key or click the close button on the SDL window. The instructions for testing are set in benchmark.c file.
Option 2: Real-Time Ray Tracing
- Type 2 and press Enter: A real-time ray tracing window will open, allowing you to explore the scene with keyboard and mouse inputs. Controls:
Key | Action |
---|---|
W | Move camera forward |
S | Move camera backward |
A | Move camera left |
D | Move camera right |
Space | Move camera up |
Left Shift | Move camera down |
B | Toggle BVH on/off |
O | Toggle BVH visualization |
Mouse (hold left-click) | Rotate the camera view by moving the mouse |
ESC | Close the application window. |