Paper shader preview: A real sheet of paper: folded, crumpled, aged, with the print bending along with it.
ittybitty

Paper

A real sheet of paper: folded, crumpled, aged, with the print bending along with it.

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

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

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

  const canvas = document.getElementById('paper');
  const effect = paper(canvas, {
    showSheet: true,
    showFibres: true,
    showFolds: true,
    showCrumple: true,
    showAge: false,
    image: '/examples/still-life.webp',
    stock: 'cold',
    texture: 0.5,
    scale: 1,
    folds: 0.5,
    layout: 'letter',
    crumple: 0.3,
    creases: 2.5,
    age: 0.5,
    distortion: 0.6,
    light: 135,
    seed: 1,
    interactive: true,
    responsiveness: 0.5,
    colour: '#f7f4ee',
    shadow: '#b9b3a8',
    // Performance
    dpr: 2,
    adaptive: true,
  });

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

Details

Built as a surface, not laid over the top as a filter. One height field holds the tooth of the stock, folds alternating valley and mountain, and a crumple of flat facets from a few broad ones to fine wrinkles. From it come the light, shading in the paper’s own shadow colour; the print, bending and kinking at every crease; and the sheet itself, cut to its picture and lying on the page with deckled edges and a soft shadow. Five stocks from hot-pressed to kraft, fibres, and age with foxing and a cup ring. Static: one draw per change, or while the pointer moves the light.

Payload
10.8 KB brotli for 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 light.
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 light.
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.