All effects

next = (Σ neighbours) / 2 − previous

Water ripples.

late '90s to today

Touch the screen and rings spread out, bounce off the edges and bend the tiles below, without a single sine. A filter over two arrays of numbers that seems to work like voodoo, as Hugo Elias put it, and nobody quite knows who found it first.

PCGPU

How it works

The algorithm

Keep two height maps: the current frame and the previous one. For every cell, the new height is half the sum of its four neighbours minus its own previous height, multiplied by a damping just below one. That small formula is a discrete wave equation, so ripples propagate, reflect off walls and interfere. To draw, offset each pixel's lookup into a background image by the local height slope, refraction, and brighten slopes that face the light.

The old-hardware trick

Integers, additions and a shift: the update needs no sines, no tables and no list of ripples, so a thousand drops cost the same as one. Swapping the two buffers instead of copying them halves the memory traffic.

Per frame, in pseudo-code
damping = 0.97
for y, x in inner cells:
  next[y][x] = ( cur[y][x−1] + cur[y][x+1]
               + cur[y−1][x] + cur[y+1][x] ) / 2
             − next[y][x]                // previous frame
  next[y][x] ·= damping
swap(cur, next)

dx = cur[y][x−1] − cur[y][x+1]
pixel = floor_image[y + dy/8][x + dx/8] · (1 + dx·k)

Timeline

Documented milestones, with a source for each. Famous examples, not claims of who did it first.

  1. late '90sPC

    ‘2D Water’

    Hugo Elias · CPU tutorial

    Elias explains a ripple program he had seen with its source included, two integer arrays and a filter, inventor unknown. A reader later recalled finding the page around 1998.

    Source
  2. 1999PC

    The flipCode water contest

    Alex Champandard · flipCode · PC · 3D hardware

    A contest entry already calls the blur-sharpen filter ‘famous’, and picks a sum of sines instead because the filter's result depends on frame rate.

    Source
  3. 2008PC

    Ripples in Silverlight

    Nikola · Microsoft developer blog · Silverlight

    Credits Elias and implements integer height buffers, damping and fast image generation inside a browser plug-in.

    Source
  4. 2010PC

    HTML5 water ripples

    Jonas Wagner · Browser · HTML5 canvas

    Inspired by a mr.doob wave-propagation demo: a pond in plain JavaScript that ripples under the mouse, refracted by offsetting texture lookups by the height difference.

    Source
  5. 2011GPU

    WebGL Water

    Evan Wallace · Browser · WebGL

    A GPU height-field simulation you draw on, with a draggable sphere, raytraced reflections and refractions, soft shadows and caustics, on floating-point textures.

    Source

Over time

4 live versions, from the oldest platform to today: 2 on the CPU, 2 on the GPU. Retro versions run at their original resolution and palette. Demos pause when off screen.

PC · VGA · 320×200

Refracting ripples

late '90s

Rain and a wandering stirrer disturb two integer buffers; the slopes bend a tiled floor with an inlay, quantised to the VGA's 18-bit colour.

PCCPUtwo buffersrefraction
Detail page
Browser · canvas

Touch the water

2010

The same simulation, now yours: move the pointer or swipe a finger sideways across the pool and watch the rings reflect off the edges and cross each other.

PCCPUinteractivewave equation
Detail page
GPU · GLSL

Analytic rain

1999 idea

Champandard's alternative: a sum of decaying ring waves, frame-rate independent, evaluated per pixel with refraction, Fresnel and a sun glint.

GPUGPUsum of sinesFresnel
Detail page
GPU · GLSL

Caustics

2011

Light bent by the moving surface bunches up into bright, shifting patches on the pool floor: where neighbouring refracted rays converge, the floor glows.

GPUGPUcausticsrefraction
Detail page