feedbackSim

A simulation that advances a picture of its own last frame by one step of your rule, every frame.

feedbackSim<TParams, TGroups = unknown>(build: (params: GpuFragmentParams, root: FeedbackRoot) => FeedbackSimConfig<TParams, TGroups>): {compute: GpuComputeNode}

Import sim from shaders/std and use sim.feedback.feedbackSim.

Spread it into a definition next to a gpu.fragment that samples display.

The build callback runs once per instance of the layer, so anything you create inside it (resources, a kernel variant picked from a compile-time prop) belongs to that instance. The simulation needs a child. Without one, or without a GPU, nothing runs and the fragment should fall back to the child.

Parameters

NameTypeNotes
build(params: GpuFragmentParams, root: FeedbackRoot) => FeedbackSimConfig<TParams, TGroups>

Example

...feedbackSim((params, root) => ({size: 768, format: 'rgba16float', speedProp: 'speed', paramsSchema: decoder.Params, bindGroups: ({childTexture, display, paramsBuffer}, read, write) => root.createBindGroup(decoder.layout, {src: childTexture, prev: read.state, next: write.state, display, params: paramsBuffer} as never), step: decoder.kernel, values: ({dt, localTime}) => ({time: localTime, dt, intensity: params.getCpuValue('intensity') as number})}))

Tip. Read time from localTime, not the layer's clock. It stops when speedProp is 0 and every frame's step matches it.

See also

  • fluidSim — A fluid the engine solves every frame.
  • gridSim — A field of cells advanced every frame by an ordered list of stages.
  • agentSim — A simulation of many agents, spread into a definition: bake assembles the steps from your declared parts, frame writes the per-frame values, and the fragment samples the picture.
  • simulate — Declare a simulation the engine runs for you.

Used by

DataMosh, TimeTrail