A Minimal Raytracer for You to Mess With and Learn From

Learn to program by writing a raytracer

Dale Thomas
The Startup

--

People often ask me what project they should work on to learn to program. I always answer the same way. Write a raytracer. I don’t just say that to people who specifically want to learn graphics programming, I say it to everyone who wants to learn general programming too.

There are many reasons why raytracers are a good way to learn to program, but here are five:

  1. It’s pretty easy. There is nothing particularly difficult about raytracing. If you have a smattering of programming experience, and highschool level mathematics, you can begin creating pretty pictures with pure code. So what are you waiting for?
  2. Shallow learning curve. First, get pixels plotted to an image. Then get a vector class working. Then intersect a ray with a sphere. Then calculate normals. Then calculate lighting. Then shadows, then textures, then reflection, then antialiasing, and so on. Each step is self-contained, simple to understand, and easy to add.
  3. Visual debugging. You can see if your normals are inverted. You can see if your shadows need a bigger epsilon. You can see if your camera rays are non-uniformly distributed. We are visual creatures, and being able to see any problems is far easier than if you are debugging an abstract data system.
  4. It fits well with programming paradigms. Regardless of which language you want to learn, or which methodology…

--

--

Dale Thomas
The Startup

Scifi writer, roboticist, and game developer, 2x Quora Top Writer. I write about writing speculative fiction, computer graphics, AI, evolution, and programming.