Skip to content
Andrew Voirol
Work → Vitrail: Stained-Glass Jenga in WebGPU & MuJoCo 4.0
Interactive SimulationLive

Vitrail: Stained-Glass Jenga in WebGPU & MuJoCo 4.0

Regulation-scale stained-glass Jenga powered by raw WebGPU and Google DeepMind's MuJoCo 4.0 WASM — multi-block Maxwell-Fresnel refraction, dark-field Brewster stress-optic polariscopy, Cowper-Timoshenko modal acoustics, 2-ply counterfactual Glazier AI, and chaos-tested Online Rooms.

Code↗ Live

MuJoCo 4.0 WASM · 0.098 mm sag · Brewster Polariscope · 58/58 invariants

Started Nov 10, 2026·Updated Nov 12, 2026

Every prism in Vitrail is modeled to 1:1 regulation Jenga dimensions — 7.5 × 2.5 × 1.5 cm (71.1 g of beveled cathedral soda-lime glass across 18 courses = 27.0 cm) — resting on a quarter-sawn ring-porous white oak bullnose table (43 cm radius). Tap any legal prism to scout 0.09 mm micro-tolerance clearance by ear, toggle the dark-field Polariscope lens to inspect live photoelastic force chains, draw blocks along narrow lead-came channels via an implicit MuJoCo <connect> tether, or challenge Glazier AI and remote players in 5-character Online Rooms before the stack shatters into hundreds of 3D Voronoi shards.

Multi-pass WebGPU optics & Brewster stress-optic polariscopy

Single-surface refraction breaks down immediately in a glass tower: as soon as one colored prism slides behind another, rear blocks vanish instead of filtering transmitted light. Vitrail runs a single-encoder rgba16float HDR pipeline (4× MSAA) that raytraces primary beveled prisms (n = 1.522) with exact unpolarized Maxwell–Fresnel reflectance 0.5(Rs+Rp)0.5(R_s + R_p)0.5(Rs​+Rp​) and Cauchy dispersion (Vd≈58V_d \approx 58Vd​≈58), marching refracted rays through up to two interior stained-glass blocks behind the front hit:

I(λ)=I0(λ) exp⁡ ⁣(−∑k=1Nσa(k)(λ) dk),I⊥(λ)=I0(λ) sin⁡2(2θp) sin⁡2 ⁣(π CBλ∫ray∣σ1−σ2∣ ds)I(\lambda) = I_0(\lambda)\,\exp\!\left(-\sum_{k=1}^{N} \sigma_a^{(k)}(\lambda)\,d_k\right), \qquad I_{\perp}(\lambda) = I_0(\lambda)\,\sin^2(2\theta_p)\,\sin^2\!\left(\frac{\pi\,C_B}{\lambda}\int_{\text{ray}} |\sigma_1 - \sigma_2|\,ds\right)I(λ)=I0​(λ)exp(−∑k=1N​σa(k)​(λ)dk​),I⊥​(λ)=I0​(λ)sin2(2θp​)sin2(λπCB​​∫ray​∣σ1​−σ2​∣ds)

In Natural mode (left), each interior segment accumulates per-swatch Beer–Lambert spectral absorption σa(k)(λ)\sigma_a^{(k)}(\lambda)σa(k)​(λ) alongside hollow-sphere seed bubble Total Internal Reflection rings and Griffith cleavage mirrors. Clicking Polariscope (Isochromatic mode, right) places the smoked-crystal stack between crossed circular polarizers (CB=2.65 BrewstersC_B = 2.65\text{ Brewsters}CB​=2.65 Brewsters), integrating per-prism MuJoCo contact wrenches across local -X, 0, and +X bearing zones plus Euler–Bernoulli three-point flexural bending so load-bearing columns illuminate in 1st- and 2nd-order interference fringes while unloaded prisms remain dark smoked crystal.

Pass / SubsystemResolution / BudgetTechnical Implementation
Sun shadow & PCSS atlas2048×2048 + 1024×1024Depth shadow map paired with spectral Beer–Lambert optical-depth and min-caster-height blocker search
Block & shard Snell caustics2048×2048 (uCausticTex.rgba)Oblique sun transmission projected across both 54 intact prisms and 512 convex 3D Voronoi shards onto white oak
Tower & Brewster raytracerrgba16float (4× MSAA)Analytic beveled OBB raytracing (<= 2 interior blocks), Maxwell–Fresnel 0.5(R_s+R_p), Cauchy dispersion, and 3-sample Brewster birefringence
Convex Voronoi shard pass512-slot ring (<= 132 verts)Differentiates outer copper-foil solder cames from raw inner conchoidal cleavage planes + residual edge retardation
Dual XDR / SDR swapchainExtended HDR + ACES SDRSwitches automatically to toneMapping: { mode: 'extended' } on Apple Silicon XDR displays via matchMedia('(dynamic-range: high)')

Why Google DeepMind's MuJoCo 4.0 WASM replaced Rapier3D

Vitrail originally shipped on @dimforge/[email protected] after an attempted upgrade to Rapier 0.21.0 (TGS Soft regularized contact solver) inflated 18-course sag from < 0.15 mm to 0.388 mm and caused 1.2 g splinters to chain-shatter intact courses. Even on 0.14.0, sequential Gauss–Seidel velocity impulses solved contacts pairwise without elliptic torsional friction or full-stack second-order coupling — requiring coordinate heuristics to suppress resting micro-jitter.

Replacing Rapier3D with @mujoco/[email protected] (4 WASM pthreads via mju_threadpool inside a dedicated ES Module Web Worker, 0.0 ms main-thread rAF stall) solved all three structural bottlenecks from first principles:

  • Full-stack sparse Newton Hessian (0.098 mm sag, 8.6 µs asleep): Solving H=M+JTDJH = M + J^T D JH=M+JTDJ via sparse Cholesky factorization at 600 Hz (timestep = 1/600 s) couples all 18–24 courses simultaneously. Calibrated 18-course sag dropped to 0.098 mm (0.199 mm across 24 courses), with 54/54 bodies entering native constraint-island sleep (d.nisland / d.tree_asleep) in 8.6 µs/step while preserving cached efc_force clamping wrenches for the Polariscope.
  • Elliptic condim = 4/6 tribology & implicit <connect> extraction: Replacing pyramidal friction boxes with elliptic cones (condim = 4 on beveled glass prisms, condim = 6 on the white oak table) couples normal load, tangential slide, and torsional pivot torque during crooked one-handed pulls, while Stribeck priority promotion (0.22 -> 0.125) models static breakaway into kinetic glide.
  • Progressive Griffith crazing & 3D Voronoi rebound (T9, C1–C8): Sub-critical impacts accumulate micro-crack damage d∈[0,1)d \in [0, 1)d∈[0,1) that weakens fracture threshold via vshatter(d)=v0(1−0.36d)v_{\text{shatter}}(d) = v_0(1 - 0.36d)vshatter​(d)=v0​(1−0.36d) before Sutherland–Hodgman half-spaces clip prisms into a 512-slot sleep="init" pool (< 0.2 ms activation, < 0.05% volume error). Routing shard-table impacts through a dedicated oak_table_shard contact pair (solref = [0.0060, 0.48]) and gating micro-jitter damping strictly on verified upward qfrc_constraint eliminated explicit Euler 1−bΔt/I1 - b\Delta t/I1−bΔt/I blowup on 0.2 g shards and preserved true 3D tabletop and mid-air shard rebounds.
💡

520-seed energy passivity fuzzing (statefulFuzz.test.ts): Every solver parameter change is gated against 58/58 Vitest invariants plus a stateful multi-action trajectory fuzzer (520 seeds × 80 randomized tap, grazing pull, placement, and nudge actions) verifying total mechanical energy passivity E=mj_energyPos+mj_energyVelE = \text{mj\_energyPos} + \text{mj\_energyVel}E=mj_energyPos+mj_energyVel (0 NaNs, 0 solver resets, automatic ddmin trace shrinking on failure). Full derivations live in docs/SCIENCE_AND_MATHEMATICS_OF_VITRAIL.md and docs/COLOSSEUM_AUDIT_REPORT.md.

First-principles modal acoustics, 2-ply Glazier AI & Online Rooms

  • Cowper–Timoshenko thick-bar & Kirchhoff oak acoustics (9/9 invariants): Because a 75 × 25 × 15 mm glass prism has aspect ratio h/L=1/3h/L = 1/3h/L=1/3, slender Euler–Bernoulli beam theory overpredicts upper bending partials by > 18%. GlassAudioEngine solves exact Cowper–Timoshenko rotary-inertia and shear dispersion (κs=0.8461\kappa_s = 0.8461κs​=0.8461) with Reuss copper-foil/60–40 Sn–Pb\text{Sn–Pb}Sn–Pb solder compliance, Griffith crazing stiffness softening (E(d)/E0=1−0.060d−0.018d2E(d)/E_0 = 1 - 0.060d - 0.018d^2E(d)/E0​=1−0.060d−0.018d2), Hertzian impact cutoff scaling (τc∝meff2/5Reff−1/5vn−1/5(E∗)−2/5\tau_c \propto m_{\text{eff}}^{2/5} R_{\text{eff}}^{-1/5} v_n^{-1/5} (E^*)^{-2/5}τc​∝meff2/5​Reff−1/5​vn−1/5​(E∗)−2/5), Leissa orthotropic white-oak Bessel plate modes, accelerating Housner bevel rocking ticks, and f0∝mi−1/3f_0 \propto m_i^{-1/3}f0​∝mi−1/3​ Voronoi shard chattering.
  • Zero-mutation mj_copyState 2-Ply Glazier AI: In Pass & Play -> AI, the worker clones live MjData into an isolated scratch buffer, optimizes extraction pull azimuth via Cross-Entropy Method (optimalPullAzimuthRad), and evaluates 2nd-ply adversarial top-course placements (twoPlyMasterScore01 = 0.763 on unloaded blocks vs 0.277 on pinned bearing columns) with a real-time bind-and-release tactician reflex if a grabbed block binds (< 8 mm travel at high tension).
  • Chaos-tested dual-transport Online Rooms: Five-character room codes (?room=K7M4P) pair browsers directly over public WebRTC RTCDataChannel (< 4 KB 0x564d binary snapshots at 30 Hz + round-robin 120-shard/packet cursor for 1:1 512-shard parity) with automatic <= 4.0 s ICE stall or mid-drag disconnect failover to a Cloudflare Durable Object SQLite WebSocket relay — verified across a 100-match network chaos simulator (8% drop + 65% burst loss, 120 ± 45 ms jitter, < 2.0 mm Guest convergence) and a 16-stage live two-browser hardware-WebGPU E2E harness.
WebGPUShadersDesignApple SiliconReactBenchmarkingArchitectureShippingOpen Source

Related Threads

Building Vitrail: Stained-Glass Jenga in WebGPU & MuJoCo 4.0

From multi-block Beer-Lambert refraction and catching a Rapier solver regression to migrating onto Google DeepMind's MuJoCo 4.0 WASM, Brewster stress-optic polariscopy, Timoshenko modal acoustics, 2-ply counterfactual AI, and chaos-tested Online Rooms.


Andrew Voirol

Builder, hacker, shipper. Currently leaving localhost.

Navigate

WorkThreadsBuilder's LogAboutContactRSS Feed

Connect

X / TwitterGitHubLinkedIn

© 2026 Andrew Voirol·Back to top ↑
✦Just one prompt away from figuring it all out.