Implementation

First time learning to build raytracer from scratch using OpenGL. The logic was pretty straightforward:

  1. Shoot a primary ray from the camera pixel by pixel within a frame
  2. Calculate to determine whether the ray hits any object, two types of geometry in the scene was Triangle and Sphere
  3. If the primary doesn’t hit anything, then there’s nothing to render
  4. If the primary does hit something, send a secondary ray from the hit spot to the light source to determine whether the object is in shadow
  5. If in shadow, render black. If not in shadow, render the color using Phong shading
  6. Shoot recursive reflection from that hit spot as well, rinse and repeat

Demo

Below are some of the result pictures: Picture 1 Picture 2 Picture 3 Picture 4 Picture 5

🛠️ Tools used

  • C++
  • OpenGL