force.pressure

Spread a 3D swarm evenly by pushing agents away from crowded cells of a density grid.

force.pressure(layout: VolumeSwarmLayout, cfg: {
    gridDim: number
    /** The grid covers shape-local [−domain, domain]³. */
    domain: number
    names: {clear: string; splat: string}
}): PressureForce

Import sim from shaders/std and use sim.agentForces.force.pressure.

Returns the force plus the two grid steps to put in the program before the update.

Parameters

NameTypeNotes
layoutVolumeSwarmLayout
cfg`{
gridDim: number
/** The grid covers shape-local [−domain, domain]³. */
domain: number
names: {clear: string; splat: string}

}` | |

Example

const pressure = force.pressure(simLayout, {gridDim: 32, domain: 1, names: {clear: 'swarmClearDensity', splat: 'swarmDensity'}})

Tip. Register pressure.clearKernel as a fixed step over pressure.cells and pressure.splatKernel over agents, both before the update.

See also

  • force.containment — Keep a 3D swarm inside a shape: a spring at the surface, a pull back from far away, and a drag when the shape rotates.
  • integrator.forces3d — A 3D swarm under summed forces, with drag, a speed limit and a position clamp.