HeadlinesBriefing favicon HeadlinesBriefing.com

ClickHouse Ray Tracer: Full 3D Rendering in Pure SQL Queries

Hacker News •
×

A new project demonstrates that ClickHouse can handle complex computational graphics by implementing a complete path tracer using only SQL queries. The renderer produces glassy chrome lettering floating over procedurally generated terrain, all computed through a single SELECT statement that outputs directly to PNG format.

The implementation leverages ClickHouse's parallel processing capabilities by treating pixels as individual rows. Each row processes multiple samples that get averaged together, while 3D vectors are represented as Tuple(Float64, Float64, Float64) types with linear algebra operations wrapped in lambda aliases.

Geometry uses Constructive Solid Geometry principles with cylinders, tori, spheres, and oriented boxes. The terrain employs Perlin noise height fields with ray marching for efficient intersection testing. Multiple example scenes showcase different techniques, including a Pixar homage and the main "Click House" banner over rolling hills.

Performance benchmarks reveal the approach works well in ClickHouse but struggles in other databases. DuckDB couldn't process even small images, while Cedar DB ran 33 times slower with bugs. Python generators create the SQL queries, allowing runtime parameters for image size and sample counts.