Used to create a ComputePass, i.e. run computations on the GPU.
A ComputePass is basically a wrapper around a ComputeMaterial that handles most of the process.

The default render behaviour of a ComputePass is to set its bind groups and then dispatch the workgroups based on the provided dispatchSize.
However, most of the time you'd want a slightly more complex behaviour. The useCustomRender hook lets you define a totally custom behaviour, but you'll have to set all the bind groups and dispatch the workgroups by yourself.

// set our main GPUCurtains instance
const gpuCurtains = new GPUCurtains({
container: '#canvas' // selector of our WebGPU canvas container
})

// set the GPU device
// note this is asynchronous
await gpuCurtains.setDevice()

// let's assume we are going to compute the positions of 100.000 particles
const nbParticles = 100_000

const computePass = new ComputePass(gpuCurtains, {
label: 'My compute pass',
shaders: {
compute: {
code: computeShaderCode, // assume it is a valid WGSL compute shader
},
},
dispatchSize: Math.ceil(nbParticles / 64),
storages: {
particles: {
access: 'read_write',
struct: {
position: {
type: 'array<vec4f>',
value: new Float32Array(nbParticles * 4),
},
},
},
},
})

Constructors

Properties

type: string

The type of the ComputePass.

uuid: string

The universal unique id of the ComputePass.

index: number

The index of the ComputePass, incremented each time a new one is instanced.

renderer: Renderer

The Renderer used.

renderOrder: number

Controls the order in which this ComputePass should be rendered by our Scene.

Options used to create this ComputePass.

material: ComputeMaterial
_ready: boolean

Flag indicating whether this ComputePass is ready to be rendered.

userData: Record<string, unknown>

Empty object to store any additional data or custom properties into your ComputePass.

_onReadyCallback: () => void = ...

function assigned to the onReady callback.

_onBeforeRenderCallback: () => void = ...

function assigned to the onBeforeRender callback.

_onRenderCallback: () => void = ...

function assigned to the onRender callback.

_onAfterRenderCallback: () => void = ...

function assigned to the onAfterRender callback.

_onAfterResizeCallback: () => void = ...

function assigned to the onAfterResize callback.

Accessors

Methods