shadertown

Canvas animation that keeps the page smooth

A canvas background animation is a <canvas>, a requestAnimationFrame loop, and arithmetic. These use the same element and drop the middle part: the loop runs on the GPU, and the arithmetic is a shader.

The same element, a different context

Everything here draws into an ordinary canvas — it asks it for a webgpu context rather than a 2d one. So the element sizes, positions and stacks exactly as any html canvas background animation does, and the surrounding CSS does not have to know the difference.

Where the per-frame work goes

A 2D canvas animation computes each frame in JavaScript and issues draw calls for it, which puts the frame budget on the main thread — the same thread as your page. A shader is handed to the GPU once and evaluated there, per pixel, so the JavaScript per frame is a handful of uniforms. The main thread stays free.

What you write

One component in React, or a call to the renderer in Svelte, Solid, Astro or plain HTML. It starts drawing when the element is on screen and stops when it leaves, holds a still frame for readers who ask for reduced motion, and caps resolution and frame rate where you tell it to.

Background.tsx
import { ShaderCanvas } from "shadertown/react";

export function Background() {
  return <ShaderCanvas shader="flow" play="visible" />;
}

Swap the loop out

Same canvas, same layout, no per-frame JavaScript. Every shader tunes free in the browser.