Skip to main content

Opacity and cutouts

Material alpha supports partially transparent surfaces and binary cutouts such as foliage, fences, and decals.

GitHub
0.0s
Compare the edges of the cutout shapes with the blended transparent surfaces.

Configuration​

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

const material: PBRMaterial = createPBRMaterial(device, {
uniforms: {
baseColorFactor: [0.2, 0.6, 1, 0.35]
}
});

// modelProps contains your shaders, geometry, and buffer layout.
const model = new Model(device, {
...modelProps,
material,
parameters: {
...modelProps.parameters,
blend: true,
blendColorOperation: 'add',
blendColorSrcFactor: 'src-alpha',
blendColorDstFactor: 'one-minus-src-alpha',
blendAlphaOperation: 'add',
blendAlphaSrcFactor: 'one',
blendAlphaDstFactor: 'one-minus-src-alpha',
depthWriteEnabled: false
}
});

For cutouts, use an opaque render pass with depth writes and set both the shader define and material threshold. Here baseColorTexture is a loaded texture with a varying alpha channel:

const cutoutMaterial: PBRMaterial = createPBRMaterial(device, {
uniforms: {alphaCutoffEnabled: true, alphaCutoff: 0.4},
bindings: {pbr_baseColorSampler: baseColorTexture}
});
const cutoutModel = new Model(device, {
...modelProps,
material: cutoutMaterial,
defines: {...modelProps.defines, HAS_BASECOLORMAP: true, ALPHA_CUTOFF: true}
});

Render blended geometry after opaque geometry and sort it from back to front; blend parameters alone do not solve overlapping transparent surfaces.

Parameters​

ParameterDefaultDescription
baseColorFactor[1, 1, 1, 1]Alpha multiplies texture and vertex alpha.
alphaCutoffEnabledfalseEnables the cutoff uniform in compatible shader paths.
alphaCutoff0.5Discard fragments below this alpha threshold when ALPHA_CUTOFF is defined.

Model render state​

Model.parameters controls blending and depth writes. Model.defines.ALPHA_CUTOFF compiles alpha rejection into the shader. Alpha blending is distinct from light transmission, which models light passing through a dielectric.

See Using PBR materials for material setup.

Remarks​

  • Core glTF alphaMode selects OPAQUE (default), MASK, or BLEND. Masked materials use alphaCutoff; blended materials use base-color alpha.