Ray Tracer

An Object Oriented ray tracer written in C++. The image below shows the Cornell Box rendered with the ray tracer.

Image
graphical divider
Avatar
Aug 21, 2020

For a programming class in my second year of studies I wrote an object oriented ray tracer in C++. There is support for multiple types of objects, diffuse and reflection, multiple light sources and a scene reader.

I have rendered the same scene with different resolutions and samples per pixel. Samples per pixel means the number of times a ray is shot through that pixel, and each time through a slightly different point in that pixel.

Renders

Render time for the cornell box on a i5-8250u processor.

Resolution Sampels Per Pixel Render time Result
100x100 10 0.27s Link
100x100 100 2.32s Link
100x100 1000 23.93s Link
100x100 10000 4m34s Link
500x500 10 6.38s Link
500x500 100 1m7s Link
500x500 1000 11m27s Link
500x500 10000 1h54m36s Link
1000x1000 10 28.16s Link
1000x1000 100 4m41s Link
1000x1000 1000 45m58s Link

Features

  • Support for Spheres, Cubes and Planes
  • Diffuse and reflection
  • Multiple lights
  • Movable camera with a user controlled FOV and position
  • Scene reader

Architecture

The ray tracer consists of different objects classified in a class structure. For example, a Parent class for all objects, and different objects derived from this Parent class such as Cube, Sphere and Plane. By using the Parent-Child structure, the child class can inherit functions that are the same for all objects. See the simple UML design below.

Simple UML
Simple UML

Installation

The installation process is quite simple. Clone this repository and execute the following command:

$ make

Todo

  • Add support for more shapes
  • Multithreading
  • Textures

Code

Checkout the source code here!

divider graphic

Check out other projects

arrow-up icon