@pixi/3d
    Preparing search index...

    Interface CreateLightingBitOptionsAdvanced

    Options for createLightingBit: the shading math of a lighting model, such as toon or Blinn-Phong, around a light loop the factory writes

    The generated fragment lighting slot runs:

    preLighting
    for (each light that can reach this fragment) {
      work out light, lightDir, attenuation, nDotL and shadow, or skip the light
      perLight
    }
    postLighting
    
    1. In preLighting, declare and zero your accumulators, such as directLight, and work out anything that doesn't depend on the light, such as nDotV.
    2. In perLight, add this light's share to them. continue; skips the rest of this light. Lights that don't reach the fragment or that the surface faces away from never get here.
    3. In postLighting, write finalColor from the accumulators and whatever the material bit declared, such as emissive. Exposure, fog and tone mapping run after it.

    The loop sits in a block of its own, so names these snippets declare aren't visible to later slots such as end.

    Name Type Value
    light Light this light
    lightDir vec3 normalized, from the fragment toward the light
    attenuation f32 distance falloff times the spot cone, above 0
    nDotL f32 max(dot(normal, lightDir), 0), above 0
    shadow f32 1 lit, 0 shadowed
    normal vec3 the world-space surface normal, as the material bits left it
    viewDir vec3 normalized, toward the camera; declared by the material bit

    Anything else the model needs, such as albedo and roughness, comes from the material bit that runs before it. The light's kind is light.kind in WGSL and light.type in GLSL; compare it with LIGHT_DIRECTIONAL, LIGHT_POINT or LIGHT_SPOT.

    Another bit in the descriptor can add per-light math to this loop, rather than run a second loop that samples every shadow again, through the fragment slots lobePreLighting, lobePerLight and lobePostLighting. Each runs after the matching snippet here, in the order the lobe bits are listed, so lobePostLighting sees the assembled finalColor and can rewrite it.

    Use the bit in a material with BaseMaterial3D#lit on, the default. A pass's own shader can't run it.

    interface CreateLightingBitOptions {
        bindings?: Partial<Record<string, BindingGroup>>;
        header?: { gl?: string; gpu?: string };
        name: string;
        perLight: { gl?: string; gpu?: string };
        postLighting?: { gl?: string; gpu?: string };
        preLighting?: { gl?: string; gpu?: string };
        requires?: ShaderBit[];
        structs?: Record<string, StructDefinition>;
        textures?: string[];
    }
    Index
    bindings?: Partial<Record<string, BindingGroup>>

    Bindings the model needs, such as its own material fields

    header?: { gl?: string; gpu?: string }

    Code for the {{header}} slot, such as helper functions and constants

    Type Declaration

    • Optionalgl?: string

      GLSL source (WebGL)

    • Optionalgpu?: string

      WGSL source (WebGPU)

    name: string

    The bit's ShaderBit#name, which must be unique

    perLight: { gl?: string; gpu?: string }

    The shading math for one light, run inside the loop; CreateLightingBitOptions lists what it reads

    Type Declaration

    • Optionalgl?: string

      GLSL source (WebGL)

    • Optionalgpu?: string

      WGSL source (WebGPU)

    postLighting?: { gl?: string; gpu?: string }

    Code that runs once, after the light loop

    It writes the template's finalColor, as in finalColor = ambient * occlusion + directLight + emissive;.

    Type Declaration

    • Optionalgl?: string

      GLSL source (WebGL)

    • Optionalgpu?: string

      WGSL source (WebGPU)

    preLighting?: { gl?: string; gpu?: string }

    Code that runs once, before the light loop

    Declare the accumulators here, and anything that doesn't depend on the light. What it declares stays in scope for perLight and postLighting.

    Type Declaration

    • Optionalgl?: string

      GLSL source (WebGL)

    • Optionalgpu?: string

      WGSL source (WebGPU)

    requires?: ShaderBit[]

    Bits the model needs in the shader, such as mathConstantsBit for PI and INV_PI

    structs?: Record<string, StructDefinition>

    Structs the model declares

    textures?: string[]

    Textures the model samples, such as a lookup table