Alexey Milovidov, co-founder of the ClickHouse DBMS, with the assistance of AI assistant Claude, published a ray tracing system fully implemented in SQL. Rendering with light simulation based on ray tracing is achieved through a single SQL query without user-defined functions (UDF) and without external code. ClickHouse DBMS capabilities are used to output graphics, saving query results in PNG format. The project runs fully operational in ClickHouse DBMS but may work in CedarDB with separate errors and is 33 times slower. The project is distributed under the Creative Commons BY-NC-SA license.
Each pixel represents a row in a table, which includes columns for coordinates (X, Y) and color representation (R, G, B). The mathematical operations necessary for 3D computations are built on tuples—a vector is encoded as Tuple(Float64, Float64, Float64).
The loop for simulating multiple reflections of light from surfaces is implemented through the SQL function arrayFold and runs inside each row to parallelize rendering. Supported geometric primitives include cylinders, tori, spheres, and oriented parallelepipeds, on which union and difference (intersection removal) operations are performed. The landscape is generated mathematically.

Previously, ClickHouse DBMS developers prepared a Doom-like game written in SQL, a RISC-V emulator, and a music synthesizer.
Source: opennet.ru
