Ray-tracing 3D Renderer


Project Background

This project began as an assignment for SFU’s “Introduction to Computer Graphics” course (CMPT 361). Over a span of 10 weeks, I was tasked with writing a basic software 3D renderer capable of performing Phong, Gouraud & flat shading.  I enjoyed this assignment immensely, so I decided to expand & improve upon it by implementing ray-traced shadows & reflections.

The project was written from scratch in C++, with library usage restricted to minor use of the C++ STL (Standard Template Library). The project uses the QT cross-platform application framework for GUI windowing, however aside from pixel set/get operations no other QT library functions were used. The project contains ~3200 lines of code.

GitHub Repository: https://github.com/b1skit/RayTracingRenderer

Demonstration images:

Shading models

A render of four spheres, demonstrating wireframe, flat shading, Gouraud shading & Phong shading

Ray traced sphere reflections

A demonstration of ray traced reflections between sphere objects

Ferrari California

A black & white ray traced render of a Ferrari California.
Model credit: https://free3d.com/3d-model/ferrari-california-93936.html

Ray traced sphere reflections

A demonstration of ray traced reflections between sphere objects

Ray traced primitives

A ray traced render of cubes, cylinders, spheres, a torus, capsule, cone & the classic Utah teapot

Shading models

A simple scene constructed from cube, sphere & 5 sided pyramid primitive shapes, demonstrating wireframe, flat shading, Gouraud shading & Phong shading

The Stanford Bunny

A render of the classic 3D scanned “Standford Bunny” model.
Model credit: http://graphics.stanford.edu/data/3Dscanrep/

Vertex color bilinear interpolation

A render of 7 cubes demonstrating bilinear interpolation of vertex colors

Specular highlights

A demonstration of various specular highlights that can be achieved by combining different specular exponent & coefficient values

Renderer Features:

  • Basic Rasterization:
    • Triangle filling
    • Line drawing
    • Wireframe rendering
    • Object transformations via matrices (Translation, rotation, scale of polygons, cameras & lights)
    • Bi-linear interpolation (Perspective correct color & normal interpolation)
    • Adjustable camera frustum/FOV (Field Of View) settings
  • Shading Techniques:
    • Flat/faceted shading (Lighting calculated once per face & applied to all vertices)
    • Gouraud shading (Lighting calculated once per vertex & interpolated across faces)
    • Phong shading (Per-pixel lighting)
  • Lighting:
    • Ray-traced reflections &  shadows
    • Point lights (User-controlled world space position, color & attenuation)
    • Ambient scene lighting
    • Depth cued distance fog
  • File Interpreter:
    • Compatible with Wavefront 3D object format (.obj)
    • 3D Scenes of can be fully constructed & controlled using a custom “simple” (.simp) ASCII file format
    • Supports command line file rendering
  • Render Pipeline Optimizations:
    • Backface culling (Discards polygons not facing the camera)
    • Frustum culling (Discards polygons outside of view frustum)
    • Sutherland–Hodgman Polygon clipping (Removes portions of polygons outside of view frustum)
    • n-gon Triangulation (Dividing convex polygons with 4 or more sides into triangles)
    • Pixel depth/Z-Culling (Early-out if current point is behind the current raster Z buffer depth)
    • Bounding boxes (Increased efficiency during ray intersection tests)