
Ship something
people remember.
A button that wakes up when you reach for it.
Bokeh
Out-of-focus lights drifting in depth, like a fast lens wide open at night.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
For your own build, add bokeh.js, ittybitty-shader.js, runtime.js and pointer.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="bokeh" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="bokeh" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { bokeh } from './bokeh.js';
const canvas = document.getElementById('bokeh');
const effect = bokeh(canvas, {
showBackground: true,
speed: 0.4,
drift: 0.3,
twinkle: 0.15,
aperture: 'circle',
density: 0.65,
size: 0.8,
focus: 0.15,
breathing: 0.4,
glow: 1,
fringe: 0.5,
catsEye: 0.5,
palette: [[0, '#ff9a2e'], [0.3, '#ffd36e'], [0.55, '#ffe6b8'], [0.8, '#ff4b2b'], [1, '#3d9bff']],
background: '#05060b',
interactive: true,
responsiveness: 0.5,
// Performance
dpr: 1.5,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
City lights seen through a fast lens wide open: each light is a disc the shape of the aperture, sized by its distance from the focal plane. Soap-bubble rims, faint onion rings, purple and green fringes either side of focus and cat’s-eye discs towards the corners give it a real lens’s character. The focus slowly breathes, lights that land in it shrink to pinpoints with tiny star flares, and the pointer pulls focus through the scene.
- Payload
- 10.3 KB brotli for bokeh.js, ittybitty-shader.js, runtime.js and pointer.js, measured at build time.
- Resolution
- Device pixel ratio capped at 1.5. Each light is drawn as one small sprite into a packed float buffer (32 bits a pixel), so a pixel only shades the lights that reach it.
- Frame rate
- Display rate.
- When unseen
- Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
- Reduced motion
- Shows a single still frame. Controls and the pointer still update it.
- 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.