Ray Tracer in SQL

Someone made a picture generator out of SQL and the internet can’t decide if it’s genius or pain

TLDR: A developer made SQL, the language used to talk to databases, generate a full image all by itself. The real drama came in the comments, where people split between calling it a brilliant hack, a pointless pain ritual, and proof that weird coding projects still know how to start fights.

A developer has pulled off the kind of stunt that makes the internet lean in, laugh, and then immediately start arguing: they built a full-on image renderer entirely inside SQL, the language people normally use to ask databases boring office questions. Instead of just fetching data, this one giant query calculates every single pixel and spits out a finished PNG image showing shiny ClickHouse letters floating over a generated landscape. No extra code, no plugins, just one massive database command doing the visual heavy lifting. Naturally, the comments turned into a mix of applause, confusion, and existential screaming.

The loudest reaction was basically: “Amazing… but also, why would anyone do this?” One commenter summed up the community’s collective double take with a blunt “Nice, but why ?” Another called it the cursed meeting point of talent and self-inflicted suffering, saying the level of skill and masochism on display “shouldn’t exist and yet it does.” That energy really became the mood of the thread: admiration wrapped in disbelief. There was also classic hacker humor, with one person joking that the obvious next step is to create “a database with SQL” so we can all query our database’s database and fall into a tech version of Inception.

But not everyone was charmed. One of the spicier takes came from the AI gloom corner, where a commenter argued these playful engineering flexes don’t hit the same anymore because AI has drained the joy from watching handcrafted coding stunts. Others pushed the opposite vibe by sharing their own weird graphics-in-database experiments, which turned the whole discussion into a celebration of glorious, unnecessary creativity. In other words: this wasn’t just a demo. It was a fresh outbreak of the internet’s favorite fight — is this brilliant art, pointless suffering, or both?

Key Points

  • The article presents a path tracer implemented entirely in ClickHouse SQL, with a single SELECT query computing all pixels and writing PNG output directly.
  • Pixels are represented as rows generated by `numbers_mt(width * height * samples)`, with per-pixel samples averaged using `GROUP BY pixel` and explicit `x`,`y` coordinates used for image placement.
  • 3D vector math is expressed with `Tuple(Float64, Float64, Float64)` values and helper functions, while ray bounces are handled through `arrayFold` so rows remain independent and parallelizable.
  • The scene uses constructive solid geometry combining cylinders, tori, spheres, and oriented boxes, including signed-distance-field ray marching for tori and subtraction operations for letter openings and a chrome planet.
  • The terrain is a procedural fBm-based height field ray-marched with interpolation and shaded using color ramps, sun and sky lighting, shadows, and distance fog; the queries are self-contained and parameterized for image size and samples.

Hottest takes

"Querying my database's database with my database's SQL's SQL would be trippy." — cma256
"Nice, but why ?" — Jgoauh
"The intersection of skill and masochism needed for this shouldn't exist" — mghackerlady
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.