This feature requires the p5.webgpu.js addon.
This API is experimental
Its behavior may change in a future version of p5.js.
Dispatches a compute shader to run on the GPU.
The first parameter, shader, is a compute shader created with buildComputeShader.
Pass a number for x to run a simple loop. Inside the shader's iteration function, index.x will count up from 0 to that number.
You can also pass y and z to loop in up to three dimensions, using index.y and index.z to get the position in each. This is useful for working with 2D grids, like in the Game of Life example below.
Examples
Syntax
compute(shader, x, [y], [z])
Parameters
shader
p5.Shader: The compute shader to run.
x
Number: Number of invocations in the X dimension.
y
Number: Number of invocations in the Y dimension.
z
Number: Number of invocations in the Z dimension.
Notice any errors or typos? Please let us know. Please feel free to edit src/core/p5.Renderer3D.js and open a pull request!