Decode shader preview: Any image, or the layers beneath, resolving from big squares into focus.
ittybitty

Decode

Any image, or the layers beneath, resolving from big squares into focus.

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 decode.js, ittybitty-shader.js, runtime.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="decode" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>

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

<script type="module">
  import { decode } from './decode.js';

  const canvas = document.getElementById('decode');
  const effect = decode(canvas, {
    showGaps: false,
    showFlash: true,
    showFinal: true,
    image: '/examples/still-life.webp',
    style: 'raw',
    levels: 4,
    dot: 0,
    palette: [[0, '#16131f'], [1, '#f2ede2']],
    start: 128,
    duration: 2.4,
    easing: 'linear',
    loop: 'restart',
    hold: 1.5,
    smart: 0.7,
    scatter: 0.4,
    interactive: true,
    // Performance
    dpr: 2,
    adaptive: true,
  });

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

Details

The picture arrives as a few big squares, and each splits into four, then four again, until it is sharp, like a progressive image over a slow line. Squares with detail split first and flat areas stay chunky longer, so the shapes appear before the sky. Show the squares in the picture’s own colour, flat tones or dithered tones, ease it how you like, and loop it or play it once. Clicking replays it.

Payload
7.1 KB brotli for decode.js and ittybitty-shader.js and runtime.js and texture.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 2.
Frame rate
Display rate while decoding.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Shows the sharp picture.
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.