kernel

Your own grid step, run once per cell: return the cell's new vec4f.

kernel(body: WgslBody | string, opts: {iterations?: number} = {}): CellKernelOp

Import op from shaders/std and use op.kernel.

It reads read(c) (any cell this step, clamped at the edges), readLinear(p) (the grid at any uv p, bilinear between cell centres: for advection, readLinear(cellUV - velocity * dt)), readPrev(c) (the state at the end of the frame before), cell: vec2i, cellUV: vec2f (the cell's centre), gridSize: vec2i, plus props, built-ins (dt is the layer clock's step, so Speed scales it), inputs and library functions. iterations repeats it within the frame, each pass reading the one before (Jacobi style).

Parameters

NameTypeNotes
bodyWgslBody | string
opts{iterations?: number}Optional. Default {}.

Example

op.kernel(wgsl`
  let c = read(cell);
  let avg = (read(cell + vec2i(1, 0)) + read(cell - vec2i(1, 0))) * 0.5;
  return mix(c, avg, 0.5);
`)