Skip to main content

Screen-Space Reflections

Reflect visible scene lighting from glossy and rough surfaces using depth, surface normals, roughness, and temporal reprojection. createSSRShaderPassPipeline traces reflection rays through the current frame and resolves them into a stabilized specular contribution.

GitHub

At a Glance

PropertyValue
ExportcreateSSRShaderPassPipeline
BackendWebGPU
Render passesSix: reflection trace, temporal resolve, depth history, two spatial filters, and composite
Required bindingsdepthTexture, normalTexture, and velocityTexture
Persistent statergba16float reflection and depth history
Reflection coverageVisible scene color and first-layer screen depth

Usage

import {ShaderPassRenderer} from '@luma.gl/engine';
import {createSSGIShaderPassPipeline, createSSRShaderPassPipeline} from '@luma.gl/effects';

const renderer = new ShaderPassRenderer(device, {
colorFormat: 'rgba16float',
shaderPasses: [
createSSGIShaderPassPipeline({resolutionScale: 0.5}),
createSSRShaderPassPipeline({resolutionScale: 0.5})
]
});

renderer.renderToScreen({
sourceTexture: litSceneTexture,
bindings: gBuffer.getShaderPassBindings(),
uniforms: {
ssrTrace: {
projectionMatrix,
inverseProjectionMatrix,
intensity: 1.35,
maxDistance: 60,
thickness: 0.45,
sampleCount: 48,
maxRoughness: 0.88,
frameIndex
},
ssrTemporal: {inverseProjectionMatrix, historyWeight: 0.86, depthThreshold: 0.018}
}
});

Parameters

ParameterDefaultRange or purpose
resolutionScale1Relative resolution of reflection tracing, history, and spatial filtering.
intensity1.35Strength of traced specular reflection before final composition.
maxDistance60Maximum view-space reflection-ray travel distance.
thickness0.45Accepted depth thickness when testing a possible screen-space hit.
sampleCount48Ray-march budget; supported range is 8 to 96.
maxRoughness0.88Highest surface roughness that can contribute reflections.
historyWeight0.86Contribution from depth-validated reflection history.
depthThreshold0.018Temporal rejection threshold for disoccluded reflected surfaces.
strength1Final ssrComposite contribution blended into scene color.

Quality and Limitations

SSR cannot reflect geometry outside the current viewport, hidden behind the first visible depth layer, or absent from the already-lit source color. Roughness-aware spatial filtering broadens reflections and rejects unrelated depth/normal surfaces. Lowering sampleCount or resolutionScale saves GPU work but can increase missed intersections or soften thin details.

Trace reflections after direct lighting and Screen-Space Global Illumination when the reflected image should include their contributions. Reset history after camera cuts or changes to attachment dimensions.