Backgrounds

Rainglass

Rain on a window with a city somewhere behind it. There is no scene being blurred — the backdrop is built out of focus to begin with, so the drops have something to bend without a render target or a blur pass anywhere in the frame. Each drop is a pure function of time inside its own grid cell, which is why a thousand of them cost the same as one and a resize cannot lose the rain. They descend the way water actually does: holding by surface tension, breaking loose, running fast, stopping again — and the trail exists only above the drop that made it.

Install

bun add ogl

Then copy 2 files into your project:

  • components/registry/rainglass/rainglass.tsx
  • hooks/use-animation-loop.ts

Props

PropTypeDefaultDescription
intensitynumber0.55How much water is on the glass. Cells are gated by this rather than dimmed by it — a cell either has a drop in it or it does not, because a half-present drop reads as a smudge on the screen rather than as weather.
dropScalenumber1Drop size, by way of the grid the drops live in. Large drops means fewer, heavier runs and a window you are standing close to; small means a fine spatter that reads as distance.
speednumber1How often a drop breaks loose, and how fast it runs once it has. Because the descent is a held stair rather than a fall, raising this shortens the holds as much as it quickens the slips.
wandernumber0.5How far a running drop drifts sideways as it goes. At zero they run dead straight down, which is the one thing real water on glass never does.
refractionnumber0.6How hard each droplet bends the city behind it. The offset points out of the droplet's own centre, so this magnifies rather than smears — turn it off and the drops flatten into stickers on the glass.
fognumber0.5Condensation film over the whole pane. It is removed by what the water has touched rather than drawn between the drops, so a trail is a clean stripe cut through the fog instead of a shape sitting on top of it.
layersnumber2Depth planes of rain, each smaller and refracting less than the one in front. Two is enough to read as depth; the third is texture and costs a full extra evaluation of the drop field per pixel.
blurnumber0.65How far out of focus the city is. This grows the bokeh discs rather than running a kernel over a rendered scene — there is nothing sharp behind the glass to soften, which is the whole reason this stays a single pass.
tintTopstring (hex)"#241436"Sky, at the top of the frame.
tintBottomstring (hex)"#0b0b12"Ground, at the bottom.
glowstring (hex)"#a855f7"The out-of-focus lights, and the highlight that catches on a wet edge.

What It Demonstrates

Loop
An animation that repeats, a set number of times or infinitely.
Idle animation
Subtle motion that plays while an element is just sitting there, waiting to be interacted with.
Blur
A blur filter used to soften an element or mask tiny imperfections.
Hardware acceleration
Animating transform and opacity lets the GPU keep motion smooth.
Compositing
Letting the GPU move or fade an element on its own layer without redoing layout or paint.

Related Components

Appears In