@ignifx/core 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{environment-DZ6WUHbm.js → environment-Bf4aphSb.js} +2 -2
- package/dist/{environment-DZ6WUHbm.js.map → environment-Bf4aphSb.js.map} +1 -1
- package/dist/{ignifx-error-B8ByiSfJ.js → ignifx-error-DwIZKxA2.js} +4 -1
- package/dist/ignifx-error-DwIZKxA2.js.map +1 -0
- package/dist/index.d.ts +49 -687
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1326 -834
- package/dist/index.js.map +1 -1
- package/dist/{light-probe-asset-B60_X-yN.js → light-probe-asset-BqfSrJe9.js} +2 -2
- package/dist/{light-probe-asset-B60_X-yN.js.map → light-probe-asset-BqfSrJe9.js.map} +1 -1
- package/dist/{light-probes-DkYN89Qw.js → light-probes-DyLapYX9.js} +3 -3
- package/dist/{light-probes-DkYN89Qw.js.map → light-probes-DyLapYX9.js.map} +1 -1
- package/dist/lightmaps-LO6Ygtwe.js +137 -0
- package/dist/lightmaps-LO6Ygtwe.js.map +1 -0
- package/dist/{material-plugin-CiAmriQ_.js → material-plugin-DapJNj04.js} +2 -2
- package/dist/{material-plugin-CiAmriQ_.js.map → material-plugin-DapJNj04.js.map} +1 -1
- package/dist/{post-effect-CQnlX1RH.js → post-effect-CaiqDlhW.js} +2 -2
- package/dist/{post-effect-CQnlX1RH.js.map → post-effect-CaiqDlhW.js.map} +1 -1
- package/dist/{post-effect-compiler-C_7HTHZy.js → post-effect-compiler-jSvOVe0U.js} +3 -3
- package/dist/{post-effect-compiler-C_7HTHZy.js.map → post-effect-compiler-jSvOVe0U.js.map} +1 -1
- package/dist/{prefab-overrides-BLQn5yHS.d.ts → prefab-overrides-CS8_cG66.d.ts} +1334 -251
- package/dist/prefab-overrides-CS8_cG66.d.ts.map +1 -0
- package/dist/{prefab-overrides-DT-wHHAJ.js → prefab-overrides-DRP2DcnC.js} +450 -30
- package/dist/prefab-overrides-DRP2DcnC.js.map +1 -0
- package/dist/prefab.d.ts +2 -2
- package/dist/prefab.js +2 -2
- package/dist/{reflection-probe-DlVsl3zJ.js → reflection-probe-AS8d4uKv.js} +30 -12
- package/dist/{reflection-probe-DlVsl3zJ.js.map → reflection-probe-AS8d4uKv.js.map} +1 -1
- package/dist/{reflection-probes-B8S9WnVX.js → reflection-probes-CUZcOjNW.js} +115 -22
- package/dist/reflection-probes-CUZcOjNW.js.map +1 -0
- package/dist/{shader-material-CaAkv5nT.js → shader-material-CJIDFvSb.js} +2 -2
- package/dist/{shader-material-CaAkv5nT.js.map → shader-material-CJIDFvSb.js.map} +1 -1
- package/dist/{shader-material-C2_UCYdO.js → shader-material-CuwK9tWC.js} +4 -4
- package/dist/{shader-material-C2_UCYdO.js.map → shader-material-CuwK9tWC.js.map} +1 -1
- package/dist/{shader-pragma-DmZpxGUo.js → shader-pragma-ljmAbVc2.js} +2 -2
- package/dist/{shader-pragma-DmZpxGUo.js.map → shader-pragma-ljmAbVc2.js.map} +1 -1
- package/dist/{surface-shader-BeDRofOV.js → surface-shader-DY9_aC9L.js} +4 -4
- package/dist/{surface-shader-BeDRofOV.js.map → surface-shader-DY9_aC9L.js.map} +1 -1
- package/package.json +1 -1
- package/dist/ignifx-error-B8ByiSfJ.js.map +0 -1
- package/dist/prefab-overrides-BLQn5yHS.d.ts.map +0 -1
- package/dist/prefab-overrides-DT-wHHAJ.js.map +0 -1
- package/dist/reflection-probes-B8S9WnVX.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as readSceneEnvironment } from "./environment-
|
|
3
|
-
import { o as rebuildMaterialPipelines } from "./material-CGk5mAah.js";
|
|
1
|
+
import { R as readOwnerTag, a as selectReflectionProbe, i as resolveReflectionProbeSize, o as EDITOR_ONLY_METADATA_KEY, q as toEntityHandle, r as resolveReflectionProbeRefreshMode } from "./reflection-probe-AS8d4uKv.js";
|
|
2
|
+
import { i as readSceneEnvironment } from "./environment-Bf4aphSb.js";
|
|
4
3
|
import { n as deviceOf, r as removeTask, t as colorTextureOf } from "./render-texture-UqRHRLQy.js";
|
|
5
|
-
import { addTask, buildFrameGraphTask, clearPbrLocalEnvironment, createBankedFreeCamera, createRenderTarget, createRenderTask, enablePbrLocalCubemap, getFrameGraph, getPbrUnlit, isPbrMaterial, isPbrSkybox, setPbrEnvironment, setPbrLocalEnvironment } from "@babylonjs/lite";
|
|
4
|
+
import { addTask, buildFrameGraphTask, clearPbrLocalEnvironment, createBankedFreeCamera, createRenderTarget, createRenderTask, enablePbrLocalCubemap, getFrameGraph, getPbrUnlit, isPbrMaterial, isPbrSkybox, rebuildMaterial, setPbrEnvironment, setPbrLocalEnvironment } from "@babylonjs/lite";
|
|
6
5
|
//#region src/lite/gpu/reflection-probe.ts
|
|
7
6
|
/**
|
|
8
7
|
* Reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1). Its own chunk,
|
|
@@ -191,7 +190,7 @@ function createLiteReflectionProbe(engine, scene, size, excludeKey, accept) {
|
|
|
191
190
|
return environment;
|
|
192
191
|
},
|
|
193
192
|
capture(x, y, z, near, far) {
|
|
194
|
-
if (isDisposed) return;
|
|
193
|
+
if (isDisposed || readSceneEnvironment(scene) === null) return false;
|
|
195
194
|
for (let index = 0; index < FACES.length; index += 1) {
|
|
196
195
|
const face = FACES[index];
|
|
197
196
|
const camera = cameras[index];
|
|
@@ -204,6 +203,7 @@ function createLiteReflectionProbe(engine, scene, size, excludeKey, accept) {
|
|
|
204
203
|
task.executionEnabled = true;
|
|
205
204
|
}
|
|
206
205
|
isCapturing = true;
|
|
206
|
+
return true;
|
|
207
207
|
},
|
|
208
208
|
resolve(decodeGamma) {
|
|
209
209
|
if (isDisposed || !isCapturing) return false;
|
|
@@ -239,7 +239,7 @@ function createLiteReflectionProbe(engine, scene, size, excludeKey, accept) {
|
|
|
239
239
|
};
|
|
240
240
|
return true;
|
|
241
241
|
},
|
|
242
|
-
dispose() {
|
|
242
|
+
dispose(after) {
|
|
243
243
|
if (isDisposed) return;
|
|
244
244
|
isDisposed = true;
|
|
245
245
|
for (const task of tasks) {
|
|
@@ -247,12 +247,29 @@ function createLiteReflectionProbe(engine, scene, size, excludeKey, accept) {
|
|
|
247
247
|
removeTask(scene, task);
|
|
248
248
|
task.dispose();
|
|
249
249
|
}
|
|
250
|
+
const retired = cube;
|
|
250
251
|
cube = null;
|
|
251
252
|
environment = null;
|
|
253
|
+
if (retired !== null) destroyWhenIdle(deviceOf(engine), retired, after);
|
|
252
254
|
}
|
|
253
255
|
};
|
|
254
256
|
}
|
|
255
257
|
/**
|
|
258
|
+
* Destroys a texture once nothing in flight can name it: a material rebuild finishes asynchronously
|
|
259
|
+
* (`rebuildMaterial`, `index.d.ts` 11136), and until then Lite may still draw with a bind group that
|
|
260
|
+
* holds the old cube, so destruction waits for `after`, then for the queue.
|
|
261
|
+
*
|
|
262
|
+
* @param device - The device, or `null` when it is gone (the texture is destroyed at once).
|
|
263
|
+
* @param texture - The texture.
|
|
264
|
+
* @param after - What must settle first, if anything.
|
|
265
|
+
*/
|
|
266
|
+
function destroyWhenIdle(device, texture, after) {
|
|
267
|
+
const destroy = () => {
|
|
268
|
+
texture.destroy();
|
|
269
|
+
};
|
|
270
|
+
Promise.resolve(after).catch(() => void 0).then(async () => device?.queue.onSubmittedWorkDone()).then(destroy, destroy);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
256
273
|
* Copies the six face targets into the cube's first mip and box-downsamples the rest.
|
|
257
274
|
*
|
|
258
275
|
* @param device - The device.
|
|
@@ -389,9 +406,11 @@ function forEachReflectiveMesh(scene, visit) {
|
|
|
389
406
|
/**
|
|
390
407
|
* Points a PBR material at a probe, or back at the scene environment, and rebuilds it.
|
|
391
408
|
*
|
|
392
|
-
* @param scene - The registered scene
|
|
409
|
+
* @param scene - The registered scene, or `null` to leave the rebuild to Lite (its device-loss
|
|
410
|
+
* recovery rebuilds every material).
|
|
393
411
|
* @param material - The material.
|
|
394
412
|
* @param binding - The probe, or `null` for the scene environment.
|
|
413
|
+
* @returns The rebuild in flight, if Lite runs it asynchronously; Lite reports its failure itself.
|
|
395
414
|
*
|
|
396
415
|
* @internal
|
|
397
416
|
*/
|
|
@@ -404,7 +423,9 @@ function assignReflectionProbe(scene, material, binding) {
|
|
|
404
423
|
projectionPosition: binding.position,
|
|
405
424
|
projectionSize: binding.box
|
|
406
425
|
});
|
|
407
|
-
|
|
426
|
+
if (scene === null) return;
|
|
427
|
+
const pending = rebuildMaterial(scene, material);
|
|
428
|
+
return pending instanceof Promise ? pending : void 0;
|
|
408
429
|
}
|
|
409
430
|
//#endregion
|
|
410
431
|
//#region src/render/gpu/reflection-probes.ts
|
|
@@ -424,21 +445,66 @@ const CAPTURE_FRAMES = 8;
|
|
|
424
445
|
*
|
|
425
446
|
* @param engine - The engine.
|
|
426
447
|
* @param scene - The registered render scene.
|
|
448
|
+
* @param warn - Where a probe's warning goes: a message with an `{entity}` slot, and the name.
|
|
427
449
|
* @returns The runtime.
|
|
428
450
|
*
|
|
429
451
|
* @internal
|
|
430
452
|
*/
|
|
431
|
-
async function createReflectionProbeRuntime(engine, scene) {
|
|
453
|
+
async function createReflectionProbeRuntime(engine, scene, warn) {
|
|
432
454
|
await enableReflectionProbes();
|
|
433
455
|
const states = /* @__PURE__ */ new Map();
|
|
434
456
|
const assigned = /* @__PURE__ */ new Map();
|
|
435
457
|
const seen = /* @__PURE__ */ new Set();
|
|
436
458
|
const candidates = [];
|
|
459
|
+
/** The cubes released this frame, freed once the materials that reflected them are rebuilt. */
|
|
460
|
+
const retiring = [];
|
|
461
|
+
/** Material rebuilds started this frame. */
|
|
462
|
+
const rebuilds = [];
|
|
463
|
+
/**
|
|
464
|
+
* Probes whose capture was freed while they stayed (resized, environment gone, device lost); they
|
|
465
|
+
* capture again whatever their mode.
|
|
466
|
+
*/
|
|
467
|
+
const recapture = /* @__PURE__ */ new WeakSet();
|
|
468
|
+
let hasWarnedEveryFrame = false;
|
|
469
|
+
const assign = (material, binding) => {
|
|
470
|
+
const pending = assignReflectionProbe(scene, material, binding);
|
|
471
|
+
if (pending !== void 0) rebuilds.push(pending);
|
|
472
|
+
};
|
|
437
473
|
const release = (probe, state) => {
|
|
438
|
-
state.lite.
|
|
474
|
+
if (state.lite.environment !== null) recapture.add(probe);
|
|
475
|
+
retiring.push({
|
|
476
|
+
lite: state.lite,
|
|
477
|
+
environment: state.lite.environment
|
|
478
|
+
});
|
|
439
479
|
states.delete(probe);
|
|
440
480
|
};
|
|
481
|
+
/**
|
|
482
|
+
* Frees the cubes released this frame. A material that reflected one and was not reassigned this
|
|
483
|
+
* frame (its mesh left the scene) goes back to the scene environment first, so it never names a
|
|
484
|
+
* destroyed cube; the cubes then wait for every rebuild started this frame.
|
|
485
|
+
*/
|
|
486
|
+
const retire = () => {
|
|
487
|
+
if (retiring.length > 0) {
|
|
488
|
+
for (const [material, binding] of assigned) if (binding !== null && retiring.some((entry) => entry.environment === binding.environment)) {
|
|
489
|
+
assigned.set(material, null);
|
|
490
|
+
assign(material, null);
|
|
491
|
+
}
|
|
492
|
+
const settled = Promise.allSettled(rebuilds);
|
|
493
|
+
for (const entry of retiring) entry.lite.dispose(settled);
|
|
494
|
+
retiring.length = 0;
|
|
495
|
+
}
|
|
496
|
+
rebuilds.length = 0;
|
|
497
|
+
};
|
|
498
|
+
/** Hands every material back to the scene environment, without walking the scene. */
|
|
499
|
+
const clearMaterials = () => {
|
|
500
|
+
for (const [material, binding] of assigned) if (binding !== null) assign(material, null);
|
|
501
|
+
assigned.clear();
|
|
502
|
+
};
|
|
441
503
|
const assignMaterials = () => {
|
|
504
|
+
if (candidates.length === 0) {
|
|
505
|
+
clearMaterials();
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
442
508
|
seen.clear();
|
|
443
509
|
forEachReflectiveMesh(scene, (material, x, y, z) => {
|
|
444
510
|
if (seen.has(material)) return;
|
|
@@ -448,21 +514,36 @@ async function createReflectionProbeRuntime(engine, scene) {
|
|
|
448
514
|
const current = assigned.get(material);
|
|
449
515
|
if (current === binding || current === void 0 && binding === null) return;
|
|
450
516
|
assigned.set(material, binding);
|
|
451
|
-
|
|
517
|
+
assign(material, binding);
|
|
452
518
|
});
|
|
453
519
|
};
|
|
454
520
|
return {
|
|
455
|
-
update(world, probes, isHdr) {
|
|
456
|
-
for (const [probe, state] of states) if (!probes.includes(probe) || resolveReflectionProbeSize(probe.size) !== state.lite.size) release(probe, state);
|
|
521
|
+
update(world, probes, isHdr, tier, hasEnvironment) {
|
|
457
522
|
candidates.length = 0;
|
|
523
|
+
if (!hasEnvironment) {
|
|
524
|
+
for (const [probe, state] of states) release(probe, state);
|
|
525
|
+
clearMaterials();
|
|
526
|
+
retire();
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const maxSize = tier?.reflectionProbeMaxSize;
|
|
530
|
+
const allowsEveryFrame = tier?.reflectionProbeEveryFrame ?? true;
|
|
531
|
+
for (const [probe, state] of states) if (!probes.includes(probe) || resolveReflectionProbeSize(probe.size, maxSize) !== state.lite.size) release(probe, state);
|
|
458
532
|
for (const probe of probes) {
|
|
459
533
|
const wantsRefresh = probe.consumeRefreshRequest();
|
|
460
534
|
if (!probe.isEnabledInHierarchy) continue;
|
|
535
|
+
const mode = resolveReflectionProbeRefreshMode(probe.refreshMode, allowsEveryFrame);
|
|
536
|
+
if (mode !== probe.refreshMode && !hasWarnedEveryFrame) {
|
|
537
|
+
hasWarnedEveryFrame = true;
|
|
538
|
+
warn("{entity} asks its ReflectionProbe for refreshMode \"everyFrame\", which only the \"high\" rendering.quality tier allows, so it captures as \"once\" (when ready and on refresh()).", probe.entity.name);
|
|
539
|
+
}
|
|
461
540
|
let state = states.get(probe);
|
|
462
541
|
if (state === void 0) {
|
|
542
|
+
if (mode === "onDemand" && !wantsRefresh && !recapture.has(probe)) continue;
|
|
543
|
+
recapture.delete(probe);
|
|
463
544
|
state = {
|
|
464
|
-
lite: createLiteReflectionProbe(engine, scene, resolveReflectionProbeSize(probe.size), EDITOR_ONLY_METADATA_KEY, cullingFilter(world, probe)),
|
|
465
|
-
framesToCapture:
|
|
545
|
+
lite: createLiteReflectionProbe(engine, scene, resolveReflectionProbeSize(probe.size, maxSize), EDITOR_ONLY_METADATA_KEY, cullingFilter(world, probe)),
|
|
546
|
+
framesToCapture: CAPTURE_FRAMES,
|
|
466
547
|
binding: null
|
|
467
548
|
};
|
|
468
549
|
states.set(probe, state);
|
|
@@ -473,10 +554,7 @@ async function createReflectionProbeRuntime(engine, scene) {
|
|
|
473
554
|
const y = matrix[13] ?? 0;
|
|
474
555
|
const z = matrix[14] ?? 0;
|
|
475
556
|
if (wantsRefresh) state.framesToCapture = CAPTURE_FRAMES;
|
|
476
|
-
if (state.framesToCapture > 0 ||
|
|
477
|
-
state.lite.capture(x, y, z, probe.near, probe.far);
|
|
478
|
-
state.framesToCapture = Math.max(0, state.framesToCapture - 1);
|
|
479
|
-
}
|
|
557
|
+
if ((state.framesToCapture > 0 || mode === "everyFrame") && state.lite.capture(x, y, z, probe.near, probe.far)) state.framesToCapture = Math.max(0, state.framesToCapture - 1);
|
|
480
558
|
const environment = state.lite.environment;
|
|
481
559
|
if (environment === null) continue;
|
|
482
560
|
const box = probe.boxProjection;
|
|
@@ -491,11 +569,26 @@ async function createReflectionProbeRuntime(engine, scene) {
|
|
|
491
569
|
});
|
|
492
570
|
}
|
|
493
571
|
assignMaterials();
|
|
572
|
+
retire();
|
|
573
|
+
},
|
|
574
|
+
handleDeviceLost() {
|
|
575
|
+
for (const [material, binding] of assigned) if (binding !== null) assignReflectionProbe(null, material, null);
|
|
576
|
+
assigned.clear();
|
|
577
|
+
for (const [probe, state] of states) {
|
|
578
|
+
if (state.lite.environment !== null) recapture.add(probe);
|
|
579
|
+
state.lite.dispose();
|
|
580
|
+
}
|
|
581
|
+
states.clear();
|
|
582
|
+
retiring.length = 0;
|
|
583
|
+
rebuilds.length = 0;
|
|
494
584
|
},
|
|
495
585
|
dispose() {
|
|
496
586
|
for (const [probe, state] of states) release(probe, state);
|
|
497
|
-
|
|
498
|
-
|
|
587
|
+
clearMaterials();
|
|
588
|
+
const settled = Promise.allSettled(rebuilds);
|
|
589
|
+
for (const entry of retiring) entry.lite.dispose(settled);
|
|
590
|
+
retiring.length = 0;
|
|
591
|
+
rebuilds.length = 0;
|
|
499
592
|
}
|
|
500
593
|
};
|
|
501
594
|
}
|
|
@@ -548,4 +641,4 @@ function bindingFor(previous, environment, x, y, z, box) {
|
|
|
548
641
|
//#endregion
|
|
549
642
|
export { createReflectionProbeRuntime };
|
|
550
643
|
|
|
551
|
-
//# sourceMappingURL=reflection-probes-
|
|
644
|
+
//# sourceMappingURL=reflection-probes-CUZcOjNW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflection-probes-CUZcOjNW.js","names":[],"sources":["../src/lite/gpu/reflection-probe.ts","../src/render/gpu/reflection-probes.ts"],"sourcesContent":["import {\n addTask,\n buildFrameGraphTask,\n clearPbrLocalEnvironment,\n createBankedFreeCamera,\n createRenderTarget,\n createRenderTask,\n enablePbrLocalCubemap,\n getFrameGraph,\n getPbrUnlit,\n isPbrMaterial,\n isPbrSkybox,\n rebuildMaterial,\n setPbrEnvironment,\n setPbrLocalEnvironment,\n} from \"@babylonjs/lite\";\nimport { readOwnerTag } from \"../picking.js\";\nimport { readSceneEnvironment } from \"./environment.js\";\nimport { colorTextureOf, deviceOf, removeTask } from \"./render-texture.js\";\nimport type { NodeTag } from \"../node.js\";\nimport type {\n BankedFreeCamera,\n EngineContext,\n EnvironmentTextures,\n Mesh,\n PbrMaterialProps,\n RenderTarget,\n RenderTask,\n SceneContext,\n} from \"@babylonjs/lite\";\n\n/**\n * Reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1). Its own chunk,\n * loaded only when a world has a `ReflectionProbe` (`CONSTITUTION.md` §2.5). Every Lite claim was\n * read from `@babylonjs/lite@1.34.0`.\n *\n * - **Capture.** Lite has no cube capture, so six render tasks (`createRenderTask`, each with its own\n * `rgba16float` target and a `createBankedFreeCamera` looking down one axis, 90° field of view,\n * square target) are appended to the frame graph, switched on for the frames that capture, like\n * `./render-texture.ts`. Faces follow the cube-map convention in Lite's left-handed space: +X, −X\n * and ±Z faces use +Y as up, +Y uses −Z and −Y uses +Z.\n * - **Cube and mips.** In the next frame's `PreRender`, a small render pipeline of ignifx's own copies\n * each face into a cube texture, decoding gamma when `rendering.hdr` is off (the faces then hold\n * tone-mapped sRGB), and box-downsamples the mip chain. It is submitted before Lite's frame, so queue\n * order makes it read the frame that rendered the faces. Mips are not GGX-prefiltered.\n * - **Environment.** The cube is wrapped in an `EnvironmentTextures` (`index.d.ts` 5598) that shares\n * the scene environment's BRDF table and spherical harmonics, so diffuse light is unchanged.\n * - **Materials.** `setPbrLocalEnvironment` (box parallax) or `setPbrEnvironment` (no box) per lit PBR\n * material, then a material rebuild (`index.d.ts` 12612–12654). `enablePbrLocalCubemap` must have\n * resolved first; it is called when the chunk loads.\n * - **Culling mask.** Render tasks have no mesh filter, so each face task's `execute` hides the meshes\n * the caller rejects and shows them again, as `./render-texture.ts` does for editor-only meshes.\n */\n\n/** The colour format of the faces and the cube. */\nconst PROBE_FORMAT: GPUTextureFormat = \"rgba16float\";\n\n/** The depth/stencil format Lite's own render tasks use. */\nconst DEPTH_STENCIL_FORMAT: GPUTextureFormat = \"depth24plus-stencil8\";\n\n/** Each face's view direction and up vector, in cube-face order +X, −X, +Y, −Y, +Z, −Z. */\nconst FACES: readonly (readonly [number, number, number, number, number, number])[] = [\n [1, 0, 0, 0, 1, 0],\n [-1, 0, 0, 0, 1, 0],\n [0, 1, 0, 0, 0, -1],\n [0, -1, 0, 0, 0, 1],\n [0, 0, 1, 0, 1, 0],\n [0, 0, -1, 0, 1, 0],\n];\n\n/** A full-screen triangle that copies, decodes, or (through a linear sampler) box-downsamples. */\nconst BLIT_WGSL = /* wgsl */ `\nstruct VsOut { @builtin(position) position: vec4<f32>, @location(0) uv: vec2<f32> };\n@vertex fn vs(@builtin(vertex_index) index: u32) -> VsOut {\n let corner = vec2<f32>(f32((index << 1u) & 2u), f32(index & 2u));\n var out: VsOut;\n out.position = vec4<f32>(corner * 2.0 - 1.0, 0.0, 1.0);\n out.uv = vec2<f32>(corner.x, 1.0 - corner.y);\n return out;\n}\n@group(0) @binding(0) var source: texture_2d<f32>;\n@group(0) @binding(1) var sourceSampler: sampler;\n@fragment fn copy(in: VsOut) -> @location(0) vec4<f32> {\n return vec4<f32>(textureSampleLevel(source, sourceSampler, in.uv, 0.0).rgb, 1.0);\n}\n@fragment fn decode(in: VsOut) -> @location(0) vec4<f32> {\n let colour = textureSampleLevel(source, sourceSampler, in.uv, 0.0).rgb;\n return vec4<f32>(pow(max(colour, vec3<f32>(0.0)), vec3<f32>(2.2)), 1.0);\n}\n`;\n\n/** The blit pipelines of one device. */\ninterface BlitPipelines {\n readonly copy: GPURenderPipeline;\n readonly decode: GPURenderPipeline;\n readonly sampler: GPUSampler;\n}\n\n/** Each device's pipelines, the map created on first use (coding standards §4). */\nlet pipelineCache: WeakMap<GPUDevice, BlitPipelines> | null = null;\n\n/**\n * One probe's capture passes and cube map.\n *\n * @internal\n */\nexport interface LiteReflectionProbe {\n /** The cube face size in pixels. */\n readonly size: number;\n /** The environment materials reflect, `null` until the first capture resolved. Stable afterwards. */\n readonly environment: EnvironmentTextures | null;\n /**\n * Renders the six faces in the coming frame.\n *\n * @param x - The world X of the capture point.\n * @param y - The world Y.\n * @param z - The world Z.\n * @param near - The near clip distance.\n * @param far - The far clip distance.\n * @returns `false`, rendering nothing, while the scene has no environment to borrow the lighting\n * tables from.\n */\n capture(x: number, y: number, z: number, near: number, far: number): boolean;\n /**\n * Turns the faces the last frame rendered into the cube map, when a capture ran.\n *\n * @param decodeGamma - Whether the faces hold gamma-encoded colour (`rendering.hdr` off).\n * @returns `true` when {@link LiteReflectionProbe.environment} was created by this call.\n */\n resolve(decodeGamma: boolean): boolean;\n /**\n * Removes the passes, frees the face targets, and destroys the cube map once `after` settled and\n * the GPU finished the work submitted by then. Idempotent.\n *\n * @param after - What must finish before the cube may go, such as the rebuilds of the materials\n * that reflected it; omitted (device lost, app closing) to wait for the queue only.\n */\n dispose(after?: PromiseLike<unknown>): void;\n}\n\n/**\n * Loads Lite's local-cubemap shader path. Resolve it before assigning any probe.\n *\n * @returns A promise that resolves once the path is registered.\n *\n * @internal\n */\nexport function enableReflectionProbes(): Promise<void> {\n return enablePbrLocalCubemap();\n}\n\n/**\n * Creates a probe's six face passes, switched off, at the end of the scene's frame graph.\n *\n * @param engine - The WebGPU engine.\n * @param scene - The registered render scene.\n * @param size - The face size in pixels, a power of two.\n * @param excludeKey - The `metadata` key that, set to `true` on a mesh, keeps it out of the faces.\n * @param accept - Whether a mesh's owner may be captured; `false` hides it during the faces.\n * @returns The probe.\n *\n * @internal\n */\nexport function createLiteReflectionProbe(\n engine: EngineContext,\n scene: SceneContext,\n size: number,\n excludeKey: string,\n accept: (tag: NodeTag | null) => boolean,\n): LiteReflectionProbe {\n const targets: RenderTarget[] = [];\n const tasks: RenderTask[] = [];\n const cameras: BankedFreeCamera[] = [];\n const hidden: Mesh[] = [];\n for (const face of FACES) {\n const target = createRenderTarget({\n lbl: \"ignifx:reflection-probe-face\",\n format: PROBE_FORMAT,\n dFormat: DEPTH_STENCIL_FORMAT,\n samples: 1,\n size: { width: size, height: size },\n });\n const camera = createBankedFreeCamera(\n { x: 0, y: 0, z: 0 },\n { x: face[0], y: face[1], z: face[2] },\n {\n x: face[3],\n y: face[4],\n z: face[5],\n },\n );\n camera.fov = Math.PI / 2;\n const task = createRenderTask({ name: \"ignifx:reflection-probe\", rt: target, cam: camera }, engine, scene);\n task.executionEnabled = false;\n const execute = task.execute?.bind(task);\n if (execute === undefined) {\n throw new TypeError(\"Lite's render task has no execute(); reflection-probe.ts needs updating for this Lite.\");\n }\n task.execute = (): number => {\n for (const mesh of scene.meshes) {\n if (mesh.visible !== false && (mesh.metadata?.[excludeKey] === true || !accept(readOwnerTag(mesh)))) {\n mesh.visible = false;\n hidden.push(mesh);\n }\n }\n try {\n return execute();\n } finally {\n for (const mesh of hidden) {\n mesh.visible = true;\n }\n hidden.length = 0;\n }\n };\n addTask(scene, task);\n buildFrameGraphTask(getFrameGraph(scene), task);\n targets.push(target);\n tasks.push(task);\n cameras.push(camera);\n }\n let cube: GPUTexture | null = null;\n let environment: EnvironmentTextures | null = null;\n let isCapturing = false;\n let isDisposed = false;\n return {\n size,\n get environment(): EnvironmentTextures | null {\n return environment;\n },\n capture(x: number, y: number, z: number, near: number, far: number): boolean {\n if (isDisposed || readSceneEnvironment(scene) === null) {\n return false;\n }\n for (let index = 0; index < FACES.length; index += 1) {\n const face = FACES[index];\n const camera = cameras[index];\n const task = tasks[index];\n if (face === undefined || camera === undefined || task === undefined) {\n continue;\n }\n camera.position.set(x, y, z);\n camera.target.set(x + face[0], y + face[1], z + face[2]);\n camera.nearPlane = near;\n camera.farPlane = far;\n task.executionEnabled = true;\n }\n isCapturing = true;\n return true;\n },\n resolve(decodeGamma: boolean): boolean {\n if (isDisposed || !isCapturing) {\n return false;\n }\n isCapturing = false;\n for (const task of tasks) {\n task.executionEnabled = false;\n }\n const device = deviceOf(engine);\n const base = readSceneEnvironment(scene);\n if (device === null || base === null) {\n return false;\n }\n cube ??= device.createTexture({\n label: \"ignifx:reflection-probe\",\n size: [size, size, FACES.length],\n format: PROBE_FORMAT,\n mipLevelCount: Math.log2(size) + 1,\n usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,\n });\n if (!blitFaces(device, cube, targets, decodeGamma)) {\n return false;\n }\n if (environment !== null) {\n return false;\n }\n environment = {\n specularCube: cube,\n specularCubeView: cube.createView({ dimension: \"cube\" }),\n brdfLut: base.brdfLut,\n brdfLutView: base.brdfLutView,\n cubeSampler: base.cubeSampler,\n brdfSampler: base.brdfSampler,\n irradianceSH: base.irradianceSH,\n sphericalHarmonics: base.sphericalHarmonics,\n lodGenerationScale: base.lodGenerationScale,\n lodGenerationOffset: base.lodGenerationOffset ?? 0,\n };\n return true;\n },\n dispose(after?: PromiseLike<unknown>): void {\n if (isDisposed) {\n return;\n }\n isDisposed = true;\n for (const task of tasks) {\n task.executionEnabled = false;\n removeTask(scene, task);\n // Frees the face target too (`lib/frame-graph/render-task-base.js` 97–109).\n task.dispose();\n }\n const retired = cube;\n cube = null;\n environment = null;\n if (retired !== null) {\n destroyWhenIdle(deviceOf(engine), retired, after);\n }\n },\n };\n}\n\n/**\n * Destroys a texture once nothing in flight can name it: a material rebuild finishes asynchronously\n * (`rebuildMaterial`, `index.d.ts` 11136), and until then Lite may still draw with a bind group that\n * holds the old cube, so destruction waits for `after`, then for the queue.\n *\n * @param device - The device, or `null` when it is gone (the texture is destroyed at once).\n * @param texture - The texture.\n * @param after - What must settle first, if anything.\n */\nfunction destroyWhenIdle(device: GPUDevice | null, texture: GPUTexture, after: PromiseLike<unknown> | undefined): void {\n const destroy = (): void => {\n texture.destroy();\n };\n Promise.resolve(after)\n .catch(() => undefined)\n .then(async () => device?.queue.onSubmittedWorkDone())\n .then(destroy, destroy);\n}\n\n/**\n * Copies the six face targets into the cube's first mip and box-downsamples the rest.\n *\n * @param device - The device.\n * @param cube - The cube texture, six layers.\n * @param targets - The face targets, in cube-face order.\n * @param decodeGamma - Whether to decode gamma on the copy.\n * @returns `false` when a face target has no texture yet.\n */\nfunction blitFaces(\n device: GPUDevice,\n cube: GPUTexture,\n targets: readonly RenderTarget[],\n decodeGamma: boolean,\n): boolean {\n const pipelines = blitPipelines(device);\n const encoder = device.createCommandEncoder({ label: \"ignifx:reflection-probe-mips\" });\n for (let face = 0; face < targets.length; face += 1) {\n const target = targets[face];\n const source = target === undefined ? null : colorTextureOf(target);\n if (source === null) {\n return false;\n }\n draw(\n device,\n encoder,\n decodeGamma ? pipelines.decode : pipelines.copy,\n pipelines.sampler,\n source.createView(),\n cubeFace(cube, face, 0),\n );\n for (let mip = 1; mip < cube.mipLevelCount; mip += 1) {\n draw(\n device,\n encoder,\n pipelines.copy,\n pipelines.sampler,\n cubeFace(cube, face, mip - 1),\n cubeFace(cube, face, mip),\n );\n }\n }\n device.queue.submit([encoder.finish()]);\n return true;\n}\n\n/**\n * A 2D view of one face and mip of the cube.\n *\n * @param cube - The cube texture.\n * @param face - The layer.\n * @param mip - The mip level.\n * @returns The view.\n */\nfunction cubeFace(cube: GPUTexture, face: number, mip: number): GPUTextureView {\n return cube.createView({\n dimension: \"2d\",\n baseArrayLayer: face,\n arrayLayerCount: 1,\n baseMipLevel: mip,\n mipLevelCount: 1,\n });\n}\n\n/**\n * Encodes one full-screen blit.\n *\n * @param device - The device.\n * @param encoder - The encoder.\n * @param pipeline - The pipeline.\n * @param sampler - The linear sampler.\n * @param source - The view to read.\n * @param destination - The view to write.\n */\nfunction draw(\n device: GPUDevice,\n encoder: GPUCommandEncoder,\n pipeline: GPURenderPipeline,\n sampler: GPUSampler,\n source: GPUTextureView,\n destination: GPUTextureView,\n): void {\n const bindGroup = device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: source },\n { binding: 1, resource: sampler },\n ],\n });\n const pass = encoder.beginRenderPass({\n colorAttachments: [\n { view: destination, loadOp: \"clear\", storeOp: \"store\", clearValue: { r: 0, g: 0, b: 0, a: 1 } },\n ],\n });\n pass.setPipeline(pipeline);\n pass.setBindGroup(0, bindGroup);\n pass.draw(3);\n pass.end();\n}\n\n/**\n * The device's blit pipelines.\n *\n * @param device - The device.\n * @returns The pipelines, created on first use.\n */\nfunction blitPipelines(device: GPUDevice): BlitPipelines {\n pipelineCache ??= new WeakMap();\n const cached = pipelineCache.get(device);\n if (cached !== undefined) {\n return cached;\n }\n const module = device.createShaderModule({ label: \"ignifx:reflection-probe-blit\", code: BLIT_WGSL });\n const pipeline = (entryPoint: string): GPURenderPipeline =>\n device.createRenderPipeline({\n label: `ignifx:reflection-probe-${entryPoint}`,\n layout: \"auto\",\n vertex: { module, entryPoint: \"vs\" },\n fragment: { module, entryPoint, targets: [{ format: PROBE_FORMAT }] },\n primitive: { topology: \"triangle-list\" },\n });\n const created: BlitPipelines = {\n copy: pipeline(\"copy\"),\n decode: pipeline(\"decode\"),\n sampler: device.createSampler({ magFilter: \"linear\", minFilter: \"linear\" }),\n };\n pipelineCache.set(device, created);\n return created;\n}\n\n/**\n * What a material reflects: a probe's environment, where it sits, and its projection box.\n *\n * @internal\n */\nexport interface LiteProbeBinding {\n /** The probe's environment. */\n readonly environment: EnvironmentTextures;\n /** The capture position. */\n readonly position: readonly [number, number, number];\n /** The full size of the projection box, or `null` for none. */\n readonly box: readonly [number, number, number] | null;\n}\n\n/**\n * Calls `visit` for every mesh whose material is a lit, non-skybox PBR material.\n *\n * @param scene - The scene.\n * @param visit - Receives the material and the mesh's world position.\n *\n * @internal\n */\nexport function forEachReflectiveMesh(\n scene: SceneContext,\n visit: (material: PbrMaterialProps, x: number, y: number, z: number) => void,\n): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const mesh = meshes[index];\n const material = mesh?.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 (mesh === undefined || material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n if (getPbrUnlit(material) !== undefined || isPbrSkybox(material)) {\n continue;\n }\n const world = mesh.worldMatrix;\n visit(material, world[12] ?? 0, world[13] ?? 0, world[14] ?? 0);\n }\n}\n\n/**\n * Points a PBR material at a probe, or back at the scene environment, and rebuilds it.\n *\n * @param scene - The registered scene, or `null` to leave the rebuild to Lite (its device-loss\n * recovery rebuilds every material).\n * @param material - The material.\n * @param binding - The probe, or `null` for the scene environment.\n * @returns The rebuild in flight, if Lite runs it asynchronously; Lite reports its failure itself.\n *\n * @internal\n */\nexport function assignReflectionProbe(\n scene: SceneContext | null,\n material: PbrMaterialProps,\n binding: LiteProbeBinding | null,\n): Promise<void> | undefined {\n if (binding === null) {\n clearPbrLocalEnvironment(material);\n } else if (binding.box === null) {\n setPbrEnvironment(material, binding.environment);\n } else {\n setPbrLocalEnvironment(material, binding.environment, {\n shape: \"box\",\n capturePosition: binding.position,\n projectionPosition: binding.position,\n projectionSize: binding.box,\n });\n }\n if (scene === null) {\n return undefined;\n }\n // Since 1.34 a PBR rebuild in a built scene finishes asynchronously (`../material.ts`).\n const pending = rebuildMaterial(scene, material);\n return pending instanceof Promise ? pending : undefined;\n}\n","import { toEntityHandle } from \"../../handles/handle.js\";\nimport {\n assignReflectionProbe,\n createLiteReflectionProbe,\n enableReflectionProbes,\n forEachReflectiveMesh,\n} from \"../../lite/gpu/reflection-probe.js\";\nimport {\n resolveReflectionProbeRefreshMode,\n resolveReflectionProbeSize,\n selectReflectionProbe,\n} from \"../reflection-probe.js\";\nimport { EDITOR_ONLY_METADATA_KEY } from \"../render-texture.js\";\nimport type { LiteProbeBinding, LiteReflectionProbe } from \"../../lite/gpu/reflection-probe.js\";\nimport type { NodeTag } from \"../../lite/node.js\";\nimport type { LiteEngine, LiteScene } from \"../../lite/scene.js\";\nimport type { Vec3Like } from \"../../math/types.js\";\nimport type { World } from \"../../world/world.js\";\nimport type { ReflectionProbe, ReflectionProbeCandidate } from \"../reflection-probe.js\";\nimport type { RenderingQualityPreset } from \"../rendering-settings.js\";\n\n/**\n * The render layer's half of reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`,\n * step B1): which probe captures when, and which probe each PBR material reflects. Loaded with\n * `../../lite/gpu/reflection-probe.ts` as one chunk, only once a world has a `ReflectionProbe`.\n */\n\n/**\n * How many consecutive frames one capture request renders. Lite compiles material pipelines\n * asynchronously, so a single frame right after start or after a scene change can miss meshes that\n * are still compiling; repeating it for a few frames catches them.\n */\nconst CAPTURE_FRAMES = 8;\n\n/** One component's GPU probe and what it last captured with. */\ninterface ProbeState {\n /** The GPU probe. */\n lite: LiteReflectionProbe;\n /** How many more frames capture before the probe rests. */\n framesToCapture: number;\n /** The binding materials use, rebuilt when the probe moves or its box changes. */\n binding: LiteProbeBinding | null;\n}\n\n/** A material `forEachReflectiveMesh` hands out. */\ntype ReflectiveMaterial = Parameters<typeof assignReflectionProbe>[1];\n\n/** A candidate with the binding it stands for. */\ninterface BoundCandidate extends ReflectionProbeCandidate {\n /** The binding. */\n readonly binding: LiteProbeBinding;\n}\n\n/**\n * Every reflection probe of a renderer.\n *\n * @internal\n */\nexport interface ReflectionProbeRuntime {\n /**\n * Captures what is due and points each lit PBR material at its probe. Called once per frame from\n * the `PreRender` system.\n *\n * @param world - The world the probes live in.\n * @param probes - Every `ReflectionProbe` in the world.\n * @param isHdr - Whether `rendering.hdr` is on.\n * @param tier - The `rendering.quality` preset, which caps the size and `everyFrame`; `null` for\n * `\"custom\"`.\n * @param hasEnvironment - Whether the scene has an environment map. Without one every probe is\n * freed and nothing else runs, not even the mesh walk.\n */\n update(\n world: World,\n probes: readonly ReflectionProbe[],\n isHdr: boolean,\n tier: RenderingQualityPreset | null,\n hasEnvironment: boolean,\n ): void;\n /**\n * Drops every GPU probe after the device was lost, before Lite's recovery rebuilds the materials,\n * so no material still names a cube of the lost device. The probes capture again on the first\n * frame after recovery.\n */\n handleDeviceLost(): void;\n /** Frees every probe and hands every material back to the scene environment. */\n dispose(): void;\n}\n\n/**\n * Creates the runtime once Lite's local-cubemap shader path is loaded.\n *\n * @param engine - The engine.\n * @param scene - The registered render scene.\n * @param warn - Where a probe's warning goes: a message with an `{entity}` slot, and the name.\n * @returns The runtime.\n *\n * @internal\n */\nexport async function createReflectionProbeRuntime(\n engine: LiteEngine,\n scene: LiteScene,\n warn: (message: string, entityName: string) => void,\n): Promise<ReflectionProbeRuntime> {\n await enableReflectionProbes();\n const states = new Map<ReflectionProbe, ProbeState>();\n const assigned = new Map<ReflectiveMaterial, LiteProbeBinding | null>();\n const seen = new Set<object>();\n const candidates: BoundCandidate[] = [];\n /** The cubes released this frame, freed once the materials that reflected them are rebuilt. */\n const retiring: { lite: LiteReflectionProbe; environment: LiteProbeBinding[\"environment\"] | null }[] = [];\n /** Material rebuilds started this frame. */\n const rebuilds: Promise<void>[] = [];\n /**\n * Probes whose capture was freed while they stayed (resized, environment gone, device lost); they\n * capture again whatever their mode.\n */\n const recapture = new WeakSet<ReflectionProbe>();\n let hasWarnedEveryFrame = false;\n\n const assign = (material: ReflectiveMaterial, binding: LiteProbeBinding | null): void => {\n const pending = assignReflectionProbe(scene, material, binding);\n if (pending !== undefined) {\n rebuilds.push(pending);\n }\n };\n\n const release = (probe: ReflectionProbe, state: ProbeState): void => {\n if (state.lite.environment !== null) {\n recapture.add(probe);\n }\n retiring.push({ lite: state.lite, environment: state.lite.environment });\n states.delete(probe);\n };\n\n /**\n * Frees the cubes released this frame. A material that reflected one and was not reassigned this\n * frame (its mesh left the scene) goes back to the scene environment first, so it never names a\n * destroyed cube; the cubes then wait for every rebuild started this frame.\n */\n const retire = (): void => {\n if (retiring.length > 0) {\n for (const [material, binding] of assigned) {\n if (binding !== null && retiring.some((entry) => entry.environment === binding.environment)) {\n assigned.set(material, null);\n assign(material, null);\n }\n }\n const settled = Promise.allSettled(rebuilds);\n for (const entry of retiring) {\n entry.lite.dispose(settled);\n }\n retiring.length = 0;\n }\n rebuilds.length = 0;\n };\n\n /** Hands every material back to the scene environment, without walking the scene. */\n const clearMaterials = (): void => {\n for (const [material, binding] of assigned) {\n if (binding !== null) {\n assign(material, null);\n }\n }\n assigned.clear();\n };\n\n const assignMaterials = (): void => {\n if (candidates.length === 0) {\n clearMaterials();\n return;\n }\n seen.clear();\n forEachReflectiveMesh(scene, (material, x, y, z) => {\n if (seen.has(material)) {\n return;\n }\n seen.add(material);\n const index = selectReflectionProbe(x, y, z, candidates);\n const binding = candidates[index]?.binding ?? null;\n const current = assigned.get(material);\n if (current === binding || (current === undefined && binding === null)) {\n return;\n }\n assigned.set(material, binding);\n assign(material, binding);\n });\n };\n\n return {\n update(\n world: World,\n probes: readonly ReflectionProbe[],\n isHdr: boolean,\n tier: RenderingQualityPreset | null,\n hasEnvironment: boolean,\n ): void {\n candidates.length = 0;\n if (!hasEnvironment) {\n // A probe borrows the environment's lighting tables, so without one it holds no GPU memory\n // and costs no frame work; refresh requests stay on the component until it can capture.\n for (const [probe, state] of states) {\n release(probe, state);\n }\n clearMaterials();\n retire();\n return;\n }\n const maxSize = tier?.reflectionProbeMaxSize;\n const allowsEveryFrame = tier?.reflectionProbeEveryFrame ?? true;\n for (const [probe, state] of states) {\n if (!probes.includes(probe) || resolveReflectionProbeSize(probe.size, maxSize) !== state.lite.size) {\n release(probe, state);\n }\n }\n for (const probe of probes) {\n const wantsRefresh = probe.consumeRefreshRequest();\n if (!probe.isEnabledInHierarchy) {\n continue;\n }\n const mode = resolveReflectionProbeRefreshMode(probe.refreshMode, allowsEveryFrame);\n if (mode !== probe.refreshMode && !hasWarnedEveryFrame) {\n hasWarnedEveryFrame = true;\n warn(\n '{entity} asks its ReflectionProbe for refreshMode \"everyFrame\", which only the \"high\" ' +\n 'rendering.quality tier allows, so it captures as \"once\" (when ready and on refresh()).',\n probe.entity.name,\n );\n }\n let state = states.get(probe);\n if (state === undefined) {\n // Nothing is allocated until a capture is due: an `onDemand` probe waits for refresh().\n if (mode === \"onDemand\" && !wantsRefresh && !recapture.has(probe)) {\n continue;\n }\n recapture.delete(probe);\n state = {\n lite: createLiteReflectionProbe(\n engine,\n scene,\n resolveReflectionProbeSize(probe.size, maxSize),\n EDITOR_ONLY_METADATA_KEY,\n cullingFilter(world, probe),\n ),\n framesToCapture: CAPTURE_FRAMES,\n binding: null,\n };\n states.set(probe, state);\n }\n state.lite.resolve(!isHdr);\n const matrix = probe.entity.transform.worldMatrix;\n const x = matrix[12] ?? 0;\n const y = matrix[13] ?? 0;\n const z = matrix[14] ?? 0;\n if (wantsRefresh) {\n state.framesToCapture = CAPTURE_FRAMES;\n }\n if (\n (state.framesToCapture > 0 || mode === \"everyFrame\") &&\n state.lite.capture(x, y, z, probe.near, probe.far)\n ) {\n state.framesToCapture = Math.max(0, state.framesToCapture - 1);\n }\n const environment = state.lite.environment;\n if (environment === null) {\n continue;\n }\n const box = probe.boxProjection;\n const binding = bindingFor(state.binding, environment, x, y, z, box);\n state.binding = binding;\n candidates.push({ x, y, z, box, binding });\n }\n assignMaterials();\n retire();\n },\n handleDeviceLost(): void {\n // Lite's recovery rebuilds every material against the new device, so only the bindings are\n // cleared here; the cubes belong to the lost device and go at once.\n for (const [material, binding] of assigned) {\n if (binding !== null) {\n void assignReflectionProbe(null, material, null);\n }\n }\n assigned.clear();\n for (const [probe, state] of states) {\n if (state.lite.environment !== null) {\n recapture.add(probe);\n }\n state.lite.dispose();\n }\n states.clear();\n retiring.length = 0;\n rebuilds.length = 0;\n },\n dispose(): void {\n for (const [probe, state] of states) {\n release(probe, state);\n }\n clearMaterials();\n const settled = Promise.allSettled(rebuilds);\n for (const entry of retiring) {\n entry.lite.dispose(settled);\n }\n retiring.length = 0;\n rebuilds.length = 0;\n },\n };\n}\n\n/**\n * Builds the mesh filter of a probe's capture: with a non-empty `cullingMask`, only meshes whose\n * entity is on one of its layers.\n *\n * @param world - The world, for the handle and layer tables.\n * @param probe - The probe; its mask is read on every call, so edits apply to the next capture.\n * @returns The filter.\n */\nfunction cullingFilter(world: World, probe: ReflectionProbe): (tag: NodeTag | null) => boolean {\n return (tag): boolean => {\n const mask = probe.cullingMask;\n if (mask.length === 0) {\n return true;\n }\n const entity = tag === null ? null : world.getEntityByHandle(toEntityHandle(tag.entity));\n if (entity === null) {\n return false;\n }\n for (const name of mask) {\n if (world.layers.indexOf(name) === entity.layer) {\n return true;\n }\n }\n return false;\n };\n}\n\n/**\n * The binding a probe's materials use: the previous one while nothing it holds changed, so a still\n * probe never rebuilds its materials.\n *\n * @param previous - The binding last used, or `null`.\n * @param environment - The probe's environment.\n * @param x - The probe's world X.\n * @param y - The probe's world Y.\n * @param z - The probe's world Z.\n * @param box - The projection box size, or `null`.\n * @returns The binding.\n */\nfunction bindingFor(\n previous: LiteProbeBinding | null,\n environment: LiteProbeBinding[\"environment\"],\n x: number,\n y: number,\n z: number,\n box: Vec3Like | null,\n): LiteProbeBinding {\n if (\n previous !== null &&\n previous.environment === environment &&\n previous.position[0] === x &&\n previous.position[1] === y &&\n previous.position[2] === z &&\n (box === null\n ? previous.box === null\n : previous.box !== null && previous.box[0] === box.x && previous.box[1] === box.y && previous.box[2] === box.z)\n ) {\n return previous;\n }\n return { environment, position: [x, y, z], box: box === null ? null : [box.x, box.y, box.z] };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,eAAiC;;AAGvC,MAAM,uBAAyC;;AAG/C,MAAM,QAAgF;CACpF;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC;CACjB;EAAC;EAAI;EAAG;EAAG;EAAG;EAAG;CAAC;CAClB;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAE;CAClB;EAAC;EAAG;EAAI;EAAG;EAAG;EAAG;CAAC;CAClB;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC;CACjB;EAAC;EAAG;EAAG;EAAI;EAAG;EAAG;CAAC;AACpB;;AAGA,MAAM,YAAuB;;;;;;;;;;;;;;;;;;;;AA4B7B,IAAI,gBAA0D;;;;;;;;AAgD9D,SAAgB,yBAAwC;CACtD,OAAO,sBAAsB;AAC/B;;;;;;;;;;;;;AAcA,SAAgB,0BACd,QACA,OACA,MACA,YACA,QACqB;CACrB,MAAM,UAA0B,CAAC;CACjC,MAAM,QAAsB,CAAC;CAC7B,MAAM,UAA8B,CAAC;CACrC,MAAM,SAAiB,CAAC;CACxB,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,SAAS,mBAAmB;GAChC,KAAK;GACL,QAAQ;GACR,SAAS;GACT,SAAS;GACT,MAAM;IAAE,OAAO;IAAM,QAAQ;GAAK;EACpC,CAAC;EACD,MAAM,SAAS,uBACb;GAAE,GAAG;GAAG,GAAG;GAAG,GAAG;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I,OAAO,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,IAE/G,OAAO;CAET,OAAO;EAAE;EAAa,UAAU;GAAC;GAAG;GAAG;EAAC;EAAG,KAAK,QAAQ,OAAO,OAAO;GAAC,IAAI;GAAG,IAAI;GAAG,IAAI;EAAC;CAAE;AAC9F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as readSceneEnvironment } from "./environment-
|
|
1
|
+
import { i as readSceneEnvironment } from "./environment-Bf4aphSb.js";
|
|
2
2
|
import { createShaderMaterial, createTexture2DArrayFromPixels, createTexture2DFromPixels, enableShaderMaterialUniformCaching, setShaderMatrix, setShaderStorageBuffer, setShaderTexture, setShaderUniform } from "@babylonjs/lite";
|
|
3
3
|
//#region src/lite/gpu/shader-material.ts
|
|
4
4
|
/** The RGBA bytes of each 1x1 fallback texture. */
|
|
@@ -302,4 +302,4 @@ function readSceneAmbient(scene, out) {
|
|
|
302
302
|
//#endregion
|
|
303
303
|
export { createFallbackTexture, createShaderMaterialFromOptions, enableShaderUniformCaching, linearOutputFragment, readSceneAmbient, resolveFallbackTexture, writeShaderMatrix, writeShaderStorageBuffer, writeShaderTexture, writeShaderUniform };
|
|
304
304
|
|
|
305
|
-
//# sourceMappingURL=shader-material-
|
|
305
|
+
//# sourceMappingURL=shader-material-CJIDFvSb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-material-CaAkv5nT.js","names":[],"sources":["../src/lite/gpu/shader-material.ts"],"sourcesContent":["import {\n createShaderMaterial,\n createTexture2DArrayFromPixels,\n createTexture2DFromPixels,\n enableShaderMaterialUniformCaching,\n setShaderMatrix,\n setShaderStorageBuffer,\n setShaderTexture,\n setShaderUniform,\n} from \"@babylonjs/lite\";\nimport { readSceneEnvironment } from \"./environment.js\";\nimport type {\n EngineContext,\n SceneContext,\n ShaderAttributeName,\n ShaderMaterial,\n ShaderSystemUniformName,\n ShaderUniformType,\n StorageBuffer,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The custom-WGSL half of the Babylon Lite adapter: `createShaderMaterial`, the `setShader*`\n * setters, and the 1x1 fallback textures a declared sampler falls back to\n * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1, ADR-0024). Everything here is `@internal`.\n *\n * Lite exports one barrel, so a static import of `createShaderMaterial` anywhere in the reachable\n * graph pulls `lib/material/shader/**` into every entry chunk. This module is therefore reached with\n * `await import(...)` from `../../render/shader-support.ts`, and only loading a `.wgsl` triggers the\n * fetch. `./storage-buffer.ts` is a separate file for the same reason: `StorageBufferAsset`\n * allocates synchronously, so it cannot wait for this chunk.\n *\n * Two Lite facts it is written around:\n *\n * - Nothing may be left unbound: `createShaderBindGroup` throws (errors 309 and 310) when a declared\n * sampler has no texture or a declared storage buffer has no buffer, which is what\n * {@link createFallbackTexture} exists for.\n * - There is no front-face culling; `ShaderMaterialOptions` carries only `backFaceCulling`\n * (`lib/material/shader/shader-pipeline.js`), so the pragma parser refuses `cull front`.\n */\n\n/**\n * A Babylon Lite custom WGSL material, 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 LiteShaderMaterial = ShaderMaterial;\n\n/** The RGBA bytes of each 1x1 fallback texture. */\nconst FALLBACK_PIXELS: Readonly<Record<string, readonly [number, number, number, number]>> = Object.freeze({\n white: [255, 255, 255, 255],\n black: [0, 0, 0, 255],\n transparent: [0, 0, 0, 0],\n});\n\n/**\n * One declared uniform in the form Babylon Lite's factory takes: either the name of a system\n * uniform it fills in itself, or a custom declaration with its initial value.\n *\n * @internal\n */\nexport type ShaderUniformEntry =\n | ShaderSystemUniformName\n | {\n /** The WGSL identifier. */\n readonly name: string;\n /** The WGSL type. */\n readonly type: ShaderUniformType;\n /** The initial value, **linear** for a colour. */\n readonly defaultValue: number | readonly number[];\n };\n\n/**\n * One declared sampler in the form Babylon Lite's factory takes.\n *\n * @internal\n */\nexport interface ShaderSamplerEntry {\n /** The WGSL identifier; Lite generates `<name>Sampler` beside it. */\n readonly name: string;\n /** `\"2d-array\"` for a `texture_2d_array<f32>` binding. */\n readonly viewDimension: \"2d\" | \"2d-array\";\n}\n\n/**\n * One declared storage buffer in the form Babylon Lite's factory takes.\n *\n * @internal\n */\nexport interface ShaderStorageEntry {\n /** The WGSL identifier. */\n readonly name: string;\n /** The WGSL variable type, verbatim. */\n readonly type: string;\n}\n\n/**\n * Everything Babylon Lite's `createShaderMaterial` needs, in ignifx's own vocabulary so that the\n * mapping from a `ShaderDeclaration` can be built and asserted without a device or a Lite import\n * (`src/render/shader-material.ts`).\n *\n * @remarks\n * A `null` blend state or depth comparison means \"leave Babylon Lite's own default in place\", so\n * this module never restates a Lite default that could change.\n *\n * @internal\n */\nexport interface ShaderMaterialBuildOptions {\n /** The material's name, used in pipeline and shader-module labels. */\n readonly name: string;\n /** The WGSL source, handed to Lite as both the vertex and the fragment source. */\n readonly source: string;\n /**\n * Whether the scene renders through `rendering.hdr`, where the fragment's display colour is\n * decoded to linear before it is written (see {@link linearOutputFragment}). Absent means `false`.\n */\n readonly linearOutput?: boolean;\n /** The vertex attributes the vertex stage reads; `position` is mandatory. */\n readonly attributes: readonly ShaderAttributeName[];\n /** The system and custom uniforms, in binding-declaration order. */\n readonly uniforms: readonly ShaderUniformEntry[];\n /** The samplers. */\n readonly samplers: readonly ShaderSamplerEntry[];\n /** The read-only storage buffers. */\n readonly storageBuffers: readonly ShaderStorageEntry[];\n /** The WGSL `const` declarations, resolved from the file's defaults and the material's overrides. */\n readonly defines: Readonly<Record<string, boolean | number>>;\n /** Whether the thin-instance RGBA stream is bound and injected into `VertexInput`. */\n readonly useThinInstanceColors: boolean;\n /** Whether the surface is alpha-blended. */\n readonly needAlphaBlending: boolean;\n /** Which of Lite's two blend equations to use when no explicit state is given. */\n readonly blendMode: \"alpha\" | \"additive\";\n /** An explicit colour-target blend state, which replaces the derived one; `null` to derive it. */\n readonly blend: GPUBlendState | null;\n /** Whether the surface samples the opaque scene colour behind it. */\n readonly transmissive: boolean;\n /** Whether back faces are culled. */\n readonly backFaceCulling: boolean;\n /** Whether the draw writes depth. */\n readonly depthWrite: boolean;\n /** The depth comparison, or `null` for Lite's own reverse-Z default. */\n readonly depthCompare: GPUCompareFunction | null;\n}\n\n/**\n * Builds a Babylon Lite custom WGSL material.\n *\n * @remarks\n * Validation is eager and compilation is lazy, so this runs under the null engine; the pipeline is\n * compiled the first time a mesh wearing the material is drawn.\n *\n * @param options - The sources and the declared attribute, uniform, sampler, and storage layout.\n * @returns The material.\n * @throws Error from Babylon Lite when the declaration is not one it can build.\n *\n * @internal\n */\nexport function createShaderMaterialFromOptions(options: ShaderMaterialBuildOptions): ShaderMaterial {\n const premultiplied = options.blend?.color.srcFactor === \"one\";\n return createShaderMaterial({\n name: options.name,\n vertexSource: options.source,\n fragmentSource:\n options.linearOutput === true ? linearOutputFragment(options.source, premultiplied) : options.source,\n attributes: options.attributes,\n uniforms: options.uniforms,\n samplers: options.samplers,\n storageBuffers: options.storageBuffers,\n defines: options.defines,\n useThinInstanceColors: options.useThinInstanceColors,\n needAlphaBlending: options.needAlphaBlending,\n blendMode: options.blendMode,\n ...(options.blend === null ? {} : { blend: options.blend }),\n transmissive: options.transmissive,\n backFaceCulling: options.backFaceCulling,\n depthWrite: options.depthWrite,\n ...(options.depthCompare === null ? {} : { depthCompare: options.depthCompare }),\n });\n}\n\n/** The name a wrapped `mainFragment` is renamed to. */\nconst WRAPPED_FRAGMENT = \"ignifxDisplayFragment\";\n\n/**\n * Wraps a custom shader's `mainFragment` so that, under `rendering.hdr`, it writes linear colour\n * (`docs/plan/2026-11-gi-phase-1-execution-plan.md`, step G3).\n *\n * @remarks\n * A custom shader writes the colour that is displayed: with HDR off it lands on the swapchain as\n * is. With HDR on it lands in the linear scene target and the output pass encodes it, so the\n * wrapper decodes it first with the exact inverse of that encode (`pow(c, 2.2)`). The user's entry\n * point loses its `@fragment` and is renamed; a new `mainFragment` with the same parameters calls\n * it. A premultiplied colour is divided by alpha before the decode and multiplied after it, so the\n * blend still sees premultiplied colour. Only a single `@location(0) vec4<f32>` return can be\n * wrapped; anything else (a struct of outputs) is returned unchanged.\n *\n * @param source - The `.wgsl` file.\n * @param premultiplied - Whether the material blends premultiplied colour.\n * @returns The fragment source.\n *\n * @internal\n */\nexport function linearOutputFragment(source: string, premultiplied: boolean): string {\n const entry = /@fragment\\s+fn\\s+mainFragment\\s*\\(/u.exec(source);\n if (entry === null) {\n return source;\n }\n const open = entry.index + entry[0].length - 1;\n const close = matchingParen(source, open);\n if (close < 0) {\n return source;\n }\n const after = source.slice(close + 1);\n const result = /^\\s*->\\s*@location\\(\\s*0\\s*\\)\\s*vec4\\s*<\\s*f32\\s*>\\s*\\{/u.exec(after);\n if (result === null) {\n return source;\n }\n const parameters = source.slice(open + 1, close);\n const names = parameterNames(parameters);\n const decode = premultiplied\n ? \"select(pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2)),pow(max(c.rgb/c.a,vec3<f32>(0.0)),vec3<f32>(2.2))*c.a,c.a>0.0)\"\n : \"pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2))\";\n return [\n // A plain function may not carry the entry point's `@location(0)` on its return type.\n `${source.slice(0, entry.index)}fn ${WRAPPED_FRAGMENT}(${stripAttributes(parameters)})->vec4<f32>{${after.slice(result[0].length)}`,\n `@fragment fn mainFragment(${parameters})->@location(0) vec4<f32>{`,\n `let c=${WRAPPED_FRAGMENT}(${names.join(\",\")});`,\n `return vec4<f32>(${decode},c.a);`,\n \"}\",\n ].join(\"\\n\");\n}\n\n/**\n * Finds the parenthesis that closes the one at `open`.\n *\n * @param text - The source.\n * @param open - The index of a `(`.\n * @returns The index of its `)`, or `-1`.\n */\nfunction matchingParen(text: string, open: number): number {\n let depth = 0;\n for (let index = open; index < text.length; index += 1) {\n const char = text[index];\n if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n return -1;\n}\n\n/**\n * Removes WGSL attributes (`@builtin(position)`, `@location(0)`, `@interpolate(flat)`) from a\n * parameter list, which a plain function's parameters may not carry.\n *\n * @param parameters - The parameter list.\n * @returns The list without attributes.\n */\nfunction stripAttributes(parameters: string): string {\n return parameters.replaceAll(/@\\w+\\s*(\\([^)]*\\))?\\s*/gu, \"\");\n}\n\n/**\n * The parameter names of a WGSL parameter list, attributes stripped.\n *\n * @param parameters - The text between an entry point's parentheses.\n * @returns The names, in order.\n */\nfunction parameterNames(parameters: string): string[] {\n const names: string[] = [];\n let depth = 0;\n let start = 0;\n const take = (end: number): void => {\n const piece = stripAttributes(parameters.slice(start, end)).trim();\n const colon = piece.indexOf(\":\");\n if (colon > 0) {\n names.push(piece.slice(0, colon).trim());\n }\n };\n for (let index = 0; index < parameters.length; index += 1) {\n const char = parameters[index];\n if (char === \"(\" || char === \"<\") {\n depth += 1;\n } else if (char === \")\" || char === \">\") {\n depth -= 1;\n } else if (char === \",\" && depth === 0) {\n take(index);\n start = index + 1;\n }\n }\n take(parameters.length);\n return names;\n}\n\n/**\n * Writes a declared scalar, vector, or matrix uniform.\n *\n * @remarks\n * Lite compares the incoming numbers with the ones it holds and bumps the material's uniform\n * version only when one changed, so calling this every frame with an unchanged value costs a few\n * comparisons and no upload (`lib/material/shader/shader-material.js`, `setUniformValue`).\n *\n * @param material - The material to write to.\n * @param name - The declared uniform name.\n * @param value - The value; its length must match the declared type.\n * @throws Error from Babylon Lite when the name is not declared or the length is wrong.\n *\n * @internal\n */\nexport function writeShaderUniform(\n material: ShaderMaterial,\n name: string,\n value: number | readonly number[] | Float32Array,\n): void {\n setShaderUniform(material, name, value);\n}\n\n/**\n * Writes a declared `mat4x4<f32>` uniform from sixteen column-major floats.\n *\n * @param material - The material to write to.\n * @param name - The declared uniform name.\n * @param value - The matrix.\n *\n * @internal\n */\nexport function writeShaderMatrix(material: ShaderMaterial, name: string, value: Float32Array): void {\n setShaderMatrix(material, name, value);\n}\n\n/**\n * Binds or clears a declared sampler's texture.\n *\n * @param material - The material to write to.\n * @param name - The declared sampler name.\n * @param texture - The texture, or `null` to unbind. An unbound sampler makes the material\n * unbuildable, so ignifx always binds a fallback instead.\n *\n * @internal\n */\nexport function writeShaderTexture(material: ShaderMaterial, name: string, texture: Texture2D | null): void {\n setShaderTexture(material, name, texture);\n}\n\n/**\n * Binds or clears a declared storage buffer.\n *\n * @param material - The material to write to.\n * @param name - The declared storage buffer name.\n * @param buffer - The buffer, or `null` to unbind.\n *\n * @internal\n */\nexport function writeShaderStorageBuffer(material: ShaderMaterial, name: string, buffer: StorageBuffer | null): void {\n setShaderStorageBuffer(material, name, buffer);\n}\n\n/**\n * The 1x1 texture a declared-but-unbound sampler is filled with, created on first use and shared for\n * the life of the app.\n *\n * @param engine - The engine that owns the texture.\n * @param cache - The app's fallback textures, keyed by kind; a miss is created and stored.\n * @param fallback - `\"white\"`, `\"black\"`, or `\"transparent\"`; `null` means white.\n * @param array - `true` for a one-layer `texture_2d_array<f32>`.\n * @returns The texture.\n *\n * @internal\n */\nexport function resolveFallbackTexture(\n engine: EngineContext,\n cache: Map<string, Texture2D>,\n fallback: string | null,\n array: boolean,\n): Texture2D {\n const kind = fallback ?? \"white\";\n const key = array ? `${kind}:array` : kind;\n const cached = cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n const created = createFallbackTexture(engine, kind, array);\n cache.set(key, created);\n return created;\n}\n\n/**\n * Creates the 1x1 texture a declared-but-unbound sampler is filled with.\n *\n * @remarks\n * Babylon Lite refuses to build a bind group for a sampler with nothing bound (error 309), so a\n * material whose file declares `// @ignifx texture noise` and whose `.material.json` binds nothing\n * would be undrawable. One 1x1 texture per fallback kind per app is what makes it legal, which is\n * also Godot's `hint_default_white` behaviour.\n *\n * @param engine - The engine that owns the texture.\n * @param fallback - `\"white\"`, `\"black\"`, or `\"transparent\"`.\n * @param array - `true` for a one-layer `texture_2d_array<f32>`, which is what a sampler declared\n * `array` binds.\n * @returns The texture.\n *\n * @internal\n */\nexport function createFallbackTexture(engine: EngineContext, fallback: string, array: boolean): Texture2D {\n const rgba = FALLBACK_PIXELS[fallback] ?? FALLBACK_PIXELS[\"white\"];\n const pixels = Uint8Array.from(rgba ?? [255, 255, 255, 255]);\n return array\n ? createTexture2DArrayFromPixels(engine, pixels, 1, 1, 1, { mipMaps: false })\n : createTexture2DFromPixels(engine, pixels, 1, 1, {});\n}\n\n/**\n * Turns on Babylon Lite's cached uniform serialization plans for shader materials.\n *\n * @remarks\n * Process-global and idempotent: it installs two writer functions that keep a `WeakMap` of layout\n * plans per material and rewrite only the custom uniform slots whose value changed\n * (`lib/material/shader/enable-shader-material-uniform-caching.js`). That is exactly the shape of\n * ignifx's per-frame `time` upload, so the adapter enables it as it loads rather than making every\n * project remember to.\n *\n * @internal\n */\nexport function enableShaderUniformCaching(): void {\n enableShaderMaterialUniformCaching();\n}\n\n/**\n * Reads the installed environment's ambient irradiance — the `L00` band of its diffuse spherical\n * harmonics — into `out`.\n *\n * @remarks\n * `EnvironmentTextures.sphericalHarmonics` is declared: 36 floats in a stride-4 layout beginning\n * `[L00.rgb, 0, …]` (`index.d.ts`), the same block Babylon Lite writes into the scene uniform buffer\n * as `scene.vSphericalL00` and friends (`lib/scene/scene-ubo-extras.js`, `writeEnvUbo`). So the\n * value ignifx uploads as `ambientColor` is exactly what a shader could read for itself as\n * `scene.vSphericalL00.rgb`, which is the documented alternative for a shader that would rather not\n * declare the uniform. Reaching the slot goes through `./environment.ts`, which is the one place\n * ignifx touches the undeclared `scene._envTextures` field\n * (`docs/architecture/07-rendering.md` §2.5, §8).\n *\n * @param scene - The render scene.\n * @param out - Receives the three linear channels; left untouched when nothing is installed.\n * @returns `true` when an environment supplied harmonics.\n *\n * @internal\n */\nexport function readSceneAmbient(scene: SceneContext, out: Float32Array): boolean {\n const harmonics = readSceneEnvironment(scene)?.sphericalHarmonics;\n if (harmonics === undefined || harmonics.length < 3) {\n return false;\n }\n out[0] = harmonics[0] ?? 0;\n out[1] = harmonics[1] ?? 0;\n out[2] = harmonics[2] ?? 0;\n return true;\n}\n\n/**\n * The subset of this module `src/render/shader-material.ts` reaches through its dynamic `import()`,\n * named so the memo has a type that does not have to be written as `typeof import(…)` (which the\n * `consistent-type-imports` rule forbids).\n *\n * @remarks\n * Assigning the imported module namespace to this type is what checks the two against each other,\n * so a signature that drifts is a compile error rather than a runtime surprise.\n *\n * @internal\n */\nexport interface ShaderMaterialAdapter {\n /** {@link createShaderMaterialFromOptions}. */\n readonly createShaderMaterialFromOptions: (options: ShaderMaterialBuildOptions) => ShaderMaterial;\n /** {@link writeShaderUniform}. */\n readonly writeShaderUniform: (\n material: ShaderMaterial,\n name: string,\n value: number | readonly number[] | Float32Array,\n ) => void;\n /** {@link writeShaderMatrix}. */\n readonly writeShaderMatrix: (material: ShaderMaterial, name: string, value: Float32Array) => void;\n /** {@link writeShaderTexture}. */\n readonly writeShaderTexture: (material: ShaderMaterial, name: string, texture: Texture2D | null) => void;\n /** {@link writeShaderStorageBuffer}. */\n readonly writeShaderStorageBuffer: (material: ShaderMaterial, name: string, buffer: StorageBuffer | null) => void;\n /** {@link resolveFallbackTexture}. */\n readonly resolveFallbackTexture: (\n engine: EngineContext,\n cache: Map<string, Texture2D>,\n fallback: string | null,\n array: boolean,\n ) => Texture2D;\n /** {@link enableShaderUniformCaching}. */\n readonly enableShaderUniformCaching: () => void;\n /** {@link readSceneAmbient}. */\n readonly readSceneAmbient: (scene: SceneContext, out: Float32Array) => boolean;\n}\n"],"mappings":";;;;AAsDA,MAAM,kBAAuF,OAAO,OAAO;CACzG,OAAO;EAAC;EAAK;EAAK;EAAK;CAAG;CAC1B,OAAO;EAAC;EAAG;EAAG;EAAG;CAAG;CACpB,aAAa;EAAC;EAAG;EAAG;EAAG;CAAC;AAC1B,CAAC;;;;;;;;;;;;;;AAyGD,SAAgB,gCAAgC,SAAqD;CACnG,MAAM,gBAAgB,QAAQ,OAAO,M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;;AAYA,SAAgB,mBAAmB,UAA0B,MAAc,SAAiC;CAC1G,iBAAiB,UAAU,MAAM,OAAO;AAC1C;;;;;;;;;;AAWA,SAAgB,yBAAyB,UAA0B,MAAc,QAAoC;CACnH,uBAAuB,UAAU,MAAM,MAAM;AAC/C;;;;;;;;;;;;;AAcA,SAAgB,uBACd,QACA,OACA,UACA,OACW;CACX,MAAM,OAAO,YAAY;CACzB,MAAM,MAAM,QAAQ,GAAG,KAAK,UAAU;CACtC,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,GACb,OAAO;CAET,MAAM,UAAU,sBAAsB,QAAQ,MAAM,KAAK;CACzD,MAAM,IAAI,KAAK,OAAO;CACtB,OAAO;AACT;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,sBAAsB,QAAuB,UAAkB,OAA2B;CACxG,MAAM,OAAO,gBAAgB,aAAa,gBAAgB;CAC1D,MAAM,SAAS,WAAW,KAAK,QAAQ;EAAC;EAAK;EAAK;EAAK;CAAG,CAAC;CAC3D,OAAO,QACH,+BAA+B,QAAQ,QAAQ,GAAG,GAAG,GAAG,EAAE,SAAS,MAAM,CAAC,IAC1E,0BAA0B,QAAQ,QAAQ,GAAG,GAAG,CAAC,CAAC;AACxD;;;;;;;;;;;;;AAcA,SAAgB,6BAAmC;CACjD,mCAAmC;AACrC;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,iBAAiB,OAAqB,KAA4B;CAChF,MAAM,YAAY,qBAAqB,KAAK,CAAC,EAAE;CAC/C,IAAI,cAAc,KAAA,KAAa,UAAU,SAAS,GAChD,OAAO;CAET,IAAI,KAAK,UAAU,MAAM;CACzB,IAAI,KAAK,UAAU,MAAM;CACzB,IAAI,KAAK,UAAU,MAAM;CACzB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"shader-material-CJIDFvSb.js","names":[],"sources":["../src/lite/gpu/shader-material.ts"],"sourcesContent":["import {\n createShaderMaterial,\n createTexture2DArrayFromPixels,\n createTexture2DFromPixels,\n enableShaderMaterialUniformCaching,\n setShaderMatrix,\n setShaderStorageBuffer,\n setShaderTexture,\n setShaderUniform,\n} from \"@babylonjs/lite\";\nimport { readSceneEnvironment } from \"./environment.js\";\nimport type {\n EngineContext,\n SceneContext,\n ShaderAttributeName,\n ShaderMaterial,\n ShaderSystemUniformName,\n ShaderUniformType,\n StorageBuffer,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The custom-WGSL half of the Babylon Lite adapter: `createShaderMaterial`, the `setShader*`\n * setters, and the 1x1 fallback textures a declared sampler falls back to\n * (`docs/plan/2026-09-terrain-particles-shaders.md` §3.1, ADR-0024). Everything here is `@internal`.\n *\n * Lite exports one barrel, so a static import of `createShaderMaterial` anywhere in the reachable\n * graph pulls `lib/material/shader/**` into every entry chunk. This module is therefore reached with\n * `await import(...)` from `../../render/shader-support.ts`, and only loading a `.wgsl` triggers the\n * fetch. `./storage-buffer.ts` is a separate file for the same reason: `StorageBufferAsset`\n * allocates synchronously, so it cannot wait for this chunk.\n *\n * Two Lite facts it is written around:\n *\n * - Nothing may be left unbound: `createShaderBindGroup` throws (errors 309 and 310) when a declared\n * sampler has no texture or a declared storage buffer has no buffer, which is what\n * {@link createFallbackTexture} exists for.\n * - There is no front-face culling; `ShaderMaterialOptions` carries only `backFaceCulling`\n * (`lib/material/shader/shader-pipeline.js`), so the pragma parser refuses `cull front`.\n */\n\n/**\n * A Babylon Lite custom WGSL material, 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 LiteShaderMaterial = ShaderMaterial;\n\n/** The RGBA bytes of each 1x1 fallback texture. */\nconst FALLBACK_PIXELS: Readonly<Record<string, readonly [number, number, number, number]>> = Object.freeze({\n white: [255, 255, 255, 255],\n black: [0, 0, 0, 255],\n transparent: [0, 0, 0, 0],\n});\n\n/**\n * One declared uniform in the form Babylon Lite's factory takes: either the name of a system\n * uniform it fills in itself, or a custom declaration with its initial value.\n *\n * @internal\n */\nexport type ShaderUniformEntry =\n | ShaderSystemUniformName\n | {\n /** The WGSL identifier. */\n readonly name: string;\n /** The WGSL type. */\n readonly type: ShaderUniformType;\n /** The initial value, **linear** for a colour. */\n readonly defaultValue: number | readonly number[];\n };\n\n/**\n * One declared sampler in the form Babylon Lite's factory takes.\n *\n * @internal\n */\nexport interface ShaderSamplerEntry {\n /** The WGSL identifier; Lite generates `<name>Sampler` beside it. */\n readonly name: string;\n /** `\"2d-array\"` for a `texture_2d_array<f32>` binding. */\n readonly viewDimension: \"2d\" | \"2d-array\";\n}\n\n/**\n * One declared storage buffer in the form Babylon Lite's factory takes.\n *\n * @internal\n */\nexport interface ShaderStorageEntry {\n /** The WGSL identifier. */\n readonly name: string;\n /** The WGSL variable type, verbatim. */\n readonly type: string;\n}\n\n/**\n * Everything Babylon Lite's `createShaderMaterial` needs, in ignifx's own vocabulary so that the\n * mapping from a `ShaderDeclaration` can be built and asserted without a device or a Lite import\n * (`src/render/shader-material.ts`).\n *\n * @remarks\n * A `null` blend state or depth comparison means \"leave Babylon Lite's own default in place\", so\n * this module never restates a Lite default that could change.\n *\n * @internal\n */\nexport interface ShaderMaterialBuildOptions {\n /** The material's name, used in pipeline and shader-module labels. */\n readonly name: string;\n /** The WGSL source, handed to Lite as both the vertex and the fragment source. */\n readonly source: string;\n /**\n * Whether the scene renders through `rendering.hdr`, where the fragment's display colour is\n * decoded to linear before it is written (see {@link linearOutputFragment}). Absent means `false`.\n */\n readonly linearOutput?: boolean;\n /** The vertex attributes the vertex stage reads; `position` is mandatory. */\n readonly attributes: readonly ShaderAttributeName[];\n /** The system and custom uniforms, in binding-declaration order. */\n readonly uniforms: readonly ShaderUniformEntry[];\n /** The samplers. */\n readonly samplers: readonly ShaderSamplerEntry[];\n /** The read-only storage buffers. */\n readonly storageBuffers: readonly ShaderStorageEntry[];\n /** The WGSL `const` declarations, resolved from the file's defaults and the material's overrides. */\n readonly defines: Readonly<Record<string, boolean | number>>;\n /** Whether the thin-instance RGBA stream is bound and injected into `VertexInput`. */\n readonly useThinInstanceColors: boolean;\n /** Whether the surface is alpha-blended. */\n readonly needAlphaBlending: boolean;\n /** Which of Lite's two blend equations to use when no explicit state is given. */\n readonly blendMode: \"alpha\" | \"additive\";\n /** An explicit colour-target blend state, which replaces the derived one; `null` to derive it. */\n readonly blend: GPUBlendState | null;\n /** Whether the surface samples the opaque scene colour behind it. */\n readonly transmissive: boolean;\n /** Whether back faces are culled. */\n readonly backFaceCulling: boolean;\n /** Whether the draw writes depth. */\n readonly depthWrite: boolean;\n /** The depth comparison, or `null` for Lite's own reverse-Z default. */\n readonly depthCompare: GPUCompareFunction | null;\n}\n\n/**\n * Builds a Babylon Lite custom WGSL material.\n *\n * @remarks\n * Validation is eager and compilation is lazy, so this runs under the null engine; the pipeline is\n * compiled the first time a mesh wearing the material is drawn.\n *\n * @param options - The sources and the declared attribute, uniform, sampler, and storage layout.\n * @returns The material.\n * @throws Error from Babylon Lite when the declaration is not one it can build.\n *\n * @internal\n */\nexport function createShaderMaterialFromOptions(options: ShaderMaterialBuildOptions): ShaderMaterial {\n const premultiplied = options.blend?.color.srcFactor === \"one\";\n return createShaderMaterial({\n name: options.name,\n vertexSource: options.source,\n fragmentSource:\n options.linearOutput === true ? linearOutputFragment(options.source, premultiplied) : options.source,\n attributes: options.attributes,\n uniforms: options.uniforms,\n samplers: options.samplers,\n storageBuffers: options.storageBuffers,\n defines: options.defines,\n useThinInstanceColors: options.useThinInstanceColors,\n needAlphaBlending: options.needAlphaBlending,\n blendMode: options.blendMode,\n ...(options.blend === null ? {} : { blend: options.blend }),\n transmissive: options.transmissive,\n backFaceCulling: options.backFaceCulling,\n depthWrite: options.depthWrite,\n ...(options.depthCompare === null ? {} : { depthCompare: options.depthCompare }),\n });\n}\n\n/** The name a wrapped `mainFragment` is renamed to. */\nconst WRAPPED_FRAGMENT = \"ignifxDisplayFragment\";\n\n/**\n * Wraps a custom shader's `mainFragment` so that, under `rendering.hdr`, it writes linear colour\n * (`docs/plan/2026-11-gi-phase-1-execution-plan.md`, step G3).\n *\n * @remarks\n * A custom shader writes the colour that is displayed: with HDR off it lands on the swapchain as\n * is. With HDR on it lands in the linear scene target and the output pass encodes it, so the\n * wrapper decodes it first with the exact inverse of that encode (`pow(c, 2.2)`). The user's entry\n * point loses its `@fragment` and is renamed; a new `mainFragment` with the same parameters calls\n * it. A premultiplied colour is divided by alpha before the decode and multiplied after it, so the\n * blend still sees premultiplied colour. Only a single `@location(0) vec4<f32>` return can be\n * wrapped; anything else (a struct of outputs) is returned unchanged.\n *\n * @param source - The `.wgsl` file.\n * @param premultiplied - Whether the material blends premultiplied colour.\n * @returns The fragment source.\n *\n * @internal\n */\nexport function linearOutputFragment(source: string, premultiplied: boolean): string {\n const entry = /@fragment\\s+fn\\s+mainFragment\\s*\\(/u.exec(source);\n if (entry === null) {\n return source;\n }\n const open = entry.index + entry[0].length - 1;\n const close = matchingParen(source, open);\n if (close < 0) {\n return source;\n }\n const after = source.slice(close + 1);\n const result = /^\\s*->\\s*@location\\(\\s*0\\s*\\)\\s*vec4\\s*<\\s*f32\\s*>\\s*\\{/u.exec(after);\n if (result === null) {\n return source;\n }\n const parameters = source.slice(open + 1, close);\n const names = parameterNames(parameters);\n const decode = premultiplied\n ? \"select(pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2)),pow(max(c.rgb/c.a,vec3<f32>(0.0)),vec3<f32>(2.2))*c.a,c.a>0.0)\"\n : \"pow(max(c.rgb,vec3<f32>(0.0)),vec3<f32>(2.2))\";\n return [\n // A plain function may not carry the entry point's `@location(0)` on its return type.\n `${source.slice(0, entry.index)}fn ${WRAPPED_FRAGMENT}(${stripAttributes(parameters)})->vec4<f32>{${after.slice(result[0].length)}`,\n `@fragment fn mainFragment(${parameters})->@location(0) vec4<f32>{`,\n `let c=${WRAPPED_FRAGMENT}(${names.join(\",\")});`,\n `return vec4<f32>(${decode},c.a);`,\n \"}\",\n ].join(\"\\n\");\n}\n\n/**\n * Finds the parenthesis that closes the one at `open`.\n *\n * @param text - The source.\n * @param open - The index of a `(`.\n * @returns The index of its `)`, or `-1`.\n */\nfunction matchingParen(text: string, open: number): number {\n let depth = 0;\n for (let index = open; index < text.length; index += 1) {\n const char = text[index];\n if (char === \"(\") {\n depth += 1;\n } else if (char === \")\") {\n depth -= 1;\n if (depth === 0) {\n return index;\n }\n }\n }\n return -1;\n}\n\n/**\n * Removes WGSL attributes (`@builtin(position)`, `@location(0)`, `@interpolate(flat)`) from a\n * parameter list, which a plain function's parameters may not carry.\n *\n * @param parameters - The parameter list.\n * @returns The list without attributes.\n */\nfunction stripAttributes(parameters: string): string {\n return parameters.replaceAll(/@\\w+\\s*(\\([^)]*\\))?\\s*/gu, \"\");\n}\n\n/**\n * The parameter names of a WGSL parameter list, attributes stripped.\n *\n * @param parameters - The text between an entry point's parentheses.\n * @returns The names, in order.\n */\nfunction parameterNames(parameters: string): string[] {\n const names: string[] = [];\n let depth = 0;\n let start = 0;\n const take = (end: number): void => {\n const piece = stripAttributes(parameters.slice(start, end)).trim();\n const colon = piece.indexOf(\":\");\n if (colon > 0) {\n names.push(piece.slice(0, colon).trim());\n }\n };\n for (let index = 0; index < parameters.length; index += 1) {\n const char = parameters[index];\n if (char === \"(\" || char === \"<\") {\n depth += 1;\n } else if (char === \")\" || char === \">\") {\n depth -= 1;\n } else if (char === \",\" && depth === 0) {\n take(index);\n start = index + 1;\n }\n }\n take(parameters.length);\n return names;\n}\n\n/**\n * Writes a declared scalar, vector, or matrix uniform.\n *\n * @remarks\n * Lite compares the incoming numbers with the ones it holds and bumps the material's uniform\n * version only when one changed, so calling this every frame with an unchanged value costs a few\n * comparisons and no upload (`lib/material/shader/shader-material.js`, `setUniformValue`).\n *\n * @param material - The material to write to.\n * @param name - The declared uniform name.\n * @param value - The value; its length must match the declared type.\n * @throws Error from Babylon Lite when the name is not declared or the length is wrong.\n *\n * @internal\n */\nexport function writeShaderUniform(\n material: ShaderMaterial,\n name: string,\n value: number | readonly number[] | Float32Array,\n): void {\n setShaderUniform(material, name, value);\n}\n\n/**\n * Writes a declared `mat4x4<f32>` uniform from sixteen column-major floats.\n *\n * @param material - The material to write to.\n * @param name - The declared uniform name.\n * @param value - The matrix.\n *\n * @internal\n */\nexport function writeShaderMatrix(material: ShaderMaterial, name: string, value: Float32Array): void {\n setShaderMatrix(material, name, value);\n}\n\n/**\n * Binds or clears a declared sampler's texture.\n *\n * @param material - The material to write to.\n * @param name - The declared sampler name.\n * @param texture - The texture, or `null` to unbind. An unbound sampler makes the material\n * unbuildable, so ignifx always binds a fallback instead.\n *\n * @internal\n */\nexport function writeShaderTexture(material: ShaderMaterial, name: string, texture: Texture2D | null): void {\n setShaderTexture(material, name, texture);\n}\n\n/**\n * Binds or clears a declared storage buffer.\n *\n * @param material - The material to write to.\n * @param name - The declared storage buffer name.\n * @param buffer - The buffer, or `null` to unbind.\n *\n * @internal\n */\nexport function writeShaderStorageBuffer(material: ShaderMaterial, name: string, buffer: StorageBuffer | null): void {\n setShaderStorageBuffer(material, name, buffer);\n}\n\n/**\n * The 1x1 texture a declared-but-unbound sampler is filled with, created on first use and shared for\n * the life of the app.\n *\n * @param engine - The engine that owns the texture.\n * @param cache - The app's fallback textures, keyed by kind; a miss is created and stored.\n * @param fallback - `\"white\"`, `\"black\"`, or `\"transparent\"`; `null` means white.\n * @param array - `true` for a one-layer `texture_2d_array<f32>`.\n * @returns The texture.\n *\n * @internal\n */\nexport function resolveFallbackTexture(\n engine: EngineContext,\n cache: Map<string, Texture2D>,\n fallback: string | null,\n array: boolean,\n): Texture2D {\n const kind = fallback ?? \"white\";\n const key = array ? `${kind}:array` : kind;\n const cached = cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n const created = createFallbackTexture(engine, kind, array);\n cache.set(key, created);\n return created;\n}\n\n/**\n * Creates the 1x1 texture a declared-but-unbound sampler is filled with.\n *\n * @remarks\n * Babylon Lite refuses to build a bind group for a sampler with nothing bound (error 309), so a\n * material whose file declares `// @ignifx texture noise` and whose `.material.json` binds nothing\n * would be undrawable. One 1x1 texture per fallback kind per app is what makes it legal, which is\n * also Godot's `hint_default_white` behaviour.\n *\n * @param engine - The engine that owns the texture.\n * @param fallback - `\"white\"`, `\"black\"`, or `\"transparent\"`.\n * @param array - `true` for a one-layer `texture_2d_array<f32>`, which is what a sampler declared\n * `array` binds.\n * @returns The texture.\n *\n * @internal\n */\nexport function createFallbackTexture(engine: EngineContext, fallback: string, array: boolean): Texture2D {\n const rgba = FALLBACK_PIXELS[fallback] ?? FALLBACK_PIXELS[\"white\"];\n const pixels = Uint8Array.from(rgba ?? [255, 255, 255, 255]);\n return array\n ? createTexture2DArrayFromPixels(engine, pixels, 1, 1, 1, { mipMaps: false })\n : createTexture2DFromPixels(engine, pixels, 1, 1, {});\n}\n\n/**\n * Turns on Babylon Lite's cached uniform serialization plans for shader materials.\n *\n * @remarks\n * Process-global and idempotent: it installs two writer functions that keep a `WeakMap` of layout\n * plans per material and rewrite only the custom uniform slots whose value changed\n * (`lib/material/shader/enable-shader-material-uniform-caching.js`). That is exactly the shape of\n * ignifx's per-frame `time` upload, so the adapter enables it as it loads rather than making every\n * project remember to.\n *\n * @internal\n */\nexport function enableShaderUniformCaching(): void {\n enableShaderMaterialUniformCaching();\n}\n\n/**\n * Reads the installed environment's ambient irradiance — the `L00` band of its diffuse spherical\n * harmonics — into `out`.\n *\n * @remarks\n * `EnvironmentTextures.sphericalHarmonics` is declared: 36 floats in a stride-4 layout beginning\n * `[L00.rgb, 0, …]` (`index.d.ts`), the same block Babylon Lite writes into the scene uniform buffer\n * as `scene.vSphericalL00` and friends (`lib/scene/scene-ubo-extras.js`, `writeEnvUbo`). So the\n * value ignifx uploads as `ambientColor` is exactly what a shader could read for itself as\n * `scene.vSphericalL00.rgb`, which is the documented alternative for a shader that would rather not\n * declare the uniform. Reaching the slot goes through `./environment.ts`, which is the one place\n * ignifx touches the undeclared `scene._envTextures` field\n * (`docs/architecture/07-rendering.md` §2.5, §8).\n *\n * @param scene - The render scene.\n * @param out - Receives the three linear channels; left untouched when nothing is installed.\n * @returns `true` when an environment supplied harmonics.\n *\n * @internal\n */\nexport function readSceneAmbient(scene: SceneContext, out: Float32Array): boolean {\n const harmonics = readSceneEnvironment(scene)?.sphericalHarmonics;\n if (harmonics === undefined || harmonics.length < 3) {\n return false;\n }\n out[0] = harmonics[0] ?? 0;\n out[1] = harmonics[1] ?? 0;\n out[2] = harmonics[2] ?? 0;\n return true;\n}\n\n/**\n * The subset of this module `src/render/shader-material.ts` reaches through its dynamic `import()`,\n * named so the memo has a type that does not have to be written as `typeof import(…)` (which the\n * `consistent-type-imports` rule forbids).\n *\n * @remarks\n * Assigning the imported module namespace to this type is what checks the two against each other,\n * so a signature that drifts is a compile error rather than a runtime surprise.\n *\n * @internal\n */\nexport interface ShaderMaterialAdapter {\n /** {@link createShaderMaterialFromOptions}. */\n readonly createShaderMaterialFromOptions: (options: ShaderMaterialBuildOptions) => ShaderMaterial;\n /** {@link writeShaderUniform}. */\n readonly writeShaderUniform: (\n material: ShaderMaterial,\n name: string,\n value: number | readonly number[] | Float32Array,\n ) => void;\n /** {@link writeShaderMatrix}. */\n readonly writeShaderMatrix: (material: ShaderMaterial, name: string, value: Float32Array) => void;\n /** {@link writeShaderTexture}. */\n readonly writeShaderTexture: (material: ShaderMaterial, name: string, texture: Texture2D | null) => void;\n /** {@link writeShaderStorageBuffer}. */\n readonly writeShaderStorageBuffer: (material: ShaderMaterial, name: string, buffer: StorageBuffer | null) => void;\n /** {@link resolveFallbackTexture}. */\n readonly resolveFallbackTexture: (\n engine: EngineContext,\n cache: Map<string, Texture2D>,\n fallback: string | null,\n array: boolean,\n ) => Texture2D;\n /** {@link enableShaderUniformCaching}. */\n readonly enableShaderUniformCaching: () => void;\n /** {@link readSceneAmbient}. */\n readonly readSceneAmbient: (scene: SceneContext, out: Float32Array) => boolean;\n}\n"],"mappings":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KAAa,UAAU,SAAS,GAChD,OAAO;CAET,IAAI,KAAK,UAAU,MAAM;CACzB,IAAI,KAAK,UAAU,MAAM;CACzB,IAAI,KAAK,UAAU,MAAM;CACzB,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-
|
|
3
|
-
import {
|
|
2
|
+
import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
|
|
3
|
+
import { I as setOwnJsonProperty } from "./prefab-overrides-DRP2DcnC.js";
|
|
4
4
|
import { t as Color } from "./color-DrR6GFTd.js";
|
|
5
5
|
import { r as isHdrScene } from "./render-path-D11i_7X8.js";
|
|
6
6
|
import { n as IGNIFX_UNIFORM_TYPES, r as LITE_SYSTEM_UNIFORM_NAMES, t as IGNIFX_UNIFORM_NAMES } from "./shader-declaration-5q__jycG.js";
|
|
@@ -163,7 +163,7 @@ let adapter = null;
|
|
|
163
163
|
*/
|
|
164
164
|
async function loadShaderMaterialAdapter() {
|
|
165
165
|
if (adapter !== null) return;
|
|
166
|
-
const loaded = await import("./shader-material-
|
|
166
|
+
const loaded = await import("./shader-material-CJIDFvSb.js");
|
|
167
167
|
loaded.enableShaderUniformCaching();
|
|
168
168
|
adapter = loaded;
|
|
169
169
|
}
|
|
@@ -1010,4 +1010,4 @@ function shapeMismatch(declaration, material, expected, actual) {
|
|
|
1010
1010
|
//#endregion
|
|
1011
1011
|
export { shader_material_exports as n, shaderMaterialsOf as t };
|
|
1012
1012
|
|
|
1013
|
-
//# sourceMappingURL=shader-material-
|
|
1013
|
+
//# sourceMappingURL=shader-material-CuwK9tWC.js.map
|