Home

Procedural Milk Stream

Project:
Farsight
Year:
2026
Type:
Procedural mesh
Tech:
Unity, C#, HLSL
Milk pouring into a cereal bowl, with the wireframe switching on
The wireframe switches on mid-pour to show the stream mesh.

The goal

There's a breakfast scene where you pour your own milk and cereal. My first version of the pour was a particle effect, and it looked like one: a spray of dots, not a stream of milk.

I wanted it to feel like actual liquid. One stream that falls in a nice arc, glugs as you tip the carton, breaks up into drops when you stop, and makes ripples where it lands.

How it works

The stream is one tube mesh that gets rebuilt in code every frame, 10 sides around and 48 segments long. That's about 570 vertices, so rebuilding it every frame costs almost nothing. A separate script on the bowl and a shader on the milk handle everything happening on the surface.

1. The arc

The tube follows the path a thrown object would take, from the carton's spout down to the milk, worked out from the pour speed and gravity. Each segment is a ring of vertices placed along that curve.

The width follows the milk's speed. Falling liquid speeds up, and the same amount of milk moving faster has to get thinner, so the radius shrinks with the square root of the speed, down to 45% of the spout. Every glug from the carton sends a slight bulge down the stream with the milk.

// speed0: the reference speed at the spout
// ArcVelocity(t): its velocity t seconds after leaving
// minRadiusScale: 0.45, the thinnest the stream is allowed to get
float radius = spoutRadius * Mathf.Max(Mathf.Sqrt(speed0 / ArcVelocity(t).magnitude), minRadiusScale);
// time - t: the moment this ring's milk left the spout
radius *= 1f + glugAmount * Glug(time - t);

Here t is how long ago a ring's milk left the spout, so time - t is the moment it left. Each ring carries whatever the glug was doing at that moment, which is why the bulge travels down at the milk's speed with no extra work.

Side view of the stream with its mesh rings
The stream at real scale, with its rings.
The stream straightened out at five moments, with a bulge travelling from the spout to the surface
The stream straightened out at five moments, 50 ms apart. A glug starts at the spout and rides down. The bulge is exaggerated 3x here so you can see it.
The milk stream as it appears in gameThe milk stream with its wireframe visible
The stream in game, and its mesh.

2. Stopping

Milk that's already in the air has left the carton, so when you stop pouring the arc locks in place and the end of the stream doesn't swing around with the carton. The tail then falls, and the last 5 cm of it pinches into beads about 8 mm apart. A real stream of liquid breaks up the same way; it's called the Plateau–Rayleigh instability. Here it's faked with a sine along the stream's length, and the rings are packed towards the tail so the beads have enough geometry.

The end of the stream breaking into beads over four moments
The tail of the stream after you stop pouring, zoomed in.

3. The surface

Where the stream lands it starts ripple rings and foam. Each ring is worked out in the milk shader: a wave that travels outwards at 9 cm a second, with a 1.6 cm wavelength. The rings only change the lighting; the surface itself stays flat. Each one fades out in about a second. Up to eight can run at once, and a ninth replaces the oldest. They're sent per bowl (a MaterialPropertyBlock), so other bowls using the same material don't ripple too.

The foam is bright specks that drift outwards within about 6 cm of where the stream lands, and fade once the pour stops.

Top view of the milk surface with several overlapping ripple rings
Four rings of different ages, from the shader's ripple function.

The milk itself is a disc that scales up as the bowl fills. The bowl isn't a cylinder, so the script measures the bowl's inner wall at the milk's height and the shader cuts the disc to fit.

Cereal makes its own ripples when it drops in. About a third of the pieces float: they rise with the milk by at most 8 mm and bob by about a millimetre.

Ripples and foam where the stream landsCereal floating in the milk
Ripples and foam where the stream lands, and cereal floating in the milk.

The diagrams on this page were rendered with a Python port of the stream and ripple code. The clip at the top is from the game.