Skip to main content

Ambient occlusion

An occlusion texture darkens creases and cavities using precomputed visibility, adding local surface shading without additional geometry.

GitHub
0.0s
Compare the shading in the creases with and without baked occlusion.

Configuration​

import {Model} from '@luma.gl/engine/api';
import {createPBRMaterial, type PBRMaterial} from '@luma.gl/engine/materials';

const occlusionTexture = device.createTexture({
width: 1,
height: 1,
format: 'rgba8unorm',
data: new Uint8Array([128, 255, 255, 255])
});
const material: PBRMaterial = createPBRMaterial(device, {
uniforms: {
occlusionStrength: 0.7
},
bindings: {pbr_occlusionSampler: occlusionTexture}
});

// modelProps contains your shaders, geometry, and buffer layout.
const model = new Model(device, {
...modelProps,
material,
defines: {...modelProps.defines, HAS_OCCLUSIONMAP: true}
});

The one-pixel map above shows the binding and strength adjustment. Supply a spatially varying baked map for cavities on a real model. This is separate from screen-space ambient occlusion and dynamic shadows. The current shared PBR shader applies this factor to its accumulated surface color.

Parameters​

ParameterDefaultDescription
occlusionStrength1Blend between unoccluded shading (0) and sampled occlusion (1).
occlusionMapEnabledfalseEnables occlusion-map sampling.

Texture bindings​

BindingModel defineDescription
pbr_occlusionSamplerHAS_OCCLUSIONMAP: trueLinear red-channel occlusion (1 means unoccluded).

See Using PBR materials for material setup.

Remarks​

  • Core glTF occlusionTexture stores visibility in the red channel. Its strength maps to occlusionStrength.