Reference buildComputeShader()

buildComputeShader()

This feature requires the p5.webgpu.js addon.
This API is experimental

Its behavior may change in a future version of p5.js.

Create a new compute shader using p5.strands.

A compute shader lets you run many calculations all at once on your GPU. They are similar to a compute() and passing the shader in, along with the number of iterations in up to three dimensions. Use the index vector inside of your iteration function to refer to the current iteration of the loop. The x, y, and z properties will count up from zero to the count in each dimension passed into compute.

A compute shader will read from and write to storage, which is often an array of numbers or objects. Use createStorage to construct initial data. Connect your iteration function to the storage by passing the storage into uniformStorage.

Often, compute shaders are paired with model(myGeometry, count) to draw one instance per object in the storage, and a shader that uses instanceID() to position each instance.

Examples

Syntax

buildComputeShader(callback)

Parameters

callback
Function: A function building a p5.strands compute shader.

Returns

p5.Shader: The compute shader.
Notice any errors or typos? Please let us know. Please feel free to edit src/core/p5.Renderer3D.js and open a pull request!

Related References