Infinity mirror room

I wanted to know if one WebGL 2 fragment shader could raytrace a 6-wall mirrored cube around a glowing HTML plaque, shift deeper bounces into soda-lime glass green, and keep the primary plaque live via projective updateElementGeometry(). Drag inside the room to orbit, type directly onto the floating plaque, switch LED palettes or drag the bounce depth between 2 and 14.

Chamber 01 · Live DOM
RIPPLE 0
starting...

Show the code ElementGL texture upload, 6-wall mirror raytracer and projective updateElementGeometry()
  1. Floating plaque markup inside one drawable canvas. The plaque sits inside <canvas content="drawable" layoutsubtree> with transparent rail gaps and open corner eyelets so mirror rays pass through the holes.
  2. One WebGL 2 context through ElementGL. On every paint event, stage.upload(plaque) calls gl.texElementSubImage2D() and rebuilds mipmaps so distant bounces stay legible.
  3. 6-wall mirrored cube raytracer in GLSL. Loops up to 14 reflections inside [-1, +1]^3, samples the double-sided plaque with analytic ray differentials via textureGrad(), passes remaining light through transparent cutouts, and applies soda-lime glass absorption per bounce.
  4. Double-sided projective updateElementGeometry(). Maps the floating plaque quad through P * V * M_world, flips its horizontal basis when orbited behind z = 0, scales by geometryUnit() and toggles dataset.hitTick.

How it works

Everything draws on a single WebGL 2 context made with new ElementGL(canvas, ...) from /lib/element-gl.js. Inside <canvas content="drawable" layoutsubtree> sits one drawable plaque with an editable headline <input>, four LED palette buttons, a polka-dot LED border and a pulse button. Whenever you type or press a button, Chromium fires a paint event, stage.upload(plaque) updates the texture via gl.texElementSubImage2D() and gl.generateMipmap() refreshes the mip chain.

For each screen pixel, the fragment shader marches a ray inside a mirrored cube spanning [-1, +1]^3 for up to uMaxBounces reflections. Before hitting a mirror wall, the ray tests the central plaque at z = 0 and ten floating micro-lantern spheres in front-to-back order. Rather than calling implicit-derivative texture() inside a conditional loop, the shader carries two reflected pixel differential vectors rayDx and rayDy across each wall bounce and calls textureGrad() on the plaque texture. When a ray hits the hollow corner eyelets or the transparent air gap around the neon rails, (1.0 - tex.a) continues through the cutout to the mirrors behind it.

Each wall bounce reflects the ray and differential vectors across the hit axis, adds a faint mitered bevel highlight near wall edges, and multiplies throughput by uMirrorTint (vec3(0.86, 0.94, 0.90) at 100% tint). After 12 bounces, red drops faster than green, turning far-off plaques and micro-lanterns deep bottle-green like real soda-lime mirror glass. To keep the primary depth-0 plaque interactive from any angle, buildPlaqueCanvasMatrix() projects the 3D quad into canvas CSS pixels, swaps the local X axis when the camera orbits behind z = 0 so the back side stays upright and front-facing, scales by geometryUnit() from /lib/surface.js, calls updateElementGeometry() and toggles dataset.hitTick when the matrix moves. If WebGL 2 texElementSubImage2D() is missing, a 2D fallback draws nested green-tinted frames with 5-argument drawElementImage(); if HTML-in-canvas is missing or the context stays lost, the plaque moves into plain HTML below the hidden canvas.

Live checks

These checks run on isolated fixtures inside testStage() and wait for a tap so loading the page never opens extra WebGL contexts or moves focus.

StatusCheckDetail

Findings