Journal
Nov 28, 2026·3 min read· WebGL

Wiping fog off a WebGL window

The first thing you meet on this site is a window fogged over by rain. Move the pointer and the fog clears where your hand has been, then slowly creeps back. It looks like one effect. It is three small passes.

Pass one: remember where the hand went

A render target holds a single value per pixel: how clear the glass is there. Every frame a shader reads the previous frame of that target, adds a soft stroke between the last pointer position and the current one, and fades everything a little toward "fogged". Two targets swap roles each frame, because a shader cannot read and write the same texture.

Drawing a stroke between two positions instead of a dot at one matters. A fast hand leaves gaps otherwise.

Pass two: blur the scene once

The city behind the glass is painted to a canvas and blurred into a second texture ahead of time. Fog is then just a mix between the sharp picture and the blurred one. Blurring live, every frame, would cost far more and look the same.

Pass three: put it together

The final shader mixes sharp and blurred by the mask, adds a little light where the glass is fogged, and bends the picture slightly under each raindrop using a normal map drawn from the rain simulation.

What I would tell myself earlier

  • Keep the mask at half resolution. Nobody can see the difference and it halves the work.
  • Stop drawing when the pane is off screen. Mine kept rendering while the visitor was at the contact form, and phones noticed.
  • Fade by time, not by frame, so a 120 Hz screen does not heal twice as fast.