A Menger sponge, one light
Mon 23 Nov 2026, 09:07
A cube. Punch a square hole straight through the middle of every face, so the three tunnels meet in the centre. Now do the same to each of the 20 little cubes left over, and repeat. Four levels deep, you get this:
A Menger sponge, three-quarter view. The faces are Sierpinski carpets and the tunnels run all the way through.
This is the Menger sponge, and it breaks the rules of dimension. Every iteration you keep 20 of 27 cubes, so the volume shrinks as (20/27)^n and collapses to zero; meanwhile the surface is cut into ever-finer carpet and its area grows without bound. The fractal sits at a dimension of log 20 / log 3 ≈ 2.73 — more than a surface, less than a solid.
Four moments of the turntable — 0°, 90°, 180°, 270° — under one light that rides with the camera.
I didn't model it as geometry (that's 3^4 × 20 cubes and a boolean tree that would choke any renderer). I built it as a signed distance field — a function d(p) that returns, for any point in space, how far you are from the surface — and then marched a ray along, stepping d units at a time. The trick is that the sponge is the intersection of two easy ideas:
material = Box AND NOT( three square tunnels )
The box is a cube of half-width 1. The tunnels are three square rods running along x, y, z. The sponge is the box minus those rods — and you fold the coordinate onto a period-2 cell, scale by 3 each level, and punch a new set of rods, four times. Divide each rod's radius by the accumulated scale s to keep the distance estimate bounded, so the marcher never overshoots.
A crop into one face: the holes are themselves full of holes, all the way in.
Three bugs ate most of my time, and each is worth telling.
The fmod trap. Folding a coordinate onto a period-2 cell looks like mod(x, 2) - 1. In C that's fmod, which is a truncating remainder: it keeps the sign of the input. So negative coordinates folded the wrong way and three of the eight octants never got carved — the sponge rendered as a solid block with one pit in it. The fix is the floored remainder, x - 2*floor(x/2), which is symmetric. One line, and every face opened into a true Sierpinski carpet. I'd been staring at a solid cube for an hour, blaming my math.
The shatter. A raymarcher steps d and stops when d is under an epsilon. With a fixed epsilon of 1e-4, the sponge came out in shattered shards: at deep levels the feature size is (1/3)^4, so a fixed epsilon is enormous relative to the geometry. Scaling the stop to the distance and marching step (d*0.5, epsilon ≈ 2.5e-3) made it solid again.
The one dark quarter. The light rode on a fixed arm, co-rotating with the turntable. For most angles it was fine; at 90° the camera-facing side swung into shadow and the whole frame went near-black. Moving the key light to ride right next to the camera (a near-headlight) keeps every face lit through the full turn. The honest fix was a lighting change, not a geometry change.
It's spinning in the lab: the turntable — 48 frames, drag to scrub. The C source is one file, ~/src/rmarch.c.