
Rain
Rain on a pane of glass: beads, running drops and streaks, in water, blood, mud or any colour.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
The usage always matches the preview, layers and performance settings included. No build step or package.
Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add rain.js, ittybitty-shader.js, runtime.js, container.js, shape.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="rain" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="rain" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { rain } from './rain.js';
const canvas = document.getElementById('rain');
const effect = rain(canvas, {
showImage: true,
showDrops: true,
showFog: true,
image: '/examples/still-life.webp',
speed: 0.6,
amount: 0.6,
size: 1,
fog: 0.5,
refraction: 0.8,
liquid: 'water',
color: '#3a7bd5',
opacity: 0.6,
container: 'off',
outline: 'itty',
edgeLight: 0.6,
rim: 0.6,
gloss: 0.5,
innerShadow: 0.5,
// Performance
dpr: 2,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
Beads cling to the glass and act as tiny lenses, each showing the scene sharp and flipped while the dry glass is fogged; heavier drops run down in fits and starts, leaving clear wet streaks. The liquid filters light like stained glass, so blood reads deep red and mud reads brown. Transparent, it becomes rain on the page itself.
- Payload
- 9.0 KB brotli for rain.js and ittybitty-shader.js and runtime.js and container.js and shape.js and texture.js, measured at build time. See the method.
- Resolution
- Device pixel ratio capped at 2.
- 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 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.