Skip to main content

Developing an Object Oriented Raytracer in C++

·2 mins

For a programming class during my studies at the Rotterdam University of Applied Sciences 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 refers to the number of times a ray is shot through every pixel. For every sample, a ray is shot through a slightly different point in the pixel.

Sampels per pixel: 10
Sampels per pixel: 100
Sampels per pixel: 1000
Sampels per pixel: 10000

Renders #

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

ResolutionSampels Per PixelRender timeResult
100x100100.27sLink
100x1001002.32sLink
100x100100023.93sLink
100x100100004m34sLink
500x500106.38sLink
500x5001001m7sLink
500x500100011m27sLink
500x500100001h54m36sLink
1000x10001028.16sLink
1000x10001004m41sLink
1000x1000100045m58sLink

Features #

  • Support for Spheres, Cubes and Planes
  • Diffuse and reflection
  • Multiple lights
  • Movable camera with a user controlled Field of View (FoV) and position
  • Scene reader using JSON

Architecture #

The ray tracer is build using Object-oriented programming (OOP). For example, a parent class (BasicObject) was created for all objects to be placed in the scene. The different objects are derived from this parent class (Cube, Sphere and Plane). By using the Parent-Child structure, the child class can inherit functions that are the same for all objects. The full UML can be found here. A simplified UML can be found below.

Simplified UML

Code & Installation #

The source code for the Ray Tracer is available here. The installation process is quite simple. Clone the repository and execute the following command:

$ make