@ignifx/core 0.2.1 → 0.3.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.
Files changed (37) hide show
  1. package/dist/async-pipelines-CI5uT5iZ.js +26 -0
  2. package/dist/async-pipelines-CI5uT5iZ.js.map +1 -0
  3. package/dist/color-DrR6GFTd.js +351 -0
  4. package/dist/color-DrR6GFTd.js.map +1 -0
  5. package/dist/effect-task-CMbuO6Kb.js +205 -0
  6. package/dist/effect-task-CMbuO6Kb.js.map +1 -0
  7. package/dist/environment-C_JfuAjj.js +224 -0
  8. package/dist/environment-C_JfuAjj.js.map +1 -0
  9. package/dist/ignifx-error-R1ma_Lzv.js +544 -0
  10. package/dist/ignifx-error-R1ma_Lzv.js.map +1 -0
  11. package/dist/index.d.ts +3756 -1656
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +6404 -5777
  14. package/dist/index.js.map +1 -1
  15. package/dist/instanced-mesh-instance-Cgx1H87p.js +701 -0
  16. package/dist/instanced-mesh-instance-Cgx1H87p.js.map +1 -0
  17. package/dist/material-plugin-CTaWZXEk.js +485 -0
  18. package/dist/material-plugin-CTaWZXEk.js.map +1 -0
  19. package/dist/math-utils-BcDnL-gi.js +277 -0
  20. package/dist/math-utils-BcDnL-gi.js.map +1 -0
  21. package/dist/mesh-CnK_PX46.js +811 -0
  22. package/dist/mesh-CnK_PX46.js.map +1 -0
  23. package/dist/post-effect-C42XJFmo.js +155 -0
  24. package/dist/post-effect-C42XJFmo.js.map +1 -0
  25. package/dist/post-effect-compiler-DTlkT1si.js +311 -0
  26. package/dist/post-effect-compiler-DTlkT1si.js.map +1 -0
  27. package/dist/shader-declaration-5q__jycG.js +165 -0
  28. package/dist/shader-declaration-5q__jycG.js.map +1 -0
  29. package/dist/shader-material-DssOqsvZ.js +1009 -0
  30. package/dist/shader-material-DssOqsvZ.js.map +1 -0
  31. package/dist/shader-material-Xk7Oc9UG.js +207 -0
  32. package/dist/shader-material-Xk7Oc9UG.js.map +1 -0
  33. package/dist/shader-pragma-CNAK4SIb.js +685 -0
  34. package/dist/shader-pragma-CNAK4SIb.js.map +1 -0
  35. package/dist/surface-shader-C2HtysNN.js +1397 -0
  36. package/dist/surface-shader-C2HtysNN.js.map +1 -0
  37. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instanced-mesh-instance-Cgx1H87p.js","names":["setThinInstances","setThinInstanceCount","flushThinInstances","setThinInstanceColors","enableThinInstanceGpuCulling","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 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 * 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 setThinInstanceLodPartner,\n setThinInstances,\n trySetThinInstanceDrawCount,\n} from \"../../lite/gpu/thin-instances.js\";\nimport { tagNode } from \"../../lite/node.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\";\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 /**\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 if (count <= 0) {\n writeBox(this.mesh, near);\n if (lod !== null && lodBox !== null) {\n writeBox(lod, lodBox);\n }\n return;\n }\n const union = this.#union;\n unionOfPlacements(matrices, count, near, union);\n setMeshBounds(this.mesh, union[0] ?? 0, union[1] ?? 0, union[2] ?? 0, union[3] ?? 0, union[4] ?? 0, union[5] ?? 0);\n if (lod !== null && lodBox !== null) {\n unionOfPlacements(matrices, count, lodBox, union);\n setMeshBounds(lod, union[0] ?? 0, union[1] ?? 0, union[2] ?? 0, union[3] ?? 0, union[4] ?? 0, union[5] ?? 0);\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.\n *\n * @param mesh - The mesh to re-bound.\n * @param box - `minX, minY, minZ, maxX, maxY, maxZ`.\n */\nfunction writeBox(mesh: LiteMesh, box: Float64Array): void {\n setMeshBounds(mesh, box[0] ?? 0, box[1] ?? 0, box[2] ?? 0, box[3] ?? 0, box[4] ?? 0, box[5] ?? 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,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;;;;;;;;AASA,SAAgBC,qBAAmB,MAAkB;CACnD,mBAAuB,IAAI;AAC7B;;;;;;;;;;;;;;;;;AAkBA,SAAgBC,w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AAI,WAAW,GAC7C,IAAI,UAAU,MAAM,GAClB,SAAS,KAAK,IAAI,SAAS,OAAO,YAAY,CAAC;EAGnD,IAAI,QAAQ,MACV;EAEF,UAAU;EACV,KAAK,IAAI,MAAM,GAAG,MAAM,GAAG,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"}
@@ -0,0 +1,485 @@
1
+ import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-R1ma_Lzv.js";
2
+ import { u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
3
+ import { createPbrMaterial, createStandardMaterial, markMaterialUboDirty, rebuildMaterial, setPbrAlphaCutoff, setPbrEmissive, setPbrUnlit, setStandardBumpTexture, setStandardEmissiveTexture, setStandardOpacityTexture, setStandardSpecularTexture } from "@babylonjs/lite";
4
+ //#region src/lite/material.ts
5
+ /** glTF's default alpha cutoff, used when a `"mask"` material declares none. */
6
+ const DEFAULT_ALPHA_CUTOFF = .5;
7
+ /**
8
+ * How a material's alpha channel is interpreted, in glTF's vocabulary, in the order the inspector
9
+ * lists them (`docs/architecture/07-rendering.md` §2.4).
10
+ *
11
+ * @public
12
+ */
13
+ const MATERIAL_ALPHA_MODES = [
14
+ "opaque",
15
+ "mask",
16
+ "blend"
17
+ ];
18
+ /**
19
+ * Builds a Lite PBR material from ignifx props.
20
+ *
21
+ * @param input - The declared properties.
22
+ * @returns The material. It holds no GPU resource of its own; the textures it references do.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const gold = createPbrMaterialFromProps({ baseColor: [1, 0.77, 0.34, 1], metallic: 1, roughness: 0.25 });
27
+ * ```
28
+ *
29
+ * @internal
30
+ */
31
+ function createPbrMaterialFromProps(input) {
32
+ const props = {};
33
+ if (input.name !== void 0) props.name = input.name;
34
+ if (input.baseColor !== void 0) props.baseColorFactor = [
35
+ input.baseColor[0],
36
+ input.baseColor[1],
37
+ input.baseColor[2],
38
+ input.baseColor[3]
39
+ ];
40
+ if (input.baseColorTexture !== void 0) props.baseColorTexture = input.baseColorTexture;
41
+ if (input.metallic !== void 0) props.metallicFactor = input.metallic;
42
+ if (input.roughness !== void 0) props.roughnessFactor = input.roughness;
43
+ if (input.metallicRoughnessTexture !== void 0) props.ormTexture = input.metallicRoughnessTexture;
44
+ if (input.normalTexture !== void 0) props.normalTexture = input.normalTexture;
45
+ if (input.normalScale !== void 0) props.normalTextureScale = input.normalScale;
46
+ if (input.emissiveTexture !== void 0) props.emissiveTexture = input.emissiveTexture;
47
+ if (input.occlusionTexture !== void 0) props.occlusionTexture = input.occlusionTexture;
48
+ if (input.occlusionStrength !== void 0) props.occlusionStrength = input.occlusionStrength;
49
+ if (input.alpha !== void 0) props.alpha = input.alpha;
50
+ if (input.doubleSided !== void 0) props.doubleSided = input.doubleSided;
51
+ if (input.environmentIntensity !== void 0) props.environmentIntensity = input.environmentIntensity;
52
+ if (input.alphaMode === "blend") props.alphaBlend = true;
53
+ const material = createPbrMaterial(props);
54
+ if (input.alphaMode === "mask") setPbrAlphaCutoff(material, input.alphaCutoff ?? DEFAULT_ALPHA_CUTOFF);
55
+ if (input.emissive !== void 0) setPbrEmissive(material, [
56
+ input.emissive[0],
57
+ input.emissive[1],
58
+ input.emissive[2]
59
+ ]);
60
+ if (input.unlit === true) setPbrUnlit(material);
61
+ return material;
62
+ }
63
+ /**
64
+ * Builds a Lite Standard material from ignifx props.
65
+ *
66
+ * @param input - The declared properties.
67
+ * @returns The material.
68
+ *
69
+ * @internal
70
+ */
71
+ function createStandardMaterialFromProps(input) {
72
+ const material = createStandardMaterial();
73
+ if (input.name !== void 0) material.name = input.name;
74
+ if (input.diffuse !== void 0) writeTriple(material.diffuseColor, input.diffuse);
75
+ if (input.specular !== void 0) writeTriple(material.specularColor, input.specular);
76
+ if (input.emissive !== void 0) writeTriple(material.emissiveColor, input.emissive);
77
+ if (input.specularPower !== void 0) material.specularPower = input.specularPower;
78
+ if (input.alpha !== void 0) material.alpha = input.alpha;
79
+ if (input.alphaCutoff !== void 0) material.alphaCutOff = input.alphaCutoff;
80
+ if (input.doubleSided !== void 0) material.backFaceCulling = !input.doubleSided;
81
+ if (input.unlit !== void 0) material.disableLighting = input.unlit;
82
+ if (input.diffuseTexture !== void 0) material.diffuseTexture = input.diffuseTexture;
83
+ if (input.specularTexture !== void 0) setStandardSpecularTexture(material, input.specularTexture);
84
+ if (input.emissiveTexture !== void 0) setStandardEmissiveTexture(material, input.emissiveTexture);
85
+ if (input.normalTexture !== void 0) setStandardBumpTexture(material, input.normalTexture);
86
+ if (input.opacityTexture !== void 0) setStandardOpacityTexture(material, input.opacityTexture);
87
+ return material;
88
+ }
89
+ /**
90
+ * The material a `MeshRenderer` uses when it declares none: a neutral, fully rough dielectric.
91
+ *
92
+ * @returns A fresh material. Callers share one instance per app rather than one per renderer.
93
+ *
94
+ * @internal
95
+ */
96
+ function createDefaultMaterial() {
97
+ return createPbrMaterialFromProps({
98
+ name: "ignifx:default",
99
+ baseColor: [
100
+ 1,
101
+ 1,
102
+ 1,
103
+ 1
104
+ ],
105
+ metallic: 0,
106
+ roughness: .9
107
+ });
108
+ }
109
+ /**
110
+ * Replaces a PBR material's linear base colour.
111
+ *
112
+ * @param material - The material to change.
113
+ * @param r - The linear red component.
114
+ * @param g - The linear green component.
115
+ * @param b - The linear blue component.
116
+ * @param a - The alpha component.
117
+ *
118
+ * @internal
119
+ */
120
+ function setPbrBaseColor(material, r, g, b, a) {
121
+ const factor = material.baseColorFactor;
122
+ if (factor === void 0) material.baseColorFactor = [
123
+ r,
124
+ g,
125
+ b,
126
+ a
127
+ ];
128
+ else {
129
+ factor[0] = r;
130
+ factor[1] = g;
131
+ factor[2] = b;
132
+ factor[3] = a;
133
+ }
134
+ markMaterialDirty(material);
135
+ }
136
+ /**
137
+ * Replaces a PBR material's metallic and roughness factors.
138
+ *
139
+ * @param material - The material to change.
140
+ * @param metallic - The metallic factor, 0 to 1.
141
+ * @param roughness - The roughness factor, 0 to 1.
142
+ *
143
+ * @internal
144
+ */
145
+ function setPbrMetallicRoughness(material, metallic, roughness) {
146
+ material.metallicFactor = metallic;
147
+ material.roughnessFactor = roughness;
148
+ markMaterialDirty(material);
149
+ }
150
+ /**
151
+ * Replaces a material's overall alpha.
152
+ *
153
+ * @param material - The PBR or Standard material to change.
154
+ * @param alpha - The new alpha, 0 to 1.
155
+ *
156
+ * @internal
157
+ */
158
+ function setMaterialAlpha(material, alpha) {
159
+ material.alpha = alpha;
160
+ markMaterialDirty(material);
161
+ }
162
+ /**
163
+ * Marks a material's uniform block for re-upload on the next frame.
164
+ *
165
+ * @remarks
166
+ * This is the cheap path and covers every scalar, vector, and colour edit. It does **not** cover
167
+ * changes that alter the compiled feature set; those go through {@link rebuildMaterialPipelines}.
168
+ *
169
+ * @param material - The material that changed.
170
+ *
171
+ * @internal
172
+ */
173
+ function markMaterialDirty(material) {
174
+ markMaterialUboDirty(material);
175
+ }
176
+ /**
177
+ * Rebuilds the renderables of a material whose compiled feature set changed.
178
+ *
179
+ * @remarks
180
+ * Needed after binding or clearing a texture, changing culling, or toggling a sub-feature
181
+ * (`index.d.ts` 9413). `rebuildFrameGraph` is left off so a component can batch several material
182
+ * edits and rebuild the frame graph once.
183
+ *
184
+ * @param scene - The scene the material renders in.
185
+ * @param material - The material that changed.
186
+ *
187
+ * @internal
188
+ */
189
+ function rebuildMaterialPipelines(scene, material) {
190
+ rebuildMaterial(scene, material);
191
+ }
192
+ /**
193
+ * Writes three components into a Lite colour tuple in place.
194
+ *
195
+ * @param target - The tuple Lite owns.
196
+ * @param source - The values to copy.
197
+ */
198
+ function writeTriple(target, source) {
199
+ target[0] = source[0];
200
+ target[1] = source[1];
201
+ target[2] = source[2];
202
+ }
203
+ //#endregion
204
+ //#region src/render/material-plugin.ts
205
+ /**
206
+ * The raw Babylon Lite material-plugin points, as a `@beta` escape hatch
207
+ * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.2, ADR-0024).
208
+ *
209
+ * `@beta` because the meaning of each point is whatever the surrounding Lite template declares at
210
+ * that line; ignifx's stable contract is the three hooks of `./surface-shader.ts`. Four rules read
211
+ * out of `@babylonjs/lite@1.27.0`'s `lib/` on 2026-09-08:
212
+ *
213
+ * - Plugin uniforms and samplers are **fragment-stage only** on both families
214
+ * (`lib/material/plugin/plugin-bridge-shared.js` 99), and there is no vertex helper-function
215
+ * channel, so vertex code may read only attributes, `mesh.world` and the scene block, and must be
216
+ * statements rather than functions.
217
+ * - `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected **twice** — Lite maps it to the two
218
+ * adjacent PBR slots `AI` and `NI` — so its code must be idempotent or guard itself with a flag
219
+ * set at an earlier point, and must declare nothing at statement level.
220
+ * - Only PBR carries `CUSTOM_FRAGMENT_UPDATE_DIFFUSE` after `CUSTOM_FRAGMENT_UPDATE_ALPHA`;
221
+ * Standard's template orders them the other way and has no `AI`/`NI`/`MF` slots.
222
+ * - `roughness` and `metallic` are `let` in the PBR template and cannot be written.
223
+ */
224
+ /**
225
+ * The Babylon Lite injection points a {@link MaterialPluginDefinition} may fill in.
226
+ *
227
+ * @remarks
228
+ * The names are Lite's own (`MaterialPluginPoint`, `index.d.ts` 7084) and are taught verbatim,
229
+ * because a plugin's code is written against the template around the point.
230
+ *
231
+ * @beta
232
+ */
233
+ const LITE_MATERIAL_PLUGIN_POINTS = [
234
+ "CUSTOM_FRAGMENT_DEFINITIONS",
235
+ "CUSTOM_FRAGMENT_MAIN_BEGIN",
236
+ "CUSTOM_FRAGMENT_UPDATE_ALPHA",
237
+ "CUSTOM_FRAGMENT_UPDATE_DIFFUSE",
238
+ "CUSTOM_FRAGMENT_BEFORE_LIGHTS",
239
+ "CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION",
240
+ "CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR",
241
+ "CUSTOM_VERTEX_MAIN_BEGIN",
242
+ "CUSTOM_VERTEX_UPDATE_WORLDPOS",
243
+ "CUSTOM_VERTEX_MAIN_END"
244
+ ];
245
+ /**
246
+ * The default priority Babylon Lite gives a plugin with none (`index.d.ts` 7057).
247
+ *
248
+ * @beta
249
+ */
250
+ const MATERIAL_PLUGIN_DEFAULT_PRIORITY = 500;
251
+ /**
252
+ * How many `texture`/`sampler` pairs one material's plugins may declare together.
253
+ *
254
+ * @remarks
255
+ * Measured on a device on 2026-09-08 (spike S0.2): a fully textured PBR material — base colour,
256
+ * normal, ORM, emissive — with image-based lighting and one PCF shadow light already binds seven
257
+ * textures and seven samplers of the sixteen per stage that every WebGPU implementation guarantees,
258
+ * SwiftShader included, and Lite requests no higher `requiredLimits`. Nine is what is left, and it
259
+ * drops to eight with a second shadow light and seven with a lightmap, so a material that means to
260
+ * be portable should stay well under the cap.
261
+ *
262
+ * @beta
263
+ */
264
+ const MATERIAL_PLUGIN_SAMPLER_BUDGET = 9;
265
+ /**
266
+ * The WGSL names the PBR and Standard templates already own, which a plugin may not reuse for a
267
+ * uniform field or a sampler.
268
+ *
269
+ * @remarks
270
+ * A plugin's fields land in the host's own uniform block and its samplers in the host's own bind
271
+ * group, so a collision is a duplicate WGSL declaration and the whole material stops compiling with
272
+ * a message that names neither the plugin nor the field. Refusing at attach time is the difference
273
+ * between a sentence and a shader dump. Read from `pbr-template.js` `_baseMaterialUboFields` and
274
+ * `_baseBindings`, and `standard-template.js` `materialStruct` and `_baseBindings`.
275
+ *
276
+ * @beta
277
+ */
278
+ const MATERIAL_PLUGIN_RESERVED_NAMES = Object.freeze([
279
+ "material",
280
+ "mesh",
281
+ "scene",
282
+ "lights",
283
+ "pluginUbo",
284
+ "shadowParams",
285
+ "main",
286
+ "environmentIntensity",
287
+ "directIntensity",
288
+ "reflectance",
289
+ "materialAlpha",
290
+ "baseColorFactor",
291
+ "metallicFactor",
292
+ "roughnessFactor",
293
+ "normalScale",
294
+ "lightFalloffMode",
295
+ "anisotropyParams",
296
+ "baseColorTexture",
297
+ "baseColorSampler",
298
+ "normalTexture",
299
+ "normalSampler_",
300
+ "ormTexture",
301
+ "ormSampler",
302
+ "emissiveTexture",
303
+ "emissiveSampler",
304
+ "specGlossTexture",
305
+ "specGlossSampler",
306
+ "dT",
307
+ "dS",
308
+ "mat",
309
+ "up"
310
+ ]);
311
+ /** Matches a WGSL identifier. */
312
+ const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
313
+ /** Matches a legal plugin name: an identifier, optionally with `.`, `:`, or `-` inside it. */
314
+ const PLUGIN_NAME = /^[A-Za-z_][A-Za-z0-9_]*(?:[.:-][A-Za-z0-9_]+)*$/;
315
+ /**
316
+ * Validates a raw material-plugin declaration and fills in its defaults.
317
+ *
318
+ * @remarks
319
+ * Nothing here reaches a device: the result is plain data that `attachSurfaceShaders` and
320
+ * `attachMaterialPlugin` turn into a Lite plugin. The checks are the ones whose failure would
321
+ * otherwise surface as a WGSL compile error with no mention of the plugin — an empty `code`, a
322
+ * duplicate or reserved binding name, a name that is not a WGSL identifier, an unknown injection
323
+ * point, or more samplers than {@link MATERIAL_PLUGIN_SAMPLER_BUDGET}.
324
+ *
325
+ * The **surface-shader compiler produces one of these**, so a bug in this validation is a bug in
326
+ * every surface shader too, which is why it lives here rather than inside the compiler.
327
+ *
328
+ * @param definition - The declaration.
329
+ * @returns The same declaration with `priority`, `uniforms`, and `textures` filled in.
330
+ * @throws IgnifxError with code `IGX-0723` when `code` fills in no point, `IGX-0712` when a name is
331
+ * not a legal, unique, unreserved WGSL identifier or a point name is unknown, or `IGX-0726` when the
332
+ * plugin alone exceeds the sampler budget.
333
+ *
334
+ * @example
335
+ * ```ts
336
+ * const tint = defineMaterialPlugin({
337
+ * name: "tint",
338
+ * code: { CUSTOM_FRAGMENT_UPDATE_ALPHA: "baseColor = baseColor * vec3<f32>(1.0, 0.5, 0.5);" },
339
+ * });
340
+ * ```
341
+ *
342
+ * @beta
343
+ */
344
+ function defineMaterialPlugin(definition) {
345
+ const name = definition.name;
346
+ if (!PLUGIN_NAME.test(name)) throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${JSON.stringify(name)} is not a legal material-plugin name.`, {
347
+ context: {
348
+ plugin: name,
349
+ name
350
+ },
351
+ hint: "Start with a letter or underscore; letters, digits, underscores, and inner . : - follow."
352
+ });
353
+ const points = Object.keys(definition.code);
354
+ let filled = 0;
355
+ for (const point of points) {
356
+ if (!isLiteMaterialPluginPoint(point)) throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${name} declares no Lite point named ${point}.`, {
357
+ context: {
358
+ plugin: name,
359
+ name: point,
360
+ point
361
+ },
362
+ hint: `The ten points are ${LITE_MATERIAL_PLUGIN_POINTS.join(", ")}.`
363
+ });
364
+ if ((definition.code[point] ?? "").trim().length > 0) filled += 1;
365
+ }
366
+ if (filled === 0) throw new IgnifxError(CoreErrorCode.surfaceHookMissing, `${name} injects no WGSL at any Lite point.`, {
367
+ context: {
368
+ plugin: name,
369
+ name
370
+ },
371
+ hint: "Fill in at least one of the ten points, or do not attach the plugin."
372
+ });
373
+ const uniforms = definition.uniforms ?? [];
374
+ const textures = definition.textures ?? [];
375
+ const seen = /* @__PURE__ */ new Set();
376
+ for (const uniform of uniforms) {
377
+ assertBindingName(name, uniform.name, seen);
378
+ assertUniformType(name, uniform.name, uniform.type);
379
+ }
380
+ for (const texture of textures) {
381
+ assertBindingName(name, texture.name, seen);
382
+ assertBindingName(name, `${texture.name}Sampler`, seen);
383
+ }
384
+ if (textures.length > 9) throw new IgnifxError(CoreErrorCode.surfaceSamplerBudgetExceeded, `${name} declares ${String(textures.length)} samplers; a material's plugins may declare ${String(9)} together.`, {
385
+ context: {
386
+ plugin: name,
387
+ samplers: textures.length,
388
+ budget: 9
389
+ },
390
+ hint: "Pack the maps into fewer textures — an RGBA control map rather than four masks."
391
+ });
392
+ return {
393
+ name,
394
+ priority: definition.priority ?? 500,
395
+ uniforms,
396
+ textures,
397
+ code: definition.code
398
+ };
399
+ }
400
+ /**
401
+ * Whether a string is one of Lite's ten injection points.
402
+ *
403
+ * @param value - The candidate.
404
+ * @returns `true` when Lite accepts it.
405
+ *
406
+ * @beta
407
+ */
408
+ function isLiteMaterialPluginPoint(value) {
409
+ for (const point of LITE_MATERIAL_PLUGIN_POINTS) if (point === value) return true;
410
+ return false;
411
+ }
412
+ /**
413
+ * How many floats one uniform of a declared type occupies on the CPU side.
414
+ *
415
+ * @param type - The declared WGSL type.
416
+ * @returns The component count: 1, 2, 3, 4, or 16.
417
+ *
418
+ * @internal
419
+ */
420
+ function uniformComponentCount(type) {
421
+ switch (type) {
422
+ case "vec2<f32>": return 2;
423
+ case "vec3<f32>": return 3;
424
+ case "vec4<f32>": return 4;
425
+ case "mat4x4<f32>": return 16;
426
+ case "f32":
427
+ case "u32":
428
+ case "i32": return 1;
429
+ default: return assertNever(type, "shader uniform type");
430
+ }
431
+ }
432
+ /**
433
+ * Refuses a binding name that is not a unique, unreserved WGSL identifier.
434
+ *
435
+ * @param plugin - The plugin's name, for the message.
436
+ * @param binding - The candidate name.
437
+ * @param seen - The names already taken by this plugin; the accepted name is added.
438
+ * @throws IgnifxError with code `IGX-0712`.
439
+ */
440
+ function assertBindingName(plugin, binding, seen) {
441
+ if (!IDENTIFIER.test(binding)) throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin} declares ${JSON.stringify(binding)}, which is not a WGSL identifier.`, {
442
+ context: {
443
+ plugin,
444
+ name: binding
445
+ },
446
+ hint: "Use letters, digits, and underscores, starting with a letter."
447
+ });
448
+ if (MATERIAL_PLUGIN_RESERVED_NAMES.includes(binding)) throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin} declares ${binding}, which Babylon Lite's own PBR or Standard shader already owns.`, {
449
+ context: {
450
+ plugin,
451
+ name: binding
452
+ },
453
+ hint: "Rename it; a plugin shares the host material's WGSL namespace."
454
+ });
455
+ if (seen.has(binding)) throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin} declares ${binding} twice.`, {
456
+ context: {
457
+ plugin,
458
+ name: binding
459
+ },
460
+ hint: "Every uniform and texture of one plugin needs its own name."
461
+ });
462
+ seen.add(binding);
463
+ }
464
+ /**
465
+ * Refuses a uniform type Lite's plugin bridge cannot carry.
466
+ *
467
+ * @param plugin - The plugin's name, for the message.
468
+ * @param binding - The uniform's name.
469
+ * @param type - The declared type.
470
+ * @throws IgnifxError with code `IGX-0712`.
471
+ */
472
+ function assertUniformType(plugin, binding, type) {
473
+ if (!SHADER_UNIFORM_TYPES.includes(type)) throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin}.${binding} declares the type ${type}.`, {
474
+ context: {
475
+ plugin,
476
+ name: binding,
477
+ type
478
+ },
479
+ hint: `The plugin uniform types are ${SHADER_UNIFORM_TYPES.join(", ")}.`
480
+ });
481
+ }
482
+ //#endregion
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
+
485
+ //# sourceMappingURL=material-plugin-CTaWZXEk.js.map