A Minimal Raytracer for You to Mess With and Learn From
Learn to program by writing a raytracer
Published in
7 min readDec 16, 2020
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:
- 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?
- 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.
- 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.
- It fits well with programming paradigms. Regardless of which language you want to learn, or which methodology…