Skip to main content

API Reference

Passes API

Constructor options and runtime methods for render, compute, and feedback passes.


Pass classes are framework-neutral and exported from root, core, and adapter entrypoints.

Shared render-pass options

ShaderPass, BlitPass, and CopyPass share:

Option Default
enabled true
needsSwap true
input 'source'
output 'target' when swapping, otherwise 'source'
clear false
clearColor [0, 0, 0, 1]
preserve true
filter 'linear'

needsSwap: true is valid only for source → target. canvas is output-only. Named slots must exist and be written before use.

ShaderPass

Requires fragment containing:

fn shade(inputColor: vec4f, uv: vec2f) -> vec4f
fn shade(inputColor: vec4f, uv: vec2f) -> vec4f

Public methods:

setFragment(fragment: string): void
getFragment(): string
setFragment(fragment: string): void
getFragment(): string

setFragment validates the next source before replacing the active program and invalidating its pipeline cache.

shade and any helper it calls can read the current pass coordinates from motiongpuFragment.uv. The existing uv parameter remains required.

BlitPass and CopyPass

BlitPass samples its input with the configured filter. CopyPass attempts a direct GPU copy and otherwise uses an internal blit. Direct copy requires no clear, preserved output, distinct non-canvas textures, and equal dimensions and formats.

Both expose setSize, render, and dispose through the render-pass lifecycle.

ComputePass

new ComputePass({
	compute: string,
	dispatch?: tuple | 'auto' | (context) => [number, number, number],
	enabled?: boolean
})
new ComputePass({
	compute: string,
	dispatch?: tuple | 'auto' | (context) => [number, number, number],
	enabled?: boolean
})

The source requires @compute, numeric @workgroup_size(...), a compute function, and @builtin(global_invocation_id) in its signature.

setCompute(source): void
setDispatch(dispatch): void
getCompute(): string
getWorkgroupSize(): [number, number, number]
resolveDispatch(context): [number, number, number]
dispose(): void
setCompute(source): void
setDispatch(dispatch): void
getCompute(): string
getWorkgroupSize(): [number, number, number]
resolveDispatch(context): [number, number, number]
dispose(): void

isCompute is the readonly true discriminant.

PingPongComputePass

Adds required target, optional positive-integer iterations (default 1), and the isPingPong discriminant. Its target must be a declared storage texture with explicit dimensions.

getCurrentOutput(): string
advanceFrame(): void
setIterations(count): void
setCompute(source): void
setDispatch(dispatch): void
getTarget(): string
getIterations(): number
getCompute(): string
getWorkgroupSize(): [number, number, number]
resolveDispatch(context): [number, number, number]
dispose(): void
getCurrentOutput(): string
advanceFrame(): void
setIterations(count): void
setCompute(source): void
setDispatch(dispatch): void
getTarget(): string
getIterations(): number
getCompute(): string
getWorkgroupSize(): [number, number, number]
resolveDispatch(context): [number, number, number]
dispose(): void

The renderer calls advanceFrame() after the current iteration batch. Output A/B parity therefore remains correct when iteration count changes between frames.

PingPongShaderPass

Runs a pre-scene fragment shader with fn frag(uv: vec2f) -> vec4f. target must be a declared, fragment-visible, non-storage material texture.

Option Default
width, height Canvas axis multiplied by scale
scale 1
format 'rgba16float'
filter 'linear'
addressModeU/V 'clamp-to-edge'
iterations 1
clearColor [0, 0, 0, 0]
defines, includes {}
enabled true

Dimensions and scale must be finite and positive, iterations a positive integer, and format float-sampled.

setFragment(fragment, { defines?, includes? }?): void
setIterations(count): void
setDimensions(width?, height?): void
setScale(scale): void
reset(clearColor?): void
consumeResetColor(): RGBA | null
getCurrentOutput(): string
advanceFrame(): void
resolveSize(canvasSize): { width, height }
getTarget(): string
getFragment(): string
getFragmentLineMap(): MaterialLineMap
getIterations(): number
getFormat(): GPUTextureFormat
getFilter(): GPUFilterMode
getAddressModeU(): GPUAddressMode
getAddressModeV(): GPUAddressMode
getClearColor(): RGBA
dispose(): void
setFragment(fragment, { defines?, includes? }?): void
setIterations(count): void
setDimensions(width?, height?): void
setScale(scale): void
reset(clearColor?): void
consumeResetColor(): RGBA | null
getCurrentOutput(): string
advanceFrame(): void
resolveSize(canvasSize): { width, height }
getTarget(): string
getFragment(): string
getFragmentLineMap(): MaterialLineMap
getIterations(): number
getFormat(): GPUTextureFormat
getFilter(): GPUFilterMode
getAddressModeU(): GPUAddressMode
getAddressModeV(): GPUAddressMode
getClearColor(): RGBA
dispose(): void

isPingPongShader is the readonly true discriminant. setDimensions, setScale, and reset request A/B reinitialization; consumeResetColor is renderer-facing and clears that pending request.

frag and its helper functions can read the ping-pong target coordinates from motiongpuFragment.uv. They use the pass target dimensions and the same public Y-up orientation as the uv parameter.

See Render Passes, Compute Shaders, and the Ping-pong Fluid demo.