Exploring how compression waves propagate through a murmuration — the same physics that creates phantom traffic jams, adapted to birds.
Watch a real starling murmuration long enough and you'll see something that doesn't fit the standard boids model: waves. Bands of compression and expansion ripple through the flock, sometimes faster than the birds themselves are flying. The flock darkens in one region as birds compress together, then lightens as they spread apart — and the pattern travels. It looks less like a school of fish and more like a fluid with pressure waves running through it.
The classic boids rules — separation, alignment, cohesion — produce beautiful coordinated motion but not this behavior. Those rules change a bird's direction. They don't change its speed. And speed variation is what density waves are made of.
The clearest everyday example of a density wave is a phantom traffic jam — the kind that has no accident, no construction, no obvious cause. You're cruising at highway speed, the car ahead brakes slightly, you brake a little harder (because your reaction takes time and you want a safety margin), the driver behind you brakes harder still, and so on. The braking cascade propagates backward through traffic at 15–20 km/h even though every car is moving forward at 100 km/h.
The wave exists in the speed differences between successive agents, not in the agents themselves. No single car is "the jam" — each car brakes, then accelerates again as space opens up. The compression zone drifts backward through the flow like a pulse.
This is the same physics as a sound wave in air: molecules don't travel from speaker to listener, but each molecule bumps into its neighbor, which bumps into the next, propagating a compression front at the speed of sound. Fluid dynamicists call these longitudinal compression waves.
In both traffic and fluids, the wave either damps out or sustains itself depending on whether agents over-correct. If each driver brakes exactly the right amount and accelerates smoothly, the disturbance dies. But if drivers over-brake (applying more braking than strictly necessary) and then over-accelerate (gunning it when space opens), the oscillation feeds itself. Each correction overshoots, creating a new disturbance for the next agent. The wave doesn't just propagate — it regenerates.
The standard boids algorithm has no mechanism for speed variation. Separation steers birds away from crowded neighbors but doesn't slow them down. The minimum-speed clamp keeps every bird cruising at roughly the same velocity magnitude. There's no equivalent of "hitting the brakes."
Our extension adds exactly that: a speed-braking response to personal space violations. When a neighbor penetrates a bird's personal space bubble, the bird doesn't just steer away — it slows down, proportionally to how deep the penetration is.
For each bird in each frame, we find the neighbor most deeply inside the personal space radius. The penetration fraction is:
penetration = (personalSpace - distance) / personalSpace
At the bubble boundary, penetration is 0 (no braking). At distance zero, penetration is 1 (maximum braking). The bird's speed is then scaled down:
speed *= max(0.01, 1 - W_SPEED_SEP * penetration)
W_SPEED_SEP controls braking intensity. At 0, the
mechanism is off entirely and the simulation behaves exactly as before.
At 1.0, a fully penetrating neighbor cuts the bird's speed to near
zero. Values in between produce proportional braking.
Crucially, this braking is applied after the normal minimum-speed clamp. This means braking can push a bird below its usual stall speed — a temporary, reactive slowdown that the bird recovers from as space opens up. Without this, the min-speed clamp would immediately undo the braking, preventing any cascade.
When something comes too close, an animal's first reaction is to slow down and assess. This is distinct from the steering response (veer away) and operates on a faster timescale. A starling that suddenly finds a neighbor uncomfortably close would plausibly reduce speed before it has time to compute and execute a turn. The braking response is a reflex; the steering response is a decision.
This is exactly what happens in traffic, too. You brake before you change lanes. The speed reduction is immediate and local — each bird reacting only to what's in its personal space.
Once birds can brake, the cascade mechanism works just like traffic:
This is the classic traffic-jam wave: a compression front moving rearward. But murmurations show something traffic usually doesn't — waves that propagate forward, outrunning the flock. How?
The murmuration simulation already has a front bias parameter: birds weight neighbors ahead of them more heavily than neighbors behind when computing alignment and cohesion. This was originally added to create naturalistic leading-edge instability. But it has a critical secondary effect for wave propagation.
A bird with high front bias is paying close attention to what's happening ahead. If the bird in front slows down, our bird notices the closing gap quickly and brakes in response. The information that "something is slowing down up ahead" propagates backward efficiently.
But the front bias isn't absolute — birds also attend to neighbors behind them and to the side, just with less weight. This means a bird can also react to compression happening behind it. If birds to its rear are bunching up, the rearward neighbors start entering its personal space too. The bird brakes even though the disturbance originated behind it, and the wave propagates forward.
Real starlings almost certainly have some awareness of birds behind them — through peripheral vision, sound, or the pressure of air displaced by nearby wingbeats. They don't only react to what's ahead. This omnidirectional awareness is what allows murmuration waves to travel in any direction through the flock, not just rearward as in one-dimensional traffic.
In the simulation, the personal space bubble is spherical — it detects penetration from any direction. Combined with the alignment front bias (which determines how strongly a bird matches its neighbors' speed changes), this creates a medium through which compression waves can propagate forward, backward, and laterally. The flock becomes an acoustic medium, with density waves analogous to sound waves in air.
Density waves are invisible when all birds are the same color. The simulation provides two visualization modes to make them visible:
Each bird is colored by how many neighbors it has within a configurable radius: red for crowded regions, blue for sparse ones, with a smooth gradient through yellow and white in between. This shows where birds are compressed together and where they've spread apart — the spatial structure of a density wave.
The density is computed in a separate pass before any positions are updated, ensuring a consistent snapshot across all birds each frame.
Each bird is colored by how its speed is changing from one frame to the next: red for braking (speed decreasing), green for accelerating (speed increasing), and light blue for steady flight. This shows the dynamics of a wave — where the compression front is (birds braking) and where the expansion is (birds recovering speed).
The dV threshold slider controls sensitivity. Lower values reveal subtle speed changes; higher values only highlight dramatic braking and acceleration events.
Tip: Boid's eye view is especially effective for seeing velocity changes from a bird's perspective — you'll see neighbors ahead flash red as they brake, then green as they recover. Increasing Speed braking magnifies the effect.
The Density and Visualize tabs in the simulation's control bar group six controls specific to wave mechanics and visualization. The first two affect the simulation itself; the rest are purely visual.
How aggressively a bird slows down when a neighbor penetrates its personal space bubble. At 0 the mechanism is off entirely and the simulation behaves as classic boids. At 1.0, a fully penetrating neighbor cuts the bird's speed to near zero. This is the parameter that enables density waves — without it, birds change direction but not speed, and no compression cascade can form.
Sensitivity of velocity coloring. This is the speed change per frame that maps to fully saturated red (braking) or green (accelerating). Lower values reveal subtle speed variations; higher values filter out noise and only highlight dramatic events. This control has no effect on the simulation — it only changes how speed changes are rendered.
The radius (in world units) used to count neighbors for density coloring. A larger radius smooths the density map by averaging over more space; a smaller radius reveals finer-grained structure. This is independent of the topological neighbor counts used for steering — it exists only for the visualization.
The color scale endpoints for density coloring. A bird with the "sparse count" of neighbors (or fewer) within the search radius is colored full blue; a bird with the "dense count" (or more) is colored full red. Values in between are mapped smoothly through yellow and white. Adjusting these lets you tune the color range to the flock's actual density distribution — useful because different presets and bird counts produce very different neighbor counts.
Switches between uniform gray (no diagnostic coloring), density coloring (neighbor count → color), and velocity coloring (speed change → color). The legend bar at the bottom right updates to show the active mapping. Presets can include a preferred color mode — the Dense flock, velocity view preset defaults to velocity coloring since that's where wave dynamics are most visible.
The braking-cascade mechanism connects murmuration dynamics to several well-studied phenomena:
Phantom jams emerge from the same mechanism: agents react to neighbors with a slight over-correction, and the error compounds through the chain. The Nagel–Schreckenberg model (1992) and its descendants show that even a one-dimensional line of cars produces spontaneous stop-and-go waves when reaction includes randomness or over-braking. Our 3D flock is a higher-dimensional version of the same dynamics.
A flock with speed-braking behaves like a compressible gas. Dense regions have higher "pressure" (personal space violations cause braking), and that pressure propagates outward as waves. The speed of wave propagation depends on how quickly the braking response cascades — analogous to how the speed of sound in a gas depends on the stiffness of intermolecular interactions.
Flocks are a canonical example of active matter — collections of self-propelled agents that consume energy and are driven out of equilibrium. The density waves we observe belong to the same family as Toner–Tu waves in active fluids, where orientational order (alignment) couples to density fluctuations. The difference is that our agents have explicit behavioral rules rather than continuous-field equations, making the connection between individual decisions and collective phenomena visible and tunable.
The Density and Visualize tabs expose the key parameters. Here's a starting recipe for producing visible waves:
The personal space radius controls how far apart birds try to stay. In a dense flock, many birds are within each other's personal space, creating persistent low-level braking even without external perturbation. Increasing personal space with speed braking active amplifies the effect.
This is experimental work in progress. The speed-braking mechanism is the foundation — future extensions may include overshoot parameters (to control whether waves damp out or self-sustain) and deliberate perturbation injection (to seed waves for controlled experiments).
Running thousands of birds at interactive frame rates requires approximations. A few are worth knowing about because they can produce visible artifacts.
Neighbor lookups use a spatial hash grid that divides the world into cubic cells. Each bird checks the 3×3×3 block of cells around it. This is fast, but introduces a hard boundary: two birds that are close in space but straddle a cell boundary at the edge of the 3×3×3 block may see different neighbor sets. The steering forces and density counts for those birds will differ slightly, even though their local environments are nearly identical.
This can create faint grid-scale structures — density or velocity patterns whose spacing roughly matches the hash cell size. If the ground plane grid happens to align with the hash grid, the structures may be especially noticeable.
For performance, bird positions are updated sequentially within a single array. A bird processed early in the frame has already moved by the time a later bird reads its position as a neighbor. This creates a subtle ordering dependency: the "view" of the flock is inconsistent within a single frame, mixing pre-move and post-move positions.
The density and velocity visualizations avoid this by computing their metrics in a separate pass before any positions are updated. But the steering forces themselves still operate on the in-place data, so small wave-like artifacts from processing order can still appear in the motion.
The density visualization uses exponential smoothing to prevent frame-to-frame flicker. This introduces a tradeoff: heavy smoothing eliminates noise but causes colors to lag behind the flock's actual state — birds that leave a dense region will carry their "crowded" color for many frames. Light smoothing tracks reality more closely but allows high-frequency noise to show through as flashing.
The current implementation uses asymmetric smoothing: density drops are tracked quickly (a bird leaving a crowd changes color promptly) while density rises are smoothed more heavily (preventing momentary spikes from causing flashes). This is a compromise, not a perfect solution.
None of these artifacts invalidate the wave behavior — the compression cascades are real emergent dynamics. But they do add noise on top of the signal, and it's worth keeping that in mind when interpreting what you see.