Torn Paper shader preview: Any image, or the layers beneath, torn open along a ragged edge.
ittybitty

Torn Paper

Any image, or the layers beneath, torn open along a ragged edge.

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

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

<script type="module">
  import { tornPaper } from './torn-paper.js';

  const canvas = document.getElementById('torn-paper');
  const effect = tornPaper(canvas, {
    showUnder: true,
    showShadow: true,
    showFibres: true,
    image: '/examples/still-life.webp',
    tear: 'split',
    open: 0.35,
    jag: 0.6,
    angle: 8,
    core: 0.6,
    seed: 1,
    interactive: true,
    responsiveness: 0.5,
    under: '#1f2a33',
    paper: '#faf7f0',
    // Performance
    dpr: 2,
    adaptive: true,
  });

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

Details

A tear ragged at every scale, where the printed skin comes away from the white core of the paper: one side of the tear keeps a wide, fibrous band of white, the other a sliver, fringed with loose fibres. The pieces lift and cast soft shadows onto what they reveal. Torn in two, a hole torn through the middle that follows the pointer, or a strip ripped off the top.

Payload
7.5 KB brotli for torn-paper.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 at rest; redraws while the pointer moves the hole.
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 only redraws when a setting changes or the pointer moves the hole.
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.