// CONTROLLED DECAY
VORONOI STRESS PROPAGATION
The lattice above is a Voronoi diagram — the mathematical dual of a Delaunay triangulation. Every point on the screen belongs to the nearest cell center. When you drag fast, you fracture the lattice. When you hold still, you crystallize it. The state persists between gestures in a ping-pong framebuffer.
FRACTURE MECHANICS
The simulation shader accumulates fracture state in four channels: R and G store
the fracture displacement vector (direction the material tore), B stores fracture
intensity (total accumulated stress), A stores heal state (crystallization energy).
Mouse velocity is the fracture driver — fast movement creates directional tears
scaled by speed * zone * 6.0.
Stress propagation happens through neighbor averaging. Each pixel samples its four cardinal neighbors and mixes toward their fracture values at 0.8% per frame for displacement, 0.5% for intensity, 0.3% for heal. This creates spreading cracks that radiate outward from the impact point, with each quantity propagating at a different speed — fast tears, slower stress buildup, slowest crystallization.
The display shader renders a Voronoi diagram that responds to the fracture state. The standard Voronoi algorithm finds the nearest and second-nearest cell centers for each pixel — the difference between these distances defines the crystal edge. Cell centers animate slowly with time, creating a living lattice even at rest.
The critical visual technique is per-channel UV warping. Instead of one Voronoi lookup, the shader computes three — one for red, green, and blue — each displaced differently by the fracture vector. This creates chromatic aberration that follows the crack direction. When fracture intensity is zero, all three channels align and you see clean crystal edges. Under stress, they separate into the RGB tear that defines the glitch aesthetic.
// VISUAL PIPELINE
VORONOI LATTICE
3x3 neighbor search for nearest cell center. Hash function maps grid coordinates to pseudo-random cell positions. Returns distance-to-nearest, distance-to-second, and cell ID for interior shading. Scale: 6 cells across screen width.
CHROMATIC SPLIT
Three separate Voronoi lookups with UV offsets derived from the fracture vector.
Red channel shifts along fracture direction, blue shifts opposite plus perpendicular.
Green stays centered. Shift magnitude: fracMag * 0.03. The split IS the fracture.
EDGE DETECTION
Crystal edges defined by d2 - d1 — the gap between nearest and second-nearest
Voronoi distances. Edge thickness widens with fracture intensity. Edge color shifts
from cool blue-white (pristine) to hot magenta (stressed).
SCANLINE CORRUPTION
Horizontal scanlines modulate brightness based on fracture intensity. Simulates CRT display degradation under signal interference. Per-channel attenuation: red full, green 70%, blue 50% — unequal degradation for analog authenticity.
BLOCK GLITCH
When intensity exceeds 0.3, quantized 8-pixel horizontal blocks displace randomly. A hash function per block row, floored by time, determines which rows glitch. Only 8% of rows affected per frame — the rarity makes the glitch feel real.
HEAL CRYSTALLIZE
Stillness accumulates heal energy. High heal regions spawn a second Voronoi pass at 18x scale — fine crystal facets that overlay the base lattice. Color: ice blue. The crystal grows where you rest, shatters where you strike.
THE DUAL GESTURE
Most interactive shaders have one mode: move = effect. This one has two opposing forces. Fast movement fractures — it accumulates directional stress that tears the Voronoi lattice apart, separating the RGB channels into a glitch aesthetic. The faster you move, the deeper the chromatic split, the wider the scanlines, the more blocks corrupt.
But stillness heals. Hold the cursor still within the influence zone and heal energy accumulates. The fine-grained crystal overlay grows, ice-blue facets emerge from the damage, and the fracture displacement decays toward zero. The two forces create a tension: you can't have maximum fracture and maximum crystal simultaneously. Every gesture is a choice between destruction and repair.
The decay rates encode this tension mathematically. Fracture displacement decays at 0.996 per frame — about 4 seconds to half-life. Intensity at 0.994. Heal at 0.998 — slower decay means crystallization persists longer than fracture. Over time, if you stop interacting, the heal state outlasts the damage. The system's equilibrium is restoration, not destruction. You have to keep breaking it to keep it broken.
The Voronoi diagram itself is the perfect structure for this. In materials science, Voronoi tessellation models grain boundaries in polycrystalline metals. Fracture propagates along grain boundaries — exactly what happens visually when the edge colors shift from blue to magenta under stress. The math produces the metaphor without forcing it.