particles

Thousands of moving points drawn into a texture, read by name in WGSL.

particles(opts: Parameters<typeof particlesInput>[0]): ParticlesInput

Import simulate from shaders/std and use simulate.particles.

  • count (number or prop) up to max; mobile: {max} caps it on phones. - forces: data, e.g. [{gravity: 0.3}, {drag: 0.5}, {cursor: 1}, {wind: 0.4}]. Every strength (and radius, scale) takes a number or a prop, {spring: p('pull')}, read live, so sliders drive the physics. Forces: gravity, drag (settling), spring (back to the spawn point), cursor (pushed from the pointer while one is over the canvas), wander (each particle jiggles on its own), wind (a shared flow), vortex, orbit, separate. - spawn: 'scatter' (default), 'ring', 'edge', 'atPointer', {fromShape: source} (a texture's opaque area, e.g. samplePoints or a layer prop), or a WGSL body returning a Particle (it sees index and rand: vec4f). - step: WGSL run per particle per frame with var p: Particle in scope (and index, rand). Forces are applied before it; position integrates after it. - lifetime: {seconds, jitter} respawns particles as they age out. - draw: WGSL returning Point(pos, sizePx, color) per particle (it sees p and index). Without a state (no spawn, step or forces) it sees only index: the formula-driven mode. - splat: 'point' (1 px) or 'soft' (a round footprint size pixels wide). - neighbors: {radius} lets step read crowd(p) and crowdSlope(p): how crowded a spot is.

Parameters

NameTypeNotes
optsParameters<typeof particlesInput>[0]

Example

inputs: {
  motes: simulate.particles({count: 20000, forces: [{wind: 0.4}, {cursor: 1}, {drag: 0.6}], lifetime: {seconds: 6, jitter: 0.5}, splat: 'soft'}),
},
paint: wgsl`return motes(uv);`,