Normal mapping
A normal map changes the direction used for lighting to reveal fine surface detail while preserving the mesh silhouette.
Configuration​
import {Model} from '@luma.gl/engine/api';
import {createPBRMaterial, type PBRMaterial} from '@luma.gl/engine/materials';
const normalTexture = device.createTexture({
width: 1,
height: 1,
format: 'rgba8unorm',
data: new Uint8Array([180, 128, 240, 255])
});
const material: PBRMaterial = createPBRMaterial(device, {
uniforms: {
normalScale: 0.8
},
bindings: {pbr_normalSampler: normalTexture}
});
// modelProps contains your shaders, geometry, and buffer layout.
const model = new Model(device, {
...modelProps,
material,
defines: {...modelProps.defines, HAS_NORMALMAP: true}
});
This constant normal illustrates texture binding. Replace it with a linear tangent-space normal map for a detailed surface. The model needs UVs and a compatible tangent basis; the glTF importer can use authored tangents. See bump mapping for height-derived perturbations.
Parameters​
| Parameter | Default | Description |
|---|---|---|
normalScale | 1 | Scales the tangent-space X and Y normal components. |
normalMapEnabled | false | Enables normal-map sampling. |
Texture bindings​
| Binding | Model define | Description |
|---|---|---|
pbr_normalSampler | HAS_NORMALMAP: true | Linear tangent-space XYZ normal encoded in RGB. |
See Using PBR materials for material setup.
Remarks​
- Core glTF
normalTexturesupplies tangent-space normals. Itsscalemaps tonormalScale.