The general concept relies on approximating the liquid's behavior by calculating its surface normal using a physics simulation, and accumulating the change of this normal (disturbance) into a foam density variable.
We feed this information as parameters into the material, which calculates the various features at each pixel:
- Depth under the "virtual" surface of the liquid.
- Opacity and liquid/container masks
- Normals (for reflection/refraction)
- Foam UVs
- Liquid thickness for light transmittance
- Opacity and liquid/container masks
- Normals (for reflection/refraction)
- Foam UVs
- Liquid thickness for light transmittance

Debug views: physics simulation (left) and liquid depth under surface (right)

More Debug Views. Left to Right: Flat liquid, World Normals, Liquid with Foam, Foam UVs

Fundamental Variables

Frontside/Backside liquid depth

Reflection/Refraction to Emissive
Key features of the liquid material

Foam UVs are spherically projected from a point along the normal, under the virtual surface