Relational Raytracing: The Right Tool for the Wrong Job
- Readers
- Tim Fischer
Throughout our research on compiling imperative programs to SQL, we’ve time and time again fallen back to using a “simple ray-tracer” as an outlandish example for what is possible. This simple ray-tracer we use, traces its origins back to a wonderful demo-scene project by Nick “Holtsetio” back in 2019. Our compilation research has moved along by major strides since we first implement the ray-tracer using the fruits of our labor, but the ray-tracer itself has remained basically the same—only simple diffuse or perfectly reflective materials with no near-grazing reflections, no surface scattering, no refraction, etc.

In this research project, your task is build a new ray-tracer in SQL for DuckDB from scratch using Flummi, the current iteration of our to-SQL compiler project. But fret not, because you are not on your own! Over the past decade, writing a ray-tracer has become a hobby onto itself, so you will find a wealth of resources all over the internet. The most solid entry point into the topic is the “Ray Tracing in One Weekend” book series. Another good source of inspiration for this project is the pure SQL ray-tracer by Gary Briggs, just be cautious with this one, as it uses PostgreSQL as a “rendering backend”—though the SQL dialect may be similar, the performance you can expect is wildly different.