Alexey Milovidov, co-founder of the ClickHouse DBMS, with the assistance of the AI assistant Claude, published a ray tracing system implemented entirely in SQL. The rendering with light simulation based on path tracing is executed as a single SQL query without user-defined functions (UDF) and without connecting external code. The ClickHouse DBMS's ability to save query results in PNG format is used to output graphics. The project functions fully when run in ClickHouse, but with some errors, may operate 33 times slower in CedarDB. 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 necessary mathematical operations for 3D computations are based on tuples — a vector is encoded as Tuple(Float64, Float64, Float64).
Il ciclo per la simulazione di riflessioni multiple della luce sulle superfici è implementato tramite la funzione SQL arrayFold ed è eseguito all'interno di ogni riga per parallelizzare il rendering. I primitivi geometrici supportati includono cilindri, torri, sfere e parallelepipedi orientati, sui quali vengono eseguite operazioni di unione e differenza (rimozione delle intersezioni). Il paesaggio è generato matematicamente.

In precedenza, gli sviluppatori del DBMS ClickHouse hanno creato un gioco in stile Doom scritto in SQL, un emulatore RISC-V e un sintetizzatore musicale.
Fonte: opennet.ru
