This is the code from Paul Graham's ANSI Common Lisp, tidied with my comments plus a few tweaks.
In particular, I added the ability to move the light source.
All comments in the source files above are my own.
This is the basic output with the world as per the book, at 4x scale to be more impressive.
Emphasis of this code is on simplicity and correctness, not speed.
Note though, Ray tracing in general is very amenable to parallelisation because the calculation of each ray can be considered computationally distinct. This code is many thousands of times slower than it could be done on your GPU.
We can pan the eye position left which is quite trivial:
But moving the light source is quite nice (this is the bit I added to the code in the book).
Here the light source is moved left by log scale increments:
Personal next steps? I plan to check back in on this code after reading 7 Concurrency Models.
Obviously there's no system definition (.asd
file) here, all I was doing is evaluating
each source file directly into a REPL. Be warned it does take about a minute on my 2015 macbook
pro to generate an image even at the smallest size.
There is more info in comments in the source files.