Ray Tracing

A ray tracing renderer written in C++

Download .zip Download .tar.gz View on GitHub

Overview

The aim of this project was to create a ray tracer which, given a .obj file, will output an image rendering of the object contained within. If the .obj file is not modified slightly to contain a camera (with position, look direction, and FOV) and/or lights (with position, color, and intensity), then the renderer picks the best values for these missing ones in an attempt to present the scene in a reasonable way.

Features

As you can see from some of the images in the next section, the ray tracer is capable of handling all three types of lighting (ambient/specular/diffuse), reflections, and shadows.

In order to speed up rendering time, the ray tracer features a BVH tree. Normally, the renderer must check every polygon in the scene when a ray is cast. A BVH tree limits the number of polygons that need to be checked. Basically, this means that every .obj is split into a tree where the root node is a bounding box that I create.

The children of the root are bounding boxes containing half as much geometry, and so on until you reach the actual geometries themselves. So, instead of checking ray collision against real geometry, we check its collision with bounding boxes. This means that rays which miss all or many objects take up much less computation time.

More information can be found on using BVH trees for efficient ray tracing here.

Examples

Below are some examples of scenes rendered with my ray tracer.

Cornell Boxes

Cornell Boxes

Sphere of Triangles

Sphere of Triangles

Bunny

Bunny from Behind

Teapots

Teapots