Skip to main content

Normal mapping

A normal map changes the direction used for lighting to reveal fine surface detail while preserving the mesh silhouette.

GitHub
0.0s
Compare the highlights on the smooth sphere and the normal-mapped sphere.

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​

ParameterDefaultDescription
normalScale1Scales the tangent-space X and Y normal components.
normalMapEnabledfalseEnables normal-map sampling.

Texture bindings​

BindingModel defineDescription
pbr_normalSamplerHAS_NORMALMAP: trueLinear tangent-space XYZ normal encoded in RGB.

See Using PBR materials for material setup.

Remarks​

  • Core glTF normalTexture supplies tangent-space normals. Its scale maps to normalScale.