参考 compute()

compute()

This feature requires the p5.webgpu.js addon.
此 API 是实验性的

其行为可能在 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.

示例

语法

compute(shader, x, [y], [z])

参数

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!

相关参考