@ignifx/core 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{environment-mr5wp69e.js → environment-BCjfp1jB.js} +2 -2
- package/dist/{environment-mr5wp69e.js.map → environment-BCjfp1jB.js.map} +1 -1
- package/dist/{ignifx-error-CRh89KUJ.js → ignifx-error-RpK-lWwE.js} +13 -2
- package/dist/ignifx-error-RpK-lWwE.js.map +1 -0
- package/dist/index.d.ts +1758 -807
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2695 -467
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-gguMoIeZ.js → instanced-mesh-instance-DYwH0vLi.js} +2 -2
- package/dist/{instanced-mesh-instance-gguMoIeZ.js.map → instanced-mesh-instance-DYwH0vLi.js.map} +1 -1
- package/dist/{material-plugin-Cfw_h_Mg.js → material-plugin-CWtV7DkH.js} +3 -3
- package/dist/material-plugin-CWtV7DkH.js.map +1 -0
- package/dist/overlay-CjVgsfrm.js +239 -0
- package/dist/overlay-CjVgsfrm.js.map +1 -0
- package/dist/{post-effect-compiler-Rce26Eue.js → post-effect-compiler-pOvXae-i.js} +2 -2
- package/dist/{post-effect-compiler-Rce26Eue.js.map → post-effect-compiler-pOvXae-i.js.map} +1 -1
- package/dist/{shader-material-U6BKZ8D1.js → shader-material-B6wwFCKB.js} +2 -2
- package/dist/{shader-material-U6BKZ8D1.js.map → shader-material-B6wwFCKB.js.map} +1 -1
- package/dist/{shader-material-BIG3UDyu.js → shader-material-C4VjLTfV.js} +3 -3
- package/dist/{shader-material-BIG3UDyu.js.map → shader-material-C4VjLTfV.js.map} +1 -1
- package/dist/{shader-pragma-tw6AKaQD.js → shader-pragma-qO9_6sTd.js} +2 -2
- package/dist/{shader-pragma-tw6AKaQD.js.map → shader-pragma-qO9_6sTd.js.map} +1 -1
- package/dist/{surface-shader-DAWIDdaa.js → surface-shader-BaR7Kg-F.js} +4 -4
- package/dist/{surface-shader-DAWIDdaa.js.map → surface-shader-BaR7Kg-F.js.map} +1 -1
- package/dist/{vec3-B31o_KF_.js → vec3-T2PasQZv.js} +2 -2
- package/dist/{vec3-B31o_KF_.js.map → vec3-T2PasQZv.js.map} +1 -1
- package/package.json +2 -2
- package/dist/ignifx-error-CRh89KUJ.js.map +0 -1
- package/dist/material-plugin-Cfw_h_Mg.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as setMeshReceiveShadows, D as setMeshId, E as setMeshBounds, M as setMeshSubtreeVisible, O as setMeshMaterial, T as removeMeshFromScene, Y as tagNode, d as cloneMeshUnderNode, j as setMeshRenderOrder, k as setMeshPickable, l as Vec3, u as addMeshToScene, x as detachMeshBounds } from "./vec3-
|
|
1
|
+
import { A as setMeshReceiveShadows, D as setMeshId, E as setMeshBounds, M as setMeshSubtreeVisible, O as setMeshMaterial, T as removeMeshFromScene, Y as tagNode, d as cloneMeshUnderNode, j as setMeshRenderOrder, k as setMeshPickable, l as Vec3, u as addMeshToScene, x as detachMeshBounds } from "./vec3-T2PasQZv.js";
|
|
2
2
|
import { clearThinInstanceLodPartner, enableThinInstanceDynamicDrawCount, enableThinInstanceGpuCulling, enableThinInstanceWorldBounds, flushThinInstances, setThinInstanceColors, setThinInstanceCount, setThinInstanceCullBoundsPad, setThinInstanceDrawCount, setThinInstanceLodPartner, setThinInstances } from "@babylonjs/lite";
|
|
3
3
|
//#region src/lite/gpu/thin-instances.ts
|
|
4
4
|
/**
|
|
@@ -762,4 +762,4 @@ function asMesh(node) {
|
|
|
762
762
|
//#endregion
|
|
763
763
|
export { InstancedMeshInstance, createInstancedMesh, releaseInstancedMesh };
|
|
764
764
|
|
|
765
|
-
//# sourceMappingURL=instanced-mesh-instance-
|
|
765
|
+
//# sourceMappingURL=instanced-mesh-instance-DYwH0vLi.js.map
|
package/dist/{instanced-mesh-instance-gguMoIeZ.js.map → instanced-mesh-instance-DYwH0vLi.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instanced-mesh-instance-gguMoIeZ.js","names":["setThinInstances","setThinInstanceCount","flushThinInstances","setThinInstanceColors","enableThinInstanceGpuCulling","setThinInstanceCullBoundsPad","enableThinInstanceWorldBounds","enableThinInstanceDynamicDrawCount","setThinInstanceLodPartner","clearThinInstanceLodPartner"],"sources":["../src/lite/gpu/thin-instances.ts","../src/render/gpu/instanced-mesh-instance.ts"],"sourcesContent":["import {\n clearThinInstanceLodPartner as liteClearThinInstanceLodPartner,\n enableThinInstanceDynamicDrawCount as liteEnableThinInstanceDynamicDrawCount,\n enableThinInstanceGpuCulling as liteEnableThinInstanceGpuCulling,\n enableThinInstanceWorldBounds as liteEnableThinInstanceWorldBounds,\n flushThinInstances as liteFlushThinInstances,\n setThinInstanceColors as liteSetThinInstanceColors,\n setThinInstanceCount as liteSetThinInstanceCount,\n setThinInstanceCullBoundsPad as liteSetThinInstanceCullBoundsPad,\n setThinInstanceDrawCount as liteSetThinInstanceDrawCount,\n setThinInstanceLodPartner as liteSetThinInstanceLodPartner,\n setThinInstances as liteSetThinInstances,\n} from \"@babylonjs/lite\";\nimport type { Mesh } from \"@babylonjs/lite\";\n\n/**\n * Thin-instance half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §2.3,\n * `docs/plan/2026-09-terrain-particles-shaders.md` §3.5). Everything here is `@internal` and needs a\n * WebGPU device, so the browser project is what covers it.\n *\n * Lite fixes the order these must be called in, and both the culling opt-in and the LOD pairing only\n * take effect through the renderable `registerScene` compiles:\n *\n * 1. {@link setThinInstances} — its `count` argument becomes `_capacity`, and the GPU buffer is\n * sized `_capacity * 64` bytes for the life of the mesh, so pass the **capacity** here once and\n * lower the active count with {@link setThinInstanceCount} straight afterwards.\n * 2. {@link enableThinInstanceWorldBounds} — gives the scene AABB the cloud rather than the\n * prototype. It does not fix a shadow frustum: `computeDirectionalLightMatrix` reads\n * `boundMin`/`boundMax` directly (`lib/shadow/shadow-base.js` 54).\n * 3. {@link enableThinInstanceGpuCulling} — compute-based, opaque only.\n * 4. {@link enableThinInstanceDynamicDrawCount} — indirect draw arguments, so a later count change\n * keeps the cached bundle valid.\n * 5. {@link setThinInstanceLodPartner} — needs both meshes instanced already and stamps both\n * `_clone`, so neither can be cloned afterwards.\n * 6. `addMeshToScene`, and only then `registerScene`.\n *\n * Moving instances costs three different amounts (`lib/mesh/thin-instance.js`):\n * {@link flushThinInstances} re-uploads the whole active range and is the only sub-range-free path\n * Lite exposes; {@link setThinInstanceCount} re-uploads as well; {@link setThinInstanceDrawCount}\n * uploads nothing but throws until the pool has completed one GPU synchronisation, which is private\n * state — {@link trySetThinInstanceDrawCount} asks by trying.\n */\n\n/**\n * Points a mesh at a matrix slab and fixes its capacity.\n *\n * @remarks\n * The `capacity` argument is written straight to Lite's `_capacity`, which sizes the GPU buffer\n * (`_capacity * 64` bytes) once and for good. Only the first `count` matrices are ever read from\n * `matrices`, and Lite clamps its dirty range to the active count\n * (`lib/mesh/thin-instance-gpu.js`), so a slab shorter than `capacity * 16` floats is safe as long\n * as the active count is lowered with {@link setThinInstanceCount} before the next frame.\n *\n * Lite keeps the array by reference and never copies it: the caller owns it, and mutating it is the\n * intended way to move instances, followed by {@link flushThinInstances}.\n *\n * @param mesh - The mesh to instance.\n * @param matrices - 16 floats per instance, column-major, caller-owned.\n * @param capacity - The largest instance count this mesh will ever draw.\n *\n * @internal\n */\nexport function setThinInstances(mesh: Mesh, matrices: Float32Array, capacity: number): void {\n liteSetThinInstances(mesh, matrices, capacity);\n}\n\n/**\n * Sets how many instances draw, re-uploading the active range.\n *\n * @remarks\n * Prefer {@link trySetThinInstanceDrawCount} for a per-frame change: this one marks `[0, count)`\n * dirty as well, so it costs a `count * 64`-byte upload.\n *\n * @param mesh - The instanced mesh.\n * @param count - The active count, at most the capacity.\n *\n * @internal\n */\nexport function setThinInstanceCount(mesh: Mesh, count: number): void {\n liteSetThinInstanceCount(mesh, count);\n}\n\n/**\n * Sets how many instances draw without re-uploading anything, when Lite accepts it.\n *\n * @remarks\n * Lite requires the pool to have completed one full-capacity GPU synchronisation first and throws\n * otherwise (`lib/mesh/thin-instance.js`, `ThrowLiteError(369)`); the state it checks — the matrix\n * buffer's existence and its version — is private, so the only way to ask is to call. The throw\n * happens before anything is mutated, so a refusal leaves the mesh untouched and the caller can\n * fall back to {@link setThinInstanceCount}.\n *\n * @param mesh - The instanced mesh.\n * @param count - The active count, at most the capacity.\n * @returns `true` when the count was changed, `false` when Lite is not ready for a bare count\n * change yet.\n *\n * @internal\n */\nexport function trySetThinInstanceDrawCount(mesh: Mesh, count: number): boolean {\n try {\n liteSetThinInstanceDrawCount(mesh, count);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Marks the whole active matrix range dirty, after the caller mutated the slab in place.\n *\n * @param mesh - The instanced mesh.\n *\n * @internal\n */\nexport function flushThinInstances(mesh: Mesh): void {\n liteFlushThinInstances(mesh);\n}\n\n/**\n * Installs, replaces, or removes the per-instance RGBA colours.\n *\n * @remarks\n * Lite exports no way to *remove* colours: `setThinInstanceColors` only assigns, and the colour\n * version counters that drive the upload are private. `ThinInstanceData.colors` is declared\n * optional and mutable (`index.d.ts` 12985), so clearing is a direct field write —\n * which is enough, because `syncThinInstanceGpuData` skips the colour upload entirely while\n * `colors` is null, and the renderable rebuild the caller triggers is what drops\n * `useThinInstanceColors` from the compiled pipeline.\n *\n * @param mesh - The instanced mesh.\n * @param colors - Four floats per instance (linear RGBA), or `null` to stop reading colours.\n *\n * @internal\n */\nexport function setThinInstanceColors(mesh: Mesh, colors: Float32Array | null): void {\n if (colors !== null) {\n liteSetThinInstanceColors(mesh, colors);\n return;\n }\n const data = mesh.thinInstances;\n if (data !== null && data !== undefined) {\n data.colors = null;\n }\n}\n\n/**\n * Turns compute-based GPU frustum culling on or off for an instanced mesh.\n *\n * @remarks\n * Opaque meshes only, and it must run after {@link setThinInstances} and before the scene is\n * registered.\n *\n * @param mesh - The instanced mesh.\n * @param enabled - Whether the culling compute pass runs.\n *\n * @internal\n */\nexport function enableThinInstanceGpuCulling(mesh: Mesh, enabled: boolean): void {\n liteEnableThinInstanceGpuCulling(mesh, enabled);\n}\n\n/**\n * Grows every instance's GPU-culling sphere by a world-space distance.\n *\n * @remarks\n * The culler builds each sphere from the prototype's vertices (`lib/mesh/thin-instance-gpu-culling.js`\n * 426), so a vertex stage that moves an instance outside it gets the instance culled while it is\n * still on screen. Lite reads the pad on every culled pass (`index.d.ts` 11232), so it can change\n * live. Needs {@link setThinInstances} first.\n *\n * @param mesh - The instanced mesh that owns the culling pass.\n * @param pad - The extra radius in world units; `0` is the exact sphere.\n *\n * @internal\n */\nexport function setThinInstanceCullBoundsPad(mesh: Mesh, pad: number): void {\n liteSetThinInstanceCullBoundsPad(mesh, pad);\n}\n\n/**\n * Makes a mesh's world bounds the union of its instances' boxes rather than the prototype's own.\n *\n * @remarks\n * The hook it installs is `O(count)` per bounds computation, and it clamps to\n * `matrices.length / 16`, so a short slab cannot walk off the end. It is read by\n * `expandWorldAabbForMesh` — the scene camera's extent and PBR's scene-size probe — and **not** by\n * the directional shadow fit; see the module note.\n *\n * @param mesh - The instanced mesh.\n *\n * @internal\n */\nexport function enableThinInstanceWorldBounds(mesh: Mesh): void {\n liteEnableThinInstanceWorldBounds(mesh);\n}\n\n/**\n * Opts a fixed-capacity pool into indirect draw arguments, so a later count change keeps the\n * cached render bundle valid.\n *\n * @param mesh - The instanced mesh.\n *\n * @internal\n */\nexport function enableThinInstanceDynamicDrawCount(mesh: Mesh): void {\n liteEnableThinInstanceDynamicDrawCount(mesh);\n}\n\n/**\n * Where a LOD pairing switches, and how softly.\n *\n * @internal\n */\nexport interface ThinInstanceLodOptions {\n /** The camera distance, in world units, at which an in-frustum instance switches to the partner. */\n readonly distance: number;\n /** The width of the per-instance threshold dither window centred on `distance`; `0` is a hard cut. */\n readonly band: number;\n}\n\n/**\n * Pairs a GPU-culled instanced mesh with a lower-detail partner.\n *\n * @remarks\n * Both meshes must already carry thin instances, and the partner may reference the very same matrix\n * slab. While paired the partner draws **only** the far bucket, and the pairing switches its own\n * GPU culling on. Lite refuses the pairing when either mesh has more than one thin-instance owner,\n * when the partner is already paired, or when the partner carries colours the full mesh does not\n * (`ThrowLiteError(375)`, `(377)`, `(379)`). Calling it again with the same pair re-sets `distance`\n * and `band` live.\n *\n * @param fullMesh - The near mesh, which owns the culling pass.\n * @param lodMesh - The far mesh.\n * @param options - Where the switch happens, and how softly.\n *\n * @internal\n */\nexport function setThinInstanceLodPartner(fullMesh: Mesh, lodMesh: Mesh, options: ThinInstanceLodOptions): void {\n liteSetThinInstanceLodPartner(fullMesh, lodMesh, { distance: options.distance, band: options.band });\n}\n\n/**\n * Dissolves a LOD pairing, returning both meshes to independent rendering.\n *\n * @remarks\n * A no-op when the mesh is not paired, so it is safe on the teardown path.\n *\n * @param fullMesh - The near mesh of the pair.\n *\n * @internal\n */\nexport function clearThinInstanceLodPartner(fullMesh: Mesh): void {\n liteClearThinInstanceLodPartner(fullMesh);\n}\n\n/**\n * How many instances a mesh is currently drawing, as Lite sees it.\n *\n * @remarks\n * The browser tests assert against Lite's own state rather than against the component's copy of it,\n * which is the only way to prove the two agree.\n *\n * @param mesh - The mesh to read.\n * @returns The active count, or `0` when the mesh carries no thin instances.\n *\n * @internal\n */\nexport function thinInstanceCount(mesh: Mesh): number {\n return mesh.thinInstances?.count ?? 0;\n}\n","import {\n addMeshToScene,\n cloneMeshUnderNode,\n detachMeshBounds,\n removeMeshFromScene,\n setMeshBounds,\n setMeshId,\n setMeshMaterial,\n setMeshPickable,\n setMeshReceiveShadows,\n setMeshRenderOrder,\n setMeshSubtreeVisible,\n} from \"../../lite/gpu/mesh.js\";\nimport {\n clearThinInstanceLodPartner,\n enableThinInstanceDynamicDrawCount,\n enableThinInstanceGpuCulling,\n enableThinInstanceWorldBounds,\n flushThinInstances,\n setThinInstanceColors,\n setThinInstanceCount,\n setThinInstanceCullBoundsPad,\n setThinInstanceLodPartner,\n setThinInstances,\n trySetThinInstanceDrawCount,\n} from \"../../lite/gpu/thin-instances.js\";\nimport { tagNode } from \"../../lite/node.js\";\nimport { Vec3 } from \"../../math/vec3.js\";\nimport type { LiteMesh } from \"../../lite/gpu/mesh.js\";\nimport type { LiteMaterial } from \"../../lite/material.js\";\nimport type { LiteSceneNode, NodeTag } from \"../../lite/node.js\";\nimport type { LiteScene } from \"../../lite/scene.js\";\nimport type { Transform } from \"../../transform/transform.js\";\n\n/**\n * One `InstancedMeshRenderer`'s near mesh and its optional LOD partner, and everything that writes\n * to them (`docs/plan/2026-09-terrain-particles-shaders.md` §3.5).\n *\n * Every line needs a WebGPU device, which is why it sits in `src/render/gpu/` — excluded from the\n * Node coverage floor and measured by the browser project — and why the component reaches it through\n * a dynamic `import()` (`../instanced-mesh-support.ts`).\n *\n * `capacity`, `gpuCulling` and the partner's identity are constructor arguments rather than `apply*`\n * methods because Lite fixes all three at `registerScene`; `distance` and `band` may be re-set live\n * by calling the pairing again. Both meshes share one matrix slab, which the pairing requires: it\n * compacts the near mesh's culling output into two buckets drawn from the same matrices.\n *\n * Bounds are the one thing an instanced caster needs that a plain mesh does not.\n * `computeDirectionalLightMatrix` composes `mesh.worldMatrix × mesh.boundMin/boundMax` directly\n * (`lib/shadow/shadow-base.js` 54) and never consults the `_expandWorldBounds` hook\n * `enableThinInstanceWorldBounds` installs, so a cloud left at its prototype's box casts nothing\n * (measured on SwiftShader, 2026-09-08). {@link InstancedMeshInstance.applyBounds} publishes the\n * union of the live placements instead; culling accuracy is unaffected because each instance's cull\n * sphere comes from the real vertices (`lib/mesh/thin-instance-gpu-culling.js` 426).\n */\n\n/** What the component remembers between uploads. Mutated in place, so a frame allocates nothing. */\nexport interface InstancedUploadState {\n /** The whole slab has to be re-pointed and re-uploaded. */\n isSlabDirty: boolean;\n /** The caller mutated the slab in place, so the active range has to be re-uploaded. */\n isRangeDirty: boolean;\n /** The count the meshes were last told about. */\n appliedCount: number;\n /** The capacity the meshes were built with. */\n appliedCapacity: number;\n /** Whether the union bounds have been published at least once. */\n hasAppliedBounds: boolean;\n /** Whether the last upload carried a colour slab. */\n hadColors: boolean;\n}\n\n/** The LOD switch the component declares, as much of it as the adapter reads. */\nexport interface InstancedLodFields {\n /** The camera distance at which an instance switches to the partner. */\n readonly distance: number;\n /** The width of the per-instance dither window. */\n readonly band: number;\n}\n\n/** The LOD partner an instance is built with. */\nexport interface InstancedLodConfig {\n /** The coarse template to clone. */\n readonly template: LiteMesh;\n /** The camera distance, in world units, at which an instance switches to the partner. */\n readonly distance: number;\n /** The width of the per-instance dither window centred on `distance`. */\n readonly band: number;\n}\n\n/** The settings Lite fixes when the meshes are built. */\nexport interface InstancedMeshSettings {\n /** The largest instance count the meshes will ever draw. */\n readonly capacity: number;\n /** Whether the compute culling pass runs. */\n readonly gpuCulling: boolean;\n /** The LOD partner, or `null`. */\n readonly lod: InstancedLodConfig | null;\n}\n\n/**\n * A live instanced mesh, and its LOD partner, in a scene.\n *\n * @internal\n */\nexport class InstancedMeshInstance {\n /** The cloned near mesh, parented under the entity's node. */\n readonly clone: LiteSceneNode;\n\n readonly #lod: LiteSceneNode | null;\n\n #material: LiteMaterial;\n\n #receiveShadows: boolean | null = null;\n\n #renderOrder = Number.NaN;\n\n #pickable: boolean | null = null;\n\n #visible = false;\n\n #lodDistance: number;\n\n #lodBand: number;\n\n readonly #nearBox: Float64Array;\n\n readonly #lodBox: Float64Array | null;\n\n readonly #union = new Float64Array(6);\n\n /** The world-space displacement the culling pad and the bounds were last widened by. */\n #displacement = 0;\n\n /** The same displacement in object units, per axis, as the published bounds carry it. */\n readonly #margin = new Vec3();\n\n /** Scratch for the entity's world scale. */\n readonly #scale = new Vec3();\n\n /**\n * Clones the templates, gives them thin instances, applies the baked settings in Lite's required\n * order, and adds them to the scene.\n *\n * @param scene - The render scene.\n * @param template - The near mesh's template.\n * @param parent - The entity's transform node.\n * @param tag - The owning entity and component, for picking.\n * @param meshId - The string id Lite's light include/exclude sets match on.\n * @param material - The material both meshes draw with. Assigned **before** the meshes join the\n * scene, for the reason `MeshInstance`'s constructor records: `addToScene` buckets a mesh by its\n * material's build group.\n * @param settings - Capacity, GPU culling, and the LOD pairing.\n * @param matrices - The matrix slab, caller-owned and never copied.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n */\n constructor(\n scene: LiteScene,\n template: LiteMesh,\n parent: LiteSceneNode,\n tag: NodeTag,\n meshId: string,\n material: LiteMaterial,\n settings: InstancedMeshSettings,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n ) {\n const clone = cloneMeshUnderNode(template, parent);\n tagNode(clone, tag);\n const mesh = asMesh(clone);\n setMeshId(mesh, meshId);\n setMeshMaterial(mesh, material);\n // A clone shares the template's bound arrays, and `applyBounds` mutates them in place.\n detachMeshBounds(mesh);\n this.#nearBox = readBox(mesh);\n installThinInstances(mesh, settings.capacity, matrices, count, colors);\n enableThinInstanceGpuCulling(mesh, settings.gpuCulling);\n enableThinInstanceDynamicDrawCount(mesh);\n\n const lodConfig = settings.lod;\n let lodClone: LiteSceneNode | null = null;\n let lodBox: Float64Array | null = null;\n if (lodConfig !== null) {\n lodClone = cloneMeshUnderNode(lodConfig.template, parent);\n tagNode(lodClone, tag);\n const lodMesh = asMesh(lodClone);\n setMeshId(lodMesh, `${meshId}#lod`);\n setMeshMaterial(lodMesh, material);\n detachMeshBounds(lodMesh);\n lodBox = readBox(lodMesh);\n installThinInstances(lodMesh, settings.capacity, matrices, count, colors);\n setThinInstanceLodPartner(mesh, lodMesh, { distance: lodConfig.distance, band: lodConfig.band });\n }\n this.#lodBox = lodBox;\n\n this.#material = material;\n this.#lodDistance = lodConfig?.distance ?? 0;\n this.#lodBand = lodConfig?.band ?? 0;\n // Hidden until the first `applyVisible`, so a renderer on an inactive entity never flashes.\n setMeshSubtreeVisible(clone, false);\n addMeshToScene(scene, clone);\n if (lodClone !== null) {\n setMeshSubtreeVisible(lodClone, false);\n addMeshToScene(scene, lodClone);\n }\n this.clone = clone;\n this.#lod = lodClone;\n }\n\n /**\n * Whether the meshes are currently drawn.\n *\n * @returns `true` when Lite's `visible` is set on them.\n */\n get isVisible(): boolean {\n return this.#visible;\n }\n\n /**\n * The near mesh.\n *\n * @returns The clone, typed as a mesh.\n */\n get mesh(): LiteMesh {\n return asMesh(this.clone);\n }\n\n /**\n * The LOD partner.\n *\n * @returns The partner clone, or `null` when the renderer declares no LOD.\n */\n get lodMesh(): LiteMesh | null {\n const lod = this.#lod;\n return lod === null ? null : asMesh(lod);\n }\n\n /**\n * Assigns the material to both meshes, when it changed.\n *\n * @param material - The Lite material to draw with.\n */\n applyMaterial(material: LiteMaterial): void {\n if (material === this.#material) {\n return;\n }\n this.#material = material;\n setMeshMaterial(this.mesh, material);\n const lod = this.lodMesh;\n if (lod !== null) {\n setMeshMaterial(lod, material);\n }\n }\n\n /**\n * Writes the per-mesh flags that changed, to both meshes.\n *\n * @param receiveShadows - Whether shadow maps darken the meshes.\n * @param renderOrder - The sort key within the phase.\n * @param pickable - Whether picking considers the meshes at all.\n */\n applyFlags(receiveShadows: boolean, renderOrder: number, pickable: boolean): void {\n if (this.#receiveShadows !== receiveShadows) {\n this.#receiveShadows = receiveShadows;\n this.#eachMesh(setMeshReceiveShadows, receiveShadows);\n }\n if (this.#renderOrder !== renderOrder) {\n this.#renderOrder = renderOrder;\n this.#eachMesh(setMeshRenderOrder, renderOrder);\n }\n if (this.#pickable !== pickable) {\n this.#pickable = pickable;\n this.#eachMesh(setMeshPickable, pickable);\n }\n }\n\n /**\n * Re-sets the LOD switch distance and dither band, when either changed.\n *\n * @param distance - The camera distance at which an instance switches to the partner.\n * @param band - The width of the per-instance dither window centred on `distance`.\n */\n applyLod(distance: number, band: number): void {\n const lod = this.lodMesh;\n if (lod === null || (distance === this.#lodDistance && band === this.#lodBand)) {\n return;\n }\n this.#lodDistance = distance;\n this.#lodBand = band;\n setThinInstanceLodPartner(this.mesh, lod, { distance, band });\n }\n\n /**\n * Shows or hides both meshes, when the state changed.\n *\n * @param visible - `entity.activeInHierarchy && component.enabled`.\n */\n applyVisible(visible: boolean): void {\n if (visible === this.#visible) {\n return;\n }\n this.#visible = visible;\n setMeshSubtreeVisible(this.clone, visible);\n const lod = this.#lod;\n if (lod !== null) {\n setMeshSubtreeVisible(lod, visible);\n }\n }\n\n /**\n * Re-points both meshes at a matrix slab and re-uploads the active range.\n *\n * @param capacity - The capacity the meshes were built with; re-stating it keeps `_capacity`\n * unchanged, which is what stops Lite from re-creating the GPU buffer.\n * @param matrices - The slab, caller-owned.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n */\n applySlab(capacity: number, matrices: Float32Array, count: number, colors: Float32Array | null): void {\n installThinInstances(this.mesh, capacity, matrices, count, colors);\n const lod = this.lodMesh;\n if (lod !== null) {\n installThinInstances(lod, capacity, matrices, count, colors);\n }\n }\n\n /**\n * Changes how many instances draw, by the cheapest route Lite accepts.\n *\n * @param count - The active count, at most the capacity.\n */\n applyCount(count: number): void {\n applyMeshCount(this.mesh, count);\n const lod = this.lodMesh;\n if (lod !== null) {\n applyMeshCount(lod, count);\n }\n }\n\n /**\n * Marks the whole active range dirty, after the caller mutated the slab in place.\n *\n * @param colors - The colour slab, when the renderer has one, so its own dirty range moves too.\n */\n flush(colors: Float32Array | null): void {\n flushThinInstances(this.mesh);\n const lod = this.lodMesh;\n if (lod !== null) {\n flushThinInstances(lod);\n }\n if (colors !== null) {\n setThinInstanceColors(this.mesh, colors);\n if (lod !== null) {\n setThinInstanceColors(lod, colors);\n }\n }\n }\n\n /**\n * Publishes the union of the live instance placements as both meshes' object-local bounds, so a\n * directional light's shadow frustum is fitted to the cloud rather than to the prototype.\n *\n * @remarks\n * `O(count)`, allocation-free, and worth paying only for a caster — see the module note. A count\n * of zero restores the prototype's own box, so an empty cloud does not report an infinite one.\n *\n * @param matrices - The live matrix slab.\n * @param count - How many instances are drawn.\n */\n applyBounds(matrices: Float32Array, count: number): void {\n const near = this.#nearBox;\n const lodBox = this.#lodBox;\n const lod = this.lodMesh;\n const margin = this.#margin;\n if (count <= 0) {\n writeBox(this.mesh, near, margin);\n if (lod !== null && lodBox !== null) {\n writeBox(lod, lodBox, margin);\n }\n return;\n }\n const union = this.#union;\n unionOfPlacements(matrices, count, near, union);\n writeBox(this.mesh, union, margin);\n if (lod !== null && lodBox !== null) {\n unionOfPlacements(matrices, count, lodBox, union);\n writeBox(lod, union, margin);\n }\n }\n\n /**\n * Widens both meshes for a vertex stage that moves vertices up to `displacement` metres: the GPU\n * culler pads every instance's sphere, and the bounds published for a shadow frustum grow too.\n *\n * @remarks\n * The culling pad is world-space already. The bounds are object-local, so each axis is divided by\n * the entity's world scale along it. A change clears `state.hasAppliedBounds`, so the next\n * {@link InstancedMeshInstance.sync} re-publishes them.\n *\n * @param state - The component's upload state.\n * @param displacement - The material's displacement, in world metres.\n * @param transform - The entity's transform, whose world scale the meshes inherit.\n */\n applyDisplacement(state: InstancedUploadState, displacement: number, transform: Transform): void {\n if (displacement !== this.#displacement) {\n this.#displacement = displacement;\n // Only the near mesh runs the culling pass; the partner draws from its output.\n setThinInstanceCullBoundsPad(this.mesh, displacement);\n }\n const scale = this.#scale;\n if (displacement > 0) {\n transform.lossyScaleToRef(scale);\n }\n const x = objectMargin(displacement, scale.x);\n const y = objectMargin(displacement, scale.y);\n const z = objectMargin(displacement, scale.z);\n const margin = this.#margin;\n if (x !== margin.x || y !== margin.y || z !== margin.z) {\n margin.set(x, y, z);\n state.hasAppliedBounds = false;\n }\n }\n\n /**\n * Writes everything the component changed since the last frame onto both meshes.\n *\n * @param state - The component's upload state, mutated in place.\n * @param material - The material both meshes draw with.\n * @param receiveShadows - Whether shadow maps darken them.\n * @param renderOrder - The sort key within the phase.\n * @param pickable - Whether picking considers them.\n * @param lod - The LOD record, whose `distance` and `band` Lite re-applies live; `null` for none.\n * @param matrices - The caller-owned matrix slab.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n * @param castShadows - Whether the union bounds have to be published for a shadow frustum.\n * @param visible - `entity.activeInHierarchy && component.enabled`.\n * @returns `true` when the compiled pipeline has to change, which only a colour slab arriving or\n * leaving does.\n */\n sync(\n state: InstancedUploadState,\n material: LiteMaterial,\n receiveShadows: boolean,\n renderOrder: number,\n pickable: boolean,\n lod: InstancedLodFields | null,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n castShadows: boolean,\n visible: boolean,\n ): boolean {\n this.applyMaterial(material);\n this.applyFlags(receiveShadows, renderOrder, pickable);\n if (lod !== null) {\n this.applyLod(lod.distance, lod.band);\n }\n let renderablesChanged = false;\n let placementsMoved = false;\n if (state.isSlabDirty) {\n state.isSlabDirty = false;\n state.isRangeDirty = false;\n this.applySlab(state.appliedCapacity, matrices, count, colors);\n state.appliedCount = count;\n placementsMoved = true;\n const hasColors = colors !== null;\n renderablesChanged = hasColors !== state.hadColors;\n state.hadColors = hasColors;\n } else {\n if (state.isRangeDirty) {\n state.isRangeDirty = false;\n this.flush(colors);\n placementsMoved = true;\n }\n if (count !== state.appliedCount) {\n state.appliedCount = count;\n this.applyCount(count);\n placementsMoved = true;\n }\n }\n // Only a caster pays the `O(count)` bounds pass, and only in a frame whose placements moved.\n if (castShadows && (placementsMoved || !state.hasAppliedBounds)) {\n state.hasAppliedBounds = true;\n this.applyBounds(matrices, count);\n }\n this.applyVisible(visible);\n return renderablesChanged;\n }\n\n /**\n * Appends both meshes to a shadow caster list, when the renderer casts and they are drawn.\n *\n * @param castShadows - Whether the renderer casts.\n * @param out - The caster list being built.\n */\n collectCasters(castShadows: boolean, out: LiteMesh[]): void {\n if (!castShadows || !this.#visible) {\n return;\n }\n out.push(this.mesh);\n const lod = this.lodMesh;\n if (lod !== null) {\n out.push(lod);\n }\n }\n\n /**\n * Dissolves the LOD pairing and removes both meshes from the scene, releasing their share of the\n * templates' buffers.\n *\n * @param scene - The render scene.\n */\n destroy(scene: LiteScene): void {\n const lod = this.#lod;\n if (lod !== null) {\n clearThinInstanceLodPartner(this.mesh);\n removeMeshFromScene(scene, lod);\n }\n removeMeshFromScene(scene, this.clone);\n }\n\n /**\n * Runs a per-mesh Lite setter over the near mesh and the partner.\n *\n * @typeParam T - The setter's value type.\n * @param write - The adapter function to call.\n * @param value - What to write.\n */\n #eachMesh<T>(write: (mesh: LiteMesh, value: T) => void, value: T): void {\n write(this.mesh, value);\n const lod = this.lodMesh;\n if (lod !== null) {\n write(lod, value);\n }\n }\n}\n\n/**\n * Builds the live meshes, filling in the LOD pairing when both templates exist.\n *\n * @param scene - The render scene.\n * @param template - The near mesh's template.\n * @param lodTemplate - The coarse template, or `null`.\n * @param lod - The LOD record the component declares, or `null`.\n * @param parent - The entity's transform node.\n * @param tag - The owning entity and component, for picking.\n * @param meshId - The string id Lite's light include/exclude sets match on.\n * @param material - The material both meshes draw with.\n * @param capacity - The largest instance count the meshes will ever draw.\n * @param gpuCulling - Whether the compute culling pass runs.\n * @param matrices - The matrix slab.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n * @returns The instance.\n *\n * @internal\n */\nexport function createInstancedMesh(\n scene: LiteScene,\n template: LiteMesh,\n lodTemplate: LiteMesh | null,\n lod: InstancedLodFields | null,\n parent: LiteSceneNode,\n tag: NodeTag,\n meshId: string,\n material: LiteMaterial,\n capacity: number,\n gpuCulling: boolean,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n): InstancedMeshInstance {\n const pairing: InstancedLodConfig | null =\n lodTemplate === null || lod === null ? null : { template: lodTemplate, distance: lod.distance, band: lod.band };\n return new InstancedMeshInstance(\n scene,\n template,\n parent,\n tag,\n meshId,\n material,\n { capacity, gpuCulling, lod: pairing },\n matrices,\n count,\n colors,\n );\n}\n\n/**\n * Removes the meshes from the scene, when there are any.\n *\n * @param instance - The live meshes, or `null`.\n * @param scene - The render scene.\n * @returns `true` when something left the scene.\n *\n * @internal\n */\nexport function releaseInstancedMesh(instance: InstancedMeshInstance | null, scene: LiteScene): boolean {\n if (instance === null) {\n return false;\n }\n instance.destroy(scene);\n return true;\n}\n\n/**\n * Gives one mesh its thin instances in the order Lite requires, at a fixed capacity.\n *\n * @remarks\n * `setThinInstances` is handed the **capacity** so that `_capacity` — and the GPU buffer it sizes —\n * never moves; the active count is then lowered in the same breath, before any frame can read the\n * range in between (`src/lite/gpu/thin-instances.ts`).\n *\n * @param mesh - The mesh to instance.\n * @param capacity - The capacity to fix.\n * @param matrices - The slab, caller-owned.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n */\nfunction installThinInstances(\n mesh: LiteMesh,\n capacity: number,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n): void {\n setThinInstances(mesh, matrices, capacity);\n setThinInstanceCount(mesh, count);\n setThinInstanceColors(mesh, colors);\n enableThinInstanceWorldBounds(mesh);\n}\n\n/**\n * Changes one mesh's active count without re-uploading when Lite allows it, and with a re-upload\n * when it does not.\n *\n * @param mesh - The instanced mesh.\n * @param count - The active count.\n */\nfunction applyMeshCount(mesh: LiteMesh, count: number): void {\n if (!trySetThinInstanceDrawCount(mesh, count)) {\n setThinInstanceCount(mesh, count);\n }\n}\n\n/**\n * Reads a mesh's object-local box into six numbers.\n *\n * @remarks\n * A mesh built by any Lite factory carries bounds; the fallback half-metre cube is the same default\n * `computeDirectionalLightMatrix` uses for a mesh that does not\n * (`lib/shadow/shadow-base.js` 62).\n *\n * @param mesh - The mesh to read.\n * @returns `minX, minY, minZ, maxX, maxY, maxZ`.\n */\nfunction readBox(mesh: LiteMesh): Float64Array {\n const min = mesh.boundMin ?? [-0.5, -0.5, -0.5];\n const max = mesh.boundMax ?? [0.5, 0.5, 0.5];\n return Float64Array.of(min[0], min[1], min[2], max[0], max[1], max[2]);\n}\n\n/**\n * Writes a six-number box back onto a mesh, grown by a margin on every side.\n *\n * @param mesh - The mesh to re-bound.\n * @param box - `minX, minY, minZ, maxX, maxY, maxZ`.\n * @param margin - How far to grow each axis, in object units.\n */\nfunction writeBox(mesh: LiteMesh, box: Float64Array, margin: Vec3): void {\n setMeshBounds(\n mesh,\n (box[0] ?? 0) - margin.x,\n (box[1] ?? 0) - margin.y,\n (box[2] ?? 0) - margin.z,\n (box[3] ?? 0) + margin.x,\n (box[4] ?? 0) + margin.y,\n (box[5] ?? 0) + margin.z,\n );\n}\n\n/**\n * Converts a world-space margin into the object-space margin along one axis.\n *\n * @param margin - The margin, in world metres.\n * @param scale - The entity's world scale along the axis.\n * @returns The margin in object units; `0` for no margin or a collapsed axis.\n */\nfunction objectMargin(margin: number, scale: number): number {\n return margin > 0 && scale > 1e-9 ? margin / scale : 0;\n}\n\n/**\n * The axis-aligned union of a prototype box placed under every live instance matrix.\n *\n * @remarks\n * The same oriented-box-to-AABB composition Lite's own\n * `expandThinInstanceWorldBounds` uses, minus the world matrix — because `Mesh.boundMin`/`boundMax`\n * are documented to be **object-local**, the frame `worldMatrix` maps out of. Degenerate matrices\n * are skipped, exactly as Lite skips them, so a slot that has not been written yet does not drag\n * the box to the origin.\n *\n * @param matrices - The slab, 16 column-major floats per instance.\n * @param count - How many instances to consider.\n * @param box - The prototype's own box.\n * @param out - Receives `minX, minY, minZ, maxX, maxY, maxZ`.\n */\nfunction unionOfPlacements(matrices: Float32Array, count: number, box: Float64Array, out: Float64Array): void {\n const centreX = ((box[0] ?? 0) + (box[3] ?? 0)) * 0.5;\n const centreY = ((box[1] ?? 0) + (box[4] ?? 0)) * 0.5;\n const centreZ = ((box[2] ?? 0) + (box[5] ?? 0)) * 0.5;\n const extentX = ((box[3] ?? 0) - (box[0] ?? 0)) * 0.5;\n const extentY = ((box[4] ?? 0) - (box[1] ?? 0)) * 0.5;\n const extentZ = ((box[5] ?? 0) - (box[2] ?? 0)) * 0.5;\n out[0] = Number.POSITIVE_INFINITY;\n out[1] = Number.POSITIVE_INFINITY;\n out[2] = Number.POSITIVE_INFINITY;\n out[3] = Number.NEGATIVE_INFINITY;\n out[4] = Number.NEGATIVE_INFINITY;\n out[5] = Number.NEGATIVE_INFINITY;\n const usable = Math.min(count, Math.floor(matrices.length / 16));\n let placed = 0;\n for (let index = 0; index < usable; index += 1) {\n const base = index * 16;\n let scale = 0;\n for (let element = 0; element < 12; element += 1) {\n if (element % 4 !== 3) {\n scale += Math.abs(matrices[base + element] ?? 0);\n }\n }\n if (scale < 1e-9) {\n continue;\n }\n placed += 1;\n for (let row = 0; row < 3; row += 1) {\n const m0 = matrices[base + row] ?? 0;\n const m1 = matrices[base + 4 + row] ?? 0;\n const m2 = matrices[base + 8 + row] ?? 0;\n const centre = (matrices[base + 12 + row] ?? 0) + m0 * centreX + m1 * centreY + m2 * centreZ;\n const radius = Math.abs(m0) * extentX + Math.abs(m1) * extentY + Math.abs(m2) * extentZ;\n const low = centre - radius;\n const high = centre + radius;\n if (low < (out[row] ?? 0)) {\n out[row] = low;\n }\n if (high > (out[row + 3] ?? 0)) {\n out[row + 3] = high;\n }\n }\n }\n if (placed === 0) {\n out.set(box);\n }\n}\n\n/**\n * Narrows a cloned subtree root to a mesh.\n *\n * @remarks\n * The same boundary assertion `MeshInstance` makes, for the same reason: `cloneTransformNode` is\n * typed as returning the wider `SceneNode` because it also clones plain transform nodes, and the\n * clone of a mesh is a mesh (coding standards §5.2).\n *\n * @param node - The clone.\n * @returns The same object, typed as a mesh.\n */\nfunction asMesh(node: LiteSceneNode): LiteMesh {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see the note above.\n return node as LiteMesh;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgBA,mBAAiB,MAAY,UAAwB,UAAwB;CAC3F,iBAAqB,MAAM,UAAU,QAAQ;AAC/C;;;;;;;;;;;;;AAcA,SAAgBC,uBAAqB,MAAY,OAAqB;CACpE,qBAAyB,MAAM,KAAK;AACtC;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,4BAA4B,MAAY,OAAwB;CAC9E,IAAI;EACF,yBAA6B,MAAM,KAAK;EACxC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;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UAAU,KAAK,IAAI,EAAE,IAAI;GAChF,MAAM,MAAM,SAAS;GACrB,MAAM,OAAO,SAAS;GACtB,IAAI,OAAO,IAAI,QAAQ,IACrB,IAAI,OAAO;GAEb,IAAI,QAAQ,IAAI,MAAM,MAAM,IAC1B,IAAI,MAAM,KAAK;EAEnB;CACF;CACA,IAAI,WAAW,GACb,IAAI,IAAI,GAAG;AAEf;;;;;;;;;;;;AAaA,SAAS,OAAO,MAA+B;CAE7C,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"instanced-mesh-instance-DYwH0vLi.js","names":["setThinInstances","setThinInstanceCount","flushThinInstances","setThinInstanceColors","enableThinInstanceGpuCulling","setThinInstanceCullBoundsPad","enableThinInstanceWorldBounds","enableThinInstanceDynamicDrawCount","setThinInstanceLodPartner","clearThinInstanceLodPartner"],"sources":["../src/lite/gpu/thin-instances.ts","../src/render/gpu/instanced-mesh-instance.ts"],"sourcesContent":["import {\n clearThinInstanceLodPartner as liteClearThinInstanceLodPartner,\n enableThinInstanceDynamicDrawCount as liteEnableThinInstanceDynamicDrawCount,\n enableThinInstanceGpuCulling as liteEnableThinInstanceGpuCulling,\n enableThinInstanceWorldBounds as liteEnableThinInstanceWorldBounds,\n flushThinInstances as liteFlushThinInstances,\n setThinInstanceColors as liteSetThinInstanceColors,\n setThinInstanceCount as liteSetThinInstanceCount,\n setThinInstanceCullBoundsPad as liteSetThinInstanceCullBoundsPad,\n setThinInstanceDrawCount as liteSetThinInstanceDrawCount,\n setThinInstanceLodPartner as liteSetThinInstanceLodPartner,\n setThinInstances as liteSetThinInstances,\n} from \"@babylonjs/lite\";\nimport type { Mesh } from \"@babylonjs/lite\";\n\n/**\n * Thin-instance half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §2.3,\n * `docs/plan/2026-09-terrain-particles-shaders.md` §3.5). Everything here is `@internal` and needs a\n * WebGPU device, so the browser project is what covers it.\n *\n * Lite fixes the order these must be called in, and both the culling opt-in and the LOD pairing only\n * take effect through the renderable `registerScene` compiles:\n *\n * 1. {@link setThinInstances} — its `count` argument becomes `_capacity`, and the GPU buffer is\n * sized `_capacity * 64` bytes for the life of the mesh, so pass the **capacity** here once and\n * lower the active count with {@link setThinInstanceCount} straight afterwards.\n * 2. {@link enableThinInstanceWorldBounds} — gives the scene AABB the cloud rather than the\n * prototype. It does not fix a shadow frustum: `computeDirectionalLightMatrix` reads\n * `boundMin`/`boundMax` directly (`lib/shadow/shadow-base.js` 54).\n * 3. {@link enableThinInstanceGpuCulling} — compute-based, opaque only.\n * 4. {@link enableThinInstanceDynamicDrawCount} — indirect draw arguments, so a later count change\n * keeps the cached bundle valid.\n * 5. {@link setThinInstanceLodPartner} — needs both meshes instanced already and stamps both\n * `_clone`, so neither can be cloned afterwards.\n * 6. `addMeshToScene`, and only then `registerScene`.\n *\n * Moving instances costs three different amounts (`lib/mesh/thin-instance.js`):\n * {@link flushThinInstances} re-uploads the whole active range and is the only sub-range-free path\n * Lite exposes; {@link setThinInstanceCount} re-uploads as well; {@link setThinInstanceDrawCount}\n * uploads nothing but throws until the pool has completed one GPU synchronisation, which is private\n * state — {@link trySetThinInstanceDrawCount} asks by trying.\n */\n\n/**\n * Points a mesh at a matrix slab and fixes its capacity.\n *\n * @remarks\n * The `capacity` argument is written straight to Lite's `_capacity`, which sizes the GPU buffer\n * (`_capacity * 64` bytes) once and for good. Only the first `count` matrices are ever read from\n * `matrices`, and Lite clamps its dirty range to the active count\n * (`lib/mesh/thin-instance-gpu.js`), so a slab shorter than `capacity * 16` floats is safe as long\n * as the active count is lowered with {@link setThinInstanceCount} before the next frame.\n *\n * Lite keeps the array by reference and never copies it: the caller owns it, and mutating it is the\n * intended way to move instances, followed by {@link flushThinInstances}.\n *\n * @param mesh - The mesh to instance.\n * @param matrices - 16 floats per instance, column-major, caller-owned.\n * @param capacity - The largest instance count this mesh will ever draw.\n *\n * @internal\n */\nexport function setThinInstances(mesh: Mesh, matrices: Float32Array, capacity: number): void {\n liteSetThinInstances(mesh, matrices, capacity);\n}\n\n/**\n * Sets how many instances draw, re-uploading the active range.\n *\n * @remarks\n * Prefer {@link trySetThinInstanceDrawCount} for a per-frame change: this one marks `[0, count)`\n * dirty as well, so it costs a `count * 64`-byte upload.\n *\n * @param mesh - The instanced mesh.\n * @param count - The active count, at most the capacity.\n *\n * @internal\n */\nexport function setThinInstanceCount(mesh: Mesh, count: number): void {\n liteSetThinInstanceCount(mesh, count);\n}\n\n/**\n * Sets how many instances draw without re-uploading anything, when Lite accepts it.\n *\n * @remarks\n * Lite requires the pool to have completed one full-capacity GPU synchronisation first and throws\n * otherwise (`lib/mesh/thin-instance.js`, `ThrowLiteError(369)`); the state it checks — the matrix\n * buffer's existence and its version — is private, so the only way to ask is to call. The throw\n * happens before anything is mutated, so a refusal leaves the mesh untouched and the caller can\n * fall back to {@link setThinInstanceCount}.\n *\n * @param mesh - The instanced mesh.\n * @param count - The active count, at most the capacity.\n * @returns `true` when the count was changed, `false` when Lite is not ready for a bare count\n * change yet.\n *\n * @internal\n */\nexport function trySetThinInstanceDrawCount(mesh: Mesh, count: number): boolean {\n try {\n liteSetThinInstanceDrawCount(mesh, count);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Marks the whole active matrix range dirty, after the caller mutated the slab in place.\n *\n * @param mesh - The instanced mesh.\n *\n * @internal\n */\nexport function flushThinInstances(mesh: Mesh): void {\n liteFlushThinInstances(mesh);\n}\n\n/**\n * Installs, replaces, or removes the per-instance RGBA colours.\n *\n * @remarks\n * Lite exports no way to *remove* colours: `setThinInstanceColors` only assigns, and the colour\n * version counters that drive the upload are private. `ThinInstanceData.colors` is declared\n * optional and mutable (`index.d.ts` 12985), so clearing is a direct field write —\n * which is enough, because `syncThinInstanceGpuData` skips the colour upload entirely while\n * `colors` is null, and the renderable rebuild the caller triggers is what drops\n * `useThinInstanceColors` from the compiled pipeline.\n *\n * @param mesh - The instanced mesh.\n * @param colors - Four floats per instance (linear RGBA), or `null` to stop reading colours.\n *\n * @internal\n */\nexport function setThinInstanceColors(mesh: Mesh, colors: Float32Array | null): void {\n if (colors !== null) {\n liteSetThinInstanceColors(mesh, colors);\n return;\n }\n const data = mesh.thinInstances;\n if (data !== null && data !== undefined) {\n data.colors = null;\n }\n}\n\n/**\n * Turns compute-based GPU frustum culling on or off for an instanced mesh.\n *\n * @remarks\n * Opaque meshes only, and it must run after {@link setThinInstances} and before the scene is\n * registered.\n *\n * @param mesh - The instanced mesh.\n * @param enabled - Whether the culling compute pass runs.\n *\n * @internal\n */\nexport function enableThinInstanceGpuCulling(mesh: Mesh, enabled: boolean): void {\n liteEnableThinInstanceGpuCulling(mesh, enabled);\n}\n\n/**\n * Grows every instance's GPU-culling sphere by a world-space distance.\n *\n * @remarks\n * The culler builds each sphere from the prototype's vertices (`lib/mesh/thin-instance-gpu-culling.js`\n * 426), so a vertex stage that moves an instance outside it gets the instance culled while it is\n * still on screen. Lite reads the pad on every culled pass (`index.d.ts` 11232), so it can change\n * live. Needs {@link setThinInstances} first.\n *\n * @param mesh - The instanced mesh that owns the culling pass.\n * @param pad - The extra radius in world units; `0` is the exact sphere.\n *\n * @internal\n */\nexport function setThinInstanceCullBoundsPad(mesh: Mesh, pad: number): void {\n liteSetThinInstanceCullBoundsPad(mesh, pad);\n}\n\n/**\n * Makes a mesh's world bounds the union of its instances' boxes rather than the prototype's own.\n *\n * @remarks\n * The hook it installs is `O(count)` per bounds computation, and it clamps to\n * `matrices.length / 16`, so a short slab cannot walk off the end. It is read by\n * `expandWorldAabbForMesh` — the scene camera's extent and PBR's scene-size probe — and **not** by\n * the directional shadow fit; see the module note.\n *\n * @param mesh - The instanced mesh.\n *\n * @internal\n */\nexport function enableThinInstanceWorldBounds(mesh: Mesh): void {\n liteEnableThinInstanceWorldBounds(mesh);\n}\n\n/**\n * Opts a fixed-capacity pool into indirect draw arguments, so a later count change keeps the\n * cached render bundle valid.\n *\n * @param mesh - The instanced mesh.\n *\n * @internal\n */\nexport function enableThinInstanceDynamicDrawCount(mesh: Mesh): void {\n liteEnableThinInstanceDynamicDrawCount(mesh);\n}\n\n/**\n * Where a LOD pairing switches, and how softly.\n *\n * @internal\n */\nexport interface ThinInstanceLodOptions {\n /** The camera distance, in world units, at which an in-frustum instance switches to the partner. */\n readonly distance: number;\n /** The width of the per-instance threshold dither window centred on `distance`; `0` is a hard cut. */\n readonly band: number;\n}\n\n/**\n * Pairs a GPU-culled instanced mesh with a lower-detail partner.\n *\n * @remarks\n * Both meshes must already carry thin instances, and the partner may reference the very same matrix\n * slab. While paired the partner draws **only** the far bucket, and the pairing switches its own\n * GPU culling on. Lite refuses the pairing when either mesh has more than one thin-instance owner,\n * when the partner is already paired, or when the partner carries colours the full mesh does not\n * (`ThrowLiteError(375)`, `(377)`, `(379)`). Calling it again with the same pair re-sets `distance`\n * and `band` live.\n *\n * @param fullMesh - The near mesh, which owns the culling pass.\n * @param lodMesh - The far mesh.\n * @param options - Where the switch happens, and how softly.\n *\n * @internal\n */\nexport function setThinInstanceLodPartner(fullMesh: Mesh, lodMesh: Mesh, options: ThinInstanceLodOptions): void {\n liteSetThinInstanceLodPartner(fullMesh, lodMesh, { distance: options.distance, band: options.band });\n}\n\n/**\n * Dissolves a LOD pairing, returning both meshes to independent rendering.\n *\n * @remarks\n * A no-op when the mesh is not paired, so it is safe on the teardown path.\n *\n * @param fullMesh - The near mesh of the pair.\n *\n * @internal\n */\nexport function clearThinInstanceLodPartner(fullMesh: Mesh): void {\n liteClearThinInstanceLodPartner(fullMesh);\n}\n\n/**\n * How many instances a mesh is currently drawing, as Lite sees it.\n *\n * @remarks\n * The browser tests assert against Lite's own state rather than against the component's copy of it,\n * which is the only way to prove the two agree.\n *\n * @param mesh - The mesh to read.\n * @returns The active count, or `0` when the mesh carries no thin instances.\n *\n * @internal\n */\nexport function thinInstanceCount(mesh: Mesh): number {\n return mesh.thinInstances?.count ?? 0;\n}\n","import {\n addMeshToScene,\n cloneMeshUnderNode,\n detachMeshBounds,\n removeMeshFromScene,\n setMeshBounds,\n setMeshId,\n setMeshMaterial,\n setMeshPickable,\n setMeshReceiveShadows,\n setMeshRenderOrder,\n setMeshSubtreeVisible,\n} from \"../../lite/gpu/mesh.js\";\nimport {\n clearThinInstanceLodPartner,\n enableThinInstanceDynamicDrawCount,\n enableThinInstanceGpuCulling,\n enableThinInstanceWorldBounds,\n flushThinInstances,\n setThinInstanceColors,\n setThinInstanceCount,\n setThinInstanceCullBoundsPad,\n setThinInstanceLodPartner,\n setThinInstances,\n trySetThinInstanceDrawCount,\n} from \"../../lite/gpu/thin-instances.js\";\nimport { tagNode } from \"../../lite/node.js\";\nimport { Vec3 } from \"../../math/vec3.js\";\nimport type { LiteMesh } from \"../../lite/gpu/mesh.js\";\nimport type { LiteMaterial } from \"../../lite/material.js\";\nimport type { LiteSceneNode, NodeTag } from \"../../lite/node.js\";\nimport type { LiteScene } from \"../../lite/scene.js\";\nimport type { Transform } from \"../../transform/transform.js\";\n\n/**\n * One `InstancedMeshRenderer`'s near mesh and its optional LOD partner, and everything that writes\n * to them (`docs/plan/2026-09-terrain-particles-shaders.md` §3.5).\n *\n * Every line needs a WebGPU device, which is why it sits in `src/render/gpu/` — excluded from the\n * Node coverage floor and measured by the browser project — and why the component reaches it through\n * a dynamic `import()` (`../instanced-mesh-support.ts`).\n *\n * `capacity`, `gpuCulling` and the partner's identity are constructor arguments rather than `apply*`\n * methods because Lite fixes all three at `registerScene`; `distance` and `band` may be re-set live\n * by calling the pairing again. Both meshes share one matrix slab, which the pairing requires: it\n * compacts the near mesh's culling output into two buckets drawn from the same matrices.\n *\n * Bounds are the one thing an instanced caster needs that a plain mesh does not.\n * `computeDirectionalLightMatrix` composes `mesh.worldMatrix × mesh.boundMin/boundMax` directly\n * (`lib/shadow/shadow-base.js` 54) and never consults the `_expandWorldBounds` hook\n * `enableThinInstanceWorldBounds` installs, so a cloud left at its prototype's box casts nothing\n * (measured on SwiftShader, 2026-09-08). {@link InstancedMeshInstance.applyBounds} publishes the\n * union of the live placements instead; culling accuracy is unaffected because each instance's cull\n * sphere comes from the real vertices (`lib/mesh/thin-instance-gpu-culling.js` 426).\n */\n\n/** What the component remembers between uploads. Mutated in place, so a frame allocates nothing. */\nexport interface InstancedUploadState {\n /** The whole slab has to be re-pointed and re-uploaded. */\n isSlabDirty: boolean;\n /** The caller mutated the slab in place, so the active range has to be re-uploaded. */\n isRangeDirty: boolean;\n /** The count the meshes were last told about. */\n appliedCount: number;\n /** The capacity the meshes were built with. */\n appliedCapacity: number;\n /** Whether the union bounds have been published at least once. */\n hasAppliedBounds: boolean;\n /** Whether the last upload carried a colour slab. */\n hadColors: boolean;\n}\n\n/** The LOD switch the component declares, as much of it as the adapter reads. */\nexport interface InstancedLodFields {\n /** The camera distance at which an instance switches to the partner. */\n readonly distance: number;\n /** The width of the per-instance dither window. */\n readonly band: number;\n}\n\n/** The LOD partner an instance is built with. */\nexport interface InstancedLodConfig {\n /** The coarse template to clone. */\n readonly template: LiteMesh;\n /** The camera distance, in world units, at which an instance switches to the partner. */\n readonly distance: number;\n /** The width of the per-instance dither window centred on `distance`. */\n readonly band: number;\n}\n\n/** The settings Lite fixes when the meshes are built. */\nexport interface InstancedMeshSettings {\n /** The largest instance count the meshes will ever draw. */\n readonly capacity: number;\n /** Whether the compute culling pass runs. */\n readonly gpuCulling: boolean;\n /** The LOD partner, or `null`. */\n readonly lod: InstancedLodConfig | null;\n}\n\n/**\n * A live instanced mesh, and its LOD partner, in a scene.\n *\n * @internal\n */\nexport class InstancedMeshInstance {\n /** The cloned near mesh, parented under the entity's node. */\n readonly clone: LiteSceneNode;\n\n readonly #lod: LiteSceneNode | null;\n\n #material: LiteMaterial;\n\n #receiveShadows: boolean | null = null;\n\n #renderOrder = Number.NaN;\n\n #pickable: boolean | null = null;\n\n #visible = false;\n\n #lodDistance: number;\n\n #lodBand: number;\n\n readonly #nearBox: Float64Array;\n\n readonly #lodBox: Float64Array | null;\n\n readonly #union = new Float64Array(6);\n\n /** The world-space displacement the culling pad and the bounds were last widened by. */\n #displacement = 0;\n\n /** The same displacement in object units, per axis, as the published bounds carry it. */\n readonly #margin = new Vec3();\n\n /** Scratch for the entity's world scale. */\n readonly #scale = new Vec3();\n\n /**\n * Clones the templates, gives them thin instances, applies the baked settings in Lite's required\n * order, and adds them to the scene.\n *\n * @param scene - The render scene.\n * @param template - The near mesh's template.\n * @param parent - The entity's transform node.\n * @param tag - The owning entity and component, for picking.\n * @param meshId - The string id Lite's light include/exclude sets match on.\n * @param material - The material both meshes draw with. Assigned **before** the meshes join the\n * scene, for the reason `MeshInstance`'s constructor records: `addToScene` buckets a mesh by its\n * material's build group.\n * @param settings - Capacity, GPU culling, and the LOD pairing.\n * @param matrices - The matrix slab, caller-owned and never copied.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n */\n constructor(\n scene: LiteScene,\n template: LiteMesh,\n parent: LiteSceneNode,\n tag: NodeTag,\n meshId: string,\n material: LiteMaterial,\n settings: InstancedMeshSettings,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n ) {\n const clone = cloneMeshUnderNode(template, parent);\n tagNode(clone, tag);\n const mesh = asMesh(clone);\n setMeshId(mesh, meshId);\n setMeshMaterial(mesh, material);\n // A clone shares the template's bound arrays, and `applyBounds` mutates them in place.\n detachMeshBounds(mesh);\n this.#nearBox = readBox(mesh);\n installThinInstances(mesh, settings.capacity, matrices, count, colors);\n enableThinInstanceGpuCulling(mesh, settings.gpuCulling);\n enableThinInstanceDynamicDrawCount(mesh);\n\n const lodConfig = settings.lod;\n let lodClone: LiteSceneNode | null = null;\n let lodBox: Float64Array | null = null;\n if (lodConfig !== null) {\n lodClone = cloneMeshUnderNode(lodConfig.template, parent);\n tagNode(lodClone, tag);\n const lodMesh = asMesh(lodClone);\n setMeshId(lodMesh, `${meshId}#lod`);\n setMeshMaterial(lodMesh, material);\n detachMeshBounds(lodMesh);\n lodBox = readBox(lodMesh);\n installThinInstances(lodMesh, settings.capacity, matrices, count, colors);\n setThinInstanceLodPartner(mesh, lodMesh, { distance: lodConfig.distance, band: lodConfig.band });\n }\n this.#lodBox = lodBox;\n\n this.#material = material;\n this.#lodDistance = lodConfig?.distance ?? 0;\n this.#lodBand = lodConfig?.band ?? 0;\n // Hidden until the first `applyVisible`, so a renderer on an inactive entity never flashes.\n setMeshSubtreeVisible(clone, false);\n addMeshToScene(scene, clone);\n if (lodClone !== null) {\n setMeshSubtreeVisible(lodClone, false);\n addMeshToScene(scene, lodClone);\n }\n this.clone = clone;\n this.#lod = lodClone;\n }\n\n /**\n * Whether the meshes are currently drawn.\n *\n * @returns `true` when Lite's `visible` is set on them.\n */\n get isVisible(): boolean {\n return this.#visible;\n }\n\n /**\n * The near mesh.\n *\n * @returns The clone, typed as a mesh.\n */\n get mesh(): LiteMesh {\n return asMesh(this.clone);\n }\n\n /**\n * The LOD partner.\n *\n * @returns The partner clone, or `null` when the renderer declares no LOD.\n */\n get lodMesh(): LiteMesh | null {\n const lod = this.#lod;\n return lod === null ? null : asMesh(lod);\n }\n\n /**\n * Assigns the material to both meshes, when it changed.\n *\n * @param material - The Lite material to draw with.\n */\n applyMaterial(material: LiteMaterial): void {\n if (material === this.#material) {\n return;\n }\n this.#material = material;\n setMeshMaterial(this.mesh, material);\n const lod = this.lodMesh;\n if (lod !== null) {\n setMeshMaterial(lod, material);\n }\n }\n\n /**\n * Writes the per-mesh flags that changed, to both meshes.\n *\n * @param receiveShadows - Whether shadow maps darken the meshes.\n * @param renderOrder - The sort key within the phase.\n * @param pickable - Whether picking considers the meshes at all.\n */\n applyFlags(receiveShadows: boolean, renderOrder: number, pickable: boolean): void {\n if (this.#receiveShadows !== receiveShadows) {\n this.#receiveShadows = receiveShadows;\n this.#eachMesh(setMeshReceiveShadows, receiveShadows);\n }\n if (this.#renderOrder !== renderOrder) {\n this.#renderOrder = renderOrder;\n this.#eachMesh(setMeshRenderOrder, renderOrder);\n }\n if (this.#pickable !== pickable) {\n this.#pickable = pickable;\n this.#eachMesh(setMeshPickable, pickable);\n }\n }\n\n /**\n * Re-sets the LOD switch distance and dither band, when either changed.\n *\n * @param distance - The camera distance at which an instance switches to the partner.\n * @param band - The width of the per-instance dither window centred on `distance`.\n */\n applyLod(distance: number, band: number): void {\n const lod = this.lodMesh;\n if (lod === null || (distance === this.#lodDistance && band === this.#lodBand)) {\n return;\n }\n this.#lodDistance = distance;\n this.#lodBand = band;\n setThinInstanceLodPartner(this.mesh, lod, { distance, band });\n }\n\n /**\n * Shows or hides both meshes, when the state changed.\n *\n * @param visible - `entity.activeInHierarchy && component.enabled`.\n */\n applyVisible(visible: boolean): void {\n if (visible === this.#visible) {\n return;\n }\n this.#visible = visible;\n setMeshSubtreeVisible(this.clone, visible);\n const lod = this.#lod;\n if (lod !== null) {\n setMeshSubtreeVisible(lod, visible);\n }\n }\n\n /**\n * Re-points both meshes at a matrix slab and re-uploads the active range.\n *\n * @param capacity - The capacity the meshes were built with; re-stating it keeps `_capacity`\n * unchanged, which is what stops Lite from re-creating the GPU buffer.\n * @param matrices - The slab, caller-owned.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n */\n applySlab(capacity: number, matrices: Float32Array, count: number, colors: Float32Array | null): void {\n installThinInstances(this.mesh, capacity, matrices, count, colors);\n const lod = this.lodMesh;\n if (lod !== null) {\n installThinInstances(lod, capacity, matrices, count, colors);\n }\n }\n\n /**\n * Changes how many instances draw, by the cheapest route Lite accepts.\n *\n * @param count - The active count, at most the capacity.\n */\n applyCount(count: number): void {\n applyMeshCount(this.mesh, count);\n const lod = this.lodMesh;\n if (lod !== null) {\n applyMeshCount(lod, count);\n }\n }\n\n /**\n * Marks the whole active range dirty, after the caller mutated the slab in place.\n *\n * @param colors - The colour slab, when the renderer has one, so its own dirty range moves too.\n */\n flush(colors: Float32Array | null): void {\n flushThinInstances(this.mesh);\n const lod = this.lodMesh;\n if (lod !== null) {\n flushThinInstances(lod);\n }\n if (colors !== null) {\n setThinInstanceColors(this.mesh, colors);\n if (lod !== null) {\n setThinInstanceColors(lod, colors);\n }\n }\n }\n\n /**\n * Publishes the union of the live instance placements as both meshes' object-local bounds, so a\n * directional light's shadow frustum is fitted to the cloud rather than to the prototype.\n *\n * @remarks\n * `O(count)`, allocation-free, and worth paying only for a caster — see the module note. A count\n * of zero restores the prototype's own box, so an empty cloud does not report an infinite one.\n *\n * @param matrices - The live matrix slab.\n * @param count - How many instances are drawn.\n */\n applyBounds(matrices: Float32Array, count: number): void {\n const near = this.#nearBox;\n const lodBox = this.#lodBox;\n const lod = this.lodMesh;\n const margin = this.#margin;\n if (count <= 0) {\n writeBox(this.mesh, near, margin);\n if (lod !== null && lodBox !== null) {\n writeBox(lod, lodBox, margin);\n }\n return;\n }\n const union = this.#union;\n unionOfPlacements(matrices, count, near, union);\n writeBox(this.mesh, union, margin);\n if (lod !== null && lodBox !== null) {\n unionOfPlacements(matrices, count, lodBox, union);\n writeBox(lod, union, margin);\n }\n }\n\n /**\n * Widens both meshes for a vertex stage that moves vertices up to `displacement` metres: the GPU\n * culler pads every instance's sphere, and the bounds published for a shadow frustum grow too.\n *\n * @remarks\n * The culling pad is world-space already. The bounds are object-local, so each axis is divided by\n * the entity's world scale along it. A change clears `state.hasAppliedBounds`, so the next\n * {@link InstancedMeshInstance.sync} re-publishes them.\n *\n * @param state - The component's upload state.\n * @param displacement - The material's displacement, in world metres.\n * @param transform - The entity's transform, whose world scale the meshes inherit.\n */\n applyDisplacement(state: InstancedUploadState, displacement: number, transform: Transform): void {\n if (displacement !== this.#displacement) {\n this.#displacement = displacement;\n // Only the near mesh runs the culling pass; the partner draws from its output.\n setThinInstanceCullBoundsPad(this.mesh, displacement);\n }\n const scale = this.#scale;\n if (displacement > 0) {\n transform.lossyScaleToRef(scale);\n }\n const x = objectMargin(displacement, scale.x);\n const y = objectMargin(displacement, scale.y);\n const z = objectMargin(displacement, scale.z);\n const margin = this.#margin;\n if (x !== margin.x || y !== margin.y || z !== margin.z) {\n margin.set(x, y, z);\n state.hasAppliedBounds = false;\n }\n }\n\n /**\n * Writes everything the component changed since the last frame onto both meshes.\n *\n * @param state - The component's upload state, mutated in place.\n * @param material - The material both meshes draw with.\n * @param receiveShadows - Whether shadow maps darken them.\n * @param renderOrder - The sort key within the phase.\n * @param pickable - Whether picking considers them.\n * @param lod - The LOD record, whose `distance` and `band` Lite re-applies live; `null` for none.\n * @param matrices - The caller-owned matrix slab.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n * @param castShadows - Whether the union bounds have to be published for a shadow frustum.\n * @param visible - `entity.activeInHierarchy && component.enabled`.\n * @returns `true` when the compiled pipeline has to change, which only a colour slab arriving or\n * leaving does.\n */\n sync(\n state: InstancedUploadState,\n material: LiteMaterial,\n receiveShadows: boolean,\n renderOrder: number,\n pickable: boolean,\n lod: InstancedLodFields | null,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n castShadows: boolean,\n visible: boolean,\n ): boolean {\n this.applyMaterial(material);\n this.applyFlags(receiveShadows, renderOrder, pickable);\n if (lod !== null) {\n this.applyLod(lod.distance, lod.band);\n }\n let renderablesChanged = false;\n let placementsMoved = false;\n if (state.isSlabDirty) {\n state.isSlabDirty = false;\n state.isRangeDirty = false;\n this.applySlab(state.appliedCapacity, matrices, count, colors);\n state.appliedCount = count;\n placementsMoved = true;\n const hasColors = colors !== null;\n renderablesChanged = hasColors !== state.hadColors;\n state.hadColors = hasColors;\n } else {\n if (state.isRangeDirty) {\n state.isRangeDirty = false;\n this.flush(colors);\n placementsMoved = true;\n }\n if (count !== state.appliedCount) {\n state.appliedCount = count;\n this.applyCount(count);\n placementsMoved = true;\n }\n }\n // Only a caster pays the `O(count)` bounds pass, and only in a frame whose placements moved.\n if (castShadows && (placementsMoved || !state.hasAppliedBounds)) {\n state.hasAppliedBounds = true;\n this.applyBounds(matrices, count);\n }\n this.applyVisible(visible);\n return renderablesChanged;\n }\n\n /**\n * Appends both meshes to a shadow caster list, when the renderer casts and they are drawn.\n *\n * @param castShadows - Whether the renderer casts.\n * @param out - The caster list being built.\n */\n collectCasters(castShadows: boolean, out: LiteMesh[]): void {\n if (!castShadows || !this.#visible) {\n return;\n }\n out.push(this.mesh);\n const lod = this.lodMesh;\n if (lod !== null) {\n out.push(lod);\n }\n }\n\n /**\n * Dissolves the LOD pairing and removes both meshes from the scene, releasing their share of the\n * templates' buffers.\n *\n * @param scene - The render scene.\n */\n destroy(scene: LiteScene): void {\n const lod = this.#lod;\n if (lod !== null) {\n clearThinInstanceLodPartner(this.mesh);\n removeMeshFromScene(scene, lod);\n }\n removeMeshFromScene(scene, this.clone);\n }\n\n /**\n * Runs a per-mesh Lite setter over the near mesh and the partner.\n *\n * @typeParam T - The setter's value type.\n * @param write - The adapter function to call.\n * @param value - What to write.\n */\n #eachMesh<T>(write: (mesh: LiteMesh, value: T) => void, value: T): void {\n write(this.mesh, value);\n const lod = this.lodMesh;\n if (lod !== null) {\n write(lod, value);\n }\n }\n}\n\n/**\n * Builds the live meshes, filling in the LOD pairing when both templates exist.\n *\n * @param scene - The render scene.\n * @param template - The near mesh's template.\n * @param lodTemplate - The coarse template, or `null`.\n * @param lod - The LOD record the component declares, or `null`.\n * @param parent - The entity's transform node.\n * @param tag - The owning entity and component, for picking.\n * @param meshId - The string id Lite's light include/exclude sets match on.\n * @param material - The material both meshes draw with.\n * @param capacity - The largest instance count the meshes will ever draw.\n * @param gpuCulling - Whether the compute culling pass runs.\n * @param matrices - The matrix slab.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n * @returns The instance.\n *\n * @internal\n */\nexport function createInstancedMesh(\n scene: LiteScene,\n template: LiteMesh,\n lodTemplate: LiteMesh | null,\n lod: InstancedLodFields | null,\n parent: LiteSceneNode,\n tag: NodeTag,\n meshId: string,\n material: LiteMaterial,\n capacity: number,\n gpuCulling: boolean,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n): InstancedMeshInstance {\n const pairing: InstancedLodConfig | null =\n lodTemplate === null || lod === null ? null : { template: lodTemplate, distance: lod.distance, band: lod.band };\n return new InstancedMeshInstance(\n scene,\n template,\n parent,\n tag,\n meshId,\n material,\n { capacity, gpuCulling, lod: pairing },\n matrices,\n count,\n colors,\n );\n}\n\n/**\n * Removes the meshes from the scene, when there are any.\n *\n * @param instance - The live meshes, or `null`.\n * @param scene - The render scene.\n * @returns `true` when something left the scene.\n *\n * @internal\n */\nexport function releaseInstancedMesh(instance: InstancedMeshInstance | null, scene: LiteScene): boolean {\n if (instance === null) {\n return false;\n }\n instance.destroy(scene);\n return true;\n}\n\n/**\n * Gives one mesh its thin instances in the order Lite requires, at a fixed capacity.\n *\n * @remarks\n * `setThinInstances` is handed the **capacity** so that `_capacity` — and the GPU buffer it sizes —\n * never moves; the active count is then lowered in the same breath, before any frame can read the\n * range in between (`src/lite/gpu/thin-instances.ts`).\n *\n * @param mesh - The mesh to instance.\n * @param capacity - The capacity to fix.\n * @param matrices - The slab, caller-owned.\n * @param count - How many instances draw.\n * @param colors - Four floats per instance, or `null`.\n */\nfunction installThinInstances(\n mesh: LiteMesh,\n capacity: number,\n matrices: Float32Array,\n count: number,\n colors: Float32Array | null,\n): void {\n setThinInstances(mesh, matrices, capacity);\n setThinInstanceCount(mesh, count);\n setThinInstanceColors(mesh, colors);\n enableThinInstanceWorldBounds(mesh);\n}\n\n/**\n * Changes one mesh's active count without re-uploading when Lite allows it, and with a re-upload\n * when it does not.\n *\n * @param mesh - The instanced mesh.\n * @param count - The active count.\n */\nfunction applyMeshCount(mesh: LiteMesh, count: number): void {\n if (!trySetThinInstanceDrawCount(mesh, count)) {\n setThinInstanceCount(mesh, count);\n }\n}\n\n/**\n * Reads a mesh's object-local box into six numbers.\n *\n * @remarks\n * A mesh built by any Lite factory carries bounds; the fallback half-metre cube is the same default\n * `computeDirectionalLightMatrix` uses for a mesh that does not\n * (`lib/shadow/shadow-base.js` 62).\n *\n * @param mesh - The mesh to read.\n * @returns `minX, minY, minZ, maxX, maxY, maxZ`.\n */\nfunction readBox(mesh: LiteMesh): Float64Array {\n const min = mesh.boundMin ?? [-0.5, -0.5, -0.5];\n const max = mesh.boundMax ?? [0.5, 0.5, 0.5];\n return Float64Array.of(min[0], min[1], min[2], max[0], max[1], max[2]);\n}\n\n/**\n * Writes a six-number box back onto a mesh, grown by a margin on every side.\n *\n * @param mesh - The mesh to re-bound.\n * @param box - `minX, minY, minZ, maxX, maxY, maxZ`.\n * @param margin - How far to grow each axis, in object units.\n */\nfunction writeBox(mesh: LiteMesh, box: Float64Array, margin: Vec3): void {\n setMeshBounds(\n mesh,\n (box[0] ?? 0) - margin.x,\n (box[1] ?? 0) - margin.y,\n (box[2] ?? 0) - margin.z,\n (box[3] ?? 0) + margin.x,\n (box[4] ?? 0) + margin.y,\n (box[5] ?? 0) + margin.z,\n );\n}\n\n/**\n * Converts a world-space margin into the object-space margin along one axis.\n *\n * @param margin - The margin, in world metres.\n * @param scale - The entity's world scale along the axis.\n * @returns The margin in object units; `0` for no margin or a collapsed axis.\n */\nfunction objectMargin(margin: number, scale: number): number {\n return margin > 0 && scale > 1e-9 ? margin / scale : 0;\n}\n\n/**\n * The axis-aligned union of a prototype box placed under every live instance matrix.\n *\n * @remarks\n * The same oriented-box-to-AABB composition Lite's own\n * `expandThinInstanceWorldBounds` uses, minus the world matrix — because `Mesh.boundMin`/`boundMax`\n * are documented to be **object-local**, the frame `worldMatrix` maps out of. Degenerate matrices\n * are skipped, exactly as Lite skips them, so a slot that has not been written yet does not drag\n * the box to the origin.\n *\n * @param matrices - The slab, 16 column-major floats per instance.\n * @param count - How many instances to consider.\n * @param box - The prototype's own box.\n * @param out - Receives `minX, minY, minZ, maxX, maxY, maxZ`.\n */\nfunction unionOfPlacements(matrices: Float32Array, count: number, box: Float64Array, out: Float64Array): void {\n const centreX = ((box[0] ?? 0) + (box[3] ?? 0)) * 0.5;\n const centreY = ((box[1] ?? 0) + (box[4] ?? 0)) * 0.5;\n const centreZ = ((box[2] ?? 0) + (box[5] ?? 0)) * 0.5;\n const extentX = ((box[3] ?? 0) - (box[0] ?? 0)) * 0.5;\n const extentY = ((box[4] ?? 0) - (box[1] ?? 0)) * 0.5;\n const extentZ = ((box[5] ?? 0) - (box[2] ?? 0)) * 0.5;\n out[0] = Number.POSITIVE_INFINITY;\n out[1] = Number.POSITIVE_INFINITY;\n out[2] = Number.POSITIVE_INFINITY;\n out[3] = Number.NEGATIVE_INFINITY;\n out[4] = Number.NEGATIVE_INFINITY;\n out[5] = Number.NEGATIVE_INFINITY;\n const usable = Math.min(count, Math.floor(matrices.length / 16));\n let placed = 0;\n for (let index = 0; index < usable; index += 1) {\n const base = index * 16;\n let scale = 0;\n for (let element = 0; element < 12; element += 1) {\n if (element % 4 !== 3) {\n scale += Math.abs(matrices[base + element] ?? 0);\n }\n }\n if (scale < 1e-9) {\n continue;\n }\n placed += 1;\n for (let row = 0; row < 3; row += 1) {\n const m0 = matrices[base + row] ?? 0;\n const m1 = matrices[base + 4 + row] ?? 0;\n const m2 = matrices[base + 8 + row] ?? 0;\n const centre = (matrices[base + 12 + row] ?? 0) + m0 * centreX + m1 * centreY + m2 * centreZ;\n const radius = Math.abs(m0) * extentX + Math.abs(m1) * extentY + Math.abs(m2) * extentZ;\n const low = centre - radius;\n const high = centre + radius;\n if (low < (out[row] ?? 0)) {\n out[row] = low;\n }\n if (high > (out[row + 3] ?? 0)) {\n out[row + 3] = high;\n }\n }\n }\n if (placed === 0) {\n out.set(box);\n }\n}\n\n/**\n * Narrows a cloned subtree root to a mesh.\n *\n * @remarks\n * The same boundary assertion `MeshInstance` makes, for the same reason: `cloneTransformNode` is\n * typed as returning the wider `SceneNode` because it also clones plain transform nodes, and the\n * clone of a mesh is a mesh (coding standards §5.2).\n *\n * @param node - The clone.\n * @returns The same object, typed as a mesh.\n */\nfunction asMesh(node: LiteSceneNode): LiteMesh {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see the note above.\n return node as LiteMesh;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgBA,mB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AAG,OAAO,GAAG;GACnC,MAAM,KAAK,SAAS,OAAO,QAAQ;GACnC,MAAM,KAAK,SAAS,OAAO,IAAI,QAAQ;GACvC,MAAM,KAAK,SAAS,OAAO,IAAI,QAAQ;GACvC,MAAM,UAAU,SAAS,OAAO,KAAK,QAAQ,KAAK,KAAK,UAAU,KAAK,UAAU,KAAK;GACrF,MAAM,SAAS,KAAK,IAAI,EAAE,IAAI,UAAU,KAAK,IAAI,EAAE,IAAI,UAAU,KAAK,IAAI,EAAE,IAAI;GAChF,MAAM,MAAM,SAAS;GACrB,MAAM,OAAO,SAAS;GACtB,IAAI,OAAO,IAAI,QAAQ,IACrB,IAAI,OAAO;GAEb,IAAI,QAAQ,IAAI,MAAM,MAAM,IAC1B,IAAI,MAAM,KAAK;EAEnB;CACF;CACA,IAAI,WAAW,GACb,IAAI,IAAI,GAAG;AAEf;;;;;;;;;;;;AAaA,SAAS,OAAO,MAA+B;CAE7C,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-
|
|
1
|
+
import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-RpK-lWwE.js";
|
|
2
2
|
import { u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
|
|
3
3
|
import { createPbrMaterial, createStandardMaterial, markMaterialUboDirty, rebuildMaterial, setPbrAlphaCutoff, setPbrEmissive, setPbrUnlit, setStandardBumpTexture, setStandardEmissiveTexture, setStandardOpacityTexture, setStandardSpecularTexture } from "@babylonjs/lite";
|
|
4
4
|
//#region src/lite/material.ts
|
|
@@ -178,7 +178,7 @@ function markMaterialDirty(material) {
|
|
|
178
178
|
*
|
|
179
179
|
* @remarks
|
|
180
180
|
* Needed after binding or clearing a texture, changing culling, or toggling a sub-feature
|
|
181
|
-
* (`index.d.ts`
|
|
181
|
+
* (`index.d.ts` 11133). `rebuildFrameGraph` is left off so a component can batch several material
|
|
182
182
|
* edits and rebuild the frame graph once.
|
|
183
183
|
*
|
|
184
184
|
* @param scene - The scene the material renders in.
|
|
@@ -482,4 +482,4 @@ function assertUniformType(plugin, binding, type) {
|
|
|
482
482
|
//#endregion
|
|
483
483
|
export { defineMaterialPlugin as a, MATERIAL_ALPHA_MODES as c, createStandardMaterialFromProps as d, markMaterialDirty as f, setPbrMetallicRoughness as g, setPbrBaseColor as h, MATERIAL_PLUGIN_SAMPLER_BUDGET as i, createDefaultMaterial as l, setMaterialAlpha as m, MATERIAL_PLUGIN_DEFAULT_PRIORITY as n, isLiteMaterialPluginPoint as o, rebuildMaterialPipelines as p, MATERIAL_PLUGIN_RESERVED_NAMES as r, uniformComponentCount as s, LITE_MATERIAL_PLUGIN_POINTS as t, createPbrMaterialFromProps as u };
|
|
484
484
|
|
|
485
|
-
//# sourceMappingURL=material-plugin-
|
|
485
|
+
//# sourceMappingURL=material-plugin-CWtV7DkH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"material-plugin-CWtV7DkH.js","names":[],"sources":["../src/lite/material.ts","../src/render/material-plugin.ts"],"sourcesContent":["import {\n createPbrMaterial,\n createStandardMaterial,\n enableMaterialTracking,\n markMaterialUboDirty,\n rebuildMaterial,\n setPbrAlphaCutoff,\n setPbrEmissive,\n setPbrUnlit,\n setStandardBumpTexture,\n setStandardEmissiveTexture,\n setStandardOpacityTexture,\n setStandardSpecularTexture,\n} from \"@babylonjs/lite\";\nimport { assertNever } from \"../errors/ignifx-error.js\";\nimport type { Material, PbrMaterialProps, SceneContext, StandardMaterialProps, Texture2D } from \"@babylonjs/lite\";\n\n/**\n * Material half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §2.6): the three\n * material kinds a `MaterialAsset` can produce, built from plain ignifx props.\n *\n * Everything here is `@internal`, and every colour that reaches it is **linear** — the sRGB decode\n * belongs to the asset layer.\n *\n * ## What a Lite material is (verified against `@babylonjs/lite@1.27.0`)\n *\n * - A material is plain data plus one private `_buildGroup` function; `createPbrMaterial` is\n * literally `{ ...props, _buildGroup, _uboVersion: 0 }` (`lib/material/pbr/pbr-material.js`), so\n * none of these factories touches the GPU and all of them run under the null engine.\n * - **The build group is a per-family singleton.** `getPbrGroupBuilder()`, `getStandardGroupBuilder()`\n * and `getShaderGroupBuilder()` each memoise one function for the whole process\n * (`lib/material/pbr/pbr-material.js`, `lib/material/standard/create-standard-material.js`,\n * `lib/material/shader/shader-material.js` line 123), and a scene keys its renderable groups by\n * that function (`lib/scene/scene-core.js`, `addToScene`). \"Material family\" in\n * `docs/architecture/07-rendering.md` §1.1 therefore means *pbr*, *standard*, *shader* or *node* —\n * **not** an individual material. Only node materials get a per-material builder\n * (`lib/material/node/node-material.js`). This is what makes {@link warmUpMaterialFamilies} in\n * `./gpu/warm-up.ts` cheap: one hidden mesh per family covers every material in it.\n * - Scalar and vector edits only need `markMaterialUboDirty` (`index.d.ts` 6974), which bumps\n * `_uboVersion`. Anything that changes the compiled feature set — binding or clearing a texture,\n * flipping `doubleSided`, changing culling — needs {@link rebuildMaterialPipelines}.\n *\n * ## The custom WGSL family lives elsewhere\n *\n * `createShaderMaterial` and the `setShader*` setters are in `./gpu/shader-material.ts`, not here:\n * this module is statically reachable from every app through the material asset layer, and Babylon\n * Lite exports one barrel, so a static import of the shader factory would put Lite's whole\n * shader-material pipeline in every entry chunk. That module is reached through a dynamic\n * `import()` instead (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1, \"Bundle cost\").\n */\n\n/**\n * The Babylon Lite material a `MaterialAsset` owns, re-exported under an ignifx name\n * (`CONSTITUTION.md` §3.4, coding standards §4).\n *\n * @remarks\n * Unstable; excluded from the stability guarantees of `CONSTITUTION.md` Article IV.\n *\n * @public\n */\nexport type LiteMaterial = Material;\n\n/**\n * A Babylon Lite physically based material, re-exported under an ignifx name.\n *\n * @remarks\n * Unstable; excluded from the stability guarantees of `CONSTITUTION.md` Article IV.\n *\n * @public\n */\nexport type LitePbrMaterial = PbrMaterialProps;\n\n/**\n * A Babylon Lite Babylon-Standard material, re-exported under an ignifx name.\n *\n * @remarks\n * Unstable; excluded from the stability guarantees of `CONSTITUTION.md` Article IV.\n *\n * @public\n */\nexport type LiteStandardMaterial = StandardMaterialProps;\n\n/** glTF's default alpha cutoff, used when a `\"mask\"` material declares none. */\nconst DEFAULT_ALPHA_CUTOFF = 0.5;\n\n/**\n * How a material's alpha channel is interpreted, in glTF's vocabulary, in the order the inspector\n * lists them (`docs/architecture/07-rendering.md` §2.4).\n *\n * @public\n */\nexport const MATERIAL_ALPHA_MODES = [\"opaque\", \"mask\", \"blend\"] as const;\n\n/**\n * The union of the alpha modes a material can declare.\n *\n * @public\n */\nexport type MaterialAlphaMode = (typeof MATERIAL_ALPHA_MODES)[number];\n\n/**\n * The physically based material properties an ignifx `.material.json` declares\n * (`docs/architecture/06-serialization-and-scene-format.md` §6). Every field is optional; an\n * omitted field leaves Lite's own default in place.\n *\n * @internal\n */\nexport interface PbrMaterialInput {\n /** A human-readable name, used for glTF material overrides and diagnostics. */\n readonly name?: string;\n /** Linear base colour and alpha, multiplied with the base colour texture. */\n readonly baseColor?: readonly [number, number, number, number];\n /** The base colour texture. Load it with an sRGB format. */\n readonly baseColorTexture?: Texture2D;\n /** Metallic factor, 0 to 1. */\n readonly metallic?: number;\n /** Roughness factor, 0 to 1. */\n readonly roughness?: number;\n /** The packed occlusion/roughness/metallic texture (glTF `ORM`). */\n readonly metallicRoughnessTexture?: Texture2D;\n /** The tangent-space normal map. */\n readonly normalTexture?: Texture2D;\n /** Normal map strength. */\n readonly normalScale?: number;\n /** Linear emissive colour. */\n readonly emissive?: readonly [number, number, number];\n /** The emissive texture. */\n readonly emissiveTexture?: Texture2D;\n /** A separate occlusion texture, sampled on UV1 when the ORM texture is not used for it. */\n readonly occlusionTexture?: Texture2D;\n /** How strongly ambient occlusion darkens the surface, 0 to 1. */\n readonly occlusionStrength?: number;\n /** How the alpha channel is interpreted. */\n readonly alphaMode?: MaterialAlphaMode;\n /** The cutoff below which a `\"mask\"` material discards a fragment. */\n readonly alphaCutoff?: number;\n /** Overall material alpha, 0 to 1. */\n readonly alpha?: number;\n /** Whether back faces are drawn. */\n readonly doubleSided?: boolean;\n /** Whether lighting is skipped entirely. */\n readonly unlit?: boolean;\n /** How strongly the environment map contributes. */\n readonly environmentIntensity?: number;\n}\n\n/**\n * The Babylon-Standard material properties an ignifx `.material.json` declares, for the cheap\n * non-PBR path (`docs/architecture/07-rendering.md` §2.6).\n *\n * @internal\n */\nexport interface StandardMaterialInput {\n /** A human-readable name. */\n readonly name?: string;\n /** Linear diffuse colour. */\n readonly diffuse?: readonly [number, number, number];\n /** The diffuse texture. */\n readonly diffuseTexture?: Texture2D;\n /** Linear specular colour. */\n readonly specular?: readonly [number, number, number];\n /** Specular exponent; higher values give a tighter highlight. */\n readonly specularPower?: number;\n /** The specular texture. */\n readonly specularTexture?: Texture2D;\n /** Linear emissive colour. */\n readonly emissive?: readonly [number, number, number];\n /** The emissive texture. */\n readonly emissiveTexture?: Texture2D;\n /** The tangent-space normal map. */\n readonly normalTexture?: Texture2D;\n /** The opacity texture. */\n readonly opacityTexture?: Texture2D;\n /** Overall material alpha, 0 to 1. */\n readonly alpha?: number;\n /** The cutoff below which a fragment is discarded. `0` disables the alpha test. */\n readonly alphaCutoff?: number;\n /** Whether back faces are drawn. */\n readonly doubleSided?: boolean;\n /** Whether lighting is skipped entirely. */\n readonly unlit?: boolean;\n}\n\n/**\n * Builds a Lite PBR material from ignifx props.\n *\n * @param input - The declared properties.\n * @returns The material. It holds no GPU resource of its own; the textures it references do.\n *\n * @example\n * ```ts\n * const gold = createPbrMaterialFromProps({ baseColor: [1, 0.77, 0.34, 1], metallic: 1, roughness: 0.25 });\n * ```\n *\n * @internal\n */\nexport function createPbrMaterialFromProps(input: PbrMaterialInput): PbrMaterialProps {\n const props: Partial<PbrMaterialProps> = {};\n if (input.name !== undefined) {\n props.name = input.name;\n }\n if (input.baseColor !== undefined) {\n props.baseColorFactor = [input.baseColor[0], input.baseColor[1], input.baseColor[2], input.baseColor[3]];\n }\n if (input.baseColorTexture !== undefined) {\n props.baseColorTexture = input.baseColorTexture;\n }\n if (input.metallic !== undefined) {\n props.metallicFactor = input.metallic;\n }\n if (input.roughness !== undefined) {\n props.roughnessFactor = input.roughness;\n }\n if (input.metallicRoughnessTexture !== undefined) {\n props.ormTexture = input.metallicRoughnessTexture;\n }\n if (input.normalTexture !== undefined) {\n props.normalTexture = input.normalTexture;\n }\n if (input.normalScale !== undefined) {\n props.normalTextureScale = input.normalScale;\n }\n if (input.emissiveTexture !== undefined) {\n props.emissiveTexture = input.emissiveTexture;\n }\n if (input.occlusionTexture !== undefined) {\n props.occlusionTexture = input.occlusionTexture;\n }\n if (input.occlusionStrength !== undefined) {\n props.occlusionStrength = input.occlusionStrength;\n }\n if (input.alpha !== undefined) {\n props.alpha = input.alpha;\n }\n if (input.doubleSided !== undefined) {\n props.doubleSided = input.doubleSided;\n }\n if (input.environmentIntensity !== undefined) {\n props.environmentIntensity = input.environmentIntensity;\n }\n if (input.alphaMode === \"blend\") {\n props.alphaBlend = true;\n }\n const material = createPbrMaterial(props);\n if (input.alphaMode === \"mask\") {\n setPbrAlphaCutoff(material, input.alphaCutoff ?? DEFAULT_ALPHA_CUTOFF);\n }\n if (input.emissive !== undefined) {\n setPbrEmissive(material, [input.emissive[0], input.emissive[1], input.emissive[2]]);\n }\n if (input.unlit === true) {\n setPbrUnlit(material);\n }\n return material;\n}\n\n/**\n * Builds a Lite Standard material from ignifx props.\n *\n * @param input - The declared properties.\n * @returns The material.\n *\n * @internal\n */\nexport function createStandardMaterialFromProps(input: StandardMaterialInput): StandardMaterialProps {\n const material = createStandardMaterial();\n if (input.name !== undefined) {\n material.name = input.name;\n }\n if (input.diffuse !== undefined) {\n writeTriple(material.diffuseColor, input.diffuse);\n }\n if (input.specular !== undefined) {\n writeTriple(material.specularColor, input.specular);\n }\n if (input.emissive !== undefined) {\n writeTriple(material.emissiveColor, input.emissive);\n }\n if (input.specularPower !== undefined) {\n material.specularPower = input.specularPower;\n }\n if (input.alpha !== undefined) {\n material.alpha = input.alpha;\n }\n if (input.alphaCutoff !== undefined) {\n material.alphaCutOff = input.alphaCutoff;\n }\n if (input.doubleSided !== undefined) {\n material.backFaceCulling = !input.doubleSided;\n }\n if (input.unlit !== undefined) {\n material.disableLighting = input.unlit;\n }\n if (input.diffuseTexture !== undefined) {\n material.diffuseTexture = input.diffuseTexture;\n }\n if (input.specularTexture !== undefined) {\n setStandardSpecularTexture(material, input.specularTexture);\n }\n if (input.emissiveTexture !== undefined) {\n setStandardEmissiveTexture(material, input.emissiveTexture);\n }\n if (input.normalTexture !== undefined) {\n setStandardBumpTexture(material, input.normalTexture);\n }\n if (input.opacityTexture !== undefined) {\n setStandardOpacityTexture(material, input.opacityTexture);\n }\n return material;\n}\n\n/**\n * The material a `MeshRenderer` uses when it declares none: a neutral, fully rough dielectric.\n *\n * @returns A fresh material. Callers share one instance per app rather than one per renderer.\n *\n * @internal\n */\nexport function createDefaultMaterial(): PbrMaterialProps {\n return createPbrMaterialFromProps({\n name: \"ignifx:default\",\n baseColor: [1, 1, 1, 1],\n metallic: 0,\n roughness: 0.9,\n });\n}\n\n/**\n * Replaces a PBR material's linear base colour.\n *\n * @param material - The material to change.\n * @param r - The linear red component.\n * @param g - The linear green component.\n * @param b - The linear blue component.\n * @param a - The alpha component.\n *\n * @internal\n */\nexport function setPbrBaseColor(material: PbrMaterialProps, r: number, g: number, b: number, a: number): void {\n const factor = material.baseColorFactor;\n if (factor === undefined) {\n material.baseColorFactor = [r, g, b, a];\n } else {\n factor[0] = r;\n factor[1] = g;\n factor[2] = b;\n factor[3] = a;\n }\n markMaterialDirty(material);\n}\n\n/**\n * Replaces a PBR material's metallic and roughness factors.\n *\n * @param material - The material to change.\n * @param metallic - The metallic factor, 0 to 1.\n * @param roughness - The roughness factor, 0 to 1.\n *\n * @internal\n */\nexport function setPbrMetallicRoughness(material: PbrMaterialProps, metallic: number, roughness: number): void {\n material.metallicFactor = metallic;\n material.roughnessFactor = roughness;\n markMaterialDirty(material);\n}\n\n/**\n * Replaces a material's overall alpha.\n *\n * @param material - The PBR or Standard material to change.\n * @param alpha - The new alpha, 0 to 1.\n *\n * @internal\n */\nexport function setMaterialAlpha(material: PbrMaterialProps | StandardMaterialProps, alpha: number): void {\n material.alpha = alpha;\n markMaterialDirty(material);\n}\n\n/**\n * Marks a material's uniform block for re-upload on the next frame.\n *\n * @remarks\n * This is the cheap path and covers every scalar, vector, and colour edit. It does **not** cover\n * changes that alter the compiled feature set; those go through {@link rebuildMaterialPipelines}.\n *\n * @param material - The material that changed.\n *\n * @internal\n */\nexport function markMaterialDirty(material: Material): void {\n markMaterialUboDirty(material);\n}\n\n/**\n * Rebuilds the renderables of a material whose compiled feature set changed.\n *\n * @remarks\n * Needed after binding or clearing a texture, changing culling, or toggling a sub-feature\n * (`index.d.ts` 11133). `rebuildFrameGraph` is left off so a component can batch several material\n * edits and rebuild the frame graph once.\n *\n * @param scene - The scene the material renders in.\n * @param material - The material that changed.\n *\n * @internal\n */\nexport function rebuildMaterialPipelines(scene: SceneContext, material: Material): void {\n // Since 1.34 a PBR rebuild in a built scene finishes asynchronously, and Lite reports its failure\n // itself (`lib/material/material-rebuild.js`, `rebuildMaterial`), so nothing is left to await.\n void rebuildMaterial(scene, material);\n}\n\n/**\n * Installs automatic dirty tracking on a material, so property writes mark its uniform block\n * without an explicit {@link markMaterialDirty}.\n *\n * @remarks\n * Lite installs the tracker by rewriting the material's property descriptors, and the module that\n * does it is loaded lazily, so this is asynchronous (`index.d.ts` 4480,\n * `lib/material/observable-material.js`). Opt-in only: it costs an accessor call per write, which\n * the zero-allocation rules (coding standards §7) do not want on every material.\n *\n * @param material - The PBR or Standard material to track.\n * @returns A promise that resolves once the tracker is installed.\n *\n * @internal\n */\nexport function enableMaterialChangeTracking(material: PbrMaterialProps | StandardMaterialProps): Promise<void> {\n return enableMaterialTracking(material);\n}\n\n/**\n * Reports whether Lite will alpha-blend a material declared with this alpha mode.\n *\n * @param mode - The declared alpha mode.\n * @returns `true` for `\"blend\"`, `false` for `\"opaque\"` and `\"mask\"`.\n *\n * @internal\n */\nexport function isBlendedAlphaMode(mode: MaterialAlphaMode): boolean {\n switch (mode) {\n case \"opaque\":\n case \"mask\":\n return false;\n case \"blend\":\n return true;\n default:\n return assertNever(mode, \"material alpha mode\");\n }\n}\n\n/**\n * Writes three components into a Lite colour tuple in place.\n *\n * @param target - The tuple Lite owns.\n * @param source - The values to copy.\n */\nfunction writeTriple(target: [number, number, number], source: readonly [number, number, number]): void {\n target[0] = source[0];\n target[1] = source[1];\n target[2] = source[2];\n}\n","import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { assertNever, IgnifxError } from \"../errors/ignifx-error.js\";\nimport { SHADER_UNIFORM_TYPES } from \"./shader-declaration.js\";\nimport type { ShaderTextureDeclaration, ShaderUniformDeclaration, ShaderUniformType } from \"./shader-declaration.js\";\n\n/**\n * The raw Babylon Lite material-plugin points, as a `@beta` escape hatch\n * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.2, ADR-0024).\n *\n * `@beta` because the meaning of each point is whatever the surrounding Lite template declares at\n * that line; ignifx's stable contract is the three hooks of `./surface-shader.ts`. Four rules read\n * out of `@babylonjs/lite@1.27.0`'s `lib/` on 2026-09-08:\n *\n * - Plugin uniforms and samplers are **fragment-stage only** on both families\n * (`lib/material/plugin/plugin-bridge-shared.js` 99), and there is no vertex helper-function\n * channel, so vertex code may read only attributes, `mesh.world` and the scene block, and must be\n * statements rather than functions.\n * - `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected **twice** — Lite maps it to the two\n * adjacent PBR slots `AI` and `NI` — so its code must be idempotent or guard itself with a flag\n * set at an earlier point, and must declare nothing at statement level.\n * - Only PBR carries `CUSTOM_FRAGMENT_UPDATE_DIFFUSE` after `CUSTOM_FRAGMENT_UPDATE_ALPHA`;\n * Standard's template orders them the other way and has no `AI`/`NI`/`MF` slots.\n * - `roughness` and `metallic` are `let` in the PBR template and cannot be written.\n */\n\n/**\n * The Babylon Lite injection points a {@link MaterialPluginDefinition} may fill in.\n *\n * @remarks\n * The names are Lite's own (`MaterialPluginPoint`, `index.d.ts` 7084) and are taught verbatim,\n * because a plugin's code is written against the template around the point.\n *\n * @beta\n */\nexport const LITE_MATERIAL_PLUGIN_POINTS = [\n \"CUSTOM_FRAGMENT_DEFINITIONS\",\n \"CUSTOM_FRAGMENT_MAIN_BEGIN\",\n \"CUSTOM_FRAGMENT_UPDATE_ALPHA\",\n \"CUSTOM_FRAGMENT_UPDATE_DIFFUSE\",\n \"CUSTOM_FRAGMENT_BEFORE_LIGHTS\",\n \"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\",\n \"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\",\n \"CUSTOM_VERTEX_MAIN_BEGIN\",\n \"CUSTOM_VERTEX_UPDATE_WORLDPOS\",\n \"CUSTOM_VERTEX_MAIN_END\",\n] as const;\n\n/**\n * One of Babylon Lite's ten material-plugin injection points.\n *\n * @beta\n */\nexport type LiteMaterialPluginPoint = (typeof LITE_MATERIAL_PLUGIN_POINTS)[number];\n\n/**\n * The default priority Babylon Lite gives a plugin with none (`index.d.ts` 7057).\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_DEFAULT_PRIORITY = 500;\n\n/**\n * How many `texture`/`sampler` pairs one material's plugins may declare together.\n *\n * @remarks\n * Measured on a device on 2026-09-08 (spike S0.2): a fully textured PBR material — base colour,\n * normal, ORM, emissive — with image-based lighting and one PCF shadow light already binds seven\n * textures and seven samplers of the sixteen per stage that every WebGPU implementation guarantees,\n * SwiftShader included, and Lite requests no higher `requiredLimits`. Nine is what is left, and it\n * drops to eight with a second shadow light and seven with a lightmap, so a material that means to\n * be portable should stay well under the cap.\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_SAMPLER_BUDGET = 9;\n\n/**\n * The WGSL names the PBR and Standard templates already own, which a plugin may not reuse for a\n * uniform field or a sampler.\n *\n * @remarks\n * A plugin's fields land in the host's own uniform block and its samplers in the host's own bind\n * group, so a collision is a duplicate WGSL declaration and the whole material stops compiling with\n * a message that names neither the plugin nor the field. Refusing at attach time is the difference\n * between a sentence and a shader dump. Read from `pbr-template.js` `_baseMaterialUboFields` and\n * `_baseBindings`, and `standard-template.js` `materialStruct` and `_baseBindings`.\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_RESERVED_NAMES: readonly string[] = Object.freeze([\n // Blocks and entry points the templates declare.\n \"material\",\n \"mesh\",\n \"scene\",\n \"lights\",\n \"pluginUbo\",\n \"shadowParams\",\n \"main\",\n // PBR material uniform fields.\n \"environmentIntensity\",\n \"directIntensity\",\n \"reflectance\",\n \"materialAlpha\",\n \"baseColorFactor\",\n \"metallicFactor\",\n \"roughnessFactor\",\n \"normalScale\",\n \"lightFalloffMode\",\n \"anisotropyParams\",\n // PBR samplers.\n \"baseColorTexture\",\n \"baseColorSampler\",\n \"normalTexture\",\n \"normalSampler_\",\n \"ormTexture\",\n \"ormSampler\",\n \"emissiveTexture\",\n \"emissiveSampler\",\n \"specGlossTexture\",\n \"specGlossSampler\",\n // Standard samplers (`standard-template.js` uses two-letter names).\n \"dT\",\n \"dS\",\n \"mat\",\n \"up\",\n]);\n\n/**\n * What a raw material plugin declares: a name, the values and textures it wants beside the host\n * material's own, and the WGSL it injects.\n *\n * @beta\n */\nexport interface MaterialPluginDefinition {\n /** The plugin's identity. It is part of Lite's pipeline cache key, so it must be stable. */\n readonly name: string;\n /** Lower runs first; Lite's own default is {@link MATERIAL_PLUGIN_DEFAULT_PRIORITY}. */\n readonly priority: number;\n /** The uniform fields appended to the host material's uniform block. Fragment stage only. */\n readonly uniforms: readonly ShaderUniformDeclaration[];\n /** The `texture`/`sampler` pairs added to the host material's bind group. Fragment stage only. */\n readonly textures: readonly ShaderTextureDeclaration[];\n /** The WGSL to inject, by point. Vertex points take statements; there are no vertex helpers. */\n readonly code: Readonly<Partial<Record<LiteMaterialPluginPoint, string>>>;\n}\n\n/**\n * The properties {@link defineMaterialPlugin} accepts; everything but `name` and `code` has a\n * default.\n *\n * @beta\n */\nexport interface MaterialPluginDefinitionInit {\n /** The plugin's identity. */\n readonly name: string;\n /** Lower runs first. Defaults to {@link MATERIAL_PLUGIN_DEFAULT_PRIORITY}. */\n readonly priority?: number;\n /** The uniform fields. Defaults to none. */\n readonly uniforms?: readonly ShaderUniformDeclaration[];\n /** The samplers. Defaults to none. */\n readonly textures?: readonly ShaderTextureDeclaration[];\n /** The WGSL to inject, by point. */\n readonly code: Readonly<Partial<Record<LiteMaterialPluginPoint, string>>>;\n}\n\n/** Matches a WGSL identifier. */\nconst IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** Matches a legal plugin name: an identifier, optionally with `.`, `:`, or `-` inside it. */\nconst PLUGIN_NAME = /^[A-Za-z_][A-Za-z0-9_]*(?:[.:-][A-Za-z0-9_]+)*$/;\n\n/**\n * Validates a raw material-plugin declaration and fills in its defaults.\n *\n * @remarks\n * Nothing here reaches a device: the result is plain data that `attachSurfaceShaders` and\n * `attachMaterialPlugin` turn into a Lite plugin. The checks are the ones whose failure would\n * otherwise surface as a WGSL compile error with no mention of the plugin — an empty `code`, a\n * duplicate or reserved binding name, a name that is not a WGSL identifier, an unknown injection\n * point, or more samplers than {@link MATERIAL_PLUGIN_SAMPLER_BUDGET}.\n *\n * The **surface-shader compiler produces one of these**, so a bug in this validation is a bug in\n * every surface shader too, which is why it lives here rather than inside the compiler.\n *\n * @param definition - The declaration.\n * @returns The same declaration with `priority`, `uniforms`, and `textures` filled in.\n * @throws IgnifxError with code `IGX-0723` when `code` fills in no point, `IGX-0712` when a name is\n * not a legal, unique, unreserved WGSL identifier or a point name is unknown, or `IGX-0726` when the\n * plugin alone exceeds the sampler budget.\n *\n * @example\n * ```ts\n * const tint = defineMaterialPlugin({\n * name: \"tint\",\n * code: { CUSTOM_FRAGMENT_UPDATE_ALPHA: \"baseColor = baseColor * vec3<f32>(1.0, 0.5, 0.5);\" },\n * });\n * ```\n *\n * @beta\n */\nexport function defineMaterialPlugin(definition: MaterialPluginDefinitionInit): MaterialPluginDefinition {\n const name = definition.name;\n if (!PLUGIN_NAME.test(name)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${JSON.stringify(name)} is not a legal material-plugin name.`,\n {\n context: { plugin: name, name },\n hint: \"Start with a letter or underscore; letters, digits, underscores, and inner . : - follow.\",\n },\n );\n }\n const points = Object.keys(definition.code);\n let filled = 0;\n for (const point of points) {\n if (!isLiteMaterialPluginPoint(point)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${name} declares no Lite point named ${point}.`, {\n context: { plugin: name, name: point, point },\n hint: `The ten points are ${LITE_MATERIAL_PLUGIN_POINTS.join(\", \")}.`,\n });\n }\n if ((definition.code[point] ?? \"\").trim().length > 0) {\n filled += 1;\n }\n }\n if (filled === 0) {\n throw new IgnifxError(CoreErrorCode.surfaceHookMissing, `${name} injects no WGSL at any Lite point.`, {\n context: { plugin: name, name },\n hint: \"Fill in at least one of the ten points, or do not attach the plugin.\",\n });\n }\n const uniforms = definition.uniforms ?? [];\n const textures = definition.textures ?? [];\n const seen = new Set<string>();\n for (const uniform of uniforms) {\n assertBindingName(name, uniform.name, seen);\n assertUniformType(name, uniform.name, uniform.type);\n }\n for (const texture of textures) {\n assertBindingName(name, texture.name, seen);\n assertBindingName(name, `${texture.name}Sampler`, seen);\n }\n if (textures.length > MATERIAL_PLUGIN_SAMPLER_BUDGET) {\n throw new IgnifxError(\n CoreErrorCode.surfaceSamplerBudgetExceeded,\n `${name} declares ${String(textures.length)} samplers; a material's plugins may declare ${String(MATERIAL_PLUGIN_SAMPLER_BUDGET)} together.`,\n {\n context: { plugin: name, samplers: textures.length, budget: MATERIAL_PLUGIN_SAMPLER_BUDGET },\n hint: \"Pack the maps into fewer textures — an RGBA control map rather than four masks.\",\n },\n );\n }\n return {\n name,\n priority: definition.priority ?? MATERIAL_PLUGIN_DEFAULT_PRIORITY,\n uniforms,\n textures,\n code: definition.code,\n };\n}\n\n/**\n * Whether a string is one of Lite's ten injection points.\n *\n * @param value - The candidate.\n * @returns `true` when Lite accepts it.\n *\n * @beta\n */\nexport function isLiteMaterialPluginPoint(value: string): value is LiteMaterialPluginPoint {\n for (const point of LITE_MATERIAL_PLUGIN_POINTS) {\n if (point === value) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * How many floats one uniform of a declared type occupies on the CPU side.\n *\n * @param type - The declared WGSL type.\n * @returns The component count: 1, 2, 3, 4, or 16.\n *\n * @internal\n */\nexport function uniformComponentCount(type: ShaderUniformType): number {\n switch (type) {\n case \"vec2<f32>\": {\n return 2;\n }\n case \"vec3<f32>\": {\n return 3;\n }\n case \"vec4<f32>\": {\n return 4;\n }\n case \"mat4x4<f32>\": {\n return 16;\n }\n case \"f32\":\n case \"u32\":\n case \"i32\": {\n return 1;\n }\n default: {\n return assertNever(type, \"shader uniform type\");\n }\n }\n}\n\n/**\n * Refuses a binding name that is not a unique, unreserved WGSL identifier.\n *\n * @param plugin - The plugin's name, for the message.\n * @param binding - The candidate name.\n * @param seen - The names already taken by this plugin; the accepted name is added.\n * @throws IgnifxError with code `IGX-0712`.\n */\nfunction assertBindingName(plugin: string, binding: string, seen: Set<string>): void {\n if (!IDENTIFIER.test(binding)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${plugin} declares ${JSON.stringify(binding)}, which is not a WGSL identifier.`,\n { context: { plugin, name: binding }, hint: \"Use letters, digits, and underscores, starting with a letter.\" },\n );\n }\n if (MATERIAL_PLUGIN_RESERVED_NAMES.includes(binding)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${plugin} declares ${binding}, which Babylon Lite's own PBR or Standard shader already owns.`,\n { context: { plugin, name: binding }, hint: \"Rename it; a plugin shares the host material's WGSL namespace.\" },\n );\n }\n if (seen.has(binding)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin} declares ${binding} twice.`, {\n context: { plugin, name: binding },\n hint: \"Every uniform and texture of one plugin needs its own name.\",\n });\n }\n seen.add(binding);\n}\n\n/**\n * Refuses a uniform type Lite's plugin bridge cannot carry.\n *\n * @param plugin - The plugin's name, for the message.\n * @param binding - The uniform's name.\n * @param type - The declared type.\n * @throws IgnifxError with code `IGX-0712`.\n */\nfunction assertUniformType(plugin: string, binding: string, type: ShaderUniformType): void {\n if (!SHADER_UNIFORM_TYPES.includes(type)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin}.${binding} declares the type ${type}.`, {\n context: { plugin, name: binding, type },\n hint: `The plugin uniform types are ${SHADER_UNIFORM_TYPES.join(\", \")}.`,\n });\n }\n}\n"],"mappings":";;;;;AAmFA,MAAM,uBAAuB;;;;;;;AAQ7B,MAAa,uBAAuB;CAAC;CAAU;CAAQ;AAAO;;;;;;;;;;;;;;AAyG9D,SAAgB,2BAA2B,OAA2C;CACpF,MAAM,QAAmC,CAAC;CAC1C,IAAI,MAAM,SAAS,KAAA,GACjB,MAAM,OAAO,MAAM;CAErB,IAAI,MAAM,cAAc,KAAA,GACtB,MAAM,kBAAkB;EAAC,MAAM,UAAU;EAAI,MAAM,UAAU;EAAI,MAAM,UAAU;EAAI,MAAM,UAAU;CAAE;CAEzG,IAAI,MAAM,qBAAqB,KAAA,GAC7B,MAAM,mBAAmB,MAAM;CAEjC,IAAI,MAAM,aAAa,KAAA,GACrB,MAAM,iBAAiB,MAAM;CAE/B,IAAI,MAAM,cAAc,KAAA,GACtB,MAAM,kBAAkB,MAAM;CAEhC,IAAI,MAAM,6BAA6B,KAAA,GACrC,MAAM,aAAa,MAAM;CAE3B,IAAI,MAAM,kBAAkB,KAAA,GAC1B,MAAM,gBAAgB,MAAM;CAE9B,IAAI,MAAM,gBAAgB,KAAA,GACxB,MAAM,qBAAqB,MAAM;CAEnC,IAAI,MAAM,oBAAoB,KAAA,GAC5B,MAAM,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AAM;EAAQ;EAAG,MAAM;CAAgE,CAC9G;CAEF,IAAI,+BAA+B,SAAS,OAAO,GACjD,MAAM,IAAI,YACR,cAAc,sBACd,GAAG,OAAO,YAAY,QAAQ,kEAC9B;EAAE,SAAS;GAAE;GAAQ,MAAM;EAAQ;EAAG,MAAM;CAAiE,CAC/G;CAEF,IAAI,KAAK,IAAI,OAAO,GAClB,MAAM,IAAI,YAAY,cAAc,sBAAsB,GAAG,OAAO,YAAY,QAAQ,UAAU;EAChG,SAAS;GAAE;GAAQ,MAAM;EAAQ;EACjC,MAAM;CACR,CAAC;CAEH,KAAK,IAAI,OAAO;AAClB;;;;;;;;;AAUA,SAAS,kBAAkB,QAAgB,SAAiB,MAA+B;CACzF,IAAI,CAAC,qBAAqB,SAAS,IAAI,GACrC,MAAM,IAAI,YAAY,cAAc,sBAAsB,GAAG,OAAO,GAAG,QAAQ,qBAAqB,KAAK,IAAI;EAC3G,SAAS;GAAE;GAAQ,MAAM;GAAS;EAAK;EACvC,MAAM,gCAAgC,qBAAqB,KAAK,IAAI,EAAE;CACxE,CAAC;AAEL"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { addTask, addToScene, buildFrameGraphTask, createHemisphericLight, createRenderTarget, createRenderTask, createSceneContext, disposeScene, getFrameGraph, getRenderingContexts, onBeforeRender, registerScene, unregisterScene } from "@babylonjs/lite";
|
|
2
|
+
//#region src/lite/gpu/overlay.ts
|
|
3
|
+
/**
|
|
4
|
+
* The render overlay (`docs/architecture/07-rendering.md` §2.10, ADR-0031): a second Lite scene drawn
|
|
5
|
+
* over the finished frame, for an editor's gizmos, selection outlines and other helpers.
|
|
6
|
+
*
|
|
7
|
+
* Everything here needs a device.
|
|
8
|
+
*
|
|
9
|
+
* ## Why core does not call `createUtilityLayer`
|
|
10
|
+
*
|
|
11
|
+
* `createUtilityLayer` (`index.d.ts` 4109) builds its scene with Lite's default render task, and
|
|
12
|
+
* `registerScene` (11268) then fixes that task up against the **last** registered rendering
|
|
13
|
+
* context (`lib/scene/swapchain-overlay.js` 11). Two things go wrong in an ignifx app (editor spike
|
|
14
|
+
* S0.2 §3.2):
|
|
15
|
+
*
|
|
16
|
+
* - When `@ignifx/ui`'s text renderer or `@ignifx/2d`'s sprite renderer was registered after the
|
|
17
|
+
* render scene, it is the last context. It has no frame graph, so Lite configures nothing and the
|
|
18
|
+
* layer's task clears the frame to transparent black.
|
|
19
|
+
* - With MSAA on, Lite borrows the base scene's multisampled colour view, and switches the layer
|
|
20
|
+
* off unless that scene resolves straight into the swapchain (`swapchain-overlay.js` 19-27). With
|
|
21
|
+
* `rendering.features.postProcessing` the render scene resolves into an offscreen target, so the
|
|
22
|
+
* layer never draws.
|
|
23
|
+
*
|
|
24
|
+
* ## What this module builds instead
|
|
25
|
+
*
|
|
26
|
+
* Only public Lite calls:
|
|
27
|
+
*
|
|
28
|
+
* 1. A scene with no default render task (`createSceneContext`, 3663) that shares the render
|
|
29
|
+
* scene's camera, plus the hemispheric light `createUtilityLayer` would add, so Lite's gizmo
|
|
30
|
+
* materials look the same.
|
|
31
|
+
* 2. `registerScene` while its frame graph is **empty**. Lite's fix-up looks for a task that targets
|
|
32
|
+
* the swapchain (`swapchain-overlay.js` 5-7), finds none, and changes nothing.
|
|
33
|
+
* 3. One render task (`createRenderTask`, 3620) added afterwards and recorded with
|
|
34
|
+
* `buildFrameGraphTask` (1501). It draws into the swapchain with `clr: false`, so it keeps the
|
|
35
|
+
* frame's colour, and `sharedRt: true`, so it never builds or frees the swapchain target
|
|
36
|
+
* (`RenderTaskConfig`, 11635). It has a single-sample depth target of its own, which it clears,
|
|
37
|
+
* so helpers draw on top of the scene. It never touches the scene's targets, so the scene's MSAA
|
|
38
|
+
* setting and render path do not matter: it reads whatever the frame's last pass presented.
|
|
39
|
+
*
|
|
40
|
+
* ## Staying last
|
|
41
|
+
*
|
|
42
|
+
* Lite renders the contexts in registration order (`renderFrame`, `lib/engine/engine.js` 246-251),
|
|
43
|
+
* and the 2D and UI extensions register theirs lazily, when the first sprite or text appears. A
|
|
44
|
+
* sprite renderer in `"sprite"` mode clears the frame, so one registered after the overlay would
|
|
45
|
+
* erase it. Each frame the overlay checks `getRenderingContexts` (6921); when a context other than
|
|
46
|
+
* another overlay follows it, it moves itself to the end after the frame: unregister, drop its task
|
|
47
|
+
* so the re-registration again finds no swapchain task, register, and build a fresh task. The frame
|
|
48
|
+
* in between draws no overlay. A move that fails (a lost device, a pipeline that does not compile) is
|
|
49
|
+
* reported and tried again on the next animation frame, {@link MOVE_ATTEMPTS} times in all; after
|
|
50
|
+
* that the overlay stays detached until it is disposed.
|
|
51
|
+
*
|
|
52
|
+
* A screenshot is taken after every context has recorded (`_captureService`, same function), so it
|
|
53
|
+
* includes the overlay.
|
|
54
|
+
*/
|
|
55
|
+
/** The depth/stencil format Lite's own single-sample scene task uses (`lib/scene/scene-core.js` 76-77). */
|
|
56
|
+
const DEPTH_STENCIL_FORMAT = "depth24plus-stencil8";
|
|
57
|
+
/** The name the overlay's task carries in Lite's frame graph and in per-task GPU timings. */
|
|
58
|
+
const OVERLAY_TASK_NAME = "ignifx:overlay";
|
|
59
|
+
/** The light `createUtilityLayer` adds by default (`lib/gizmo/utility-layer.js` 24-36). */
|
|
60
|
+
const LIGHT_INTENSITY = 2;
|
|
61
|
+
/** The ground colour of that light. */
|
|
62
|
+
const LIGHT_GROUND = .5;
|
|
63
|
+
/** How many times a move to the end of the context list is tried before the overlay gives up. */
|
|
64
|
+
const MOVE_ATTEMPTS = 3;
|
|
65
|
+
/**
|
|
66
|
+
* Builds an overlay scene and registers it after every rendering context on the surface.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Call it only after the render scene is registered: the overlay draws after it because it is
|
|
70
|
+
* registered after it.
|
|
71
|
+
*
|
|
72
|
+
* @param engine - The WebGPU engine, which is also the primary surface.
|
|
73
|
+
* @param mainScene - The render scene whose camera the overlay follows.
|
|
74
|
+
* @param callbacks - The owner's peer test, disposal hook and error sink.
|
|
75
|
+
* @returns The overlay, drawing from the next frame.
|
|
76
|
+
* @throws Whatever the first `registerScene` rejects with; the overlay is disposed first.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const overlay = await openOverlayScene(engine, scene, {
|
|
81
|
+
* isPeer: () => false,
|
|
82
|
+
* onDispose: () => {},
|
|
83
|
+
* onError: (error) => console.error(error),
|
|
84
|
+
* });
|
|
85
|
+
* overlay.dispose();
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
async function openOverlayScene(engine, mainScene, callbacks) {
|
|
91
|
+
const overlay = new LiteOverlayScene(engine, mainScene, callbacks);
|
|
92
|
+
try {
|
|
93
|
+
await overlay.attach();
|
|
94
|
+
} catch (error) {
|
|
95
|
+
overlay.dispose();
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return overlay;
|
|
99
|
+
}
|
|
100
|
+
/** The overlay scene, its registration and its place in the context list. */
|
|
101
|
+
var LiteOverlayScene = class {
|
|
102
|
+
lite;
|
|
103
|
+
#engine;
|
|
104
|
+
#scene;
|
|
105
|
+
#callbacks;
|
|
106
|
+
#isDisposed = false;
|
|
107
|
+
#isMoving = false;
|
|
108
|
+
/**
|
|
109
|
+
* Creates the scene, with the light `createUtilityLayer` would add, following the render scene's
|
|
110
|
+
* camera. It is not registered yet.
|
|
111
|
+
*
|
|
112
|
+
* @param engine - The WebGPU engine.
|
|
113
|
+
* @param mainScene - The render scene.
|
|
114
|
+
* @param callbacks - The owner's peer test, disposal hook and error sink.
|
|
115
|
+
*/
|
|
116
|
+
constructor(engine, mainScene, callbacks) {
|
|
117
|
+
const scene = createSceneContext(engine, { defaultRenderTask: false });
|
|
118
|
+
scene.name = OVERLAY_TASK_NAME;
|
|
119
|
+
scene.camera = mainScene.camera;
|
|
120
|
+
const light = createHemisphericLight([
|
|
121
|
+
0,
|
|
122
|
+
1,
|
|
123
|
+
0
|
|
124
|
+
], LIGHT_INTENSITY);
|
|
125
|
+
light.groundColor = [
|
|
126
|
+
LIGHT_GROUND,
|
|
127
|
+
LIGHT_GROUND,
|
|
128
|
+
LIGHT_GROUND
|
|
129
|
+
];
|
|
130
|
+
addToScene(scene, light);
|
|
131
|
+
this.lite = {
|
|
132
|
+
scene,
|
|
133
|
+
mainScene
|
|
134
|
+
};
|
|
135
|
+
this.#engine = engine;
|
|
136
|
+
this.#scene = scene;
|
|
137
|
+
this.#callbacks = callbacks;
|
|
138
|
+
onBeforeRender(scene, () => {
|
|
139
|
+
if (scene.camera !== mainScene.camera) scene.camera = mainScene.camera;
|
|
140
|
+
this.#keepLast();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Registers the scene at the end of the context list and builds its task.
|
|
145
|
+
*
|
|
146
|
+
* @returns A promise that settles once the overlay draws from the next frame.
|
|
147
|
+
*/
|
|
148
|
+
async attach() {
|
|
149
|
+
await registerScene(this.#scene);
|
|
150
|
+
if (this.#isDisposed) return;
|
|
151
|
+
const task = createOverlayTask(this.#engine, this.#scene);
|
|
152
|
+
addTask(this.#scene, task);
|
|
153
|
+
buildFrameGraphTask(getFrameGraph(this.#scene), task);
|
|
154
|
+
}
|
|
155
|
+
dispose() {
|
|
156
|
+
if (this.#isDisposed) return;
|
|
157
|
+
this.#isDisposed = true;
|
|
158
|
+
unregisterScene(this.#scene);
|
|
159
|
+
disposeScene(this.#scene);
|
|
160
|
+
this.#callbacks.onDispose(this.#scene);
|
|
161
|
+
}
|
|
162
|
+
/** Schedules a move to the end of the context list when a context that is not an overlay follows. */
|
|
163
|
+
#keepLast() {
|
|
164
|
+
if (this.#isMoving || !this.#isFollowed()) return;
|
|
165
|
+
this.#isMoving = true;
|
|
166
|
+
queueMicrotask(() => {
|
|
167
|
+
this.#move(MOVE_ATTEMPTS);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Moves the overlay to the end, reporting a failure and trying again on the next animation frame.
|
|
172
|
+
*
|
|
173
|
+
* @param attemptsLeft - How many attempts remain, this one included.
|
|
174
|
+
*/
|
|
175
|
+
#move(attemptsLeft) {
|
|
176
|
+
this.#moveToEnd().then(() => {
|
|
177
|
+
this.#isMoving = false;
|
|
178
|
+
}, (error) => {
|
|
179
|
+
this.#callbacks.onError(error);
|
|
180
|
+
if (attemptsLeft > 1 && !this.#isDisposed) {
|
|
181
|
+
requestAnimationFrame(() => {
|
|
182
|
+
this.#move(attemptsLeft - 1);
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.#isMoving = false;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Whether a rendering context other than another overlay is registered after this one.
|
|
191
|
+
*
|
|
192
|
+
* @returns `true` when the overlay has to move.
|
|
193
|
+
*/
|
|
194
|
+
#isFollowed() {
|
|
195
|
+
const contexts = getRenderingContexts(this.#engine);
|
|
196
|
+
for (let index = contexts.indexOf(this.#scene) + 1; index < contexts.length; index += 1) {
|
|
197
|
+
const context = contexts[index];
|
|
198
|
+
if (context !== void 0 && !this.#callbacks.isPeer(context)) return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Re-registers the overlay at the end of the context list.
|
|
204
|
+
*
|
|
205
|
+
* @returns A promise that settles once it draws last.
|
|
206
|
+
*/
|
|
207
|
+
async #moveToEnd() {
|
|
208
|
+
if (this.#isDisposed) return;
|
|
209
|
+
unregisterScene(this.#scene);
|
|
210
|
+
getFrameGraph(this.#scene).dispose();
|
|
211
|
+
await this.attach();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Creates the overlay's render task: into the swapchain, keeping its colour, over a depth buffer of
|
|
216
|
+
* its own that it clears.
|
|
217
|
+
*
|
|
218
|
+
* @param engine - The engine.
|
|
219
|
+
* @param scene - The overlay scene.
|
|
220
|
+
* @returns The task, not yet added to a frame graph.
|
|
221
|
+
*/
|
|
222
|
+
function createOverlayTask(engine, scene) {
|
|
223
|
+
return createRenderTask({
|
|
224
|
+
name: OVERLAY_TASK_NAME,
|
|
225
|
+
rt: engine.scRT,
|
|
226
|
+
sharedRt: true,
|
|
227
|
+
depth: createRenderTarget({
|
|
228
|
+
lbl: "ignifx:overlay-depth",
|
|
229
|
+
dFormat: DEPTH_STENCIL_FORMAT,
|
|
230
|
+
samples: 1,
|
|
231
|
+
size: engine
|
|
232
|
+
}),
|
|
233
|
+
clr: false
|
|
234
|
+
}, engine, scene);
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
export { openOverlayScene };
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=overlay-CjVgsfrm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-CjVgsfrm.js","names":[],"sources":["../src/lite/gpu/overlay.ts"],"sourcesContent":["import {\n addTask,\n addToScene,\n buildFrameGraphTask,\n createHemisphericLight,\n createRenderTarget,\n createRenderTask,\n createSceneContext,\n disposeScene,\n getFrameGraph,\n getRenderingContexts,\n onBeforeRender,\n registerScene,\n unregisterScene,\n} from \"@babylonjs/lite\";\nimport type { EngineContext, RenderTask, SceneContext } from \"@babylonjs/lite\";\n\n/**\n * The render overlay (`docs/architecture/07-rendering.md` §2.10, ADR-0031): a second Lite scene drawn\n * over the finished frame, for an editor's gizmos, selection outlines and other helpers.\n *\n * Everything here needs a device.\n *\n * ## Why core does not call `createUtilityLayer`\n *\n * `createUtilityLayer` (`index.d.ts` 4109) builds its scene with Lite's default render task, and\n * `registerScene` (11268) then fixes that task up against the **last** registered rendering\n * context (`lib/scene/swapchain-overlay.js` 11). Two things go wrong in an ignifx app (editor spike\n * S0.2 §3.2):\n *\n * - When `@ignifx/ui`'s text renderer or `@ignifx/2d`'s sprite renderer was registered after the\n * render scene, it is the last context. It has no frame graph, so Lite configures nothing and the\n * layer's task clears the frame to transparent black.\n * - With MSAA on, Lite borrows the base scene's multisampled colour view, and switches the layer\n * off unless that scene resolves straight into the swapchain (`swapchain-overlay.js` 19-27). With\n * `rendering.features.postProcessing` the render scene resolves into an offscreen target, so the\n * layer never draws.\n *\n * ## What this module builds instead\n *\n * Only public Lite calls:\n *\n * 1. A scene with no default render task (`createSceneContext`, 3663) that shares the render\n * scene's camera, plus the hemispheric light `createUtilityLayer` would add, so Lite's gizmo\n * materials look the same.\n * 2. `registerScene` while its frame graph is **empty**. Lite's fix-up looks for a task that targets\n * the swapchain (`swapchain-overlay.js` 5-7), finds none, and changes nothing.\n * 3. One render task (`createRenderTask`, 3620) added afterwards and recorded with\n * `buildFrameGraphTask` (1501). It draws into the swapchain with `clr: false`, so it keeps the\n * frame's colour, and `sharedRt: true`, so it never builds or frees the swapchain target\n * (`RenderTaskConfig`, 11635). It has a single-sample depth target of its own, which it clears,\n * so helpers draw on top of the scene. It never touches the scene's targets, so the scene's MSAA\n * setting and render path do not matter: it reads whatever the frame's last pass presented.\n *\n * ## Staying last\n *\n * Lite renders the contexts in registration order (`renderFrame`, `lib/engine/engine.js` 246-251),\n * and the 2D and UI extensions register theirs lazily, when the first sprite or text appears. A\n * sprite renderer in `\"sprite\"` mode clears the frame, so one registered after the overlay would\n * erase it. Each frame the overlay checks `getRenderingContexts` (6921); when a context other than\n * another overlay follows it, it moves itself to the end after the frame: unregister, drop its task\n * so the re-registration again finds no swapchain task, register, and build a fresh task. The frame\n * in between draws no overlay. A move that fails (a lost device, a pipeline that does not compile) is\n * reported and tried again on the next animation frame, {@link MOVE_ATTEMPTS} times in all; after\n * that the overlay stays detached until it is disposed.\n *\n * A screenshot is taken after every context has recorded (`_captureService`, same function), so it\n * includes the overlay.\n */\n\n/** The depth/stencil format Lite's own single-sample scene task uses (`lib/scene/scene-core.js` 76-77). */\nconst DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/** The name the overlay's task carries in Lite's frame graph and in per-task GPU timings. */\nexport const OVERLAY_TASK_NAME = \"ignifx:overlay\";\n\n/** The light `createUtilityLayer` adds by default (`lib/gizmo/utility-layer.js` 24-36). */\nconst LIGHT_INTENSITY = 2;\n\n/** The ground colour of that light. */\nconst LIGHT_GROUND = 0.5;\n\n/** How many times a move to the end of the context list is tried before the overlay gives up. */\nconst MOVE_ATTEMPTS = 3;\n\n/**\n * What an overlay reports to its owner.\n *\n * @internal\n */\nexport interface OverlayCallbacks {\n /**\n * Answers whether a rendering context is another overlay, which may follow this one.\n *\n * @param context - A registered rendering context.\n * @returns `true` for another overlay.\n */\n isPeer(context: object): boolean;\n /**\n * Called once when the overlay is disposed.\n *\n * @param scene - The overlay's scene.\n */\n onDispose(scene: object): void;\n /**\n * Receives a failed move to the end of the context list.\n *\n * @param error - What `registerScene` rejected with.\n */\n onError(error: unknown): void;\n}\n\n/**\n * The overlay scene and the render scene, in the shape Lite's gizmo constructors take as a\n * `UtilityLayer` (`index.d.ts` 15747).\n *\n * @internal\n */\nexport interface OverlaySceneHandles {\n /** The overlay scene. Add helpers to it. */\n readonly scene: SceneContext;\n /** The render scene, whose camera the overlay scene follows. */\n readonly mainScene: SceneContext;\n}\n\n/**\n * An open overlay scene.\n *\n * @internal\n */\nexport interface OverlayScene {\n /** The Lite scenes. */\n readonly lite: OverlaySceneHandles;\n /** Unregisters and disposes the overlay scene, its task and its depth target. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Builds an overlay scene and registers it after every rendering context on the surface.\n *\n * @remarks\n * Call it only after the render scene is registered: the overlay draws after it because it is\n * registered after it.\n *\n * @param engine - The WebGPU engine, which is also the primary surface.\n * @param mainScene - The render scene whose camera the overlay follows.\n * @param callbacks - The owner's peer test, disposal hook and error sink.\n * @returns The overlay, drawing from the next frame.\n * @throws Whatever the first `registerScene` rejects with; the overlay is disposed first.\n *\n * @example\n * ```ts\n * const overlay = await openOverlayScene(engine, scene, {\n * isPeer: () => false,\n * onDispose: () => {},\n * onError: (error) => console.error(error),\n * });\n * overlay.dispose();\n * ```\n *\n * @internal\n */\nexport async function openOverlayScene(\n engine: EngineContext,\n mainScene: SceneContext,\n callbacks: OverlayCallbacks,\n): Promise<OverlayScene> {\n const overlay = new LiteOverlayScene(engine, mainScene, callbacks);\n try {\n await overlay.attach();\n } catch (error) {\n overlay.dispose();\n throw error;\n }\n return overlay;\n}\n\n/** The overlay scene, its registration and its place in the context list. */\nclass LiteOverlayScene implements OverlayScene {\n readonly lite: OverlaySceneHandles;\n\n readonly #engine: EngineContext;\n\n readonly #scene: SceneContext;\n\n readonly #callbacks: OverlayCallbacks;\n\n #isDisposed = false;\n\n #isMoving = false;\n\n /**\n * Creates the scene, with the light `createUtilityLayer` would add, following the render scene's\n * camera. It is not registered yet.\n *\n * @param engine - The WebGPU engine.\n * @param mainScene - The render scene.\n * @param callbacks - The owner's peer test, disposal hook and error sink.\n */\n constructor(engine: EngineContext, mainScene: SceneContext, callbacks: OverlayCallbacks) {\n const scene = createSceneContext(engine, { defaultRenderTask: false });\n scene.name = OVERLAY_TASK_NAME;\n scene.camera = mainScene.camera;\n const light = createHemisphericLight([0, 1, 0], LIGHT_INTENSITY);\n light.groundColor = [LIGHT_GROUND, LIGHT_GROUND, LIGHT_GROUND];\n addToScene(scene, light);\n this.lite = { scene, mainScene };\n this.#engine = engine;\n this.#scene = scene;\n this.#callbacks = callbacks;\n onBeforeRender(scene, () => {\n // The render scene's camera can change from frame to frame (the highest-priority `Camera` wins).\n if (scene.camera !== mainScene.camera) {\n scene.camera = mainScene.camera;\n }\n this.#keepLast();\n });\n }\n\n /**\n * Registers the scene at the end of the context list and builds its task.\n *\n * @returns A promise that settles once the overlay draws from the next frame.\n */\n async attach(): Promise<void> {\n // Registered while its frame graph is empty, so Lite's swapchain fix-up finds nothing to change.\n await registerScene(this.#scene);\n if (this.#isDisposed) {\n return;\n }\n const task = createOverlayTask(this.#engine, this.#scene);\n addTask(this.#scene, task);\n buildFrameGraphTask(getFrameGraph(this.#scene), task);\n }\n\n dispose(): void {\n if (this.#isDisposed) {\n return;\n }\n this.#isDisposed = true;\n unregisterScene(this.#scene);\n disposeScene(this.#scene);\n this.#callbacks.onDispose(this.#scene);\n }\n\n /** Schedules a move to the end of the context list when a context that is not an overlay follows. */\n #keepLast(): void {\n if (this.#isMoving || !this.#isFollowed()) {\n return;\n }\n // Not now: Lite is walking the context list. The microtask runs once the frame has been submitted.\n this.#isMoving = true;\n queueMicrotask(() => {\n this.#move(MOVE_ATTEMPTS);\n });\n }\n\n /**\n * Moves the overlay to the end, reporting a failure and trying again on the next animation frame.\n *\n * @param attemptsLeft - How many attempts remain, this one included.\n */\n #move(attemptsLeft: number): void {\n this.#moveToEnd().then(\n () => {\n this.#isMoving = false;\n },\n (error: unknown) => {\n this.#callbacks.onError(error);\n if (attemptsLeft > 1 && !this.#isDisposed) {\n // The overlay is unregistered now, so its own frame callback no longer runs to retry.\n requestAnimationFrame(() => {\n this.#move(attemptsLeft - 1);\n });\n return;\n }\n this.#isMoving = false;\n },\n );\n }\n\n /**\n * Whether a rendering context other than another overlay is registered after this one.\n *\n * @returns `true` when the overlay has to move.\n */\n #isFollowed(): boolean {\n const contexts = getRenderingContexts(this.#engine);\n for (let index = contexts.indexOf(this.#scene) + 1; index < contexts.length; index += 1) {\n const context = contexts[index];\n if (context !== undefined && !this.#callbacks.isPeer(context)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Re-registers the overlay at the end of the context list.\n *\n * @returns A promise that settles once it draws last.\n */\n async #moveToEnd(): Promise<void> {\n if (this.#isDisposed) {\n return;\n }\n unregisterScene(this.#scene);\n // Disposing the graph drops the task, which also frees its depth target.\n getFrameGraph(this.#scene).dispose();\n await this.attach();\n }\n}\n\n/**\n * Creates the overlay's render task: into the swapchain, keeping its colour, over a depth buffer of\n * its own that it clears.\n *\n * @param engine - The engine.\n * @param scene - The overlay scene.\n * @returns The task, not yet added to a frame graph.\n */\nfunction createOverlayTask(engine: EngineContext, scene: SceneContext): RenderTask {\n return createRenderTask(\n {\n name: OVERLAY_TASK_NAME,\n rt: engine.scRT,\n sharedRt: true,\n depth: createRenderTarget({\n lbl: \"ignifx:overlay-depth\",\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: 1,\n size: engine,\n }),\n clr: false,\n },\n engine,\n scene,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAM,uBAAyC;;AAG/C,MAAa,oBAAoB;;AAGjC,MAAM,kBAAkB;;AAGxB,MAAM,eAAe;;AAGrB,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EtB,eAAsB,iBACpB,QACA,WACA,WACuB;CACvB,MAAM,UAAU,IAAI,iBAAiB,QAAQ,WAAW,SAAS;CACjE,IAAI;EACF,MAAM,QAAQ,OAAO;CACvB,SAAS,OAAO;EACd,QAAQ,QAAQ;EAChB,MAAM;CACR;CACA,OAAO;AACT;;AAGA,IAAM,mBAAN,MAA+C;CAC7C;CAEA;CAEA;CAEA;CAEA,cAAc;CAEd,YAAY;;;;;;;;;CAUZ,YAAY,QAAuB,WAAyB,WAA6B;EACvF,MAAM,QAAQ,mBAAmB,QAAQ,EAAE,mBAAmB,MAAM,CAAC;EACrE,MAAM,OAAO;EACb,MAAM,SAAS,UAAU;EACzB,MAAM,QAAQ,uBAAuB;GAAC;GAAG;GAAG;EAAC,GAAG,eAAe;EAC/D,MAAM,cAAc;GAAC;GAAc;GAAc;EAAY;EAC7D,WAAW,OAAO,KAAK;EACvB,KAAK,OAAO;GAAE;GAAO;EAAU;EAC/B,KAAK,UAAU;EACf,KAAK,SAAS;EACd,KAAK,aAAa;EAClB,eAAe,aAAa;GAE1B,IAAI,MAAM,WAAW,UAAU,QAC7B,MAAM,SAAS,UAAU;GAE3B,KAAK,UAAU;EACjB,CAAC;CACH;;;;;;CAOA,MAAM,SAAwB;EAE5B,MAAM,cAAc,KAAK,MAAM;EAC/B,IAAI,KAAK,aACP;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