Render targets are named off-screen textures that passes can read from and write to. They allow techniques like downsampled blur pyramids, multi-resolution effects, and intermediate computation buffers.
Declaring render targets
Render targets are declared as a renderTargets prop on FragCanvas:
The map keys become the names used to access targets in passes.
Using named targets as pass slots
Named target keys can be used directly in RenderPass.input and RenderPass.output:
Rules:
- Named slots must exist in
renderTargets. - Named outputs are only valid with
needsSwap: false. needsSwap: trueis reserved forsource -> target.
RenderTargetDefinition fields
Resolution rules
Each dimension is resolved independently:
- If
widthorheightis explicitly set, that value is used (Math.max(1, Math.floor(value))). - If a dimension is not set, it is computed as
Math.max(1, Math.floor(canvasDimension * scale)). - If
scaleis not set, it defaults to1(full canvas resolution).
Examples
Naming rules
Target keys must be WGSL-safe identifiers: [A-Za-z_][A-Za-z0-9_]*. Invalid names throw during resolution.
Validation
Accessing targets in passes
Render targets are available in the RenderPassContext via the targets field:
Named targets are accessed through context.targets inside custom passes.
Lifecycle
The renderer manages render target textures automatically:
Signature-based change detection
Render target definitions are compared each frame using a deterministic signature: key:format:widthxheight. Only targets whose signature changed are reallocated — stable targets keep their existing GPU texture.