At the time of writing, the term raytracing is used often to represent “high quality graphics” or making scenes look more realistic. Even though this could be achieved by using ray tracing techniques, in essence raytracing is used for a lot more. Let’s first split the term to make sure we’re talking about the same thing:

  • Raycasting is calculating the first intersection of a ray with the scene geometry. This is used commonly to trace visibility queries, or find the world space coordinates for a pixel on the screen for example.
  • Raytracing is a series of tracing a rays into the scene, usually with secondary rays to calculate light traversal paths. For example we could try to render a diffuse object by sending out 10 secondary rays in different directions to calculate how lit this part of the surface should be.
  • Pathtracing is a form of raytracing where we use probability sampling to reflect realistic light paths. It’s an iterative process where we sample new directions from the material properties that will make the end result eventually converge to the reference image given enough samples. In this tutorial series we’re going to start by building a simple raycaster and then continue to expand to a full fledged pathtracer at the end. Pathtracing involves a lot of theory and math, but raycasting and raytracing are pretty straightforward tools to use in everyday scenarios!

Over the years there have been plenty of amazing free online resources to learn raytracing from. One of them is Ray Tracing in One Weekend. Throughout the series I will refer to some of these articles that I’ve learned from in addition to providing my own examples. Feel free to follow any of the reference articles I mention. Without further ado, here’s the complete final example from Ray Tracing in One Weekend running live:

It may take a while to compute the final image. I’ve adapted the code slightly to run on this web page, but no major changes to the code have been made.