Ambient occlusion
An occlusion texture darkens creases and cavities using precomputed visibility, adding local surface shading without additional geometry.
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​
| Parameter | Default | Description |
|---|---|---|
occlusionStrength | 1 | Blend between unoccluded shading (0) and sampled occlusion (1). |
occlusionMapEnabled | false | Enables occlusion-map sampling. |
Texture bindings​
| Binding | Model define | Description |
|---|---|---|
pbr_occlusionSampler | HAS_OCCLUSIONMAP: true | Linear red-channel occlusion (1 means unoccluded). |
See Using PBR materials for material setup.
Remarks​
- Core glTF
occlusionTexturestores visibility in the red channel. Itsstrengthmaps toocclusionStrength.