@ignifx/core 0.16.0 → 0.18.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 (58) hide show
  1. package/dist/{environment-DPi0_0SP.js → environment-DZ6WUHbm.js} +2 -2
  2. package/dist/{environment-DPi0_0SP.js.map → environment-DZ6WUHbm.js.map} +1 -1
  3. package/dist/{hdr-output-BrUvpAsE.js → hdr-output-Dbv0lhFl.js} +4 -3
  4. package/dist/{hdr-output-BrUvpAsE.js.map → hdr-output-Dbv0lhFl.js.map} +1 -1
  5. package/dist/{ignifx-error-oYdVnT1S.js → ignifx-error-B8ByiSfJ.js} +16 -1
  6. package/dist/ignifx-error-B8ByiSfJ.js.map +1 -0
  7. package/dist/index.d.ts +128 -14654
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1501 -4037
  10. package/dist/index.js.map +1 -1
  11. package/dist/{instanced-mesh-instance-NnODkvqK.js → instanced-mesh-instance-BMhREEfx.js} +3 -2
  12. package/dist/{instanced-mesh-instance-NnODkvqK.js.map → instanced-mesh-instance-BMhREEfx.js.map} +1 -1
  13. package/dist/light-probe-asset-B60_X-yN.js +331 -0
  14. package/dist/light-probe-asset-B60_X-yN.js.map +1 -0
  15. package/dist/light-probes-DkYN89Qw.js +284 -0
  16. package/dist/light-probes-DkYN89Qw.js.map +1 -0
  17. package/dist/{material-plugin-BUlqLsap.js → material-plugin-CiAmriQ_.js} +2 -2
  18. package/dist/{material-plugin-BUlqLsap.js.map → material-plugin-CiAmriQ_.js.map} +1 -1
  19. package/dist/node-DznSvwap.js +301 -0
  20. package/dist/node-DznSvwap.js.map +1 -0
  21. package/dist/{post-effect-BHl7U56q.js → post-effect-CQnlX1RH.js} +3 -30
  22. package/dist/post-effect-CQnlX1RH.js.map +1 -0
  23. package/dist/{post-effect-compiler-CRek8VxQ.js → post-effect-compiler-C_7HTHZy.js} +3 -3
  24. package/dist/{post-effect-compiler-CRek8VxQ.js.map → post-effect-compiler-C_7HTHZy.js.map} +1 -1
  25. package/dist/prefab-overrides-BLQn5yHS.d.ts +15149 -0
  26. package/dist/prefab-overrides-BLQn5yHS.d.ts.map +1 -0
  27. package/dist/prefab-overrides-DT-wHHAJ.js +2396 -0
  28. package/dist/prefab-overrides-DT-wHHAJ.js.map +1 -0
  29. package/dist/prefab.d.ts +2 -0
  30. package/dist/prefab.js +2 -0
  31. package/dist/reflection-probe-DlVsl3zJ.js +1883 -0
  32. package/dist/reflection-probe-DlVsl3zJ.js.map +1 -0
  33. package/dist/reflection-probes-B8S9WnVX.js +551 -0
  34. package/dist/reflection-probes-B8S9WnVX.js.map +1 -0
  35. package/dist/{render-path-Be7WgN7r.js → render-path-D11i_7X8.js} +3 -2
  36. package/dist/{render-path-Be7WgN7r.js.map → render-path-D11i_7X8.js.map} +1 -1
  37. package/dist/{render-texture-C_TnaSz2.js → render-texture-UqRHRLQy.js} +15 -2
  38. package/dist/{render-texture-C_TnaSz2.js.map → render-texture-UqRHRLQy.js.map} +1 -1
  39. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  40. package/dist/{scene-color-passes-DlNr-qyZ.js → scene-color-passes-B93qTOka.js} +35 -12
  41. package/dist/scene-color-passes-B93qTOka.js.map +1 -0
  42. package/dist/{shader-material-B6p66wB8.js → shader-material-C2_UCYdO.js} +6 -17
  43. package/dist/{shader-material-B6p66wB8.js.map → shader-material-C2_UCYdO.js.map} +1 -1
  44. package/dist/{shader-material-C0TAUr4t.js → shader-material-CaAkv5nT.js} +2 -2
  45. package/dist/{shader-material-C0TAUr4t.js.map → shader-material-CaAkv5nT.js.map} +1 -1
  46. package/dist/{shader-pragma-BKCoZTTA.js → shader-pragma-DmZpxGUo.js} +2 -2
  47. package/dist/{shader-pragma-BKCoZTTA.js.map → shader-pragma-DmZpxGUo.js.map} +1 -1
  48. package/dist/{surface-shader-BaK0kvBB.js → surface-shader-BeDRofOV.js} +4 -4
  49. package/dist/{surface-shader-BaK0kvBB.js.map → surface-shader-BeDRofOV.js.map} +1 -1
  50. package/dist/{vec3-D-0Y2mzE.js → vec3-Cc19wl4r.js} +3 -300
  51. package/dist/vec3-Cc19wl4r.js.map +1 -0
  52. package/package.json +8 -4
  53. package/dist/ignifx-error-oYdVnT1S.js.map +0 -1
  54. package/dist/json-CzZZ6K4x.js +0 -24
  55. package/dist/json-CzZZ6K4x.js.map +0 -1
  56. package/dist/post-effect-BHl7U56q.js.map +0 -1
  57. package/dist/scene-color-passes-DlNr-qyZ.js.map +0 -1
  58. package/dist/vec3-D-0Y2mzE.js.map +0 -1
@@ -0,0 +1,284 @@
1
+ import { i as readSceneEnvironment } from "./environment-DZ6WUHbm.js";
2
+ import { a as markMaterialDirty, o as rebuildMaterialPipelines } from "./material-CGk5mAah.js";
3
+ import { s as packLightProbeTexels } from "./light-probe-asset-B60_X-yN.js";
4
+ import { n as deviceOf } from "./render-texture-UqRHRLQy.js";
5
+ import { createRenderTexture2D, enableMaterialPlugins, getPbrUnlit, isPbrMaterial, isPbrSkybox } from "@babylonjs/lite";
6
+ //#region src/lite/gpu/light-probes.ts
7
+ /**
8
+ * Light probes on the GPU (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B2). Its own chunk,
9
+ * loaded only once a world has a `LightProbeVolume` (`CONSTITUTION.md` §2.5). Every Lite claim was
10
+ * read from `@babylonjs/lite@1.34.0`.
11
+ *
12
+ * - **Texture.** The grid's coefficients, packed by `packLightProbeTexels`, in an `rgba16float`
13
+ * texture read with `textureLoad` (plugins bind `texture_2d<f32>` only, `index.d.ts` 10607, so no
14
+ * 3D texture).
15
+ * - **Plugin.** Lite declares `environmentIrradiance` with `let` inside the IBL code
16
+ * (`lib/material/pbr/fragments/ibl-fragment.js`), so a plugin cannot replace it. Instead the plugin
17
+ * adds `(probes − environment) · surfaceAlbedo · occlusion` to `color`, recomputing the
18
+ * environment's harmonics from the scene uniforms the IBL code reads. Its point,
19
+ * `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION`, is injected twice (`AI` before the IBL code, `NI`
20
+ * after it; `lib/material/plugin/plugin-bridge-shared.js` line 13), so a private counter applies it
21
+ * on the second pass only. Its priority runs it before the HDR linear-output plugin saves `color`.
22
+ * - **Grid constants** are written into the WGSL, so a different grid is a different plugin and a
23
+ * material rebuild: grids change rarely. `intensity` is a uniform on the host material's block,
24
+ * so changing it rebuilds nothing.
25
+ */
26
+ /**
27
+ * The name the plugin carries; part of Lite's pipeline cache key.
28
+ *
29
+ * @internal
30
+ */
31
+ const LIGHT_PROBE_PLUGIN_NAME = "ignifx-light-probes";
32
+ /** The uniform field the plugin adds to each host material's block. */
33
+ const INTENSITY_FIELD = "ignifxLpIntensity";
34
+ /**
35
+ * A WGSL float literal.
36
+ *
37
+ * @param value - A finite number.
38
+ * @returns The literal.
39
+ */
40
+ function f(value) {
41
+ return Number.isInteger(value) ? `${String(value)}.0` : String(value);
42
+ }
43
+ /**
44
+ * The plugin's WGSL.
45
+ *
46
+ * @param shape - The grid.
47
+ * @returns The definitions and the composition code.
48
+ *
49
+ * @internal
50
+ */
51
+ function lightProbePluginWgsl(shape) {
52
+ const [nx, ny, nz] = shape.counts;
53
+ const origin = `vec3<f32>(${shape.origin.map(f).join(",")})`;
54
+ const inverse = `vec3<f32>(${shape.cellSize.map((size) => f(1 / size)).join(",")})`;
55
+ const maxCell = `vec3<f32>(${f(nx - 1)},${f(ny - 1)},${f(nz - 1)})`;
56
+ return {
57
+ definitions: `var<private> igxLpPass:i32;fn igxLpTexel(c:vec3<i32>,k:i32)->vec3<f32>{return textureLoad(ignifxLp,vec2<i32>(c.x+${String(nx)}*k,c.y+${String(ny)}*c.z),0).rgb;}fn igxLpAt(c:vec3<i32>,n:vec3<f32>)->vec3<f32>{return igxLpTexel(c,0)+igxLpTexel(c,1)*n.y+igxLpTexel(c,2)*n.z+igxLpTexel(c,3)*n.x;}fn igxLpSample(p:vec3<f32>,n:vec3<f32>)->vec3<f32>{let m=${maxCell};let g=clamp((p-${origin})*${inverse},vec3<f32>(0.0),m);let lo=min(floor(g),max(m-1.0,vec3<f32>(0.0)));let t=g-lo;let hi=min(lo+1.0,m);var r=vec3<f32>(0.0);for(var i=0;i<8;i++){let s=vec3<i32>(i&1,(i>>1u)&1,(i>>2u)&1)==vec3<i32>(1);let w=select(1.0-t,t,s);r+=igxLpAt(vec3<i32>(select(lo,hi,s)),n)*(w.x*w.y*w.z);}return max(r,vec3<f32>(0.0));}`,
58
+ composition: `igxLpPass=igxLpPass+1;if(igxLpPass==2){let igxC=cos(scene.envRotationY);let igxS=sin(scene.envRotationY);let igxN=vec3<f32>(N.x*igxC+N.z*igxS,N.y,-N.x*igxS+N.z*igxC);let igxEnv=(scene.vSphericalL00.rgb+scene.vSphericalL1_1.rgb*igxN.y+scene.vSphericalL10.rgb*igxN.z+scene.vSphericalL11.rgb*igxN.x+scene.vSphericalL2_2.rgb*(igxN.y*igxN.x)+scene.vSphericalL2_1.rgb*(igxN.y*igxN.z)+scene.vSphericalL20.rgb*(3.0*igxN.z*igxN.z-1.0)+scene.vSphericalL21.rgb*(igxN.z*igxN.x)+scene.vSphericalL22.rgb*(igxN.x*igxN.x-igxN.y*igxN.y))*material.environmentIntensity;color+=(igxLpSample(input.worldPos,N)*material.${INTENSITY_FIELD}-igxEnv)*surfaceAlbedo*occlusion;}`
59
+ };
60
+ }
61
+ /**
62
+ * Installs Lite's material-plugin bridges, which the plugin needs, unless the project already did.
63
+ *
64
+ * @remarks
65
+ * Idempotent (`lib/material/plugin/enable-material-plugins.js` replaces its one scene hook). The
66
+ * HDR path calls it before `registerScene` (`./hdr-output.ts`); here it runs after, which works for
67
+ * PBR because the bridge assigns a material's plugin identity during the rebuild that attaching
68
+ * the plugin queues. `light-probe.browser.test.ts` covers that case with HDR off.
69
+ *
70
+ * @param scene - The registered scene.
71
+ *
72
+ * @internal
73
+ */
74
+ function enableLightProbePlugins(scene) {
75
+ enableMaterialPlugins(scene);
76
+ }
77
+ /**
78
+ * Uploads packed probe texels into a texture.
79
+ *
80
+ * @param engine - The engine.
81
+ * @param width - The texel width.
82
+ * @param height - The texel height.
83
+ * @param texels - Four half floats per texel.
84
+ * @returns The texture, or `null` when the engine has no device.
85
+ *
86
+ * @internal
87
+ */
88
+ function createLightProbeTexture(engine, width, height, texels) {
89
+ const device = deviceOf(engine);
90
+ if (device === null) return null;
91
+ const texture = createRenderTexture2D(engine, width, height, {
92
+ format: "rgba16float",
93
+ minFilter: "nearest",
94
+ magFilter: "nearest"
95
+ });
96
+ device.queue.writeTexture({ texture: texture.texture }, texels, { bytesPerRow: width * 8 }, {
97
+ width,
98
+ height
99
+ });
100
+ return texture;
101
+ }
102
+ /**
103
+ * Builds the plugin for one grid and its texture.
104
+ *
105
+ * @param shape - The grid.
106
+ * @param texture - The packed texture.
107
+ * @param uniforms - The live settings; the plugin reads them on every uniform write.
108
+ * @returns The plugin, shared by every lit PBR material.
109
+ *
110
+ * @internal
111
+ */
112
+ function createLightProbePlugin(shape, texture, uniforms) {
113
+ const wgsl = lightProbePluginWgsl(shape);
114
+ const fragment = {
115
+ CUSTOM_FRAGMENT_DEFINITIONS: wgsl.definitions,
116
+ CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: wgsl.composition
117
+ };
118
+ return {
119
+ name: LIGHT_PROBE_PLUGIN_NAME,
120
+ priority: -100,
121
+ getSamplers: () => [{
122
+ texture: "ignifxLp",
123
+ sampler: "ignifxLpSampler"
124
+ }],
125
+ getUniforms: () => ({ ubo: [{
126
+ name: INTENSITY_FIELD,
127
+ type: "f32"
128
+ }] }),
129
+ writeUbo: (data, offsets) => {
130
+ const byteOffset = offsets.get(INTENSITY_FIELD);
131
+ if (byteOffset !== void 0) data[byteOffset / 4] = uniforms.intensity;
132
+ },
133
+ bindTextures: (out) => {
134
+ out.push({ texture });
135
+ },
136
+ getCustomCode: (stage) => stage === "fragment" ? fragment : null
137
+ };
138
+ }
139
+ /**
140
+ * Re-uploads the plugin's uniforms on every material that carries it, after
141
+ * {@link LightProbeUniforms} changed.
142
+ *
143
+ * @param scene - The scene.
144
+ * @param plugin - The plugin.
145
+ *
146
+ * @internal
147
+ */
148
+ function refreshLightProbeUniforms(scene, plugin) {
149
+ const meshes = scene.meshes;
150
+ for (let index = 0; index < meshes.length; index += 1) {
151
+ const material = meshes[index]?.material;
152
+ if (material === void 0 || material === null || !isPbrMaterial(material)) continue;
153
+ if (material.plugins?.includes(plugin) === true) markMaterialDirty(material);
154
+ }
155
+ }
156
+ /**
157
+ * Gives every lit PBR material `next` in place of `previous`, rebuilding the ones that changed.
158
+ *
159
+ * @param scene - The registered scene.
160
+ * @param previous - The plugin to take off, or `null`.
161
+ * @param next - The plugin to put on, or `null` to only take `previous` off.
162
+ *
163
+ * @internal
164
+ */
165
+ function swapLightProbePlugin(scene, previous, next) {
166
+ const meshes = scene.meshes;
167
+ for (let index = 0; index < meshes.length; index += 1) {
168
+ const material = meshes[index]?.material;
169
+ if (material === void 0 || material === null || !isPbrMaterial(material)) continue;
170
+ const current = material.plugins ?? [];
171
+ const lit = getPbrUnlit(material) === void 0 && !isPbrSkybox(material);
172
+ const hasPrevious = previous !== null && current.includes(previous);
173
+ const wantsNext = next !== null && lit;
174
+ if (!hasPrevious && (!wantsNext || current.includes(next))) continue;
175
+ const kept = hasPrevious ? current.filter((plugin) => plugin !== previous) : current;
176
+ material.plugins = wantsNext && !kept.includes(next) ? [...kept, next] : kept;
177
+ rebuildMaterialPipelines(scene, material);
178
+ }
179
+ }
180
+ //#endregion
181
+ //#region src/render/gpu/light-probes.ts
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
185
+ * `../../lite/gpu/light-probes.ts` as one chunk, only once a world has a `LightProbeVolume`.
186
+ */
187
+ /** Frames a replaced texture outlives its plugin, so no in-flight bind group still names it. */
188
+ const RETIRE_FRAMES = 8;
189
+ /**
190
+ * Creates the runtime.
191
+ *
192
+ * @param engine - The engine.
193
+ * @param scene - The registered render scene.
194
+ * @returns The runtime.
195
+ *
196
+ * @internal
197
+ */
198
+ function createLightProbeRuntime(engine, scene) {
199
+ enableLightProbePlugins(scene);
200
+ let applied = null;
201
+ const retiring = [];
202
+ const apply = (asset, intensity) => {
203
+ const { data } = asset;
204
+ const packed = packLightProbeTexels(data);
205
+ const texture = createLightProbeTexture(engine, packed.width, packed.height, packed.texels);
206
+ if (texture === null) return null;
207
+ const uniforms = { intensity };
208
+ return {
209
+ asset,
210
+ uniforms,
211
+ plugin: createLightProbePlugin({
212
+ origin: [
213
+ data.origin.x,
214
+ data.origin.y,
215
+ data.origin.z
216
+ ],
217
+ cellSize: [
218
+ data.cellSize.x,
219
+ data.cellSize.y,
220
+ data.cellSize.z
221
+ ],
222
+ counts: [
223
+ data.counts.x,
224
+ data.counts.y,
225
+ data.counts.z
226
+ ]
227
+ }, texture, uniforms),
228
+ destroy: () => texture.texture.destroy()
229
+ };
230
+ };
231
+ const replace = (next) => {
232
+ swapLightProbePlugin(scene, applied?.plugin ?? null, next?.plugin ?? null);
233
+ if (applied !== null) retiring.push({
234
+ destroy: applied.destroy,
235
+ frames: RETIRE_FRAMES
236
+ });
237
+ applied = next;
238
+ };
239
+ return {
240
+ get isLighting() {
241
+ return applied !== null;
242
+ },
243
+ update(volumes) {
244
+ for (let index = retiring.length - 1; index >= 0; index -= 1) {
245
+ const entry = retiring[index];
246
+ if (entry !== void 0 && --entry.frames <= 0) {
247
+ entry.destroy();
248
+ retiring.splice(index, 1);
249
+ }
250
+ }
251
+ let winner = null;
252
+ let asset = null;
253
+ if (readSceneEnvironment(scene) !== null) for (const volume of volumes) {
254
+ const loaded = volume.isEnabledInHierarchy ? volume.loadedProbes() : null;
255
+ if (loaded !== null) {
256
+ winner = volume;
257
+ asset = loaded;
258
+ }
259
+ }
260
+ if (winner === null || asset === null) {
261
+ if (applied !== null) replace(null);
262
+ return;
263
+ }
264
+ if (applied === null || applied.asset !== asset) {
265
+ replace(apply(asset, winner.intensity));
266
+ return;
267
+ }
268
+ if (applied.uniforms.intensity !== winner.intensity) {
269
+ applied.uniforms.intensity = winner.intensity;
270
+ refreshLightProbeUniforms(scene, applied.plugin);
271
+ }
272
+ swapLightProbePlugin(scene, null, applied.plugin);
273
+ },
274
+ dispose() {
275
+ replace(null);
276
+ for (const entry of retiring) entry.destroy();
277
+ retiring.length = 0;
278
+ }
279
+ };
280
+ }
281
+ //#endregion
282
+ export { createLightProbeRuntime };
283
+
284
+ //# sourceMappingURL=light-probes-DkYN89Qw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light-probes-DkYN89Qw.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/plan/2026-11-gi-phase-2-execution-plan.md`, step B2). 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/plan/2026-11-gi-phase-2-execution-plan.md`, step\n * B2): which volume 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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AAO,SAA4C;GACjD,KAAK,IAAI,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,4 +1,4 @@
1
- import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-oYdVnT1S.js";
1
+ import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-B8ByiSfJ.js";
2
2
  import { u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
3
3
  //#region src/render/material-plugin.ts
4
4
  /**
@@ -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-BUlqLsap.js.map
284
+ //# sourceMappingURL=material-plugin-CiAmriQ_.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"material-plugin-BUlqLsap.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 * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.2, ADR-0024).\n *\n * `@beta` because the meaning of each point is whatever the surrounding Lite template declares at\n * that line; ignifx's stable contract is the three hooks of `./surface-shader.ts`. Four rules read\n * out of `@babylonjs/lite@1.27.0`'s `lib/` on 2026-09-08:\n *\n * - Plugin uniforms and samplers are **fragment-stage only** on both families\n * (`lib/material/plugin/plugin-bridge-shared.js` 99), and there is no vertex helper-function\n * channel, so vertex code may read only attributes, `mesh.world` and the scene block, and must be\n * statements rather than functions.\n * - `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected **twice** — Lite maps it to the two\n * adjacent PBR slots `AI` and `NI` — so its code must be idempotent or guard itself with a flag\n * set at an earlier point, and must declare nothing at statement level.\n * - Only PBR carries `CUSTOM_FRAGMENT_UPDATE_DIFFUSE` after `CUSTOM_FRAGMENT_UPDATE_ALPHA`;\n * Standard's template orders them the other way and has no `AI`/`NI`/`MF` slots.\n * - `roughness` and `metallic` are `let` in the PBR template and cannot be written.\n */\n\n/**\n * The Babylon Lite injection points a {@link MaterialPluginDefinition} may fill in.\n *\n * @remarks\n * The names are Lite's own (`MaterialPluginPoint`, `index.d.ts` 7084) and are taught verbatim,\n * because a plugin's code is written against the template around the point.\n *\n * @beta\n */\nexport const LITE_MATERIAL_PLUGIN_POINTS = [\n \"CUSTOM_FRAGMENT_DEFINITIONS\",\n \"CUSTOM_FRAGMENT_MAIN_BEGIN\",\n \"CUSTOM_FRAGMENT_UPDATE_ALPHA\",\n \"CUSTOM_FRAGMENT_UPDATE_DIFFUSE\",\n \"CUSTOM_FRAGMENT_BEFORE_LIGHTS\",\n \"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\",\n \"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\",\n \"CUSTOM_VERTEX_MAIN_BEGIN\",\n \"CUSTOM_VERTEX_UPDATE_WORLDPOS\",\n \"CUSTOM_VERTEX_MAIN_END\",\n] as const;\n\n/**\n * One of Babylon Lite's ten material-plugin injection points.\n *\n * @beta\n */\nexport type LiteMaterialPluginPoint = (typeof LITE_MATERIAL_PLUGIN_POINTS)[number];\n\n/**\n * The default priority Babylon Lite gives a plugin with none (`index.d.ts` 7057).\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_DEFAULT_PRIORITY = 500;\n\n/**\n * How many `texture`/`sampler` pairs one material's plugins may declare together.\n *\n * @remarks\n * Measured on a device on 2026-09-08 (spike S0.2): a fully textured PBR material — base colour,\n * normal, ORM, emissive — with image-based lighting and one PCF shadow light already binds seven\n * textures and seven samplers of the sixteen per stage that every WebGPU implementation guarantees,\n * SwiftShader included, and Lite requests no higher `requiredLimits`. Nine is what is left, and it\n * drops to eight with a second shadow light and seven with a lightmap, so a material that means to\n * be portable should stay well under the cap.\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_SAMPLER_BUDGET = 9;\n\n/**\n * The WGSL names the PBR and Standard templates already own, which a plugin may not reuse for a\n * uniform field or a sampler.\n *\n * @remarks\n * A plugin's fields land in the host's own uniform block and its samplers in the host's own bind\n * group, so a collision is a duplicate WGSL declaration and the whole material stops compiling with\n * a message that names neither the plugin nor the field. Refusing at attach time is the difference\n * between a sentence and a shader dump. Read from `pbr-template.js` `_baseMaterialUboFields` and\n * `_baseBindings`, and `standard-template.js` `materialStruct` and `_baseBindings`.\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_RESERVED_NAMES: readonly string[] = Object.freeze([\n // Blocks and entry points the templates declare.\n \"material\",\n \"mesh\",\n \"scene\",\n \"lights\",\n \"pluginUbo\",\n \"shadowParams\",\n \"main\",\n // PBR material uniform fields.\n \"environmentIntensity\",\n \"directIntensity\",\n \"reflectance\",\n \"materialAlpha\",\n \"baseColorFactor\",\n \"metallicFactor\",\n \"roughnessFactor\",\n \"normalScale\",\n \"lightFalloffMode\",\n \"anisotropyParams\",\n // PBR samplers.\n \"baseColorTexture\",\n \"baseColorSampler\",\n \"normalTexture\",\n \"normalSampler_\",\n \"ormTexture\",\n \"ormSampler\",\n \"emissiveTexture\",\n \"emissiveSampler\",\n \"specGlossTexture\",\n \"specGlossSampler\",\n // Standard samplers (`standard-template.js` uses two-letter names).\n \"dT\",\n \"dS\",\n \"mat\",\n \"up\",\n]);\n\n/**\n * What a raw material plugin declares: a name, the values and textures it wants beside the host\n * material's own, and the WGSL it injects.\n *\n * @beta\n */\nexport interface MaterialPluginDefinition {\n /** The plugin's identity. It is part of Lite's pipeline cache key, so it must be stable. */\n readonly name: string;\n /** Lower runs first; Lite's own default is {@link MATERIAL_PLUGIN_DEFAULT_PRIORITY}. */\n readonly priority: number;\n /** The uniform fields appended to the host material's uniform block. Fragment stage only. */\n readonly uniforms: readonly ShaderUniformDeclaration[];\n /** The `texture`/`sampler` pairs added to the host material's bind group. Fragment stage only. */\n readonly textures: readonly ShaderTextureDeclaration[];\n /** The WGSL to inject, by point. Vertex points take statements; there are no vertex helpers. */\n readonly code: Readonly<Partial<Record<LiteMaterialPluginPoint, string>>>;\n}\n\n/**\n * The properties {@link defineMaterialPlugin} accepts; everything but `name` and `code` has a\n * default.\n *\n * @beta\n */\nexport interface MaterialPluginDefinitionInit {\n /** The plugin's identity. */\n readonly name: string;\n /** Lower runs first. Defaults to {@link MATERIAL_PLUGIN_DEFAULT_PRIORITY}. */\n readonly priority?: number;\n /** The uniform fields. Defaults to none. */\n readonly uniforms?: readonly ShaderUniformDeclaration[];\n /** The samplers. Defaults to none. */\n readonly textures?: readonly ShaderTextureDeclaration[];\n /** The WGSL to inject, by point. */\n readonly code: Readonly<Partial<Record<LiteMaterialPluginPoint, string>>>;\n}\n\n/** Matches a WGSL identifier. */\nconst IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** Matches a legal plugin name: an identifier, optionally with `.`, `:`, or `-` inside it. */\nconst PLUGIN_NAME = /^[A-Za-z_][A-Za-z0-9_]*(?:[.:-][A-Za-z0-9_]+)*$/;\n\n/**\n * Validates a raw material-plugin declaration and fills in its defaults.\n *\n * @remarks\n * Nothing here reaches a device: the result is plain data that `attachSurfaceShaders` and\n * `attachMaterialPlugin` turn into a Lite plugin. The checks are the ones whose failure would\n * otherwise surface as a WGSL compile error with no mention of the plugin — an empty `code`, a\n * duplicate or reserved binding name, a name that is not a WGSL identifier, an unknown injection\n * point, or more samplers than {@link MATERIAL_PLUGIN_SAMPLER_BUDGET}.\n *\n * The **surface-shader compiler produces one of these**, so a bug in this validation is a bug in\n * every surface shader too, which is why it lives here rather than inside the compiler.\n *\n * @param definition - The declaration.\n * @returns The same declaration with `priority`, `uniforms`, and `textures` filled in.\n * @throws IgnifxError with code `IGX-0723` when `code` fills in no point, `IGX-0712` when a name is\n * not a legal, unique, unreserved WGSL identifier or a point name is unknown, or `IGX-0726` when the\n * plugin alone exceeds the sampler budget.\n *\n * @example\n * ```ts\n * const tint = defineMaterialPlugin({\n * name: \"tint\",\n * code: { CUSTOM_FRAGMENT_UPDATE_ALPHA: \"baseColor = baseColor * vec3<f32>(1.0, 0.5, 0.5);\" },\n * });\n * ```\n *\n * @beta\n */\nexport function defineMaterialPlugin(definition: MaterialPluginDefinitionInit): MaterialPluginDefinition {\n const name = definition.name;\n if (!PLUGIN_NAME.test(name)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${JSON.stringify(name)} is not a legal material-plugin name.`,\n {\n context: { plugin: name, name },\n hint: \"Start with a letter or underscore; letters, digits, underscores, and inner . : - follow.\",\n },\n );\n }\n const points = Object.keys(definition.code);\n let filled = 0;\n for (const point of points) {\n if (!isLiteMaterialPluginPoint(point)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${name} declares no Lite point named ${point}.`, {\n context: { plugin: name, name: point, point },\n hint: `The ten points are ${LITE_MATERIAL_PLUGIN_POINTS.join(\", \")}.`,\n });\n }\n if ((definition.code[point] ?? \"\").trim().length > 0) {\n filled += 1;\n }\n }\n if (filled === 0) {\n throw new IgnifxError(CoreErrorCode.surfaceHookMissing, `${name} injects no WGSL at any Lite point.`, {\n context: { plugin: name, name },\n hint: \"Fill in at least one of the ten points, or do not attach the plugin.\",\n });\n }\n const uniforms = definition.uniforms ?? [];\n const textures = definition.textures ?? [];\n const seen = new Set<string>();\n for (const uniform of uniforms) {\n assertBindingName(name, uniform.name, seen);\n assertUniformType(name, uniform.name, uniform.type);\n }\n for (const texture of textures) {\n assertBindingName(name, texture.name, seen);\n assertBindingName(name, `${texture.name}Sampler`, seen);\n }\n if (textures.length > MATERIAL_PLUGIN_SAMPLER_BUDGET) {\n throw new IgnifxError(\n CoreErrorCode.surfaceSamplerBudgetExceeded,\n `${name} declares ${String(textures.length)} samplers; a material's plugins may declare ${String(MATERIAL_PLUGIN_SAMPLER_BUDGET)} together.`,\n {\n context: { plugin: name, samplers: textures.length, budget: MATERIAL_PLUGIN_SAMPLER_BUDGET },\n hint: \"Pack the maps into fewer textures — an RGBA control map rather than four masks.\",\n },\n );\n }\n return {\n name,\n priority: definition.priority ?? MATERIAL_PLUGIN_DEFAULT_PRIORITY,\n uniforms,\n textures,\n code: definition.code,\n };\n}\n\n/**\n * Whether a string is one of Lite's ten injection points.\n *\n * @param value - The candidate.\n * @returns `true` when Lite accepts it.\n *\n * @beta\n */\nexport function isLiteMaterialPluginPoint(value: string): value is LiteMaterialPluginPoint {\n for (const point of LITE_MATERIAL_PLUGIN_POINTS) {\n if (point === value) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * How many floats one uniform of a declared type occupies on the CPU side.\n *\n * @param type - The declared WGSL type.\n * @returns The component count: 1, 2, 3, 4, or 16.\n *\n * @internal\n */\nexport function uniformComponentCount(type: ShaderUniformType): number {\n switch (type) {\n case \"vec2<f32>\": {\n return 2;\n }\n case \"vec3<f32>\": {\n return 3;\n }\n case \"vec4<f32>\": {\n return 4;\n }\n case \"mat4x4<f32>\": {\n return 16;\n }\n case \"f32\":\n case \"u32\":\n case \"i32\": {\n return 1;\n }\n default: {\n return assertNever(type, \"shader uniform type\");\n }\n }\n}\n\n/**\n * Refuses a binding name that is not a unique, unreserved WGSL identifier.\n *\n * @param plugin - The plugin's name, for the message.\n * @param binding - The candidate name.\n * @param seen - The names already taken by this plugin; the accepted name is added.\n * @throws IgnifxError with code `IGX-0712`.\n */\nfunction assertBindingName(plugin: string, binding: string, seen: Set<string>): void {\n if (!IDENTIFIER.test(binding)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${plugin} declares ${JSON.stringify(binding)}, which is not a WGSL identifier.`,\n { context: { plugin, name: binding }, hint: \"Use letters, digits, and underscores, starting with a letter.\" },\n );\n }\n if (MATERIAL_PLUGIN_RESERVED_NAMES.includes(binding)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${plugin} declares ${binding}, which Babylon Lite's own PBR or Standard shader already owns.`,\n { context: { plugin, name: binding }, hint: \"Rename it; a plugin shares the host material's WGSL namespace.\" },\n );\n }\n if (seen.has(binding)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin} declares ${binding} twice.`, {\n context: { plugin, name: binding },\n hint: \"Every uniform and texture of one plugin needs its own name.\",\n });\n }\n seen.add(binding);\n}\n\n/**\n * Refuses a uniform type Lite's plugin bridge cannot carry.\n *\n * @param plugin - The plugin's name, for the message.\n * @param binding - The uniform's name.\n * @param type - The declared type.\n * @throws IgnifxError with code `IGX-0712`.\n */\nfunction assertUniformType(plugin: string, binding: string, type: ShaderUniformType): void {\n if (!SHADER_UNIFORM_TYPES.includes(type)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin}.${binding} declares the type ${type}.`, {\n context: { plugin, name: binding, type },\n hint: `The plugin uniform types are ${SHADER_UNIFORM_TYPES.join(\", \")}.`,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,8BAA8B;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;AAcA,MAAa,mCAAmC;;;;;;;;;;;;;;AAehD,MAAa,iCAAiC;;;;;;;;;;;;;;AAe9C,MAAa,iCAAoD,OAAO,OAAO;CAE7E;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;AACF,CAAC;;AAyCD,MAAM,aAAa;;AAGnB,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BpB,SAAgB,qBAAqB,YAAoE;CACvG,MAAM,OAAO,WAAW;CACxB,IAAI,CAAC,YAAY,KAAK,IAAI,GACxB,MAAM,IAAI,YACR,cAAc,sBACd,GAAG,KAAK,UAAU,IAAI,EAAE,wCACxB;EACE,SAAS;GAAE,QAAQ;GAAM;EAAK;EAC9B,MAAM;CACR,CACF;CAEF,MAAM,SAAS,OAAO,KAAK,WAAW,IAAI;CAC1C,IAAI,SAAS;CACb,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,0BAA0B,KAAK,GAClC,MAAM,IAAI,YAAY,cAA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H,OAAO;EAET,KAAK,aACH,OAAO;EAET,KAAK,eACH,OAAO;EAET,KAAK;EACL,KAAK;EACL,KAAK,OACH,OAAO;EAET,SACE,OAAO,YAAY,MAAM,qBAAqB;CAElD;AACF;;;;;;;;;AAUA,SAAS,kBAAkB,QAAgB,SAAiB,MAAyB;CACnF,IAAI,CAAC,WAAW,KAAK,OAAO,GAC1B,MAAM,IAAI,YACR,cAAc,sBACd,GAAG,OAAO,YAAY,KAAK,UAAU,OAAO,EAAE,oCAC9C;EAAE,SAAS;GAAE;GAAQ,MAAM;EAAQ;EAAG,MAAM;CAAgE,CAC9G;CAEF,IAAI,+BAA+B,SAAS,OAAO,GACjD,MAAM,IAAI,YACR,cAAc,sBACd,GAAG,OAAO,YAAY,QAAQ,kEAC9B;EAAE,SAAS;GAAE;GAAQ,MAAM;EAAQ;EAAG,MAAM;CAAiE,CAC/G;CAEF,IAAI,KAAK,IAAI,OAAO,GAClB,MAAM,IAAI,YAAY,cAAc,sBAAsB,GAAG,OAAO,YAAY,QAAQ,UAAU;EAChG,SAAS;GAAE;GAAQ,MAAM;EAAQ;EACjC,MAAM;CACR,CAAC;CAEH,KAAK,IAAI,OAAO;AAClB;;;;;;;;;AAUA,SAAS,kBAAkB,QAAgB,SAAiB,MAA+B;CACzF,IAAI,CAAC,qBAAqB,SAAS,IAAI,GACrC,MAAM,IAAI,YAAY,cAAc,sBAAsB,GAAG,OAAO,GAAG,QAAQ,qBAAqB,KAAK,IAAI;EAC3G,SAAS;GAAE;GAAQ,MAAM;GAAS;EAAK;EACvC,MAAM,gCAAgC,qBAAqB,KAAK,IAAI,EAAE;CACxE,CAAC;AAEL"}
1
+ {"version":3,"file":"material-plugin-CiAmriQ_.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 * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.2, ADR-0024).\n *\n * `@beta` because the meaning of each point is whatever the surrounding Lite template declares at\n * that line; ignifx's stable contract is the three hooks of `./surface-shader.ts`. Four rules read\n * out of `@babylonjs/lite@1.27.0`'s `lib/` on 2026-09-08:\n *\n * - Plugin uniforms and samplers are **fragment-stage only** on both families\n * (`lib/material/plugin/plugin-bridge-shared.js` 99), and there is no vertex helper-function\n * channel, so vertex code may read only attributes, `mesh.world` and the scene block, and must be\n * statements rather than functions.\n * - `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected **twice** — Lite maps it to the two\n * adjacent PBR slots `AI` and `NI` — so its code must be idempotent or guard itself with a flag\n * set at an earlier point, and must declare nothing at statement level.\n * - Only PBR carries `CUSTOM_FRAGMENT_UPDATE_DIFFUSE` after `CUSTOM_FRAGMENT_UPDATE_ALPHA`;\n * Standard's template orders them the other way and has no `AI`/`NI`/`MF` slots.\n * - `roughness` and `metallic` are `let` in the PBR template and cannot be written.\n */\n\n/**\n * The Babylon Lite injection points a {@link MaterialPluginDefinition} may fill in.\n *\n * @remarks\n * The names are Lite's own (`MaterialPluginPoint`, `index.d.ts` 7084) and are taught verbatim,\n * because a plugin's code is written against the template around the point.\n *\n * @beta\n */\nexport const LITE_MATERIAL_PLUGIN_POINTS = [\n \"CUSTOM_FRAGMENT_DEFINITIONS\",\n \"CUSTOM_FRAGMENT_MAIN_BEGIN\",\n \"CUSTOM_FRAGMENT_UPDATE_ALPHA\",\n \"CUSTOM_FRAGMENT_UPDATE_DIFFUSE\",\n \"CUSTOM_FRAGMENT_BEFORE_LIGHTS\",\n \"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\",\n \"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\",\n \"CUSTOM_VERTEX_MAIN_BEGIN\",\n \"CUSTOM_VERTEX_UPDATE_WORLDPOS\",\n \"CUSTOM_VERTEX_MAIN_END\",\n] as const;\n\n/**\n * One of Babylon Lite's ten material-plugin injection points.\n *\n * @beta\n */\nexport type LiteMaterialPluginPoint = (typeof LITE_MATERIAL_PLUGIN_POINTS)[number];\n\n/**\n * The default priority Babylon Lite gives a plugin with none (`index.d.ts` 7057).\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_DEFAULT_PRIORITY = 500;\n\n/**\n * How many `texture`/`sampler` pairs one material's plugins may declare together.\n *\n * @remarks\n * Measured on a device on 2026-09-08 (spike S0.2): a fully textured PBR material — base colour,\n * normal, ORM, emissive — with image-based lighting and one PCF shadow light already binds seven\n * textures and seven samplers of the sixteen per stage that every WebGPU implementation guarantees,\n * SwiftShader included, and Lite requests no higher `requiredLimits`. Nine is what is left, and it\n * drops to eight with a second shadow light and seven with a lightmap, so a material that means to\n * be portable should stay well under the cap.\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_SAMPLER_BUDGET = 9;\n\n/**\n * The WGSL names the PBR and Standard templates already own, which a plugin may not reuse for a\n * uniform field or a sampler.\n *\n * @remarks\n * A plugin's fields land in the host's own uniform block and its samplers in the host's own bind\n * group, so a collision is a duplicate WGSL declaration and the whole material stops compiling with\n * a message that names neither the plugin nor the field. Refusing at attach time is the difference\n * between a sentence and a shader dump. Read from `pbr-template.js` `_baseMaterialUboFields` and\n * `_baseBindings`, and `standard-template.js` `materialStruct` and `_baseBindings`.\n *\n * @beta\n */\nexport const MATERIAL_PLUGIN_RESERVED_NAMES: readonly string[] = Object.freeze([\n // Blocks and entry points the templates declare.\n \"material\",\n \"mesh\",\n \"scene\",\n \"lights\",\n \"pluginUbo\",\n \"shadowParams\",\n \"main\",\n // PBR material uniform fields.\n \"environmentIntensity\",\n \"directIntensity\",\n \"reflectance\",\n \"materialAlpha\",\n \"baseColorFactor\",\n \"metallicFactor\",\n \"roughnessFactor\",\n \"normalScale\",\n \"lightFalloffMode\",\n \"anisotropyParams\",\n // PBR samplers.\n \"baseColorTexture\",\n \"baseColorSampler\",\n \"normalTexture\",\n \"normalSampler_\",\n \"ormTexture\",\n \"ormSampler\",\n \"emissiveTexture\",\n \"emissiveSampler\",\n \"specGlossTexture\",\n \"specGlossSampler\",\n // Standard samplers (`standard-template.js` uses two-letter names).\n \"dT\",\n \"dS\",\n \"mat\",\n \"up\",\n]);\n\n/**\n * What a raw material plugin declares: a name, the values and textures it wants beside the host\n * material's own, and the WGSL it injects.\n *\n * @beta\n */\nexport interface MaterialPluginDefinition {\n /** The plugin's identity. It is part of Lite's pipeline cache key, so it must be stable. */\n readonly name: string;\n /** Lower runs first; Lite's own default is {@link MATERIAL_PLUGIN_DEFAULT_PRIORITY}. */\n readonly priority: number;\n /** The uniform fields appended to the host material's uniform block. Fragment stage only. */\n readonly uniforms: readonly ShaderUniformDeclaration[];\n /** The `texture`/`sampler` pairs added to the host material's bind group. Fragment stage only. */\n readonly textures: readonly ShaderTextureDeclaration[];\n /** The WGSL to inject, by point. Vertex points take statements; there are no vertex helpers. */\n readonly code: Readonly<Partial<Record<LiteMaterialPluginPoint, string>>>;\n}\n\n/**\n * The properties {@link defineMaterialPlugin} accepts; everything but `name` and `code` has a\n * default.\n *\n * @beta\n */\nexport interface MaterialPluginDefinitionInit {\n /** The plugin's identity. */\n readonly name: string;\n /** Lower runs first. Defaults to {@link MATERIAL_PLUGIN_DEFAULT_PRIORITY}. */\n readonly priority?: number;\n /** The uniform fields. Defaults to none. */\n readonly uniforms?: readonly ShaderUniformDeclaration[];\n /** The samplers. Defaults to none. */\n readonly textures?: readonly ShaderTextureDeclaration[];\n /** The WGSL to inject, by point. */\n readonly code: Readonly<Partial<Record<LiteMaterialPluginPoint, string>>>;\n}\n\n/** Matches a WGSL identifier. */\nconst IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** Matches a legal plugin name: an identifier, optionally with `.`, `:`, or `-` inside it. */\nconst PLUGIN_NAME = /^[A-Za-z_][A-Za-z0-9_]*(?:[.:-][A-Za-z0-9_]+)*$/;\n\n/**\n * Validates a raw material-plugin declaration and fills in its defaults.\n *\n * @remarks\n * Nothing here reaches a device: the result is plain data that `attachSurfaceShaders` and\n * `attachMaterialPlugin` turn into a Lite plugin. The checks are the ones whose failure would\n * otherwise surface as a WGSL compile error with no mention of the plugin — an empty `code`, a\n * duplicate or reserved binding name, a name that is not a WGSL identifier, an unknown injection\n * point, or more samplers than {@link MATERIAL_PLUGIN_SAMPLER_BUDGET}.\n *\n * The **surface-shader compiler produces one of these**, so a bug in this validation is a bug in\n * every surface shader too, which is why it lives here rather than inside the compiler.\n *\n * @param definition - The declaration.\n * @returns The same declaration with `priority`, `uniforms`, and `textures` filled in.\n * @throws IgnifxError with code `IGX-0723` when `code` fills in no point, `IGX-0712` when a name is\n * not a legal, unique, unreserved WGSL identifier or a point name is unknown, or `IGX-0726` when the\n * plugin alone exceeds the sampler budget.\n *\n * @example\n * ```ts\n * const tint = defineMaterialPlugin({\n * name: \"tint\",\n * code: { CUSTOM_FRAGMENT_UPDATE_ALPHA: \"baseColor = baseColor * vec3<f32>(1.0, 0.5, 0.5);\" },\n * });\n * ```\n *\n * @beta\n */\nexport function defineMaterialPlugin(definition: MaterialPluginDefinitionInit): MaterialPluginDefinition {\n const name = definition.name;\n if (!PLUGIN_NAME.test(name)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${JSON.stringify(name)} is not a legal material-plugin name.`,\n {\n context: { plugin: name, name },\n hint: \"Start with a letter or underscore; letters, digits, underscores, and inner . : - follow.\",\n },\n );\n }\n const points = Object.keys(definition.code);\n let filled = 0;\n for (const point of points) {\n if (!isLiteMaterialPluginPoint(point)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${name} declares no Lite point named ${point}.`, {\n context: { plugin: name, name: point, point },\n hint: `The ten points are ${LITE_MATERIAL_PLUGIN_POINTS.join(\", \")}.`,\n });\n }\n if ((definition.code[point] ?? \"\").trim().length > 0) {\n filled += 1;\n }\n }\n if (filled === 0) {\n throw new IgnifxError(CoreErrorCode.surfaceHookMissing, `${name} injects no WGSL at any Lite point.`, {\n context: { plugin: name, name },\n hint: \"Fill in at least one of the ten points, or do not attach the plugin.\",\n });\n }\n const uniforms = definition.uniforms ?? [];\n const textures = definition.textures ?? [];\n const seen = new Set<string>();\n for (const uniform of uniforms) {\n assertBindingName(name, uniform.name, seen);\n assertUniformType(name, uniform.name, uniform.type);\n }\n for (const texture of textures) {\n assertBindingName(name, texture.name, seen);\n assertBindingName(name, `${texture.name}Sampler`, seen);\n }\n if (textures.length > MATERIAL_PLUGIN_SAMPLER_BUDGET) {\n throw new IgnifxError(\n CoreErrorCode.surfaceSamplerBudgetExceeded,\n `${name} declares ${String(textures.length)} samplers; a material's plugins may declare ${String(MATERIAL_PLUGIN_SAMPLER_BUDGET)} together.`,\n {\n context: { plugin: name, samplers: textures.length, budget: MATERIAL_PLUGIN_SAMPLER_BUDGET },\n hint: \"Pack the maps into fewer textures — an RGBA control map rather than four masks.\",\n },\n );\n }\n return {\n name,\n priority: definition.priority ?? MATERIAL_PLUGIN_DEFAULT_PRIORITY,\n uniforms,\n textures,\n code: definition.code,\n };\n}\n\n/**\n * Whether a string is one of Lite's ten injection points.\n *\n * @param value - The candidate.\n * @returns `true` when Lite accepts it.\n *\n * @beta\n */\nexport function isLiteMaterialPluginPoint(value: string): value is LiteMaterialPluginPoint {\n for (const point of LITE_MATERIAL_PLUGIN_POINTS) {\n if (point === value) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * How many floats one uniform of a declared type occupies on the CPU side.\n *\n * @param type - The declared WGSL type.\n * @returns The component count: 1, 2, 3, 4, or 16.\n *\n * @internal\n */\nexport function uniformComponentCount(type: ShaderUniformType): number {\n switch (type) {\n case \"vec2<f32>\": {\n return 2;\n }\n case \"vec3<f32>\": {\n return 3;\n }\n case \"vec4<f32>\": {\n return 4;\n }\n case \"mat4x4<f32>\": {\n return 16;\n }\n case \"f32\":\n case \"u32\":\n case \"i32\": {\n return 1;\n }\n default: {\n return assertNever(type, \"shader uniform type\");\n }\n }\n}\n\n/**\n * Refuses a binding name that is not a unique, unreserved WGSL identifier.\n *\n * @param plugin - The plugin's name, for the message.\n * @param binding - The candidate name.\n * @param seen - The names already taken by this plugin; the accepted name is added.\n * @throws IgnifxError with code `IGX-0712`.\n */\nfunction assertBindingName(plugin: string, binding: string, seen: Set<string>): void {\n if (!IDENTIFIER.test(binding)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${plugin} declares ${JSON.stringify(binding)}, which is not a WGSL identifier.`,\n { context: { plugin, name: binding }, hint: \"Use letters, digits, and underscores, starting with a letter.\" },\n );\n }\n if (MATERIAL_PLUGIN_RESERVED_NAMES.includes(binding)) {\n throw new IgnifxError(\n CoreErrorCode.unknownShaderBinding,\n `${plugin} declares ${binding}, which Babylon Lite's own PBR or Standard shader already owns.`,\n { context: { plugin, name: binding }, hint: \"Rename it; a plugin shares the host material's WGSL namespace.\" },\n );\n }\n if (seen.has(binding)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin} declares ${binding} twice.`, {\n context: { plugin, name: binding },\n hint: \"Every uniform and texture of one plugin needs its own name.\",\n });\n }\n seen.add(binding);\n}\n\n/**\n * Refuses a uniform type Lite's plugin bridge cannot carry.\n *\n * @param plugin - The plugin's name, for the message.\n * @param binding - The uniform's name.\n * @param type - The declared type.\n * @throws IgnifxError with code `IGX-0712`.\n */\nfunction assertUniformType(plugin: string, binding: string, type: ShaderUniformType): void {\n if (!SHADER_UNIFORM_TYPES.includes(type)) {\n throw new IgnifxError(CoreErrorCode.unknownShaderBinding, `${plugin}.${binding} declares the type ${type}.`, {\n context: { plugin, name: binding, type },\n hint: `The plugin uniform types are ${SHADER_UNIFORM_TYPES.join(\", \")}.`,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,8BAA8B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