StealThis .dev

Shader Gradient Background

A full-viewport animated gradient painted by a hand-written WebGL fragment shader — flowing fractal noise blends four palette colors in real time, with live controls for scheme, speed, grain and warp, plus a graceful CSS fallback when WebGL is unavailable.

Open in Lab
webgl vanilla-js
Targets: JS HTML

Code

Shader Gradient Background

A living gradient rendered entirely on the GPU. Instead of a static CSS linear-gradient, this component compiles a tiny vertex + fragment shader pair with raw WebGL, draws a single full-screen triangle, and drives an animated fractal-Brownian-motion noise field from a u_time uniform ticked by requestAnimationFrame. The noise warps and folds four palette colors into a smooth, endlessly flowing field that never repeats.

The floating control panel is fully interactive: switch between five curated color schemes, scrub animation speed, add filmic grain, and dial the domain-warp intensity — every slider feeds a uniform the shader reads each frame, so changes are instant. A pause toggle freezes time, and the panel can be collapsed to admire the background. The canvas is resize-aware via ResizeObserver and respects devicePixelRatio for crisp rendering on retina displays.

This demonstrates the low-level WebGL rendering pipeline — shader compilation, uniform plumbing, and a rAF render loop — while degrading gracefully: if getContext("webgl") fails, an animated CSS gradient stands in and the panel reports the fallback. Controls are keyboard-operable with visible focus rings, and animation honours prefers-reduced-motion.