rayzee 9.5.0 → 11.0.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 (78) hide show
  1. package/README.md +22 -20
  2. package/dist/{ArchiveImporter-xuUJiklP.js → ArchiveImporter-BRQvLggb.js} +12 -13
  3. package/dist/{BidirectionalIntegrator-C5PKjJoT.js → BidirectionalIntegrator-9lZQxFVH.js} +87 -87
  4. package/dist/BufferLayout-D_IBo2ci.js +150 -0
  5. package/dist/{ColorManagement-CheBCPaW.js → ColorManagement-oeEk7oSu.js} +171 -171
  6. package/dist/{NeuralRetouch-CW11yLZ_.js → NeuralRetouch-BCXylThH.js} +3 -3
  7. package/dist/{NeuralSuperRes-BekaecYg.js → NeuralSuperRes-sZAeS142.js} +3 -3
  8. package/dist/{PathTracer-Ccl9KOuF.js → PathTracer-CQPW06Mm.js} +2911 -2669
  9. package/dist/{PhysicalSky-Dv2PMFGW.js → PhysicalSky-BvqCw_dy.js} +2 -2
  10. package/dist/{RayzeeRenderer-BQxnzCTD.js → RayzeeRenderer-COpwotpU.js} +338 -329
  11. package/dist/{SolarLimb-ken-JbDK.js → SolarLimb-CPaeZVwz.js} +10 -10
  12. package/dist/{ToneMapGPU-BHi5JzIq.js → ToneMapGPU-CjU3osDd.js} +1 -1
  13. package/dist/{ViewTransforms-D0rTLBsX.js → ViewTransforms-CYN7bq2w.js} +2 -2
  14. package/dist/addons/archives.es.js +1 -1
  15. package/dist/addons/bidirectional.es.js +1 -1
  16. package/dist/addons/color.es.js +1 -1
  17. package/dist/addons/physical-sky.es.js +1 -1
  18. package/dist/rayzee-core.es.js +11 -11
  19. package/dist/rayzee.es.js +734 -599
  20. package/dist/rayzee.umd.js +102 -102
  21. package/dist/sceneCachePolicy-BSSsKY98.js +443 -0
  22. package/package.json +1 -1
  23. package/src/Color/ViewTransforms.js +5 -1
  24. package/src/EngineDefaults.js +59 -1032
  25. package/src/Headless.js +6 -5
  26. package/src/Passes/OIDNTemporalHistory.js +1 -1
  27. package/src/PathTracerApp.js +5 -3
  28. package/src/Processor/AssetLoader.js +6 -5
  29. package/src/Processor/BVHBuilder.js +10 -31
  30. package/src/Processor/BVHLeafFold.js +4 -6
  31. package/src/Processor/BVHRefitter.js +3 -46
  32. package/src/Processor/BufferLayout.js +291 -0
  33. package/src/Processor/EmissiveTriangleBuilder.js +1 -1
  34. package/src/Processor/GeometryExtractor.js +3 -3
  35. package/src/Processor/HostMemory.js +7 -1
  36. package/src/Processor/InstanceTable.js +1 -1
  37. package/src/Processor/MaterialPacking.js +2 -1
  38. package/src/Processor/PBRT/PBRTSceneBuilder.js +1 -1
  39. package/src/Processor/QueueManager.js +28 -3
  40. package/src/Processor/SceneProcessor.js +4 -2
  41. package/src/Processor/SplitBLAS.js +1 -1
  42. package/src/Processor/StorageTexturePool.js +22 -1
  43. package/src/Processor/TLASBuilder.js +1 -3
  44. package/src/Processor/TextureBuckets.js +237 -0
  45. package/src/Processor/TextureCreator.js +10 -1
  46. package/src/Processor/Workers/TexturesWorker.js +5 -6
  47. package/src/RayzeeRenderer.js +29 -32
  48. package/src/RenderSettings.js +26 -28
  49. package/src/Stages/ASVGF.js +8 -7
  50. package/src/Stages/AutoExposure.js +14 -5
  51. package/src/Stages/BilateralFilter.js +2 -1
  52. package/src/Stages/DenoiserSettings.js +182 -0
  53. package/src/Stages/EdgeFilter.js +2 -1
  54. package/src/Stages/MotionVector.js +1 -1
  55. package/src/Stages/NRD.js +2 -3
  56. package/src/Stages/NormalDepth.js +3 -2
  57. package/src/Stages/PathTracer.js +72 -4
  58. package/src/Stages/PathTracerStage.js +2 -1
  59. package/src/Stages/Variance.js +1 -1
  60. package/src/TSL/BVHTraversal.js +4 -1
  61. package/src/TSL/Common.js +1 -1
  62. package/src/TSL/EmissiveSampling.js +1 -1
  63. package/src/TSL/LightVisibility.js +111 -0
  64. package/src/TSL/LightsSampling.js +151 -15
  65. package/src/TSL/Random.js +1 -1
  66. package/src/TSL/ShadeKernel.js +88 -3
  67. package/src/TSL/TextureSampling.js +1 -1
  68. package/src/core.js +5 -9
  69. package/src/index.js +10 -21
  70. package/src/integrators/BidirectionalIntegrator.js +2 -1
  71. package/src/managers/CameraManager.js +17 -7
  72. package/src/managers/DenoisingManager.js +14 -10
  73. package/src/managers/EnvironmentManager.js +32 -13
  74. package/src/managers/MaterialDataManager.js +3 -3
  75. package/src/managers/UniformManager.js +2 -2
  76. package/dist/EngineDefaults-DH3bI5t-.js +0 -844
  77. package/dist/sceneCachePolicy-BmwYOYDu.js +0 -183
  78. /package/dist/{Logger-BnHghprG.js → Logger-dDDGj9Av.js} +0 -0
package/README.md CHANGED
@@ -325,7 +325,6 @@ const engine = new PathTracerApp(canvas, options?)
325
325
  | `options.autoResize` | `boolean` | Auto-resize on window resize (default: `true`; always off headless) |
326
326
  | `options.container` | `HTMLElement` | Single DOM parent the engine mounts auxiliary elements into — HUD overlay (tile borders, helpers) and denoiser canvas. Defaults to `canvas.parentNode`. |
327
327
  | `options.strict` | `boolean` | Throw an `EngineIssueError` where the engine would otherwise degrade and carry on (default: `false`). See [Degradation contract](#degradation-contract). |
328
- | `options.profile` | `string` | `'viewer'` (default) or `'physical'` — product tuning that is not a physical constant: area-light scale, environment rotation, tone mapping, saturation. An unknown name throws. |
329
328
  | `options.maxSceneBytes` | `number` | Raise or lower the CPU memory ceiling a scene may need before the engine refuses it (default 9,216 MB). See [Memory monitoring](#memory-monitoring). |
330
329
  | `options.hostMemoryGB` | `number` | The host's memory, for runtimes without Chrome's `navigator.deviceMemory` (which then read as 4 GB and cap the render reserve at 2048). Sizes the reserve and the path pool. |
331
330
  | `options.storage` | `false \| 'auto' \| StorageManager` | On-disk storage (default: `configureAssets( { storage } )`; off under `strict` unless you set it there or here). A manager you pass stays yours to dispose. See [On-disk storage](#on-disk-storage-opfs). |
@@ -445,6 +444,9 @@ Key settings:
445
444
  | `enableEnvironment` | `boolean` | true | Use environment lighting |
446
445
  | `environmentIntensity` | `number` | 1.0 | Environment light strength |
447
446
  | `environmentRotation` | `number` | 0 | Environment Y-rotation (degrees); 0 shows the HDRI as authored, as Blender's unmapped world does |
447
+ | `areaLightIntensityScale` | `number` | 0.1 | Power of a glTF model's placeholder area lights (RectAreaLight extras), read when the model loads, so set it first; 1 is the authored power |
448
+ | `maxTextureSize` | `number` | 4096 | Longest edge of a material texture, read when a model loads (clamped to the hardware ceiling); `setMaxTextureSize()` applies it to the current scene too |
449
+ | `wavefrontSortMaterials` | `boolean` | true | Sort rays by material before shading, above 8 materials; read when the shaders next build |
448
450
  | `showBackground` | `boolean` | true | Show the environment as a visible backdrop for camera-miss rays (vs. a solid/transparent background) |
449
451
  | `samplingTechnique` | `number` | 2 | Sampler: `0` PCG, `1` scrambled Halton, `2` Owen-scrambled Sobol |
450
452
  | `integrator` | `string` | 'path' | `'path'` \| `'bidirectional'` \| `'vcm'` (on the core, needs the bidirectional add-on). Bidirectional also traces light subpaths from every light — emissive surfaces, rect/disk, point, spot and directional lights, the sun and the environment — far faster for caustics and light through small openings, about 2× the cost per sample. On a lamp-lit interior with an HDRI it is ~20 % less noisy at equal time; a room lit only through a window stays better path traced. `'vcm'` adds photon merging, for caustics seen in mirrors and through glass. Switching rebuilds the kernels |
@@ -454,7 +456,7 @@ Key settings:
454
456
  | `maxSubsurfaceSteps` | `number` | 8 | Max random-walk steps for subsurface scattering (raised to 64 by `configureForMode('production')`) |
455
457
  | `enableAlphaShadows` | `boolean` | false | Alpha-tested shadow rays (enabled by `configureForMode('production')`) |
456
458
  | `enableDOF` | `boolean` | false | Enable depth of field |
457
- | `dofMode` | `string` | 'look' | `'look'`: the blur is set by `dofBlur`, the same at any scene scale; `'physical'`: a real lens set by `aperture`, `focalLength` and `unitsPerMetre`. The `physical` render profile defaults to `'physical'` |
459
+ | `dofMode` | `string` | 'look' | `'look'`: the blur is set by `dofBlur`, the same at any scene scale; `'physical'`: a real lens set by `aperture`, `focalLength` and `unitsPerMetre`. |
458
460
  | `dofBlur` | `number` | 0.05 | Look mode: how far a distant background blurs, as a fraction of the image height |
459
461
  | `focusDistance` | `number` | 0.8 | DOF focus distance in scene units — depth along the view axis (the focal plane is flat) |
460
462
  | `aperture` | `number` | 5.6 | Physical mode: f-stop |
@@ -478,7 +480,7 @@ Key settings:
478
480
  | `pixelFreezeThreshold` | `number` | 0.02 | Relative-error threshold for a pixel to become a freeze candidate |
479
481
  | `pixelFreezeStability` | `number` | 8 | Consecutive candidate frames required before a pixel freezes |
480
482
 
481
- See `ENGINE_DEFAULTS` for the full list with default values. The default look is AgX (`toneMapping: 6`) at neutral saturation; tone mapping is chosen through [Colour Management](#colour-management) (`engine.color.setActiveView( id )`), not `settings`. On the core without the colour add-on, set `renderer.renderer.toneMapping`.
483
+ See `ENGINE_DEFAULTS` for the full list with default values — every key in it is a setting of the same name. The default look is AgX (`DEFAULT_VIEW`) at neutral saturation; tone mapping is chosen through [Colour Management](#colour-management) (`engine.color.setActiveView( id )`), not `settings`. On the core without the colour add-on, set `renderer.renderer.toneMapping`.
482
484
 
483
485
  #### Rendering Modes
484
486
 
@@ -645,11 +647,11 @@ await renderer.init();
645
647
  Several renderers, core or full, can live in one page; they share only the colour management and the on-disk storage,
646
648
  which are page-wide.
647
649
 
648
- Code of your own that adds a setting declares it on the renderer's settings, so it gets the same provenance, change
649
- events and session saving as the built-in ones:
650
+ Code of your own that adds a setting declares it on the renderer's settings, with its default, so it gets the same
651
+ provenance, change events and session saving as the built-in ones:
650
652
 
651
653
  ```js
652
- renderer.settings.define('myGlowStrength', { apply: (value) => glow.setStrength(value), reset: true });
654
+ renderer.settings.define('myGlowStrength', { default: 1, apply: (value) => glow.setStrength(value), reset: true });
653
655
  renderer.settings.set('myGlowStrength', 2);
654
656
  ```
655
657
 
@@ -790,7 +792,8 @@ engine.stages.pathTracer.materialData.updateMaterial(index, mat) // Replace a m
790
792
  await engine.rebuildMaterials(scene) // Full rebuild (after texture changes)
791
793
 
792
794
  // Cap the longest edge of processed material textures (clamped to the hardware max).
793
- // Larger = sharper textures, ~quadratic VRAM. Reprocesses the current scene by default.
795
+ // Larger = sharper textures, ~quadratic VRAM. Reprocesses the current scene by default;
796
+ // settings.set('maxTextureSize', n) stores it for the next load instead.
794
797
  await engine.setMaxTextureSize(2048)
795
798
  await engine.setMaxTextureSize(4096, { reprocess: false })
796
799
 
@@ -1199,7 +1202,7 @@ auto-exposure, if you turn it on.
1199
1202
  #### Batch rendering
1200
1203
 
1201
1204
  The supported entry point for a render farm is `rayzee/src/Headless.js`, exported from the package.
1202
- Its defaults are a batch renderer's — `strict`, `profile: 'physical'`, deterministic, storage off —
1205
+ Its defaults are a batch renderer's — `strict`, deterministic, storage off —
1203
1206
  so a degraded render throws instead of shipping:
1204
1207
 
1205
1208
  ```js
@@ -1230,16 +1233,19 @@ unavailable or fails, the CPU does it instead: the result's `toneMappedOn` says
1230
1233
  Constructing `PathTracerApp` yourself instead: pass `strict: true`; storage is then off unless you
1231
1234
  set it. Outside Chrome, pass `hostMemoryGB`.
1232
1235
 
1236
+ The engine has one set of defaults, the viewer's. For lens-accurate depth of field and glTF placeholder area
1237
+ lights at their authored power, set `dofMode: 'physical'` and `areaLightIntensityScale: 1` — through `settings`
1238
+ here, or `engine.settings` before loading the model.
1239
+
1233
1240
  **Provenance.** `engine.getProvenance()` — also `frame.provenance` from `captureHeadless` — is plain
1234
- JSON naming what produced the image: engine and three.js versions, the profile by name *and* by
1235
- value, the adapter, every live setting with its source, the colour pipeline, the render size and
1241
+ JSON naming what produced the image: engine and three.js versions, the adapter, every live setting with its source, the colour pipeline, the render size and
1236
1242
  samples, and whether it ran headless, strict, deterministic or lockstepped. `mode.lockstep` says
1237
1243
  whether the current image was traced in lockstep, so it stays true after `renderUntilComplete` turns
1238
1244
  lockstep back off. Store it beside each render and "what made this?" has an answer without rendering
1239
1245
  again.
1240
1246
 
1241
1247
  **Pinning a look.** A change to what a render looks like when a host sets nothing — a default
1242
- setting, a mode preset, a profile's values, light units — is released as a **major**, with the
1248
+ setting, a mode preset, light units — is released as a **major**, with the
1243
1249
  change described under BREAKING CHANGES in the release notes. Pin a major to pin a look; read the
1244
1250
  notes before moving to the next one.
1245
1251
 
@@ -1515,22 +1521,18 @@ import { nodePlatform, NodeWorker } from 'rayzee/node';
1515
1521
  // Configuration & presets
1516
1522
  import {
1517
1523
  ENGINE_DEFAULTS,
1524
+ DENOISER_DEFAULTS,
1525
+ AUTO_EXPOSURE_DEFAULTS,
1526
+ AUTO_FOCUS_DEFAULTS,
1518
1527
  ASVGF_QUALITY_PRESETS,
1519
- CAMERA_PRESETS,
1520
- CAMERA_RANGES,
1521
- SKY_PRESETS,
1528
+ SKY_DEFAULTS,
1522
1529
  DEFAULT_SUN_PATH,
1523
- AUTO_FOCUS_MODES,
1524
- AF_DEFAULTS,
1530
+ DEFAULT_VIEW,
1525
1531
  TRIANGLE_DATA_LAYOUT,
1526
1532
  BVH_LEAF_MARKERS,
1527
- TEXTURE_CONSTANTS,
1528
- DEFAULT_TEXTURE_MATRIX,
1529
- MEMORY_CONSTANTS,
1530
1533
  PRODUCTION_RENDER_CONFIG,
1531
1534
  INTERACTIVE_RENDER_CONFIG,
1532
1535
  MAX_RESERVABLE_RENDER_SIZE,
1533
- RENDER_PROFILES,
1534
1536
  MATERIAL_DEFAULTS,
1535
1537
  } from 'rayzee';
1536
1538
 
@@ -1,6 +1,5 @@
1
- import { n as e } from "./BidirectionalIntegrator-C5PKjJoT.js";
2
- import { g as t, n, o as r, r as i } from "./sceneCachePolicy-BmwYOYDu.js";
3
- import "./EngineDefaults-DH3bI5t-.js";
1
+ import { n as e } from "./BidirectionalIntegrator-9lZQxFVH.js";
2
+ import { A as t, g as n, n as r, r as i } from "./sceneCachePolicy-BSSsKY98.js";
4
3
  import { n as a, r as o } from "./EngineIssues-CIZnXHsF.js";
5
4
  import { r as s } from "./shared-BGBcSxBQ.js";
6
5
  import { a as c, n as l, r as u } from "./identity-DrQsGT2o.js";
@@ -3860,7 +3859,7 @@ var ti = /* @__PURE__ */ e({
3860
3859
  c.release(), u && (console.warn(`The stored scene could not be used, parsing the archive instead: ${u.message}`), this.loader._issues?.warn(a.STORAGE_ENTRY_CORRUPT, `stored scene unusable: ${u.message}`, { key: e }), o.remove(e).catch(() => {}));
3861
3860
  }
3862
3861
  }
3863
- _storeGraph(e, t, r) {
3862
+ _storeGraph(e, t, n) {
3864
3863
  let i = this.loader.storage?.area(s.SCENES);
3865
3864
  if (!i) return;
3866
3865
  let a;
@@ -3888,17 +3887,17 @@ var ti = /* @__PURE__ */ e({
3888
3887
  let o = {
3889
3888
  key: e,
3890
3889
  encoded: a,
3891
- label: r,
3890
+ label: n,
3892
3891
  parseMs: (t.parseMs ?? 0) + (t.buildMs ?? 0),
3893
3892
  triangles: t.triangleCount ?? null
3894
3893
  };
3895
- n(o.parseMs, a.byteLength) ? this._writeGraph(i, o) : this._pendingGraph = o;
3894
+ r(o.parseMs, a.byteLength) ? this._writeGraph(i, o) : this._pendingGraph = o;
3896
3895
  }
3897
3896
  flushPendingGraph(e) {
3898
3897
  let t = this._pendingGraph;
3899
3898
  this._pendingGraph = null;
3900
- let r = this.loader.storage?.area(s.SCENES);
3901
- !t || !r || !n(t.parseMs + e, t.encoded.byteLength) || this._writeGraph(r, t);
3899
+ let n = this.loader.storage?.area(s.SCENES);
3900
+ !t || !n || !r(t.parseMs + e, t.encoded.byteLength) || this._writeGraph(n, t);
3902
3901
  }
3903
3902
  _writeGraph(e, t) {
3904
3903
  (async () => {
@@ -3971,7 +3970,7 @@ var ti = /* @__PURE__ */ e({
3971
3970
  }
3972
3971
  return c.length && console.info(`Archive "${n}": loaded ${c.map((e) => `"${e}"`).join(", ")} — ${Object.keys(l).length} of ${u.length} files, ${(d / 1048576).toFixed(1)} MB.`), l;
3973
3972
  }
3974
- async loadPBRTFromZip(e, n, s = null, l = {}, u = null) {
3973
+ async loadPBRTFromZip(e, r, s = null, l = {}, u = null) {
3975
3974
  if (t({
3976
3975
  isLoading: !0,
3977
3976
  status: "Parsing PBRT scene...",
@@ -3984,10 +3983,10 @@ var ti = /* @__PURE__ */ e({
3984
3983
  let n = await this._pbrtTextureFromBytes(e, t);
3985
3984
  return n && (n.userData[Ze] = t), n;
3986
3985
  }, p = async (e, t) => {
3987
- let n = t.split(".").pop().toLowerCase(), i = new Blob([e]), a = n === "pfm" ? null : URL.createObjectURL(i);
3986
+ let r = t.split(".").pop().toLowerCase(), i = new Blob([e]), a = r === "pfm" ? null : URL.createObjectURL(i);
3988
3987
  try {
3989
- let o = a ? await this.loader.loadEnvironmentByExtension(a, n, { loader: n === "exr" ? this._exrLoader() : null }) : ei(e);
3990
- return o.mapping = C, r(o, `bytes:${await c(i)}`), o.userData[Ze] = t, o.userData[Qe] = "environment", o;
3988
+ let o = a ? await this.loader.loadEnvironmentByExtension(a, r, { loader: r === "exr" ? this._exrLoader() : null }) : ei(e);
3989
+ return o.mapping = C, n(o, `bytes:${await c(i)}`), o.userData[Ze] = t, o.userData[Qe] = "environment", o;
3991
3990
  } finally {
3992
3991
  a && URL.revokeObjectURL(a);
3993
3992
  }
@@ -4032,7 +4031,7 @@ var ti = /* @__PURE__ */ e({
4032
4031
  let e = S.length < T ? ` (first ${S.length} of ${T})` : "";
4033
4032
  console.groupCollapsed(`PBRT loader: ${T} mesh(es) from "${E}"${e}`), console.table(S), console.groupEnd();
4034
4033
  }
4035
- return w && w.length && (console.warn(`PBRT loader: ${w.length} warning(s) parsing "${E}"`), w.forEach((e) => console.warn(" •", e))), b?.texture && (b.texture.generateMipmaps = !0, this.loader.applyEnvironmentToScene(b.texture)), y.name = E || n, this.loader.releaseTargetModel(), this.loader._sourceKey = g, g && !_ && this._storeGraph(g, v, n), this.loader.targetModel = y, this.loader.animations = x ?? [], this.loader.sceneMetadata = { environment: b?.texture ? {
4034
+ return w && w.length && (console.warn(`PBRT loader: ${w.length} warning(s) parsing "${E}"`), w.forEach((e) => console.warn(" •", e))), b?.texture && (b.texture.generateMipmaps = !0, this.loader.applyEnvironmentToScene(b.texture)), y.name = E || r, this.loader.releaseTargetModel(), this.loader._sourceKey = g, g && !_ && this._storeGraph(g, v, r), this.loader.targetModel = y, this.loader.animations = x ?? [], this.loader.sceneMetadata = { environment: b?.texture ? {
4036
4035
  rotation: 0,
4037
4036
  intensity: 1
4038
4037
  } : { enabled: !1 } }, t({
@@ -1,6 +1,6 @@
1
- import { $t as e, F as t, Ft as n, I as r, J as i, K as a, L as o, Mt as s, R as c, Rt as l, U as u, X as d, Y as f, Z as p, Zt as m, c as ee, ct as h, dt as te, et as g, ft as ne, i as _, j as re, jt as ie, k as ae, lt as oe, nn as se, q as v, qt as ce, r as le, rn as ue, wt as y, y as de } from "./SolarLimb-ken-JbDK.js";
2
- import { A as b, At as fe, C as x, D as S, Dt as pe, E as C, Et as w, F as T, G as me, I as E, J as he, M as ge, O as _e, Ot as ve, S as ye, T as be, Tt as D, U as xe, V as O, W as k, Y as Se, _ as A, a as Ce, at as j, b as we, c as Te, d as Ee, f as De, g as M, h as N, i as Oe, it as ke, j as Ae, k as je, kt as Me, l as Ne, m as Pe, o as Fe, p as Ie, q as Le, r as Re, rt as P, s as ze, t as Be, u as F, v as Ve, w as He, x as Ue, y as We } from "./PathTracer-Ccl9KOuF.js";
3
- import { l as Ge } from "./EngineDefaults-DH3bI5t-.js";
1
+ import { $t as e, F as t, Ft as n, I as r, J as i, K as a, L as o, Mt as s, R as c, Rt as l, U as u, X as d, Y as f, Z as p, Zt as m, c as ee, ct as h, dt as te, et as g, ft as ne, i as _, j as re, jt as ie, k as ae, lt as oe, nn as se, q as v, qt as ce, r as le, rn as ue, wt as y, y as de } from "./SolarLimb-CPaeZVwz.js";
2
+ import { A as b, C as fe, D as x, E as pe, F as S, Ft as me, G as he, I as C, J as w, M as ge, Mt as _e, Nt as ve, O as ye, Pt as T, S as be, T as xe, Tt as E, U as Se, V as D, W as O, Y as Ce, _ as k, a as we, at as A, b as Te, c as Ee, d as De, f as Oe, g as j, h as M, i as ke, it as N, j as Ae, jt as je, k as Me, l as Ne, m as Pe, o as Fe, p as Ie, q as Le, r as Re, rt as P, s as ze, t as Be, u as F, v as Ve, w as He, wt as Ue, x as We, y as Ge } from "./PathTracer-CQPW06Mm.js";
3
+ import "./BufferLayout-D_IBo2ci.js";
4
4
  import { Break as Ke, Fn as I, If as L, Loop as qe, Return as R, abs as z, atomicAdd as Je, atomicFunc as Ye, atomicLoad as B, atomicStore as Xe, bool as Ze, cos as Qe, cross as $e, dot as V, exp2 as et, float as H, floor as tt, instanceIndex as U, int as W, ivec2 as nt, ivec3 as rt, length as it, localId as at, log2 as ot, max as G, min as st, mix as ct, normalize as lt, sampler as ut, select as K, sin as dt, sqrt as ft, storage as pt, texture as mt, uint as q, uniform as J, uniformArray as ht, vec2 as gt, vec3 as Y, vec4 as _t, workgroupId as vt } from "three/tsl";
5
5
  import { DataTexture as yt, FloatType as bt, RedFormat as xt, Vector3 as St } from "three";
6
6
  //#region \0rolldown/runtime.js
@@ -36,15 +36,15 @@ var Ct = Object.defineProperty, wt = (e, t) => {
36
36
  i(W(e), t, n(t).toVar());
37
37
  });
38
38
  });
39
- a(0, e.numDirectional, (t) => Ie(We.wrap(x(e.directional, t)), n, r, W(0))), a(1, e.numArea, (i) => {
40
- let a = Ve.wrap(ye(e.area, i));
41
- return K(a.intensity.greaterThan(0), M(a, t, n, r), H(0));
42
- }), a(2, e.numPoint, (i) => Pe(we.wrap(He(e.point, i)), t, n, r)), a(3, e.numSpot, (i) => N(Ue.wrap(C(e.spot, i)), t, n, r));
39
+ a(0, e.numDirectional, (t) => Ie(Ge.wrap(fe(e.directional, t)), n, r, W(0))), a(1, e.numArea, (i) => {
40
+ let a = Ve.wrap(be(e.area, i));
41
+ return K(a.intensity.greaterThan(0), j(a, t, n, r), H(0));
42
+ }), a(2, e.numPoint, (i) => Pe(Te.wrap(He(e.point, i)), t, n, r)), a(3, e.numSpot, (i) => M(We.wrap(pe(e.spot, i)), t, n, r));
43
43
  };
44
44
  function jt(e, t, n, r, i, a) {
45
45
  let o = W(-1).toVar(), s = W(-1).toVar(), c = H(0).toVar(), l = H(0).toVar();
46
46
  At(e, t, n, r, (t, n, r) => {
47
- l.addAssign(r), L(r.greaterThan(0).and(a(W(w + 64).add(kt(e, t)).add(n)).mul(l).lessThan(r)), () => {
47
+ l.addAssign(r), L(r.greaterThan(0).and(a(W(je + 64).add(kt(e, t)).add(n)).mul(l).lessThan(r)), () => {
48
48
  o.assign(t), s.assign(n), c.assign(r);
49
49
  });
50
50
  });
@@ -102,7 +102,7 @@ var Nt = (e) => H(2 * oe).mul(G(H(1).sub(Qe(e.angle)), 1e-10)), Pt = (e) => H(2
102
102
  sourcePick: () => an,
103
103
  strategyWeight: () => $t,
104
104
  sunEmissionPdf: () => nn
105
- }), X = w + 2048, Lt = 65536, Rt = 16384, zt = 4096, Bt = 2147483648, Vt = 1e30, Z = (e) => K(e.equal(e), e, H(0)).clamp(0, Vt), Ht = (e, t) => {
105
+ }), X = je + 2048, Lt = 65536, Rt = 16384, zt = 4096, Bt = 2147483648, Vt = 1e30, Z = (e) => K(e.equal(e), e, H(0)).clamp(0, Vt), Ht = (e, t) => {
106
106
  let n = q(t.x);
107
107
  return gt(H(q(e).mod(n)).add(.5), H(q(e).div(n).add(q(Lt))).add(.5));
108
108
  }, Q = (e) => e.mul(e), Ut = (e, t, n) => {
@@ -138,14 +138,14 @@ var Nt = (e) => H(2 * oe).mul(G(H(1).sub(Qe(e.angle)), 1e-10)), Pt = (e) => H(2
138
138
  function ln(t, n, r, i) {
139
139
  let a = e.wrap(y(W(t), i)).toVar();
140
140
  a.normalMapIndex.assign(W(-1)), a.bumpMapIndex.assign(W(-1)), a.displacementMapIndex.assign(W(-1)), a.diffuseTransmission.assign(0);
141
- let o = m.wrap(O(a, n, r, _t(0))).toVar(), s = o.roughness.toVar();
141
+ let o = m.wrap(D(a, n, r, _t(0))).toVar(), s = o.roughness.toVar();
142
142
  a.color.assign(o.albedo), a.metalness.assign(o.metalness.clamp(0, 1)), a.roughness.assign(o.roughness.clamp(h, 1)), a.sheenRoughness.assign(a.sheenRoughness.clamp(.05, 1));
143
- let c = T({
143
+ let c = S({
144
144
  uv: n,
145
145
  transform: a.albedoTransform
146
146
  }).toVar();
147
147
  L(a.anisotropyMapIndex.greaterThanEqual(W(0)), () => {
148
- let e = E(a, c).toVar();
148
+ let e = C(a, c).toVar();
149
149
  a.anisotropy.assign(e.x), a.anisotropyRotation.assign(e.y);
150
150
  });
151
151
  let l = ce.wrap(ge(a, c)).toVar();
@@ -227,105 +227,105 @@ function Cn({ counters: e, out: t }) {
227
227
  }
228
228
  function wn({ counters: e }) {
229
229
  return I(() => {
230
- L(U.lessThan(q(ke)), () => {
230
+ L(U.lessThan(q(N)), () => {
231
231
  Xe(e.element(q(P.GUIDE).add(U)), q(0));
232
232
  });
233
- })().compute(ke, [256]);
233
+ })().compute(N, [256]);
234
234
  }
235
235
  //#endregion
236
236
  //#region src/TSL/LightGenerateKernel.js
237
237
  function Tn(e) {
238
- let { rayBufferRW: t, hitBufferRW: n, activeIndicesRW: r, counters: o, lightBuffer: c, triangleBuffer: m, bvhBuffer: ee, emissiveTriangleCount: h, emissiveVec4Offset: te, emissiveTotalPower: g, emissiveBoost: ne, sunDirection: _, sunRadiance: re, sunParams: ie, environmentIntensity: ae, envTexture: oe, envCDFTexture: se, envMatrix: ce, envResolution: le, directionalLightsBuffer: ue, areaLightsBuffer: y, pointLightsBuffer: de, spotLightsBuffer: b, bidirectional: w, resolution: T, frame: E, transmissiveBounces: he } = e, { lightPaths: ge } = w;
238
+ let { rayBufferRW: t, hitBufferRW: n, activeIndicesRW: r, counters: o, lightBuffer: c, triangleBuffer: m, bvhBuffer: ee, emissiveTriangleCount: h, emissiveVec4Offset: te, emissiveTotalPower: g, emissiveBoost: ne, sunDirection: _, sunRadiance: re, sunParams: ie, environmentIntensity: ae, envTexture: oe, envCDFTexture: se, envMatrix: ce, envResolution: le, directionalLightsBuffer: ue, areaLightsBuffer: y, pointLightsBuffer: de, spotLightsBuffer: b, bidirectional: S, resolution: C, frame: w, transmissiveBounces: ge } = e, { lightPaths: E } = S;
239
239
  return I(() => {
240
240
  let e = U;
241
241
  L(e.equal(q(0)), () => {
242
- Xe(o.element(q(P.ACTIVE_RAY_COUNT)), ge), Xe(o.element(q(P.ENTERING_COUNT)), ge);
243
- }), L(e.greaterThanEqual(ge), () => {
242
+ Xe(o.element(q(P.ACTIVE_RAY_COUNT)), E), Xe(o.element(q(P.ENTERING_COUNT)), E);
243
+ }), L(e.greaterThanEqual(E), () => {
244
244
  R();
245
245
  }), r.element(e).assign(e);
246
- let D = Ht(e, T).toVar(), O = fe({ state: pe({
246
+ let D = Ht(e, C).toVar(), k = me({ state: _e({
247
247
  pixelCoord: D,
248
248
  rayIndex: W(3),
249
- frame: E
250
- }) }).toVar(), A = Y(0).toVar(), M = Y(0, 1, 0).toVar(), N = Y(0).toVar(), ke = H(0).toVar(), Ae = H(0).toVar(), Pe = W(-1).toVar(), Ie = W(0).toVar(), Le = H(1).toVar(), ze = Ze(!1).toVar(), Be = ve(D, W(0), W(X + 4), O, T, E).toVar(), F = W(0).toVar(), Ge = W(w.sourceCount - 1).toVar();
251
- qe(F.lessThan(Ge), () => {
252
- let e = F.add(Ge).div(2).toVar();
253
- L(w.sourceCdf.element(e).lessThanEqual(Be), () => {
249
+ frame: w
250
+ }) }).toVar(), j = Y(0).toVar(), M = Y(0, 1, 0).toVar(), N = Y(0).toVar(), Ae = H(0).toVar(), je = H(0).toVar(), Pe = W(-1).toVar(), Ie = W(0).toVar(), Le = H(1).toVar(), ze = Ze(!1).toVar(), Be = ve(D, W(0), W(X + 4), k, C, w).toVar(), F = W(0).toVar(), Ue = W(S.sourceCount - 1).toVar();
251
+ qe(F.lessThan(Ue), () => {
252
+ let e = F.add(Ue).div(2).toVar();
253
+ L(S.sourceCdf.element(e).lessThanEqual(Be), () => {
254
254
  F.assign(e.add(1));
255
255
  }).Else(() => {
256
- Ge.assign(e);
256
+ Ue.assign(e);
257
257
  });
258
258
  });
259
- let Ke = w.guideTexture, I = (e) => {
260
- let t = xn(w, Ke, e, ve(D, W(0), W(X + 7), O, T, E), Me(D, W(0), W(X + 6), O, T, E)).toVar();
259
+ let Ke = S.guideTexture, I = (e) => {
260
+ let t = xn(S, Ke, e, ve(D, W(0), W(X + 7), k, C, w), T(D, W(0), W(X + 6), k, C, w)).toVar();
261
261
  return {
262
262
  start: t,
263
- pdf: bn(w, Ke, e, t)
263
+ pdf: bn(S, Ke, e, t)
264
264
  };
265
265
  };
266
266
  L(F.equal(W(rn.SUN)), () => {
267
- let e = Ee(_, ie, Me(D, W(0), W(X + 5), O, T, E)).toVar(), t = De(e, _, re, ie).mul(ae).toVar(), n = I(e), r = nn(w, ie, n.pdf).toVar();
267
+ let e = De(_, ie, T(D, W(0), W(X + 5), k, C, w)).toVar(), t = Oe(e, _, re, ie).mul(ae).toVar(), n = I(e), r = nn(S, ie, n.pdf).toVar();
268
268
  L(t.x.add(t.y).add(t.z).greaterThan(0).and(r.greaterThan(0)), () => {
269
- A.assign(n.start), M.assign(e.negate()), N.assign(t.div(r)), ke.assign(Q(H(1).div(ie.y.mul(r)))), Ae.assign(Q(H(1).div(r))), ze.assign(!0);
269
+ j.assign(n.start), M.assign(e.negate()), N.assign(t.div(r)), Ae.assign(Q(H(1).div(ie.y.mul(r)))), je.assign(Q(H(1).div(r))), ze.assign(!0);
270
270
  });
271
271
  }).ElseIf(F.equal(W(rn.EMITTERS)), () => {
272
- let e = Oe(c, te, h, ve(D, W(0), W(X), O, T, E)).toVar(), t = te.add(e.mul(W(2))), n = c.element(t).toVar(), r = c.element(t.add(W(1))).toVar();
272
+ let e = ke(c, te, h, ve(D, W(0), W(X), k, C, w)).toVar(), t = te.add(e.mul(W(2))), n = c.element(t).toVar(), r = c.element(t.add(W(1))).toVar();
273
273
  Pe.assign(W(n.x)), Ie.assign(W(n.w));
274
- let i = Re.wrap(Ce(Pe, m, ee, Ie)).toVar(), a = Fe(i.v0, i.v1, i.v2, Me(D, W(0), W(X + 1), O, T, E)).toVar(), o = lt($e(i.v1.sub(i.v0), i.v2.sub(i.v0))).toVar(), u = Se(l(m, Pe, 4).z).toVar(), d = K(u.equal(W(1)).or(u.equal(W(2)).and(ve(D, W(0), W(X + 3), O, T, E).lessThan(.5))).toVar(), o.negate(), o).toVar();
275
- M.assign(xe(d, Me(D, W(0), W(X + 2), O, T, E)));
276
- let f = V(M, d).toVar(), p = G(n.y, 0).div(G(g, 1e-10)).div(G(r.w, 1e-20)).mul(K(u.equal(W(2)), H(.5), H(1))).mul(w.emitterPick).toVar(), _ = p.mul(f).div(Math.PI).toVar();
274
+ let i = Re.wrap(we(Pe, m, ee, Ie)).toVar(), a = Fe(i.v0, i.v1, i.v2, T(D, W(0), W(X + 1), k, C, w)).toVar(), o = lt($e(i.v1.sub(i.v0), i.v2.sub(i.v0))).toVar(), u = Ce(l(m, Pe, 4).z).toVar(), d = K(u.equal(W(1)).or(u.equal(W(2)).and(ve(D, W(0), W(X + 3), k, C, w).lessThan(.5))).toVar(), o.negate(), o).toVar();
275
+ M.assign(Se(d, T(D, W(0), W(X + 2), k, C, w)));
276
+ let f = V(M, d).toVar(), p = G(n.y, 0).div(G(g, 1e-10)).div(G(r.w, 1e-20)).mul(K(u.equal(W(2)), H(.5), H(1))).mul(S.emitterPick).toVar(), _ = p.mul(f).div(Math.PI).toVar();
277
277
  L(f.greaterThan(1e-6).and(_.greaterThan(0)), () => {
278
- A.assign(s(a, d)), N.assign(r.xyz.mul(ne).mul(Math.PI).div(p)), ke.assign(Q(H(1).div(_))), Ae.assign(Q(f.div(_))), Le.assign(f), ze.assign(!0);
278
+ j.assign(s(a, d)), N.assign(r.xyz.mul(ne).mul(Math.PI).div(p)), Ae.assign(Q(H(1).div(_))), je.assign(Q(f.div(_))), Le.assign(f), ze.assign(!0);
279
279
  });
280
280
  }).ElseIf(F.equal(W(rn.ENVIRONMENT)), () => {
281
- let e = me(se, ce, le, Me(D, W(0), W(X + 5), O, T, E)), t = e.direction.toVar(), n = e.pdf.toVar(), r = k({
281
+ let e = he(se, ce, le, T(D, W(0), W(X + 5), k, C, w)), t = e.direction.toVar(), n = e.pdf.toVar(), r = O({
282
282
  tex: oe,
283
283
  samp: ut(oe),
284
284
  direction: t,
285
285
  environmentMatrix: ce,
286
286
  environmentIntensity: ae,
287
287
  enableEnvironmentLight: H(1)
288
- }).xyz.toVar(), i = I(t), a = w.envPick.mul(n).mul(i.pdf).toVar();
288
+ }).xyz.toVar(), i = I(t), a = S.envPick.mul(n).mul(i.pdf).toVar();
289
289
  L(r.x.add(r.y).add(r.z).greaterThan(0).and(a.greaterThan(0)), () => {
290
- A.assign(i.start), M.assign(t.negate()), N.assign(r.div(a)), ke.assign(Q(n.div(a))), Ae.assign(Q(H(1).div(a))), Pe.assign(W(-1 - rn.ENVIRONMENT)), ze.assign(!0);
290
+ j.assign(i.start), M.assign(t.negate()), N.assign(r.div(a)), Ae.assign(Q(n.div(a))), je.assign(Q(H(1).div(a))), Pe.assign(W(-1 - rn.ENVIRONMENT)), ze.assign(!0);
291
291
  });
292
292
  }).ElseIf(F.greaterThanEqual(W(rn.LAMPS)), () => {
293
- let e = an(w, F).toVar(), t = sn(w, F).toVar(), n = cn(w, F, t).toVar();
293
+ let e = an(S, F).toVar(), t = sn(S, F).toVar(), n = cn(S, F, t).toVar();
294
294
  Pe.assign(W(-1).sub(F));
295
- let r = H(0).toVar(), i = Y(0).toVar(), a = Me(D, W(0), W(X + 2), O, T, E).toVar();
295
+ let r = H(0).toVar(), i = Y(0).toVar(), a = T(D, W(0), W(X + 2), k, C, w).toVar();
296
296
  L(t.equal(W(0)), () => {
297
- let t = We.wrap(x(ue, n)), a = lt(t.direction).toVar();
297
+ let t = Ge.wrap(fe(ue, n)), a = lt(t.direction).toVar();
298
298
  i.assign(t.color.mul(t.intensity)), r.assign(e), L(t.angle.greaterThan(0), () => {
299
299
  let e = Pt(t).toVar();
300
- a.assign(S(a, t.angle.mul(.5), Me(D, W(0), W(X + 5), O, T, E))), i.divAssign(e), r.divAssign(e);
300
+ a.assign(x(a, t.angle.mul(.5), T(D, W(0), W(X + 5), k, C, w))), i.divAssign(e), r.divAssign(e);
301
301
  });
302
302
  let o = I(a);
303
- r.mulAssign(o.pdf), A.assign(o.start), M.assign(a.negate());
303
+ r.mulAssign(o.pdf), j.assign(o.start), M.assign(a.negate());
304
304
  }).ElseIf(t.equal(W(1)), () => {
305
- let t = Ve.wrap(ye(y, n)), o = t.shape.greaterThan(.5), s = Me(D, W(0), W(X + 1), O, T, E).toVar(), c = ft(s.x), l = s.y.mul(2 * Math.PI);
306
- A.assign(t.position.add(t.u.mul(K(o, c.mul(Qe(l)), s.x.mul(2).sub(1)))).add(t.v.mul(K(o, c.mul(dt(l)), s.y.mul(2).sub(1))))), M.assign(xe(t.normal, a));
305
+ let t = Ve.wrap(be(y, n)), o = t.shape.greaterThan(.5), s = T(D, W(0), W(X + 1), k, C, w).toVar(), c = ft(s.x), l = s.y.mul(2 * Math.PI);
306
+ j.assign(t.position.add(t.u.mul(K(o, c.mul(Qe(l)), s.x.mul(2).sub(1)))).add(t.v.mul(K(o, c.mul(dt(l)), s.y.mul(2).sub(1))))), M.assign(Se(t.normal, a));
307
307
  let u = V(M, t.normal).toVar();
308
- i.assign(K(t.area.greaterThan(0).and(u.greaterThan(1e-6)), Te(t).mul(Ne(u, t.spread)).mul(u), Y(0))), r.assign(e.div(G(t.area, 1e-20)).mul(u).div(Math.PI)), Ae.assign(Q(u.div(G(r, 1e-30))));
308
+ i.assign(K(t.area.greaterThan(0).and(u.greaterThan(1e-6)), Ee(t).mul(Ne(u, t.spread)).mul(u), Y(0))), r.assign(e.div(G(t.area, 1e-20)).mul(u).div(Math.PI)), je.assign(Q(u.div(G(r, 1e-30))));
309
309
  }).ElseIf(t.equal(W(2)), () => {
310
- let t = we.wrap(He(de, n));
311
- A.assign(t.position), M.assign(S(Y(0, 1, 0), H(Math.PI), a)), i.assign(t.color.mul(t.intensity)), r.assign(e.div(4 * Math.PI));
310
+ let t = Te.wrap(He(de, n));
311
+ j.assign(t.position), M.assign(x(Y(0, 1, 0), H(Math.PI), a)), i.assign(t.color.mul(t.intensity)), r.assign(e.div(4 * Math.PI));
312
312
  }).Else(() => {
313
- let t = Ue.wrap(C(b, n));
314
- A.assign(t.position), M.assign(S(t.direction, t.angle, a));
313
+ let t = We.wrap(pe(b, n));
314
+ j.assign(t.position), M.assign(x(t.direction, t.angle, a));
315
315
  let o = M.negate();
316
- i.assign(t.color.mul(t.intensity).mul(be({
316
+ i.assign(t.color.mul(t.intensity).mul(xe({
317
317
  coneCosine: Qe(t.angle),
318
318
  blend: t.penumbra,
319
319
  angleCosine: V(M, t.direction)
320
- })).mul(je(t, o)).mul(_e(t, o))), r.assign(e.div(Nt(t)));
320
+ })).mul(Me(t, o)).mul(ye(t, o))), r.assign(e.div(Nt(t)));
321
321
  }), L(i.x.add(i.y).add(i.z).greaterThan(0).and(r.greaterThan(0)), () => {
322
- N.assign(i.div(r)), ke.assign(Q(H(1).div(r))), ze.assign(!0);
322
+ N.assign(i.div(r)), Ae.assign(Q(H(1).div(r))), ze.assign(!0);
323
323
  });
324
324
  }), L(ze.not(), () => {
325
325
  v(t, e, M, q(0)), R();
326
326
  });
327
327
  let z = G(G(G(N.x, N.y), N.z), 1e-20).toVar();
328
- i(t, e, A, W(0), W(0)), v(t, e, M, q(j.ACTIVE | j.REDIRECTED | j.LIGHT_PATH | j.LIGHT_EMITTED)), d(t, e, N.div(z), H(0)), f(t, e, _t(Y(0), H(1))), a(t, e, q(0), q(he), H(1), H(1), H(1)), p(n, e, O, ke, Ae), u(n, e, Pe, Ie, Le, z);
328
+ i(t, e, j, W(0), W(0)), v(t, e, M, q(A.ACTIVE | A.REDIRECTED | A.LIGHT_PATH | A.LIGHT_EMITTED)), d(t, e, N.div(z), H(0)), f(t, e, _t(Y(0), H(1))), a(t, e, q(0), q(ge), H(1), H(1), H(1)), p(n, e, k, Ae, je), u(n, e, Pe, Ie, Le, z);
329
329
  });
330
330
  }
331
331
  //#endregion
@@ -337,30 +337,30 @@ function En(e) {
337
337
  L(e.greaterThanEqual(B(i.element(q(P.ENTERING_COUNT)))), () => {
338
338
  R();
339
339
  });
340
- let x = r.element(e).toVar(), S = ee(x);
341
- L(c(n, S).notEqual(se), () => {
340
+ let fe = r.element(e).toVar(), x = ee(fe);
341
+ L(c(n, x).notEqual(se), () => {
342
342
  R();
343
343
  });
344
- let pe = o(n, S), C = {
344
+ let pe = o(n, x), S = {
345
345
  ...pe,
346
346
  vm: b?.(pe.position) ?? null
347
- }, w = W(C.extra).add(W(1)).toVar(), T = W(d.x), me = W(x).add(te.mul(T)), E = gt(H(me.mod(T)).add(.5), H(me.div(T)).add(.5)).toVar(), he = W(h).mul(W(32)), ge = fe({ state: re(n, x).bitXor(q(2654435769)) }).toVar(), _e = ve(E, W(0), he.add(W(16)), ge, d, p).toVar(), ye = ve(E, W(0), he.add(W(17)), ge, d, p).toVar(), be = st(q(H(g).mul(_e)), g.sub(q(1))).toVar().mul(_).toVar(), D = st(W(de(n, le(be), oe)), W(ce).add(W(1)).sub(w)).toVar();
348
- L(D.lessThan(W(1)), () => {
347
+ }, he = W(S.extra).add(W(1)).toVar(), C = W(d.x), w = W(fe).add(te.mul(C)), ge = gt(H(w.mod(C)).add(.5), H(w.div(C)).add(.5)).toVar(), _e = W(h).mul(W(32)), ye = me({ state: re(n, fe).bitXor(q(2654435769)) }).toVar(), T = ve(ge, W(0), _e.add(W(16)), ye, d, p).toVar(), be = ve(ge, W(0), _e.add(W(17)), ye, d, p).toVar(), xe = st(q(H(g).mul(T)), g.sub(q(1))).toVar().mul(_).toVar(), E = st(W(de(n, le(xe), oe)), W(ce).add(W(1)).sub(he)).toVar();
348
+ L(E.lessThan(W(1)), () => {
349
349
  R();
350
350
  });
351
- let xe = st(W(H(D).mul(ye)), D.sub(W(1))).toVar(), O = o(n, le(be.add(q(xe)))), k = {
352
- ...O,
353
- vm: b?.(O.position) ?? null
354
- }, Se = k.position.sub(C.position).toVar(), Ce = G(V(Se, Se), 1e-12).toVar(), j = Se.div(ft(Ce)).toVar(), we = V(j, C.N).toVar(), Te = V(j, C.facetN).toVar(), Ee = V(j, k.facetN).negate().toVar();
355
- L(we.lessThanEqual(0).or(Te.lessThanEqual(0)).or(Ee.lessThanEqual(0)), () => {
351
+ let Se = st(W(H(E).mul(be)), E.sub(W(1))).toVar(), D = o(n, le(xe.add(q(Se)))), O = {
352
+ ...D,
353
+ vm: b?.(D.position) ?? null
354
+ }, Ce = O.position.sub(S.position).toVar(), we = G(V(Ce, Ce), 1e-12).toVar(), A = Ce.div(ft(we)).toVar(), Te = V(A, S.N).toVar(), Ee = V(A, S.facetN).toVar(), De = V(A, O.facetN).negate().toVar();
355
+ L(Te.lessThanEqual(0).or(Ee.lessThanEqual(0)).or(De.lessThanEqual(0)), () => {
356
356
  R();
357
357
  });
358
- let De = ln(C.materialIndex, C.uv, C.N, u), M = ln(k.materialIndex, k.uv, k.N, u), N = j.negate(), Oe = Ae(C.V, j, C.N, De).toVar(), ke = Ae(N, k.V, k.N, M).toVar(), je = we.mul(un(k.V, k.N, k.facetN, N)).div(Ce), Me = F(C.V, j, C.N, De), Ne = F(j, C.V, C.N, De), Pe = F(k.V, N, k.N, M), Fe = F(N, k.V, k.N, M), Ie = Kt(Me.mul(Ee).div(Ce), k, Fe), Re = Kt(Pe.mul(Te).div(Ce), C, Ne), Be = w.add(xe).add(W(1)), Ve = $t(v, Qt.CONNECT, Zt(Ie, Re), H(1).div(H(Be.sub(W(1))))), He = ze(C.throughput.mul(Oe).mul(ke).mul(k.throughput).mul(je.mul(Ve).mul(H(D)).mul(ue)), H(Be.sub(W(1))), y, W(m)).toVar();
358
+ let Oe = ln(S.materialIndex, S.uv, S.N, u), j = ln(O.materialIndex, O.uv, O.N, u), M = A.negate(), ke = Ae(S.V, A, S.N, Oe).toVar(), N = Ae(M, O.V, O.N, j).toVar(), je = Te.mul(un(O.V, O.N, O.facetN, M)).div(we), Me = F(S.V, A, S.N, Oe), Ne = F(A, S.V, S.N, Oe), Pe = F(O.V, M, O.N, j), Fe = F(M, O.V, O.N, j), Ie = Kt(Me.mul(De).div(we), O, Fe), Re = Kt(Pe.mul(Ee).div(we), S, Ne), Be = he.add(Se).add(W(1)), Ve = $t(v, Qt.CONNECT, Zt(Ie, Re), H(1).div(H(Be.sub(W(1))))), He = ze(S.throughput.mul(ke).mul(N).mul(O.throughput).mul(je.mul(Ve).mul(H(E)).mul(ue)), H(Be.sub(W(1))), y, W(m)).toVar();
359
359
  L(ie(He).greaterThan(0), () => {
360
- let e = s(C.position, C.facetN).toVar(), n = s(k.position, k.facetN).sub(e).toVar(), r = it(n).toVar(), i = A(e, n.div(r), r.mul(ne), Le, a, l, u);
360
+ let e = s(S.position, S.facetN).toVar(), n = s(O.position, O.facetN).sub(e).toVar(), r = it(n).toVar(), i = k(e, n.div(r), r.mul(ne), Le, a, l, u);
361
361
  L(i.greaterThan(0), () => {
362
- let e = ae(t, x).toVar();
363
- f(t, x, _t(e.xyz.add(He.mul(i)), e.w));
362
+ let e = ae(t, fe).toVar();
363
+ f(t, fe, _t(e.xyz.add(He.mul(i)), e.w));
364
364
  });
365
365
  });
366
366
  });
@@ -405,15 +405,15 @@ function In(e) {
405
405
  L(c(i, se).notEqual(g), () => {
406
406
  R();
407
407
  });
408
- let v = o(i, se), ce = W(v.extra).toVar(), ue = W(p).add(W(1)).sub(ce).toVar(), y = ln(v.materialIndex, v.uv, v.N, u), de = Y(0).toVar(), b = qt(d, v.position).toVar(), fe = b.mul(b).toVar(), x = Jt(d, b).toVar(), S = x.mul(d.mergeTrust), pe = H(1).div(G(S.mul(S), 1e-30)).toVar(), C = it(v.position.sub(d.cameraPosition)).toVar(), w = An(d, G(d.mergeConst.add(d.mergeSlope.mul(G(C.sub(b), 0))), d.mergeMin)).toVar(), T = st(An(d, d.mergeConst.add(d.mergeSlope.mul(C.add(b)))), w.add(W(1))).toVar();
408
+ let v = o(i, se), ce = W(v.extra).toVar(), ue = W(p).add(W(1)).sub(ce).toVar(), y = ln(v.materialIndex, v.uv, v.N, u), de = Y(0).toVar(), b = qt(d, v.position).toVar(), fe = b.mul(b).toVar(), x = Jt(d, b).toVar(), pe = x.mul(d.mergeTrust), S = H(1).div(G(pe.mul(pe), 1e-30)).toVar(), me = it(v.position.sub(d.cameraPosition)).toVar(), he = An(d, G(d.mergeConst.add(d.mergeSlope.mul(G(me.sub(b), 0))), d.mergeMin)).toVar(), C = st(An(d, d.mergeConst.add(d.mergeSlope.mul(me.add(b)))), he.add(W(1))).toVar();
409
409
  qe({
410
410
  start: W(0),
411
411
  end: W(16),
412
412
  type: "int",
413
413
  condition: "<"
414
414
  }, ({ i: e }) => {
415
- let n = w.add(e.shiftRight(W(3))).toVar();
416
- L(n.greaterThan(T), () => {
415
+ let n = he.add(e.shiftRight(W(3))).toVar();
416
+ L(n.greaterThan(C), () => {
417
417
  Ke();
418
418
  });
419
419
  let a = jn(d, n).toVar(), s = e.bitAnd(W(7)), c = rt(tt(v.position.div(a).sub(.5))).add(rt(s.bitAnd(W(1)), s.shiftRight(W(1)).bitAnd(W(1)), s.shiftRight(W(2)))).toVar(), u = B(l.element(Mn(n, c, re))).toVar(), f = W(0).toVar();
@@ -424,7 +424,7 @@ function In(e) {
424
424
  L(t.shell.equal(n).and(t.cell.x.equal(c.x)).and(t.cell.y.equal(c.y)).and(t.cell.z.equal(c.z)), () => {
425
425
  let t = o(i, e), n = V(t.V, v.N).toVar(), r = V(t.V, v.facetN).toVar();
426
426
  L(n.greaterThan(0).and(r.greaterThan(0)), () => {
427
- let e = Ae(v.V, t.V, v.N, y), i = Xt(t, F(v.V, t.V, v.N, y), pe), a = Xt(v, F(t.V, v.V, v.N, y), pe), o = ce.add(l), s = $t(_, Qt.MERGE, Zt(i, a), H(1).div(H(o))), c = K(o.greaterThan(W(1)), m, H(1)), u = n.div(G(r, 1e-4));
427
+ let e = Ae(v.V, t.V, v.N, y), i = Xt(t, F(v.V, t.V, v.N, y), S), a = Xt(v, F(t.V, v.V, v.N, y), S), o = ce.add(l), s = $t(_, Qt.MERGE, Zt(i, a), H(1).div(H(o))), c = K(o.greaterThan(W(1)), m, H(1)), u = n.div(G(r, 1e-4));
428
428
  de.addAssign(ze(v.throughput.mul(e).mul(t.throughput).mul(s.mul(u).div(x).mul(c)), H(o.sub(W(1))), h, W(te)));
429
429
  });
430
430
  });
@@ -450,25 +450,25 @@ function Ln(e) {
450
450
  let ue = o(t, le(e)), y = {
451
451
  ...ue,
452
452
  vm: se?.(ue.position) ?? null
453
- }, b = p.sub(y.position).toVar(), x = G(V(b, b), 1e-12).toVar(), S = b.div(ft(x)).toVar(), pe = V(S, y.facetN).toVar(), C = V(S, m).negate().toVar();
454
- L(pe.lessThanEqual(0).or(C.lessThanEqual(1e-6)).or(y.extra.notEqual(q(0))), () => {
453
+ }, b = p.sub(y.position).toVar(), fe = G(V(b, b), 1e-12).toVar(), x = b.div(ft(fe)).toVar(), pe = V(x, y.facetN).toVar(), S = V(x, m).negate().toVar();
454
+ L(pe.lessThanEqual(0).or(S.lessThanEqual(1e-6)).or(y.extra.notEqual(q(0))), () => {
455
455
  R();
456
456
  });
457
- let w = h.mul(ee.mul(_t(y.position, 1))).toVar();
458
- L(w.w.lessThanEqual(0), () => {
457
+ let he = h.mul(ee.mul(_t(y.position, 1))).toVar();
458
+ L(he.w.lessThanEqual(0), () => {
459
459
  R();
460
460
  });
461
- let T = tt(w.x.div(w.w).mul(.5).add(.5).mul(H(g))).toVar(), me = tt(H(.5).sub(w.y.div(w.w).mul(.5)).mul(H(_))).toVar();
462
- L(T.lessThan(0).or(me.lessThan(0)).or(T.greaterThanEqual(H(g))).or(me.greaterThanEqual(H(_))), () => {
461
+ let C = tt(he.x.div(he.w).mul(.5).add(.5).mul(H(g))).toVar(), ge = tt(H(.5).sub(he.y.div(he.w).mul(.5)).mul(H(_))).toVar();
462
+ L(C.lessThan(0).or(ge.lessThan(0)).or(C.greaterThanEqual(H(g))).or(ge.greaterThanEqual(H(_))), () => {
463
463
  R();
464
464
  });
465
- let E = ln(y.materialIndex, y.uv, y.N, c), ge = Ae(S, y.V, y.N, E).toVar(), _e = H(1).div(te.mul(C).mul(C).mul(C)).div(x).toVar(), ve = Kt(_e.mul(pe).div(H(l)), y, F(S, y.V, y.N, E)), ye = v.add(q(1)), be = H(1).toVar();
466
- L(ye.greaterThan(q(1)), () => {
467
- be.assign(re);
465
+ let _e = ln(y.materialIndex, y.uv, y.N, c), ve = Ae(x, y.V, y.N, _e).toVar(), ye = H(1).div(te.mul(S).mul(S).mul(S)).div(fe).toVar(), T = Kt(ye.mul(pe).div(H(l)), y, F(x, y.V, y.N, _e)), be = v.add(q(1)), xe = H(1).toVar();
466
+ L(be.greaterThan(q(1)), () => {
467
+ xe.assign(re);
468
468
  });
469
- let D = ze(y.throughput.mul(ge).mul(un(y.V, y.N, y.facetN, S)).mul(_e.div(H(l)).mul($t(f, Qt.LIGHT_TRACE, Zt(ve, H(0)))).mul(be)), H(v), ie, W(ae)).toVar(), xe = s(y.position, y.facetN).toVar(), O = p.sub(xe).toVar(), k = it(O).toVar(), Se = A(xe, O.div(k), k.mul(ne), he, i, a, c);
470
- L(Se.greaterThan(0), () => {
471
- let t = st(n(D.mul(Se)), Y(zt)).mul(Rt).toVar(), i = H(fe({ state: e.bitXor(q(oe).mul(q(2654435769))) }).shiftRight(q(8))).mul(1 / 16777216).toVar(), a = q(me).mul(q(g)).add(q(T)).mul(q(3)).toVar();
469
+ let E = ze(y.throughput.mul(ve).mul(un(y.V, y.N, y.facetN, x)).mul(ye.div(H(l)).mul($t(f, Qt.LIGHT_TRACE, Zt(T, H(0)))).mul(xe)), H(v), ie, W(ae)).toVar(), Se = s(y.position, y.facetN).toVar(), D = p.sub(Se).toVar(), O = it(D).toVar(), Ce = k(Se, D.div(O), O.mul(ne), w, i, a, c);
470
+ L(Ce.greaterThan(0), () => {
471
+ let t = st(n(E.mul(Ce)), Y(zt)).mul(Rt).toVar(), i = H(me({ state: e.bitXor(q(oe).mul(q(2654435769))) }).shiftRight(q(8))).mul(1 / 16777216).toVar(), a = q(ge).mul(q(g)).add(q(C)).mul(q(3)).toVar();
472
472
  Je(r.element(a), q(tt(t.x.add(i)))), Je(r.element(a.add(q(1))), q(tt(t.y.add(i)))), Je(r.element(a.add(q(2))), q(tt(t.z.add(i))));
473
473
  });
474
474
  });
@@ -794,12 +794,12 @@ var { PASS_TAG_BIT: zn, STRATEGY: Bn, STRATEGY_ALONE: Vn, SOURCE: $, mergeVmAt:
794
794
  e.cameraPosition.value.set(a[12], a[13], a[14]), e.cameraForward.value.set(-a[8], -a[9], -a[10]).normalize();
795
795
  let o = this.pt.cameraProjectionMatrix.value.elements;
796
796
  e.pixelArea.value = 4 / (o[0] * o[5] * t * n);
797
- let s = this.pt.cameraProjection.value === Ge.perspective && !this.pt.enableDOF.value;
797
+ let s = this.pt.cameraProjection.value === E.perspective && !this.pt.enableDOF.value;
798
798
  return e.lightTrace.value = +!!s, this.merging && this._updateMergeRadius(t, n), !0;
799
799
  }
800
800
  _updateMergeRadius(e, t) {
801
801
  let n = this.uniforms, r = this._mergeRadiusPixels * (this.pt.frameCount + 1) ** ((Yn - 1) / 2), i = this.pt.cameraProjection.value, a = this.pt.cameraProjectionMatrix.value.elements, o = 0, s = 0;
802
- i === Ge.orthographic ? s = r * 2 / (a[5] * t) : o = i === Ge.equirectangular ? r * 2 * Math.PI / e : r * Math.sqrt(n.pixelArea.value), n.mergeSlope.value = Math.min(o, .1), n.mergeConst.value = s, n.mergeMin.value = Math.max(s, o * .001 * n.sceneRadius.value, 1e-9);
802
+ i === E.orthographic ? s = r * 2 / (a[5] * t) : o = i === E.equirectangular ? r * 2 * Math.PI / e : r * Math.sqrt(n.pixelArea.value), n.mergeSlope.value = Math.min(o, .1), n.mergeConst.value = s, n.mergeMin.value = Math.max(s, o * .001 * n.sceneRadius.value, 1e-9);
803
803
  }
804
804
  _sizeSourceTable() {
805
805
  let e = this.uniforms, t = $.LAMPS;
@@ -809,14 +809,14 @@ var { PASS_TAG_BIT: zn, STRATEGY: Bn, STRATEGY_ALONE: Vn, SOURCE: $, mergeVmAt:
809
809
  "point",
810
810
  "spot"
811
811
  ].forEach((n, r) => {
812
- e.sourceOffsets[r] = t, t += this.pt[`${n}LightsBufferNode`].array.length / D[n];
812
+ e.sourceOffsets[r] = t, t += this.pt[`${n}LightsBufferNode`].array.length / Ue[n];
813
813
  }), e.sourceCount = t, e.sourceCdf.array.length !== t && (e.sourceCdf.array = new Float32Array(t));
814
814
  }
815
815
  _updateSourceTable() {
816
816
  let e = this.uniforms, t = e.sourceCdf.array, n = new Float64Array(t.length), r = (e, t) => Math.max(.2126 * e[t] + .7152 * e[t + 1] + .0722 * e[t + 2], 0), i = (e) => ({
817
817
  a: this.pt[`${e}LightsBufferNode`].array,
818
818
  n: this.pt[`num${e[0].toUpperCase()}${e.slice(1)}Lights`].value,
819
- f: D[e]
819
+ f: Ue[e]
820
820
  }), a = i("directional"), o = this.pt.enableEnvironment.value > 0, s = this.pt.environment.exactTable;
821
821
  e.envTable.value = +!!s;
822
822
  let c = o && (this.pt.hasSun.value > 0 || s) || a.n > 0, l = c || this.merging ? this._sceneDisc() : 0, u = c ? l * Gn : 0;