Documentation
    Preparing search index...

    Class LitProgram

    The Lambert-lit pipeline (§57 LitMaterial, §68, §120 "lighting") — added by the lighting packet, 2026-08-04.

    const program = LitProgram.create(gl);
    program.use();
    program.setViewProjection(viewProjection); // once per viewport
    program.setAmbientLight(lights.ambientColor); // once per viewport
    program.setDirectionalLight(
    lights.direction, // once per viewport
    lights.directionalColor,
    );
    program.setPunctualLights(lights); // once per viewport
    program.setModel(item.worldMatrix); // once per draw
    program.setColor(item.material.color);

    It shares gl-geometry.ts's vertex arrays with the other pipelines: the position stream sits at the fixed POSITION_ATTRIBUTE_LOCATION and the normal stream — when the geometry has one — at the fixed NORMAL_ATTRIBUTE_LOCATION, so one geometry cache serves all four programs. Light uniforms are per frame state uploaded per viewport (they live in the program object, exactly like the view-projection): the scene ambient term, one directional light, and up to @fourjs/render!MAX_PUNCTUAL_LIGHTS point and spot lights (R-17, 2026-08-09). Shadows (§69), tone mapping (§60a), and §68's remaining light types are staged where @fourjs/scene's light.ts records.

    Owns its GL objects and nothing else; the renderer re-creates it on context restore exactly as it re-creates the unlit one (§61).

    Implements

    Index
    • get disposed(): boolean

      Whether LitProgram.dispose has run.

      Returns boolean

    • Deletes the GL program (§83). Idempotent.

      Only call this on a live context — see UnlitProgram.dispose.

      Returns void

    • Uploads the scene ambient term (§68), straight RGB. Accepts the SceneLights record's own live array — copied into scratch, as every upload here is.

      Parameters

      • color: readonly [number, number, number]

      Returns void

    • Uploads a straight-alpha, linear-light RGBA colour (§57, §60a) — the material's base color, scaled by its opacity exactly as UnlitProgram.setColor does. Accepts the material's own live array; the values are copied into scratch, so the material keeps ownership of its array.

      Parameters

      • color: readonly [number, number, number, number]
      • Optionalopacity: number

      Returns void

    • Uploads the directional light (§68): the world-space unit vector the light travels along (SceneLights.direction — the fragment stage negates it for the surface term) and its color premultiplied by intensity (SceneLights.directionalColor). A frame with no directional light uploads black, which zeroes the Lambert term — see the fragment source.

      Parameters

      • direction: Vector3
      • color: readonly [number, number, number]

      Returns void

    • Selects whether this draw samples the bound albedo texture (§57's map, R-19). Identical in contract to UnlitProgram.setFeatures — mirrored on the CPU, uploaded only on change, sampler unit uploaded lazily — minus the vertex-colour switch, which §57 puts on UnlitMaterial alone.

      Parameters

      • useMap: boolean

      Returns void

    • Uploads the frame's hemisphere (§68) — or nothing, for a scene that has none. See HemisphereLightUniforms for the contract and for why "nothing" is load-bearing.

      Parameters

      Returns void

    • Uploads one render item's world matrix and its derived normal matrix.

      Parameters

      Returns void

    • One-target morph weight; a no-op on the default lit program.

      Parameters

      • weight: number

      Returns void

    • Uploads the frame's point and spot lights (§68, R-17) — or nothing, for a scene that has none. See PunctualLightUniforms for the contract and for why "nothing" is load-bearing.

      Parameters

      Returns void

    • Selects whether the draw about to be issued is shadowed (§49's receiveShadow, §69) — see ShadowUniforms.setReceiving, whose contract this is verbatim.

      Parameters

      • receiving: boolean

      Returns void

    • Uploads the frame's shadow matrix, biases and tap size (§69, R-18) — or nothing, for a frame in which no light casts. Call once per viewport; see ShadowUniforms for the contract and for why "nothing" is load-bearing.

      Parameters

      Returns void

    • Uploads projection * view for the viewport being drawn. Column-major, so transpose is false — the engine's Matrix4 layout is already GL's (§7b).

      Parameters

      Returns void

    • Makes this the current program. Call before any upload below.

      Returns void