Skip to main content

Scene attachments for effects

Use SceneEffectAttachments to pass scene color, depth, normals, motion, selection, and exposure from capture or lighting passes into an effect stack. The field names match the shader bindings used by built-in effects. Supply the attachments required by the effects you select.

Loading interactive example…

The WebGPU example captures linear HDR color, view-space normals, roughness, and depth in a single scene pass at 75% of display resolution. The graph applies SSAO and HDR bloom, then tone mapping, sRGB encoding, grading, FXAA, and dithering. The WebGL example draws the same scene into a framebuffer and uses a fragment-only stack in GPUSimpleGraph. Both examples present the result at canvas resolution.

Attachment semantics​

FieldWhat the producer writesTypical consumers
colorScene color in the first effect's working space. Use linear HDR, such as rgba16float, before exposure and tone mapping. Follow the effect's alpha convention.All color effects
depthTextureSampleable, single-sample hardware depth. Standard projection clears to 1 and maps the near plane to 0 and the far plane to 1 in the stored texture. Supply the camera constants or inverse projection expected by the consumer.SSAO, GTAO, SSR, SSGI, depth of field, fog, contact shadows
normalTextureView-space unit normal packed as normal * 0.5 + 0.5 in RGB, with perceptual roughness in A. Clear pixels follow the consumer's depth-background rule.Texture-normal SSAO, GTAO, SSR, SSGI
velocityTextureSigned RG motion in top-left UV space. Store current unjittered UV minus previous unjittered UV, including camera and object motion. rg16float is a typical choice.TAA, temporal upscaling, temporal modes of screen-space effects
selectionTextureSelection coverage in R, usually zero for background and one for a selected surface. Convert discrete object IDs to coverage before sampling with a filter.Selection outline
exposureTextureExposure state written in the layout expected by the consuming shader. The HDR auto-exposure effect manages its own exposure reduction and history when used as a stack entry.Exposure application

Capture depth and normals with the same camera, viewport, and jitter as scene color. For reconstruction, WebGPU clip depth is already in [0, 1], while traditional WebGL projection produces [-1, 1] clip depth before viewport mapping into the depth texture. Use a projection and depth reconstruction convention that match. Use the standard depth direction unless the selected effect explicitly supports reverse-Z. If the scene uses MSAA, resolve color before sampling. Capture a separate single-sample depth attachment when the backend cannot provide a sampleable depth resolve.

For motion, project both current and previous positions without jitter and convert to top-left UV before subtracting. Pass current and previous jitter separately through the shared temporal frame fields when the effect accepts them. Preserve the motion values in normalized units when the effect runs at another resolution. Allocate history at the extent declared by the effect. The command graph applies effect resource scales to the effect operation’s output extent. Use a render-sized effect output followed by a separate upscale operation when a stage should work at render resolution. Render extent is the scene capture size. Display extent is the size of the output after upscaling or presentation.

Pass attachments to the effect stack​

Keep construction options in the effect entries. Pass textures and animated uniforms at frame time unless an override belongs to one occurrence. The occurrence's bindings and uniforms take precedence over frame defaults. Effect-defined input routing controls inputs such as source color and named intermediates.

import type {Texture} from '@luma.gl/core';
import {EffectRenderer} from '@luma.gl/engine';
import {ssaoEffect, type SceneEffectAttachments} from '@luma.gl/engine/effects';

const attachments = {
color: sceneColor,
depthTexture: sceneDepth,
normalTexture: sceneNormals
} satisfies SceneEffectAttachments<Texture>;

const renderer = new EffectRenderer(device, {
effects: [{effect: ssaoEffect, options: {normalSource: 'normal-texture'}}]
});

const {color: sourceTexture, ...bindings} = attachments;
renderer.renderToScreen({
sourceTexture,
bindings,
uniforms: {ssaoEvaluate: {nearPlane: 0.15, farPlane: 25}}
});

In a WebGPU command graph, use SceneEffectAttachments<GraphTextureView> and pass the views produced by the capture node directly to GPUCommandEffectOperation. The graph infers producer-to-consumer dependencies from the views. Import external textures if another part of your renderer owns them.

const {color: input, ...bindings} = attachments;
graph.add(new GPUCommandEffectOperation({
id: 'finish-scene',
input,
output: displayColorView,
bindings,
effects: [
{
effect: ssaoEffect,
options: {normalSource: 'normal-texture', resolutionScale: 0.5},
uniforms: {ssaoEvaluate: {nearPlane: 0.15, farPlane: 25}}
},
hdrBloom,
toneMappingEffect,
displayEncodingEffect, // App-defined transfer for an unorm display target.
fxaaEffect,
outputDitheringEffect
]
}));

With named GPUGraph, use the graph's resource names as the attachment values. With GPUSimpleGraph, pass borrowed textures to createEffectRenderOperation and add the result with graph.addRenderOperation. Select fragment effects with implementations for both backends, such as sepia, FXAA, or simple bloom. A fragment implementation written only in WGSL still needs WebGPU. The declarative effects guide covers effect definitions and compute-to-fragment selection.

Backend support​

Effect or modeRequired scene inputsWebGPU command graphWebGL SimpleGraph
Sepia, FXAA, output ditheringColorYesYes
Simple bloomColorFragmentFragment
Multiscale HDR bloomLinear HDR color and matching intermediate formatsCompute extraction when supported, fragment fallbackFragment fallback with renderable and sampleable formats
SSAODepth, camera near/far, and normals in texture modeYesWGSL only
Selection outlineSelection coverageYesYes
TAA and temporal upscalingDepth, motion, temporal frame fields, and retained historyYesWGSL only
Clustered volumetric lightingDepth, camera, light and cluster storage, and motion for temporal modeYesWGSL and storage buffers required

Ownership and history​

Give a texture the usage flags required by each pass that uses it. A scene texture that is written by a render pass and sampled by a later effect needs Texture.RENDER | Texture.SAMPLE. Sample from a separate view or texture when a pass writes its output. Keep graph transients inside their compiled graph. Keep borrowed textures and views alive through submission. Destroy or replace them when the caller rebuilds the pipeline for a new size or format.

Use GPUTextureHistory for persistent graph history. Import previous/current roles with importTemporalGraphHistory, bind the roles for the current frame, and advance the pairs together after successful submission. Reset history on first use, a camera cut, or a resize that invalidates it. For clustered volumetric lighting, allocate radiance/transmittance in rgba16float and linear depth in rg16float at the selected integration extent. Pass the read-only cluster and light buffers as the operation's storage bindings so the graph can track upstream writes. Supply unjittered camera view-projection matrices for the fallback reprojection and pass the current and previous UV jitter separately. Zero history contribution on reset. Depth rejection handles disocclusion during ordinary motion.

Choose the lighting and output stages​

Shadow capture precedes scene shading because lighting samples shadow maps. When ambient occlusion is part of the lighting model, compute it from a prepass or G-buffer and bind the AO texture during lighting. A post-lighting SSAO composite is an alternative when you own only the captured scene color.

Keep HDR bloom and other light accumulation upstream of tone mapping. Use the color encoding expected by the next effect. Place display-space grading and spatial AA after tone mapping when their definitions expect display color. Place TAA or temporal upscaling at the stage specified by the effect's color, depth, and motion inputs. Dither at the final output precision. Match texture formats and presentation conversion so the display transfer function is applied once.

Use graph preflight to inspect pass order, texture formats, transient lifetimes, and graph dependencies. On a backend with GPU timestamps, compare GPU time independently of CPU submit time. Use the same scene, pass list, render size, and display size when comparing execution paths.