@ignifx/core 0.19.0 → 0.21.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 (45) hide show
  1. package/dist/{gtao-_nr0b6-E.js → gtao-Bpu5-0Ne.js} +2 -2
  2. package/dist/{gtao-_nr0b6-E.js.map → gtao-Bpu5-0Ne.js.map} +1 -1
  3. package/dist/{hdr-output-Dbv0lhFl.js → hdr-output-DBQwMphy.js} +2 -2
  4. package/dist/{hdr-output-Dbv0lhFl.js.map → hdr-output-DBQwMphy.js.map} +1 -1
  5. package/dist/index.d.ts +181 -21
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1616 -174
  8. package/dist/index.js.map +1 -1
  9. package/dist/{instanced-mesh-instance-BMhREEfx.js → instanced-mesh-instance-B-fXKSrY.js} +2 -2
  10. package/dist/{instanced-mesh-instance-BMhREEfx.js.map → instanced-mesh-instance-B-fXKSrY.js.map} +1 -1
  11. package/dist/{light-probes-DyLapYX9.js → light-probes-DDojYajw.js} +2 -2
  12. package/dist/{light-probes-DyLapYX9.js.map → light-probes-DDojYajw.js.map} +1 -1
  13. package/dist/lightmaps-BUUIIkt9.js +230 -0
  14. package/dist/lightmaps-BUUIIkt9.js.map +1 -0
  15. package/dist/{material-CGk5mAah.js → material-myMbl9mW.js} +37 -2
  16. package/dist/{material-CGk5mAah.js.map → material-myMbl9mW.js.map} +1 -1
  17. package/dist/{post-effect-CaiqDlhW.js → post-effect-Cu3Enpz7.js} +2 -2
  18. package/dist/{post-effect-CaiqDlhW.js.map → post-effect-Cu3Enpz7.js.map} +1 -1
  19. package/dist/{post-effect-compiler-jSvOVe0U.js → post-effect-compiler-cCq9lcHt.js} +2 -2
  20. package/dist/{post-effect-compiler-jSvOVe0U.js.map → post-effect-compiler-cCq9lcHt.js.map} +1 -1
  21. package/dist/{prefab-overrides-DRP2DcnC.js → prefab-overrides-C2GsgOQc.js} +24 -7
  22. package/dist/prefab-overrides-C2GsgOQc.js.map +1 -0
  23. package/dist/{prefab-overrides-CS8_cG66.d.ts → prefab-overrides-htDc_5Po.d.ts} +53 -12
  24. package/dist/prefab-overrides-htDc_5Po.d.ts.map +1 -0
  25. package/dist/prefab.d.ts +1 -1
  26. package/dist/prefab.js +1 -1
  27. package/dist/{reflection-probe-AS8d4uKv.js → reflection-probe-QkD1Fo_d.js} +79 -3
  28. package/dist/{reflection-probe-AS8d4uKv.js.map → reflection-probe-QkD1Fo_d.js.map} +1 -1
  29. package/dist/{reflection-probes-CUZcOjNW.js → reflection-probes-CAzSuqf8.js} +298 -21
  30. package/dist/reflection-probes-CAzSuqf8.js.map +1 -0
  31. package/dist/{shader-material-CuwK9tWC.js → shader-material-TM4f8eKA.js} +2 -2
  32. package/dist/{shader-material-CuwK9tWC.js.map → shader-material-TM4f8eKA.js.map} +1 -1
  33. package/dist/{ssgi-Dm-maZrc.js → ssgi-DSnhqotl.js} +2 -2
  34. package/dist/{ssgi-Dm-maZrc.js.map → ssgi-DSnhqotl.js.map} +1 -1
  35. package/dist/{surface-shader-DY9_aC9L.js → surface-shader-rpPpeosD.js} +4 -4
  36. package/dist/{surface-shader-DY9_aC9L.js.map → surface-shader-rpPpeosD.js.map} +1 -1
  37. package/dist/{vec3-Cc19wl4r.js → vec3-2C3LBZnt.js} +55 -3
  38. package/dist/vec3-2C3LBZnt.js.map +1 -0
  39. package/package.json +1 -1
  40. package/dist/lightmaps-LO6Ygtwe.js +0 -137
  41. package/dist/lightmaps-LO6Ygtwe.js.map +0 -1
  42. package/dist/prefab-overrides-CS8_cG66.d.ts.map +0 -1
  43. package/dist/prefab-overrides-DRP2DcnC.js.map +0 -1
  44. package/dist/reflection-probes-CUZcOjNW.js.map +0 -1
  45. package/dist/vec3-Cc19wl4r.js.map +0 -1
@@ -1,7 +1,7 @@
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";
1
+ import { J as toEntityHandle, a as resolveReflectionProbeSize, i as resolveReflectionProbeRefreshMode, o as selectReflectionProbe, r as reflectionProbeBlendLayout, s as EDITOR_ONLY_METADATA_KEY, z as readOwnerTag } from "./reflection-probe-QkD1Fo_d.js";
2
2
  import { i as readSceneEnvironment } from "./environment-Bf4aphSb.js";
3
3
  import { n as deviceOf, r as removeTask, t as colorTextureOf } from "./render-texture-UqRHRLQy.js";
4
- import { addTask, buildFrameGraphTask, clearPbrLocalEnvironment, createBankedFreeCamera, createRenderTarget, createRenderTask, enablePbrLocalCubemap, getFrameGraph, getPbrUnlit, isPbrMaterial, isPbrSkybox, rebuildMaterial, setPbrEnvironment, setPbrLocalEnvironment } from "@babylonjs/lite";
4
+ import { addTask, buildFrameGraphTask, clearPbrLocalEnvironment, createBankedFreeCamera, createPbrLocalEnvironmentProbeSet, createRenderTarget, createRenderTask, enablePbrLocalCubemap, getFrameGraph, getPbrUnlit, isPbrMaterial, isPbrSkybox, rebuildMaterial, setPbrEnvironment, setPbrLocalEnvironment, setPbrLocalEnvironmentProbeSet } from "@babylonjs/lite";
5
5
  //#region src/lite/gpu/reflection-probe.ts
6
6
  /**
7
7
  * Reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`, step B1). Its own chunk,
@@ -24,6 +24,15 @@ import { addTask, buildFrameGraphTask, clearPbrLocalEnvironment, createBankedFre
24
24
  * resolved first; it is called when the chunk loads.
25
25
  * - **Culling mask.** Render tasks have no mesh filter, so each face task's `execute` hides the meshes
26
26
  * the caller rejects and shows them again, as `./render-texture.ts` does for editor-only meshes.
27
+ * - **Blending (B1b).** `createPbrLocalEnvironmentProbeSet` (`index.d.ts` 3411) **copies** every
28
+ * probe's cube into one cube array when it is created (`lib/material/pbr/enable-pbr-local-cubemap.js`,
29
+ * `createProbeTexture`) and blends up to four candidates per voxel per fragment. It has no dispose:
30
+ * its buffers and texture are destroyed only when the scene is (`scene._disposables`), so a set
31
+ * replaced earlier is freed through its `_texture`, `_uniformBuffer` and `_gridBuffer` fields and
32
+ * its closure is taken off `scene._disposables`, all read from the pinned source
33
+ * ({@link releaseLiteProbeSet}). A fragment inside a probe's inner box takes
34
+ * that probe alone; between inner and outer boxes the candidates are weighted; outside every outer
35
+ * box the nearest probe by its normalised distance wins (`local-cubemap-fragment.js`).
27
36
  */
28
37
  /** The colour format of the faces and the cube. */
29
38
  const PROBE_FORMAT = "rgba16float";
@@ -384,6 +393,105 @@ function blitPipelines(device) {
384
393
  pipelineCache.set(device, created);
385
394
  return created;
386
395
  }
396
+ /** The three GPU resources of a Lite probe set, by the field names `enable-pbr-local-cubemap.js` uses. */
397
+ const PROBE_SET_RESOURCE_FIELDS = [
398
+ "_texture",
399
+ "_uniformBuffer",
400
+ "_gridBuffer"
401
+ ];
402
+ /**
403
+ * Frees what a Lite probe set holds: its three GPU resources, and the cleanup closure Lite pushed
404
+ * onto `scene._disposables`, which would otherwise keep the whole set (its 64 KiB uniform data and
405
+ * its grid) alive until the scene is disposed.
406
+ *
407
+ * @remarks
408
+ * Every field is checked before use: a Lite upgrade that renames one degrades to `warn` (a leak
409
+ * that is logged) and never throws. Destroying twice is harmless.
410
+ *
411
+ * @param set - The set, as Lite returned it.
412
+ * @param disposables - The scene's `_disposables` list, or anything else when it is not one.
413
+ * @param cleanup - The closure Lite pushed for this set, or `undefined` when it was not found.
414
+ * @param warn - Receives one message per missing field or list.
415
+ *
416
+ * @internal
417
+ */
418
+ function releaseLiteProbeSet(set, disposables, cleanup, warn) {
419
+ const record = typeof set === "object" && set !== null ? set : {};
420
+ for (const field of PROBE_SET_RESOURCE_FIELDS) {
421
+ const resource = record[field];
422
+ const destroy = typeof resource === "object" && resource !== null ? resource.destroy : void 0;
423
+ if (typeof destroy === "function") Reflect.apply(destroy, resource, []);
424
+ else warn(`a Babylon Lite probe set has no ${field} to destroy, so its GPU memory stays until the scene goes`);
425
+ }
426
+ if (!Array.isArray(disposables) || cleanup === void 0) {
427
+ warn("the Babylon Lite probe set's scene cleanup could not be found, so its CPU data stays until the scene goes");
428
+ return;
429
+ }
430
+ const index = disposables.indexOf(cleanup);
431
+ if (index >= 0) disposables.splice(index, 1);
432
+ }
433
+ /**
434
+ * The scene's `_disposables` list, which Lite's set pushes its cleanup onto.
435
+ *
436
+ * @param scene - The scene.
437
+ * @returns The list, or `undefined` when the scene has none (a Lite change).
438
+ */
439
+ function disposablesOf(scene) {
440
+ const list = scene._disposables;
441
+ return Array.isArray(list) ? list : void 0;
442
+ }
443
+ /**
444
+ * Builds a blended set from captured probes.
445
+ *
446
+ * @param engine - The engine, for the queue a disposal waits on.
447
+ * @param scene - The registered scene.
448
+ * @param volumes - The probes, at least two.
449
+ * @param minimum - The voxel grid's minimum corner.
450
+ * @param maximum - The voxel grid's maximum corner.
451
+ * @param cellSize - The voxel edge.
452
+ * @param warn - Where a disposal that cannot free everything reports it.
453
+ * @returns The set.
454
+ * @throws When Lite refuses it: more than four probes in a voxel, more probes than the uniform block
455
+ * holds, or cubes of different formats.
456
+ *
457
+ * @internal
458
+ */
459
+ function createLiteProbeSet(engine, scene, volumes, minimum, maximum, cellSize, warn) {
460
+ const probes = volumes.map((volume) => ({
461
+ shape: "box",
462
+ environment: volume.environment,
463
+ capturePosition: volume.position,
464
+ projectionPosition: volume.position,
465
+ influencePosition: volume.position,
466
+ projectionSize: volume.outer,
467
+ influenceInnerSize: volume.inner,
468
+ influenceOuterSize: volume.outer
469
+ }));
470
+ const disposables = disposablesOf(scene);
471
+ const before = disposables?.length ?? 0;
472
+ const set = createPbrLocalEnvironmentProbeSet(scene, {
473
+ probes,
474
+ voxelGrid: {
475
+ minimum,
476
+ maximum,
477
+ cellSize
478
+ }
479
+ });
480
+ const cleanup = disposables !== void 0 && disposables.length === before + 1 ? disposables[before] : void 0;
481
+ let isDisposed = false;
482
+ return {
483
+ set,
484
+ dispose(after) {
485
+ if (isDisposed) return;
486
+ isDisposed = true;
487
+ const release = () => {
488
+ releaseLiteProbeSet(set, disposables, cleanup, warn);
489
+ };
490
+ const device = deviceOf(engine);
491
+ Promise.resolve(after).catch(() => void 0).then(async () => device?.queue.onSubmittedWorkDone()).then(release, release);
492
+ }
493
+ };
494
+ }
387
495
  /**
388
496
  * Calls `visit` for every mesh whose material is a lit, non-skybox PBR material.
389
497
  *
@@ -409,13 +517,14 @@ function forEachReflectiveMesh(scene, visit) {
409
517
  * @param scene - The registered scene, or `null` to leave the rebuild to Lite (its device-loss
410
518
  * recovery rebuilds every material).
411
519
  * @param material - The material.
412
- * @param binding - The probe, or `null` for the scene environment.
520
+ * @param binding - The probe, a blended set, or `null` for the scene environment.
413
521
  * @returns The rebuild in flight, if Lite runs it asynchronously; Lite reports its failure itself.
414
522
  *
415
523
  * @internal
416
524
  */
417
525
  function assignReflectionProbe(scene, material, binding) {
418
526
  if (binding === null) clearPbrLocalEnvironment(material);
527
+ else if ("set" in binding) setPbrLocalEnvironmentProbeSet(material, binding.set);
419
528
  else if (binding.box === null) setPbrEnvironment(material, binding.environment);
420
529
  else setPbrLocalEnvironment(material, binding.environment, {
421
530
  shape: "box",
@@ -433,6 +542,16 @@ function assignReflectionProbe(scene, material, binding) {
433
542
  * The render layer's half of reflection probes (`docs/plan/2026-11-gi-phase-2-execution-plan.md`,
434
543
  * step B1): which probe captures when, and which probe each PBR material reflects. Loaded with
435
544
  * `../../lite/gpu/reflection-probe.ts` as one chunk, only once a world has a `ReflectionProbe`.
545
+ *
546
+ * Blending (B1b): when `reflectionProbeBlendLayout` says the frame's probes blend and every box probe
547
+ * has finished capturing (none `everyFrame`), one Lite probe set built from their cubes goes on every
548
+ * lit PBR material. The set copies the cubes, so it is rebuilt when a probe moves, recaptures,
549
+ * resizes its box or changes `blendDistance`, and the replaced set is freed once the material
550
+ * rebuilds that dropped it settled. While a box probe is still capturing, the last set stays (or,
551
+ * before the first, the nearest-probe choice applies); while one is being moved or edited (its
552
+ * binding or `blendDistance` changed within the last {@link BLEND_STILL_FRAMES} frames) the
553
+ * nearest-probe choice applies. A material whose nearest probe has no box keeps that probe. A set Lite refuses (more than four probes
554
+ * overlapping in a voxel, too many probes) logs once and the nearest-probe choice applies.
436
555
  */
437
556
  /**
438
557
  * How many consecutive frames one capture request renders. Lite compiles material pipelines
@@ -441,11 +560,18 @@ function assignReflectionProbe(scene, material, binding) {
441
560
  */
442
561
  const CAPTURE_FRAMES = 8;
443
562
  /**
563
+ * How many frames a blended probe's position, box and `blendDistance` must stay unchanged before a
564
+ * probe set is built with it (about 250 ms at 60 Hz). A set copies every cube and rebuilds every lit
565
+ * material, so a probe being moved, dragged or scrubbed falls back to the nearest-probe choice until
566
+ * it rests.
567
+ */
568
+ const BLEND_STILL_FRAMES = 15;
569
+ /**
444
570
  * Creates the runtime once Lite's local-cubemap shader path is loaded.
445
571
  *
446
572
  * @param engine - The engine.
447
573
  * @param scene - The registered render scene.
448
- * @param warn - Where a probe's warning goes: a message with an `{entity}` slot, and the name.
574
+ * @param warn - Where a probe's warning goes, with the entity's name already in the message.
449
575
  * @returns The runtime.
450
576
  *
451
577
  * @internal
@@ -454,24 +580,49 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
454
580
  await enableReflectionProbes();
455
581
  const states = /* @__PURE__ */ new Map();
456
582
  const assigned = /* @__PURE__ */ new Map();
583
+ /** The blended set on every lit material, or `null` for the nearest-probe choice. */
584
+ let blend = null;
585
+ /** The key of a set Lite refused, so it is not tried again every frame. */
586
+ let refusedKey = null;
587
+ let hasWarnedRefusal = false;
588
+ const warnedLeaks = /* @__PURE__ */ new Set();
589
+ const warnLeakOnce = (message) => {
590
+ if (!warnedLeaks.has(message)) {
591
+ warnedLeaks.add(message);
592
+ warn(`Reflection probe blending: ${message}.`);
593
+ }
594
+ };
595
+ /** Sets replaced this frame, freed with the retired cubes. */
596
+ const retiringSets = [];
457
597
  const seen = /* @__PURE__ */ new Set();
458
598
  const candidates = [];
459
599
  /** The cubes released this frame, freed once the materials that reflected them are rebuilt. */
460
600
  const retiring = [];
461
- /** Material rebuilds started this frame. */
462
- const rebuilds = [];
601
+ /**
602
+ * Material rebuilds still in flight, whichever frame started them: a rebuild started a frame ago
603
+ * may still draw with a cube retired now, so a retired cube waits for all of them.
604
+ */
605
+ const rebuilds = /* @__PURE__ */ new Set();
463
606
  /**
464
607
  * Probes whose capture was freed while they stayed (resized, environment gone, device lost); they
465
608
  * capture again whatever their mode.
466
609
  */
467
610
  const recapture = /* @__PURE__ */ new WeakSet();
468
611
  let hasWarnedEveryFrame = false;
612
+ /** Between a device loss and Lite's recovery, nothing on the GPU may be touched. */
613
+ let isDeviceLost = false;
469
614
  const assign = (material, binding) => {
470
615
  const pending = assignReflectionProbe(scene, material, binding);
471
- if (pending !== void 0) rebuilds.push(pending);
616
+ if (pending !== void 0) {
617
+ rebuilds.add(pending);
618
+ const forget = () => {
619
+ rebuilds.delete(pending);
620
+ };
621
+ pending.then(forget, forget);
622
+ }
472
623
  };
473
624
  const release = (probe, state) => {
474
- if (state.lite.environment !== null) recapture.add(probe);
625
+ if (state.lite.environment !== null || state.framesToCapture > 0) recapture.add(probe);
475
626
  retiring.push({
476
627
  lite: state.lite,
477
628
  environment: state.lite.environment
@@ -481,11 +632,11 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
481
632
  /**
482
633
  * Frees the cubes released this frame. A material that reflected one and was not reassigned this
483
634
  * 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.
635
+ * destroyed cube; the cubes then wait for every rebuild still in flight, from any frame.
485
636
  */
486
637
  const retire = () => {
487
638
  if (retiring.length > 0) {
488
- for (const [material, binding] of assigned) if (binding !== null && retiring.some((entry) => entry.environment === binding.environment)) {
639
+ for (const [material, binding] of assigned) if (binding !== null && !("set" in binding) && retiring.some((entry) => entry.environment === binding.environment)) {
489
640
  assigned.set(material, null);
490
641
  assign(material, null);
491
642
  }
@@ -493,7 +644,77 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
493
644
  for (const entry of retiring) entry.lite.dispose(settled);
494
645
  retiring.length = 0;
495
646
  }
496
- rebuilds.length = 0;
647
+ if (retiringSets.length > 0) {
648
+ for (const [material, binding] of assigned) if (binding !== null && "set" in binding && retiringSets.includes(binding)) {
649
+ assigned.set(material, null);
650
+ assign(material, null);
651
+ }
652
+ const settled = Promise.allSettled(rebuilds);
653
+ for (const set of retiringSets) set.dispose(settled);
654
+ retiringSets.length = 0;
655
+ }
656
+ };
657
+ /** Stops blending; the set goes once the materials that used it were rebuilt. */
658
+ const dropBlend = () => {
659
+ if (blend !== null) {
660
+ retiringSets.push(blend.lite);
661
+ blend = null;
662
+ }
663
+ };
664
+ /**
665
+ * Builds, keeps or drops the blended set for this frame's candidates.
666
+ *
667
+ * @param layout - The blend layout, or `null` when the probes do not blend.
668
+ */
669
+ const updateBlend = (layout) => {
670
+ if (layout === null) {
671
+ dropBlend();
672
+ refusedKey = null;
673
+ return;
674
+ }
675
+ let isCapturing = false;
676
+ let hasEveryFrame = false;
677
+ let isMoving = false;
678
+ for (const volume of layout.volumes) {
679
+ const candidate = candidates[volume.index];
680
+ isCapturing ||= candidate?.isCapturing === true;
681
+ hasEveryFrame ||= candidate?.isEveryFrame === true;
682
+ isMoving ||= candidate?.isMoving === true;
683
+ }
684
+ if (hasEveryFrame || isMoving) {
685
+ dropBlend();
686
+ return;
687
+ }
688
+ if (isCapturing) return;
689
+ const key = [];
690
+ const volumes = layout.volumes.map((volume) => {
691
+ const candidate = candidates[volume.index];
692
+ if (candidate !== void 0) key.push(candidate.binding, candidate.generation, candidate.blendDistance);
693
+ return {
694
+ environment: candidate?.binding.environment ?? null,
695
+ position: volume.position,
696
+ outer: volume.outer,
697
+ inner: volume.inner
698
+ };
699
+ });
700
+ if (sameKey(blend?.key ?? null, key) || sameKey(refusedKey, key)) return;
701
+ const ready = volumes.filter((volume) => volume.environment !== null);
702
+ try {
703
+ const created = createLiteProbeSet(engine, scene, ready, layout.minimum, layout.maximum, layout.cellSize, warnLeakOnce);
704
+ dropBlend();
705
+ blend = {
706
+ lite: created,
707
+ key
708
+ };
709
+ refusedKey = null;
710
+ } catch (error) {
711
+ dropBlend();
712
+ refusedKey = key;
713
+ if (!hasWarnedRefusal) {
714
+ hasWarnedRefusal = true;
715
+ warn(`The reflection probes cannot blend (${error instanceof Error ? error.message : String(error)}), so each material reflects its nearest probe. Lite blends at most four overlapping probes.`);
716
+ }
717
+ }
497
718
  };
498
719
  /** Hands every material back to the scene environment, without walking the scene. */
499
720
  const clearMaterials = () => {
@@ -506,11 +727,12 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
506
727
  return;
507
728
  }
508
729
  seen.clear();
730
+ const blended = blend?.lite ?? null;
509
731
  forEachReflectiveMesh(scene, (material, x, y, z) => {
510
732
  if (seen.has(material)) return;
511
733
  seen.add(material);
512
- const index = selectReflectionProbe(x, y, z, candidates);
513
- const binding = candidates[index]?.binding ?? null;
734
+ const chosen = candidates[selectReflectionProbe(x, y, z, candidates)];
735
+ const binding = blended !== null && chosen?.box !== null ? blended : chosen?.binding ?? null;
514
736
  const current = assigned.get(material);
515
737
  if (current === binding || current === void 0 && binding === null) return;
516
738
  assigned.set(material, binding);
@@ -519,9 +741,11 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
519
741
  };
520
742
  return {
521
743
  update(world, probes, isHdr, tier, hasEnvironment) {
744
+ if (isDeviceLost) return;
522
745
  candidates.length = 0;
523
746
  if (!hasEnvironment) {
524
747
  for (const [probe, state] of states) release(probe, state);
748
+ dropBlend();
525
749
  clearMaterials();
526
750
  retire();
527
751
  return;
@@ -535,7 +759,7 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
535
759
  const mode = resolveReflectionProbeRefreshMode(probe.refreshMode, allowsEveryFrame);
536
760
  if (mode !== probe.refreshMode && !hasWarnedEveryFrame) {
537
761
  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);
762
+ warn(`${JSON.stringify(probe.entity.name)} asks its ReflectionProbe for refreshMode "everyFrame", which only the "high" rendering.quality tier allows, so it captures as "once" (when ready and on refresh()).`);
539
763
  }
540
764
  let state = states.get(probe);
541
765
  if (state === void 0) {
@@ -544,7 +768,10 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
544
768
  state = {
545
769
  lite: createLiteReflectionProbe(engine, scene, resolveReflectionProbeSize(probe.size, maxSize), EDITOR_ONLY_METADATA_KEY, cullingFilter(world, probe)),
546
770
  framesToCapture: CAPTURE_FRAMES,
547
- binding: null
771
+ binding: null,
772
+ generation: 0,
773
+ blendDistance: probe.blendDistance,
774
+ stillFrames: 0
548
775
  };
549
776
  states.set(probe, state);
550
777
  }
@@ -554,45 +781,95 @@ async function createReflectionProbeRuntime(engine, scene, warn) {
554
781
  const y = matrix[13] ?? 0;
555
782
  const z = matrix[14] ?? 0;
556
783
  if (wantsRefresh) state.framesToCapture = CAPTURE_FRAMES;
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);
784
+ if ((state.framesToCapture > 0 || mode === "everyFrame") && state.lite.capture(x, y, z, probe.near, probe.far)) {
785
+ state.framesToCapture = Math.max(0, state.framesToCapture - 1);
786
+ state.generation += 1;
787
+ }
558
788
  const environment = state.lite.environment;
559
789
  if (environment === null) continue;
560
790
  const box = probe.boxProjection;
561
791
  const binding = bindingFor(state.binding, environment, x, y, z, box);
792
+ state.stillFrames = binding === state.binding && probe.blendDistance === state.blendDistance ? state.stillFrames + 1 : 0;
562
793
  state.binding = binding;
794
+ state.blendDistance = probe.blendDistance;
563
795
  candidates.push({
564
796
  x,
565
797
  y,
566
798
  z,
567
799
  box,
568
- binding
800
+ binding,
801
+ blendDistance: probe.blendDistance,
802
+ generation: state.generation,
803
+ isCapturing: state.framesToCapture > 0,
804
+ isEveryFrame: mode === "everyFrame",
805
+ isMoving: state.stillFrames < BLEND_STILL_FRAMES
569
806
  });
570
807
  }
808
+ updateBlend(mayBlend(candidates) ? reflectionProbeBlendLayout(candidates) : null);
571
809
  assignMaterials();
572
810
  retire();
573
811
  },
574
812
  handleDeviceLost() {
813
+ isDeviceLost = true;
814
+ blend?.lite.dispose();
815
+ blend = null;
816
+ refusedKey = null;
817
+ for (const set of retiringSets) set.dispose();
818
+ retiringSets.length = 0;
575
819
  for (const [material, binding] of assigned) if (binding !== null) assignReflectionProbe(null, material, null);
576
820
  assigned.clear();
577
821
  for (const [probe, state] of states) {
578
- if (state.lite.environment !== null) recapture.add(probe);
822
+ if (state.lite.environment !== null || state.framesToCapture > 0) recapture.add(probe);
579
823
  state.lite.dispose();
580
824
  }
581
825
  states.clear();
826
+ for (const entry of retiring) entry.lite.dispose();
582
827
  retiring.length = 0;
583
- rebuilds.length = 0;
828
+ rebuilds.clear();
829
+ },
830
+ handleDeviceRecovered() {
831
+ isDeviceLost = false;
584
832
  },
585
833
  dispose() {
586
834
  for (const [probe, state] of states) release(probe, state);
835
+ dropBlend();
587
836
  clearMaterials();
588
837
  const settled = Promise.allSettled(rebuilds);
589
838
  for (const entry of retiring) entry.lite.dispose(settled);
590
839
  retiring.length = 0;
591
- rebuilds.length = 0;
840
+ for (const set of retiringSets) set.dispose(settled);
841
+ retiringSets.length = 0;
842
+ rebuilds.clear();
592
843
  }
593
844
  };
594
845
  }
595
846
  /**
847
+ * Whether a frame's probes can blend at all, checked without allocating: two box probes, one with a
848
+ * `blendDistance`.
849
+ *
850
+ * @param candidates - The frame's candidates.
851
+ * @returns `true` when {@link reflectionProbeBlendLayout} is worth calling.
852
+ */
853
+ function mayBlend(candidates) {
854
+ let boxes = 0;
855
+ let blends = false;
856
+ for (const candidate of candidates) if (candidate.box !== null) {
857
+ boxes += 1;
858
+ blends ||= candidate.blendDistance > 0;
859
+ }
860
+ return boxes >= 2 && blends;
861
+ }
862
+ /**
863
+ * Whether two set keys are equal, element by element.
864
+ *
865
+ * @param a - A key, or `null`.
866
+ * @param b - Another key.
867
+ * @returns `true` when both have the same elements.
868
+ */
869
+ function sameKey(a, b) {
870
+ return a !== null && a.length === b.length && a.every((value, index) => value === b[index]);
871
+ }
872
+ /**
596
873
  * Builds the mesh filter of a probe's capture: with a non-empty `cullingMask`, only meshes whose
597
874
  * entity is on one of its layers.
598
875
  *
@@ -641,4 +918,4 @@ function bindingFor(previous, environment, x, y, z, box) {
641
918
  //#endregion
642
919
  export { createReflectionProbeRuntime };
643
920
 
644
- //# sourceMappingURL=reflection-probes-CUZcOjNW.js.map
921
+ //# sourceMappingURL=reflection-probes-CAzSuqf8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection-probes-CAzSuqf8.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 createPbrLocalEnvironmentProbeSet,\n createRenderTarget,\n createRenderTask,\n enablePbrLocalCubemap,\n getFrameGraph,\n getPbrUnlit,\n isPbrMaterial,\n isPbrSkybox,\n rebuildMaterial,\n setPbrEnvironment,\n setPbrLocalEnvironment,\n setPbrLocalEnvironmentProbeSet,\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 PbrLocalEnvironmentProbe,\n PbrLocalEnvironmentProbeSet,\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 * - **Blending (B1b).** `createPbrLocalEnvironmentProbeSet` (`index.d.ts` 3411) **copies** every\n * probe's cube into one cube array when it is created (`lib/material/pbr/enable-pbr-local-cubemap.js`,\n * `createProbeTexture`) and blends up to four candidates per voxel per fragment. It has no dispose:\n * its buffers and texture are destroyed only when the scene is (`scene._disposables`), so a set\n * replaced earlier is freed through its `_texture`, `_uniformBuffer` and `_gridBuffer` fields and\n * its closure is taken off `scene._disposables`, all read from the pinned source\n * ({@link releaseLiteProbeSet}). A fragment inside a probe's inner box takes\n * that probe alone; between inner and outer boxes the candidates are weighted; outside every outer\n * box the nearest probe by its normalised distance wins (`local-cubemap-fragment.js`).\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 * One probe of a blended set, as {@link createLiteProbeSet} takes it.\n *\n * @internal\n */\nexport interface LiteProbeSetVolume {\n /** The probe's environment, copied into the set. */\n readonly environment: EnvironmentTextures;\n /** The capture position, also the centre of both boxes. */\n readonly position: readonly [number, number, number];\n /** The full size of the projection and outer influence box. */\n readonly outer: readonly [number, number, number];\n /** The full size of the inner influence box. */\n readonly inner: readonly [number, number, number];\n}\n\n/**\n * A blended probe set and its release.\n *\n * @internal\n */\nexport interface LiteProbeSet {\n /** Lite's set. */\n readonly set: PbrLocalEnvironmentProbeSet;\n /**\n * Destroys the set's GPU resources once `after` settled and the queue drained. Idempotent.\n *\n * @param after - What must finish first, such as the rebuilds of the materials that used it;\n * omitted to wait for the queue only.\n */\n dispose(after?: PromiseLike<unknown>): void;\n}\n\n/** The three GPU resources of a Lite probe set, by the field names `enable-pbr-local-cubemap.js` uses. */\nconst PROBE_SET_RESOURCE_FIELDS = [\"_texture\", \"_uniformBuffer\", \"_gridBuffer\"] as const;\n\n/**\n * Frees what a Lite probe set holds: its three GPU resources, and the cleanup closure Lite pushed\n * onto `scene._disposables`, which would otherwise keep the whole set (its 64 KiB uniform data and\n * its grid) alive until the scene is disposed.\n *\n * @remarks\n * Every field is checked before use: a Lite upgrade that renames one degrades to `warn` (a leak\n * that is logged) and never throws. Destroying twice is harmless.\n *\n * @param set - The set, as Lite returned it.\n * @param disposables - The scene's `_disposables` list, or anything else when it is not one.\n * @param cleanup - The closure Lite pushed for this set, or `undefined` when it was not found.\n * @param warn - Receives one message per missing field or list.\n *\n * @internal\n */\nexport function releaseLiteProbeSet(\n set: unknown,\n disposables: unknown,\n cleanup: unknown,\n warn: (message: string) => void,\n): void {\n // Boundary narrowing of Lite's undeclared fields (coding standards §5.2).\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const record = typeof set === \"object\" && set !== null ? (set as Record<string, unknown>) : {};\n for (const field of PROBE_SET_RESOURCE_FIELDS) {\n const resource = record[field];\n const destroy =\n typeof resource === \"object\" && resource !== null ? (resource as { destroy?: unknown }).destroy : undefined;\n if (typeof destroy === \"function\") {\n Reflect.apply(destroy, resource, []);\n } else {\n warn(`a Babylon Lite probe set has no ${field} to destroy, so its GPU memory stays until the scene goes`);\n }\n }\n if (!Array.isArray(disposables) || cleanup === undefined) {\n warn(\"the Babylon Lite probe set's scene cleanup could not be found, so its CPU data stays until the scene goes\");\n return;\n }\n const index = disposables.indexOf(cleanup);\n if (index >= 0) {\n disposables.splice(index, 1);\n }\n}\n\n/**\n * The scene's `_disposables` list, which Lite's set pushes its cleanup onto.\n *\n * @param scene - The scene.\n * @returns The list, or `undefined` when the scene has none (a Lite change).\n */\nfunction disposablesOf(scene: SceneContext): unknown[] | undefined {\n // Lite's scene type does not declare it; read from `lib/scene/scene-core.js` and\n // `enable-pbr-local-cubemap.js` (`scene._disposables.push`).\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion, no-underscore-dangle\n const list = (scene as unknown as { _disposables?: unknown })._disposables;\n return Array.isArray(list) ? list : undefined;\n}\n\n/**\n * Builds a blended set from captured probes.\n *\n * @param engine - The engine, for the queue a disposal waits on.\n * @param scene - The registered scene.\n * @param volumes - The probes, at least two.\n * @param minimum - The voxel grid's minimum corner.\n * @param maximum - The voxel grid's maximum corner.\n * @param cellSize - The voxel edge.\n * @param warn - Where a disposal that cannot free everything reports it.\n * @returns The set.\n * @throws When Lite refuses it: more than four probes in a voxel, more probes than the uniform block\n * holds, or cubes of different formats.\n *\n * @internal\n */\nexport function createLiteProbeSet(\n engine: EngineContext,\n scene: SceneContext,\n volumes: readonly LiteProbeSetVolume[],\n minimum: readonly [number, number, number],\n maximum: readonly [number, number, number],\n cellSize: number,\n warn: (message: string) => void,\n): LiteProbeSet {\n const probes: PbrLocalEnvironmentProbe[] = volumes.map((volume) => ({\n shape: \"box\",\n environment: volume.environment,\n capturePosition: volume.position,\n projectionPosition: volume.position,\n influencePosition: volume.position,\n projectionSize: volume.outer,\n influenceInnerSize: volume.inner,\n influenceOuterSize: volume.outer,\n }));\n const disposables = disposablesOf(scene);\n const before = disposables?.length ?? 0;\n const set = createPbrLocalEnvironmentProbeSet(scene, { probes, voxelGrid: { minimum, maximum, cellSize } });\n // Lite pushes exactly one cleanup closure as the set's last step.\n const cleanup = disposables !== undefined && disposables.length === before + 1 ? disposables[before] : undefined;\n let isDisposed = false;\n return {\n set,\n dispose(after?: PromiseLike<unknown>): void {\n if (isDisposed) {\n return;\n }\n isDisposed = true;\n const release = (): void => {\n releaseLiteProbeSet(set, disposables, cleanup, warn);\n };\n const device = deviceOf(engine);\n Promise.resolve(after)\n .catch(() => undefined)\n .then(async () => device?.queue.onSubmittedWorkDone())\n .then(release, release);\n },\n };\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, a blended set, 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 | LiteProbeSet | null,\n): Promise<void> | undefined {\n if (binding === null) {\n clearPbrLocalEnvironment(material);\n } else if (\"set\" in binding) {\n setPbrLocalEnvironmentProbeSet(material, binding.set);\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 createLiteProbeSet,\n createLiteReflectionProbe,\n enableReflectionProbes,\n forEachReflectiveMesh,\n} from \"../../lite/gpu/reflection-probe.js\";\nimport {\n reflectionProbeBlendLayout,\n resolveReflectionProbeRefreshMode,\n resolveReflectionProbeSize,\n selectReflectionProbe,\n} from \"../reflection-probe.js\";\nimport { EDITOR_ONLY_METADATA_KEY } from \"../render-texture.js\";\nimport type { LiteProbeBinding, LiteProbeSet, 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 {\n ReflectionProbe,\n ReflectionProbeBlendCandidate,\n ReflectionProbeBlendLayout,\n} 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 * Blending (B1b): when `reflectionProbeBlendLayout` says the frame's probes blend and every box probe\n * has finished capturing (none `everyFrame`), one Lite probe set built from their cubes goes on every\n * lit PBR material. The set copies the cubes, so it is rebuilt when a probe moves, recaptures,\n * resizes its box or changes `blendDistance`, and the replaced set is freed once the material\n * rebuilds that dropped it settled. While a box probe is still capturing, the last set stays (or,\n * before the first, the nearest-probe choice applies); while one is being moved or edited (its\n * binding or `blendDistance` changed within the last {@link BLEND_STILL_FRAMES} frames) the\n * nearest-probe choice applies. A material whose nearest probe has no box keeps that probe. A set Lite refuses (more than four probes\n * overlapping in a voxel, too many probes) logs once and the nearest-probe choice applies.\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/**\n * How many frames a blended probe's position, box and `blendDistance` must stay unchanged before a\n * probe set is built with it (about 250 ms at 60 Hz). A set copies every cube and rebuilds every lit\n * material, so a probe being moved, dragged or scrubbed falls back to the nearest-probe choice until\n * it rests.\n */\nconst BLEND_STILL_FRAMES = 15;\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 /** How many captures it ran, so a blended set made before a recapture is rebuilt. */\n generation: number;\n /** The `blendDistance` seen last frame. */\n blendDistance: number;\n /** How many frames its binding and `blendDistance` have not changed. */\n stillFrames: number;\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 ReflectionProbeBlendCandidate {\n /** The binding. */\n readonly binding: LiteProbeBinding;\n /** Its capture count. */\n readonly generation: number;\n /** Whether it has capture frames left, so a set made of it now would go stale. */\n readonly isCapturing: boolean;\n /** Whether it captures every frame, so any set made of it goes stale at once. */\n readonly isEveryFrame: boolean;\n /** Whether its binding or `blendDistance` changed within {@link BLEND_STILL_FRAMES}. */\n readonly isMoving: boolean;\n}\n\n/** A blended set and what it was built from, compared to decide a rebuild. */\ninterface BlendState {\n readonly lite: LiteProbeSet;\n /** Per volume: binding, generation and blend distance, flattened. */\n readonly key: readonly unknown[];\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. Until {@link handleDeviceRecovered},\n * `update` does nothing; the probes capture again on the first frame after it.\n */\n handleDeviceLost(): void;\n /** Lets `update` run again once Lite rebuilt the scene on the new device. */\n handleDeviceRecovered(): 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, with the entity's name already in the message.\n * @returns The runtime.\n *\n * @internal\n */\nexport async function createReflectionProbeRuntime(\n engine: LiteEngine,\n scene: LiteScene,\n warn: (message: string) => void,\n): Promise<ReflectionProbeRuntime> {\n await enableReflectionProbes();\n const states = new Map<ReflectionProbe, ProbeState>();\n const assigned = new Map<ReflectiveMaterial, LiteProbeBinding | LiteProbeSet | null>();\n /** The blended set on every lit material, or `null` for the nearest-probe choice. */\n let blend: BlendState | null = null;\n /** The key of a set Lite refused, so it is not tried again every frame. */\n let refusedKey: readonly unknown[] | null = null;\n let hasWarnedRefusal = false;\n const warnedLeaks = new Set<string>();\n const warnLeakOnce = (message: string): void => {\n if (!warnedLeaks.has(message)) {\n warnedLeaks.add(message);\n warn(`Reflection probe blending: ${message}.`);\n }\n };\n /** Sets replaced this frame, freed with the retired cubes. */\n const retiringSets: LiteProbeSet[] = [];\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 /**\n * Material rebuilds still in flight, whichever frame started them: a rebuild started a frame ago\n * may still draw with a cube retired now, so a retired cube waits for all of them.\n */\n const rebuilds = new Set<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 /** Between a device loss and Lite's recovery, nothing on the GPU may be touched. */\n let isDeviceLost = false;\n\n const assign = (material: ReflectiveMaterial, binding: LiteProbeBinding | LiteProbeSet | null): void => {\n const pending = assignReflectionProbe(scene, material, binding);\n if (pending !== undefined) {\n rebuilds.add(pending);\n const forget = (): void => {\n rebuilds.delete(pending);\n };\n pending.then(forget, forget);\n }\n };\n\n const release = (probe: ReflectionProbe, state: ProbeState): void => {\n // A capture still under way (an `onDemand` refresh whose frames are not done) counts as wanted.\n if (state.lite.environment !== null || state.framesToCapture > 0) {\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 still in flight, from any frame.\n */\n const retire = (): void => {\n if (retiring.length > 0) {\n for (const [material, binding] of assigned) {\n if (\n binding !== null &&\n !(\"set\" in binding) &&\n retiring.some((entry) => entry.environment === binding.environment)\n ) {\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 if (retiringSets.length > 0) {\n // A material still on a retired set was reassigned this frame or is gone from the scene.\n for (const [material, binding] of assigned) {\n if (binding !== null && \"set\" in binding && retiringSets.includes(binding)) {\n assigned.set(material, null);\n assign(material, null);\n }\n }\n const settled = Promise.allSettled(rebuilds);\n for (const set of retiringSets) {\n set.dispose(settled);\n }\n retiringSets.length = 0;\n }\n };\n\n /** Stops blending; the set goes once the materials that used it were rebuilt. */\n const dropBlend = (): void => {\n if (blend !== null) {\n retiringSets.push(blend.lite);\n blend = null;\n }\n };\n\n /**\n * Builds, keeps or drops the blended set for this frame's candidates.\n *\n * @param layout - The blend layout, or `null` when the probes do not blend.\n */\n const updateBlend = (layout: ReflectionProbeBlendLayout | null): void => {\n if (layout === null) {\n dropBlend();\n refusedKey = null;\n return;\n }\n let isCapturing = false;\n let hasEveryFrame = false;\n let isMoving = false;\n for (const volume of layout.volumes) {\n const candidate = candidates[volume.index];\n isCapturing ||= candidate?.isCapturing === true;\n hasEveryFrame ||= candidate?.isEveryFrame === true;\n isMoving ||= candidate?.isMoving === true;\n }\n if (hasEveryFrame || isMoving) {\n // A probe capturing every frame would leave any set stale at once; one being moved would\n // rebuild it every frame. Both take the nearest-probe choice until that stops.\n dropBlend();\n return;\n }\n if (isCapturing) {\n return;\n }\n const key: unknown[] = [];\n const volumes = layout.volumes.map((volume) => {\n const candidate = candidates[volume.index];\n if (candidate !== undefined) {\n key.push(candidate.binding, candidate.generation, candidate.blendDistance);\n }\n return {\n environment: candidate?.binding.environment ?? null,\n position: volume.position,\n outer: volume.outer,\n inner: volume.inner,\n };\n });\n if (sameKey(blend?.key ?? null, key) || sameKey(refusedKey, key)) {\n return;\n }\n const ready = volumes.filter(\n (volume): volume is typeof volume & { environment: NonNullable<typeof volume.environment> } =>\n volume.environment !== null,\n );\n try {\n const created = createLiteProbeSet(\n engine,\n scene,\n ready,\n layout.minimum,\n layout.maximum,\n layout.cellSize,\n warnLeakOnce,\n );\n dropBlend();\n blend = { lite: created, key };\n refusedKey = null;\n } catch (error) {\n dropBlend();\n refusedKey = key;\n if (!hasWarnedRefusal) {\n hasWarnedRefusal = true;\n warn(\n `The reflection probes cannot blend (${error instanceof Error ? error.message : String(error)}), ` +\n \"so each material reflects its nearest probe. Lite blends at most four overlapping probes.\",\n );\n }\n }\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 const blended = blend?.lite ?? null;\n forEachReflectiveMesh(scene, (material, x, y, z) => {\n if (seen.has(material)) {\n return;\n }\n seen.add(material);\n // A material whose nearest probe has no box keeps it: such probes are not in the set.\n const chosen = candidates[selectReflectionProbe(x, y, z, candidates)];\n const binding = blended !== null && chosen?.box !== null ? blended : (chosen?.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 if (isDeviceLost) {\n return;\n }\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 dropBlend();\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 `${JSON.stringify(probe.entity.name)} asks its ReflectionProbe for refreshMode \"everyFrame\", ` +\n 'which only the \"high\" rendering.quality tier allows, so it captures as \"once\" (when ready ' +\n \"and on refresh()).\",\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 generation: 0,\n blendDistance: probe.blendDistance,\n stillFrames: 0,\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 const isCapturing = state.framesToCapture > 0 || mode === \"everyFrame\";\n if (isCapturing && state.lite.capture(x, y, z, probe.near, probe.far)) {\n state.framesToCapture = Math.max(0, state.framesToCapture - 1);\n state.generation += 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.stillFrames =\n binding === state.binding && probe.blendDistance === state.blendDistance ? state.stillFrames + 1 : 0;\n state.binding = binding;\n state.blendDistance = probe.blendDistance;\n candidates.push({\n x,\n y,\n z,\n box,\n binding,\n blendDistance: probe.blendDistance,\n generation: state.generation,\n isCapturing: state.framesToCapture > 0,\n isEveryFrame: mode === \"everyFrame\",\n isMoving: state.stillFrames < BLEND_STILL_FRAMES,\n });\n }\n updateBlend(mayBlend(candidates) ? reflectionProbeBlendLayout(candidates) : null);\n assignMaterials();\n retire();\n },\n handleDeviceLost(): void {\n isDeviceLost = true;\n // The set's copies belong to the lost device; Lite would otherwise recopy from dead cubes.\n blend?.lite.dispose();\n blend = null;\n refusedKey = null;\n for (const set of retiringSets) {\n set.dispose();\n }\n retiringSets.length = 0;\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 || state.framesToCapture > 0) {\n recapture.add(probe);\n }\n state.lite.dispose();\n }\n states.clear();\n // The retired cubes belonged to the lost device too.\n for (const entry of retiring) {\n entry.lite.dispose();\n }\n retiring.length = 0;\n rebuilds.clear();\n },\n handleDeviceRecovered(): void {\n isDeviceLost = false;\n },\n dispose(): void {\n for (const [probe, state] of states) {\n release(probe, state);\n }\n dropBlend();\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 for (const set of retiringSets) {\n set.dispose(settled);\n }\n retiringSets.length = 0;\n rebuilds.clear();\n },\n };\n}\n\n/**\n * Whether a frame's probes can blend at all, checked without allocating: two box probes, one with a\n * `blendDistance`.\n *\n * @param candidates - The frame's candidates.\n * @returns `true` when {@link reflectionProbeBlendLayout} is worth calling.\n */\nfunction mayBlend(candidates: readonly BoundCandidate[]): boolean {\n let boxes = 0;\n let blends = false;\n for (const candidate of candidates) {\n if (candidate.box !== null) {\n boxes += 1;\n blends ||= candidate.blendDistance > 0;\n }\n }\n return boxes >= 2 && blends;\n}\n\n/**\n * Whether two set keys are equal, element by element.\n *\n * @param a - A key, or `null`.\n * @param b - Another key.\n * @returns `true` when both have the same elements.\n */\nfunction sameKey(a: readonly unknown[] | null, b: readonly unknown[]): boolean {\n return a !== null && a.length === b.length && a.every((value, index) => value === b[index]);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,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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,KACzB,SAAS,SAAS,OAAO,MACxB,QAAQ,OACL,SAAS,QAAQ,OACjB,SAAS,QAAQ,QAAQ,SAAS,IAAI,OAAO,IAAI,KAAK,SAAS,IAAI,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,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
2
  import { o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
3
- import { I as setOwnJsonProperty } from "./prefab-overrides-DRP2DcnC.js";
3
+ import { I as setOwnJsonProperty } from "./prefab-overrides-C2GsgOQc.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";
@@ -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-CuwK9tWC.js.map
1013
+ //# sourceMappingURL=shader-material-TM4f8eKA.js.map