SQL Language Now Supports Ray Tracing System

Alexey Milovidov, co-founder of the ClickHouse DBMS, along with the help of the AI assistant Claude has recently released a ray tracing system that has been fully implemented using SQL. The system utilizes lighting simulation rendering through path tracing, all in the form of a single SQL query without the need for user-defined functions (UDFs) or external code. The ClickHouse DBMS’s capability to save query results in PNG format is leveraged to display the graphics. The project is currently fully operational within the ClickHouse DBMS, but experiences some errors and is 33 times slower when run on the CedarDB DBMS. The project is licensed under a Creative Commons BY-NC-SA license.

Each pixel in the system corresponds to a row in a table containing columns for coordinates (X, Y) and color representation (R, G, B). Mathematical operations for 3D calculations are represented using tuples, where vectors are encoded as Tuple(Float64, Float64, Float64). The system implements a loop for modeling multiple reflections of light from surfaces using the arrayFold SQL function, which runs within each row to parallelize rendering. Geometric primitives supported include cylinders, tori, spheres, and oriented parallelepipeds, with operations such as union and difference (removing intersections) performed on them. The landscape is generated mathematically.


Previously, the ClickHouse DBMS developers have worked on projects such as a Doom-like game, a RISC-V emulator, and a music synthesizer.

/Reports, release notes, official announcements.