Ray Tracing Renderer

GitHub

A ray tracing renderer built from scratch in C++.

An image rendered by the ray tracer demonstrating reflection, refraction, shadows, and texture mapping.

Key Features

  • Ambient, diffuse and specular shading
  • Directional lights
  • Attenuated point lights
  • Depthcueing
  • Hard shadows
  • Soft shadows
  • Reflection
  • Transparency
  • Refraction
  • Depth of field
  • Texture mapping
  • OBJ support
  • BVH acceleration

Description

I built this ray tracer from scratch using C++ as part of a semester-long project in CSCI 5607: Computer Graphics.

This ray tracer is capable of rendering scenes with diffuse shading, multiple light sources, light attenuation, reflections, transparency & refraction, soft shadows, depth of field, texture mapping and depthcueing. It utilizes a bounding volume hierarchy (BVH) to efficiently render scenes with more complex geometry, and also has a custom "scene description" file parser that supports OBJ models with normals, uvs and material properties.

Challenges

With the ability to interpret arbitrary OBJ models via my custom file parser, I thought it would be fun to test my ray tracer on some higher complexity models, such as the classic Stanford bunny. Unfortunately, when I first attempted to render the Stanford bunny it took well over 10 minutes to complete. This made it practically impossible to setup a compelling scene since every time I wanted to test a new camera position, tweak the lighting or change the material properties I was forced to wait minutes for a render to complete.

To speed things up, I knew I needed to utilize some sort of spacial data structure to avoid the O(N²) computation of checking every ray against every triangle for intersection. To achieve this I implemented a basic bounding volume hierarchy, partitioning the scene into a tree of bounding boxes, which decreased render times for complex models from minutes to seconds!

While using a BVH allowed for the efficient rendering of much more complex scenes than my ray tracer was initially designed for, and sub-second rendering speeds for simple scenes, if I were to build a ray tracer from scratch again I would absolutely do so utilizing the GPU instead of the CPU.

Demo

Demonstration of depth of field, along with reflection, refraction and texture mapping.
Demonstration of soft shadows and depthcueing, where utilizing a BVH allows for efficient rendering of such a complex model.
Example of a "scene description" input file (left) and its corresponding output (right). Scene description files provide robust control over the camera, lighting, materials and objects rendered in the scene.

Tools Used

Languages: C++

Software: Make, Git