Advanced
The lighting model's snippets and metadata
The composed lighting bit
export const lambertLightingBit = createLightingBit({
name: 'lambertLighting',
preLighting: {
gpu: 'var directLight = vec3<f32>(0.0);',
gl: 'vec3 directLight = vec3(0.0);',
},
perLight: {
gpu: 'directLight += albedo * light.color * nDotL * attenuation * shadow;',
gl: 'directLight += albedo * light.color * nDotL * attenuation * shadow;',
},
postLighting: {
gpu: 'finalColor = directLight;',
gl: 'finalColor = directLight;',
},
});
The PBR material's Cook-Torrance lighting and the toon material's toonLightingBit are built the
same way.
Builds a lighting
ShaderBitaround the shading math inoptsCall it once at module scope and list the bit in a material's
bitsGpuandbitsGl. CreateLightingBitOptions says what each snippet can read.