Week 2. A chromatic glitch shader that runs on any DOM element.
The element is rasterized to a texture with SVG foreignObject, then a fullscreen
triangle samples it three times — once per color channel, each slightly offset. The offsets
drift slowly, so the headline slides in and out of registration like a misprinted page.
Thursday shader series · Week 2
RGB Split
One headline, three offset texture samples
🌈 RGB Split fragment shader
Red from one sample, green from the center, blue from a sample shifted the other way.
The offsets drift on slow sine waves, so the channels slide apart and back together —
print misregistration, no duplicated DOM.
Source element (plain DOM)
→
rgb-split.frag · live WebGL
How it works
Rasterize. The source element’s HTML (inline styles only, so it survives
serialization) goes into an SVG foreignObject, drawn to a 2D canvas at 2x. That canvas
becomes the WebGL texture. No screenshots, no html2canvas.
Split. The shader samples that texture three times: red from a sample shifted
one way, green from the center, blue from a sample shifted the other way. The offsets are two
slow sine waves, so the channels drift apart and back together on their own.
Respect motion. If prefers-reduced-motion is set, time freezes and
one composed frame renders. The pause button does the same on demand.