API

Function enableMaterialStencil

  • Enable per-material stencil state for Standard, PBR, and Shader materials.

    A writer material uses compare: "always" + passOp: "increment-clamp" to stamp the stencil buffer where it draws; a tester material uses compare: "equal" to draw only where the stencil is still the pass's default reference of 0 (i.e. where the writer did NOT draw). No dynamic stencil reference is needed.

    const mask = createStandardMaterial();
    mask.stencil = { passOp: "increment-clamp" }; // writes 1 where it draws
    const masked = createStandardMaterial();
    masked.stencil = { compare: "equal" }; // draws only where stencil is still 0

    enableMaterialStencil(); // ← opt-in, before registerScene
    await registerScene(scene);

    Returns void