This is a raytracer written in C++ following the Ray tracing in one weekend book. The purpose of thie project is to generate realistic images by simulating shadows, reflection, refraction and many other natural phenomenon. I also wanted to use linear algebra, so I worked on this personal project.
https://github.com/ananthvk/cpp-raytracer
- Shadows, diffuse materials
- Reflections, metals, refractions and glass
- Simple geometric shapes such as spheres
- Anti-aliasing
- Multithreading
- A C++ 11 compiler, (GCC, MSVC, etc)
- CMake >= 3.10
- Git (optional)
You can install the packages on linux using your preferred package manager. For example on ubuntu,
sudo apt update
sudo apt install build-essential cmake
On windows, install mingw and cmake.
Get the sources
git clone https://github.com/ananthvk/cpp-raytracer.git
Otherwise you can also download the source directly from github.
cd cpp-raytracer
mkdir build
cd build
cmake ..
make
Then run the application with
./raytracer
On windows, open the project in MSVC and build the project. Or you can also install mingw and use gcc for compilation. Run the generated executable.
A list of files in src
directory with a short description.
File | Description |
---|---|
camera.cpp and camera.hpp | Has the camera class, which produces rays cast into the scene |
colors.hpp | Defines color types, lerp for color, common colors and gamma correction. |
commons.hpp | Common functions - random number functions, intersection, interaction structs |
config.hpp | Default configuration for the raytracer |
frombook.hpp | Methods copied from book to test a particular functionality |
image.hpp and image.cpp | Functions for writing the image to a file |
main.cpp | Entry point for the program, main function |
material.hpp and material.cpp | Material class and defines various materials such as lambertian, glass, and metals. |
objects.hpp and objects.cpp | Different objects used in raytracing - spheres |
progressbar.hpp | Functions to display progressbar on the console |
raytracer.hpp and raytracer.cpp | Single threaded and multi threaded raytracer class and functions. They perform the main task of raytracing |
scene.hpp and scene.cpp | Defines the scene to be used for raytracing. |
This project is licensed under the MIT License - see the LICENSE file for details.
stb_image_write.h
andstb_image.h
for writing images - https://github.com/nothings/stb/linalg.h
for vectors - https://github.com/sgorsten/linalg
https://raytracing.github.io/books/RayTracingInOneWeekend.html