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.
MuJoCo 4.0 WASM · 0.098 mm sag · Brewster Polariscope · 58/58 invariants
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 and Cauchy dispersion (), marching refracted rays through up to two interior stained-glass blocks behind the front hit:
In Natural mode (left), each interior segment accumulates per-swatch Beer–Lambert spectral absorption 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 (), 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 / Subsystem | Resolution / Budget | Technical Implementation |
|---|---|---|
| Sun shadow & PCSS atlas | 2048×2048 + 1024×1024 | Depth shadow map paired with spectral Beer–Lambert optical-depth and min-caster-height blocker search |
| Block & shard Snell caustics | 2048×2048 (uCausticTex.rgba) | Oblique sun transmission projected across both 54 intact prisms and 512 convex 3D Voronoi shards onto white oak |
| Tower & Brewster raytracer | rgba16float (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 pass | 512-slot ring (<= 132 verts) | Differentiates outer copper-foil solder cames from raw inner conchoidal cleavage planes + residual edge retardation |
| Dual XDR / SDR swapchain | Extended HDR + ACES SDR | Switches 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 mmsag,8.6 µsasleep): Solving via sparse Cholesky factorization at600 Hz(timestep = 1/600 s) couples all 18–24 courses simultaneously. Calibrated 18-course sag dropped to0.098 mm(0.199 mmacross 24 courses), with54/54bodies entering native constraint-island sleep (d.nisland/d.tree_asleep) in8.6 µs/stepwhile preserving cachedefc_forceclamping wrenches for the Polariscope. - Elliptic
condim = 4/6tribology & implicit<connect>extraction: Replacing pyramidal friction boxes with elliptic cones (condim = 4on beveled glass prisms,condim = 6on 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 that weakens fracture threshold via before Sutherland–Hodgman half-spaces clip prisms into a512-slotsleep="init"pool (< 0.2 msactivation,< 0.05%volume error). Routing shard-table impacts through a dedicatedoak_table_shardcontact pair (solref = [0.0060, 0.48]) and gating micro-jitter damping strictly on verified upwardqfrc_constrainteliminated explicit Euler blowup on0.2 gshards 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 (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/9invariants): Because a75 × 25 × 15 mmglass prism has aspect ratio , slender Euler–Bernoulli beam theory overpredicts upper bending partials by> 18%.GlassAudioEnginesolves exact Cowper–Timoshenko rotary-inertia and shear dispersion () with Reuss copper-foil/60–40 solder compliance, Griffith crazing stiffness softening (), Hertzian impact cutoff scaling (), Leissa orthotropic white-oak Bessel plate modes, accelerating Housner bevel rocking ticks, and Voronoi shard chattering. - Zero-mutation
mj_copyState2-Ply Glazier AI: In Pass & Play -> AI, the worker clones liveMjDatainto an isolated scratch buffer, optimizes extraction pull azimuth via Cross-Entropy Method (optimalPullAzimuthRad), and evaluates 2nd-ply adversarial top-course placements (twoPlyMasterScore01 = 0.763on unloaded blocks vs0.277on pinned bearing columns) with a real-time bind-and-release tactician reflex if a grabbed block binds (< 8 mmtravel at high tension). - Chaos-tested dual-transport Online Rooms: Five-character room codes (
?room=K7M4P) pair browsers directly over public WebRTCRTCDataChannel(< 4 KB0x564dbinary snapshots at30 Hz+ round-robin120-shard/packet cursor for1:1512-shard parity) with automatic<= 4.0 sICE stall or mid-drag disconnect failover to a Cloudflare Durable Object SQLite WebSocket relay — verified across a100-match network chaos simulator (8%drop +65%burst loss,120 ± 45 msjitter,< 2.0 mmGuest convergence) and a16-stage live two-browser hardware-WebGPU E2E harness.