buffer

A storage buffer of count records of a struct type, zero-filled.

buffer(type: StructType, count: ScalarArg, opts: {max?: number} = {}): BufferInput

Import buffer from shaders/std.

Kernels name it in their WGSL to read and write it (stars[index].pos). count may be a prop (with max the most it can grow to); only the first count records are processed each frame.

Parameters

NameTypeNotes
typeStructType
countScalarArg
opts{max?: number}Optional. Default {}.

Example

const Star = struct('Star', {pos: 'vec2f', vel: 'vec2f'})
inputs: {
  stars: buffer(Star, p('count'), {max: 65536}),
  move: kernel(wgsl`stars[index].pos += stars[index].vel * dt;`, {over: 'stars'}),
},

See also

  • kernel — Your own compute pass.
  • struct — Declare a record type.

Keep reading