Raytracer

  • C++
  • Student

The Raytracer was developed for the Advanced Computer Graphics Techniques class in college. This project involves creating a complete system of algorithms to render three-dimensional images using the backward raytracing technique.

The raytracer simulates light paths as they occur in the real world, rendering effects based on the characteristics of objects. It can generate a high degree of realism, but at a significant computational cost.

Features

The complete list of features of the Raytracer project:

Workflow

  1. Rays are traced from the observer to each pixel on a virtual screen.
  2. Each ray must test for intersections with scene objects.
  3. Upon intersecting with the nearest object, the color is calculated from light sources by examining the object's material properties and combining (or shading) the information to produce the final pixel color.
  4. Reflective, refractive, or translucent materials, and extensive shadow generation, will require additional rays to be traced.

Acceleration Structures

Rendering a scene with thousands of primitives using the traditional raytracer algorithm is very slow and impractical. To address this we can use acceleration structures!

There are many alternatives for these structures, but in this project, I chose to implement a Bounding Volume Hierarchy (BVH).

BVH is a spatial partitioning binary tree formed from "bounding volumes." Each object has a bounding volume that defines its maximum boundaries. There are several variations and optimizations for real-time use.

Optimizing

To optimize the rendering routine of the raytracer, consider these points. In this project, I added the following optimizations:

1. BVH - Surface Area Heuristics

This is a BVH division method that seeks to minimize the time spent during ray intersections. While building the BVH, it estimates whether to create a leaf node or divide the node by checking the child nodes.

The cost of each node is proportional to the area of the bounding volume and the number of primitives contained within the node. The optimal division minimizes the cost of each node, though this method increases the construction time of the BVH. This same algorithm is used in kD-trees.

2. Polygonal Mesh Subdivision

A specific BVH for meshes follows the same principle as the scene BVH, but creates a bounding volume for each polygon in a mesh.

Polygonal Mesh Subdivision representation by [Thomas Diewald](https://github.com/diwi).
Polygonal Mesh Subdivision representation by Thomas Diewald.

3. Parallel Ray Tracing

To speed up the ray tracing process, the image buffer is subdivided among n threads. Each thread handles ray tracing for a portion of the buffer.

Multi-threaded ray-tracing.
Multi-threaded ray-tracing.

Future Improvements

There are several issues and potential improvements for this project:

Code and References

Some Links and other user codes that helped me during development:

Websites of data and resources sources: