@ignifx/core 0.21.0 → 0.22.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 (93) hide show
  1. package/README.md +22 -0
  2. package/dist/{agx-tone-mapping-Cgt844j6.js → agx-tone-mapping-CCdGk_ly.js} +2 -2
  3. package/dist/agx-tone-mapping-CCdGk_ly.js.map +1 -0
  4. package/dist/auto-exposure-uzPn0beO.js.map +1 -1
  5. package/dist/{bloom-hdr-CLtQj-oY.js → bloom-hdr-xPwkIdHG.js} +5 -6
  6. package/dist/bloom-hdr-xPwkIdHG.js.map +1 -0
  7. package/dist/contact-shadows-T523EXaP.js.map +1 -1
  8. package/dist/effect-task-CMbuO6Kb.js.map +1 -1
  9. package/dist/{environment-Bf4aphSb.js → environment-7fJbN402.js} +2 -2
  10. package/dist/{environment-Bf4aphSb.js.map → environment-7fJbN402.js.map} +1 -1
  11. package/dist/{gtao-Bpu5-0Ne.js → gtao-CVAYWBEJ.js} +10 -11
  12. package/dist/gtao-CVAYWBEJ.js.map +1 -0
  13. package/dist/{hdr-output-DBQwMphy.js → hdr-output-_2TU-jWy.js} +8 -8
  14. package/dist/hdr-output-_2TU-jWy.js.map +1 -0
  15. package/dist/index.d.ts +61 -48
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +148 -129
  18. package/dist/index.js.map +1 -1
  19. package/dist/{instanced-mesh-instance-B-fXKSrY.js → instanced-mesh-instance-BLdAJTj8.js} +3 -3
  20. package/dist/instanced-mesh-instance-BLdAJTj8.js.map +1 -0
  21. package/dist/{light-probe-asset-BqfSrJe9.js → light-probe-asset-DGNIwKNb.js} +2 -2
  22. package/dist/light-probe-asset-DGNIwKNb.js.map +1 -0
  23. package/dist/{light-probes-DDojYajw.js → light-probes-C8jharz9.js} +6 -6
  24. package/dist/light-probes-C8jharz9.js.map +1 -0
  25. package/dist/lightmaps-BUUIIkt9.js.map +1 -1
  26. package/dist/material-myMbl9mW.js.map +1 -1
  27. package/dist/{material-plugin-DapJNj04.js → material-plugin-BBxIy6eo.js} +4 -4
  28. package/dist/material-plugin-BBxIy6eo.js.map +1 -0
  29. package/dist/{overlay-CjVgsfrm.js → overlay-DokHzP6_.js} +2 -3
  30. package/dist/overlay-DokHzP6_.js.map +1 -0
  31. package/dist/{post-effect-Cu3Enpz7.js → post-effect-DEZD-r0I.js} +3 -3
  32. package/dist/post-effect-DEZD-r0I.js.map +1 -0
  33. package/dist/{post-effect-compiler-cCq9lcHt.js → post-effect-compiler-unDD3hod.js} +4 -4
  34. package/dist/post-effect-compiler-unDD3hod.js.map +1 -0
  35. package/dist/{prefab-overrides-C2GsgOQc.js → prefab-overrides-Bb7jVm7A.js} +3 -3
  36. package/dist/prefab-overrides-Bb7jVm7A.js.map +1 -0
  37. package/dist/{prefab-overrides-htDc_5Po.d.ts → prefab-overrides-CkwXhp5A.d.ts} +84 -64
  38. package/dist/{prefab-overrides-htDc_5Po.d.ts.map → prefab-overrides-CkwXhp5A.d.ts.map} +1 -1
  39. package/dist/prefab.d.ts +1 -1
  40. package/dist/prefab.js +1 -1
  41. package/dist/{reflection-probe-QkD1Fo_d.js → reflection-probe-C2jcreI1.js} +5 -5
  42. package/dist/reflection-probe-C2jcreI1.js.map +1 -0
  43. package/dist/{reflection-probes-CAzSuqf8.js → reflection-probes-BMVQfbhm.js} +10 -10
  44. package/dist/reflection-probes-BMVQfbhm.js.map +1 -0
  45. package/dist/{render-path-D11i_7X8.js → render-path-CWXHrRa2.js} +2 -2
  46. package/dist/render-path-CWXHrRa2.js.map +1 -0
  47. package/dist/scene-color-passes-CM_T2KF-.js +177 -0
  48. package/dist/scene-color-passes-CM_T2KF-.js.map +1 -0
  49. package/dist/scene-inputs-CbTkrkOw.js +489 -0
  50. package/dist/scene-inputs-CbTkrkOw.js.map +1 -0
  51. package/dist/{shader-declaration-5q__jycG.js → shader-declaration-BGprFBLq.js} +4 -4
  52. package/dist/shader-declaration-BGprFBLq.js.map +1 -0
  53. package/dist/{shader-material-TM4f8eKA.js → shader-material-C9sYMGWw.js} +8 -9
  54. package/dist/shader-material-C9sYMGWw.js.map +1 -0
  55. package/dist/{shader-material-CJIDFvSb.js → shader-material-vmkJ25II.js} +3 -3
  56. package/dist/shader-material-vmkJ25II.js.map +1 -0
  57. package/dist/{shader-pragma-ljmAbVc2.js → shader-pragma-D0MjCOIg.js} +3 -3
  58. package/dist/shader-pragma-D0MjCOIg.js.map +1 -0
  59. package/dist/ssgi-Dk20U3oR.js +492 -0
  60. package/dist/ssgi-Dk20U3oR.js.map +1 -0
  61. package/dist/{surface-shader-rpPpeosD.js → surface-shader-BfADq9Wx.js} +6 -6
  62. package/dist/surface-shader-BfADq9Wx.js.map +1 -0
  63. package/dist/{taa-BwBZLy11.js → taa-nxVA78Ur.js} +5 -6
  64. package/dist/taa-nxVA78Ur.js.map +1 -0
  65. package/dist/vec3-2C3LBZnt.js.map +1 -1
  66. package/package.json +1 -1
  67. package/dist/agx-tone-mapping-Cgt844j6.js.map +0 -1
  68. package/dist/bloom-hdr-CLtQj-oY.js.map +0 -1
  69. package/dist/gtao-Bpu5-0Ne.js.map +0 -1
  70. package/dist/hdr-output-DBQwMphy.js.map +0 -1
  71. package/dist/instanced-mesh-instance-B-fXKSrY.js.map +0 -1
  72. package/dist/light-probe-asset-BqfSrJe9.js.map +0 -1
  73. package/dist/light-probes-DDojYajw.js.map +0 -1
  74. package/dist/material-plugin-DapJNj04.js.map +0 -1
  75. package/dist/overlay-CjVgsfrm.js.map +0 -1
  76. package/dist/post-effect-Cu3Enpz7.js.map +0 -1
  77. package/dist/post-effect-compiler-cCq9lcHt.js.map +0 -1
  78. package/dist/prefab-overrides-C2GsgOQc.js.map +0 -1
  79. package/dist/reflection-probe-QkD1Fo_d.js.map +0 -1
  80. package/dist/reflection-probes-CAzSuqf8.js.map +0 -1
  81. package/dist/render-path-D11i_7X8.js.map +0 -1
  82. package/dist/scene-color-passes-B93qTOka.js +0 -88
  83. package/dist/scene-color-passes-B93qTOka.js.map +0 -1
  84. package/dist/scene-inputs-BxGOsnIZ.js +0 -318
  85. package/dist/scene-inputs-BxGOsnIZ.js.map +0 -1
  86. package/dist/shader-declaration-5q__jycG.js.map +0 -1
  87. package/dist/shader-material-CJIDFvSb.js.map +0 -1
  88. package/dist/shader-material-TM4f8eKA.js.map +0 -1
  89. package/dist/shader-pragma-ljmAbVc2.js.map +0 -1
  90. package/dist/ssgi-DSnhqotl.js +0 -113
  91. package/dist/ssgi-DSnhqotl.js.map +0 -1
  92. package/dist/surface-shader-rpPpeosD.js.map +0 -1
  93. package/dist/taa-BwBZLy11.js.map +0 -1
@@ -3,8 +3,8 @@ import { A as setMeshPickable, D as setMeshBounds, E as removeMeshFromScene, M a
3
3
  import { clearThinInstanceLodPartner, enableThinInstanceDynamicDrawCount, enableThinInstanceGpuCulling, enableThinInstanceWorldBounds, flushThinInstances, setThinInstanceColors, setThinInstanceCount, setThinInstanceCullBoundsPad, setThinInstanceDrawCount, setThinInstanceLodPartner, setThinInstances } from "@babylonjs/lite";
4
4
  //#region src/lite/gpu/thin-instances.ts
5
5
  /**
6
- * Thin-instance half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §2.3,
7
- * `docs/plan/2026-09-terrain-particles-shaders.md` §3.5). Everything here is `@internal` and needs a
6
+ * Thin-instance half of the Babylon Lite adapter (`docs/architecture/07-rendering.md` §2.3, §2.9).
7
+ * Everything here is `@internal` and needs a
8
8
  * WebGPU device, so the browser project is what covers it.
9
9
  *
10
10
  * Lite fixes the order these must be called in, and both the culling opt-in and the LOD pairing only
@@ -763,4 +763,4 @@ function asMesh(node) {
763
763
  //#endregion
764
764
  export { InstancedMeshInstance, createInstancedMesh, releaseInstancedMesh };
765
765
 
766
- //# sourceMappingURL=instanced-mesh-instance-B-fXKSrY.js.map
766
+ //# sourceMappingURL=instanced-mesh-instance-BLdAJTj8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instanced-mesh-instance-BLdAJTj8.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, §2.9).\n * 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/architecture/07-rendering.md` §2.9).\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;;;;;;;;AASA,SAAgBC,qBAAmB,MAAkB;CACnD,mBAAuB,IAAI;AAC7B;;;;;;;;;;;;;;;;;AAkBA,SAAgBC,wBAAsB,MAA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ACrB,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,7 +1,7 @@
1
1
  import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
2
2
  //#region src/render/light-probe-asset.ts
3
3
  /**
4
- * Light probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B2): a regular grid of baked
4
+ * Light probes (`docs/architecture/07-rendering.md` §2.15): a regular grid of baked
5
5
  * irradiance samples that a `LightProbeVolume` lights PBR materials with, in place of the scene
6
6
  * environment's diffuse light. Everything here is plain data and runs in Node.
7
7
  *
@@ -328,4 +328,4 @@ function invalid(address, problem) {
328
328
  //#endregion
329
329
  export { LightProbeAsset as a, readLightProbeFile as c, writeLightProbeFile as d, LIGHT_PROBE_FORMAT_VERSION as i, readLightProbeGrid as l, LIGHT_PROBE_FILE_EXTENSIONS as n, createLightProbeAsset as o, LIGHT_PROBE_FILE_FORMAT as r, packLightProbeTexels as s, LIGHT_PROBE_ASSET_TYPE as t, sampleLightProbes as u };
330
330
 
331
- //# sourceMappingURL=light-probe-asset-BqfSrJe9.js.map
331
+ //# sourceMappingURL=light-probe-asset-DGNIwKNb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light-probe-asset-DGNIwKNb.js","names":[],"sources":["../src/render/light-probe-asset.ts"],"sourcesContent":["import { CoreErrorCode } from \"../errors/error-codes.js\";\nimport { IgnifxError } from \"../errors/ignifx-error.js\";\nimport type { App } from \"../app/types.js\";\nimport type { AssetHandle } from \"../assets/types.js\";\nimport type { Vec3Like } from \"../math/types.js\";\n\n/**\n * Light probes (`docs/architecture/07-rendering.md` §2.15): a regular grid of baked\n * irradiance samples that a `LightProbeVolume` lights PBR materials with, in place of the scene\n * environment's diffuse light. Everything here is plain data and runs in Node.\n *\n * Each probe stores four RGB coefficients of first-order spherical harmonics, already convolved and\n * scaled the way Babylon Lite's environment harmonics are, so the diffuse light a white surface with\n * normal `n` receives is `c0 + c1·n.y + c2·n.z + c3·n.x` (Lite's `environmentIrradiance`, L1 part).\n */\n\n/**\n * The asset type light-probe grids are registered under.\n *\n * @public\n */\nexport const LIGHT_PROBE_ASSET_TYPE = \"lightprobes\";\n\n/**\n * The address extensions that select the light-probe loader.\n *\n * @public\n */\nexport const LIGHT_PROBE_FILE_EXTENSIONS: readonly string[] = Object.freeze([\".probes.json\"]);\n\n/**\n * The `format` header every `.probes.json` carries.\n *\n * @public\n */\nexport const LIGHT_PROBE_FILE_FORMAT = \"ignifx-probes\";\n\n/**\n * The `formatVersion` this engine reads and writes.\n *\n * @public\n */\nexport const LIGHT_PROBE_FORMAT_VERSION = 1;\n\n/** Floats per probe: four RGB coefficients. */\nconst FLOATS_PER_PROBE = 12;\n\n/** The largest grid side along X (the texture is four times as wide) and the largest Y·Z product. */\nconst MAX_X = 1024;\nconst MAX_YZ = 4096;\n\n/** The bounds that keep the generated shader constants valid 32-bit floats. */\nconst MAX_COORDINATE = 1e20;\nconst MIN_CELL = 1e-30;\n\n/**\n * A grid of light probes, as a `.probes.json` stores it.\n *\n * @remarks\n * Probe `(i, j, k)` sits at `origin + (i, j, k) · cellSize`. `coefficients` holds 12 floats per probe,\n * probes ordered X fastest, then Y, then Z (`index = i + countX·(j + countY·k)`); each probe's floats\n * are `c0.rgb, c1.rgb, c2.rgb, c3.rgb` in linear RGB (see the module remarks).\n *\n * @public\n */\nexport interface LightProbeData {\n /** The world position of probe `(0, 0, 0)`. */\n readonly origin: Vec3Like;\n /** The distance between neighbouring probes along each axis, in metres. */\n readonly cellSize: Vec3Like;\n /** How many probes along X, Y and Z; each at least 1. */\n readonly counts: { readonly x: number; readonly y: number; readonly z: number };\n /** 12 floats per probe, `countX · countY · countZ · 12` in all. */\n readonly coefficients: readonly number[];\n}\n\n/**\n * A loaded light-probe grid.\n *\n * @example\n * ```ts\n * const probes = await app.assets.loadAsync<LightProbeAsset>(\"lighting/hall.probes.json\");\n * world.createEntity(\"Probes\").addComponent(LightProbeVolume, { probes });\n * ```\n *\n * @beta\n */\nexport class LightProbeAsset {\n /** The type name the asset service registers light-probe grids under. */\n static assetType: string = LIGHT_PROBE_ASSET_TYPE;\n\n /** The grid. */\n readonly data: LightProbeData;\n\n /**\n * Wraps a checked grid. Use the loader or {@link createLightProbeAsset}.\n *\n * @param data - The grid, already checked by `readLightProbeData`.\n *\n * @internal\n */\n constructor(data: LightProbeData) {\n this.data = data;\n }\n}\n\n/**\n * Publishes a grid built in code, such as the result of a bake, as an asset.\n *\n * @param app - The app.\n * @param data - The grid.\n * @returns A handle a `LightProbeVolume` can take.\n * @throws IgnifxError with code `IGX-0709` when the grid is malformed.\n *\n * @beta\n */\nexport function createLightProbeAsset(app: App, data: LightProbeData): AssetHandle<LightProbeAsset> {\n return app.assets.register(new LightProbeAsset(readLightProbeData(data, \"light probe data\")), {\n type: LIGHT_PROBE_ASSET_TYPE,\n });\n}\n\n/**\n * Turns a grid into the JSON a `.probes.json` file holds.\n *\n * @param data - The grid.\n * @returns The file contents, with the format header.\n *\n * @beta\n */\nexport function writeLightProbeFile(data: LightProbeData): Record<string, unknown> {\n return {\n format: LIGHT_PROBE_FILE_FORMAT,\n formatVersion: LIGHT_PROBE_FORMAT_VERSION,\n origin: { x: data.origin.x, y: data.origin.y, z: data.origin.z },\n cellSize: { x: data.cellSize.x, y: data.cellSize.y, z: data.cellSize.z },\n counts: { x: data.counts.x, y: data.counts.y, z: data.counts.z },\n coefficients: [...data.coefficients],\n };\n}\n\n/**\n * Reads a parsed `.probes.json`.\n *\n * @param parsed - The parsed JSON.\n * @param address - The file's address, for the error.\n * @returns The grid.\n * @throws IgnifxError with code `IGX-0709` when the header, a field or the coefficient count is wrong.\n *\n * @internal\n */\nexport function readLightProbeFile(parsed: unknown, address: string): LightProbeData {\n const file = asRecord(parsed);\n if (\n file === null ||\n file[\"format\"] !== LIGHT_PROBE_FILE_FORMAT ||\n file[\"formatVersion\"] !== LIGHT_PROBE_FORMAT_VERSION\n ) {\n throw invalid(address, `it must start with { \"format\": \"${LIGHT_PROBE_FILE_FORMAT}\", \"formatVersion\": 1 }`);\n }\n return readLightProbeData(file, address);\n}\n\n/**\n * Checks a grid's fields.\n *\n * @param value - The candidate grid.\n * @param address - Where it came from, for the error.\n * @returns A grid with copied, checked fields.\n * @throws IgnifxError with code `IGX-0709` on a malformed field.\n *\n * @internal\n */\nexport function readLightProbeData(value: unknown, address: string): LightProbeData {\n const record = asRecord(value);\n if (record === null) {\n throw invalid(address, \"it is not an object\");\n }\n const grid = readLightProbeGrid(record);\n if (typeof grid === \"string\") {\n throw invalid(address, grid);\n }\n const { origin, cellSize, counts } = grid;\n const coefficients = record[\"coefficients\"];\n const expected = counts.x * counts.y * counts.z * FLOATS_PER_PROBE;\n if (\n !Array.isArray(coefficients) ||\n coefficients.length !== expected ||\n !coefficients.every((n) => Number.isFinite(n))\n ) {\n throw invalid(address, `coefficients must be ${String(expected)} finite numbers (12 per probe)`);\n }\n return { origin, cellSize, counts, coefficients: coefficients.map(Number) };\n}\n\n/**\n * The grid part of a light-probe grid: where it is, how far apart the probes are, and how many.\n *\n * @internal\n */\nexport interface LightProbeGrid {\n readonly origin: { x: number; y: number; z: number };\n readonly cellSize: { x: number; y: number; z: number };\n readonly counts: { x: number; y: number; z: number };\n}\n\n/**\n * Checks the grid fields of a candidate grid, for a file and for a bake alike.\n *\n * @remarks\n * Besides the format's count limits, `origin` stays below 1e20 in size and `cellSize` between\n * 1e-30 and 1e20, so the constants the shader is generated with stay valid 32-bit floats.\n *\n * @param record - An object with `origin`, `cellSize` and `counts`.\n * @returns The checked copies, or what is wrong with them.\n *\n * @internal\n */\nexport function readLightProbeGrid(record: Readonly<Record<string, unknown>>): LightProbeGrid | string {\n const origin = readVec3(record[\"origin\"], (n) => Number.isFinite(n) && Math.abs(n) < MAX_COORDINATE);\n const cellSize = readVec3(record[\"cellSize\"], (n) => Number.isFinite(n) && n > MIN_CELL && n < MAX_COORDINATE);\n const counts = readVec3(record[\"counts\"], (n) => Number.isSafeInteger(n) && n >= 1);\n if (origin === null || cellSize === null || counts === null) {\n return \"origin (finite, below 1e20), cellSize (from 1e-30 to 1e20) and counts (whole, at least 1) must each be { x, y, z }\";\n }\n if (counts.x > MAX_X || counts.y * counts.z > MAX_YZ) {\n return `counts.x must be at most ${String(MAX_X)} and counts.y × counts.z at most ${String(MAX_YZ)}`;\n }\n return { origin, cellSize, counts };\n}\n\n/**\n * The diffuse light a white surface receives at a point, read from the grid on the CPU the same way\n * the shader reads it: trilinear between the eight surrounding probes, clamped at the grid's edges.\n *\n * @param data - The grid.\n * @param x - World X.\n * @param y - World Y.\n * @param z - World Z.\n * @param normal - The surface normal, unit length.\n * @returns Linear RGB.\n *\n * @beta\n */\nexport function sampleLightProbes(\n data: LightProbeData,\n x: number,\n y: number,\n z: number,\n normal: Vec3Like,\n): [number, number, number] {\n const { counts } = data;\n const gx = gridCoordinate(x, data.origin.x, data.cellSize.x, counts.x);\n const gy = gridCoordinate(y, data.origin.y, data.cellSize.y, counts.y);\n const gz = gridCoordinate(z, data.origin.z, data.cellSize.z, counts.z);\n const out: [number, number, number] = [0, 0, 0];\n for (let corner = 0; corner < 8; corner += 1) {\n const ix = corner & 1 ? gx.high : gx.low;\n const iy = corner & 2 ? gy.high : gy.low;\n const iz = corner & 4 ? gz.high : gz.low;\n const weight = (corner & 1 ? gx.t : 1 - gx.t) * (corner & 2 ? gy.t : 1 - gy.t) * (corner & 4 ? gz.t : 1 - gz.t);\n const base = (ix + counts.x * (iy + counts.y * iz)) * FLOATS_PER_PROBE;\n for (let channel = 0; channel < 3; channel += 1) {\n const c = (index: number): number => data.coefficients[base + index * 3 + channel] ?? 0;\n out[channel] = (out[channel] ?? 0) + weight * (c(0) + c(1) * normal.y + c(2) * normal.z + c(3) * normal.x);\n }\n }\n return out;\n}\n\n/**\n * Packs a grid into the half-float RGBA texels the shader reads: probe `(i, j, k)`'s coefficient `c`\n * at texel `(i + countX·c, j + countY·k)`.\n *\n * @param data - The grid.\n * @returns The width, height and texels (four half floats each, alpha 1).\n *\n * @internal\n */\nexport function packLightProbeTexels(data: LightProbeData): { width: number; height: number; texels: Uint16Array } {\n const { x: nx, y: ny, z: nz } = data.counts;\n const width = nx * 4;\n const height = ny * nz;\n const texels = new Uint16Array(width * height * 4);\n const one = toHalfFloat(1);\n for (let k = 0; k < nz; k += 1) {\n for (let j = 0; j < ny; j += 1) {\n for (let i = 0; i < nx; i += 1) {\n const base = (i + nx * (j + ny * k)) * FLOATS_PER_PROBE;\n for (let c = 0; c < 4; c += 1) {\n const texel = (i + nx * c + width * (j + ny * k)) * 4;\n for (let channel = 0; channel < 3; channel += 1) {\n texels[texel + channel] = toHalfFloat(data.coefficients[base + c * 3 + channel] ?? 0);\n }\n texels[texel + 3] = one;\n }\n }\n }\n }\n return { width, height, texels };\n}\n\n/**\n * Converts a number to IEEE 754 half precision, rounding to nearest and saturating to ±65504.\n *\n * @param value - The number.\n * @returns The 16 bits.\n *\n * @internal\n */\nexport function toHalfFloat(value: number): number {\n if (Number.isNaN(value)) {\n return 0x7e00;\n }\n const sign = value < 0 || Object.is(value, -0) ? 0x8000 : 0;\n const magnitude = Math.min(Math.abs(value), 65504);\n if (magnitude < 2 ** -24) {\n return sign;\n }\n if (magnitude < 2 ** -14) {\n return sign | Math.round(magnitude / 2 ** -24);\n }\n const exponent = Math.floor(Math.log2(magnitude));\n const mantissa = Math.round((magnitude / 2 ** exponent - 1) * 1024);\n // A mantissa that rounds up to 1024 carries into the exponent.\n return sign | (((exponent + 15) << 10) + mantissa);\n}\n\n/** A grid axis lookup: the two probe indices around a point and the blend between them. */\ninterface AxisCell {\n readonly low: number;\n readonly high: number;\n readonly t: number;\n}\n\n/**\n * Finds the probes around a coordinate on one axis.\n *\n * @param value - The world coordinate.\n * @param origin - The grid origin on this axis.\n * @param cell - The cell size on this axis.\n * @param count - The probe count on this axis.\n * @returns The cell.\n */\nfunction gridCoordinate(value: number, origin: number, cell: number, count: number): AxisCell {\n const g = Math.min(Math.max((value - origin) / cell, 0), count - 1);\n const low = Math.min(Math.floor(g), Math.max(count - 2, 0));\n const high = Math.min(low + 1, count - 1);\n return { low, high, t: g - low };\n}\n\n/**\n * Reads `{ x, y, z }` whose components all pass a check.\n *\n * @param value - The candidate.\n * @param check - The per-component test.\n * @returns A copy, or `null`.\n */\nfunction readVec3(value: unknown, check: (n: number) => boolean): { x: number; y: number; z: number } | null {\n const record = asRecord(value);\n if (record === null) {\n return null;\n }\n const { x, y, z } = record;\n if (typeof x !== \"number\" || typeof y !== \"number\" || typeof z !== \"number\" || ![x, y, z].every(check)) {\n return null;\n }\n return { x, y, z };\n}\n\n/**\n * Narrows a value to a plain record.\n *\n * @param value - The candidate.\n * @returns The record, or `null` for anything else.\n */\nfunction asRecord(value: unknown): Record<string, unknown> | null {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return null;\n }\n // Boundary narrowing of parsed JSON (coding standards §5.2).\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n return value as Record<string, unknown>;\n}\n\n/**\n * The error for a malformed grid.\n *\n * @param address - Where it came from.\n * @param problem - What is wrong.\n * @returns The error.\n */\nfunction invalid(address: string, problem: string): IgnifxError {\n return new IgnifxError(CoreErrorCode.invalidAssetFile, `${address} is not an ${LIGHT_PROBE_FILE_FORMAT} file.`, {\n context: { file: address, format: LIGHT_PROBE_FILE_FORMAT },\n hint: `Fix the file: ${problem}.`,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAa,yBAAyB;;;;;;AAOtC,MAAa,8BAAiD,OAAO,OAAO,CAAC,cAAc,CAAC;;;;;;AAO5F,MAAa,0BAA0B;;;;;;AAOvC,MAAa,6BAA6B;;AAG1C,MAAM,mBAAmB;;AAGzB,MAAM,QAAQ;AACd,MAAM,SAAS;;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O;CAET,OAAO;EAAE;EAAG;EAAG;CAAE;AACnB;;;;;;;AAQA,SAAS,SAAS,OAAgD;CAChE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,OAAO;CAIT,OAAO;AACT;;;;;;;;AASA,SAAS,QAAQ,SAAiB,SAA8B;CAC9D,OAAO,IAAI,YAAY,cAAc,kBAAkB,GAAG,QAAQ,aAAa,wBAAwB,SAAS;EAC9G,SAAS;GAAE,MAAM;GAAS,QAAQ;EAAwB;EAC1D,MAAM,iBAAiB,QAAQ;CACjC,CAAC;AACH"}
@@ -1,11 +1,11 @@
1
- import { i as readSceneEnvironment } from "./environment-Bf4aphSb.js";
1
+ import { i as readSceneEnvironment } from "./environment-7fJbN402.js";
2
2
  import { a as markMaterialDirty, o as rebuildMaterialPipelines } from "./material-myMbl9mW.js";
3
- import { s as packLightProbeTexels } from "./light-probe-asset-BqfSrJe9.js";
3
+ import { s as packLightProbeTexels } from "./light-probe-asset-DGNIwKNb.js";
4
4
  import { n as deviceOf } from "./render-texture-UqRHRLQy.js";
5
5
  import { createRenderTexture2D, enableMaterialPlugins, getPbrUnlit, isPbrMaterial, isPbrSkybox } from "@babylonjs/lite";
6
6
  //#region src/lite/gpu/light-probes.ts
7
7
  /**
8
- * Light probes on the GPU (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B2). Its own chunk,
8
+ * Light probes on the GPU (`docs/architecture/07-rendering.md` §2.15). Its own chunk,
9
9
  * loaded only once a world has a `LightProbeVolume` (`CONSTITUTION.md` §2.5). Every Lite claim was
10
10
  * read from `@babylonjs/lite@1.34.0`.
11
11
  *
@@ -180,8 +180,8 @@ function swapLightProbePlugin(scene, previous, next) {
180
180
  //#endregion
181
181
  //#region src/render/gpu/light-probes.ts
182
182
  /**
183
- * The render layer's half of light probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step
184
- * B2): which volume lights the scene, and keeping its plugin on every lit PBR material. Loaded with
183
+ * The render layer's half of light probes (`docs/architecture/07-rendering.md` §2.15): which volume
184
+ * lights the scene, and keeping its plugin on every lit PBR material. Loaded with
185
185
  * `../../lite/gpu/light-probes.ts` as one chunk, only once a world has a `LightProbeVolume`.
186
186
  */
187
187
  /** Frames a replaced texture outlives its plugin, so no in-flight bind group still names it. */
@@ -281,4 +281,4 @@ function createLightProbeRuntime(engine, scene) {
281
281
  //#endregion
282
282
  export { createLightProbeRuntime };
283
283
 
284
- //# sourceMappingURL=light-probes-DDojYajw.js.map
284
+ //# sourceMappingURL=light-probes-C8jharz9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light-probes-C8jharz9.js","names":[],"sources":["../src/lite/gpu/light-probes.ts","../src/render/gpu/light-probes.ts"],"sourcesContent":["import { createRenderTexture2D, enableMaterialPlugins, getPbrUnlit, isPbrMaterial, isPbrSkybox } from \"@babylonjs/lite\";\nimport { markMaterialDirty, rebuildMaterialPipelines } from \"../material.js\";\nimport { deviceOf } from \"./render-texture.js\";\nimport type { EngineContext, MaterialPlugin, SceneContext, Texture2D } from \"@babylonjs/lite\";\n\n/**\n * Light probes on the GPU (`docs/architecture/07-rendering.md` §2.15). Its own chunk,\n * loaded only once a world has a `LightProbeVolume` (`CONSTITUTION.md` §2.5). Every Lite claim was\n * read from `@babylonjs/lite@1.34.0`.\n *\n * - **Texture.** The grid's coefficients, packed by `packLightProbeTexels`, in an `rgba16float`\n * texture read with `textureLoad` (plugins bind `texture_2d<f32>` only, `index.d.ts` 10607, so no\n * 3D texture).\n * - **Plugin.** Lite declares `environmentIrradiance` with `let` inside the IBL code\n * (`lib/material/pbr/fragments/ibl-fragment.js`), so a plugin cannot replace it. Instead the plugin\n * adds `(probes − environment) · surfaceAlbedo · occlusion` to `color`, recomputing the\n * environment's harmonics from the scene uniforms the IBL code reads. Its point,\n * `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION`, is injected twice (`AI` before the IBL code, `NI`\n * after it; `lib/material/plugin/plugin-bridge-shared.js` line 13), so a private counter applies it\n * on the second pass only. Its priority runs it before the HDR linear-output plugin saves `color`.\n * - **Grid constants** are written into the WGSL, so a different grid is a different plugin and a\n * material rebuild: grids change rarely. `intensity` is a uniform on the host material's block,\n * so changing it rebuilds nothing.\n */\n\n/**\n * The name the plugin carries; part of Lite's pipeline cache key.\n *\n * @internal\n */\nexport const LIGHT_PROBE_PLUGIN_NAME = \"ignifx-light-probes\";\n\n/**\n * The grid shape the shader needs.\n *\n * @internal\n */\nexport interface LightProbeGridShape {\n /** Probe `(0, 0, 0)`'s world position. */\n readonly origin: readonly [number, number, number];\n /** The cell size per axis. */\n readonly cellSize: readonly [number, number, number];\n /** Probe counts per axis. */\n readonly counts: readonly [number, number, number];\n}\n\n/**\n * The plugin's live settings: read on every material uniform write, so changing them needs only\n * {@link refreshLightProbeUniforms}, not a pipeline rebuild.\n *\n * @internal\n */\nexport interface LightProbeUniforms {\n /** The multiplier on the probes' light. */\n intensity: number;\n}\n\n/** The uniform field the plugin adds to each host material's block. */\nconst INTENSITY_FIELD = \"ignifxLpIntensity\";\n\n/**\n * A WGSL float literal.\n *\n * @param value - A finite number.\n * @returns The literal.\n */\nfunction f(value: number): string {\n return Number.isInteger(value) ? `${String(value)}.0` : String(value);\n}\n\n/**\n * The plugin's WGSL.\n *\n * @param shape - The grid.\n * @returns The definitions and the composition code.\n *\n * @internal\n */\nexport function lightProbePluginWgsl(shape: LightProbeGridShape): { definitions: string; composition: string } {\n const [nx, ny, nz] = shape.counts;\n const origin = `vec3<f32>(${shape.origin.map(f).join(\",\")})`;\n const inverse = `vec3<f32>(${shape.cellSize.map((size) => f(1 / size)).join(\",\")})`;\n const maxCell = `vec3<f32>(${f(nx - 1)},${f(ny - 1)},${f(nz - 1)})`;\n const definitions =\n \"var<private> igxLpPass:i32;\" +\n \"fn igxLpTexel(c:vec3<i32>,k:i32)->vec3<f32>{\" +\n `return textureLoad(ignifxLp,vec2<i32>(c.x+${String(nx)}*k,c.y+${String(ny)}*c.z),0).rgb;}` +\n \"fn igxLpAt(c:vec3<i32>,n:vec3<f32>)->vec3<f32>{\" +\n \"return igxLpTexel(c,0)+igxLpTexel(c,1)*n.y+igxLpTexel(c,2)*n.z+igxLpTexel(c,3)*n.x;}\" +\n \"fn igxLpSample(p:vec3<f32>,n:vec3<f32>)->vec3<f32>{\" +\n `let m=${maxCell};let g=clamp((p-${origin})*${inverse},vec3<f32>(0.0),m);` +\n \"let lo=min(floor(g),max(m-1.0,vec3<f32>(0.0)));let t=g-lo;let hi=min(lo+1.0,m);\" +\n \"var r=vec3<f32>(0.0);\" +\n \"for(var i=0;i<8;i++){let s=vec3<i32>(i&1,(i>>1u)&1,(i>>2u)&1)==vec3<i32>(1);\" +\n \"let w=select(1.0-t,t,s);r+=igxLpAt(vec3<i32>(select(lo,hi,s)),n)*(w.x*w.y*w.z);}\" +\n // Trilinear blending of ringing harmonics can dip below zero; light never does.\n \"return max(r,vec3<f32>(0.0));}\";\n const composition =\n \"igxLpPass=igxLpPass+1;\" +\n \"if(igxLpPass==2){\" +\n \"let igxC=cos(scene.envRotationY);let igxS=sin(scene.envRotationY);\" +\n \"let igxN=vec3<f32>(N.x*igxC+N.z*igxS,N.y,-N.x*igxS+N.z*igxC);\" +\n \"let igxEnv=(scene.vSphericalL00.rgb+scene.vSphericalL1_1.rgb*igxN.y+scene.vSphericalL10.rgb*igxN.z\" +\n \"+scene.vSphericalL11.rgb*igxN.x+scene.vSphericalL2_2.rgb*(igxN.y*igxN.x)+scene.vSphericalL2_1.rgb*(igxN.y*igxN.z)\" +\n \"+scene.vSphericalL20.rgb*(3.0*igxN.z*igxN.z-1.0)+scene.vSphericalL21.rgb*(igxN.z*igxN.x)\" +\n \"+scene.vSphericalL22.rgb*(igxN.x*igxN.x-igxN.y*igxN.y))*material.environmentIntensity;\" +\n `color+=(igxLpSample(input.worldPos,N)*material.${INTENSITY_FIELD}-igxEnv)*surfaceAlbedo*occlusion;}`;\n return { definitions, composition };\n}\n\n/**\n * Installs Lite's material-plugin bridges, which the plugin needs, unless the project already did.\n *\n * @remarks\n * Idempotent (`lib/material/plugin/enable-material-plugins.js` replaces its one scene hook). The\n * HDR path calls it before `registerScene` (`./hdr-output.ts`); here it runs after, which works for\n * PBR because the bridge assigns a material's plugin identity during the rebuild that attaching\n * the plugin queues. `light-probe.browser.test.ts` covers that case with HDR off.\n *\n * @param scene - The registered scene.\n *\n * @internal\n */\nexport function enableLightProbePlugins(scene: SceneContext): void {\n enableMaterialPlugins(scene);\n}\n\n/**\n * Uploads packed probe texels into a texture.\n *\n * @param engine - The engine.\n * @param width - The texel width.\n * @param height - The texel height.\n * @param texels - Four half floats per texel.\n * @returns The texture, or `null` when the engine has no device.\n *\n * @internal\n */\nexport function createLightProbeTexture(\n engine: EngineContext,\n width: number,\n height: number,\n texels: Uint16Array,\n): Texture2D | null {\n const device = deviceOf(engine);\n if (device === null) {\n return null;\n }\n const texture = createRenderTexture2D(engine, width, height, {\n format: \"rgba16float\",\n minFilter: \"nearest\",\n magFilter: \"nearest\",\n });\n device.queue.writeTexture({ texture: texture.texture }, texels, { bytesPerRow: width * 8 }, { width, height });\n return texture;\n}\n\n/**\n * Builds the plugin for one grid and its texture.\n *\n * @param shape - The grid.\n * @param texture - The packed texture.\n * @param uniforms - The live settings; the plugin reads them on every uniform write.\n * @returns The plugin, shared by every lit PBR material.\n *\n * @internal\n */\nexport function createLightProbePlugin(\n shape: LightProbeGridShape,\n texture: Texture2D,\n uniforms: LightProbeUniforms,\n): MaterialPlugin {\n const wgsl = lightProbePluginWgsl(shape);\n const fragment = {\n CUSTOM_FRAGMENT_DEFINITIONS: wgsl.definitions,\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: wgsl.composition,\n };\n return {\n name: LIGHT_PROBE_PLUGIN_NAME,\n // Before the HDR linear-output plugin (priority 0) saves `color` at the same point.\n priority: -100,\n getSamplers: () => [{ texture: \"ignifxLp\", sampler: \"ignifxLpSampler\" }],\n getUniforms: () => ({ ubo: [{ name: INTENSITY_FIELD, type: \"f32\" }] }),\n writeUbo: (data, offsets) => {\n // Lite hands over byte offsets.\n const byteOffset = offsets.get(INTENSITY_FIELD);\n if (byteOffset !== undefined) {\n data[byteOffset / 4] = uniforms.intensity;\n }\n },\n bindTextures: (out) => {\n out.push({ texture });\n },\n getCustomCode: (stage) => (stage === \"fragment\" ? fragment : null),\n };\n}\n\n/**\n * Re-uploads the plugin's uniforms on every material that carries it, after\n * {@link LightProbeUniforms} changed.\n *\n * @param scene - The scene.\n * @param plugin - The plugin.\n *\n * @internal\n */\nexport function refreshLightProbeUniforms(scene: SceneContext, plugin: MaterialPlugin): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const material = meshes[index]?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n if (material.plugins?.includes(plugin) === true) {\n markMaterialDirty(material);\n }\n }\n}\n\n/**\n * Gives every lit PBR material `next` in place of `previous`, rebuilding the ones that changed.\n *\n * @param scene - The registered scene.\n * @param previous - The plugin to take off, or `null`.\n * @param next - The plugin to put on, or `null` to only take `previous` off.\n *\n * @internal\n */\nexport function swapLightProbePlugin(\n scene: SceneContext,\n previous: MaterialPlugin | null,\n next: MaterialPlugin | null,\n): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const material = meshes[index]?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n const current = material.plugins ?? [];\n const lit = getPbrUnlit(material) === undefined && !isPbrSkybox(material);\n const hasPrevious = previous !== null && current.includes(previous);\n const wantsNext = next !== null && lit;\n if (!hasPrevious && (!wantsNext || current.includes(next))) {\n continue;\n }\n const kept = hasPrevious ? current.filter((plugin) => plugin !== previous) : current;\n material.plugins = wantsNext && !kept.includes(next) ? [...kept, next] : kept;\n rebuildMaterialPipelines(scene, material);\n }\n}\n","import { readSceneEnvironment } from \"../../lite/gpu/environment.js\";\nimport {\n createLightProbePlugin,\n createLightProbeTexture,\n enableLightProbePlugins,\n refreshLightProbeUniforms,\n swapLightProbePlugin,\n} from \"../../lite/gpu/light-probes.js\";\nimport { packLightProbeTexels } from \"../light-probe-asset.js\";\nimport type { LightProbeUniforms } from \"../../lite/gpu/light-probes.js\";\nimport type { LiteMaterialPlugin } from \"../../lite/gpu/material-plugin.js\";\nimport type { LiteEngine, LiteScene } from \"../../lite/scene.js\";\nimport type { LightProbeAsset } from \"../light-probe-asset.js\";\nimport type { LightProbeVolume } from \"../light-probe-volume.js\";\n\n/**\n * The render layer's half of light probes (`docs/architecture/07-rendering.md` §2.15): which volume\n * lights the scene, and keeping its plugin on every lit PBR material. Loaded with\n * `../../lite/gpu/light-probes.ts` as one chunk, only once a world has a `LightProbeVolume`.\n */\n\n/** Frames a replaced texture outlives its plugin, so no in-flight bind group still names it. */\nconst RETIRE_FRAMES = 8;\n\n/** What is applied: which grid, at which intensity, through which plugin. */\ninterface Applied {\n readonly asset: LightProbeAsset;\n readonly uniforms: LightProbeUniforms;\n readonly plugin: LiteMaterialPlugin;\n readonly destroy: () => void;\n}\n\n/**\n * The light probes of a renderer.\n *\n * @internal\n */\nexport interface LightProbeRuntime {\n /** Whether a grid is applied. */\n readonly isLighting: boolean;\n /**\n * Picks the volume that lights the scene and keeps its plugin on every lit PBR material.\n *\n * @param volumes - Every `LightProbeVolume` in the world.\n */\n update(volumes: readonly LightProbeVolume[]): void;\n /** Takes the plugin off every material and frees the texture. */\n dispose(): void;\n}\n\n/**\n * Creates the runtime.\n *\n * @param engine - The engine.\n * @param scene - The registered render scene.\n * @returns The runtime.\n *\n * @internal\n */\nexport function createLightProbeRuntime(engine: LiteEngine, scene: LiteScene): LightProbeRuntime {\n enableLightProbePlugins(scene);\n let applied: Applied | null = null;\n const retiring: { destroy: () => void; frames: number }[] = [];\n\n const apply = (asset: LightProbeAsset, intensity: number): Applied | null => {\n const { data } = asset;\n const packed = packLightProbeTexels(data);\n const texture = createLightProbeTexture(engine, packed.width, packed.height, packed.texels);\n if (texture === null) {\n return null;\n }\n const uniforms: LightProbeUniforms = { intensity };\n const plugin = createLightProbePlugin(\n {\n origin: [data.origin.x, data.origin.y, data.origin.z],\n cellSize: [data.cellSize.x, data.cellSize.y, data.cellSize.z],\n counts: [data.counts.x, data.counts.y, data.counts.z],\n },\n texture,\n uniforms,\n );\n return { asset, uniforms, plugin, destroy: () => texture.texture.destroy() };\n };\n\n const replace = (next: Applied | null): void => {\n swapLightProbePlugin(scene, applied?.plugin ?? null, next?.plugin ?? null);\n if (applied !== null) {\n retiring.push({ destroy: applied.destroy, frames: RETIRE_FRAMES });\n }\n applied = next;\n };\n\n return {\n get isLighting(): boolean {\n return applied !== null;\n },\n update(volumes: readonly LightProbeVolume[]): void {\n for (let index = retiring.length - 1; index >= 0; index -= 1) {\n const entry = retiring[index];\n if (entry !== undefined && --entry.frames <= 0) {\n entry.destroy();\n retiring.splice(index, 1);\n }\n }\n let winner: LightProbeVolume | null = null;\n let asset: LightProbeAsset | null = null;\n // The plugin recomputes the environment's harmonics, so it needs one installed.\n if (readSceneEnvironment(scene) !== null) {\n for (const volume of volumes) {\n const loaded = volume.isEnabledInHierarchy ? volume.loadedProbes() : null;\n if (loaded !== null) {\n winner = volume;\n asset = loaded;\n }\n }\n }\n if (winner === null || asset === null) {\n if (applied !== null) {\n replace(null);\n }\n return;\n }\n if (applied === null || applied.asset !== asset) {\n replace(apply(asset, winner.intensity));\n return;\n }\n if (applied.uniforms.intensity !== winner.intensity) {\n applied.uniforms.intensity = winner.intensity;\n refreshLightProbeUniforms(scene, applied.plugin);\n }\n // Meshes created since the last frame get the plugin too; nothing is rebuilt otherwise.\n swapLightProbePlugin(scene, null, applied.plugin);\n },\n dispose(): void {\n replace(null);\n for (const entry of retiring) {\n entry.destroy();\n }\n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,QAAQ,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG;IAC5D,MAAM,QAAQ,SAAS;IACvB,IAAI,UAAU,KAAA,KAAa,EAAE,MAAM,UAAU,GAAG;KAC9C,MAAM,QAAQ;KACd,SAAS,OAAO,OAAO,CAAC;IAC1B;GACF;GACA,IAAI,SAAkC;GACtC,IAAI,QAAgC;GAEpC,IAAI,qBAAqB,KAAK,MAAM,MAClC,KAAK,MAAM,UAAU,SAAS;IAC5B,MAAM,SAAS,OAAO,uBAAuB,OAAO,aAAa,IAAI;IACrE,IAAI,WAAW,MAAM;KACnB,SAAS;KACT,QAAQ;IACV;GACF;GAEF,IAAI,WAAW,QAAQ,UAAU,MAAM;IACrC,IAAI,YAAY,MACd,QAAQ,IAAI;IAEd;GACF;GACA,IAAI,YAAY,QAAQ,QAAQ,UAAU,OAAO;IAC/C,QAAQ,MAAM,OAAO,OAAO,SAAS,CAAC;IACtC;GACF;GACA,IAAI,QAAQ,SAAS,cAAc,OAAO,WAAW;IACnD,QAAQ,SAAS,YAAY,OAAO;IACpC,0BAA0B,OAAO,QAAQ,MAAM;GACjD;GAEA,qBAAqB,OAAO,MAAM,QAAQ,MAAM;EAClD;EACA,UAAgB;GACd,QAAQ,IAAI;GACZ,KAAK,MAAM,SAAS,UAClB,MAAM,QAAQ;GAEhB,SAAS,SAAS;EACpB;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"lightmaps-BUUIIkt9.js","names":[],"sources":["../src/lite/gpu/lightmap.ts","../src/render/gpu/lightmaps.ts"],"sourcesContent":["import { enableMaterialPlugins, enablePbrLightmap, isPbrMaterial, setPbrLightmap } from \"@babylonjs/lite\";\nimport { markMaterialDirty } from \"../material.js\";\nimport type { Material, MaterialPlugin, SceneContext, Texture2D } from \"@babylonjs/lite\";\n\n/**\n * Lightmaps on the GPU (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B3). Loaded with\n * `../../render/gpu/lightmaps.ts` as one chunk, only once a static `MeshRenderer` names a loaded\n * lightmap (`CONSTITUTION.md` §2.5). Every Lite claim was read from `@babylonjs/lite@1.34.0`.\n *\n * - **Late enable.** `enablePbrLightmap` (`index.d.ts` 5342) asks to be awaited before\n * `registerScene`, but all it does is register the fragment extension in a process-wide map whose\n * sorted cache it resets (`lib/material/pbr/pbr-flags.js`, `_registerPbrExt`). A material that has\n * no `lightmapTexture` reports no lightmap feature bits (`lightmap-fragment.js`, `detect`), so\n * pipelines built before the call keep their keys, and a material built after it sees the\n * extension. The chunk therefore enables it on load; `rendering.features.lightmaps` only does it\n * earlier.\n * - **Per-material.** `setPbrLightmap` (12635) writes the texture, level, UV set, blend mode and\n * decode onto one material and claims TEXCOORD_1 for it, so a renderer gets its own material\n * before the call. Only `level` is a uniform (`writeLightmapUBO`); the rest are feature bits, so a\n * change of them needs a new material.\n * - **Atlas placement (GI plan §5, spike P2).** The fragment samples `input.uv2` raw (line 24) and\n * ignores the texture's `uScale`/`uOffset`, so Lite has no lightmap UV transform. The PBR vertex\n * template writes `out.uv2 = uv2;` just before the `CUSTOM_VERTEX_MAIN_END` slot\n * (`lib/material/pbr/pbr-template.js` 133, `pbr-template-ext.js` 71), so a plugin there rewrites\n * the varying the lightmap reads: {@link lightmapAtlasPlugin}. The scale and offset are WGSL\n * constants rather than uniforms, because a vertex-visible plugin uniform needs\n * `enablePbrMaterialPluginVertexData` (`index.d.ts` 5349), whose bridge maps\n * `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` to the `NI` slot only\n * (`lib/material/plugin/pbr-plugin-vertex-data.js` versus `plugin-bridge-shared.js`, which also\n * injects it at `AI`), and the light-probe, HDR-output and SSGI plugins count on the double\n * injection. So each distinct placement is its own pipeline variant. The varying exists only\n * when the lightmap samples TEXCOORD_1 and the mesh has a `uvs2` buffer (`pbr-compose.js` 42), so\n * the plugin is only for that case. Lite's own V flip, when the texture asks for one, applies to\n * the transformed coordinate, as it does to the raw one.\n */\n\n/**\n * The options one material's lightmap is drawn with.\n *\n * @internal\n */\nexport interface LiteLightmapOptions {\n /** Intensity multiplier on the sample. */\n readonly level: number;\n /** `true` multiplies the shaded colour (Lite's `useAsShadowmap`); `false` adds to it. */\n readonly shadowmap: boolean;\n /** Decode the sample from sRGB to linear (`pow(x, 2.2)`). */\n readonly gamma: boolean;\n /** Sample with the second UV set (`TEXCOORD_1`) rather than the first. */\n readonly uv2: boolean;\n /**\n * Where the renderer's UV2 square sits in the texture (`uv2 · scale + offset`), or `null` for the\n * whole texture. Only honoured with `uv2` on a mesh that has a second UV set.\n */\n readonly atlas: LiteLightmapAtlas | null;\n}\n\n/**\n * One renderer's placement in a lightmap atlas, as plain numbers.\n *\n * @internal\n */\nexport interface LiteLightmapAtlas {\n /** The atlas-space size of the renderer's UV2 square. */\n readonly scale: { readonly x: number; readonly y: number };\n /** The atlas-space position of the square's `(0, 0)` corner. */\n readonly offset: { readonly x: number; readonly y: number };\n}\n\n/** The atlas plugins made so far, by WGSL; a plugin holds no state, so one per placement does. */\nlet atlasPlugins: Map<string, MaterialPlugin> | null = null;\n\n/** The name every atlas plugin carries; the WGSL tells placements apart in Lite's cache key. */\nexport const LIGHTMAP_ATLAS_PLUGIN_NAME = \"ignifx-lightmap-atlas\";\n\n/**\n * A WGSL float literal, always with a decimal point or an exponent.\n *\n * @param value - A finite number.\n * @returns The literal.\n */\nfunction float(value: number): string {\n const text = String(value);\n return /[.e]/.test(text) ? text : `${text}.0`;\n}\n\n/**\n * The vertex code that moves the lightmap's UV2 varying into the renderer's atlas square.\n *\n * @param atlas - The placement.\n * @returns WGSL for `CUSTOM_VERTEX_MAIN_END`.\n *\n * @internal\n */\nexport function lightmapAtlasWgsl(atlas: LiteLightmapAtlas): string {\n const { scale, offset } = atlas;\n return (\n `out.uv2=out.uv2*vec2<f32>(${float(scale.x)},${float(scale.y)})` +\n `+vec2<f32>(${float(offset.x)},${float(offset.y)});`\n );\n}\n\n/**\n * The plugin that applies one atlas placement, shared by every material with that placement.\n *\n * @remarks\n * Only valid on a material whose lightmap samples TEXCOORD_1 drawn on a mesh with a `uvs2` buffer:\n * anywhere else `out.uv2` does not exist and the pipeline fails to compile.\n *\n * @param atlas - The placement.\n * @returns The plugin; the same object for the same placement.\n *\n * @internal\n */\nexport function lightmapAtlasPlugin(atlas: LiteLightmapAtlas): MaterialPlugin {\n const code = lightmapAtlasWgsl(atlas);\n atlasPlugins ??= new Map();\n let plugin = atlasPlugins.get(code);\n if (plugin === undefined) {\n const vertex = { CUSTOM_VERTEX_MAIN_END: code };\n plugin = {\n name: LIGHTMAP_ATLAS_PLUGIN_NAME,\n getCustomCode: (stage) => (stage === \"vertex\" ? vertex : null),\n };\n atlasPlugins.set(code, plugin);\n }\n return plugin;\n}\n\n/**\n * Whether a plugin is an atlas plugin.\n *\n * @param plugin - Any plugin.\n * @returns `true` for one {@link lightmapAtlasPlugin} made.\n */\nfunction isAtlasPlugin(plugin: MaterialPlugin): boolean {\n return plugin.name === LIGHTMAP_ATLAS_PLUGIN_NAME;\n}\n\n/**\n * Installs Lite's PBR lightmap extension. Idempotent.\n *\n * @returns A promise that settles once the extension is registered.\n *\n * @internal\n */\nexport function enableLightmaps(): Promise<void> {\n return enablePbrLightmap();\n}\n\n/**\n * Gives a PBR material a lightmap.\n *\n * @remarks\n * With an `atlas` placement (and `uv2`), the material also gets the {@link lightmapAtlasPlugin} for\n * it, replacing an earlier one, and the scene's material-plugin bridges are installed first\n * (idempotent; light probes install them after `registerScene` the same way). The caller rebuilds\n * the material's pipelines afterwards.\n *\n * @param scene - The registered scene.\n * @param material - A material no other mesh shares, not yet built with other lightmap options.\n * @param texture - The lightmap.\n * @param options - How it is drawn.\n * @returns `false` when the material is not PBR, so nothing was set.\n *\n * @internal\n */\nexport function applyLightmap(\n scene: SceneContext,\n material: Material,\n texture: Texture2D,\n options: LiteLightmapOptions,\n): boolean {\n if (!isPbrMaterial(material)) {\n return false;\n }\n setPbrLightmap(material, texture, {\n level: options.level,\n coordIndex: options.uv2 ? 1 : 0,\n useAsShadowmap: options.shadowmap,\n gamma: options.gamma,\n });\n const current = material.plugins ?? [];\n const kept = current.some(isAtlasPlugin) ? current.filter((plugin) => !isAtlasPlugin(plugin)) : current;\n if (options.atlas !== null && options.uv2) {\n enableMaterialPlugins(scene);\n material.plugins = [...kept, lightmapAtlasPlugin(options.atlas)];\n } else if (kept !== current) {\n material.plugins = kept;\n }\n return true;\n}\n\n/**\n * Changes a lightmapped material's intensity; only its uniform block is rewritten.\n *\n * @param material - A material {@link applyLightmap} set up.\n * @param level - The new multiplier.\n *\n * @internal\n */\nexport function setLightmapLevel(material: Material, level: number): void {\n if (isPbrMaterial(material) && material.lightmapLevel !== level) {\n material.lightmapLevel = level;\n markMaterialDirty(material);\n }\n}\n","import { applyLightmap, enableLightmaps, lightmapAtlasWgsl, setLightmapLevel } from \"../../lite/gpu/lightmap.js\";\nimport { rebuildMaterialPipelines, syncPbrFactors } from \"../../lite/material.js\";\nimport type { App } from \"../../app/types.js\";\nimport type { AssetHandle } from \"../../assets/types.js\";\nimport type { LiteLightmapOptions } from \"../../lite/gpu/lightmap.js\";\nimport type { LiteTexture2D } from \"../../lite/gpu/texture.js\";\nimport type { LiteMaterial } from \"../../lite/material.js\";\nimport type { LiteScene } from \"../../lite/scene.js\";\nimport type { LightmapAsset, LightmapPlacement } from \"../lightmap-asset.js\";\nimport type { MaterialAsset } from \"../material-asset.js\";\nimport type { LightmapMode, MeshRendererLightmap } from \"../mesh-renderer.js\";\n\n/**\n * The render layer's half of lightmaps (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B3):\n * one material clone per lightmapped renderer. Loaded with `../../lite/gpu/lightmap.ts` as one\n * chunk, only once a static `MeshRenderer` names a loaded lightmap.\n *\n * `MaterialAsset`s are shared, and a lightmap is per renderer, so each renderer draws with\n * `MaterialAsset.clone` of its material carrying the lightmap. The clone is rebuilt when the\n * material, the lightmap, its texture, a compiled option (`mode`, `gamma`, `uv2`) or the atlas\n * placement changes; a `level` change only rewrites the clone's uniform block. A placement other\n * than the whole texture is a vertex plugin on the clone (`../../lite/gpu/lightmap.ts`), one\n * pipeline variant per distinct placement. Nothing here allocates on a frame where no clone changes. Edits made to the shared material through\n * its factor setters (`setBaseColor`, `setMetallicRoughness`, `setAlpha`) are copied onto the clone\n * the next frame it is asked for (a comparison of seven numbers per frame); a reloaded material is a\n * new asset, so it gets a new clone.\n *\n * ## Two frames, because of how Lite plumbs `uv2`\n *\n * Lite decides whether its PBR group carries the `uv2` attribute and varying when it builds the\n * group, from the meshes' materials at that time (`lib/material/pbr/pbr-renderable.js`, `hasAnyUv2`).\n * A `mesh.material` swap reuses the group's single-mesh rebuild (`lib/scene/scene-material-swap.js`),\n * whose composer has no `uv2` then, and a lightmap that samples `input.uv2` fails to compile; the\n * pipeline keeps failing after a later group rebuild, because the broken composition was cached\n * under the same feature key (measured in `lightmap.browser.test.ts`). So the renderer first draws\n * with a plain clone, which compiles like its base material, and on the next\n * {@link LightmapRuntime.flush} the clone gets its lightmap and `rebuildMaterial`, which for a built\n * PBR scene rebuilds the whole PBR group (`lib/scene/scene-runtime-mesh-build.js`, `B`) and so\n * composes the lightmap with `uv2`. That costs one PBR group rebuild per frame that new lightmapped\n * renderers arrive in, and one frame without the lightmap.\n */\n\n/**\n * How many distinct atlas placements may be alive before the runtime warns once: each compiles its\n * own pipeline variant per pass.\n *\n * @internal\n */\nexport const LIGHTMAP_PLACEMENT_WARNING_THRESHOLD = 64;\n\n/** One renderer's clone and what it was built from. */\ninterface Entry {\n readonly base: MaterialAsset;\n readonly lightmap: LightmapAsset;\n readonly texture: LiteTexture2D;\n /** The compiled options: a change of any of them needs a new clone. */\n readonly mode: LightmapMode;\n readonly gamma: boolean;\n readonly uv2: boolean;\n /** The atlas placement applied, or `null` for the whole texture; compared by reference. */\n readonly atlas: LightmapPlacement | null;\n /** The placement's WGSL, which tells distinct placements apart, or `null` without one. */\n readonly atlasKey: string | null;\n readonly clone: AssetHandle<MaterialAsset>;\n /** The intensity the next flush applies; it follows the record every frame. */\n level: number;\n /** Whether the lightmap is set on the clone yet. */\n isApplied: boolean;\n /** Whether the clone was given up, so a pending flush skips it. */\n isReleased: boolean;\n}\n\n/**\n * The lightmaps of a renderer.\n *\n * @internal\n */\nexport interface LightmapRuntime {\n /** How many renderers draw with a lightmapped clone. */\n readonly count: number;\n /**\n * The material a renderer draws with: its lightmapped clone, built or refreshed as needed.\n *\n * @param owner - The renderer, as a map key.\n * @param base - The material it declares.\n * @param lightmap - The loaded lightmap.\n * @param settings - Its `lightmap` record.\n * @param atlas - The renderer's placement in the texture, or `null` to sample all of it. The host\n * passes one only for a UV2 lightmap on a mesh with a second UV set; a placement object from the\n * asset keeps its identity, so a new one rebuilds the clone.\n * @returns The clone's Lite material, or `base`'s while the texture is not on the GPU.\n */\n materialFor(\n owner: object,\n base: MaterialAsset,\n lightmap: LightmapAsset,\n settings: MeshRendererLightmap,\n atlas: LightmapPlacement | null,\n ): LiteMaterial;\n /**\n * Drops a renderer's clone, if it has one.\n *\n * @param owner - The renderer.\n */\n release(owner: object): void;\n /** Gives the clones handed out a frame ago their lightmap; the renderer calls it after every `MeshRenderer` synced. */\n flush(): void;\n /** Drops every clone. */\n dispose(): void;\n}\n\n/**\n * Installs Lite's lightmap extension and creates the runtime.\n *\n * @param app - The app whose asset service publishes the clones.\n * @param scene - The registered render scene.\n * @returns The runtime, once the extension is registered.\n *\n * @internal\n */\nexport async function createLightmapRuntime(app: App, scene: LiteScene): Promise<LightmapRuntime> {\n await enableLightmaps();\n const entries = new Map<object, Entry>();\n /** Clones handed out this frame, and those whose meshes have drawn them plain for a frame. */\n let fresh: Entry[] = [];\n let due: Entry[] = [];\n /** Live renderers per distinct placement, for the pipeline-count warning. */\n const placements = new Map<string, number>();\n let hasWarnedPlacements = false;\n\n const release = (owner: object): void => {\n const entry = entries.get(owner);\n if (entry !== undefined) {\n entries.delete(owner);\n entry.isReleased = true;\n if (entry.atlasKey !== null) {\n const left = (placements.get(entry.atlasKey) ?? 1) - 1;\n if (left > 0) {\n placements.set(entry.atlasKey, left);\n } else {\n placements.delete(entry.atlasKey);\n }\n }\n entry.clone.release();\n }\n };\n\n return {\n get count(): number {\n return entries.size;\n },\n materialFor(owner, base, lightmap, settings, atlas): LiteMaterial {\n const handle = lightmap.texture;\n const texture = handle.state === \"loaded\" ? handle.value.lite.texture : null;\n if (texture === null) {\n release(owner);\n return base.lite.material;\n }\n const current = entries.get(owner);\n if (\n current !== undefined &&\n current.base === base &&\n current.lightmap === lightmap &&\n current.texture === texture &&\n current.mode === settings.mode &&\n current.gamma === settings.gamma &&\n current.uv2 === settings.uv2 &&\n current.atlas === atlas\n ) {\n const material = current.clone.value.lite.material;\n syncPbrFactors(base.lite.material, material);\n current.level = settings.level;\n if (current.isApplied) {\n setLightmapLevel(material, settings.level);\n }\n return material;\n }\n release(owner);\n const clone = base.clone(app);\n // The clone replays the declaration, so it takes the edits made to the base since it loaded.\n syncPbrFactors(base.lite.material, clone.value.lite.material);\n const entry: Entry = {\n base,\n lightmap,\n texture,\n mode: settings.mode,\n gamma: settings.gamma,\n uv2: settings.uv2,\n atlas,\n atlasKey: atlas === null ? null : lightmapAtlasWgsl(atlas),\n clone,\n level: settings.level,\n isApplied: false,\n isReleased: false,\n };\n entries.set(owner, entry);\n if (entry.atlasKey !== null) {\n placements.set(entry.atlasKey, (placements.get(entry.atlasKey) ?? 0) + 1);\n if (!hasWarnedPlacements && placements.size > LIGHTMAP_PLACEMENT_WARNING_THRESHOLD) {\n hasWarnedPlacements = true;\n app.log.warn(\n `${String(placements.size)} distinct lightmap atlas placements are in use; each compiles its own ` +\n \"shader pipeline per pass, which costs load time and memory. A shared-UV approach is planned; \" +\n \"until then, bake UV2 that already points into the atlas and leave the entries empty.\",\n );\n }\n }\n fresh.push(entry);\n return clone.value.lite.material;\n },\n release,\n flush(): void {\n for (const entry of due) {\n if (entry.isReleased) {\n continue;\n }\n const material = entry.clone.value.lite.material;\n const options: LiteLightmapOptions = {\n level: entry.level,\n shadowmap: entry.mode === \"shadowmap\",\n gamma: entry.gamma,\n uv2: entry.uv2,\n atlas: entry.atlas,\n };\n if (applyLightmap(scene, material, entry.texture, options)) {\n entry.isApplied = true;\n rebuildMaterialPipelines(scene, material);\n }\n }\n due = fresh;\n fresh = [];\n },\n dispose(): void {\n fresh = [];\n due = [];\n for (const owner of entries.keys()) {\n release(owner);\n }\n },\n };\n}\n"],"mappings":";;;;AAsEA,IAAI,eAAmD;;AAGvD,MAAa,6BAA6B;;;;;;;AAQ1C,SAAS,MAAM,OAAuB;CACpC,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK;AAC5C;;;;;;;;;AAUA,SAAgB,kBAAkB,OAAkC;CAClE,MAAM,EAAE,OAAO,WAAW;CAC1B,OACE,6BAA6B,MAAM,MAAM,CAAC,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,cAChD,MAAM,OAAO,CAAC,EAAE,GAAG,MAAM,OAAO,CAAC,EAAE;AAErD;;;;;;;;;;;;;AAcA,SAAgB,oBAAoB,OAA0C;CAC5E,MAAM,OAAO,kBAAkB,KAAK;CACpC,iCAAiB,IAAI,IAAI;CACzB,IAAI,SAAS,aAAa,IAAI,IAAI;CAClC,IAAI,WAAW,KAAA,GAAW;EACxB,MAAM,SAAS,EAAE,wBAAwB,KAAK;EAC9C,SAAS;GACP,MAAM;GACN,gBAAgB,UAAW,UAAU,WAAW,SAAS;EAC3D;EACA,aAAa,IAAI,MAAM,MAAM;CAC/B;CACA,OAAO;AACT;;;;;;;AAQA,SAAS,cAAc,QAAiC;CACtD,OAAO,OAAO,SAAS;AACzB;;;;;;;;AASA,SAAgB,kBAAiC;CAC/C,OAAO,kBAAkB;AAC3B;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,cACd,OACA,UACA,SACA,SACS;CACT,IAAI,CAAC,cAAc,QAAQ,GACzB,OAAO;CAET,eAAe,UAAU,SAAS;EAChC,OAAO,QAAQ;EACf,YA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M,WAAW,MAAM,MAAM,MAAM,KAAK;IACxC,MAAM,UAA+B;KACnC,OAAO,MAAM;KACb,WAAW,MAAM,SAAS;KAC1B,OAAO,MAAM;KACb,KAAK,MAAM;KACX,OAAO,MAAM;IACf;IACA,IAAI,cAAc,OAAO,UAAU,MAAM,SAAS,OAAO,GAAG;KAC1D,MAAM,YAAY;KAClB,yBAAyB,OAAO,QAAQ;IAC1C;GACF;GACA,MAAM;GACN,QAAQ,CAAC;EACX;EACA,UAAgB;GACd,QAAQ,CAAC;GACT,MAAM,CAAC;GACP,KAAK,MAAM,SAAS,QAAQ,KAAK,GAC/B,QAAQ,KAAK;EAEjB;CACF;AACF"}
1
+ {"version":3,"file":"lightmaps-BUUIIkt9.js","names":[],"sources":["../src/lite/gpu/lightmap.ts","../src/render/gpu/lightmaps.ts"],"sourcesContent":["import { enableMaterialPlugins, enablePbrLightmap, isPbrMaterial, setPbrLightmap } from \"@babylonjs/lite\";\nimport { markMaterialDirty } from \"../material.js\";\nimport type { Material, MaterialPlugin, SceneContext, Texture2D } from \"@babylonjs/lite\";\n\n/**\n * Lightmaps on the GPU (`docs/architecture/07-rendering.md` §2.15). Loaded with\n * `../../render/gpu/lightmaps.ts` as one chunk, only once a static `MeshRenderer` names a loaded\n * lightmap (`CONSTITUTION.md` §2.5). Every Lite claim was read from `@babylonjs/lite@1.34.0`.\n *\n * - **Late enable.** `enablePbrLightmap` (`index.d.ts` 5342) asks to be awaited before\n * `registerScene`, but all it does is register the fragment extension in a process-wide map whose\n * sorted cache it resets (`lib/material/pbr/pbr-flags.js`, `_registerPbrExt`). A material that has\n * no `lightmapTexture` reports no lightmap feature bits (`lightmap-fragment.js`, `detect`), so\n * pipelines built before the call keep their keys, and a material built after it sees the\n * extension. The chunk therefore enables it on load; `rendering.features.lightmaps` only does it\n * earlier.\n * - **Per-material.** `setPbrLightmap` (12635) writes the texture, level, UV set, blend mode and\n * decode onto one material and claims TEXCOORD_1 for it, so a renderer gets its own material\n * before the call. Only `level` is a uniform (`writeLightmapUBO`); the rest are feature bits, so a\n * change of them needs a new material.\n * - **Atlas placement.** The fragment samples `input.uv2` raw (line 24) and ignores the texture's\n * `uScale`/`uOffset`, so Lite has no lightmap UV transform. The PBR vertex template writes\n * `out.uv2 = uv2;` just before the `CUSTOM_VERTEX_MAIN_END` slot\n * (`lib/material/pbr/pbr-template.js` 133, `pbr-template-ext.js` 71), so a plugin there rewrites\n * the varying the lightmap reads: {@link lightmapAtlasPlugin}. The scale and offset are WGSL\n * constants rather than uniforms, because a vertex-visible plugin uniform needs\n * `enablePbrMaterialPluginVertexData` (`index.d.ts` 5349), whose bridge maps\n * `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` to the `NI` slot only\n * (`lib/material/plugin/pbr-plugin-vertex-data.js` versus `plugin-bridge-shared.js`, which also\n * injects it at `AI`), and the light-probe, HDR-output and SSGI plugins count on the double\n * injection. So each distinct placement is its own pipeline variant. The varying exists only when\n * the lightmap samples TEXCOORD_1 and the mesh has a `uvs2` buffer (`pbr-compose.js` 42), so the\n * plugin is only for that case. Lite's own V flip, when the texture asks for one, applies to the\n * transformed coordinate, as it does to the raw one.\n */\n\n/**\n * The options one material's lightmap is drawn with.\n *\n * @internal\n */\nexport interface LiteLightmapOptions {\n /** Intensity multiplier on the sample. */\n readonly level: number;\n /** `true` multiplies the shaded colour (Lite's `useAsShadowmap`); `false` adds to it. */\n readonly shadowmap: boolean;\n /** Decode the sample from sRGB to linear (`pow(x, 2.2)`). */\n readonly gamma: boolean;\n /** Sample with the second UV set (`TEXCOORD_1`) rather than the first. */\n readonly uv2: boolean;\n /**\n * Where the renderer's UV2 square sits in the texture (`uv2 · scale + offset`), or `null` for the\n * whole texture. Only honoured with `uv2` on a mesh that has a second UV set.\n */\n readonly atlas: LiteLightmapAtlas | null;\n}\n\n/**\n * One renderer's placement in a lightmap atlas, as plain numbers.\n *\n * @internal\n */\nexport interface LiteLightmapAtlas {\n /** The atlas-space size of the renderer's UV2 square. */\n readonly scale: { readonly x: number; readonly y: number };\n /** The atlas-space position of the square's `(0, 0)` corner. */\n readonly offset: { readonly x: number; readonly y: number };\n}\n\n/** The atlas plugins made so far, by WGSL; a plugin holds no state, so one per placement does. */\nlet atlasPlugins: Map<string, MaterialPlugin> | null = null;\n\n/** The name every atlas plugin carries; the WGSL tells placements apart in Lite's cache key. */\nexport const LIGHTMAP_ATLAS_PLUGIN_NAME = \"ignifx-lightmap-atlas\";\n\n/**\n * A WGSL float literal, always with a decimal point or an exponent.\n *\n * @param value - A finite number.\n * @returns The literal.\n */\nfunction float(value: number): string {\n const text = String(value);\n return /[.e]/.test(text) ? text : `${text}.0`;\n}\n\n/**\n * The vertex code that moves the lightmap's UV2 varying into the renderer's atlas square.\n *\n * @param atlas - The placement.\n * @returns WGSL for `CUSTOM_VERTEX_MAIN_END`.\n *\n * @internal\n */\nexport function lightmapAtlasWgsl(atlas: LiteLightmapAtlas): string {\n const { scale, offset } = atlas;\n return (\n `out.uv2=out.uv2*vec2<f32>(${float(scale.x)},${float(scale.y)})` +\n `+vec2<f32>(${float(offset.x)},${float(offset.y)});`\n );\n}\n\n/**\n * The plugin that applies one atlas placement, shared by every material with that placement.\n *\n * @remarks\n * Only valid on a material whose lightmap samples TEXCOORD_1 drawn on a mesh with a `uvs2` buffer:\n * anywhere else `out.uv2` does not exist and the pipeline fails to compile.\n *\n * @param atlas - The placement.\n * @returns The plugin; the same object for the same placement.\n *\n * @internal\n */\nexport function lightmapAtlasPlugin(atlas: LiteLightmapAtlas): MaterialPlugin {\n const code = lightmapAtlasWgsl(atlas);\n atlasPlugins ??= new Map();\n let plugin = atlasPlugins.get(code);\n if (plugin === undefined) {\n const vertex = { CUSTOM_VERTEX_MAIN_END: code };\n plugin = {\n name: LIGHTMAP_ATLAS_PLUGIN_NAME,\n getCustomCode: (stage) => (stage === \"vertex\" ? vertex : null),\n };\n atlasPlugins.set(code, plugin);\n }\n return plugin;\n}\n\n/**\n * Whether a plugin is an atlas plugin.\n *\n * @param plugin - Any plugin.\n * @returns `true` for one {@link lightmapAtlasPlugin} made.\n */\nfunction isAtlasPlugin(plugin: MaterialPlugin): boolean {\n return plugin.name === LIGHTMAP_ATLAS_PLUGIN_NAME;\n}\n\n/**\n * Installs Lite's PBR lightmap extension. Idempotent.\n *\n * @returns A promise that settles once the extension is registered.\n *\n * @internal\n */\nexport function enableLightmaps(): Promise<void> {\n return enablePbrLightmap();\n}\n\n/**\n * Gives a PBR material a lightmap.\n *\n * @remarks\n * With an `atlas` placement (and `uv2`), the material also gets the {@link lightmapAtlasPlugin} for\n * it, replacing an earlier one, and the scene's material-plugin bridges are installed first\n * (idempotent; light probes install them after `registerScene` the same way). The caller rebuilds\n * the material's pipelines afterwards.\n *\n * @param scene - The registered scene.\n * @param material - A material no other mesh shares, not yet built with other lightmap options.\n * @param texture - The lightmap.\n * @param options - How it is drawn.\n * @returns `false` when the material is not PBR, so nothing was set.\n *\n * @internal\n */\nexport function applyLightmap(\n scene: SceneContext,\n material: Material,\n texture: Texture2D,\n options: LiteLightmapOptions,\n): boolean {\n if (!isPbrMaterial(material)) {\n return false;\n }\n setPbrLightmap(material, texture, {\n level: options.level,\n coordIndex: options.uv2 ? 1 : 0,\n useAsShadowmap: options.shadowmap,\n gamma: options.gamma,\n });\n const current = material.plugins ?? [];\n const kept = current.some(isAtlasPlugin) ? current.filter((plugin) => !isAtlasPlugin(plugin)) : current;\n if (options.atlas !== null && options.uv2) {\n enableMaterialPlugins(scene);\n material.plugins = [...kept, lightmapAtlasPlugin(options.atlas)];\n } else if (kept !== current) {\n material.plugins = kept;\n }\n return true;\n}\n\n/**\n * Changes a lightmapped material's intensity; only its uniform block is rewritten.\n *\n * @param material - A material {@link applyLightmap} set up.\n * @param level - The new multiplier.\n *\n * @internal\n */\nexport function setLightmapLevel(material: Material, level: number): void {\n if (isPbrMaterial(material) && material.lightmapLevel !== level) {\n material.lightmapLevel = level;\n markMaterialDirty(material);\n }\n}\n","import { applyLightmap, enableLightmaps, lightmapAtlasWgsl, setLightmapLevel } from \"../../lite/gpu/lightmap.js\";\nimport { rebuildMaterialPipelines, syncPbrFactors } from \"../../lite/material.js\";\nimport type { App } from \"../../app/types.js\";\nimport type { AssetHandle } from \"../../assets/types.js\";\nimport type { LiteLightmapOptions } from \"../../lite/gpu/lightmap.js\";\nimport type { LiteTexture2D } from \"../../lite/gpu/texture.js\";\nimport type { LiteMaterial } from \"../../lite/material.js\";\nimport type { LiteScene } from \"../../lite/scene.js\";\nimport type { LightmapAsset, LightmapPlacement } from \"../lightmap-asset.js\";\nimport type { MaterialAsset } from \"../material-asset.js\";\nimport type { LightmapMode, MeshRendererLightmap } from \"../mesh-renderer.js\";\n\n/**\n * The render layer's half of lightmaps (`docs/architecture/07-rendering.md` §2.15): one material\n * clone per lightmapped renderer. Loaded with `../../lite/gpu/lightmap.ts` as one chunk, only once\n * a static `MeshRenderer` names a loaded lightmap.\n *\n * `MaterialAsset`s are shared, and a lightmap is per renderer, so each renderer draws with\n * `MaterialAsset.clone` of its material carrying the lightmap. The clone is rebuilt when the\n * material, the lightmap, its texture, a compiled option (`mode`, `gamma`, `uv2`) or the atlas\n * placement changes; a `level` change only rewrites the clone's uniform block. A placement other\n * than the whole texture is a vertex plugin on the clone (`../../lite/gpu/lightmap.ts`), one\n * pipeline variant per distinct placement. Nothing here allocates on a frame where no clone changes. Edits made to the shared material through\n * its factor setters (`setBaseColor`, `setMetallicRoughness`, `setAlpha`) are copied onto the clone\n * the next frame it is asked for (a comparison of seven numbers per frame); a reloaded material is a\n * new asset, so it gets a new clone.\n *\n * ## Two frames, because of how Lite plumbs `uv2`\n *\n * Lite decides whether its PBR group carries the `uv2` attribute and varying when it builds the\n * group, from the meshes' materials at that time (`lib/material/pbr/pbr-renderable.js`, `hasAnyUv2`).\n * A `mesh.material` swap reuses the group's single-mesh rebuild (`lib/scene/scene-material-swap.js`),\n * whose composer has no `uv2` then, and a lightmap that samples `input.uv2` fails to compile; the\n * pipeline keeps failing after a later group rebuild, because the broken composition was cached\n * under the same feature key (measured in `lightmap.browser.test.ts`). So the renderer first draws\n * with a plain clone, which compiles like its base material, and on the next\n * {@link LightmapRuntime.flush} the clone gets its lightmap and `rebuildMaterial`, which for a built\n * PBR scene rebuilds the whole PBR group (`lib/scene/scene-runtime-mesh-build.js`, `B`) and so\n * composes the lightmap with `uv2`. That costs one PBR group rebuild per frame that new lightmapped\n * renderers arrive in, and one frame without the lightmap.\n */\n\n/**\n * How many distinct atlas placements may be alive before the runtime warns once: each compiles its\n * own pipeline variant per pass.\n *\n * @internal\n */\nexport const LIGHTMAP_PLACEMENT_WARNING_THRESHOLD = 64;\n\n/** One renderer's clone and what it was built from. */\ninterface Entry {\n readonly base: MaterialAsset;\n readonly lightmap: LightmapAsset;\n readonly texture: LiteTexture2D;\n /** The compiled options: a change of any of them needs a new clone. */\n readonly mode: LightmapMode;\n readonly gamma: boolean;\n readonly uv2: boolean;\n /** The atlas placement applied, or `null` for the whole texture; compared by reference. */\n readonly atlas: LightmapPlacement | null;\n /** The placement's WGSL, which tells distinct placements apart, or `null` without one. */\n readonly atlasKey: string | null;\n readonly clone: AssetHandle<MaterialAsset>;\n /** The intensity the next flush applies; it follows the record every frame. */\n level: number;\n /** Whether the lightmap is set on the clone yet. */\n isApplied: boolean;\n /** Whether the clone was given up, so a pending flush skips it. */\n isReleased: boolean;\n}\n\n/**\n * The lightmaps of a renderer.\n *\n * @internal\n */\nexport interface LightmapRuntime {\n /** How many renderers draw with a lightmapped clone. */\n readonly count: number;\n /**\n * The material a renderer draws with: its lightmapped clone, built or refreshed as needed.\n *\n * @param owner - The renderer, as a map key.\n * @param base - The material it declares.\n * @param lightmap - The loaded lightmap.\n * @param settings - Its `lightmap` record.\n * @param atlas - The renderer's placement in the texture, or `null` to sample all of it. The host\n * passes one only for a UV2 lightmap on a mesh with a second UV set; a placement object from the\n * asset keeps its identity, so a new one rebuilds the clone.\n * @returns The clone's Lite material, or `base`'s while the texture is not on the GPU.\n */\n materialFor(\n owner: object,\n base: MaterialAsset,\n lightmap: LightmapAsset,\n settings: MeshRendererLightmap,\n atlas: LightmapPlacement | null,\n ): LiteMaterial;\n /**\n * Drops a renderer's clone, if it has one.\n *\n * @param owner - The renderer.\n */\n release(owner: object): void;\n /** Gives the clones handed out a frame ago their lightmap; the renderer calls it after every `MeshRenderer` synced. */\n flush(): void;\n /** Drops every clone. */\n dispose(): void;\n}\n\n/**\n * Installs Lite's lightmap extension and creates the runtime.\n *\n * @param app - The app whose asset service publishes the clones.\n * @param scene - The registered render scene.\n * @returns The runtime, once the extension is registered.\n *\n * @internal\n */\nexport async function createLightmapRuntime(app: App, scene: LiteScene): Promise<LightmapRuntime> {\n await enableLightmaps();\n const entries = new Map<object, Entry>();\n /** Clones handed out this frame, and those whose meshes have drawn them plain for a frame. */\n let fresh: Entry[] = [];\n let due: Entry[] = [];\n /** Live renderers per distinct placement, for the pipeline-count warning. */\n const placements = new Map<string, number>();\n let hasWarnedPlacements = false;\n\n const release = (owner: object): void => {\n const entry = entries.get(owner);\n if (entry !== undefined) {\n entries.delete(owner);\n entry.isReleased = true;\n if (entry.atlasKey !== null) {\n const left = (placements.get(entry.atlasKey) ?? 1) - 1;\n if (left > 0) {\n placements.set(entry.atlasKey, left);\n } else {\n placements.delete(entry.atlasKey);\n }\n }\n entry.clone.release();\n }\n };\n\n return {\n get count(): number {\n return entries.size;\n },\n materialFor(owner, base, lightmap, settings, atlas): LiteMaterial {\n const handle = lightmap.texture;\n const texture = handle.state === \"loaded\" ? handle.value.lite.texture : null;\n if (texture === null) {\n release(owner);\n return base.lite.material;\n }\n const current = entries.get(owner);\n if (\n current !== undefined &&\n current.base === base &&\n current.lightmap === lightmap &&\n current.texture === texture &&\n current.mode === settings.mode &&\n current.gamma === settings.gamma &&\n current.uv2 === settings.uv2 &&\n current.atlas === atlas\n ) {\n const material = current.clone.value.lite.material;\n syncPbrFactors(base.lite.material, material);\n current.level = settings.level;\n if (current.isApplied) {\n setLightmapLevel(material, settings.level);\n }\n return material;\n }\n release(owner);\n const clone = base.clone(app);\n // The clone replays the declaration, so it takes the edits made to the base since it loaded.\n syncPbrFactors(base.lite.material, clone.value.lite.material);\n const entry: Entry = {\n base,\n lightmap,\n texture,\n mode: settings.mode,\n gamma: settings.gamma,\n uv2: settings.uv2,\n atlas,\n atlasKey: atlas === null ? null : lightmapAtlasWgsl(atlas),\n clone,\n level: settings.level,\n isApplied: false,\n isReleased: false,\n };\n entries.set(owner, entry);\n if (entry.atlasKey !== null) {\n placements.set(entry.atlasKey, (placements.get(entry.atlasKey) ?? 0) + 1);\n if (!hasWarnedPlacements && placements.size > LIGHTMAP_PLACEMENT_WARNING_THRESHOLD) {\n hasWarnedPlacements = true;\n app.log.warn(\n `${String(placements.size)} distinct lightmap atlas placements are in use; each compiles its own ` +\n \"shader pipeline per pass, which costs load time and memory. A shared-UV approach is planned; \" +\n \"until then, bake UV2 that already points into the atlas and leave the entries empty.\",\n );\n }\n }\n fresh.push(entry);\n return clone.value.lite.material;\n },\n release,\n flush(): void {\n for (const entry of due) {\n if (entry.isReleased) {\n continue;\n }\n const material = entry.clone.value.lite.material;\n const options: LiteLightmapOptions = {\n level: entry.level,\n shadowmap: entry.mode === \"shadowmap\",\n gamma: entry.gamma,\n uv2: entry.uv2,\n atlas: entry.atlas,\n };\n if (applyLightmap(scene, material, entry.texture, options)) {\n entry.isApplied = true;\n rebuildMaterialPipelines(scene, material);\n }\n }\n due = fresh;\n fresh = [];\n },\n dispose(): void {\n fresh = [];\n due = [];\n for (const owner of entries.keys()) {\n release(owner);\n }\n },\n };\n}\n"],"mappings":";;;;AAsEA,IAAI,eAAmD;;AAGvD,MAAa,6BAA6B;;;;;;;AAQ1C,SAAS,MAAM,OAAuB;CACpC,MAAM,OAAO,OAAO,KAAK;CACzB,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK;AAC5C;;;;;;;;;AAUA,SAAgB,kBAAkB,OAAkC;CAClE,MAAM,EAAE,OAAO,WAAW;C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esContent":["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 * Makes one PBR material's base colour, metallic, roughness and alpha factors (what\n * `MaterialAsset`'s setters write) equal another's, such as a renderer's lightmapped copy of a\n * shared material. Writes, and marks the copy dirty, only when something differs.\n *\n * @param from - The material to read.\n * @param to - The material to change.\n * @returns `true` when `to` changed.\n *\n * @internal\n */\nexport function syncPbrFactors(from: PbrMaterialProps, to: PbrMaterialProps): boolean {\n const color = from.baseColorFactor ?? [1, 1, 1, 1];\n const current = to.baseColorFactor ?? [1, 1, 1, 1];\n const metallic = from.metallicFactor ?? 1;\n const roughness = from.roughnessFactor ?? 1;\n const alpha = from.alpha ?? 1;\n if (\n color[0] === current[0] &&\n color[1] === current[1] &&\n color[2] === current[2] &&\n color[3] === current[3] &&\n metallic === (to.metallicFactor ?? 1) &&\n roughness === (to.roughnessFactor ?? 1) &&\n alpha === (to.alpha ?? 1)\n ) {\n return false;\n }\n setPbrBaseColor(to, color[0], color[1], color[2], color[3]);\n to.metallicFactor = metallic;\n to.roughnessFactor = roughness;\n to.alpha = alpha;\n markMaterialDirty(to);\n return true;\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"],"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,kBAAkB,MAAM;CAEhC,IAAI,MAAM,qBAAqB,KAAA,GAC7B,MAAM,mBAAmB,MAAM;CAEjC,IAAI,MAAM,sBAAsB,KAAA,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rC,WAAW,GAAG,SAAS,IAEvB,OAAO;CAET,gBAAgB,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE;CAC1D,GAAG,iBAAiB;CACpB,GAAG,kBAAkB;CACrB,GAAG,QAAQ;CACX,kBAAkB,EAAE;CACpB,OAAO;AACT;;;;;;;;;AAUA,SAAgB,iBAAiB,UAAoD,OAAqB;CACxG,SAAS,QAAQ;CACjB,kBAAkB,QAAQ;AAC5B;;;;;;;;;;;;AAaA,SAAgB,kBAAkB,UAA0B;CAC1D,qBAAqB,QAAQ;AAC/B;;;;;;;;;;;;;;AAeA,SAAgB,yBAAyB,OAAqB,UAA0B;CAGtF,gBAAqB,OAAO,QAAQ;AACtC;;;;;;;AA+CA,SAAS,YAAY,QAAkC,QAAiD;CACtG,OAAO,KAAK,OAAO;CACnB,OAAO,KAAK,OAAO;CACnB,OAAO,KAAK,OAAO;AACrB"}
1
+ {"version":3,"file":"material-myMbl9mW.js","names":[],"sources":["../src/lite/material.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/architecture/07-rendering.md` §2.8, \"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 * Makes one PBR material's base colour, metallic, roughness and alpha factors (what\n * `MaterialAsset`'s setters write) equal another's, such as a renderer's lightmapped copy of a\n * shared material. Writes, and marks the copy dirty, only when something differs.\n *\n * @param from - The material to read.\n * @param to - The material to change.\n * @returns `true` when `to` changed.\n *\n * @internal\n */\nexport function syncPbrFactors(from: PbrMaterialProps, to: PbrMaterialProps): boolean {\n const color = from.baseColorFactor ?? [1, 1, 1, 1];\n const current = to.baseColorFactor ?? [1, 1, 1, 1];\n const metallic = from.metallicFactor ?? 1;\n const roughness = from.roughnessFactor ?? 1;\n const alpha = from.alpha ?? 1;\n if (\n color[0] === current[0] &&\n color[1] === current[1] &&\n color[2] === current[2] &&\n color[3] === current[3] &&\n metallic === (to.metallicFactor ?? 1) &&\n roughness === (to.roughnessFactor ?? 1) &&\n alpha === (to.alpha ?? 1)\n ) {\n return false;\n }\n setPbrBaseColor(to, color[0], color[1], color[2], color[3]);\n to.metallicFactor = metallic;\n to.roughnessFactor = roughness;\n to.alpha = alpha;\n markMaterialDirty(to);\n return true;\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"],"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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ever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
2
- import { u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
2
+ import { u as SHADER_UNIFORM_TYPES } from "./shader-declaration-BGprFBLq.js";
3
3
  //#region src/render/material-plugin.ts
4
4
  /**
5
5
  * The raw Babylon Lite material-plugin points, as a `@beta` escape hatch
6
- * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.2, ADR-0024).
6
+ * (ADR-0024).
7
7
  *
8
8
  * `@beta` because the meaning of each point is whatever the surrounding Lite template declares at
9
9
  * that line; ignifx's stable contract is the three hooks of `./surface-shader.ts`. Four rules read
@@ -51,7 +51,7 @@ const MATERIAL_PLUGIN_DEFAULT_PRIORITY = 500;
51
51
  * How many `texture`/`sampler` pairs one material's plugins may declare together.
52
52
  *
53
53
  * @remarks
54
- * Measured on a device on 2026-09-08 (spike S0.2): a fully textured PBR material — base colour,
54
+ * Measured on a device on 2026-09-08: a fully textured PBR material — base colour,
55
55
  * normal, ORM, emissive — with image-based lighting and one PCF shadow light already binds seven
56
56
  * textures and seven samplers of the sixteen per stage that every WebGPU implementation guarantees,
57
57
  * SwiftShader included, and Lite requests no higher `requiredLimits`. Nine is what is left, and it
@@ -281,4 +281,4 @@ function assertUniformType(plugin, binding, type) {
281
281
  //#endregion
282
282
  export { defineMaterialPlugin as a, MATERIAL_PLUGIN_SAMPLER_BUDGET as i, MATERIAL_PLUGIN_DEFAULT_PRIORITY as n, isLiteMaterialPluginPoint as o, MATERIAL_PLUGIN_RESERVED_NAMES as r, uniformComponentCount as s, LITE_MATERIAL_PLUGIN_POINTS as t };
283
283
 
284
- //# sourceMappingURL=material-plugin-DapJNj04.js.map
284
+ //# sourceMappingURL=material-plugin-BBxIy6eo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"material-plugin-BBxIy6eo.js","names":[],"sources":["../src/render/material-plugin.ts"],"sourcesContent":["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 * (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: 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":";;;;;;;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+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"}
@@ -10,8 +10,7 @@ import { addTask, addToScene, buildFrameGraphTask, createHemisphericLight, creat
10
10
  *
11
11
  * `createUtilityLayer` (`index.d.ts` 4109) builds its scene with Lite's default render task, and
12
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):
13
+ * context (`lib/scene/swapchain-overlay.js` 11). Two things go wrong in an ignifx app:
15
14
  *
16
15
  * - When `@ignifx/ui`'s text renderer or `@ignifx/2d`'s sprite renderer was registered after the
17
16
  * render scene, it is the last context. It has no frame graph, so Lite configures nothing and the
@@ -236,4 +235,4 @@ function createOverlayTask(engine, scene) {
236
235
  //#endregion
237
236
  export { openOverlayScene };
238
237
 
239
- //# sourceMappingURL=overlay-CjVgsfrm.js.map
238
+ //# sourceMappingURL=overlay-DokHzP6_.js.map