Skip to main content

Volumetric Fog

Add depth-aware height fog, directional atmospheric scattering, and temporally stabilized haze. createVolumetricFogShaderPassPipeline provides a compact participating-media treatment when a full scene-lighting integration is unnecessary.

GitHub

At a Glance

PropertyValue
ExportcreateVolumetricFogShaderPassPipeline
Shader uniform namespacevolumetricFog
BackendWebGPU
Render passesTwo: fog/history resolve and composed-color copy
Required bindingdepthTexture
Persistent stateOne renderer-owned fog-history texture

Usage

import {ShaderPassRenderer} from '@luma.gl/engine';
import {createVolumetricFogShaderPassPipeline} from '@luma.gl/effects';

const renderer = new ShaderPassRenderer(device, {
colorFormat: 'rgba16float',
shaderPasses: [createVolumetricFogShaderPassPipeline()]
});

renderer.renderToScreen({
sourceTexture: gBuffer.colorTexture,
bindings: {depthTexture: gBuffer.depthTexture},
uniforms: {
volumetricFog: {
fogColor: [0.18, 0.34, 0.48, 0.6],
density: 0.22,
heightFalloff: 3,
scattering: 0.35,
historyWeight: 0.82,
time: elapsedSeconds
}
}
});

Parameters

ParameterDefaultDescription
fogColor[0.18, 0.34, 0.48, 0.6]Atmospheric RGB color and directional-scattering influence.
density0.22Overall participating-media density.
heightFalloff3Rate at which the simulated fog density decreases with height.
scattering0.35Strength of the built-in directional light contribution.
historyWeight0.82Contribution from the preceding temporally accumulated fog result.
time0Application-owned animation value used to vary the sampling pattern.

Performance and Limitations

The main stage takes 20 depth-dependent integration samples and blends against one persistent history texture; the second stage copies the stabilized result back into the shared pass chain. This compact model does not inspect application point-light buffers or clustered light lists. Choose Clustered Volumetric Lighting when the atmosphere must react to actual scene lights, physically oriented anisotropy, or depth-occluded light shafts.