Stained Glass shader preview: Turns any image into a stained-glass window of rich panes and dark lead.
ittybitty

Stained Glass

Turns any image into a stained-glass window of rich panes and dark lead.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add stained-glass.js, ittybitty-shader.js, runtime.js, pointer.js, texture.js next to this page. Highlighted values follow the controls.

<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="stained-glass" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="stained-glass" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>

<script type="module">
  import { stainedGlass } from './stained-glass.js';

  const canvas = document.getElementById('stained-glass');
  const effect = stainedGlass(canvas, {
    showGlass: true,
    showLead: true,
    image: '/examples/still-life.webp',
    panes: 0.5,
    lead: 0.5,
    saturation: 1.4,
    mottle: 0.5,
    glow: 0.6,
    interactive: true,
    responsiveness: 0.5,
    came: '#1a1714',
    // Performance
    dpr: 2,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

The picture is cut into panes, each one flat, rich colour with the mottling of real cathedral glass, and pale areas become antique amber, straw, blue and sage. Lead came runs between the panes and along the outlines of the picture. Light glows through strongest where the sun would fall; the pointer moves the light.

Payload
7.0 KB brotli for stained-glass.js and ittybitty-shader.js and runtime.js and pointer.js and texture.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 2.
Frame rate
None. One frame per change.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Nothing to change: it never moves.
Layers
Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
Browsers
Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
Licence
MIT. Copy it, change it, ship it.