loading...
Kernel profile: field of one blob vs distance (green line = iso level T, vertical = surface radius)
Merge test: field at the midpoint of two equal blobs vs separation D (crossing T at D_crit)
running...
The science
Metaballs are an implicit surface. Every blob i has a centre ci, an influence radius Ri and a strength si. The scalar field is a sum of kernels, and the visible skin is the iso-surface where the field equals a threshold T:
F(p) = Σi si · f(qi), qi = |p - ci|² / Ri² (f = 0 for q ≥ 1)
surface = { p : F(p) = T }
Kernels used here: Wyvill f = (1 - q)³ (smooth, compact support), quadratic f = (1 - q)², and a clipped Gaussian (Blinn) f = (e-4.5q - e-4.5)/(1 - e-4.5). Compact support means a blob only touches grid points inside its radius, which keeps the update cheap.
Size of one blob. Solve s f(r²/R²) = T. For Wyvill: r = R √(1 - (T/s)1/3). A blob exists only if T < s.
When do two blobs fuse? For two equal blobs the field along the line joining them has a saddle at the midpoint, Fmid = 2 s f((D/2)²/R²). The surfaces join exactly when Fmid = T, i.e. for Wyvill Dcrit = 2R √(1 - (T/2s)1/3). Below that distance the two spheres become one body with a neck. In Morse-theory language the topology of the iso-surface changes when the level crosses an index-1 critical point (a saddle) of F. The same arithmetic explains the volume bonus: where two fields overlap they add, so the merged body encloses more than the sum of the two isolated spheres.
Meshing. The field is sampled on a regular grid. Each grid cube is split into six tetrahedra (marching tetrahedra, a sibling of Lorensen and Cline's marching cubes that needs no 256-entry table and has no ambiguous faces). Where an edge changes sign, the vertex is placed by linear interpolation, t = (T - Fa)/(Fb - Fa). Vertices are shared between triangles. Normals are the exact analytic gradient, n = -∇F/|∇F|, ∇F = Σ s f'(q) 2 (p - c)/R², not a mesh estimate, which is why the skin looks smooth. Colour at a vertex is the field-weighted average of the blob colours.
The motion is a model, not fluid dynamics. Lava lamp: each blob has a temperature that rises near the heater and decays with height, and a buoyancy acceleration a = b (θ - 0.42) (a Boussinesq-style simplification of thermal expansion). Cohesion adds a = κ ∇Fothers, a toy surface-tension attraction: it pulls a blob up the field gradient of its neighbours. Drag, glass walls and an elastic floor complete the model. Real wax melts, deforms and conserves volume; metaballs do not. That mismatch is the honest limit of the technique: it is a modelling and graphics tool, not a solver.
Other ways to draw the same field. The identical F can be sphere-traced in a fragment shader (no mesh at all) or contoured in 2D with marching squares; the companion 2D lab shows the 2D version. History: Blinn 1982 (blobby molecules), Wyvill, McPheeters and Wyvill 1986 (soft objects).
Numerical checks (run in this page). (1) mean mesh radius of an isolated blob vs the closed-form solution; (2) enclosed volume and surface area of that mesh vs 4/3 πr³ and 4 πr²; (3) the number of connected bodies at 0.88 and 1.12 times the analytic Dcrit must be 1 and 2; (4) the analytic gradient vs a central difference. Expect small mesh errors of a fraction of a percent at the default cell size.