HomeArticlesRendering

The Lava Lamp: Convection, Surface Tension and Metaball Rendering

Colourful wax blobs rise, merge and sink, driven by heat and buoyancy - and how real-time GLSL metaballs fake the same gooey merging on screen.

mysimulator teamUpdated June 2026≈ 7 min read▶ Open the simulation

Two liquids, one density trick

A real lava lamp holds two liquids that do not mix, most commonly a wax-based compound and a clear water-and-solvent mixture, chosen so that at room temperature the wax is very slightly denser than the surrounding liquid and sits as a solid lump at the bottom. The trick that makes the whole thing work is that the wax's density changes with temperature faster than the surrounding liquid's does, so a modest amount of heating is enough to flip which one is denser.

live demo · blobs rising, merging and sinking● LIVE

The convection cycle: buoyancy meets thermal expansion

A bulb or heating element in the base warms the wax sitting closest to it. Like almost all materials, the wax expands as it warms, which lowers its density, and once it becomes less dense than the liquid around it, buoyancy carries it upward as a rising blob. Away from the heat source near the top of the lamp it gradually cools, contracts, becomes denser again, and sinks back down to the base to be reheated - a self-sustaining loop known as thermal convection, the same basic mechanism that drives weather patterns in the atmosphere and mantle convection beneath the Earth's crust, just running on a much smaller, gentler scale.

Why the blobs stay round instead of dissolving

The wax and the surrounding liquid are chemically immiscible - they simply do not dissolve into each other, the same relationship oil has with water. At the boundary between the two liquids, surface tension acts like a stretched elastic skin trying to minimise the interface area, which is why a floating blob of wax pulls itself into a smooth, rounded shape rather than spreading into a thin film. When two blobs collide, that same surface tension is what lets them merge into one larger blob rather than bouncing apart, briefly forming a thin connecting neck that widens as the merger completes.

Metaballs: rendering blobs that merge smoothly

Simulating the full fluid dynamics of two immiscible liquids in real time, tracking every droplet's exact boundary, is expensive. A cheaper and visually convincing trick borrowed from computer graphics is the metaball: instead of a rigid mesh, each blob is represented as a smooth scalar field that peaks at its centre and fades with distance, and the visible surface is drawn wherever the sum of every nearby blob's field crosses a fixed threshold.

field(p) = sum over all blobs i of  radius_i^2 / dot(p - center_i, p - center_i)
surface  = { p : field(p) >= threshold }     // drawn per-pixel in the fragment shader

Because the fields blend additively, two metaballs approaching each other cause their combined field to rise between them before their visible surfaces even touch, so the rendered shape stretches into a connecting bridge and merges smoothly - visually identical to the real surface-tension merger, achieved with a per-pixel field evaluation in a GLSL fragment shader instead of an actual fluid solver.

Frequently asked questions

Why does the wax in a lava lamp rise and fall instead of just sitting at the bottom?

The bulb at the base heats the wax, which expands and becomes less dense than the surrounding cooler liquid, so buoyancy pushes it upward. Away from the bulb it cools back down, contracts, becomes denser again, and sinks back to the bottom to be reheated. This slow thermal cycle, not any pump or moving part, is what drives the wax up and down continuously while the lamp is on.

Why doesn't the wax mix with the surrounding liquid?

The wax and the liquid are chosen to be chemically immiscible, meaning they do not dissolve into one another no matter how much they touch, similar to oil and water. Surface tension at their boundary pulls each blob into a compact shape that minimises its surface area, which is why the wax forms rounded blobs rather than dispersing into the liquid around it.

What are metaballs and why are they used to render this effect?

Metaballs are a rendering technique where each blob is represented not as a fixed mesh but as a mathematical field that fades with distance from a centre point; wherever the summed field from all nearby blobs crosses a threshold, that surface is drawn. Because the fields blend smoothly, two metaballs that approach each other naturally stretch and merge into one continuous shape instead of colliding as separate rigid objects, which is exactly the organic, gooey look real wax blobs have when they touch.

Try it live

Everything above runs in your browser - open Lava Lamp and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Lava Lamp simulation

What did you find?

Add reproduction steps (optional)