gridSim

A field of cells advanced every frame by an ordered list of stages.

gridSim(build: (params: GpuFragmentParams, root: GridRoot) => GridSimConfig | null): {compute: GpuComputeNode}

Import sim from shaders/std and use sim.grids.gridSim.

Spread it into a definition next to a gpu.fragment that samples one of its outputs.

The build callback runs once per instance of the layer, with the GPU device, and returns the outputs, the frame-delta clamp and the stages. Return null to run nothing (a required child is missing). Without a GPU the fragment should fall back to the child or to transparent.

Parameters

NameTypeNotes
build(params: GpuFragmentParams, root: GridRoot) => GridSimConfig | null

Example

...gridSim((params, root) => ({outputs: {state}, clampDt: 0.05, stages: [op.values('write', (f) => paramsU.write({dt: f.dt, radius: f.num('radius', 0.4)})), op.pass(update), op.publish(() => output)]}))

Tip. Everything created in the build callback (buffers, passes, trackers) belongs to that layer instance. Create nothing at module scope that holds per-frame state.

See also

  • op — The stages a grid frame is built from.
  • hostGridProgram — A frame program for a small grid stepped in plain JavaScript: the steps run in order every frame until one returns 'skip'.
  • simulate — Declare a simulation the engine runs for you.
  • fluidSim — A fluid the engine solves every frame.
  • feedbackSim — A simulation that advances a picture of its own last frame by one step of your rule, every frame.

Used by

GridDistortion, Liquify, PixelSort, ReactionDiffusion