Particle advection

Quoting wikipedia: "advection is the transport of a substance by bulk motion". Imagine a leaf floating on the surface of a river: wherever the river flow goes, there goes the leaf too. In this case, the leaf is being advected (carried) by the river.

In Obi Fluid, fluid particles can be used to advect regular Unity particles. Since regular particles do not perform any expensive simulation themselves (they are passively carried by the fluid), you can have many more Unity particles than fluid particles. This is useful to simulate foam, bubbles, smoke, or add interesting internal details to a simulation.

Still, advection can be expensive if the amount of advected particles is very large, or if the CPU you're targeting has few hardware threads.

Setup

To perform advection on a Unity particle system, simply add a ParticleAdvector component to it. This component only needs a reference to the ObiSolver in charge of simulating the fluid.

Once you've got a shuriken Unity particle system set up for advection, you need to make sure that the particles it emits are spatially close to the fluid particles. If they are not, the particles will just sit in there motionless because they aren't near the fluid flow and thus cannot be carried by it. Let's see an example (included in the /Obi/SampleScenes folder: FluidKarmanVortex.unity):

Edge-shaped 2D fluid emitter
Regular Unity particle system, placed on top of the fluid emitter. This way particles will be close enough to the fluid for it to advect them.

How it works

Every frame, for each Unity particle, Obi determines all fluid particles closer to it than the solver's advection radius. Then it sets the particle velocity to the weighted average of all neighbor fluid particles. Fluid particles that are closer get higher weights, so they influence the final advection velocity more than particles further away.

The white spheres are fluid particles. The red dots are regular particles being advected trough the fluid.

Foam generation

Obi includes a helper component that will automatically emit Unity particles near fluid particles that meet a certain condition. This makes it easy to simulate foam or bubbles. To use it, simply add a ObiFoamGenerator component to any ObiEmitter.

Note that the FoamGenerator simply decides where to emit new regular particles. Advection is still performed by the ParticleAdvector component, so you need both in order to simulate foam.

Emission rate

Maximum amount of foam particles that can be emitted per second.

Randomness

Amount of jitter used when spawning foam particles near a fluid particle. A value of zero will spawn foam particles directly on top of fluid particles. Use small values for a realistic look.

Vorticity threshold

Minimum fluid vorticity that can cause a foam particle to be emitted. Foam generally appears where particles have high rotational motion, so you can use this parameter to control how much vorticity is needed for foam to appear.

Density threshold

Maximum fluid density that can cause a foam particle to be emitted. Foam generally appears near the surface of the fluid, where density is lower. You can use this parameter to control how light the fluid needs to be for foam to appear.

Advector

The ParticleAdvector used to advect the foam particles.