grid

A grid of vec4f cells advanced once per frame by step, with named outputs in derive.

grid(config: GridSimInit): GridSim & InputNode

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

Read the grid in WGSL as name(uv) (bilinear between cell centres) and an output as name.output(uv).

  • resolution: cells per side of a square grid, or [width, height] (it does not follow the frame's shape: give [w, h] in the frame's proportions). Its cost is fixed, whatever the canvas size. - history: 2 lets steps read last frame's state with readPrev (a wave, or Verlet motion). - precision: 'full' stores 32-bit cells, for positions and anything that moves by tiny amounts. - init seeds every cell once: a WGSL body returning vec4f that sees cell, cellUV (the cell's centre, 0–1), gridSize, props, helpers and library functions. - step runs in order every frame: op.* steps and your own op.kernel bodies. A kernel reads the grid (read, readPrev, readLinear), the built-ins (dt follows the layer's Speed), props, helpers and other inputs by name (clicks(i), another grid's field(uv)). - Revising the component restarts the grid from init; a capture continues it.

Parameters

NameTypeNotes
configGridSimInit

Example

inputs: {
  field: simulate.grid({
    resolution: 256, history: 2,
    step: [op.wave({damping: p('decay')}), op.splat({at: pointer(), amount: pointerSpeed({max: 2}), radius: p('radius')})],
    derive: {slope: op.gradient()},
  }),
},
effect: wgsl`return textureSample(childTexture, childSampler, uv + field.slope(uv).xy * intensity);`,

See also

  • op
  • displaceBy — Push the child's pixels around by a vector field from one of your simulations.