Terminal Ray Tracer

Unknown

At the end of October 2021, I gained access to the beta for the AI GitHub Copilot, and wanted to test it out on something small in scope. I remembered a side project from 10th grade, I tried developing my own rendering engine from scratch. At the time, I lacked the math experience necessary to ultimately get it working. Though I'd never heard of a ray tracer before, it turns out the design I came up was almost identical (at the time, I was less interested in the reflection aspect, and more interested in the prospect of arbitrarily detailed geometry at any scale level, à la SVGs). Long story short, I figured it would be a fun challenge to write a ray tracer, now that I had the math background from my linear algebra and robotics classes in college. And as an added challenge (technically to make things easier), I decided that it should run directly in the terminal without the need for any sort of window or display.

As it turns out, Copilot isn't going to replace programmers any time soon (especially domain experts). I definitely was surprised by how well it "understood" what I wanted it to do, but in general, it tended to lack the high level view needed to get things working together, and also definitely had a hard time dealing with very specific domain problems. But it is still an incredible productivity booster—just about every situation where it was perfectly clear what the code needed to do, the copilot usually had the correct suggestion ready to go.

Development

All clips are in real time, and running directly on my cpu (Intel® Core™ i7-6700 CPU @ 3.40GHz × 8). Future work definitely includes converting to CUDA and other optimizations.


Initial rendering of colored spheres


Added reflections without lighting


Added ground plane and sky color


Added multiple rays per pixel for anti-aliasing. Also testing out higher resolution


Added lighting (point lights and directional lights)


Added image based lighting with skybox cube map

Try It


git clone git@github.com:david-andrew/TerminalRayTracer.git
cd TerminalRayTracer
clang TerminalRayTracer.c -lm -O3 && ./a.out