rayzee 11.7.0 → 11.8.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 (59) hide show
  1. package/README.md +13 -0
  2. package/dist/{ArchiveImporter-DYcRXeKE.js → ArchiveImporter-_sJm5uaK.js} +1923 -1243
  3. package/dist/{BidirectionalIntegrator-BvjRpbTP.js → BidirectionalIntegrator-Dzt4Z97x.js} +290 -289
  4. package/dist/{ColorManagement-oeEk7oSu.js → ColorManagement-30MfpHwQ.js} +1 -1
  5. package/dist/{EngineIssues-CIZnXHsF.js → EngineIssues-xljoXM0E.js} +18 -8
  6. package/dist/{NeuralRetouch-ClaMiKYg.js → NeuralRetouch-BKQCsmEs.js} +2 -2
  7. package/dist/{NeuralSuperRes-WNEXun9s.js → NeuralSuperRes-C4ymq68e.js} +2 -2
  8. package/dist/{PathTracer-B9wZPPVL.js → PathTracer-C_to_i40.js} +3156 -3098
  9. package/dist/{PhysicalSky-DcjItqKi.js → PhysicalSky-bMHbm_7H.js} +1 -1
  10. package/dist/{RayzeeRenderer-p-NeE6E2.js → RayzeeRenderer-B_aB6VTJ.js} +370 -371
  11. package/dist/SceneMetadata-CSmlJW4c.js +183 -0
  12. package/dist/{ToneMapGPU-sAs8wdgI.js → ToneMapGPU-4GPwoG_c.js} +13 -6
  13. package/dist/addons/archives.es.js +1 -1
  14. package/dist/addons/bidirectional.es.js +1 -1
  15. package/dist/addons/color.es.js +1 -1
  16. package/dist/addons/physical-sky.es.js +1 -1
  17. package/dist/addons/storage.es.js +1 -1
  18. package/dist/{openStorage-Fe9BoS1_.js → openStorage-B085D9FR.js} +1 -1
  19. package/dist/rayzee-core.es.js +5 -5
  20. package/dist/rayzee.es.js +815 -796
  21. package/dist/rayzee.umd.js +106 -102
  22. package/dist/{sceneCachePolicy-B9w3BnaP.js → sceneCachePolicy-D_uBSbQF.js} +2 -2
  23. package/package.json +1 -1
  24. package/src/EngineIssues.js +20 -6
  25. package/src/Passes/AIUpscaler.js +4 -0
  26. package/src/Passes/OIDNDenoiser.js +8 -6
  27. package/src/PathTracerApp.js +10 -1
  28. package/src/Processor/ArchiveImporter.js +23 -6
  29. package/src/Processor/AssetLoader.js +15 -0
  30. package/src/Processor/LightSerializer.js +6 -2
  31. package/src/Processor/PBRT/PBRTMaterials.js +2 -1
  32. package/src/Processor/PBRT/PBRTSceneBuilder.js +1 -1
  33. package/src/Processor/PlatformImageLoader.js +9 -0
  34. package/src/Processor/TextureCreator.js +44 -4
  35. package/src/Processor/ToneMapCPU.js +34 -5
  36. package/src/Processor/ToneMapGPU.js +15 -9
  37. package/src/Processor/USD/USDScene.js +981 -17
  38. package/src/RayzeeRenderer.js +81 -26
  39. package/src/Stages/AutoExposure.js +21 -8
  40. package/src/Stages/Compositor.js +39 -1
  41. package/src/Stages/LocalExposure.js +44 -18
  42. package/src/Stages/NormalDepth.js +7 -3
  43. package/src/Stages/PathTracer.js +25 -1
  44. package/src/Stages/PathTracerStage.js +9 -1
  45. package/src/TSL/CameraRay.js +12 -1
  46. package/src/TSL/DebugKernel.js +3 -2
  47. package/src/TSL/FinalWriteKernel.js +4 -7
  48. package/src/TSL/GenerateKernel.js +6 -2
  49. package/src/TSL/LightSplatKernel.js +7 -4
  50. package/src/TSL/LightsCore.js +6 -2
  51. package/src/TSL/LightsSampling.js +45 -12
  52. package/src/TSL/SceneResources.js +11 -0
  53. package/src/TSL/ShadeKernel.js +1 -2
  54. package/src/integrators/BidirectionalIntegrator.js +1 -0
  55. package/src/managers/CameraManager.js +9 -0
  56. package/src/managers/DenoisingManager.js +1 -0
  57. package/src/managers/InteractionManager.js +6 -0
  58. package/src/managers/UniformManager.js +3 -1
  59. package/dist/SceneMetadata-D2Sh-0e-.js +0 -110
package/dist/rayzee.es.js CHANGED
@@ -1,38 +1,38 @@
1
- import { t as e } from "./BidirectionalIntegrator-BvjRpbTP.js";
1
+ import { t as e } from "./BidirectionalIntegrator-Dzt4Z97x.js";
2
2
  import { $t as t, Ft as n, Pt as r, Yt as i, en as a, nn as o, rt as s, wt as c } from "./SolarLimb-bZE6y63S.js";
3
- import { _ as l, a as u, c as d, d as f, f as p, g as m, h, i as g, l as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, u as T } from "./RayzeeRenderer-p-NeE6E2.js";
4
- import { $ as E, At as D, B as ee, Dt as O, Et as k, F as te, H as ne, I as re, J as ie, Ot as A, Q as ae, V as oe, W as se, _t as ce, dt as le, et as ue, ft as j, ht as de, it as fe, jt as pe, mt as me, nt as he, pt as ge, rt as _e, tt as ve, vt as ye, yt as be, z as xe } from "./PathTracer-B9wZPPVL.js";
5
- import { n as Se, t as M } from "./EngineEvents-CLckhYbL.js";
6
- import { D as Ce, G as we, J as Te, K as Ee, O as De, W as Oe, Y as ke, a as Ae, c as je, et as Me, i as Ne, m as Pe, ot as Fe, p as Ie, q as Le, r as Re, tt as ze, x as Be, y as Ve } from "./sceneCachePolicy-B9w3BnaP.js";
3
+ import { _ as l, a as u, c as d, d as f, f as p, g as m, h, i as g, l as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, u as T } from "./RayzeeRenderer-B_aB6VTJ.js";
4
+ import { $ as E, At as D, B as ee, F as O, H as te, I as ne, J as re, Mt as k, Nt as A, Ot as j, Q as ie, V as ae, W as oe, _t as se, at as ce, bt as le, dt as M, et as ue, gt as de, ht as fe, it as pe, kt as N, mt as me, nt as he, pt as ge, rt as _e, tt as ve, xt as ye, yt as be, z as xe } from "./PathTracer-C_to_i40.js";
5
+ import { n as Se, t as P } from "./EngineEvents-CLckhYbL.js";
6
+ import { D as Ce, G as we, J as Te, K as Ee, O as De, W as Oe, Y as ke, a as Ae, c as je, et as Me, i as Ne, m as Pe, ot as Fe, p as Ie, q as Le, r as Re, tt as ze, x as Be, y as Ve } from "./sceneCachePolicy-D_uBSbQF.js";
7
7
  import { i as He, n as Ue, r as We, t as Ge } from "./Logger-dDDGj9Av.js";
8
8
  import { f as Ke, r as qe } from "./BufferLayout-xPRH9jYD.js";
9
- import { i as Je, n as Ye, r as Xe, t as Ze } from "./EngineIssues-CIZnXHsF.js";
9
+ import { i as Je, n as Ye, r as Xe, t as Ze } from "./EngineIssues-xljoXM0E.js";
10
10
  import { i as Qe, r as $e } from "./shared-BGBcSxBQ.js";
11
11
  import { r as et } from "./WorkingMatrix-C6y233hT.js";
12
12
  import { i as tt, r as nt, t as rt } from "./ActiveColor-YvuQq44O.js";
13
13
  import { n as it, t as at } from "./AssetConfig-DSEntE65.js";
14
14
  import { a as ot, d as st, g as ct, i as lt, l as ut, o as dt, p as ft, r as pt, s as mt, t as ht, u as gt } from "./ViewTransforms-CYN7bq2w.js";
15
15
  import { a as _t, i as vt, n as yt, r as bt } from "./identity-C1cLD1C0.js";
16
- import { a as xt, n as St, r as Ct, t as wt } from "./SceneMetadata-D2Sh-0e-.js";
17
- import { t as Tt } from "./ToneMapGPU-sAs8wdgI.js";
16
+ import { l as xt, n as St, s as Ct, t as wt } from "./SceneMetadata-CSmlJW4c.js";
17
+ import { t as Tt } from "./ToneMapGPU-4GPwoG_c.js";
18
18
  import { t as Et } from "./FileFormats-sPGJeCRc.js";
19
- import { A as Dt, C as Ot, D as kt, E as At, O as jt, S as Mt, T as Nt, _ as Pt, a as Ft, b as It, c as Lt, d as Rt, f as zt, g as Bt, h as Vt, i as Ht, k as Ut, l as Wt, m as Gt, n as Kt, o as qt, p as Jt, r as Yt, s as Xt, t as Zt, u as Qt, v as $t, w as en, x as tn, y as nn } from "./ColorManagement-oeEk7oSu.js";
20
- import { c as rn, l as an, n as on, o as sn, t as cn } from "./openStorage-Fe9BoS1_.js";
19
+ import { A as Dt, C as Ot, D as kt, E as At, O as jt, S as Mt, T as Nt, _ as Pt, a as Ft, b as It, c as Lt, d as Rt, f as zt, g as Bt, h as Vt, i as Ht, k as Ut, l as Wt, m as Gt, n as Kt, o as qt, p as Jt, r as Yt, s as Xt, t as Zt, u as Qt, v as $t, w as en, x as tn, y as nn } from "./ColorManagement-30MfpHwQ.js";
20
+ import { c as rn, l as an, n as on, o as sn, t as cn } from "./openStorage-B085D9FR.js";
21
21
  import { n as ln, t as un } from "./ZipReader-gDSWr0I5.js";
22
- import { i as dn, n as fn, r as pn } from "./NeuralSuperRes-WNEXun9s.js";
23
- import { i as mn, n as hn, r as gn } from "./NeuralRetouch-ClaMiKYg.js";
22
+ import { i as dn, n as fn, r as pn } from "./NeuralSuperRes-C4ymq68e.js";
23
+ import { i as mn, n as hn, r as gn } from "./NeuralRetouch-BKQCsmEs.js";
24
24
  import { ExternalTexture as _n, MeshBasicNodeMaterial as vn, QuadMesh as yn, ReadbackBuffer as bn, RenderTarget as xn, StorageTexture as Sn, TextureNode as Cn, WebGPURenderer as wn } from "three/webgpu";
25
- import { Fn as Tn, If as N, Loop as En, Return as Dn, atan as On, atomicAdd as kn, atomicLoad as An, atomicStore as jn, attributeArray as Mn, dot as P, exp as Nn, exp2 as Pn, float as F, floatBitsToUint as Fn, floor as In, fract as Ln, int as I, ivec2 as Rn, localId as L, log2 as zn, max as R, min as Bn, mix as z, normalize as Vn, pow as Hn, round as Un, saturate as B, select as V, smoothstep as Wn, sqrt as Gn, storage as Kn, textureLoad as H, textureStore as U, toneMappingExposure as qn, uint as W, uniform as G, uvec2 as Jn, uvec4 as Yn, vec2 as K, vec3 as Xn, vec4 as q, workgroupArray as Zn, workgroupBarrier as Qn, workgroupId as J } from "three/tsl";
26
- import { ACESFilmicToneMapping as $n, AddEquation as er, AnimationMixer as tr, Box2 as nr, Box3 as rr, ClampToEdgeWrapping as ir, Color as ar, Controls as or, CustomBlending as sr, DataArrayTexture as cr, DataTexture as lr, EventDispatcher as ur, FloatType as dr, HalfFloatType as fr, InterpolateSmooth as pr, LinearFilter as mr, LoopOnce as hr, LoopRepeat as gr, MathUtils as _r, Matrix3 as vr, Matrix4 as Y, Mesh as yr, MeshBasicMaterial as br, NearestFilter as X, NoColorSpace as xr, NumberKeyframeTrack as Sr, OneFactor as Cr, OrthographicCamera as wr, PerspectiveCamera as Tr, PropertyBinding as Er, Quaternion as Dr, RGBAFormat as Or, Raycaster as kr, RedIntegerFormat as Ar, SRGBColorSpace as jr, Scene as Mr, SphereGeometry as Nr, Timer as Pr, UnsignedByteType as Fr, UnsignedIntType as Ir, Vector2 as Lr, Vector3 as Z, Vector4 as Rr, VectorKeyframeTrack as zr } from "three";
27
- import { OrbitControls as Br } from "three/addons/controls/OrbitControls.js";
28
- import { outline as Vr } from "three/addons/tsl/display/OutlineNode.js";
29
- import { TransformControls as Hr } from "three/addons/controls/TransformControls.js";
25
+ import { Fn as Tn, If as F, Loop as En, Return as Dn, atan as On, atomicAdd as kn, atomicLoad as An, atomicStore as jn, attributeArray as Mn, dot as I, exp as Nn, exp2 as Pn, float as L, floatBitsToUint as Fn, floor as In, fract as Ln, int as R, ivec2 as Rn, localId as z, log2 as zn, max as B, min as Bn, mix as V, normalize as Vn, pow as Hn, round as Un, saturate as H, select as U, smoothstep as Wn, sqrt as Gn, storage as Kn, textureLoad as W, textureStore as G, toneMappingExposure as qn, uint as K, uniform as q, uvec2 as Jn, uvec4 as Yn, vec2 as J, vec3 as Xn, vec4 as Y, workgroupArray as Zn, workgroupBarrier as Qn, workgroupId as X } from "three/tsl";
26
+ import { ACESFilmicToneMapping as $n, AddEquation as er, AnimationMixer as tr, Box2 as nr, Box3 as rr, ClampToEdgeWrapping as ir, Color as ar, Controls as or, CustomBlending as sr, DataArrayTexture as cr, DataTexture as lr, EventDispatcher as ur, FloatType as dr, HalfFloatType as fr, InterpolateSmooth as pr, LinearFilter as mr, LoopOnce as hr, LoopRepeat as gr, MathUtils as _r, Matrix3 as vr, Matrix4 as yr, Mesh as br, MeshBasicMaterial as xr, NearestFilter as Z, NoColorSpace as Sr, NumberKeyframeTrack as Cr, OneFactor as wr, OrthographicCamera as Tr, PerspectiveCamera as Er, PropertyBinding as Dr, Quaternion as Or, RGBAFormat as kr, Raycaster as Ar, RedIntegerFormat as jr, SRGBColorSpace as Mr, Scene as Nr, SphereGeometry as Pr, Timer as Fr, UnsignedByteType as Ir, UnsignedIntType as Lr, Vector2 as Rr, Vector3 as Q, Vector4 as zr, VectorKeyframeTrack as Br } from "three";
27
+ import { OrbitControls as Vr } from "three/addons/controls/OrbitControls.js";
28
+ import { outline as Hr } from "three/addons/tsl/display/OutlineNode.js";
29
+ import { TransformControls as Ur } from "three/addons/controls/TransformControls.js";
30
30
  //#region src/Stages/DenoiserSettings.js
31
- var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
31
+ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
32
32
  "none",
33
33
  "nrd",
34
34
  "oidn"
35
- ]), qr = 3, Jr = .1, Yr = {
35
+ ]), Jr = 3, Yr = .1, Xr = {
36
36
  maxAccumulatedFrameNum: 30,
37
37
  maxFastAccumulatedFrameNum: 6,
38
38
  maxStabilizedFrameNum: 63,
@@ -56,7 +56,7 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
56
56
  convergenceP: .8,
57
57
  lobeVolumePercent: .1,
58
58
  handoverFrames: 0
59
- }, Xr = [
59
+ }, Zr = [
60
60
  "maxAccumulatedFrameNum",
61
61
  "maxFastAccumulatedFrameNum",
62
62
  "maxStabilizedFrameNum",
@@ -64,7 +64,7 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
64
64
  "prepassBlurRadius",
65
65
  "maxBlurRadius",
66
66
  "enableAntiFirefly"
67
- ], Zr = {
67
+ ], Qr = {
68
68
  low: {
69
69
  maxAccumulatedFrameNum: 16,
70
70
  maxFastAccumulatedFrameNum: 4,
@@ -82,7 +82,7 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
82
82
  prepassBlurRadius: 40,
83
83
  maxBlurRadius: 40
84
84
  }
85
- }, Qr = {
85
+ }, $r = {
86
86
  denoiserStrategy: "none",
87
87
  enableOIDN: !1,
88
88
  oidnQuality: "fast",
@@ -95,26 +95,26 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
95
95
  upscalerHdr: !0,
96
96
  nrdQualityPreset: "medium",
97
97
  nrdDebugMode: 0
98
- }, $r = class extends D {
98
+ }, ei = class extends k {
99
99
  constructor(e, t = {}) {
100
100
  super("NormalDepth", {
101
101
  ...t,
102
- executionMode: pe.ALWAYS
103
- }), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = G(new Y(), "mat4"), this.cameraProjectionMatrixInverse = G(new Y(), "mat4"), this.cameraRay = ue(), this.resolutionWidth = G(t.width || 1), this.resolutionHeight = G(t.height || 1);
102
+ executionMode: A.ALWAYS
103
+ }), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = q(new yr(), "mat4"), this.cameraProjectionMatrixInverse = q(new yr(), "mat4"), this.cameraRay = ve(), this.resolutionWidth = q(t.width || 1), this.resolutionHeight = q(t.height || 1);
104
104
  let n = t.width || 1, r = t.height || 1;
105
- this._outputStorageTex = new Sn(O, O), this._outputStorageTex.type = fr, this._outputStorageTex.format = Or, this._outputStorageTex.minFilter = X, this._outputStorageTex.magFilter = X, this._shadingStorageTex = new Sn(O, O), this._shadingStorageTex.type = fr, this._shadingStorageTex.format = Or, this._shadingStorageTex.minFilter = X, this._shadingStorageTex.magFilter = X, this._shadingRT = new xn(n, r, {
105
+ this._outputStorageTex = new Sn(N, N), this._outputStorageTex.type = fr, this._outputStorageTex.format = kr, this._outputStorageTex.minFilter = Z, this._outputStorageTex.magFilter = Z, this._shadingStorageTex = new Sn(N, N), this._shadingStorageTex.type = fr, this._shadingStorageTex.format = kr, this._shadingStorageTex.minFilter = Z, this._shadingStorageTex.magFilter = Z, this._shadingRT = new xn(n, r, {
106
106
  type: fr,
107
- format: Or,
108
- minFilter: X,
109
- magFilter: X,
107
+ format: kr,
108
+ minFilter: Z,
109
+ magFilter: Z,
110
110
  depthBuffer: !1,
111
111
  stencilBuffer: !1
112
- }), this._leafStorageTex = null, this._leafRT = null, this._srcRegion = new nr(new Lr(0, 0), new Lr(0, 0));
112
+ }), this._leafStorageTex = null, this._leafRT = null, this._srcRegion = new nr(new Rr(0, 0), new Rr(0, 0));
113
113
  let i = {
114
114
  type: fr,
115
- format: Or,
116
- minFilter: X,
117
- magFilter: X,
115
+ format: kr,
116
+ minFilter: Z,
117
+ magFilter: Z,
118
118
  depthBuffer: !1,
119
119
  stencilBuffer: !1
120
120
  };
@@ -135,35 +135,38 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
135
135
  let t = e.sceneStorageNodes?.();
136
136
  t && (this._triStorageNode = t.triangles, this._bvhStorageNode = t.bvh);
137
137
  }
138
- return t && !this._matStorageNode && (this._matStorageNode = Kn(t, "vec4", t.count).toReadOnly()), this._linearBuckets && ne(this._linearBuckets, e.materialData?.linearBuckets), this._lastTriAttr = e.triangleGeoAttr || this._lastTriAttr, this._lastBvhAttr = e.bvhStorageAttr || this._lastBvhAttr, this._lastMatAttr = t || this._lastMatAttr, !!(this._triStorageNode && this._bvhStorageNode && this._matStorageNode);
138
+ return t && !this._matStorageNode && (this._matStorageNode = Kn(t, "vec4", t.count).toReadOnly()), this._linearBuckets && te(this._linearBuckets, e.materialData?.linearBuckets), this._lastTriAttr = e.triangleGeoAttr || this._lastTriAttr, this._lastBvhAttr = e.bvhStorageAttr || this._lastBvhAttr, this._lastMatAttr = t || this._lastMatAttr, !!(this._triStorageNode && this._bvhStorageNode && this._matStorageNode);
139
139
  }
140
140
  _buildCompute() {
141
141
  let e = this._triStorageNode, n = this._bvhStorageNode, r = this._matStorageNode;
142
- this._linearBuckets = te(this.pathTracer?.materialData?.linearBuckets);
142
+ this._linearBuckets = O(this.pathTracer?.materialData?.linearBuckets);
143
143
  let s = {
144
- srgbBuckets: te(null),
144
+ srgbBuckets: O(null),
145
145
  linearBuckets: this._linearBuckets,
146
146
  shadowAlbedoMaps: null,
147
147
  goboMaps: null,
148
148
  iesProfiles: null,
149
149
  alphaShadows: null
150
150
  }, l = this.cameraWorldMatrix, u = this.cameraProjectionMatrixInverse, d = this.resolutionWidth, f = this.resolutionHeight, p = this._outputStorageTex, m = this._shadingStorageTex, h = this._leafStorageTex;
151
- this._computeNode = ce(Tn(([s, l]) => {
152
- let u = I(J.x).mul(8).add(I(L.x)), g = I(J.y).mul(8).add(I(L.y));
153
- N(u.lessThan(I(d)).and(g.lessThan(I(f))), () => {
154
- let _ = t(ae(K(F(u).add(.5).div(d), F(g).add(.5).div(f)), s, l, this.cameraRay)), v = i.wrap(ie(_, n, e)), y = v.normal.mul(.5).add(.5), b = Bn(v.dst, F(65504)), x = v.didHit.select(q(y, b), q(0, 0, 0, F(Ur)));
155
- U(p, Jn(W(u), W(g)), x).toWriteOnly(), h && U(h, Jn(W(u), W(g)), Yn(W(v.instanceLeaf.add(1)), 0, 0, 0)).toWriteOnly();
156
- let S = v.normal.toVar(), C = F(1).toVar();
157
- N(v.didHit, () => {
158
- let t = a.wrap(c(v.materialIndex, r)).toVar(), i = o.wrap(re(v.uv, t)).toVar(), s = q(0).toVar();
159
- N(t.normalMapIndex.greaterThanEqual(I(0)), () => {
160
- s.assign(se(e, v.triangleIndex, v.normal, t.normalTransform, n, v.instanceLeaf));
151
+ this._computeNode = be(Tn(([s, l]) => {
152
+ let u = R(X.x).mul(8).add(R(z.x)), g = R(X.y).mul(8).add(R(z.y));
153
+ F(u.lessThan(R(d)).and(g.lessThan(R(f))), () => {
154
+ let _ = E(J(L(u).add(.5).div(d), L(g).add(.5).div(f)), s, l, this.cameraRay), v = _.direction.toVar(), y = ie(v, this.cameraRay.clipStart, s, this.cameraRay.cameraProjection).toVar(), b = t({
155
+ origin: _.origin.add(v.mul(y)),
156
+ direction: v
157
+ }), x = i.wrap(re(b, n, e)), S = x.normal.mul(.5).add(.5), C = Bn(x.dst.add(y), L(65504)), w = x.didHit.select(Y(S, C), Y(0, 0, 0, L(Wr)));
158
+ G(p, Jn(K(u), K(g)), w).toWriteOnly(), h && G(h, Jn(K(u), K(g)), Yn(K(x.instanceLeaf.add(1)), 0, 0, 0)).toWriteOnly();
159
+ let T = x.normal.toVar(), D = L(1).toVar();
160
+ F(x.didHit, () => {
161
+ let t = a.wrap(c(x.materialIndex, r)).toVar(), i = o.wrap(ne(x.uv, t)).toVar(), s = Y(0).toVar();
162
+ F(t.normalMapIndex.greaterThanEqual(R(0)), () => {
163
+ s.assign(oe(e, x.triangleIndex, x.normal, t.normalTransform, n, x.instanceLeaf));
161
164
  });
162
- let l = oe(v.normal, t, i, s).toVar();
163
- S.assign(xe(l, t, i)), C.assign(ee(t, i).y.clamp(.05, 1));
165
+ let l = ae(x.normal, t, i, s).toVar();
166
+ T.assign(xe(l, t, i)), D.assign(ee(t, i).y.clamp(.05, 1));
164
167
  });
165
- let w = v.didHit.select(q(S.mul(.5).add(.5), C), q(0, 0, 0, 1));
166
- U(m, Jn(W(u), W(g)), w).toWriteOnly();
168
+ let O = x.didHit.select(Y(T.mul(.5).add(.5), D), Y(0, 0, 0, 1));
169
+ G(m, Jn(K(u), K(g)), O).toWriteOnly();
167
170
  });
168
171
  })(l, u), s).compute([
169
172
  this._dispatchX,
@@ -209,17 +212,17 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
209
212
  reallocateReservedStorage() {
210
213
  this._computeNode?.dispose(), this._computeNode = null, this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose();
211
214
  let e = () => {
212
- let e = new Sn(O, O);
213
- return e.type = fr, e.format = Or, e.minFilter = X, e.magFilter = X, e;
215
+ let e = new Sn(N, N);
216
+ return e.type = fr, e.format = kr, e.minFilter = Z, e.magFilter = Z, e;
214
217
  };
215
218
  this._outputStorageTex = e(), this._shadingStorageTex = e(), this._leafStorageTex &&= (this._leafStorageTex.dispose(), this._makeLeafStorage()), this._computeBuilt = !1;
216
219
  }
217
220
  setInstanceLeafOutput(e) {
218
221
  e = !!e, e !== !!this._leafStorageTex && (this._computeNode?.dispose(), this._computeNode = null, this._computeBuilt = !1, this._dirty = !0, e ? (this._leafStorageTex = this._makeLeafStorage(), this._leafRT = new xn(this._rtA.width, this._rtA.height, {
219
- type: Ir,
220
- format: Ar,
221
- minFilter: X,
222
- magFilter: X,
222
+ type: Lr,
223
+ format: jr,
224
+ minFilter: Z,
225
+ magFilter: Z,
223
226
  depthBuffer: !1,
224
227
  stencilBuffer: !1
225
228
  })) : (this._leafStorageTex.dispose(), this._leafRT.dispose(), this._leafStorageTex = null, this._leafRT = null));
@@ -228,24 +231,24 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
228
231
  this._leafRT ? e.setTexture("pathtracer:instanceLeaf", this._leafRT.texture) : e.getTexture("pathtracer:instanceLeaf") && e.removeTexture("pathtracer:instanceLeaf");
229
232
  }
230
233
  _makeLeafStorage() {
231
- let e = new Sn(O, O);
232
- return e.type = Ir, e.format = Ar, e.minFilter = X, e.magFilter = X, e;
234
+ let e = new Sn(N, N);
235
+ return e.type = Lr, e.format = jr, e.minFilter = Z, e.magFilter = Z, e;
233
236
  }
234
237
  dispose() {
235
238
  this._computeNode?.dispose(), this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose(), this._shadingRT?.dispose(), this._leafStorageTex?.dispose(), this._leafRT?.dispose(), this._rtA?.dispose(), this._rtB?.dispose();
236
239
  }
237
- }, ei = class extends D {
240
+ }, ti = class extends k {
238
241
  constructor(e, t, n = {}) {
239
242
  super("MotionVector", {
240
243
  ...n,
241
- executionMode: pe.ALWAYS
244
+ executionMode: A.ALWAYS
242
245
  }), this.renderer = e, this.camera = t, this.pathTracer = n.pathTracer || null;
243
246
  let r = n.width || 1, i = n.height || 1;
244
- this.prevViewProjectionMatrix = new Y(), this.currentViewProjectionMatrix = new Y(), this.matricesInitialized = !1, this.cameraWorldMatrix = G(new Y(), "mat4"), this.cameraProjectionMatrixInverse = G(new Y(), "mat4"), this.cameraRay = ue(), this.prevVP = G(new Y(), "mat4"), this.resolutionWidth = G(r), this.resolutionHeight = G(i), this._normalDepthTexNode = new Cn(), this._screenSpaceStorageTex = new Sn(O, O), this._screenSpaceStorageTex.type = fr, this._screenSpaceStorageTex.format = Or, this._screenSpaceStorageTex.minFilter = X, this._screenSpaceStorageTex.magFilter = X, this._srcRegion = new nr(new Lr(0, 0), new Lr(0, 0)), this.screenSpaceTarget = new xn(r, i, {
247
+ this.prevViewProjectionMatrix = new yr(), this.currentViewProjectionMatrix = new yr(), this.matricesInitialized = !1, this.cameraWorldMatrix = q(new yr(), "mat4"), this.cameraProjectionMatrixInverse = q(new yr(), "mat4"), this.cameraRay = ve(), this.prevVP = q(new yr(), "mat4"), this.resolutionWidth = q(r), this.resolutionHeight = q(i), this._normalDepthTexNode = new Cn(), this._screenSpaceStorageTex = new Sn(N, N), this._screenSpaceStorageTex.type = fr, this._screenSpaceStorageTex.format = kr, this._screenSpaceStorageTex.minFilter = Z, this._screenSpaceStorageTex.magFilter = Z, this._srcRegion = new nr(new Rr(0, 0), new Rr(0, 0)), this.screenSpaceTarget = new xn(r, i, {
245
248
  type: fr,
246
- format: Or,
247
- minFilter: X,
248
- magFilter: X,
249
+ format: kr,
250
+ minFilter: Z,
251
+ magFilter: Z,
249
252
  depthBuffer: !1,
250
253
  stencilBuffer: !1
251
254
  }), this._dispatchX = Math.ceil(r / 16), this._dispatchY = Math.ceil(i / 16), this._buildScreenSpaceCompute();
@@ -253,13 +256,13 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
253
256
  _buildScreenSpaceCompute() {
254
257
  let e = this._normalDepthTexNode, t = this.cameraWorldMatrix, n = this.cameraProjectionMatrixInverse, r = this.prevVP, i = this.resolutionWidth, a = this.resolutionHeight, o = this._screenSpaceStorageTex;
255
258
  this._screenSpaceComputeNode = Tn(([t, n]) => {
256
- let s = I(J.x).mul(16).add(I(L.x)), c = I(J.y).mul(16).add(I(L.y));
257
- N(s.lessThan(I(i)).and(c.lessThan(I(a))), () => {
258
- let l = H(e, Rn(s, c)).w, u = K(F(s).add(.5).div(i), F(c).add(.5).div(a)), d = q(0, 0, l, 1).toVar();
259
- N(l.lessThan(F(6e4)), () => {
260
- let e = E(u, l, t, n, this.cameraRay), i = r.mul(q(e, 1)), a = i.xy.div(i.w), o = K(a.x.mul(.5).add(.5), a.y.mul(-.5).add(.5)), s = u.sub(o), c = o.x.greaterThanEqual(0).and(o.x.lessThanEqual(1)).and(o.y.greaterThanEqual(0)).and(o.y.lessThanEqual(1));
261
- d.assign(c.select(q(s, l, 1), q(F(1e3), F(1e3), l, 0)));
262
- }), U(o, Jn(W(s), W(c)), d).toWriteOnly();
259
+ let s = R(X.x).mul(16).add(R(z.x)), c = R(X.y).mul(16).add(R(z.y));
260
+ F(s.lessThan(R(i)).and(c.lessThan(R(a))), () => {
261
+ let l = W(e, Rn(s, c)).w, u = J(L(s).add(.5).div(i), L(c).add(.5).div(a)), d = Y(0, 0, l, 1).toVar();
262
+ F(l.lessThan(L(6e4)), () => {
263
+ let e = ue(u, l, t, n, this.cameraRay), i = r.mul(Y(e, 1)), a = i.xy.div(i.w), o = J(a.x.mul(.5).add(.5), a.y.mul(-.5).add(.5)), s = u.sub(o), c = o.x.greaterThanEqual(0).and(o.x.lessThanEqual(1)).and(o.y.greaterThanEqual(0)).and(o.y.lessThanEqual(1));
264
+ d.assign(c.select(Y(s, l, 1), Y(L(1e3), L(1e3), l, 0)));
265
+ }), G(o, Jn(K(s), K(c)), d).toWriteOnly();
263
266
  });
264
267
  })(t, n).compute([
265
268
  this._dispatchX,
@@ -301,13 +304,13 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
301
304
  }
302
305
  reallocateReservedStorage() {
303
306
  this._screenSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose();
304
- let e = new Sn(O, O);
305
- e.type = fr, e.format = Or, e.minFilter = X, e.magFilter = X, this._screenSpaceStorageTex = e, this._buildScreenSpaceCompute();
307
+ let e = new Sn(N, N);
308
+ e.type = fr, e.format = kr, e.minFilter = Z, e.magFilter = Z, this._screenSpaceStorageTex = e, this._buildScreenSpaceCompute();
306
309
  }
307
310
  dispose() {
308
311
  this._screenSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this.screenSpaceTarget?.dispose(), this._normalDepthTexNode?.dispose();
309
312
  }
310
- }, ti = 1e-6, ni = 1.5 / 255, ri = .01, ii = 3, ai = 2, oi = 2, si = 3, ci = 2, li = 38, ui = .1, di = 4, fi = Math.cos(89 * Math.PI / 180), pi = .5, Q = 16, mi = {
313
+ }, ni = 1e-6, ri = 1.5 / 255, ii = .01, ai = 3, oi = 2, si = 2, ci = 3, li = 2, ui = 38, di = .1, fi = 4, pi = Math.cos(89 * Math.PI / 180), mi = .5, hi = 16, gi = {
311
314
  pre: {
312
315
  radiusScale: 1,
313
316
  fractionScale: 2
@@ -320,7 +323,7 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
320
323
  radiusScale: 2,
321
324
  fractionScale: .5
322
325
  }
323
- }, hi = .25 * Math.SQRT2, gi = [
326
+ }, _i = .25 * Math.SQRT2, vi = [
324
327
  [
325
328
  -1,
326
329
  0,
@@ -342,62 +345,62 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
342
345
  1
343
346
  ],
344
347
  [
345
- -hi,
346
- hi,
348
+ -_i,
349
+ _i,
347
350
  .5
348
351
  ],
349
352
  [
350
- hi,
351
- hi,
353
+ _i,
354
+ _i,
352
355
  .5
353
356
  ],
354
357
  [
355
- hi,
356
- -hi,
358
+ _i,
359
+ -_i,
357
360
  .5
358
361
  ],
359
362
  [
360
- -hi,
361
- -hi,
363
+ -_i,
364
+ -_i,
362
365
  .5
363
366
  ]
364
- ], _i = (e, t, n) => Wn(0, 1, F(1).sub(e.mul(t).add(n).abs())), vi = (e, t, n) => {
365
- let r = e.mul(t).add(n).abs().mul(-ii);
366
- return F(1).div(r.mul(r).sub(r).add(1));
367
- }, yi = (e) => z(F(1.570796), F(1.395402), B(e)).mul(Gn(B(F(1).sub(e)))), bi = (e, t) => F(1).sub(Pn(e.mul(e).mul(-200))).mul(Hn(B(e), t)), xi = (e, t) => B(e).mul(Gn(t.div(F(1).sub(t).add(ti)))), Si = (e, t, n, r) => {
368
- let i = R(On(xi(n, r.mul(z(B(t), F(1), e)))), F(ni));
369
- return F(1).div(i);
370
- }, Ci = (e, t) => {
371
- let n = F(1).div(z(F(ri), F(1), B(e.mul(t))));
372
- return K(n, e.mul(n).negate());
373
- }, wi = (e, t, n) => {
374
- let r = F(1).div(z(F(n), F(1), z(e.mul(e), e, B(t))));
375
- return K(r, e.mul(r).negate());
367
+ ], yi = (e, t, n) => Wn(0, 1, L(1).sub(e.mul(t).add(n).abs())), bi = (e, t, n) => {
368
+ let r = e.mul(t).add(n).abs().mul(-ai);
369
+ return L(1).div(r.mul(r).sub(r).add(1));
370
+ }, xi = (e) => V(L(1.570796), L(1.395402), H(e)).mul(Gn(H(L(1).sub(e)))), Si = (e, t) => L(1).sub(Pn(e.mul(e).mul(-200))).mul(Hn(H(e), t)), Ci = (e, t) => H(e).mul(Gn(t.div(L(1).sub(t).add(ni)))), wi = (e, t, n, r) => {
371
+ let i = B(On(Ci(n, r.mul(V(H(t), L(1), e)))), L(ri));
372
+ return L(1).div(i);
376
373
  }, Ti = (e, t) => {
377
- let n = F(1).div(t);
378
- return K(n, e.mul(n).negate());
379
- }, Ei = (e, t, n, r) => {
380
- let i = F(1).div(e.mul(t));
381
- return K(i, P(r, n).mul(i).negate());
382
- }, Di = (e) => K(1).sub(K(1).sub(Ln(e.mul(.5)).mul(2)).abs()).min(.99999), Oi = (e) => Xn(P(e, Xn(.25, .5, .25)), P(e, Xn(.5, 0, -.5)), P(e, Xn(-.25, .5, -.25))), ki = (e) => {
374
+ let n = L(1).div(V(L(ii), L(1), H(e.mul(t))));
375
+ return J(n, e.mul(n).negate());
376
+ }, Ei = (e, t, n) => {
377
+ let r = L(1).div(V(L(n), L(1), V(e.mul(e), e, H(t))));
378
+ return J(r, e.mul(r).negate());
379
+ }, Di = (e, t) => {
380
+ let n = L(1).div(t);
381
+ return J(n, e.mul(n).negate());
382
+ }, Oi = (e, t, n, r) => {
383
+ let i = L(1).div(e.mul(t));
384
+ return J(i, I(r, n).mul(i).negate());
385
+ }, ki = (e) => J(1).sub(J(1).sub(Ln(e.mul(.5)).mul(2)).abs()).min(.99999), Ai = (e) => Xn(I(e, Xn(.25, .5, .25)), I(e, Xn(.5, 0, -.5)), I(e, Xn(-.25, .5, -.25))), ji = (e) => {
383
386
  let t = e.x.sub(e.z);
384
- return R(Xn(t.add(e.y), e.x.add(e.z), t.sub(e.y)), Xn(0));
385
- }, Ai = (e, t) => t.add(ti).div(e.add(ti)), ji = (e, t) => q(e.xyz.mul(Ai(e.x, t)), e.w), Mi = (e) => q(Oi(ki(e.xyz)), B(e.w)), Ni = (e, t) => Gn(t.sub(e.mul(e)).abs()), Pi = (e, t) => K(e.x.mul(t.x).add(e.y.mul(t.y)), e.z.mul(t.x).add(e.w.mul(t.y))), Fi = (e, t) => V(e.equal(0), q(0), t);
386
- function Ii(e) {
387
+ return B(Xn(t.add(e.y), e.x.add(e.z), t.sub(e.y)), Xn(0));
388
+ }, Mi = (e, t) => t.add(ni).div(e.add(ni)), Ni = (e, t) => Y(e.xyz.mul(Mi(e.x, t)), e.w), Pi = (e) => Y(Ai(ji(e.xyz)), H(e.w)), Fi = (e, t) => Gn(t.sub(e.mul(e)).abs()), Ii = (e, t) => J(e.x.mul(t.x).add(e.y.mul(t.y)), e.z.mul(t.x).add(e.w.mul(t.y))), Li = (e, t) => U(e.equal(0), Y(0), t);
389
+ function Ri(e) {
387
390
  let t = Math.imul(e | 0, 2654435761) >>> 0;
388
391
  return t ^= t >>> 15, t = Math.imul(t, 2246822507) >>> 0, t ^= t >>> 13, t = Math.imul(t, 3266489909) >>> 0, t ^= t >>> 16, t / 4294967296;
389
392
  }
390
- var Li = class extends D {
393
+ var zi = class extends k {
391
394
  constructor(e, t = {}) {
392
395
  super("NRD", {
393
396
  ...t,
394
- executionMode: pe.PER_CYCLE
397
+ executionMode: A.PER_CYCLE
395
398
  }), this.renderer = e, this.pathTracer = t.pathTracer || null, this.settings = {
396
- ...Yr,
399
+ ...Xr,
397
400
  ...t.settings || {}
398
- }, this._releaseHitDistance = this.pathTracer?.requestOutput?.("hitDistance", { encode: (e, t) => e.div(R(t.mul(.1).add(3), F(1e-4))).clamp(0, 1) }) ?? null;
401
+ }, this._releaseHitDistance = this.pathTracer?.requestOutput?.("hitDistance", { encode: (e, t) => e.div(B(t.mul(.1).add(3), L(1e-4))).clamp(0, 1) }) ?? null;
399
402
  let n = t.width || 1, r = t.height || 1;
400
- this.resW = G(n), this.resH = G(r), this.minRectDimMulUnproject = G(1), this.inputFrames = G(0), this.resetU = G(0), this.debugMode = G(0, "int"), this.rotPre = G(new Rr(1, 0, 0, 1), "vec4"), this.rotBlur = G(new Rr(1, 0, 0, 1), "vec4"), this.rotPost = G(new Rr(1, 0, 0, 1), "vec4"), this.camWorld = G(new Y(), "mat4"), this.camProjInv = G(new Y(), "mat4"), this.camView = G(new Y(), "mat4"), this.prevCamView = G(new Y(), "mat4"), this.camPos = G(new Z(), "vec3"), this.prevCamPos = G(new Z(), "vec3"), this.viewVector = G(new Z(), "vec3"), this.prevViewVector = G(new Z(), "vec3"), this.cameraRay = ue(), this.u = {};
403
+ this.resW = q(n), this.resH = q(r), this.minRectDimMulUnproject = q(1), this.inputFrames = q(0), this.resetU = q(0), this.debugMode = q(0, "int"), this.rotPre = q(new zr(1, 0, 0, 1), "vec4"), this.rotBlur = q(new zr(1, 0, 0, 1), "vec4"), this.rotPost = q(new zr(1, 0, 0, 1), "vec4"), this.camWorld = q(new yr(), "mat4"), this.camProjInv = q(new yr(), "mat4"), this.camView = q(new yr(), "mat4"), this.prevCamView = q(new yr(), "mat4"), this.camPos = q(new Q(), "vec3"), this.prevCamPos = q(new Q(), "vec3"), this.viewVector = q(new Q(), "vec3"), this.prevViewVector = q(new Q(), "vec3"), this.cameraRay = ve(), this.u = {};
401
404
  for (let e of [
402
405
  "maxAccum",
403
406
  "maxFast",
@@ -417,25 +420,25 @@ var Li = class extends D {
417
420
  "disocclusionThreshold",
418
421
  "lobeVolumePercent",
419
422
  "handoverFrames"
420
- ]) this.u[e] = G(0);
421
- this.u.antilag = G(new Lr(), "vec2"), this.u.convergence = G(new Z(), "vec3"), this._syncUniforms(), this._colorTexNode = new Cn(), this._albedoTexNode = new Cn(), this._ndTexNode = new Cn(), this._snTexNode = new Cn(), this._motionTexNode = new Cn(), this._placeholders = /* @__PURE__ */ new Map();
423
+ ]) this.u[e] = q(0);
424
+ this.u.antilag = q(new Rr(), "vec2"), this.u.convergence = q(new Q(), "vec3"), this._syncUniforms(), this._colorTexNode = new Cn(), this._albedoTexNode = new Cn(), this._ndTexNode = new Cn(), this._snTexNode = new Cn(), this._motionTexNode = new Cn(), this._placeholders = /* @__PURE__ */ new Map();
422
425
  let i = () => {
423
- let e = new lr(new Float32Array(4), 1, 1, Or, dr);
426
+ let e = new lr(new Float32Array(4), 1, 1, kr, dr);
424
427
  e.needsUpdate = !0;
425
428
  let t = new Cn(e);
426
429
  return this._placeholders.set(t, e), t;
427
430
  };
428
- this._nTmpA = i(), this._nTmpB = i(), this._nHist = i(), this._nFast = i(), this._nInternal = i(), this._nGeom = i(), this._nData = i(), this._nStabRead = i(), this._allocStorage(), this._srcRegion = new nr(new Lr(0, 0), new Lr(0, 0)), this.outputTarget = new xn(n, r, {
431
+ this._nTmpA = i(), this._nTmpB = i(), this._nHist = i(), this._nFast = i(), this._nInternal = i(), this._nGeom = i(), this._nData = i(), this._nStabRead = i(), this._allocStorage(), this._srcRegion = new nr(new Rr(0, 0), new Rr(0, 0)), this.outputTarget = new xn(n, r, {
429
432
  type: fr,
430
- format: Or,
433
+ format: kr,
431
434
  minFilter: mr,
432
435
  magFilter: mr,
433
436
  depthBuffer: !1,
434
437
  stencilBuffer: !1
435
- }), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n / Q), this._dispatchY = Math.ceil(r / Q), this._buildKernels();
438
+ }), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n / hi), this._dispatchY = Math.ceil(r / hi), this._buildKernels();
436
439
  }
437
440
  _allocStorage() {
438
- let e = () => A(fr);
441
+ let e = () => D(fr);
439
442
  this._tmpA = e(), this._tmpB = e(), this._hist = e(), this._fastHist = e(), this._internal = e(), this._geomPrev = e(), this._stabA = e(), this._stabB = e(), this._dataT = e();
440
443
  }
441
444
  _disposeStorage() {
@@ -456,7 +459,7 @@ var Li = class extends D {
456
459
  }
457
460
  updateParameters(e) {
458
461
  if (e) {
459
- for (let t of Object.keys(e)) t === "debugMode" ? this.debugMode.value = e.debugMode | 0 : t in Yr && (this.settings[t] = e[t]);
462
+ for (let t of Object.keys(e)) t === "debugMode" ? this.debugMode.value = e.debugMode | 0 : t in Xr && (this.settings[t] = e[t]);
460
463
  this._syncUniforms();
461
464
  }
462
465
  }
@@ -467,32 +470,32 @@ var Li = class extends D {
467
470
  t.fastClampSigmaScale.value = 3 + (e.fastHistoryClampingSigmaScale - 3) * a, t.fireflyMinRelativeScale.value = e.fireflySuppressorMinRelativeScale, t.antiFirefly.value = +!!e.enableAntiFirefly, t.antilag.value.set(e.antilagLuminanceSigmaScale, e.antilagLuminanceSensitivity), t.disocclusionThreshold.value = e.disocclusionThreshold, t.convergence.value.set(e.convergenceS, e.convergenceB, e.convergenceP), t.lobeVolumePercent.value = e.lobeVolumePercent, t.handoverFrames.value = e.handoverFrames > 0 ? e.handoverFrames : 2 * n;
468
471
  }
469
472
  _worldPosAt(e, t, n, r) {
470
- return E(e, t, n, r, this.cameraRay);
473
+ return ue(e, t, n, r, this.cameraRay);
471
474
  }
472
475
  _viewVector(e, t, n) {
473
- return V(ve(this.cameraRay.cameraProjection), n, Vn(t.sub(e)));
476
+ return U(he(this.cameraRay.cameraProjection), n, Vn(t.sub(e)));
474
477
  }
475
478
  _frustumSize(e) {
476
- return this.minRectDimMulUnproject.mul(V(ve(this.cameraRay.cameraProjection), F(1), e));
479
+ return this.minRectDimMulUnproject.mul(U(he(this.cameraRay.cameraProjection), L(1), e));
477
480
  }
478
481
  _pixelUv(e, t) {
479
- return K(F(e).add(.5).div(this.resW), F(t).add(.5).div(this.resH));
482
+ return J(L(e).add(.5).div(this.resW), L(t).add(.5).div(this.resH));
480
483
  }
481
484
  _clampCoord(e, t) {
482
- return Rn(e.clamp(I(0), I(this.resW).sub(1)), t.clamp(I(0), I(this.resH).sub(1)));
485
+ return Rn(e.clamp(R(0), R(this.resW).sub(1)), t.clamp(R(0), R(this.resH).sub(1)));
483
486
  }
484
487
  _uvToCoord(e) {
485
- return this._clampCoord(I(e.x.mul(this.resW)), I(e.y.mul(this.resH)));
488
+ return this._clampCoord(R(e.x.mul(this.resW)), R(e.y.mul(this.resH)));
486
489
  }
487
490
  _advancedNonLinear(e) {
488
- let t = this.u.convergence, n = B(e.div(F(1).add(this.u.maxAccum.mul(t.z)))), r = t.x.mul(z(t.y, F(1), n));
489
- return F(1).div(F(1).add(r.mul(e)));
491
+ let t = this.u.convergence, n = H(e.div(L(1).add(this.u.maxAccum.mul(t.z)))), r = t.x.mul(V(t.y, L(1), n));
492
+ return L(1).div(L(1).add(r.mul(e)));
490
493
  }
491
494
  _handover(e) {
492
- return B(e.div(R(this.u.handoverFrames, 1)));
495
+ return H(e.div(B(this.u.handoverFrames, 1)));
493
496
  }
494
497
  _bilinear(e) {
495
- let t = e.mul(K(this.resW, this.resH)).sub(.5), n = In(t), r = B(t.sub(n)), i = I(n.x), a = I(n.y), o = (e, t) => V(e.greaterThanEqual(I(0)).and(t.greaterThanEqual(I(0))).and(e.lessThan(I(this.resW))).and(t.lessThan(I(this.resH))), F(1), F(0));
498
+ let t = e.mul(J(this.resW, this.resH)).sub(.5), n = In(t), r = H(t.sub(n)), i = R(n.x), a = R(n.y), o = (e, t) => U(e.greaterThanEqual(R(0)).and(t.greaterThanEqual(R(0))).and(e.lessThan(R(this.resW))).and(t.lessThan(R(this.resH))), L(1), L(0));
496
499
  return {
497
500
  f: r,
498
501
  taps: [
@@ -508,22 +511,22 @@ var Li = class extends D {
508
511
  o(i.add(1), a.add(1))
509
512
  ],
510
513
  customWeights: (e) => [
511
- e[0].mul(F(1).sub(r.x)).mul(F(1).sub(r.y)),
512
- e[1].mul(r.x).mul(F(1).sub(r.y)),
513
- e[2].mul(F(1).sub(r.x)).mul(r.y),
514
+ e[0].mul(L(1).sub(r.x)).mul(L(1).sub(r.y)),
515
+ e[1].mul(r.x).mul(L(1).sub(r.y)),
516
+ e[2].mul(L(1).sub(r.x)).mul(r.y),
514
517
  e[3].mul(r.x).mul(r.y)
515
518
  ],
516
- filter: (e) => z(z(e[0], e[1], r.x), z(e[2], e[3], r.x), r.y)
519
+ filter: (e) => V(V(e[0], e[1], r.x), V(e[2], e[3], r.x), r.y)
517
520
  };
518
521
  }
519
522
  _applyCustomWeights(e, t, n) {
520
523
  let r = e[0].mul(t[0]).add(e[1].mul(t[1])).add(e[2].mul(t[2])).add(e[3].mul(t[3])), i = t[0].add(t[1]).add(t[2]).add(t[3]);
521
- return V(i.lessThan(1e-4), n, r.div(R(i, 1e-4)));
524
+ return U(i.lessThan(1e-4), n, r.div(B(i, 1e-4)));
522
525
  }
523
526
  _sampleHistory(e, t, n, r, i) {
524
- let a = q(0).toVar();
525
- return N(i, () => {
526
- let n = B(t).mul(K(this.resW, this.resH)), r = In(n.sub(.5)).add(.5), i = B(n.sub(r)), o = pi, s = i.mul(i.mul(i.mul(-o).add(2 * o)).sub(o)), c = i.mul(i.mul(i.mul(2 - o).sub(3 - o))).add(1), l = i.mul(i.mul(i.mul(-(2 - o)).add(3 - 2 * o)).add(o)), u = i.mul(i.mul(i.mul(o).sub(o))), d = [
527
+ let a = Y(0).toVar();
528
+ return F(i, () => {
529
+ let n = H(t).mul(J(this.resW, this.resH)), r = In(n.sub(.5)).add(.5), i = H(n.sub(r)), o = mi, s = i.mul(i.mul(i.mul(-o).add(2 * o)).sub(o)), c = i.mul(i.mul(i.mul(2 - o).sub(3 - o))).add(1), l = i.mul(i.mul(i.mul(-(2 - o)).add(3 - 2 * o)).add(o)), u = i.mul(i.mul(i.mul(o).sub(o))), d = [
527
530
  s.x,
528
531
  c.x,
529
532
  l.x,
@@ -533,15 +536,15 @@ var Li = class extends D {
533
536
  c.y,
534
537
  l.y,
535
538
  u.y
536
- ], p = I(r.x).sub(1), m = I(r.y).sub(1), h = q(0).toVar(), g = F(0).toVar();
539
+ ], p = R(r.x).sub(1), m = R(r.y).sub(1), h = Y(0).toVar(), g = L(0).toVar();
537
540
  for (let t = 0; t < 4; t++) for (let n = 0; n < 4; n++) {
538
541
  if ((n === 0 || n === 3) && (t === 0 || t === 3)) continue;
539
542
  let r = d[n].mul(f[t]);
540
543
  h.addAssign(e(this._clampCoord(p.add(n), m.add(t))).mul(r)), g.addAssign(r);
541
544
  }
542
- a.assign(V(g.lessThan(1e-4), q(0), h.div(R(g, 1e-4))));
545
+ a.assign(U(g.lessThan(1e-4), Y(0), h.div(B(g, 1e-4))));
543
546
  }).Else(() => {
544
- a.assign(this._applyCustomWeights(n.taps.map((t) => e(t)), r, q(0)));
547
+ a.assign(this._applyCustomWeights(n.taps.map((t) => e(t)), r, Y(0)));
545
548
  }), a;
546
549
  }
547
550
  _buildKernels() {
@@ -561,119 +564,119 @@ var Li = class extends D {
561
564
  this._dispatchY,
562
565
  1
563
566
  ], [
564
- Q,
565
- Q,
567
+ hi,
568
+ hi,
566
569
  1
567
570
  ]);
568
571
  }
569
572
  _buildSpatial(e) {
570
- let t = e === "pre", { radiusScale: i, fractionScale: a } = mi[e], o = this.u, c = this._colorTexNode, l = this._albedoTexNode, u = this._ndTexNode, d = this._snTexNode, f = this._nData, p = e === "blur" ? this._nTmpA : this._nTmpB, m = e === "blur" ? this._tmpB : t ? this._tmpA : this._hist, h = this._geomPrev, g = t ? this.rotPre : e === "blur" ? this.rotBlur : this.rotPost, _ = t ? o.prepassBlurRadius : o.maxBlurRadius, v = this.camView, y = this.camPos, b = this.resW, x = this.resH, S = this.inputFrames, C = t ? (e) => {
571
- let t = H(c, e), i = H(l, e);
572
- return q(Oi(n(t.xyz.div(R(i.xyz, Xn(Gr))))), r(i.w, s).min(1));
573
- } : (e) => H(p, e), w = Tn(([n, r]) => {
574
- let s = I(J.x).mul(Q).add(I(L.x)), c = I(J.y).mul(Q).add(I(L.y));
575
- N(s.lessThan(I(b)).and(c.lessThan(I(x))), () => {
576
- let l = Rn(s, c), p = Jn(W(s), W(c)), w = H(u, l).w.toVar(), T = w.greaterThanEqual(Wr), E = H(d, l).toVar(), D = Vn(E.xyz.mul(2).sub(1)).toVar(), ee = E.w.clamp(.05, 1).toVar(), O = F(Wr).toVar(), k = C(l).toVar();
577
- N(T.not(), () => {
573
+ let t = e === "pre", { radiusScale: i, fractionScale: a } = gi[e], o = this.u, c = this._colorTexNode, l = this._albedoTexNode, u = this._ndTexNode, d = this._snTexNode, f = this._nData, p = e === "blur" ? this._nTmpA : this._nTmpB, m = e === "blur" ? this._tmpB : t ? this._tmpA : this._hist, h = this._geomPrev, g = t ? this.rotPre : e === "blur" ? this.rotBlur : this.rotPost, _ = t ? o.prepassBlurRadius : o.maxBlurRadius, v = this.camView, y = this.camPos, b = this.resW, x = this.resH, S = this.inputFrames, C = t ? (e) => {
574
+ let t = W(c, e), i = W(l, e);
575
+ return Y(Ai(n(t.xyz.div(B(i.xyz, Xn(Kr))))), r(i.w, s).min(1));
576
+ } : (e) => W(p, e), w = Tn(([n, r]) => {
577
+ let s = R(X.x).mul(hi).add(R(z.x)), c = R(X.y).mul(hi).add(R(z.y));
578
+ F(s.lessThan(R(b)).and(c.lessThan(R(x))), () => {
579
+ let l = Rn(s, c), p = Jn(K(s), K(c)), w = W(u, l).w.toVar(), T = w.greaterThanEqual(Gr), E = W(d, l).toVar(), D = Vn(E.xyz.mul(2).sub(1)).toVar(), ee = E.w.clamp(.05, 1).toVar(), O = L(Gr).toVar(), te = C(l).toVar();
580
+ F(T.not(), () => {
578
581
  let e = this._pixelUv(s, c), p = this._worldPosAt(e, w, n, r).toVar();
579
- O.assign(v.mul(q(p, 1)).z.abs()), N(_.greaterThan(0), () => {
580
- let s = P(D, this._viewVector(p, y, this.viewVector)).abs().toVar(), c = this._frustumSize(O).toVar(), m = S.add(1), h = t ? R(S, F(10)) : H(f, l).y.add(S), w = (t ? F(1).div(h.add(1)) : this._advancedNonLinear(h)).toVar(), T = bi(ee, .5).toVar(), E = O.mul(Jr).add(3), te = k.w.toVar(), ne = B(te.mul(E).div(c)), re = F(1).sub(this._handover(m)), ie = (t ? ne.div(m) : ne.mul(w)).mul(re), A = o.minBlurRadius.mul(B(F(2).sub(h.div(R(o.maxAccum, 1))))), ae = R(B(Gn(B(ie)).mul(i)).mul(_).mul(T), A.mul(T)).toVar(), oe = Ei(o.planeDistSensitivity, c, p, D).toVar(), se = Si(w, o.lobeAngleFraction, ee, o.lobeVolumePercent).div(a).toVar(), ce = Ci(ee, o.roughnessFraction.mul(a)).toVar(), le = Ti(te, w).toVar(), ue = o.minHitDistanceWeight.mul(a).mul(T);
581
- t || (ue = ue.mul(w)), ue = ue.toVar();
582
- let j = K(1);
582
+ O.assign(v.mul(Y(p, 1)).z.abs()), F(_.greaterThan(0), () => {
583
+ let s = I(D, this._viewVector(p, y, this.viewVector)).abs().toVar(), c = this._frustumSize(O).toVar(), m = S.add(1), h = t ? B(S, L(10)) : W(f, l).y.add(S), w = (t ? L(1).div(h.add(1)) : this._advancedNonLinear(h)).toVar(), T = Si(ee, .5).toVar(), E = O.mul(Yr).add(3), ne = te.w.toVar(), re = H(ne.mul(E).div(c)), k = L(1).sub(this._handover(m)), A = (t ? re.div(m) : re.mul(w)).mul(k), j = o.minBlurRadius.mul(H(L(2).sub(h.div(B(o.maxAccum, 1))))), ie = B(H(Gn(H(A)).mul(i)).mul(_).mul(T), j.mul(T)).toVar(), ae = Oi(o.planeDistSensitivity, c, p, D).toVar(), oe = wi(w, o.lobeAngleFraction, ee, o.lobeVolumePercent).div(a).toVar(), se = Ti(ee, o.roughnessFraction.mul(a)).toVar(), ce = Di(ne, w).toVar(), le = o.minHitDistanceWeight.mul(a).mul(T);
584
+ t || (le = le.mul(w)), le = le.toVar();
585
+ let M = J(1);
583
586
  if (!t) {
584
- let e = v.mul(q(D, 0)).xy;
585
- j = z(K(1).sub(e.abs()), K(1), s), j = j.div(R(j.x, j.y));
587
+ let e = v.mul(Y(D, 0)).xy;
588
+ M = V(J(1).sub(e.abs()), J(1), s), M = M.div(B(M.x, M.y));
586
589
  }
587
- let de = j.mul(K(F(1).div(b), F(1).div(x))).mul(ae).toVar(), fe = F(1).toVar();
588
- for (let t = 0; t < gi.length; t++) {
589
- let i = gi[t], a = e.add(Pi(g, K(i[0], i[1])).mul(de)), o = Di(a), s = V(o.x.notEqual(a.x).or(o.y.notEqual(a.y)), F(1), F(Math.exp(-.66 * i[2] * i[2]))).toVar(), c = this._uvToCoord(o), l = H(u, c).w, f = this._worldPosAt(o, l, n, r), p = H(d, c), m = yi(P(D, Vn(p.xyz.mul(2).sub(1))));
590
- s.mulAssign(_i(m, se, F(0))), s.mulAssign(_i(p.w, ce.x, ce.y)), s.mulAssign(_i(P(D, f), oe.x, oe.y)), s.assign(V(l.greaterThanEqual(Wr), F(0), s));
591
- let h = Fi(s, C(c));
592
- s.mulAssign(ue.add(vi(h.w, le.x, le.y))), fe.addAssign(s), k.addAssign(h.mul(s));
590
+ let ue = M.mul(J(L(1).div(b), L(1).div(x))).mul(ie).toVar(), de = L(1).toVar();
591
+ for (let t = 0; t < vi.length; t++) {
592
+ let i = vi[t], a = e.add(Ii(g, J(i[0], i[1])).mul(ue)), o = ki(a), s = U(o.x.notEqual(a.x).or(o.y.notEqual(a.y)), L(1), L(Math.exp(-.66 * i[2] * i[2]))).toVar(), c = this._uvToCoord(o), l = W(u, c).w, f = this._worldPosAt(o, l, n, r), p = W(d, c), m = xi(I(D, Vn(p.xyz.mul(2).sub(1))));
593
+ s.mulAssign(yi(m, oe, L(0))), s.mulAssign(yi(p.w, se.x, se.y)), s.mulAssign(yi(I(D, f), ae.x, ae.y)), s.assign(U(l.greaterThanEqual(Gr), L(0), s));
594
+ let h = Li(s, C(c));
595
+ s.mulAssign(le.add(bi(h.w, ce.x, ce.y))), de.addAssign(s), te.addAssign(h.mul(s));
593
596
  }
594
- k.divAssign(R(fe, 1e-6)), t || k.assign(q(k.xyz, te));
597
+ te.divAssign(B(de, 1e-6)), t || te.assign(Y(te.xyz, ne));
595
598
  });
596
- }), U(m, p, k).toWriteOnly(), e === "post" && U(h, p, q(D, O)).toWriteOnly();
599
+ }), G(m, p, te).toWriteOnly(), e === "post" && G(h, p, Y(D, O)).toWriteOnly();
597
600
  });
598
601
  });
599
602
  return this._dispatchOf(w);
600
603
  }
601
604
  _buildTemporalAccumulation() {
602
605
  let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._motionTexNode, i = this._nTmpA, a = this._nHist, o = this._nFast, s = this._nInternal, c = this._nGeom, l = this._tmpB, u = this._dataT, d = this.camView, f = this.prevCamView, p = this.camPos, m = this.prevCamPos, h = this.resW, g = this.resH, _ = this.inputFrames, v = this.resetU, y = Tn(([y, b]) => {
603
- let x = I(J.x).mul(Q).add(I(L.x)), S = I(J.y).mul(Q).add(I(L.y));
604
- N(x.lessThan(I(h)).and(S.lessThan(I(g))), () => {
605
- let h = Rn(x, S), g = Jn(W(x), W(S)), C = H(t, h).w, w = H(i, h).toVar();
606
- N(C.greaterThanEqual(Wr), () => {
607
- U(l, g, w).toWriteOnly(), U(u, g, q(0)).toWriteOnly(), Dn();
606
+ let x = R(X.x).mul(hi).add(R(z.x)), S = R(X.y).mul(hi).add(R(z.y));
607
+ F(x.lessThan(R(h)).and(S.lessThan(R(g))), () => {
608
+ let h = Rn(x, S), g = Jn(K(x), K(S)), C = W(t, h).w, w = W(i, h).toVar();
609
+ F(C.greaterThanEqual(Gr), () => {
610
+ G(l, g, w).toWriteOnly(), G(u, g, Y(0)).toWriteOnly(), Dn();
608
611
  });
609
- let T = e.maxAccum.mul(F(1).sub(v)).toVar(), E = e.maxFast.mul(F(1).sub(v)).toVar(), D = H(n, h), ee = Vn(D.xyz.mul(2).sub(1)).toVar(), O = D.w.clamp(.05, 1).toVar(), k = this._pixelUv(x, S), te = this._worldPosAt(k, C, y, b).toVar(), ne = d.mul(q(te, 1)).z.abs().toVar(), re = P(ee, this._viewVector(te, p, this.viewVector)).abs().toVar(), ie = this._frustumSize(ne).toVar(), A = Xn(0).toVar();
610
- A.addAssign(ee.mul(.25));
612
+ let T = e.maxAccum.mul(L(1).sub(v)).toVar(), E = e.maxFast.mul(L(1).sub(v)).toVar(), D = W(n, h), ee = Vn(D.xyz.mul(2).sub(1)).toVar(), O = D.w.clamp(.05, 1).toVar(), te = this._pixelUv(x, S), ne = this._worldPosAt(te, C, y, b).toVar(), re = d.mul(Y(ne, 1)).z.abs().toVar(), k = I(ee, this._viewVector(ne, p, this.viewVector)).abs().toVar(), A = this._frustumSize(re).toVar(), j = Xn(0).toVar();
613
+ j.addAssign(ee.mul(.25));
611
614
  for (let e = -1; e <= 0; e++) for (let r = -1; r <= 0; r++) {
612
615
  if (r === 0 && e === 0) continue;
613
- let i = this._clampCoord(x.add(r), S.add(e)), a = Vn(H(n, i).xyz.mul(2).sub(1)), o = H(t, i).w.lessThan(Wr);
614
- A.addAssign(V(o, a, ee).mul(.25));
616
+ let i = this._clampCoord(x.add(r), S.add(e)), a = Vn(W(n, i).xyz.mul(2).sub(1)), o = W(t, i).w.lessThan(Gr);
617
+ j.addAssign(U(o, a, ee).mul(.25));
615
618
  }
616
- let ae = H(r, h), oe = k.sub(ae.xy).toVar(), se = f.mul(q(te, 1)).z.abs().toVar(), ce = this._bilinear(oe), le = ie.mul(B(e.disocclusionThreshold.div(R(re, .05)))).sub(ti).toVar(), ue = F(1).sub(v), j = [], de = [];
619
+ let ie = W(r, h), ae = te.sub(ie.xy).toVar(), oe = f.mul(Y(ne, 1)).z.abs().toVar(), se = this._bilinear(ae), ce = A.mul(H(e.disocclusionThreshold.div(B(k, .05)))).sub(ni).toVar(), le = L(1).sub(v), M = [], ue = [];
617
620
  for (let e = 0; e < 4; e++) {
618
- let t = H(c, ce.taps[e]), n = V(P(t.xyz, A).greaterThan(fi), F(1), F(0)), r = V(t.w.sub(se).abs().lessThanEqual(le), F(1), F(0)), i = V(t.w.lessThan(Wr), F(1), F(0));
619
- j.push(n.mul(r).mul(i).mul(ce.inScreen[e]).mul(ue).toVar()), de.push(H(s, ce.taps[e]).x);
621
+ let t = W(c, se.taps[e]), n = U(I(t.xyz, j).greaterThan(pi), L(1), L(0)), r = U(t.w.sub(oe).abs().lessThanEqual(ce), L(1), L(0)), i = U(t.w.lessThan(Gr), L(1), L(0));
622
+ M.push(n.mul(r).mul(i).mul(se.inScreen[e]).mul(le).toVar()), ue.push(W(s, se.taps[e]).x);
620
623
  }
621
- let fe = ce.customWeights(j).map((e) => e.toVar()), pe = j[0].add(j[1]).add(j[2]).add(j[3]).greaterThan(3.5).toVar(), me = j[0].add(j[1].mul(2)).add(j[2].mul(4)).add(j[3].mul(8)), he = this._applyCustomWeights(de, fe, F(0)).toVar(), ge = P(ee, this._viewVector(te, m, this.prevViewVector)).abs().add(.001).div(re.add(.001)).toVar();
622
- ge.assign(z(F(.1), F(1), B(ge.mul(ge))));
623
- let _e = Gn(B(ce.filter(j))).mul(ge).toVar();
624
- he.assign(he.mul(z(_e, F(1), F(1).div(he.add(1))))), he.assign(Bn(he, T));
625
- let ve = Mi(this._sampleHistory((e) => H(a, e), oe, ce, fe, pe)).toVar(), ye = R(this._applyCustomWeights(ce.taps.map((e) => H(o, e).x), fe, F(0)), 0).toVar(), be = _.add(1), xe = this._handover(be).toVar(), Se = he.mul(F(1).sub(xe)), M = be.div(be.add(Se)).toVar(), Ce = F(1).div(F(1).add(bi(O, .25).mul(.5).mul(T))), we = q(z(ve.xyz, w.xyz, M), z(ve.w, w.w, R(M, Ce))).toVar(), Te = e.fireflyMinRelativeScale.add(F(li).div(he.add(1))).toVar(), Ee = he.mul(e.maxBlurRadius).mul(ui).toVar();
626
- Ee.assign(Ee.div(Ee.add(1)).mul(F(1).sub(xe)));
627
- let De = z(we.x, Bn(we.x, ve.x.mul(Te)), Ee);
628
- we.assign(ji(we, De));
629
- let Oe = F(1.2).add(F(1).div(he.add(1)));
630
- we.assign(q(we.xyz, z(we.w, Bn(we.w, ve.w.mul(Oe)), Ee))), U(l, g, we).toWriteOnly();
631
- let ke = Bn(he, E).mul(F(1).sub(xe)), Ae = be.div(be.add(ke)), je = z(ye, w.x, Ae).toVar(), Me = Bn(je, ve.x.mul(Te).mul(di));
632
- je.assign(z(je, Me, Ee)), U(u, g, q(je, he, me, V(pe, F(1), F(0)))).toWriteOnly();
624
+ let de = se.customWeights(M).map((e) => e.toVar()), fe = M[0].add(M[1]).add(M[2]).add(M[3]).greaterThan(3.5).toVar(), pe = M[0].add(M[1].mul(2)).add(M[2].mul(4)).add(M[3].mul(8)), N = this._applyCustomWeights(ue, de, L(0)).toVar(), me = I(ee, this._viewVector(ne, m, this.prevViewVector)).abs().add(.001).div(k.add(.001)).toVar();
625
+ me.assign(V(L(.1), L(1), H(me.mul(me))));
626
+ let he = Gn(H(se.filter(M))).mul(me).toVar();
627
+ N.assign(N.mul(V(he, L(1), L(1).div(N.add(1))))), N.assign(Bn(N, T));
628
+ let ge = Pi(this._sampleHistory((e) => W(a, e), ae, se, de, fe)).toVar(), _e = B(this._applyCustomWeights(se.taps.map((e) => W(o, e).x), de, L(0)), 0).toVar(), ve = _.add(1), ye = this._handover(ve).toVar(), be = N.mul(L(1).sub(ye)), xe = ve.div(ve.add(be)).toVar(), Se = L(1).div(L(1).add(Si(O, .25).mul(.5).mul(T))), P = Y(V(ge.xyz, w.xyz, xe), V(ge.w, w.w, B(xe, Se))).toVar(), Ce = e.fireflyMinRelativeScale.add(L(ui).div(N.add(1))).toVar(), we = N.mul(e.maxBlurRadius).mul(di).toVar();
629
+ we.assign(we.div(we.add(1)).mul(L(1).sub(ye)));
630
+ let Te = V(P.x, Bn(P.x, ge.x.mul(Ce)), we);
631
+ P.assign(Ni(P, Te));
632
+ let Ee = L(1.2).add(L(1).div(N.add(1)));
633
+ P.assign(Y(P.xyz, V(P.w, Bn(P.w, ge.w.mul(Ee)), we))), G(l, g, P).toWriteOnly();
634
+ let De = Bn(N, E).mul(L(1).sub(ye)), Oe = ve.div(ve.add(De)), ke = V(_e, w.x, Oe).toVar(), Ae = Bn(ke, ge.x.mul(Ce).mul(fi));
635
+ ke.assign(V(ke, Ae, we)), G(u, g, Y(ke, N, pe, U(fe, L(1), L(0)))).toWriteOnly();
633
636
  });
634
637
  });
635
638
  return this._dispatchOf(y);
636
639
  }
637
640
  _buildHistoryFix() {
638
641
  let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._nTmpB, i = this._nData, a = this._tmpA, o = this._fastHist, s = this.camView, c = this.resW, l = this.resH, u = this.inputFrames, d = Tn(([d, f]) => {
639
- let p = I(J.x).mul(Q).add(I(L.x)), m = I(J.y).mul(Q).add(I(L.y));
640
- N(p.lessThan(I(c)).and(m.lessThan(I(l))), () => {
641
- let h = Rn(p, m), g = Jn(W(p), W(m)), _ = H(t, h).w;
642
- N(_.greaterThanEqual(Wr), () => {
643
- let e = H(r, h);
644
- U(a, g, e).toWriteOnly(), U(o, g, q(e.x, 0, 0, 0)).toWriteOnly(), Dn();
642
+ let p = R(X.x).mul(hi).add(R(z.x)), m = R(X.y).mul(hi).add(R(z.y));
643
+ F(p.lessThan(R(c)).and(m.lessThan(R(l))), () => {
644
+ let h = Rn(p, m), g = Jn(K(p), K(m)), _ = W(t, h).w;
645
+ F(_.greaterThanEqual(Gr), () => {
646
+ let e = W(r, h);
647
+ G(a, g, e).toWriteOnly(), G(o, g, Y(e.x, 0, 0, 0)).toWriteOnly(), Dn();
645
648
  });
646
- let v = H(i, h).toVar(), y = v.y.toVar(), b = y.add(u), x = this._handover(u.add(1)).toVar(), S = H(n, h), C = Vn(S.xyz.mul(2).sub(1)).toVar(), w = S.w.clamp(.05, 1).toVar(), T = this._pixelUv(p, m), E = this._worldPosAt(T, _, d, f).toVar(), D = s.mul(q(E, 1)).z.abs(), ee = this._frustumSize(D).toVar(), O = H(r, h).toVar(), k = F(1).div(b.add(1)).toVar(), te = D.mul(Jr).add(3), ne = B(O.w.mul(te).div(ee)), re = O.w.toVar(), ie = Un(V(b.lessThan(e.historyFixFrameNum), F(1), F(0)).mul(.5).mul(2 / ai).mul(e.historyFixStride).mul(z(F(.25).add(Gn(ne).mul(.75)), F(1), k))).toVar();
647
- N(ie.notEqual(0), () => {
648
- let a = Si(k, e.lobeAngleFraction, w, e.lobeVolumePercent).toVar(), o = Ei(e.planeDistSensitivity, ee, E, C).toVar(), s = Ti(re, k).toVar(), u = wi(w.mul(w), Gn(e.roughnessFraction), ri).toVar(), p = F(1).add(y).toVar();
649
+ let v = W(i, h).toVar(), y = v.y.toVar(), b = y.add(u), x = this._handover(u.add(1)).toVar(), S = W(n, h), C = Vn(S.xyz.mul(2).sub(1)).toVar(), w = S.w.clamp(.05, 1).toVar(), T = this._pixelUv(p, m), E = this._worldPosAt(T, _, d, f).toVar(), D = s.mul(Y(E, 1)).z.abs(), ee = this._frustumSize(D).toVar(), O = W(r, h).toVar(), te = L(1).div(b.add(1)).toVar(), ne = D.mul(Yr).add(3), re = H(O.w.mul(ne).div(ee)), k = O.w.toVar(), A = Un(U(b.lessThan(e.historyFixFrameNum), L(1), L(0)).mul(.5).mul(2 / oi).mul(e.historyFixStride).mul(V(L(.25).add(Gn(re).mul(.75)), L(1), te))).toVar();
650
+ F(A.notEqual(0), () => {
651
+ let a = wi(te, e.lobeAngleFraction, w, e.lobeVolumePercent).toVar(), o = Oi(e.planeDistSensitivity, ee, E, C).toVar(), s = Di(k, te).toVar(), u = Ei(w.mul(w), Gn(e.roughnessFraction), ii).toVar(), p = L(1).add(y).toVar();
649
652
  O.mulAssign(p);
650
- for (let e = -ai; e <= ai; e++) for (let m = -ai; m <= ai; m++) {
651
- if (m === 0 && e === 0 || Math.abs(m) + Math.abs(e) === ai * 2) continue;
652
- let h = Di(T.add(K(m, e).mul(ie).mul(K(F(1).div(c), F(1).div(l))))), g = this._uvToCoord(h), _ = H(t, g).w, v = this._worldPosAt(h, _, d, f), y = H(n, g), b = vi(yi(P(Vn(y.xyz.mul(2).sub(1)), C)), a, F(0)).toVar();
653
- b.mulAssign(vi(y.w.mul(y.w), u.x, u.y)), b.mulAssign(F(1).add(H(i, g).y)), b.mulAssign(_i(P(C, v), o.x, o.y)), b.assign(V(_.greaterThanEqual(Wr), F(0), b));
654
- let x = Fi(b, H(r, g));
655
- b.mulAssign(vi(x.w, s.x, s.y)), p.addAssign(b), O.addAssign(x.mul(b));
653
+ for (let e = -oi; e <= oi; e++) for (let m = -oi; m <= oi; m++) {
654
+ if (m === 0 && e === 0 || Math.abs(m) + Math.abs(e) === oi * 2) continue;
655
+ let h = ki(T.add(J(m, e).mul(A).mul(J(L(1).div(c), L(1).div(l))))), g = this._uvToCoord(h), _ = W(t, g).w, v = this._worldPosAt(h, _, d, f), y = W(n, g), b = bi(xi(I(Vn(y.xyz.mul(2).sub(1)), C)), a, L(0)).toVar();
656
+ b.mulAssign(bi(y.w.mul(y.w), u.x, u.y)), b.mulAssign(L(1).add(W(i, g).y)), b.mulAssign(yi(I(C, v), o.x, o.y)), b.assign(U(_.greaterThanEqual(Gr), L(0), b));
657
+ let x = Li(b, W(r, g));
658
+ b.mulAssign(bi(x.w, s.x, s.y)), p.addAssign(b), O.addAssign(x.mul(b));
656
659
  }
657
- O.divAssign(R(p, 1e-6));
660
+ O.divAssign(B(p, 1e-6));
658
661
  });
659
- let A = O.x.toVar(), ae = B(y.div(R(e.historyFixFrameNum, ti))), oe = z(A, v.x, ae).toVar();
660
- U(o, g, q(oe, 0, 0, 0)).toWriteOnly();
661
- let se = oe.toVar(), ce = oe.mul(oe).toVar(), le = F(0).toVar(), ue = F(0).toVar(), j = (e, n, r) => {
662
- let a = this._clampCoord(p.add(e), m.add(n)), o = H(t, a).w, s = V(o.greaterThanEqual(Wr), oe, H(i, a).x);
663
- Math.abs(e) <= oi && Math.abs(n) <= oi && (se.addAssign(s), ce.addAssign(s.mul(s))), r && (le.addAssign(s), ue.addAssign(s.mul(s)));
664
- }, de = e.antiFirefly.greaterThan(.5);
665
- for (let e = -oi; e <= oi; e++) for (let t = -oi; t <= oi; t++) t === 0 && e === 0 || j(t, e, Math.abs(t) > 1 || Math.abs(e) > 1);
666
- N(de, () => {
667
- for (let e = -si; e <= si; e++) for (let t = -si; t <= si; t++) Math.abs(t) <= oi && Math.abs(e) <= oi || j(t, e, !0);
668
- }), N(de, () => {
669
- let e = 1 / ((si * 2 + 1) ** 2 - 9), t = le.mul(e), n = Ni(t, ue.mul(e)).mul(ci);
670
- A.assign(z(A.clamp(t.sub(n), t.add(n)), A, x));
662
+ let j = O.x.toVar(), ie = H(y.div(B(e.historyFixFrameNum, ni))), ae = V(j, v.x, ie).toVar();
663
+ G(o, g, Y(ae, 0, 0, 0)).toWriteOnly();
664
+ let oe = ae.toVar(), se = ae.mul(ae).toVar(), ce = L(0).toVar(), le = L(0).toVar(), M = (e, n, r) => {
665
+ let a = this._clampCoord(p.add(e), m.add(n)), o = W(t, a).w, s = U(o.greaterThanEqual(Gr), ae, W(i, a).x);
666
+ Math.abs(e) <= si && Math.abs(n) <= si && (oe.addAssign(s), se.addAssign(s.mul(s))), r && (ce.addAssign(s), le.addAssign(s.mul(s)));
667
+ }, ue = e.antiFirefly.greaterThan(.5);
668
+ for (let e = -si; e <= si; e++) for (let t = -si; t <= si; t++) t === 0 && e === 0 || M(t, e, Math.abs(t) > 1 || Math.abs(e) > 1);
669
+ F(ue, () => {
670
+ for (let e = -ci; e <= ci; e++) for (let t = -ci; t <= ci; t++) Math.abs(t) <= si && Math.abs(e) <= si || M(t, e, !0);
671
+ }), F(ue, () => {
672
+ let e = 1 / ((ci * 2 + 1) ** 2 - 9), t = ce.mul(e), n = Fi(t, le.mul(e)).mul(li);
673
+ j.assign(V(j.clamp(t.sub(n), t.add(n)), j, x));
671
674
  });
672
675
  {
673
- let t = 1 / (oi * 2 + 1) ** 2, n = se.mul(t), r = Ni(n, ce.mul(t)).mul(e.fastClampSigmaScale), i = A.clamp(n.sub(r), n.add(r)), a = V(e.maxFast.lessThan(e.maxAccum), F(1), F(0)), o = z(F(1).div(F(1).add(a.mul(y).mul(2))), F(1), x);
674
- A.assign(z(i, A, o));
676
+ let t = 1 / (si * 2 + 1) ** 2, n = oe.mul(t), r = Fi(n, se.mul(t)).mul(e.fastClampSigmaScale), i = j.clamp(n.sub(r), n.add(r)), a = U(e.maxFast.lessThan(e.maxAccum), L(1), L(0)), o = V(L(1).div(L(1).add(a.mul(y).mul(2))), L(1), x);
677
+ j.assign(V(i, j, o));
675
678
  }
676
- U(a, g, ji(O, A)).toWriteOnly();
679
+ G(a, g, Ni(O, j)).toWriteOnly();
677
680
  });
678
681
  });
679
682
  return this._dispatchOf(d);
@@ -681,56 +684,56 @@ var Li = class extends D {
681
684
  _buildTemporalStabilization(e) {
682
685
  let t = this.u, n = this._colorTexNode, r = this._albedoTexNode, i = this._ndTexNode, a = this._snTexNode, o = this._motionTexNode, s = this._nHist, c = this._nData, l = this._nStabRead, u = this._internal, d = this._tmpA, f = this.resW, p = this.resH, m = this.inputFrames, h = this.resetU, g = this.debugMode;
683
686
  return Tn(() => {
684
- let _ = I(J.x).mul(Q).add(I(L.x)), v = I(J.y).mul(Q).add(I(L.y));
685
- N(_.lessThan(I(f)).and(v.lessThan(I(p))), () => {
686
- let f = Rn(_, v), p = Jn(W(_), W(v)), y = H(i, f).w, b = H(n, f).toVar();
687
- N(y.greaterThanEqual(Wr), () => {
688
- U(d, p, b).toWriteOnly(), U(e, p, q(H(s, f).x, 0, 0, 0)).toWriteOnly(), U(u, p, q(0, 1, 0, 0)).toWriteOnly(), Dn();
687
+ let _ = R(X.x).mul(hi).add(R(z.x)), v = R(X.y).mul(hi).add(R(z.y));
688
+ F(_.lessThan(R(f)).and(v.lessThan(R(p))), () => {
689
+ let f = Rn(_, v), p = Jn(K(_), K(v)), y = W(i, f).w, b = W(n, f).toVar();
690
+ F(y.greaterThanEqual(Gr), () => {
691
+ G(d, p, b).toWriteOnly(), G(e, p, Y(W(s, f).x, 0, 0, 0)).toWriteOnly(), G(u, p, Y(0, 1, 0, 0)).toWriteOnly(), Dn();
689
692
  });
690
- let x = H(a, f).w.clamp(.05, 1), S = this._pixelUv(_, v), C = H(o, f), w = S.sub(C.xy).toVar(), T = H(c, f).toVar(), E = T.y.toVar(), D = W(T.z.add(.5)).toVar(), ee = T.w.greaterThan(.5), O = this._bilinear(w), k = [
693
+ let x = W(a, f).w.clamp(.05, 1), S = this._pixelUv(_, v), C = W(o, f), w = S.sub(C.xy).toVar(), T = W(c, f).toVar(), E = T.y.toVar(), D = K(T.z.add(.5)).toVar(), ee = T.w.greaterThan(.5), O = this._bilinear(w), te = [
691
694
  1,
692
695
  2,
693
696
  4,
694
697
  8
695
- ].map((e) => V(D.bitAnd(W(e)).notEqual(W(0)), F(1), F(0))), te = O.customWeights(k).map((e) => e.toVar()), ne = Gn(B(O.filter(k))).toVar(), re = H(s, f).toVar(), ie = re.x.toVar(), A = ie.toVar(), ae = ie.mul(ie).toVar();
698
+ ].map((e) => U(D.bitAnd(K(e)).notEqual(K(0)), L(1), L(0))), ne = O.customWeights(te).map((e) => e.toVar()), re = Gn(H(O.filter(te))).toVar(), k = W(s, f).toVar(), A = k.x.toVar(), j = A.toVar(), ie = A.mul(A).toVar();
696
699
  for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
697
700
  if (t === 0 && e === 0) continue;
698
- let n = this._clampCoord(_.add(t), v.add(e)), r = H(i, n).w, a = V(r.greaterThanEqual(Wr), ie, H(s, n).x);
699
- A.addAssign(a), ae.addAssign(a.mul(a));
701
+ let n = this._clampCoord(_.add(t), v.add(e)), r = W(i, n).w, a = U(r.greaterThanEqual(Gr), A, W(s, n).x);
702
+ j.addAssign(a), ie.addAssign(a.mul(a));
700
703
  }
701
- A.divAssign(9), ae.divAssign(9);
702
- let oe = Ni(A, ae).toVar();
703
- N(E.lessThan(t.historyFixFrameNum), () => {
704
- ie.assign(Bn(ie, A.mul(F(1.2).add(F(1).div(E.add(1))))));
704
+ j.divAssign(9), ie.divAssign(9);
705
+ let ae = Fi(j, ie).toVar();
706
+ F(E.lessThan(t.historyFixFrameNum), () => {
707
+ A.assign(Bn(A, j.mul(L(1.2).add(L(1).div(E.add(1))))));
705
708
  });
706
- let se = R(this._sampleHistory((e) => H(l, e), w, O, te, ee).x, 0).toVar(), ce = oe.mul(t.antilag.x), le = t.antilag.y.mul(4), ue = se.clamp(A.sub(ce), A.add(ce)), j = se.sub(ue).abs().div(R(se, ue).add(ti)), de = F(1).div(F(1).add(j.mul(E.mul(ne)).div(le))).toVar(), fe = Bn(E, t.historyFixFrameNum);
707
- E.assign(z(fe, E, de));
708
- let pe = m.add(1), me = this._handover(pe), he = ne.mul(F(1).sub(this._advancedNonLinear(E.mul(F(1).sub(me)).div(pe)))).mul(de).toVar(), ge = F(1).add(he.mul(6)), _e = t.stabilizationStrength.mul(F(1).sub(h)), ve = z(ie, se.clamp(A.sub(oe.mul(ge)), A.add(oe.mul(ge))), Bn(he, _e)).toVar();
709
- re.assign(ji(re, ve)), U(e, p, q(ve, 0, 0, 0)).toWriteOnly();
710
- let ye = t.maxAccum.mul(F(1).sub(h));
711
- U(u, p, q(Bn(E.add(1), ye), x, 0, 0)).toWriteOnly();
712
- let be = H(r, f), xe = q(ki(re.xyz).mul(R(be.xyz, Xn(Gr))), b.w).toVar();
713
- N(g.equal(I(1)), () => {
714
- let e = B(E.div(R(t.maxAccum, 1)));
715
- xe.assign(q(F(1).sub(e), e, .2, 1));
716
- }).ElseIf(g.equal(I(2)), () => {
717
- xe.assign(q(Xn(re.w), 1));
718
- }).ElseIf(g.equal(I(3)), () => {
719
- xe.assign(q(Xn(x), 1));
720
- }).ElseIf(g.equal(I(4)), () => {
709
+ let oe = B(this._sampleHistory((e) => W(l, e), w, O, ne, ee).x, 0).toVar(), se = ae.mul(t.antilag.x), ce = t.antilag.y.mul(4), le = oe.clamp(j.sub(se), j.add(se)), M = oe.sub(le).abs().div(B(oe, le).add(ni)), ue = L(1).div(L(1).add(M.mul(E.mul(re)).div(ce))).toVar(), de = Bn(E, t.historyFixFrameNum);
710
+ E.assign(V(de, E, ue));
711
+ let fe = m.add(1), pe = this._handover(fe), N = re.mul(L(1).sub(this._advancedNonLinear(E.mul(L(1).sub(pe)).div(fe)))).mul(ue).toVar(), me = L(1).add(N.mul(6)), he = t.stabilizationStrength.mul(L(1).sub(h)), ge = V(A, oe.clamp(j.sub(ae.mul(me)), j.add(ae.mul(me))), Bn(N, he)).toVar();
712
+ k.assign(Ni(k, ge)), G(e, p, Y(ge, 0, 0, 0)).toWriteOnly();
713
+ let _e = t.maxAccum.mul(L(1).sub(h));
714
+ G(u, p, Y(Bn(E.add(1), _e), x, 0, 0)).toWriteOnly();
715
+ let ve = W(r, f), ye = Y(ji(k.xyz).mul(B(ve.xyz, Xn(Kr))), b.w).toVar();
716
+ F(g.equal(R(1)), () => {
717
+ let e = H(E.div(B(t.maxAccum, 1)));
718
+ ye.assign(Y(L(1).sub(e), e, .2, 1));
719
+ }).ElseIf(g.equal(R(2)), () => {
720
+ ye.assign(Y(Xn(k.w), 1));
721
+ }).ElseIf(g.equal(R(3)), () => {
722
+ ye.assign(Y(Xn(x), 1));
723
+ }).ElseIf(g.equal(R(4)), () => {
721
724
  let e = T.x.div(T.x.add(1));
722
- xe.assign(q(Xn(e), 1));
723
- }).ElseIf(g.equal(I(5)), () => {
724
- xe.assign(q(Xn(T.z.div(15)), 1));
725
- }), U(d, p, xe).toWriteOnly();
725
+ ye.assign(Y(Xn(e), 1));
726
+ }).ElseIf(g.equal(R(5)), () => {
727
+ ye.assign(Y(Xn(T.z.div(15)), 1));
728
+ }), G(d, p, ye).toWriteOnly();
726
729
  });
727
730
  })().compute([
728
731
  this._dispatchX,
729
732
  this._dispatchY,
730
733
  1
731
734
  ], [
732
- Q,
733
- Q,
735
+ hi,
736
+ hi,
734
737
  1
735
738
  ]);
736
739
  }
@@ -750,7 +753,7 @@ var Li = class extends D {
750
753
  }
751
754
  _updateRotators(e) {
752
755
  let t = (t, n) => {
753
- let r = Ii(e * 3 + n) * Math.PI * 2;
756
+ let r = Ri(e * 3 + n) * Math.PI * 2;
754
757
  t.value.set(Math.cos(r), Math.sin(r), -Math.sin(r), Math.cos(r));
755
758
  };
756
759
  t(this.rotPre, 0), t(this.rotBlur, 1), t(this.rotPost, 2);
@@ -777,7 +780,7 @@ var Li = class extends D {
777
780
  this._nTmpA.value = this._tmpA, this._nTmpB.value = this._tmpB, this._nHist.value = this._hist, this._nFast.value = this._fastHist, this._nInternal.value = this._internal, this._nGeom.value = this._geomPrev, this._nData.value = this._dataT, this._nStabRead.value = this._stabPing === 0 ? this._stabB : this._stabA, this.renderer.compute(this._kPre), this.renderer.compute(this._kTa), this.renderer.compute(this._kHf), this.renderer.compute(this._kBlur), this.renderer.compute(this._kPost), this.renderer.compute(this._stabPing === 0 ? this._kTsA : this._kTsB), this._srcRegion.max.set(this.outputTarget.width, this.outputTarget.height), this.renderer.copyTextureToTexture(this._tmpA, this.outputTarget.texture, this._srcRegion), e.setTexture("nrd:output", this.outputTarget.texture), this._stabPing = 1 - this._stabPing, this._needsReset = !1, this._needsReset = !1;
778
781
  }
779
782
  setSize(e, t) {
780
- this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e / Q), this._dispatchY = Math.ceil(t / Q);
783
+ this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e / hi), this._dispatchY = Math.ceil(t / hi);
781
784
  let n = [
782
785
  this._dispatchX,
783
786
  this._dispatchY,
@@ -806,7 +809,7 @@ var Li = class extends D {
806
809
  for (let [e, t] of this._placeholders) e.dispose(), t.dispose();
807
810
  this._placeholders.clear();
808
811
  }
809
- }, Ri = {
812
+ }, Bi = {
810
813
  autoExposure: !1,
811
814
  autoExposureMetering: "center",
812
815
  autoExposureStrength: .3,
@@ -815,120 +818,124 @@ var Li = class extends D {
815
818
  autoExposureMaxExposure: 2 ** 8,
816
819
  autoExposureAdaptSpeedBright: 3,
817
820
  autoExposureAdaptSpeedDark: 1
818
- }, zi = [
821
+ }, Vi = [
819
822
  "average",
820
823
  "center",
821
824
  "spot"
822
- ], Bi = 64, Vi = 8, Hi = 8, Ui = 256, Wi = -16, Gi = (12 - Wi) / Ui, Ki = 2 ** -24, qi = 65536, Ji = 256, Yi = 128, Xi = 1.5, Zi = .01, Qi = .06, $i = .25, ea = 4, ta = .3, na = 1.5, ra = 3, ia = [
825
+ ], Hi = 64, Ui = 8, Wi = 8, Gi = 256, Ki = -16, qi = (12 - Ki) / Gi, Ji = 2 ** -24, Yi = 65536, Xi = 256, Zi = 128, Qi = 1.5, $i = .01, ea = .06, ta = .25, na = 4, ra = .3, ia = 1.5, aa = 3, oa = [
823
826
  .2126,
824
827
  .7152,
825
828
  .0722
826
- ];
827
- function aa(e, t, n, r, i) {
829
+ ], sa = .999, ca = {
830
+ transparent: 0,
831
+ environment: 1,
832
+ color: 2
833
+ };
834
+ function la(e, t, n, r, i) {
828
835
  let a = t - e;
829
836
  if (a === 0 || !(n > 0)) return e;
830
837
  let o = Math.max(a < 0 ? r : i, .001);
831
838
  if (n === Infinity) return t;
832
- let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n / Xi)));
839
+ let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n / Qi)));
833
840
  return e + Math.sign(a) * s;
834
841
  }
835
- function oa(e, t, n) {
842
+ function ua(e, t, n) {
836
843
  let r = Math.abs(e);
837
- return e * (r <= na ? n : r >= ra ? 1 : n + (1 - n) * (r - na) / (ra - na)) + n * (t - e);
844
+ return e * (r <= ia ? n : r >= aa ? 1 : n + (1 - n) * (r - ia) / (aa - ia)) + n * (t - e);
838
845
  }
839
- function sa(e, t) {
840
- if (!e) return t.fromArray(ia);
846
+ function da(e, t) {
847
+ if (!e) return t.fromArray(oa);
841
848
  let n = new vr().set(...e).invert().elements;
842
- return t.set(ia[0] * n[0] + ia[1] * n[1] + ia[2] * n[2], ia[0] * n[3] + ia[1] * n[4] + ia[2] * n[5], ia[0] * n[6] + ia[1] * n[7] + ia[2] * n[8]);
849
+ return t.set(oa[0] * n[0] + oa[1] * n[1] + oa[2] * n[2], oa[0] * n[3] + oa[1] * n[4] + oa[2] * n[5], oa[0] * n[6] + oa[1] * n[7] + oa[2] * n[8]);
843
850
  }
844
- var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
851
+ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
845
852
  constructor(e, t = {}) {
846
853
  super("AutoExposure", {
847
854
  ...t,
848
- executionMode: pe.ALWAYS
849
- }), this.renderer = e, this.metering = t.metering ?? Ri.autoExposureMetering, this.meteringPoint = new Lr(.5, .5), this.keyValue = t.keyValue ?? Ri.autoExposureKeyValue, this.minExposure = t.minExposure ?? Ri.autoExposureMinExposure, this.maxExposure = t.maxExposure ?? Ri.autoExposureMaxExposure, this.adaptSpeedBright = t.adaptSpeedBright ?? Ri.autoExposureAdaptSpeedBright, this.adaptSpeedDark = t.adaptSpeedDark ?? Ri.autoExposureAdaptSpeedDark, this.centerWeight = t.centerWeight ?? 8, this.strength = t.strength ?? Ri.autoExposureStrength, this.instant = !1, this.holdSamples = 0, this.onChange = null, this._lowU = G(t.lowPercentile ?? .1), this._highU = G(t.highPercentile ?? .9), this._falloffU = G(new Lr()), this._pointU = G(new Lr(.5, .5)), this._lumWeightsU = G(new Z().fromArray(ia)), this._widthU = G(1, "int"), this._heightU = G(1, "int"), this._strideU = G(1, "int"), this._gridXU = G(Bi, "int"), this._gridYU = G(Bi, "int"), this._inputNode = new Cn(), this._workingMatrix = void 0, this._histogram = Mn(Ui, "uint").toAtomic(), this._result = Mn(1, "vec4"), this._readback = new bn(16), this._readback.name = "AutoExposure", this._kernels = [this._buildTileKernel(), this._buildResolveKernel()], this._compensation = 1, this._exposureEV = 0, this._targetEV = null, this._viewEV = null, this._roomEV = null, this._clock = 0, this._movingUntil = -1, this._viewMoves = 0, this._landed = null, this._meteredLog2 = null, this._snap = !0, this._lastUpdate = null, this._accumulating = !1, this._emittedEV = null, this._pending = null, this._generation = 0, this._restarts = 0, this._meteredAt = {
855
+ executionMode: A.ALWAYS
856
+ }), this.renderer = e, this.metering = t.metering ?? Bi.autoExposureMetering, this.meteringPoint = new Rr(.5, .5), this.keyValue = t.keyValue ?? Bi.autoExposureKeyValue, this.minExposure = t.minExposure ?? Bi.autoExposureMinExposure, this.maxExposure = t.maxExposure ?? Bi.autoExposureMaxExposure, this.adaptSpeedBright = t.adaptSpeedBright ?? Bi.autoExposureAdaptSpeedBright, this.adaptSpeedDark = t.adaptSpeedDark ?? Bi.autoExposureAdaptSpeedDark, this.centerWeight = t.centerWeight ?? 8, this.strength = t.strength ?? Bi.autoExposureStrength, this.instant = !1, this.holdSamples = 0, this.onChange = null, this._lowU = q(t.lowPercentile ?? .1), this._highU = q(t.highPercentile ?? .9), this._falloffU = q(new Rr()), this._pointU = q(new Rr(.5, .5)), this._lumWeightsU = q(new Q().fromArray(oa)), this._backdropModeU = q(ca.transparent, "int"), this._widthU = q(1, "int"), this._heightU = q(1, "int"), this._strideU = q(1, "int"), this._gridXU = q(Hi, "int"), this._gridYU = q(Hi, "int"), this._inputNode = new Cn(), this._workingMatrix = void 0, this._histogram = Mn(Gi, "uint").toAtomic(), this._result = Mn(1, "vec4"), this._readback = new bn(16), this._readback.name = "AutoExposure", this._kernels = [this._buildTileKernel(), this._buildResolveKernel()], this._compensation = 1, this._exposureEV = 0, this._targetEV = null, this._viewEV = null, this._roomEV = null, this._clock = 0, this._movingUntil = -1, this._viewMoves = 0, this._landed = null, this._meteredLog2 = null, this._snap = !0, this._lastUpdate = null, this._accumulating = !1, this._emittedEV = null, this._pending = null, this._generation = 0, this._restarts = 0, this._meteredAt = {
850
857
  restarts: -1,
851
858
  samples: -1
852
859
  }, this._stale = !1, this._disposed = !1;
853
860
  }
854
861
  _buildTileKernel() {
855
- let e = this._inputNode, t = this._histogram, n = this._widthU, r = this._heightU, i = this._strideU, a = this._gridXU, o = this._gridYU, s = this._lumWeightsU, c = this._falloffU, l = this._pointU;
862
+ let e = this._inputNode, t = this._histogram, n = this._widthU, r = this._heightU, i = this._strideU, a = this._gridXU, o = this._gridYU, s = this._lumWeightsU, c = this._falloffU, l = this._pointU, u = this._backdropModeU;
856
863
  return Tn(() => {
857
- let u = L.y.mul(W(Hi)).add(L.x), d = I(J.x), f = I(J.y), p = d.mul(n).div(a).toVar(), m = d.add(I(1)).mul(n).div(a).toVar(), h = f.mul(r).div(o).toVar(), g = f.add(I(1)).mul(r).div(o).toVar(), _ = i.mul(I(Hi)), v = F(0).toVar(), y = F(0).toVar();
864
+ let d = z.y.mul(K(Wi)).add(z.x), f = R(X.x), p = R(X.y), m = f.mul(n).div(a).toVar(), h = f.add(R(1)).mul(n).div(a).toVar(), g = p.mul(r).div(o).toVar(), _ = p.add(R(1)).mul(r).div(o).toVar(), v = i.mul(R(Wi)), y = L(0).toVar(), b = L(0).toVar();
858
865
  En({
859
- start: h.add(I(L.y)),
860
- end: g,
866
+ start: g.add(R(z.y)),
867
+ end: _,
861
868
  type: "int",
862
869
  condition: "<",
863
- update: _,
870
+ update: v,
864
871
  name: "py"
865
872
  }, ({ py: t }) => {
866
873
  En({
867
- start: p.add(I(L.x)),
868
- end: m,
874
+ start: m.add(R(z.x)),
875
+ end: h,
869
876
  type: "int",
870
877
  condition: "<",
871
- update: _,
878
+ update: v,
872
879
  name: "px"
873
880
  }, ({ px: n }) => {
874
- let r = H(e, Rn(n, t)), i = P(r.xyz, s).toVar(), a = Fn(i).bitAnd(W(2139095040)).notEqual(W(2139095040)), o = r.w.clamp(0, 1);
875
- v.addAssign(V(a, i.clamp(0, 1e6), F(0)).mul(o)), y.addAssign(o);
881
+ let r = W(e, Rn(n, t)), i = I(r.xyz, s).toVar(), a = Fn(i).bitAnd(K(2139095040)).notEqual(K(2139095040)), o = r.w.clamp(0, 1), c = U(u.equal(R(ca.environment)), L(1), U(u.equal(R(ca.color)), U(o.greaterThanEqual(sa), L(1), L(0)), o));
882
+ y.addAssign(U(a, i.clamp(0, 1e6), L(0)).mul(c)), b.addAssign(c);
876
883
  });
877
884
  });
878
- let b = Zn("float", Hi * Hi), x = Zn("float", Hi * Hi);
879
- b.element(u).assign(v), x.element(u).assign(y), Qn();
880
- for (let e = Hi * Hi >> 1; e > 0; e >>= 1) N(u.lessThan(W(e)), () => {
881
- b.element(u).addAssign(b.element(u.add(W(e)))), x.element(u).addAssign(x.element(u.add(W(e))));
885
+ let x = Zn("float", Wi * Wi), S = Zn("float", Wi * Wi);
886
+ x.element(d).assign(y), S.element(d).assign(b), Qn();
887
+ for (let e = Wi * Wi >> 1; e > 0; e >>= 1) F(d.lessThan(K(e)), () => {
888
+ x.element(d).addAssign(x.element(d.add(K(e)))), S.element(d).addAssign(S.element(d.add(K(e))));
882
889
  }), Qn();
883
- N(u.equal(W(0)), () => {
884
- let e = b.element(W(0)).toVar(), i = x.element(W(0)).toVar(), a = (e) => e.div(_).mul(I(Hi)).add(Bn(e.mod(_), I(Hi))), o = F(a(m.sub(p)).mul(a(g.sub(h))));
885
- N(i.greaterThan(0).and(e.greaterThan(i.mul(Ki))), () => {
886
- let a = W(zn(e.div(i)).sub(Wi).div(Gi).floor().clamp(0, Ui - 1)), s = K(F(p.add(m)).div(F(n)), F(h.add(g)).div(F(r))).mul(.5).sub(l), u = W(Nn(P(s.mul(s), c).negate()).mul(i.div(R(o, 1))).mul(qi).add(.5));
887
- N(u.greaterThan(W(0)), () => {
890
+ F(d.equal(K(0)), () => {
891
+ let e = x.element(K(0)).toVar(), i = S.element(K(0)).toVar(), a = (e) => e.div(v).mul(R(Wi)).add(Bn(e.mod(v), R(Wi))), o = L(a(h.sub(m)).mul(a(_.sub(g))));
892
+ F(i.greaterThan(0).and(e.greaterThan(i.mul(Ji))), () => {
893
+ let a = K(zn(e.div(i)).sub(Ki).div(qi).floor().clamp(0, Gi - 1)), s = J(L(m.add(h)).div(L(n)), L(g.add(_)).div(L(r))).mul(.5).sub(l), u = K(Nn(I(s.mul(s), c).negate()).mul(i.div(B(o, 1))).mul(Yi).add(.5));
894
+ F(u.greaterThan(K(0)), () => {
888
895
  kn(t.element(a), u);
889
896
  });
890
897
  });
891
898
  });
892
899
  })().compute([
893
- Bi,
894
- Bi,
895
- 1
896
- ], [
897
900
  Hi,
898
901
  Hi,
899
902
  1
903
+ ], [
904
+ Wi,
905
+ Wi,
906
+ 1
900
907
  ]);
901
908
  }
902
909
  _buildResolveKernel() {
903
910
  let e = this._histogram, t = this._result, n = this._lowU, r = this._highU;
904
911
  return Tn(() => {
905
- let i = L.x, a = F(An(e.element(i))).toVar();
906
- jn(e.element(i), W(0));
907
- let o = Zn("float", Ui), s = Zn("float", Ui);
912
+ let i = z.x, a = L(An(e.element(i))).toVar();
913
+ jn(e.element(i), K(0));
914
+ let o = Zn("float", Gi), s = Zn("float", Gi);
908
915
  o.element(i).assign(a), Qn();
909
- for (let e = 1; e < Ui; e <<= 1) {
916
+ for (let e = 1; e < Gi; e <<= 1) {
910
917
  let t = o.element(i).toVar();
911
- N(i.greaterThanEqual(W(e)), () => {
912
- t.addAssign(o.element(i.sub(W(e))));
918
+ F(i.greaterThanEqual(K(e)), () => {
919
+ t.addAssign(o.element(i.sub(K(e))));
913
920
  }), Qn(), o.element(i).assign(t), Qn();
914
921
  }
915
- let c = o.element(W(Ui - 1)).toVar(), l = o.element(i).toVar();
922
+ let c = o.element(K(Gi - 1)).toVar(), l = o.element(i).toVar();
916
923
  Qn();
917
- let u = R(Bn(l, c.mul(r)).sub(R(l.sub(a), c.mul(n))), 0);
918
- o.element(i).assign(u), s.element(i).assign(u.mul(F(i).add(.5).mul(Gi).add(Wi))), Qn();
919
- for (let e = Ui >> 1; e > 0; e >>= 1) N(i.lessThan(W(e)), () => {
920
- o.element(i).addAssign(o.element(i.add(W(e)))), s.element(i).addAssign(s.element(i.add(W(e))));
924
+ let u = B(Bn(l, c.mul(r)).sub(B(l.sub(a), c.mul(n))), 0);
925
+ o.element(i).assign(u), s.element(i).assign(u.mul(L(i).add(.5).mul(qi).add(Ki))), Qn();
926
+ for (let e = Gi >> 1; e > 0; e >>= 1) F(i.lessThan(K(e)), () => {
927
+ o.element(i).addAssign(o.element(i.add(K(e)))), s.element(i).addAssign(s.element(i.add(K(e))));
921
928
  }), Qn();
922
- N(i.equal(W(0)), () => {
923
- let e = o.element(W(0));
924
- t.element(W(0)).assign(q(s.element(W(0)).div(R(e, 1e-6)), c.div(qi), e.div(qi), 1));
929
+ F(i.equal(K(0)), () => {
930
+ let e = o.element(K(0));
931
+ t.element(K(0)).assign(Y(s.element(K(0)).div(B(e, 1e-6)), c.div(Yi), e.div(Yi), 1));
925
932
  });
926
933
  })().compute([
927
934
  1,
928
935
  1,
929
936
  1
930
937
  ], [
931
- Ui,
938
+ Gi,
932
939
  1,
933
940
  1
934
941
  ]);
@@ -940,7 +947,7 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
940
947
  if (!this.enabled) return;
941
948
  let t = e.getState("pathtracer:samples") ?? 0;
942
949
  if (this._accumulating = t >= 2, !this._pending) {
943
- let n = this._meteredAt, r = this._stale || this._targetEV === null || n.restarts !== this._restarts || t - n.samples >= ca(t), i = t < this.holdSamples && this._targetEV !== null && !this._stale;
950
+ let n = this._meteredAt, r = this._stale || this._targetEV === null || n.restarts !== this._restarts || t - n.samples >= fa(t), i = t < this.holdSamples && this._targetEV !== null && !this._stale;
944
951
  r && !i && this._meter(e, t);
945
952
  }
946
953
  e.setState("autoexposure:value", this.renderer.toneMappingExposure), e.setState("autoexposure:avgLuminance", this.luminance);
@@ -955,13 +962,13 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
955
962
  if (!n || r < 1 || i < 1 || this._disposed) return null;
956
963
  this._meteredAt.restarts = this._restarts, this._meteredAt.samples = t, this._stale = !1;
957
964
  let a = et();
958
- a !== this._workingMatrix && (this._workingMatrix = a, sa(a, this._lumWeightsU.value));
959
- let o = Math.min(Bi, Math.max(1, Math.floor(r / Vi))), s = Math.min(Bi, Math.max(1, Math.floor(i / Vi))), c = r / o * (i / s);
965
+ a !== this._workingMatrix && (this._workingMatrix = a, da(a, this._lumWeightsU.value));
966
+ let o = Math.min(Hi, Math.max(1, Math.floor(r / Ui))), s = Math.min(Hi, Math.max(1, Math.floor(i / Ui))), c = r / o * (i / s);
960
967
  this._gridXU.value = o, this._gridYU.value = s, this._kernels[0].dispatchSize = [
961
968
  o,
962
969
  s,
963
970
  1
964
- ], this._strideU.value = Math.max(1, Math.round(Math.sqrt(c / Ji))), this._widthU.value = r, this._heightU.value = i, this._updateMeteringPattern(r / i), this._inputNode.value = n, this.renderer.compute(this._kernels);
971
+ ], this._strideU.value = Math.max(1, Math.round(Math.sqrt(c / Xi))), this._widthU.value = r, this._heightU.value = i, this._backdropModeU.value = ca[e.getState("pathtracer:backdrop")] ?? ca.transparent, this._updateMeteringPattern(r / i), this._inputNode.value = n, this.renderer.compute(this._kernels);
965
972
  let l = this._generation, u = {
966
973
  restarts: this._restarts,
967
974
  moves: this._viewMoves
@@ -977,7 +984,7 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
977
984
  let t = this._falloffU.value, n = this._pointU.value;
978
985
  if (this.metering === "average") t.set(0, 0);
979
986
  else if (this.metering === "spot") {
980
- t.set(Yi * e * e, Yi), n.copy(this.meteringPoint);
987
+ t.set(Zi * e * e, Zi), n.copy(this.meteringPoint);
981
988
  return;
982
989
  } else t.set(this.centerWeight, this.centerWeight);
983
990
  n.set(.5, .5);
@@ -986,25 +993,25 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
986
993
  let [n, r, i] = e;
987
994
  if (!this.enabled || !(r > 0 && i > 0) || !Number.isFinite(n)) return null;
988
995
  let a = this._viewEV;
989
- this._meteredLog2 = n, this._viewEV = Math.log2(this.keyValue) - n, this._roomEV === null ? this._roomEV = this._viewEV : t?.moves === this._landed?.moves ? this._roomEV += this._viewEV - a : this._movingUntil = this._clock + ta, this._landed = t;
990
- let o = this._aim(), s = this._targetEV === null || Math.abs(o - this._targetEV) > Zi;
996
+ this._meteredLog2 = n, this._viewEV = Math.log2(this.keyValue) - n, this._roomEV === null ? this._roomEV = this._viewEV : t?.moves === this._landed?.moves ? this._roomEV += this._viewEV - a : this._movingUntil = this._clock + ra, this._landed = t;
997
+ let o = this._aim(), s = this._targetEV === null || Math.abs(o - this._targetEV) > $i;
991
998
  return this._targetEV = o, (s || this.settling) && this.onChange?.(), n;
992
999
  }
993
1000
  update(e = performance.now()) {
994
- let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3, $i), n = this.advance(t, this._accumulating);
1001
+ let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3, ta), n = this.advance(t, this._accumulating);
995
1002
  return this._lastUpdate = this.settling || this._clock <= this._movingUntil ? e : null, n;
996
1003
  }
997
1004
  advance(e, t = !1) {
998
1005
  if (!this.enabled || this._targetEV === null) return !1;
999
- e > 0 && e !== Infinity && (this._clock += e, this._clock <= this._movingUntil && (this._roomEV += (this._viewEV - this._roomEV) * (1 - Math.exp(-Math.min(e, $i) / ea)), this._targetEV = this._aim()));
1006
+ e > 0 && e !== Infinity && (this._clock += e, this._clock <= this._movingUntil && (this._roomEV += (this._viewEV - this._roomEV) * (1 - Math.exp(-Math.min(e, ta) / na)), this._targetEV = this._aim()));
1000
1007
  let n = this._exposureEV;
1001
- return this._snap || this.instant ? (this._exposureEV = this._targetEV, this._snap = !1) : (this._exposureEV = t ? n + (this._targetEV - n) * (1 - Math.exp(-e / Qi)) : aa(n, this._targetEV, e, this.adaptSpeedBright, this.adaptSpeedDark), Math.abs(this._targetEV - this._exposureEV) <= Zi && (this._exposureEV = this._targetEV)), this._exposureEV === n ? !1 : (this._apply(), !0);
1008
+ return this._snap || this.instant ? (this._exposureEV = this._targetEV, this._snap = !1) : (this._exposureEV = t ? n + (this._targetEV - n) * (1 - Math.exp(-e / ea)) : la(n, this._targetEV, e, this.adaptSpeedBright, this.adaptSpeedDark), Math.abs(this._targetEV - this._exposureEV) <= $i && (this._exposureEV = this._targetEV)), this._exposureEV === n ? !1 : (this._apply(), !0);
1002
1009
  }
1003
1010
  _inRange(e) {
1004
1011
  return Math.min(Math.max(e, Math.log2(this.minExposure)), Math.log2(this.maxExposure));
1005
1012
  }
1006
1013
  _aim() {
1007
- return this._inRange(oa(this._roomEV, this._viewEV, this.strength));
1014
+ return this._inRange(ua(this._roomEV, this._viewEV, this.strength));
1008
1015
  }
1009
1016
  noteViewChanged() {
1010
1017
  this._viewMoves++;
@@ -1047,7 +1054,7 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
1047
1054
  }
1048
1055
  updateParameters(e) {
1049
1056
  let t = e.metering;
1050
- t !== void 0 && zi.includes(t) && (this.metering = t), e.meteringPoint && this.meteringPoint.set(e.meteringPoint.x, e.meteringPoint.y);
1057
+ t !== void 0 && Vi.includes(t) && (this.metering = t), e.meteringPoint && this.meteringPoint.set(e.meteringPoint.x, e.meteringPoint.y);
1051
1058
  for (let t of [
1052
1059
  "keyValue",
1053
1060
  "minExposure",
@@ -1070,32 +1077,32 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
1070
1077
  for (let e of this._kernels) e.dispose();
1071
1078
  this._readback.dispose(), this._inputNode.dispose();
1072
1079
  }
1073
- }, ua = {
1080
+ }, ma = {
1074
1081
  localExposure: !1,
1075
1082
  localExposureHighlightContrast: .6,
1076
1083
  localExposureShadowContrast: 1,
1077
1084
  localExposureDetailStrength: 1
1078
- }, da = 128, fa = (da / 2) ** 2, $ = 32, pa = -16, ma = 16, ha = -40, ga = 40, _a = 256, va = 32, ya = .6, ba = 50, xa = Math.log2(.18), Sa = 2 ** -24, Ca = Math.ceil(k / da), wa = Math.ceil(k / va), Ta = [
1085
+ }, ha = 128, ga = (ha / 2) ** 2, $ = 32, _a = -16, va = 16, ya = -40, ba = 40, xa = 256, Sa = 32, Ca = .6, wa = 50, Ta = Math.log2(.18), Ea = .999, Da = 2 ** -24, Oa = Math.ceil(j / ha), ka = Math.ceil(j / Sa), Aa = [
1079
1086
  .2126,
1080
1087
  .7152,
1081
1088
  .0722
1082
- ], Ea = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Da = (e, t, n) => Math.min(Math.max(e, t), n);
1083
- function Oa(e, t, n, r, i, a, o) {
1084
- let s = Math.min(Math.log2(Math.max(a, Sa)), ga), c = e[6], l = e[7], u = Da(r * e[2] - .5, 0, c - 1), d = Da(i * e[3] - .5, 0, l - 1), f = Math.floor(u), p = Math.floor(d), m = Math.min(f + 1, c - 1), h = Math.min(p + 1, l - 1), g = u - f, _ = d - p, v = (e) => n[e * c + f] + (n[e * c + m] - n[e * c + f]) * g, y = v(p) + (v(h) - v(p)) * _, b = e[4], x = e[5], S = Da(r * e[0] - .5, 0, b - 1), C = Da(i * e[1] - .5, 0, x - 1), w = Da((s + e[8] - pa) / (ma - pa), 0, 1) * ($ - 1), T = Math.floor(S), E = Math.floor(C), D = Math.floor(w), ee = S - T, O = C - E, k = w - D, te = 0, ne = 0;
1089
+ ], ja = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ma = (e, t, n) => Math.min(Math.max(e, t), n);
1090
+ function Na(e, t, n, r, i, a, o) {
1091
+ let s = Math.min(Math.log2(Math.max(a, Da)), ba), c = e[6], l = e[7], u = Ma(r * e[2] - .5, 0, c - 1), d = Ma(i * e[3] - .5, 0, l - 1), f = Math.floor(u), p = Math.floor(d), m = Math.min(f + 1, c - 1), h = Math.min(p + 1, l - 1), g = u - f, _ = d - p, v = (e) => n[e * c + f] + (n[e * c + m] - n[e * c + f]) * g, y = v(p) + (v(h) - v(p)) * _, b = e[4], x = e[5], S = Ma(r * e[0] - .5, 0, b - 1), C = Ma(i * e[1] - .5, 0, x - 1), w = Ma((s + e[8] - _a) / (va - _a), 0, 1) * ($ - 1), T = Math.floor(S), E = Math.floor(C), D = Math.floor(w), ee = S - T, O = C - E, te = w - D, ne = 0, re = 0;
1085
1092
  for (let e = 0; e < 8; e++) {
1086
- let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? ee : 1 - ee) * (r ? O : 1 - O) * (i ? k : 1 - k), o = ((Math.min(E + r, x - 1) * b + Math.min(T + n, b - 1)) * $ + Math.min(D + i, $ - 1)) * 2;
1087
- te += t[o] * a, ne += t[o + 1] * a;
1093
+ let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? ee : 1 - ee) * (r ? O : 1 - O) * (i ? te : 1 - te), o = ((Math.min(E + r, x - 1) * b + Math.min(T + n, b - 1)) * $ + Math.min(D + i, $ - 1)) * 2;
1094
+ ne += t[o] * a, re += t[o + 1] * a;
1088
1095
  }
1089
- let re = ne * fa < .001 ? y : te / ne, ie = re + (y - re) * e[12] + o, A = s + o, ae = ie > e[13] ? e[9] : e[10];
1090
- return 2 ** (e[13] + (ie - e[13]) * ae + (A - ie) * e[11] - A);
1096
+ let k = re * ga < .001 ? y : ne / re, A = k + (y - k) * e[12] + o, j = s + o, ie = A > e[13] ? e[9] : e[10];
1097
+ return 2 ** (e[13] + (A - e[13]) * ie + (j - A) * e[11] - j);
1091
1098
  }
1092
- var ka = `
1099
+ var Pa = `
1093
1100
  @group(1) @binding(0) var<storage, read> leGrid: array<vec2<f32>>;
1094
1101
  @group(1) @binding(1) var<storage, read> leBlur: array<f32>;
1095
1102
  @group(1) @binding(2) var<uniform> le: array<vec4<f32>, 4>;
1096
1103
 
1097
1104
  fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1098
- let logL = min( log2( max( dot( linear, vec3<f32>( ${Ta.join(", ")} ) ), ${Sa} ) ), ${ga}.0 );
1105
+ let logL = min( log2( max( dot( linear, vec3<f32>( ${Aa.join(", ")} ) ), ${Da} ) ), ${ba}.0 );
1099
1106
  let logExposure = log2( exposure );
1100
1107
 
1101
1108
  let bs = vec2<i32>( le[ 1 ].zw );
@@ -1109,7 +1116,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1109
1116
 
1110
1117
  let cs = vec2<i32>( le[ 1 ].xy );
1111
1118
  let gp = clamp( uv * le[ 0 ].xy - 0.5, vec2<f32>( 0.0 ), vec2<f32>( cs - 1 ) );
1112
- let gz = clamp( ( logL + le[ 2 ].x - (${pa}.0) ) / ${ma - pa}.0, 0.0, 1.0 ) * ${$ - 1}.0;
1119
+ let gz = clamp( ( logL + le[ 2 ].x - (${_a}.0) ) / ${va - _a}.0, 0.0, 1.0 ) * ${$ - 1}.0;
1113
1120
  let g0 = vec3<i32>( vec2<i32>( floor( gp ) ), i32( floor( gz ) ) );
1114
1121
  let gf = vec3<f32>( gp - floor( gp ), gz - floor( gz ) );
1115
1122
  var acc = vec2<f32>( 0.0 );
@@ -1120,26 +1127,26 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1120
1127
  acc += leGrid[ ( c.y * cs.x + c.x ) * ${$} + c.z ] * ( wv.x * wv.y * wv.z );
1121
1128
  }
1122
1129
 
1123
- let bilateral = select( acc.x / acc.y, blurred, acc.y * ${fa}.0 < 1e-3 );
1130
+ let bilateral = select( acc.x / acc.y, blurred, acc.y * ${ga}.0 < 1e-3 );
1124
1131
  let base = mix( bilateral, blurred, le[ 3 ].x ) + logExposure;
1125
1132
  let y = logL + logExposure;
1126
1133
  let contrast = select( le[ 2 ].z, le[ 2 ].y, base > le[ 3 ].y );
1127
1134
  return exp2( le[ 3 ].y + ( base - le[ 3 ].y ) * contrast + ( y - base ) * le[ 2 ].w - y );
1128
1135
  }
1129
- `, Aa = class extends D {
1136
+ `, Fa = class extends k {
1130
1137
  constructor(e, t = {}) {
1131
1138
  super("LocalExposure", {
1132
1139
  ...t,
1133
- executionMode: pe.ALWAYS
1134
- }), this.renderer = e, this.highlightContrast = t.highlightContrast ?? ua.localExposureHighlightContrast, this.shadowContrast = t.shadowContrast ?? ua.localExposureShadowContrast, this.detailStrength = t.detailStrength ?? ua.localExposureDetailStrength, this.onChange = null, this._grid = Mn(Ca * Ca * $, "vec2"), this._blur = Mn(wa * wa, "float"), this._blurTmp = Mn(wa * wa, "float"), this._inputNode = new Cn(), this._widthU = G(1, "int"), this._heightU = G(1, "int"), this._cellsXU = G(1, "int"), this._blurWU = G(1, "int"), this._blurHU = G(1, "int"), this._radiusU = G(1), this._logExposureU = G(0), this._p = [
1135
- new Rr(),
1136
- new Rr(),
1137
- new Rr(),
1138
- new Rr()
1139
- ].map((e) => G(e)), this._params = new Float32Array(16), this._kernels = [
1140
+ executionMode: A.ALWAYS
1141
+ }), this.renderer = e, this.highlightContrast = t.highlightContrast ?? ma.localExposureHighlightContrast, this.shadowContrast = t.shadowContrast ?? ma.localExposureShadowContrast, this.detailStrength = t.detailStrength ?? ma.localExposureDetailStrength, this.onChange = null, this._grid = Mn(Oa * Oa * $, "vec2"), this._blur = Mn(ka * ka, "float"), this._blurSource = Mn(ka * ka, "vec2"), this._blurTmp = Mn(ka * ka, "vec2"), this._inputNode = new Cn(), this._widthU = q(1, "int"), this._heightU = q(1, "int"), this._cellsXU = q(1, "int"), this._blurWU = q(1, "int"), this._blurHU = q(1, "int"), this._radiusU = q(1), this._logExposureU = q(0), this._sceneOnlyU = q(0, "int"), this._p = [
1142
+ new zr(),
1143
+ new zr(),
1144
+ new zr(),
1145
+ new zr()
1146
+ ].map((e) => q(e)), this._params = new Float32Array(16), this._kernels = [
1140
1147
  this._buildGridKernel(),
1141
1148
  this._buildBlurSourceKernel(),
1142
- this._buildBlurKernel(this._blur, this._blurTmp, !0),
1149
+ this._buildBlurKernel(this._blurSource, this._blurTmp, !0),
1143
1150
  this._buildBlurKernel(this._blurTmp, this._blur, !1)
1144
1151
  ], this._built = !1, this._restarts = 0, this._builtAt = {
1145
1152
  restarts: -1,
@@ -1147,41 +1154,41 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1147
1154
  }, this._stale = !1, this._paramsBuffer = null, this._disposed = !1;
1148
1155
  }
1149
1156
  _buildGridKernel() {
1150
- let e = this._inputNode, t = this._grid, n = this._widthU, r = this._heightU, i = this._cellsXU, a = this._logExposureU, o = q(...Ta, 0).xyz;
1157
+ let e = this._inputNode, t = this._grid, n = this._widthU, r = this._heightU, i = this._cellsXU, a = this._logExposureU, o = this._sceneOnlyU.greaterThan(R(0)), s = Y(...Aa, 0).xyz;
1151
1158
  return Tn(() => {
1152
- let s = L.y.mul(W(16)).add(L.x), c = Zn("uint", $).toAtomic(), l = Zn("uint", $).toAtomic();
1153
- N(s.lessThan(W($)), () => {
1154
- jn(c.element(s), W(0)), jn(l.element(s), W(0));
1159
+ let c = z.y.mul(K(16)).add(z.x), l = Zn("uint", $).toAtomic(), u = Zn("uint", $).toAtomic();
1160
+ F(c.lessThan(K($)), () => {
1161
+ jn(l.element(c), K(0)), jn(u.element(c), K(0));
1155
1162
  }), Qn();
1156
- let u = I(J.x).mul(I(da)).add(I(L.x).mul(I(8))), d = I(J.y).mul(I(da)).add(I(L.y).mul(I(8)));
1163
+ let d = R(X.x).mul(R(ha)).add(R(z.x).mul(R(8))), f = R(X.y).mul(R(ha)).add(R(z.y).mul(R(8)));
1157
1164
  En({
1158
- start: I(0),
1159
- end: I(8),
1165
+ start: R(0),
1166
+ end: R(8),
1160
1167
  type: "int",
1161
1168
  condition: "<",
1162
1169
  update: 2,
1163
1170
  name: "ty"
1164
1171
  }, ({ ty: t }) => {
1165
1172
  En({
1166
- start: I(0),
1167
- end: I(8),
1173
+ start: R(0),
1174
+ end: R(8),
1168
1175
  type: "int",
1169
1176
  condition: "<",
1170
1177
  update: 2,
1171
1178
  name: "tx"
1172
1179
  }, ({ tx: i }) => {
1173
- let s = u.add(i), f = d.add(t);
1174
- N(s.lessThan(n).and(f.lessThan(r)), () => {
1175
- let t = Bn(s.add(I(1)), n.sub(I(1))), i = Bn(f.add(I(1)), r.sub(I(1))), u = P(H(e, Rn(s, f)).xyz, o).add(P(H(e, Rn(t, f)).xyz, o)).add(P(H(e, Rn(s, i)).xyz, o)).add(P(H(e, Rn(t, i)).xyz, o)).mul(.25).toVar();
1176
- N(Fn(u).bitAnd(W(2139095040)).notEqual(W(2139095040)), () => {
1177
- let e = zn(R(u, Sa)).clamp(ha, ga).toVar(), t = e.add(a).sub(pa).div(ma - pa).clamp(0, 1).mul($ - 1).toVar(), n = W(In(t)).min(W($ - 1)), r = n.add(W(1)).min(W($ - 1)), i = t.sub(In(t)), o = F(1).sub(i), s = e.sub(ha).mul(_a);
1178
- kn(c.element(n), W(s.mul(o).add(.5))), kn(l.element(n), W(o.mul(_a).add(.5))), kn(c.element(r), W(s.mul(i).add(.5))), kn(l.element(r), W(i.mul(_a).add(.5)));
1180
+ let c = d.add(i), p = f.add(t);
1181
+ F(c.lessThan(n).and(p.lessThan(r)), () => {
1182
+ let t = Bn(c.add(R(1)), n.sub(R(1))), i = Bn(p.add(R(1)), r.sub(R(1))), d = W(e, Rn(c, p)).toVar(), f = W(e, Rn(t, p)).toVar(), m = W(e, Rn(c, i)).toVar(), h = W(e, Rn(t, i)).toVar(), g = (e) => U(o.and(e.w.lessThan(Ea)), L(0), L(1)), _ = g(d), v = g(f), y = g(m), b = g(h), x = _.add(v).add(y).add(b).toVar(), S = I(d.xyz, s).mul(_).add(I(f.xyz, s).mul(v)).add(I(m.xyz, s).mul(y)).add(I(h.xyz, s).mul(b)).div(B(x, 1e-6)).toVar(), C = x.mul(.25).toVar();
1183
+ F(Fn(S).bitAnd(K(2139095040)).notEqual(K(2139095040)).and(x.greaterThan(0)), () => {
1184
+ let e = zn(B(S, Da)).clamp(ya, ba).toVar(), t = e.add(a).sub(_a).div(va - _a).clamp(0, 1).mul($ - 1).toVar(), n = K(In(t)).min(K($ - 1)), r = n.add(K(1)).min(K($ - 1)), i = t.sub(In(t)).mul(C), o = L(1).sub(t.sub(In(t))).mul(C), s = e.sub(ya).mul(xa);
1185
+ kn(l.element(n), K(s.mul(o).add(.5))), kn(u.element(n), K(o.mul(xa).add(.5))), kn(l.element(r), K(s.mul(i).add(.5))), kn(u.element(r), K(i.mul(xa).add(.5)));
1179
1186
  });
1180
1187
  });
1181
1188
  });
1182
- }), Qn(), N(s.lessThan(W($)), () => {
1183
- let e = F(An(l.element(s))).div(_a), n = F(An(c.element(s))).div(_a).add(e.mul(ha)), r = W(J.y).mul(W(i)).add(W(J.x));
1184
- t.element(r.mul(W($)).add(s)).assign(K(n, e).div(fa));
1189
+ }), Qn(), F(c.lessThan(K($)), () => {
1190
+ let e = L(An(u.element(c))).div(xa), n = L(An(l.element(c))).div(xa).add(e.mul(ya)), r = K(X.y).mul(K(i)).add(K(X.x));
1191
+ t.element(r.mul(K($)).add(c)).assign(J(n, e).div(ga));
1185
1192
  });
1186
1193
  })().compute([
1187
1194
  1,
@@ -1194,40 +1201,40 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1194
1201
  ]);
1195
1202
  }
1196
1203
  _buildBlurSourceKernel() {
1197
- let e = this._inputNode, t = this._blur, n = this._widthU, r = this._heightU, i = this._blurWU, a = q(...Ta, 0).xyz;
1204
+ let e = this._inputNode, t = this._blurSource, n = this._widthU, r = this._heightU, i = this._blurWU, a = this._sceneOnlyU.greaterThan(R(0)), o = Y(...Aa, 0).xyz;
1198
1205
  return Tn(() => {
1199
- let o = L.y.mul(W(8)).add(L.x), s = I(J.x).mul(I(va)), c = I(J.y).mul(I(va)), l = F(0).toVar(), u = F(0).toVar();
1206
+ let s = z.y.mul(K(8)).add(z.x), c = R(X.x).mul(R(Sa)), l = R(X.y).mul(R(Sa)), u = L(0).toVar(), d = L(0).toVar(), f = L(0).toVar();
1200
1207
  En({
1201
- start: I(L.y),
1202
- end: I(va),
1208
+ start: R(z.y),
1209
+ end: R(Sa),
1203
1210
  type: "int",
1204
1211
  condition: "<",
1205
1212
  update: 8,
1206
1213
  name: "by"
1207
1214
  }, ({ by: t }) => {
1208
1215
  En({
1209
- start: I(L.x),
1210
- end: I(va),
1216
+ start: R(z.x),
1217
+ end: R(Sa),
1211
1218
  type: "int",
1212
1219
  condition: "<",
1213
1220
  update: 8,
1214
1221
  name: "bx"
1215
1222
  }, ({ bx: i }) => {
1216
- let o = s.add(i), d = c.add(t);
1217
- N(o.lessThan(n).and(d.lessThan(r)), () => {
1218
- let t = P(H(e, Rn(o, d)).xyz, a).toVar(), n = Fn(t).bitAnd(W(2139095040)).notEqual(W(2139095040));
1219
- l.addAssign(V(n, t.max(0), F(0))), u.addAssign(V(n, F(1), F(0)));
1223
+ let s = c.add(i), p = l.add(t);
1224
+ F(s.lessThan(n).and(p.lessThan(r)), () => {
1225
+ let t = W(e, Rn(s, p)).toVar(), n = I(t.xyz, o).toVar(), r = Fn(n).bitAnd(K(2139095040)).notEqual(K(2139095040)), i = U(a.and(t.w.lessThan(Ea)), L(0), L(1));
1226
+ u.addAssign(U(r, n.max(0).mul(i), L(0))), d.addAssign(U(r, i, L(0))), f.addAssign(U(r, L(1), L(0)));
1220
1227
  });
1221
1228
  });
1222
1229
  });
1223
- let d = Zn("float", 64), f = Zn("float", 64);
1224
- d.element(o).assign(l), f.element(o).assign(u), Qn();
1225
- for (let e = 32; e > 0; e >>= 1) N(o.lessThan(W(e)), () => {
1226
- d.element(o).addAssign(d.element(o.add(W(e)))), f.element(o).addAssign(f.element(o.add(W(e))));
1230
+ let p = Zn("float", 64), m = Zn("float", 64), h = Zn("float", 64);
1231
+ p.element(s).assign(u), m.element(s).assign(d), h.element(s).assign(f), Qn();
1232
+ for (let e = 32; e > 0; e >>= 1) F(s.lessThan(K(e)), () => {
1233
+ p.element(s).addAssign(p.element(s.add(K(e)))), m.element(s).addAssign(m.element(s.add(K(e)))), h.element(s).addAssign(h.element(s.add(K(e))));
1227
1234
  }), Qn();
1228
- N(o.equal(W(0)), () => {
1229
- let e = d.element(W(0)).div(R(f.element(W(0)), 1));
1230
- t.element(W(I(J.y).mul(i).add(I(J.x)))).assign(zn(R(e, Sa)).clamp(ha, ga));
1235
+ F(s.equal(K(0)), () => {
1236
+ let e = zn(B(p.element(K(0)).div(B(m.element(K(0)), 1)), Da)).clamp(ya, ba), n = U(a, m.element(K(0)).div(B(h.element(K(0)), 1)), L(1)).toVar();
1237
+ t.element(K(R(X.y).mul(i).add(R(X.x)))).assign(J(e.mul(n), n));
1231
1238
  });
1232
1239
  })().compute([
1233
1240
  1,
@@ -1242,23 +1249,25 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1242
1249
  _buildBlurKernel(e, t, n) {
1243
1250
  let r = this._blurWU, i = this._blurHU, a = this._radiusU;
1244
1251
  return Tn(() => {
1245
- let o = I(J.x).mul(I(8)).add(I(L.x)), s = I(J.y).mul(I(8)).add(I(L.y));
1246
- N(o.lessThan(r).and(s.lessThan(i)), () => {
1247
- let c = n ? r : i, l = n ? o : s, u = I(a.ceil()), d = F(0).toVar(), f = F(0).toVar();
1252
+ let o = R(X.x).mul(R(8)).add(R(z.x)), s = R(X.y).mul(R(8)).add(R(z.y));
1253
+ F(o.lessThan(r).and(s.lessThan(i)), () => {
1254
+ let c = n ? r : i, l = n ? o : s, u = R(a.ceil()), d = J(0).toVar(), f = L(0).toVar();
1248
1255
  En({
1249
1256
  start: u.negate(),
1250
- end: u.add(I(1)),
1257
+ end: u.add(R(1)),
1251
1258
  type: "int",
1252
1259
  condition: "<",
1253
1260
  name: "o"
1254
1261
  }, ({ o: t }) => {
1255
- let i = F(t).div(a), u = Nn(i.mul(i).mul(-16.7)), p = c.mul(I(2)), m = l.add(t).mod(p).add(p).mod(p).toVar();
1256
- N(m.greaterThanEqual(c), () => {
1257
- m.assign(p.sub(m).sub(I(1)));
1262
+ let i = L(t).div(a), u = Nn(i.mul(i).mul(-16.7)), p = c.mul(R(2)), m = l.add(t).mod(p).add(p).mod(p).toVar();
1263
+ F(m.greaterThanEqual(c), () => {
1264
+ m.assign(p.sub(m).sub(R(1)));
1258
1265
  });
1259
1266
  let h = n ? s.mul(r).add(m) : m.mul(r).add(o);
1260
- d.addAssign(e.element(W(h)).mul(u)), f.addAssign(u);
1261
- }), t.element(W(s.mul(r).add(o))).assign(d.div(f));
1267
+ d.addAssign(e.element(K(h)).mul(u)), f.addAssign(u);
1268
+ });
1269
+ let p = d.div(f).toVar();
1270
+ t.element(K(s.mul(r).add(o))).assign(n ? p : p.x.div(B(p.y, 1e-30)));
1262
1271
  });
1263
1272
  })().compute([
1264
1273
  1,
@@ -1276,14 +1285,14 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1276
1285
  render(e) {
1277
1286
  if (!this.enabled) return;
1278
1287
  let t = e.getState("pathtracer:samples") ?? 0, n = this._builtAt;
1279
- (this._stale || !this._built || n.restarts !== this._restarts || t - n.samples >= Ea(t)) && this.build(e);
1288
+ (this._stale || !this._built || n.restarts !== this._restarts || t - n.samples >= ja(t)) && this.build(e);
1280
1289
  }
1281
1290
  build(e = this.context) {
1282
1291
  let t = e?.getTexture("pathtracer:color"), n = t?.image?.width | 0, r = t?.image?.height | 0;
1283
1292
  if (!t || n < 1 || r < 1 || this._disposed) return !1;
1284
1293
  this._builtAt.restarts = this._restarts, this._builtAt.samples = e.getState("pathtracer:samples") ?? 0, this._stale = !1;
1285
- let i = Math.min(Ca, Math.ceil(n / da)), a = Math.min(Ca, Math.ceil(r / da)), o = Math.min(wa, Math.ceil(n / va)), s = Math.min(wa, Math.ceil(r / va)), c = Math.log2(Math.max(this.renderer.toneMappingExposure, 1e-6));
1286
- return this._inputNode.value = t, this._widthU.value = n, this._heightU.value = r, this._cellsXU.value = i, this._blurWU.value = o, this._blurHU.value = s, this._radiusU.value = Math.max(1, ba / 100 * o), this._logExposureU.value = c, this._kernels[0].dispatchSize = [
1294
+ let i = Math.min(Oa, Math.ceil(n / ha)), a = Math.min(Oa, Math.ceil(r / ha)), o = Math.min(ka, Math.ceil(n / Sa)), s = Math.min(ka, Math.ceil(r / Sa)), c = Math.log2(Math.max(this.renderer.toneMappingExposure, 1e-6));
1295
+ return this._inputNode.value = t, this._widthU.value = n, this._heightU.value = r, this._cellsXU.value = i, this._blurWU.value = o, this._blurHU.value = s, this._radiusU.value = Math.max(1, wa / 100 * o), this._logExposureU.value = c, this._sceneOnlyU.value = +(e.getState("pathtracer:backdrop") === "color"), this._kernels[0].dispatchSize = [
1287
1296
  i,
1288
1297
  a,
1289
1298
  1
@@ -1296,10 +1305,10 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1296
1305
  Math.ceil(s / 8),
1297
1306
  1
1298
1307
  ], this.renderer.compute(this._kernels), this._params.set([
1299
- n / da,
1300
- r / da,
1301
- n / va,
1302
- r / va,
1308
+ n / ha,
1309
+ r / ha,
1310
+ n / Sa,
1311
+ r / Sa,
1303
1312
  i,
1304
1313
  a,
1305
1314
  o,
@@ -1309,7 +1318,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1309
1318
  }
1310
1319
  _writeParams() {
1311
1320
  let e = this._params;
1312
- e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] = ya, e[13] = xa;
1321
+ e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] = Ca, e[13] = Ta;
1313
1322
  for (let t = 0; t < 4; t++) this._p[t].value.fromArray(e, t * 4);
1314
1323
  this.onChange?.();
1315
1324
  }
@@ -1328,14 +1337,14 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1328
1337
  this.enabled !== e && (this.enabled = e, this._stale = !0, this.onChange?.());
1329
1338
  }
1330
1339
  gainNode(e, t) {
1331
- let n = Kn(this._grid.value, "vec2", Ca * Ca * $).toReadOnly(), r = Kn(this._blur.value, "float", wa * wa).toReadOnly(), [i, a, o, s] = this._p;
1340
+ let n = Kn(this._grid.value, "vec2", Oa * Oa * $).toReadOnly(), r = Kn(this._blur.value, "float", ka * ka).toReadOnly(), [i, a, o, s] = this._p;
1332
1341
  return Tn(([e, t]) => {
1333
- let c = zn(R(P(e, q(...Ta, 0).xyz), Sa)).min(ga).toVar(), l = zn(qn).toVar(), u = Rn(a.zw), d = t.mul(i.zw).sub(.5).clamp(K(0), K(u.sub(I(1)))).toVar(), f = Rn(In(d)).toVar(), p = f.add(I(1)).min(u.sub(I(1))).toVar(), m = d.sub(In(d)).toVar(), h = (e, t) => r.element(W(t.mul(u.x).add(e))), g = z(z(h(f.x, f.y), h(p.x, f.y), m.x), z(h(f.x, p.y), h(p.x, p.y), m.x), m.y).toVar(), _ = Rn(a.xy), v = t.mul(i.xy).sub(.5).clamp(K(0), K(_.sub(I(1)))).toVar(), y = c.add(o.x).sub(pa).div(ma - pa).clamp(0, 1).mul($ - 1).toVar(), b = I(In(v.x)), x = I(In(v.y)), S = I(In(y)), C = v.x.sub(In(v.x)), w = v.y.sub(In(v.y)), T = y.sub(In(y)), E = K(0).toVar();
1342
+ let c = zn(B(I(e, Y(...Aa, 0).xyz), Da)).min(ba).toVar(), l = zn(qn).toVar(), u = Rn(a.zw), d = t.mul(i.zw).sub(.5).clamp(J(0), J(u.sub(R(1)))).toVar(), f = Rn(In(d)).toVar(), p = f.add(R(1)).min(u.sub(R(1))).toVar(), m = d.sub(In(d)).toVar(), h = (e, t) => r.element(K(t.mul(u.x).add(e))), g = V(V(h(f.x, f.y), h(p.x, f.y), m.x), V(h(f.x, p.y), h(p.x, p.y), m.x), m.y).toVar(), _ = Rn(a.xy), v = t.mul(i.xy).sub(.5).clamp(J(0), J(_.sub(R(1)))).toVar(), y = c.add(o.x).sub(_a).div(va - _a).clamp(0, 1).mul($ - 1).toVar(), b = R(In(v.x)), x = R(In(v.y)), S = R(In(y)), C = v.x.sub(In(v.x)), w = v.y.sub(In(v.y)), T = y.sub(In(y)), E = J(0).toVar();
1334
1343
  for (let e = 0; e < 8; e++) {
1335
- let t = e & 1, r = e >> 1 & 1, i = e >> 2, a = (t ? C : C.oneMinus()).mul(r ? w : w.oneMinus()).mul(i ? T : T.oneMinus()), o = b.add(I(t)).min(_.x.sub(I(1))), s = x.add(I(r)).min(_.y.sub(I(1))), c = S.add(I(i)).min(I($ - 1));
1336
- E.addAssign(n.element(W(s.mul(_.x).add(o).mul(I($)).add(c))).mul(a));
1344
+ let t = e & 1, r = e >> 1 & 1, i = e >> 2, a = (t ? C : C.oneMinus()).mul(r ? w : w.oneMinus()).mul(i ? T : T.oneMinus()), o = b.add(R(t)).min(_.x.sub(R(1))), s = x.add(R(r)).min(_.y.sub(R(1))), c = S.add(R(i)).min(R($ - 1));
1345
+ E.addAssign(n.element(K(s.mul(_.x).add(o).mul(R($)).add(c))).mul(a));
1337
1346
  }
1338
- let D = z(V(E.y.mul(fa).lessThan(.001), g, E.x.div(E.y)), g, s.x).add(l).toVar(), ee = c.add(l), O = V(D.greaterThan(s.y), o.y, o.z);
1347
+ let D = V(U(E.y.mul(ga).lessThan(.001), g, E.x.div(E.y)), g, s.x).add(l).toVar(), ee = c.add(l), O = U(D.greaterThan(s.y), o.y, o.z);
1339
1348
  return Pn(s.y.add(D.sub(s.y).mul(O)).add(ee.sub(D).mul(o.w)).sub(ee));
1340
1349
  })(e, t);
1341
1350
  }
@@ -1351,7 +1360,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1351
1360
  let r = this._params.slice(), i = () => Promise.all([this.renderer.getArrayBufferAsync(this._grid.value), this.renderer.getArrayBufferAsync(this._blur.value)]);
1352
1361
  return {
1353
1362
  key: "local-exposure",
1354
- wgsl: ka,
1363
+ wgsl: Pa,
1355
1364
  device: e.device,
1356
1365
  entries: [
1357
1366
  {
@@ -1369,7 +1378,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1369
1378
  ],
1370
1379
  cpu: async () => {
1371
1380
  let [e, t] = await i(), n = new Float32Array(e), a = new Float32Array(t);
1372
- return (e, t, i, o) => Oa(r, n, a, e, t, i, o);
1381
+ return (e, t, i, o) => Na(r, n, a, e, t, i, o);
1373
1382
  },
1374
1383
  copyTo: async (e) => {
1375
1384
  let [t, n] = await i(), a = [
@@ -1386,7 +1395,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1386
1395
  });
1387
1396
  return {
1388
1397
  key: "local-exposure",
1389
- wgsl: ka,
1398
+ wgsl: Pa,
1390
1399
  device: e,
1391
1400
  entries: a.map((e, t) => ({
1392
1401
  binding: t,
@@ -1404,16 +1413,16 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1404
1413
  for (let e of this._kernels) e.dispose();
1405
1414
  this._inputNode.dispose(), this._paramsBuffer?.destroy(), this._paramsBuffer = null;
1406
1415
  }
1407
- }, ja = new Z(), Ma = new Z();
1408
- function Na(e, t) {
1409
- return Ma.subVectors(e, t.position).dot(t.getWorldDirection(ja));
1416
+ }, Ia = new Q(), La = new Q();
1417
+ function Ra(e, t) {
1418
+ return La.subVectors(e, t.position).dot(t.getWorldDirection(Ia));
1410
1419
  }
1411
- function Pa(e, t, n = !1) {
1412
- return n ? e.distance : Na(e.point, t);
1420
+ function za(e, t, n = !1) {
1421
+ return n ? e.distance : Ra(e.point, t);
1413
1422
  }
1414
- var Fa = class extends ur {
1423
+ var Ba = class extends ur {
1415
1424
  constructor({ scene: e, camera: t, canvas: n, assetLoader: r, pathTracer: i, floorPlane: a, isGeometryOnDisk: o = null }) {
1416
- super(), this.scene = e, this.isGeometryOnDisk = o, this.camera = t, this.canvas = n, this.assetLoader = r, this.pathTracer = i, this.floorPlane = a, this.raycaster = new kr(), this.focusMode = !1, this.focusPointIndicator = null, this.afPointPlacementMode = !1, this.handleAFPointClick = this.handleAFPointClick.bind(this), this.selectedObject = null, this.selectMode = !1, this.clickTimeout = null, this.mouseDownPosition = null, this.dragThreshold = 5, this.handleFocusClick = this.handleFocusClick.bind(this), this.handleSelectClick = this.handleSelectClick.bind(this), this.handleSelectDoubleClick = this.handleSelectDoubleClick.bind(this), this.handleMouseDown = this.handleMouseDown.bind(this), this.handleMouseUp = this.handleMouseUp.bind(this), this.handleContextMenu = this.handleContextMenu.bind(this), this.handleContextPointerDown = this.handleContextPointerDown.bind(this), this.handleContextPointerUp = this.handleContextPointerUp.bind(this), this.contextPointerDownPosition = null, this.canvas.addEventListener("pointerdown", this.handleContextPointerDown), this.canvas.addEventListener("pointerup", this.handleContextPointerUp), this.canvas.addEventListener("contextmenu", this.handleContextMenu), this._overlayManager = null, this._transformManager = null, this._appDispatch = null, this._orbitControls = null, this._helperScene = null;
1425
+ super(), this.scene = e, this.isGeometryOnDisk = o, this.camera = t, this.canvas = n, this.assetLoader = r, this.pathTracer = i, this.floorPlane = a, this.raycaster = new Ar(), this.focusMode = !1, this.focusPointIndicator = null, this.afPointPlacementMode = !1, this.handleAFPointClick = this.handleAFPointClick.bind(this), this.selectedObject = null, this.selectMode = !1, this.clickTimeout = null, this.mouseDownPosition = null, this.dragThreshold = 5, this.handleFocusClick = this.handleFocusClick.bind(this), this.handleSelectClick = this.handleSelectClick.bind(this), this.handleSelectDoubleClick = this.handleSelectDoubleClick.bind(this), this.handleMouseDown = this.handleMouseDown.bind(this), this.handleMouseUp = this.handleMouseUp.bind(this), this.handleContextMenu = this.handleContextMenu.bind(this), this.handleContextPointerDown = this.handleContextPointerDown.bind(this), this.handleContextPointerUp = this.handleContextPointerUp.bind(this), this.contextPointerDownPosition = null, this.canvas.addEventListener("pointerdown", this.handleContextPointerDown), this.canvas.addEventListener("pointerup", this.handleContextPointerUp), this.canvas.addEventListener("contextmenu", this.handleContextMenu), this._overlayManager = null, this._transformManager = null, this._appDispatch = null, this._orbitControls = null, this._helperScene = null;
1417
1426
  }
1418
1427
  setDependencies({ overlayManager: e, transformManager: t, appDispatch: n, orbitControls: r, helperScene: i }) {
1419
1428
  this._overlayManager = e || null, this._transformManager = t || null, this._appDispatch = n || null, this._orbitControls = r || null, this._helperScene = i || null;
@@ -1421,7 +1430,7 @@ var Fa = class extends ur {
1421
1430
  select(e) {
1422
1431
  let t = this._overlayManager?.getHelper("outline");
1423
1432
  t && t.setSelectedObjects(e && !this.isGeometryOnDisk?.() ? [e] : []), this.selectedObject = e || null, e ? this._transformManager?.attach(e) : this._transformManager?.detach(), this._appDispatch?.({
1424
- type: M.OBJECT_SELECTED,
1433
+ type: P.OBJECT_SELECTED,
1425
1434
  object: e || null
1426
1435
  });
1427
1436
  }
@@ -1445,7 +1454,7 @@ var Fa = class extends ur {
1445
1454
  this.raycaster.setFromCamera(t, this.camera);
1446
1455
  let n = this._intersectScene();
1447
1456
  if (n.length > 0) {
1448
- let e = n[0], t = this.pathTracer?.cameraProjection?.value === Oe.equirectangular, r = Pa(e, this.camera, t);
1457
+ let e = n[0], t = this.pathTracer?.cameraProjection?.value === Oe.equirectangular, r = za(e, this.camera, t);
1449
1458
  this.showFocusPoint(e.point), this.toggleFocusMode(), this.dispatchEvent({
1450
1459
  type: "focusChanged",
1451
1460
  distance: r / this.assetLoader.getSceneScale(),
@@ -1454,7 +1463,7 @@ var Fa = class extends ur {
1454
1463
  }
1455
1464
  }
1456
1465
  showFocusPoint(e) {
1457
- this.focusPointIndicator && this.scene.remove(this.focusPointIndicator), this.focusPointIndicator = new yr(new Nr(this.assetLoader.getSceneScale() * .02, 16, 16), new br({
1466
+ this.focusPointIndicator && this.scene.remove(this.focusPointIndicator), this.focusPointIndicator = new br(new Pr(this.assetLoader.getSceneScale() * .02, 16, 16), new xr({
1458
1467
  color: 65280,
1459
1468
  transparent: !0,
1460
1469
  opacity: .8,
@@ -1585,7 +1594,8 @@ var Fa = class extends ur {
1585
1594
  };
1586
1595
  }
1587
1596
  _intersectScene() {
1588
- return this.isGeometryOnDisk?.() ? [] : this.raycaster.intersectObjects(this.scene.children, !0);
1597
+ let e = this.camera.userData?.clipStart ?? 0;
1598
+ return this.raycaster.near = e > 0 && !this.camera.isOrthographicCamera ? e / Math.max(this.raycaster.ray.direction.dot(this.camera.getWorldDirection(Ia)), 1e-4) : 0, this.isGeometryOnDisk?.() ? [] : this.raycaster.intersectObjects(this.scene.children, !0);
1589
1599
  }
1590
1600
  pickSurface(e, t) {
1591
1601
  return this.raycaster.setFromCamera({
@@ -1620,35 +1630,35 @@ var Fa = class extends ur {
1620
1630
  wireAppEvents(e) {
1621
1631
  this.addEventListener("objectSelected", (t) => {
1622
1632
  this.select(t.object), e.refreshFrame(), e.dispatchEvent({
1623
- type: M.OBJECT_SELECTED,
1633
+ type: P.OBJECT_SELECTED,
1624
1634
  object: t.object,
1625
1635
  uuid: t.uuid
1626
1636
  });
1627
1637
  }), this.addEventListener("objectDeselected", (t) => {
1628
1638
  this.select(null), e.refreshFrame(), e.dispatchEvent({
1629
- type: M.OBJECT_DESELECTED,
1639
+ type: P.OBJECT_DESELECTED,
1630
1640
  object: t.object,
1631
1641
  uuid: t.uuid
1632
1642
  });
1633
1643
  }), this.addEventListener("selectModeChanged", (t) => {
1634
1644
  e.dispatchEvent({
1635
- type: M.SELECT_MODE_CHANGED,
1645
+ type: P.SELECT_MODE_CHANGED,
1636
1646
  enabled: t.enabled
1637
1647
  });
1638
1648
  }), this.addEventListener("objectDoubleClicked", (t) => {
1639
1649
  this.select(t.object), e.refreshFrame(), e.dispatchEvent({
1640
- type: M.OBJECT_DOUBLE_CLICKED,
1650
+ type: P.OBJECT_DOUBLE_CLICKED,
1641
1651
  object: t.object,
1642
1652
  uuid: t.uuid
1643
1653
  });
1644
1654
  }), this.addEventListener("focusChanged", (t) => {
1645
1655
  e.settings.set("focusDistance", t.worldDistance), e.dispatchEvent({
1646
- type: M.FOCUS_CHANGED,
1656
+ type: P.FOCUS_CHANGED,
1647
1657
  distance: t.distance
1648
1658
  });
1649
1659
  }), this.addEventListener("afPointPlaced", (t) => {
1650
1660
  e.dispatchEvent({
1651
- type: M.AF_POINT_PLACED,
1661
+ type: P.AF_POINT_PLACED,
1652
1662
  point: t.point
1653
1663
  });
1654
1664
  });
@@ -1656,7 +1666,7 @@ var Fa = class extends ur {
1656
1666
  dispose() {
1657
1667
  this.canvas.removeEventListener("click", this.handleAFPointClick), this.canvas.removeEventListener("click", this.handleFocusClick), this.canvas.removeEventListener("mousedown", this.handleMouseDown), this.canvas.removeEventListener("mouseup", this.handleMouseUp), this.canvas.removeEventListener("click", this.handleSelectClick), this.canvas.removeEventListener("dblclick", this.handleSelectDoubleClick), this.canvas.removeEventListener("contextmenu", this.handleContextMenu), this.canvas.removeEventListener("pointerdown", this.handleContextPointerDown), this.canvas.removeEventListener("pointerup", this.handleContextPointerUp), this.clickTimeout &&= (clearTimeout(this.clickTimeout), null), this.mouseDownPosition = null, this.contextPointerDownPosition = null, this.focusPointIndicator &&= (this.scene.remove(this.focusPointIndicator), null), this.canvas.style.cursor = "auto", this.scene = null, this.camera = null, this.canvas = null, this.assetLoader = null, this.pathTracer = null, this.floorPlane = null, this.raycaster = null;
1658
1668
  }
1659
- }, Ia = 8, La = 4, Ra = .25, za = _r.degToRad(89), Ba = .25, Va = {
1669
+ }, Va = 8, Ha = 4, Ua = .25, Wa = _r.degToRad(89), Ga = .25, Ka = {
1660
1670
  KeyD: [
1661
1671
  1,
1662
1672
  0,
@@ -1707,15 +1717,15 @@ var Fa = class extends ur {
1707
1717
  0,
1708
1718
  -1
1709
1719
  ]
1710
- }, Ha = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=textbox], [role=combobox], [role=listbox], [role=menu], [role=menuitem]", Ua = (e) => e.shiftKey ? La : e.altKey ? Ra : 1, Wa = { type: "change" }, Ga = { type: "start" }, Ka = new Z(), qa = new Z(), Ja = new Z(), Ya = new Z(), Xa = new Dr(), Za = class extends or {
1720
+ }, qa = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=textbox], [role=combobox], [role=listbox], [role=menu], [role=menuitem]", Ja = (e) => e.shiftKey ? Ha : e.altKey ? Ua : 1, Ya = { type: "change" }, Xa = { type: "start" }, Za = new Q(), Qa = new Q(), $a = new Q(), eo = new Q(), to = new Or(), no = class extends or {
1711
1721
  constructor(e, t, n) {
1712
- super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 / Ia, this._held = /* @__PURE__ */ new Set(), this._factor = 1, this._lastTime = 0, this._drag = null, this._onKeyDown = this._onKeyDown.bind(this), this._onKeyUp = this._onKeyUp.bind(this), this.release = this.release.bind(this), this._onPointerDown = this._onPointerDown.bind(this), this._onPointerMove = this._onPointerMove.bind(this), this._onPointerUp = this._onPointerUp.bind(this), t && this.connect(t);
1722
+ super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 / Va, this._held = /* @__PURE__ */ new Set(), this._factor = 1, this._lastTime = 0, this._drag = null, this._onKeyDown = this._onKeyDown.bind(this), this._onKeyUp = this._onKeyUp.bind(this), this.release = this.release.bind(this), this._onPointerDown = this._onPointerDown.bind(this), this._onPointerMove = this._onPointerMove.bind(this), this._onPointerUp = this._onPointerUp.bind(this), t && this.connect(t);
1713
1723
  }
1714
1724
  get active() {
1715
1725
  return this.enabled && this.orbit.enabled;
1716
1726
  }
1717
1727
  fitSpeed(e) {
1718
- this.speed = (e > 0 ? e : 1) / Ia;
1728
+ this.speed = (e > 0 ? e : 1) / Va;
1719
1729
  }
1720
1730
  connect(e) {
1721
1731
  super.connect(e);
@@ -1735,34 +1745,34 @@ var Fa = class extends ur {
1735
1745
  if (!this._held.size || !this.active) return !1;
1736
1746
  let t = 0, n = 0, r = 0;
1737
1747
  for (let e of this._held) {
1738
- let [i, a, o] = Va[e];
1748
+ let [i, a, o] = Ka[e];
1739
1749
  t += i, n += a, r += o;
1740
1750
  }
1741
1751
  if (!t && !n && !r) return !1;
1742
1752
  let i = this.object;
1743
- return qa.set(1, 0, 0).applyQuaternion(i.quaternion), Ka.crossVectors(i.up, qa).normalize(), qa.crossVectors(Ka, i.up), Ja.set(0, 0, 0).addScaledVector(qa, t).addScaledVector(Ka, n).addScaledVector(i.up, r).normalize().multiplyScalar(this.speed * this._factor * e), i.position.add(Ja), this.orbit.target.add(Ja), i.updateMatrixWorld(), this.dispatchEvent(Wa), !0;
1753
+ return Qa.set(1, 0, 0).applyQuaternion(i.quaternion), Za.crossVectors(i.up, Qa).normalize(), Qa.crossVectors(Za, i.up), $a.set(0, 0, 0).addScaledVector(Qa, t).addScaledVector(Za, n).addScaledVector(i.up, r).normalize().multiplyScalar(this.speed * this._factor * e), i.position.add($a), this.orbit.target.add($a), i.updateMatrixWorld(), this.dispatchEvent(Ya), !0;
1744
1754
  }
1745
1755
  _elapsed() {
1746
- let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3, Ba);
1756
+ let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3, Ga);
1747
1757
  return this._lastTime = e, t;
1748
1758
  }
1749
1759
  _look(e, t) {
1750
1760
  let n = this.object, r = this.orbit.target, i = n.position.distanceTo(r) || 1, a = _r.degToRad(n.fov) / (this.domElement.clientHeight || 1);
1751
- n.quaternion.premultiply(Xa.setFromAxisAngle(n.up, e * a)), n.getWorldDirection(Ka);
1752
- let o = Math.asin(_r.clamp(Ka.dot(n.up), -1, 1)), s = _r.clamp(o + t * a, -za, za);
1753
- n.quaternion.multiply(Xa.setFromAxisAngle(Ya.set(1, 0, 0), s - o)), n.updateMatrixWorld(), r.copy(n.position).addScaledVector(n.getWorldDirection(Ka), i), this.dispatchEvent(Wa);
1761
+ n.quaternion.premultiply(to.setFromAxisAngle(n.up, e * a)), n.getWorldDirection(Za);
1762
+ let o = Math.asin(_r.clamp(Za.dot(n.up), -1, 1)), s = _r.clamp(o + t * a, -Wa, Wa);
1763
+ n.quaternion.multiply(to.setFromAxisAngle(eo.set(1, 0, 0), s - o)), n.updateMatrixWorld(), r.copy(n.position).addScaledVector(n.getWorldDirection(Za), i), this.dispatchEvent(Ya);
1754
1764
  }
1755
1765
  _onKeyDown(e) {
1756
- if (!(!this.active || e.defaultPrevented || e.target?.closest?.(Ha))) {
1766
+ if (!(!this.active || e.defaultPrevented || e.target?.closest?.(qa))) {
1757
1767
  if (e.metaKey || e.ctrlKey) {
1758
1768
  this.release();
1759
1769
  return;
1760
1770
  }
1761
- this._factor = Ua(e), Va[e.code] && (e.preventDefault(), !this._held.has(e.code) && (this._held.add(e.code), this._held.size === 1 && (this._lastTime = performance.now(), this.dispatchEvent(Ga))));
1771
+ this._factor = Ja(e), Ka[e.code] && (e.preventDefault(), !this._held.has(e.code) && (this._held.add(e.code), this._held.size === 1 && (this._lastTime = performance.now(), this.dispatchEvent(Xa))));
1762
1772
  }
1763
1773
  }
1764
1774
  _onKeyUp(e) {
1765
- this._factor = Ua(e), this._held.delete(e.code);
1775
+ this._factor = Ja(e), this._held.delete(e.code);
1766
1776
  }
1767
1777
  release() {
1768
1778
  this._held.clear(), this._factor = 1;
@@ -1783,25 +1793,25 @@ var Fa = class extends ur {
1783
1793
  _onPointerUp(e) {
1784
1794
  this._drag?.id === e.pointerId && (this._drag = null, this.domElement.releasePointerCapture?.(e.pointerId));
1785
1795
  }
1786
- }, Qa = {
1796
+ }, ro = {
1787
1797
  autoFocusMode: "auto",
1788
1798
  afScreenPoint: {
1789
1799
  x: .5,
1790
1800
  y: .5
1791
1801
  },
1792
1802
  afSmoothingFactor: .15
1793
- }, $a = .05, eo = 10, to = .5, no = Object.freeze(new Z(1, 1, 1)), ro = (e) => e?.isOrthographicCamera ? (e.top - e.bottom) / e.zoom : null, io = class extends ur {
1803
+ }, io = .05, ao = 10, oo = .5, so = Object.freeze(new Q(1, 1, 1)), co = (e) => e?.isOrthographicCamera ? (e.top - e.bottom) / e.zoom : null, lo = class extends ur {
1794
1804
  constructor(e) {
1795
1805
  super();
1796
1806
  let t = e.clientWidth, n = e.clientHeight;
1797
- this.camera = new g(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new Br(this.camera, e), this.controls.screenSpacePanning = !0, this.controls.zoomToCursor = !0, this.controls.saveState(), this._reportedOrthoHeight = null, this._reportOrthoHeight = this._reportOrthoHeight.bind(this), this.controls.addEventListener("change", this._reportOrthoHeight), this.walkControls = new Za(this.camera, e, this.controls), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this._userCameraCounter = 0, this.autoFocusMode = Qa.autoFocusMode, this.afScreenPoint = { ...Qa.afScreenPoint }, this.afSmoothingFactor = Qa.afSmoothingFactor, this._lastValidFocusDistance = null, this._smoothedFocusDistance = null, this._afPointDirty = !1, this._afSuspended = !1, this._afPick = null, this._defaultCameraState = null, this._onResize = null, this._onReset = null, this._getSettings = null, this._applySettings = null;
1807
+ this.camera = new g(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new Vr(this.camera, e), this.controls.screenSpacePanning = !0, this.controls.zoomToCursor = !0, this.controls.saveState(), this._reportedOrthoHeight = null, this._reportOrthoHeight = this._reportOrthoHeight.bind(this), this.controls.addEventListener("change", this._reportOrthoHeight), this.walkControls = new no(this.camera, e, this.controls), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this._userCameraCounter = 0, this.autoFocusMode = ro.autoFocusMode, this.afScreenPoint = { ...ro.afScreenPoint }, this.afSmoothingFactor = ro.afSmoothingFactor, this._lastValidFocusDistance = null, this._smoothedFocusDistance = null, this._afPointDirty = !1, this._afSuspended = !1, this._afPick = null, this._defaultCameraState = null, this._onResize = null, this._onReset = null, this._getSettings = null, this._applySettings = null;
1798
1808
  }
1799
1809
  setCameras(e) {
1800
- this.cameras = e, this._userCameraCounter = 0, this.resetAutoFocus();
1810
+ this.cameras = e, this._userCameraCounter = 0, this.camera.userData.clipStart = 0, this.resetAutoFocus();
1801
1811
  }
1802
1812
  addCameraFromView(e) {
1803
- let t = this.camera, n = t.orthographic ? new wr(t.left, t.right, t.top, t.bottom, t.near, t.far) : new Tr(t.fov, t.aspect, t.near, t.far);
1804
- return n.zoom = t.zoom, n.position.copy(t.position), n.quaternion.copy(t.quaternion), n.scale.copy(t.scale), n.updateMatrixWorld(!0), n.userData.__rayzeeUserCamera = !0, n.userData.__rayzeeEffects = this._captureEffects(), this.controls && (n.userData.__rayzeeOrbitTarget = this.controls.target.clone()), this._userCameraCounter += 1, n.name = e || `View Camera ${this._userCameraCounter}`, this.cameras.push(n), this.cameras.length - 1;
1813
+ let t = this.camera, n = t.orthographic ? new Tr(t.left, t.right, t.top, t.bottom, t.near, t.far) : new Er(t.fov, t.aspect, t.near, t.far);
1814
+ return n.zoom = t.zoom, n.position.copy(t.position), n.quaternion.copy(t.quaternion), n.scale.copy(t.scale), n.updateMatrixWorld(!0), n.userData.__rayzeeUserCamera = !0, n.userData.__rayzeeEffects = this._captureEffects(), this.controls && (n.userData.__rayzeeOrbitTarget = this.controls.target.clone()), t.userData.clipStart > 0 && (n.userData.clipStart = t.userData.clipStart), this._userCameraCounter += 1, n.name = e || `View Camera ${this._userCameraCounter}`, this.cameras.push(n), this.cameras.length - 1;
1805
1815
  }
1806
1816
  removeCamera(e) {
1807
1817
  if (!Number.isInteger(e) || e <= 0 || e >= this.cameras.length || !this.cameras[e]?.userData?.__rayzeeUserCamera) return !1;
@@ -1854,12 +1864,12 @@ var Fa = class extends ur {
1854
1864
  target: this.controls ? this.controls.target.clone() : null
1855
1865
  }), this.currentCameraIndex = e, e === 0 && this._defaultCameraState) {
1856
1866
  let e = this._defaultCameraState;
1857
- this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ?? no), this.camera.fov = e.fov, this.camera.near = e.near, this.camera.far = e.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls && e.target && (this.controls.target.copy(e.target), this.controls.update());
1867
+ this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ?? so), this.camera.fov = e.fov, this.camera.near = e.near, this.camera.far = e.far, this.camera.userData.clipStart = 0, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls && e.target && (this.controls.target.copy(e.target), this.controls.update());
1858
1868
  } else this._placeAt(this.cameras[e], t);
1859
1869
  this.resetAutoFocus();
1860
1870
  let a = this.cameras[e], o = a?.userData?.__rayzeeEffects;
1861
- this._showOrthographic(o ? o.orthoHeight : ro(a)), this._applyEffects(o), n?.(), r?.(), this.dispatchEvent({
1862
- type: M.CAMERA_SWITCHED,
1871
+ this._showOrthographic(o ? o.orthoHeight : co(a)), this._applyEffects(o), n?.(), r?.(), this.dispatchEvent({
1872
+ type: P.CAMERA_SWITCHED,
1863
1873
  cameraIndex: e,
1864
1874
  effects: this._captureEffects(),
1865
1875
  fov: this.camera.fov,
@@ -1873,15 +1883,15 @@ var Fa = class extends ur {
1873
1883
  return;
1874
1884
  }
1875
1885
  this._placeAt(e, this._getSettings?.("focusDistance"));
1876
- let t = ro(e);
1886
+ let t = co(e);
1877
1887
  this.camera.orthographic && this._setView(!0, t ? t / 2 : this.camera.orthoHalfHeight), this._onReset?.();
1878
1888
  }
1879
1889
  _placeAt(e, t) {
1880
- if (this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale), e.isPerspectiveCamera && (this.camera.fov = e.fov), this.camera.near = e.near, this.camera.far = e.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), !this.controls) return;
1890
+ if (this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale), e.isPerspectiveCamera && (this.camera.fov = e.fov), this.camera.near = e.near, this.camera.far = e.far, this.camera.userData.clipStart = e.userData?.clipStart ?? 0, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), !this.controls) return;
1881
1891
  let n = e.userData?.__rayzeeOrbitTarget;
1882
1892
  if (n) this.controls.target.copy(n);
1883
1893
  else {
1884
- let n = new Z(0, 0, -1).applyQuaternion(e.quaternion);
1894
+ let n = new Q(0, 0, -1).applyQuaternion(e.quaternion);
1885
1895
  this.controls.target.copy(this.camera.position).addScaledVector(n, t || 5);
1886
1896
  }
1887
1897
  this.controls.update();
@@ -1903,7 +1913,7 @@ var Fa = class extends ur {
1903
1913
  }
1904
1914
  }
1905
1915
  get orthoHeight() {
1906
- return ro(this.camera);
1916
+ return co(this.camera);
1907
1917
  }
1908
1918
  setOrthoHeight(e) {
1909
1919
  e > 0 && (this._setView(this.camera.orthographic, e / 2), this._onReset?.());
@@ -1922,7 +1932,7 @@ var Fa = class extends ur {
1922
1932
  if (!this.camera.orthographic) return;
1923
1933
  let e = this.orthoHeight;
1924
1934
  e !== this._reportedOrthoHeight && (this._reportedOrthoHeight = e, this.dispatchEvent({
1925
- type: M.ORTHO_HEIGHT_UPDATED,
1935
+ type: P.ORTHO_HEIGHT_UPDATED,
1926
1936
  height: e
1927
1937
  }));
1928
1938
  }
@@ -1938,7 +1948,7 @@ var Fa = class extends ur {
1938
1948
  let r = this.interactionManager?.pickSurface(0, 0);
1939
1949
  if (!r) return;
1940
1950
  let i = _r.clamp(r.distance, n.minDistance, n.maxDistance);
1941
- n.target.copy(this.camera.position).addScaledVector(this.camera.getWorldDirection(new Z()), i), n.update();
1951
+ n.target.copy(this.camera.position).addScaledVector(this.camera.getWorldDirection(new Q()), i), n.update();
1942
1952
  }
1943
1953
  get navigationMode() {
1944
1954
  return this.walkControls.enabled ? "walk" : "orbit";
@@ -1970,6 +1980,7 @@ var Fa = class extends ur {
1970
1980
  fov: e.fov,
1971
1981
  near: e.near,
1972
1982
  far: e.far,
1983
+ clipStart: e.userData.clipStart ?? 0,
1973
1984
  zoom: e.zoom,
1974
1985
  orthographic: !!e.orthographic,
1975
1986
  orthoHalfHeight: e.orthoHalfHeight,
@@ -1993,7 +2004,7 @@ var Fa = class extends ur {
1993
2004
  let n = {
1994
2005
  index: t,
1995
2006
  name: e.name ?? "",
1996
- effects: be(e.userData?.__rayzeeEffects) ?? null
2007
+ effects: ye(e.userData?.__rayzeeEffects) ?? null
1997
2008
  };
1998
2009
  return t === 0 || !e.userData?.__rayzeeUserCamera ? n : {
1999
2010
  ...n,
@@ -2009,6 +2020,7 @@ var Fa = class extends ur {
2009
2020
  aspect: e.aspect ?? null,
2010
2021
  near: e.near,
2011
2022
  far: e.far,
2023
+ clipStart: e.userData.clipStart ?? 0,
2012
2024
  zoom: e.zoom,
2013
2025
  position: e.position.toArray(),
2014
2026
  quaternion: e.quaternion.toArray(),
@@ -2025,8 +2037,8 @@ var Fa = class extends ur {
2025
2037
  let n = /* @__PURE__ */ new Map();
2026
2038
  for (let r of e.cameras ?? []) {
2027
2039
  if (r.user) {
2028
- let e = r.orthographic ? new wr(...r.frustum, r.near, r.far) : new Tr(r.fov, r.aspect, r.near, r.far);
2029
- e.name = r.name, e.zoom = r.zoom ?? 1, e.position.fromArray(r.position), e.quaternion.fromArray(r.quaternion), e.scale.fromArray(r.scale), e.updateProjectionMatrix(), e.updateMatrixWorld(!0), e.userData.__rayzeeUserCamera = !0, e.userData.__rayzeeEffects = ye(r.effects), r.orbitTarget && (e.userData.__rayzeeOrbitTarget = new Z().fromArray(r.orbitTarget)), n.set(r.index, this.cameras.length), this.cameras.push(e);
2040
+ let e = r.orthographic ? new Tr(...r.frustum, r.near, r.far) : new Er(r.fov, r.aspect, r.near, r.far);
2041
+ e.name = r.name, e.zoom = r.zoom ?? 1, e.position.fromArray(r.position), e.quaternion.fromArray(r.quaternion), e.scale.fromArray(r.scale), e.updateProjectionMatrix(), e.updateMatrixWorld(!0), e.userData.__rayzeeUserCamera = !0, e.userData.__rayzeeEffects = le(r.effects), r.clipStart > 0 && (e.userData.clipStart = r.clipStart), r.orbitTarget && (e.userData.__rayzeeOrbitTarget = new Q().fromArray(r.orbitTarget)), n.set(r.index, this.cameras.length), this.cameras.push(e);
2030
2042
  continue;
2031
2043
  }
2032
2044
  let e = this.cameras[r.index];
@@ -2034,26 +2046,26 @@ var Fa = class extends ur {
2034
2046
  t.push(r.name);
2035
2047
  continue;
2036
2048
  }
2037
- n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = ye(r.effects));
2049
+ n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = le(r.effects));
2038
2050
  }
2039
2051
  this._userCameraCounter = this.cameras.filter((e) => e.userData?.__rayzeeUserCamera).length, this.currentCameraIndex = n.get(e.current) ?? 0;
2040
2052
  let r = e.defaultView;
2041
2053
  this._defaultCameraState = r ? {
2042
- position: new Z().fromArray(r.position),
2043
- quaternion: new Dr().fromArray(r.quaternion),
2044
- scale: new Z().fromArray(r.scale),
2054
+ position: new Q().fromArray(r.position),
2055
+ quaternion: new Or().fromArray(r.quaternion),
2056
+ scale: new Q().fromArray(r.scale),
2045
2057
  fov: r.fov,
2046
2058
  near: r.near,
2047
2059
  far: r.far,
2048
- target: r.target ? new Z().fromArray(r.target) : null
2060
+ target: r.target ? new Q().fromArray(r.target) : null
2049
2061
  } : null, e.navigationMode && this.setNavigationMode(e.navigationMode);
2050
2062
  let i = e.view;
2051
2063
  if (i) {
2052
2064
  let e = this.camera;
2053
- e.position.fromArray(i.position), e.quaternion.fromArray(i.quaternion), e.scale.fromArray(i.scale), e.fov = i.fov, e.near = i.near, e.far = i.far, this._setView(i.orthographic, i.orthoHalfHeight), e.zoom = i.zoom ?? 1, e.updateProjectionMatrix(), e.updateMatrixWorld(!0), this.controls.target.fromArray(i.target), this.controls.update();
2065
+ e.position.fromArray(i.position), e.quaternion.fromArray(i.quaternion), e.scale.fromArray(i.scale), e.fov = i.fov, e.near = i.near, e.far = i.far, e.userData.clipStart = i.clipStart ?? 0, this._setView(i.orthographic, i.orthoHalfHeight), e.zoom = i.zoom ?? 1, e.updateProjectionMatrix(), e.updateMatrixWorld(!0), this.controls.target.fromArray(i.target), this.controls.update();
2054
2066
  }
2055
2067
  return e.autoFocus && (this.setAutoFocusMode(e.autoFocus.mode), this.setAFScreenPoint(e.autoFocus.point.x, e.autoFocus.point.y)), this.resetAutoFocus(), this._reportOrthoHeight(), this.dispatchEvent({
2056
- type: M.CAMERA_SWITCHED,
2068
+ type: P.CAMERA_SWITCHED,
2057
2069
  cameraIndex: this.currentCameraIndex,
2058
2070
  effects: this._captureEffects(),
2059
2071
  fov: this.camera.fov,
@@ -2097,36 +2109,36 @@ var Fa = class extends ur {
2097
2109
  let c = i;
2098
2110
  if (c?.isReady && c.renderMode?.value === 1 && c.frameCount > 0 && !c.isComplete) return;
2099
2111
  let l = this._pickFocusPoint(c.resetCount), u;
2100
- if (l) u = Na(l, this.camera), this._lastValidFocusDistance = u;
2112
+ if (l) u = Ra(l, this.camera), this._lastValidFocusDistance = u;
2101
2113
  else if (this._lastValidFocusDistance !== null) u = this._lastValidFocusDistance;
2102
2114
  else {
2103
- let e = this.controls ? Na(this.controls.target, this.camera) : 0;
2104
- u = e > 0 ? e : eo * (n?.getSceneScale() || 1), this._lastValidFocusDistance = u;
2115
+ let e = this.controls ? Ra(this.controls.target, this.camera) : 0;
2116
+ u = e > 0 ? e : ao * (n?.getSceneScale() || 1), this._lastValidFocusDistance = u;
2105
2117
  }
2106
2118
  let d = this._afPointDirty;
2107
- this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance > to ? this._smoothedFocusDistance = u : this._smoothedFocusDistance += this.afSmoothingFactor * (u - this._smoothedFocusDistance);
2119
+ this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance > oo ? this._smoothedFocusDistance = u : this._smoothedFocusDistance += this.afSmoothingFactor * (u - this._smoothedFocusDistance);
2108
2120
  let f = r, p = this._smoothedFocusDistance;
2109
2121
  if (d || f === 0 || Math.abs(p - f) / Math.max(f, .001) > .001) {
2110
2122
  a(p);
2111
2123
  let e = n?.getSceneScale() || 1;
2112
2124
  this.dispatchEvent({
2113
- type: M.AUTO_FOCUS_UPDATED,
2125
+ type: P.AUTO_FOCUS_UPDATED,
2114
2126
  distance: p / e,
2115
2127
  worldDistance: p
2116
2128
  });
2117
2129
  let t = Math.abs(p - f) / Math.max(f, .001);
2118
- d ? s?.() : t > $a && o?.();
2130
+ d ? s?.() : t > io && o?.();
2119
2131
  }
2120
2132
  }
2121
2133
  _pickFocusPoint(e) {
2122
2134
  let t = this.camera, { x: n, y: r } = this.afScreenPoint, i = this._afPick ??= {
2123
- point: new Z(),
2135
+ point: new Q(),
2124
2136
  hit: !1,
2125
2137
  resetCount: NaN,
2126
2138
  x: NaN,
2127
2139
  y: NaN,
2128
- view: new Y(),
2129
- projection: new Y()
2140
+ view: new yr(),
2141
+ projection: new yr()
2130
2142
  };
2131
2143
  if (this._afPointDirty || e !== i.resetCount || n !== i.x || r !== i.y || !i.view.equals(t.matrixWorld) || !i.projection.equals(t.projectionMatrix)) {
2132
2144
  let a = this.interactionManager.pickSurface(n * 2 - 1, 1 - r * 2);
@@ -2149,7 +2161,7 @@ var Fa = class extends ur {
2149
2161
  dispose() {
2150
2162
  this.walkControls?.dispose(), this.controls?.removeEventListener("change", this._reportOrthoHeight), this.controls?.dispose();
2151
2163
  }
2152
- }, ao = .001, oo = 2, so = (e, t, n, r) => new e(t, n, r, pr).createInterpolant(), co = class {
2164
+ }, uo = .001, fo = 2, po = (e, t, n, r) => new e(t, n, r, pr).createInterpolant(), mo = class {
2153
2165
  constructor(e, t) {
2154
2166
  this._cameraManager = e, this._onChange = t, this.keys = [], this._nextId = 1, this._interpolants = null;
2155
2167
  }
@@ -2159,7 +2171,7 @@ var Fa = class extends ur {
2159
2171
  get duration() {
2160
2172
  return this.keys.length ? this.keys[this.keys.length - 1].time : 0;
2161
2173
  }
2162
- addKey(e = this.keys.length ? this.duration + oo : 0) {
2174
+ addKey(e = this.keys.length ? this.duration + fo : 0) {
2163
2175
  return this.add(this._cameraManager.captureView(), e);
2164
2176
  }
2165
2177
  updateKey(e) {
@@ -2173,13 +2185,13 @@ var Fa = class extends ur {
2173
2185
  let n = {
2174
2186
  id: this._nextId++,
2175
2187
  time: t,
2176
- ...lo(e)
2188
+ ...ho(e)
2177
2189
  };
2178
2190
  return this.keys.push(n), this._changed(), n;
2179
2191
  }
2180
2192
  update(e, t) {
2181
2193
  let n = this.get(e);
2182
- n && (Object.assign(n, lo(t)), this._changed());
2194
+ n && (Object.assign(n, ho(t)), this._changed());
2183
2195
  }
2184
2196
  setTime(e, t) {
2185
2197
  let n = this.get(e);
@@ -2205,8 +2217,8 @@ var Fa = class extends ur {
2205
2217
  this.keys = (e ?? []).map((e) => ({
2206
2218
  id: this._nextId++,
2207
2219
  time: e.time,
2208
- position: new Z().fromArray(e.position),
2209
- target: new Z().fromArray(e.target),
2220
+ position: new Q().fromArray(e.position),
2221
+ target: new Q().fromArray(e.target),
2210
2222
  fov: e.fov,
2211
2223
  orthoHeight: e.orthoHeight
2212
2224
  })), this._changed();
@@ -2218,8 +2230,8 @@ var Fa = class extends ur {
2218
2230
  return this.keys.find((t) => t.id === e);
2219
2231
  }
2220
2232
  sample(e, t = {
2221
- position: new Z(),
2222
- target: new Z(),
2233
+ position: new Q(),
2234
+ target: new Q(),
2223
2235
  fov: 0,
2224
2236
  orthoHeight: 0
2225
2237
  }) {
@@ -2229,7 +2241,7 @@ var Fa = class extends ur {
2229
2241
  }
2230
2242
  _build() {
2231
2243
  let e = [];
2232
- for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] + ao) : t.time);
2244
+ for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] + uo) : t.time);
2233
2245
  let t = e[0], n = e[e.length - 1], r = this.keys;
2234
2246
  if (r.length > 1) {
2235
2247
  let i = r.length;
@@ -2243,17 +2255,17 @@ var Fa = class extends ur {
2243
2255
  return {
2244
2256
  start: t,
2245
2257
  end: n,
2246
- position: so(zr, ".position", e, i((e) => e.position)),
2247
- target: so(zr, ".target", e, i((e) => e.target)),
2248
- fov: so(Sr, ".fov", e, r.map((e) => e.fov)),
2249
- logHeight: so(Sr, ".orthoHeight", e, r.map((e) => Math.log(e.orthoHeight)))
2258
+ position: po(Br, ".position", e, i((e) => e.position)),
2259
+ target: po(Br, ".target", e, i((e) => e.target)),
2260
+ fov: po(Cr, ".fov", e, r.map((e) => e.fov)),
2261
+ logHeight: po(Cr, ".orthoHeight", e, r.map((e) => Math.log(e.orthoHeight)))
2250
2262
  };
2251
2263
  }
2252
2264
  _changed() {
2253
2265
  this.keys.sort((e, t) => e.time - t.time), this._interpolants = null, this._onChange?.();
2254
2266
  }
2255
2267
  };
2256
- function lo({ position: e, target: t, fov: n, orthoHeight: r }) {
2268
+ function ho({ position: e, target: t, fov: n, orthoHeight: r }) {
2257
2269
  return {
2258
2270
  position: e.clone(),
2259
2271
  target: t.clone(),
@@ -2263,9 +2275,9 @@ function lo({ position: e, target: t, fov: n, orthoHeight: r }) {
2263
2275
  }
2264
2276
  //#endregion
2265
2277
  //#region src/managers/timeline/TimelineManager.js
2266
- var uo = class extends ur {
2278
+ var go = class extends ur {
2267
2279
  constructor({ cameraManager: e, onReset: t }) {
2268
- super(), this._cameraManager = e, this._onReset = t, this.camera = new co(e, () => this._changed("camera")), this._playback = null, this._timer = new Pr(), typeof document < "u" && this._timer.connect(document);
2280
+ super(), this._cameraManager = e, this._onReset = t, this.camera = new mo(e, () => this._changed("camera")), this._playback = null, this._timer = new Fr(), typeof document < "u" && this._timer.connect(document);
2269
2281
  }
2270
2282
  get duration() {
2271
2283
  return this.camera.duration;
@@ -2314,18 +2326,18 @@ var uo = class extends ur {
2314
2326
  }
2315
2327
  _changed(e) {
2316
2328
  this.dispatchEvent({
2317
- type: M.TIMELINE_CHANGED,
2329
+ type: P.TIMELINE_CHANGED,
2318
2330
  track: e
2319
2331
  });
2320
2332
  }
2321
- }, fo = class {
2333
+ }, _o = class {
2322
2334
  constructor(e, t = {}) {
2323
2335
  this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._size = 256;
2324
2336
  }
2325
2337
  async loadLibrary(e, { size: t = 256 } = {}) {
2326
2338
  if (!Array.isArray(e) || e.length === 0) return [];
2327
2339
  this._size = t;
2328
- let n = await Promise.all(e.map((e) => po(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
2340
+ let n = await Promise.all(e.map((e) => vo(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
2329
2341
  s.width = r, s.height = i;
2330
2342
  let c = s.getContext("2d", { willReadFrequently: !0 }), l = performance.now();
2331
2343
  for (let e = 0; e < a; e++) {
@@ -2334,7 +2346,7 @@ var uo = class extends ur {
2334
2346
  o.set(t.data, e * r * i * 4), performance.now() - l > 16 && (await new Promise((e) => setTimeout(e, 0)), l = performance.now());
2335
2347
  }
2336
2348
  let u = new cr(o, r, i, a);
2337
- u.minFilter = mr, u.magFilter = mr, u.format = Or, u.type = Fr, u.generateMipmaps = !1, u.needsUpdate = !0;
2349
+ u.minFilter = mr, u.magFilter = mr, u.format = kr, u.type = Ir, u.generateMipmaps = !1, u.needsUpdate = !0;
2338
2350
  let d = this.texture;
2339
2351
  return this.texture = u, this.entries = e.map((e, t) => ({
2340
2352
  name: e.name,
@@ -2357,7 +2369,7 @@ var uo = class extends ur {
2357
2369
  o.userData.gobo = {
2358
2370
  name: e.name,
2359
2371
  index: e.index,
2360
- intensity: mo(r),
2372
+ intensity: yo(r),
2361
2373
  inverted: !!i,
2362
2374
  scale: Math.max(1e-4, a)
2363
2375
  };
@@ -2399,7 +2411,7 @@ var uo = class extends ur {
2399
2411
  return t && t.isSpotLight ? t : null;
2400
2412
  }
2401
2413
  };
2402
- async function po(e) {
2414
+ async function vo(e) {
2403
2415
  let t = await _(e);
2404
2416
  try {
2405
2417
  return await new Promise((n, r) => {
@@ -2410,22 +2422,22 @@ async function po(e) {
2410
2422
  t.release();
2411
2423
  }
2412
2424
  }
2413
- function mo(e) {
2425
+ function yo(e) {
2414
2426
  return Math.max(0, Math.min(1, e));
2415
2427
  }
2416
2428
  //#endregion
2417
2429
  //#region src/Processor/IESParser.js
2418
- function ho(e, t = "ies") {
2430
+ function bo(e, t = "ies") {
2419
2431
  let n = e.search(/TILT\s*=/i);
2420
2432
  if (n < 0) throw Error(`IES (${t}): missing TILT line`);
2421
2433
  let r = e.indexOf("\n", n);
2422
2434
  if (r < 0) throw Error(`IES (${t}): truncated TILT line`);
2423
2435
  let i = e.slice(n, r).match(/TILT\s*=\s*(\w+)/i), a = i ? i[1].toUpperCase() : "NONE", o = e.slice(r);
2424
2436
  if (a === "INCLUDE") {
2425
- let e = bo(o), t = 2 + 2 * Number(e[1]);
2426
- o = xo(o, t);
2437
+ let e = To(o), t = 2 + 2 * Number(e[1]);
2438
+ o = Eo(o, t);
2427
2439
  }
2428
- let s = bo(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
2440
+ let s = To(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
2429
2441
  l(), l(), l(), l();
2430
2442
  let g = l();
2431
2443
  if (l(), l(), !Number.isFinite(p) || p <= 0) throw Error(`IES (${t}): invalid vertical angle count ${p}`);
@@ -2451,34 +2463,34 @@ function ho(e, t = "ies") {
2451
2463
  name: t
2452
2464
  };
2453
2465
  }
2454
- function go(e, t, n) {
2466
+ function xo(e, t, n) {
2455
2467
  if (t === 0 && n === 90) {
2456
2468
  let t = e % 180;
2457
2469
  return t > 90 ? 180 - t : t;
2458
2470
  }
2459
2471
  return t === 0 && n === 180 ? e > 180 ? 360 - e : e : t === 90 && n === 270 ? e >= 90 && e <= 270 ? e : (540 - e) % 360 : e;
2460
2472
  }
2461
- function _o(e, t, n) {
2473
+ function So(e, t, n) {
2462
2474
  let r = new Uint8Array(t * n), { verticalAngles: i, horizontalAngles: a, candela: o, maxCandela: s, photometricType: c } = e;
2463
2475
  if (s <= 0) return r;
2464
2476
  let l = c === void 0 || c === 1, u = i[0], d = i[i.length - 1], f = a[0], p = a[a.length - 1], m = a.length === 1 || p === f, h = (e, t, n, r) => {
2465
- if (m) return Co(o[e][0], o[t][0], n);
2477
+ if (m) return Oo(o[e][0], o[t][0], n);
2466
2478
  if (r < f || r > p) return 0;
2467
- let i = So(a, r), s = Math.min(i + 1, a.length - 1), c = a[s] - a[i], l = c > 0 ? (r - a[i]) / c : 0;
2468
- return Co(Co(o[e][i], o[e][s], l), Co(o[t][i], o[t][s], l), n);
2479
+ let i = Do(a, r), s = Math.min(i + 1, a.length - 1), c = a[s] - a[i], l = c > 0 ? (r - a[i]) / c : 0;
2480
+ return Oo(Oo(o[e][i], o[e][s], l), Oo(o[t][i], o[t][s], l), n);
2469
2481
  };
2470
2482
  for (let e = 0; e < n; e++) {
2471
2483
  let a = (e + .5) / n, o = l ? a * 180 : u + a * (d - u);
2472
2484
  if (o < u || o > d) continue;
2473
- let c = So(i, o), m = Math.min(c + 1, i.length - 1), g = i[m] - i[c], _ = g > 0 ? (o - i[c]) / g : 0;
2485
+ let c = Do(i, o), m = Math.min(c + 1, i.length - 1), g = i[m] - i[c], _ = g > 0 ? (o - i[c]) / g : 0;
2474
2486
  for (let n = 0; n < t; n++) {
2475
- let i = (n + .5) / t, a = l ? go(i * 360, f, p) : f + i * (p - f), o = Math.min(1, Math.max(0, h(c, m, _, a) / s));
2487
+ let i = (n + .5) / t, a = l ? xo(i * 360, f, p) : f + i * (p - f), o = Math.min(1, Math.max(0, h(c, m, _, a) / s));
2476
2488
  r[e * t + n] = Math.round(o * 255);
2477
2489
  }
2478
2490
  }
2479
2491
  return r;
2480
2492
  }
2481
- function vo(e, t = .1) {
2493
+ function Co(e, t = .1) {
2482
2494
  let { verticalAngles: n, horizontalAngles: r, candela: i, maxCandela: a } = e, o = Math.PI / 4;
2483
2495
  if (a <= 0 || !n?.length) return o;
2484
2496
  let s = a * t, c = r.length, l = n[n.length - 1], u = !1;
@@ -2493,7 +2505,7 @@ function vo(e, t = .1) {
2493
2505
  let d = l * Math.PI / 180;
2494
2506
  return Math.min(Math.max(d, 5 * Math.PI / 180), 89 * Math.PI / 180);
2495
2507
  }
2496
- function yo(e, t, n = .7) {
2508
+ function wo(e, t, n = .7) {
2497
2509
  let { verticalAngles: r, horizontalAngles: i, candela: a, maxCandela: o } = e;
2498
2510
  if (o <= 0 || !r?.length || t <= 0) return 0;
2499
2511
  let s = o * n, c = i.length, l = 0;
@@ -2506,15 +2518,15 @@ function yo(e, t, n = .7) {
2506
2518
  let u = t * 180 / Math.PI, d = u > 0 ? 1 - l / u : 0;
2507
2519
  return Math.min(Math.max(d, 0), 1);
2508
2520
  }
2509
- function bo(e) {
2521
+ function To(e) {
2510
2522
  return e.split(/\s+/).filter((e) => e.length > 0);
2511
2523
  }
2512
- function xo(e, t) {
2524
+ function Eo(e, t) {
2513
2525
  let n = /\S+/g, r = 0;
2514
2526
  for (; n.exec(e) !== null;) if (r++, r === t) return e.slice(n.lastIndex);
2515
2527
  return "";
2516
2528
  }
2517
- function So(e, t) {
2529
+ function Do(e, t) {
2518
2530
  if (t <= e[0]) return 0;
2519
2531
  if (t >= e[e.length - 1]) return e.length - 1;
2520
2532
  let n = 0, r = e.length - 1;
@@ -2524,12 +2536,12 @@ function So(e, t) {
2524
2536
  }
2525
2537
  return n;
2526
2538
  }
2527
- function Co(e, t, n) {
2539
+ function Oo(e, t, n) {
2528
2540
  return e + (t - e) * n;
2529
2541
  }
2530
2542
  //#endregion
2531
2543
  //#region src/managers/IESManager.js
2532
- var wo = class {
2544
+ var ko = class {
2533
2545
  constructor(e, t = {}) {
2534
2546
  this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._gridWidth = 128, this._gridHeight = 128;
2535
2547
  }
@@ -2538,11 +2550,11 @@ var wo = class {
2538
2550
  this._gridWidth = t, this._gridHeight = n;
2539
2551
  let r = (await Promise.all(e.map(async (e) => {
2540
2552
  try {
2541
- let { file: r, release: i } = await p().fetch(e.url), a = ho(await r.text().finally(i), e.name);
2553
+ let { file: r, release: i } = await p().fetch(e.url), a = bo(await r.text().finally(i), e.name);
2542
2554
  return {
2543
2555
  it: e,
2544
2556
  profile: a,
2545
- grid: _o(a, t, n)
2557
+ grid: So(a, t, n)
2546
2558
  };
2547
2559
  } catch (t) {
2548
2560
  return this._issues?.warn(Ye.ASSET_UNREACHABLE, `IES profile "${e.name}" could not be loaded: ${t.message}`, {
@@ -2560,19 +2572,19 @@ var wo = class {
2560
2572
  let r = t[e];
2561
2573
  o[n + e * 4 + 0] = r, o[n + e * 4 + 1] = r, o[n + e * 4 + 2] = r, o[n + e * 4 + 3] = 255;
2562
2574
  }
2563
- let i = r[e].profile, c = vo(i);
2575
+ let i = r[e].profile, c = Co(i);
2564
2576
  s.push({
2565
2577
  name: r[e].it.name,
2566
2578
  index: e,
2567
2579
  maxCandela: i.maxCandela,
2568
2580
  photometricType: i.photometricType,
2569
2581
  suggestedAngle: c,
2570
- suggestedPenumbra: yo(i, c),
2582
+ suggestedPenumbra: wo(i, c),
2571
2583
  lumens: i.lumens
2572
2584
  });
2573
2585
  }
2574
2586
  let c = new cr(o, t, n, i);
2575
- c.format = Or, c.type = Fr, c.minFilter = mr, c.magFilter = mr, c.generateMipmaps = !1, c.needsUpdate = !0;
2587
+ c.format = kr, c.type = Ir, c.minFilter = mr, c.magFilter = mr, c.generateMipmaps = !1, c.needsUpdate = !0;
2576
2588
  let l = this.texture;
2577
2589
  return this.texture = c, this.entries = s, this.pathTracer.iesProfiles = c, this.pathTracer.shaderBuilder?.updateIESProfiles?.(c), l?.dispose?.(), this.entries.map(({ name: e, index: t }) => ({
2578
2590
  name: e,
@@ -2603,7 +2615,7 @@ var wo = class {
2603
2615
  l = Number.isFinite(e.lumens) ? e.lumens : null, i.userData.ies = {
2604
2616
  name: e.name,
2605
2617
  index: e.index,
2606
- intensity: To(n),
2618
+ intensity: Ao(n),
2607
2619
  fixtureLumens: l
2608
2620
  }, r && (Number.isFinite(e.suggestedAngle) && (i.angle = e.suggestedAngle, o = e.suggestedAngle), Number.isFinite(e.suggestedPenumbra) && (i.penumbra = e.suggestedPenumbra, s = e.suggestedPenumbra), i.decay = 2, c = 2);
2609
2621
  }
@@ -2626,24 +2638,24 @@ var wo = class {
2626
2638
  return t && t.isSpotLight ? t : null;
2627
2639
  }
2628
2640
  };
2629
- function To(e) {
2641
+ function Ao(e) {
2630
2642
  return Math.max(0, Math.min(1, e));
2631
2643
  }
2632
2644
  //#endregion
2633
2645
  //#region src/Passes/OIDNDenoiser.js
2634
- var Eo = We("oidn"), Do = 16, Oo = 16;
2635
- function ko(e, t) {
2636
- let n = (e) => Math.ceil((e + 2 * Oo) / Do) * Do;
2646
+ var jo = We("oidn"), Mo = 16, No = 16;
2647
+ function Po(e, t) {
2648
+ let n = (e) => Math.ceil((e + 2 * No) / Mo) * Mo;
2637
2649
  return {
2638
2650
  width: n(e),
2639
2651
  height: n(t)
2640
2652
  };
2641
2653
  }
2642
- var Ao = null;
2643
- async function jo() {
2644
- return Ao ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Ao;
2654
+ var Fo = null;
2655
+ async function Io() {
2656
+ return Fo ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Fo;
2645
2657
  }
2646
- var Mo = {
2658
+ var Lo = {
2647
2659
  QUALITY_MODELS: {
2648
2660
  fast: {
2649
2661
  model: "rt_hdr_alb_nrm_small",
@@ -2667,9 +2679,9 @@ var Mo = {
2667
2679
  oidnQuality: "fast",
2668
2680
  tileSize: 1024
2669
2681
  }
2670
- }, No = .18, Po = 256, Fo = 256, Io = `
2671
- const WG: u32 = ${Po}u;
2672
- const GROUPS: u32 = ${Fo}u;
2682
+ }, Ro = .18, zo = 256, Bo = 256, Vo = `
2683
+ const WG: u32 = ${zo}u;
2684
+ const GROUPS: u32 = ${Bo}u;
2673
2685
 
2674
2686
  @group(0) @binding(0) var<storage, read> col: array<vec4<f32>>;
2675
2687
  @group(0) @binding(1) var<storage, read_write> partials: array<f32>;
@@ -2688,7 +2700,7 @@ fn treeSum( lid: u32 ) {
2688
2700
  }
2689
2701
  }
2690
2702
 
2691
- @compute @workgroup_size(${Po})
2703
+ @compute @workgroup_size(${zo})
2692
2704
  fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
2693
2705
  @builtin(local_invocation_id) lid: vec3<u32>,
2694
2706
  @builtin(workgroup_id) wid: vec3<u32> ) {
@@ -2712,7 +2724,7 @@ fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
2712
2724
  if ( lid.x == 0u ) { partials[ wid.x ] = sdata[ 0 ]; }
2713
2725
  }
2714
2726
 
2715
- @compute @workgroup_size(${Po})
2727
+ @compute @workgroup_size(${zo})
2716
2728
  fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
2717
2729
 
2718
2730
  var v = 0.0;
@@ -2722,12 +2734,12 @@ fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
2722
2734
  treeSum( lid.x );
2723
2735
 
2724
2736
  if ( lid.x == 0u ) {
2725
- let scale = ${No} / exp2( sdata[ 0 ] / f32( params.x ) );
2737
+ let scale = ${Ro} / exp2( sdata[ 0 ] / f32( params.x ) );
2726
2738
  // Mirrors the CPU guard: a non-finite or non-positive scale means no scaling at all.
2727
2739
  scaleOut[ 0 ] = select( 1.0, scale, scale > 0.0 && scale < 3.4e38 );
2728
2740
  }
2729
2741
  }
2730
- `, Lo = "\n@group(0) @binding(0) var<storage, read_write> col: array<vec4<f32>>;\n@group(0) @binding(1) var<storage, read> scaleBuf: array<f32>;\n\n@compute @workgroup_size(64)\nfn main( @builtin(global_invocation_id) gid: vec3<u32>,\n @builtin(num_workgroups) nwg: vec3<u32> ) {\n let i = gid.y * nwg.x * 64u + gid.x;\n if ( i >= arrayLength( &col ) ) { return; }\n let c = col[ i ];\n col[ i ] = vec4<f32>( c.xyz * scaleBuf[ 0 ], c.w );\n}\n", Ro = 64, zo = 32768, Bo = 16, Vo = 32, Ho = `
2742
+ `, Ho = "\n@group(0) @binding(0) var<storage, read_write> col: array<vec4<f32>>;\n@group(0) @binding(1) var<storage, read> scaleBuf: array<f32>;\n\n@compute @workgroup_size(64)\nfn main( @builtin(global_invocation_id) gid: vec3<u32>,\n @builtin(num_workgroups) nwg: vec3<u32> ) {\n let i = gid.y * nwg.x * 64u + gid.x;\n if ( i >= arrayLength( &col ) ) { return; }\n let c = col[ i ];\n col[ i ] = vec4<f32>( c.xyz * scaleBuf[ 0 ], c.w );\n}\n", Uo = 64, Wo = 32768, Go = 16, Ko = 32, qo = `
2731
2743
  struct UnpackParams {
2732
2744
  srcWidth: u32,
2733
2745
  tileX: u32,
@@ -2745,7 +2757,7 @@ struct UnpackParams {
2745
2757
  @group(0) @binding(3) var<storage, read> inColor: array<vec4<f32>>;
2746
2758
  @group(0) @binding(4) var dst: texture_storage_2d<rgba16float, write>;
2747
2759
 
2748
- @compute @workgroup_size(${Bo}, ${Bo})
2760
+ @compute @workgroup_size(${Go}, ${Go})
2749
2761
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2750
2762
 
2751
2763
  if ( gid.x >= P.tileW || gid.y >= P.tileH ) { return; }
@@ -2759,7 +2771,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2759
2771
  // survives the denoise.
2760
2772
  textureStore( dst, vec2<u32>( px, py ), vec4<f32>( src[ si ].xyz / scaleBuf[ 0 ], inColor[ si ].w ) );
2761
2773
  }
2762
- `, Uo = 8, Wo = `
2774
+ `, Jo = 8, Yo = `
2763
2775
  @group(0) @binding(0) var src: texture_2d<f32>;
2764
2776
  @group(0) @binding(1) var<storage, read_write> dst: array<vec4<f32>>;
2765
2777
  @group(0) @binding(2) var<uniform> size: vec4<u32>; // buffer w, h; frame w, h
@@ -2769,15 +2781,15 @@ fn mirror( i: i32, n: i32 ) -> i32 {
2769
2781
  return clamp( select( m, 2 * n - 2 - m, m >= n ), 0, n - 1 );
2770
2782
  }
2771
2783
 
2772
- @compute @workgroup_size(${Uo}, ${Uo})
2784
+ @compute @workgroup_size(${Jo}, ${Jo})
2773
2785
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2774
2786
 
2775
2787
  if ( gid.x >= size.x || gid.y >= size.y ) { return; }
2776
- let p = vec2<i32>( gid.xy ) - ${Oo};
2788
+ let p = vec2<i32>( gid.xy ) - ${No};
2777
2789
  let s = vec2<i32>( mirror( p.x, i32( size.z ) ), mirror( p.y, i32( size.w ) ) );
2778
2790
  dst[ gid.y * size.x + gid.x ] = textureLoad( src, s, 0 );
2779
2791
  }
2780
- `, Go = class extends ur {
2792
+ `, Xo = class extends ur {
2781
2793
  constructor(e, t = {}) {
2782
2794
  if (super(), !e) throw Error("OIDNDenoiser requires a renderer");
2783
2795
  this.renderer = e, this._renderWidth = e.domElement.width, this._renderHeight = e.domElement.height, this.backendParamsGetter = t.backendParams || null, this.getGPUTextures = t.getGPUTextures || null, this.gpuDevice = null, this._gpuInputBuffers = {
@@ -2791,14 +2803,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2791
2803
  width: 0,
2792
2804
  height: 0
2793
2805
  }, this.config = {
2794
- ...Mo.DEFAULT_OPTIONS,
2806
+ ...Lo.DEFAULT_OPTIONS,
2795
2807
  ...t
2796
2808
  }, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
2797
2809
  isDenoising: !1,
2798
2810
  isLoading: !1,
2799
2811
  abortController: null
2800
2812
  }, this._tilesWritten = 0, this._runId = 0, this._hasOutput = !1, this.lastDenoiseMs = 0, this.currentTZAUrl = null, this.unet = null, this._weights = /* @__PURE__ */ new Map(), this._pendingStart = !1, this._pendingStartContinuous = !1, this._reloadPending = !1, this._initialize().catch((e) => {
2801
- Eo.error("init failed:", e), this.dispatchEvent({
2813
+ jo.error("init failed:", e), this.dispatchEvent({
2802
2814
  type: "error",
2803
2815
  error: e
2804
2816
  });
@@ -2812,7 +2824,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2812
2824
  }
2813
2825
  }
2814
2826
  expectsCleanAux(e = this.quality) {
2815
- let { QUALITY_MODELS: t } = Mo;
2827
+ let { QUALITY_MODELS: t } = Lo;
2816
2828
  return (t[e] || t.balance).cleanAux;
2817
2829
  }
2818
2830
  getRuntimeInfo() {
@@ -2826,8 +2838,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2826
2838
  }
2827
2839
  _resolveTileSize() {
2828
2840
  if (!this._renderWidth || !this._renderHeight) return this.maxTileSize;
2829
- let e = ko(this._renderWidth, this._renderHeight), t = ko(this.maxTileSize, this.maxTileSize);
2830
- return e.width * e.height <= t.width * t.height ? Math.max(e.width, e.height) : Math.max(Do, Math.floor(this.maxTileSize / Do) * Do);
2841
+ let e = Po(this._renderWidth, this._renderHeight), t = Po(this.maxTileSize, this.maxTileSize);
2842
+ return e.width * e.height <= t.width * t.height ? Math.max(e.width, e.height) : Math.max(Mo, Math.floor(this.maxTileSize / Mo) * Mo);
2831
2843
  }
2832
2844
  _setupUNetDenoiser() {
2833
2845
  return this.state.isLoading ? (this._reloadPending = !0, Promise.resolve()) : (this._loading = this._loadUNet(), this._loading);
@@ -2841,7 +2853,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2841
2853
  try {
2842
2854
  await this._loadUNetWeights();
2843
2855
  } catch (e) {
2844
- Eo.error("UNet weights failed to load:", e), this.dispatchEvent({
2856
+ jo.error("UNet weights failed to load:", e), this.dispatchEvent({
2845
2857
  type: "error",
2846
2858
  error: /* @__PURE__ */ Error(`Denoiser loading failed: ${e.message}`),
2847
2859
  url: this._generateTzaUrl()
@@ -2850,7 +2862,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2850
2862
  this.state.isLoading = !1;
2851
2863
  }
2852
2864
  } while (this._reloadPending);
2853
- if (this._pendingStart && this.unet && this.enabled) {
2865
+ if (this._pendingStart && this.enabled) {
2854
2866
  let e = this._pendingStartContinuous;
2855
2867
  this._pendingStart = !1, this._pendingStartContinuous = !1, this.start({ continuous: e });
2856
2868
  }
@@ -2867,26 +2879,26 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2867
2879
  let e = this.backendParamsGetter();
2868
2880
  this.gpuDevice = e?.device ?? null, n = e?.device ? { device: e.device } : void 0;
2869
2881
  }
2870
- this.unet = await (await jo())(await this._fetchWeights(e), n, {
2882
+ this.unet = await (await Io())(await this._fetchWeights(e), n, {
2871
2883
  aux: !0,
2872
2884
  hdr: !0,
2873
2885
  maxTileSize: t,
2874
2886
  dynamicTile: !1
2875
- }), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), Eo.debug("UNet weights loaded:", e);
2887
+ }), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), jo.debug("UNet weights loaded:", e);
2876
2888
  }
2877
2889
  _fetchWeights(e) {
2878
2890
  let t = this._weights.get(e);
2879
2891
  return t || (t = p().fetch(e, { policy: C.IMMUTABLE }).then(({ file: e, release: t }) => e.arrayBuffer().finally(t)), t.catch(() => this._weights.delete(e)), this._weights.set(e, t)), t;
2880
2892
  }
2881
2893
  _generateTzaUrl() {
2882
- let { oidnWeightsBaseUrl: e } = it(), { QUALITY_MODELS: t } = Mo;
2894
+ let { oidnWeightsBaseUrl: e } = it(), { QUALITY_MODELS: t } = Lo;
2883
2895
  return `${e}${(t[this.quality] || t.balance).model}.tza`;
2884
2896
  }
2885
2897
  async updateConfiguration(e) {
2886
2898
  Object.keys(e).some((t) => this.config[t] !== e[t]) && (Object.assign(this.config, e), this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, await this._setupUNetDenoiser());
2887
2899
  }
2888
2900
  async updateQuality(e) {
2889
- if (!Object.prototype.hasOwnProperty.call(Mo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Mo.QUALITY_MODELS).join(", ")}`);
2901
+ if (!Object.prototype.hasOwnProperty.call(Lo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Lo.QUALITY_MODELS).join(", ")}`);
2890
2902
  await this.updateConfiguration({ oidnQuality: e });
2891
2903
  }
2892
2904
  async start({ continuous: e = !1 } = {}) {
@@ -2897,16 +2909,15 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2897
2909
  continuous: e
2898
2910
  });
2899
2911
  let t = performance.now(), n = await this.execute(e);
2900
- return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t, Eo.debug(`denoise complete in ${He.ms(this.lastDenoiseMs)} · quality ${this.quality}`)), n;
2912
+ return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t, jo.debug(`denoise complete in ${He.ms(this.lastDenoiseMs)} · quality ${this.quality}`)), n;
2901
2913
  }
2902
2914
  async execute(e = !1) {
2903
- if (!this.enabled || !this.unet) return !1;
2904
2915
  let t = ++this._runId;
2905
2916
  this.state.abortController = new AbortController(), this.state.isDenoising = !0;
2906
2917
  try {
2907
- return await this._executeUNetGPU(e) !== !1;
2918
+ return !this.enabled || !this.unet ? !1 : await this._executeUNetGPU(e) !== !1;
2908
2919
  } catch (e) {
2909
- return e.name === "AbortError" ? Eo.debug("denoise aborted") : Eo.error("denoise error:", e), !1;
2920
+ return e.name === "AbortError" ? jo.debug("denoise aborted") : jo.error("denoise error:", e), !1;
2910
2921
  } finally {
2911
2922
  this._runId === t && (this.state.isDenoising = !1, this.state.abortController = null), this.dispatchEvent({
2912
2923
  type: "end",
@@ -2916,13 +2927,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2916
2927
  }
2917
2928
  async _executeUNetGPU(e = !1) {
2918
2929
  let t = this._renderWidth, n = this._renderHeight;
2919
- if (!this.getGPUTextures) return Eo.warn("GPU mode enabled but getGPUTextures not provided"), !1;
2930
+ if (!this.getGPUTextures) return jo.warn("GPU mode enabled but getGPUTextures not provided"), !1;
2920
2931
  let r = this.getGPUTextures({ continuous: e });
2921
- if (!r?.color) return Eo.warn("GPU textures not ready yet"), !1;
2932
+ if (!r?.color) return jo.warn("GPU textures not ready yet"), !1;
2922
2933
  let i = this.gpuDevice;
2923
- if (!i) return Eo.warn("gpuDevice not available"), !1;
2934
+ if (!i) return jo.warn("gpuDevice not available"), !1;
2924
2935
  this._ensureGPUInputBuffers(t, n), this._copyInputs(i, r, t, n);
2925
- let a = ko(t, n);
2936
+ let a = Po(t, n);
2926
2937
  this._computeInputScale(i, t, n), this._applyColorScale(i, a.width * a.height), !e && !this._hasOutput && this._unpackToTexture(this._gpuInputBuffers.color, {
2927
2938
  x: 0,
2928
2939
  y: 0,
@@ -2941,7 +2952,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2941
2952
  return this._executeWithAbortGPU(s, e);
2942
2953
  }
2943
2954
  _copyInputs(e, t, n, r) {
2944
- let i = ko(n, r), a = e.createCommandEncoder({ label: "oidn-tex-to-buf" }), o = this._beginPack(e, a, i, n, r);
2955
+ let i = Po(n, r), a = e.createCommandEncoder({ label: "oidn-tex-to-buf" }), o = this._beginPack(e, a, i, n, r);
2945
2956
  for (let n of [
2946
2957
  "color",
2947
2958
  "albedo",
@@ -2962,14 +2973,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2962
2973
  resource: { buffer: this._packParams }
2963
2974
  }
2964
2975
  ]
2965
- })), o.dispatchWorkgroups(Math.ceil(i.width / Uo), Math.ceil(i.height / Uo));
2976
+ })), o.dispatchWorkgroups(Math.ceil(i.width / Jo), Math.ceil(i.height / Jo));
2966
2977
  o.end(), e.queue.submit([a.finish()]);
2967
2978
  }
2968
2979
  _ensureGPUInputBuffers(e, t) {
2969
2980
  let { width: n, height: r } = this._gpuInputBufferSize;
2970
2981
  if (n === e && r === t && this._gpuInputBuffers.color) return;
2971
2982
  this._destroyGPUInputBuffers();
2972
- let i = this.gpuDevice, a = ko(e, t), o = a.width * a.height * 16, s = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
2983
+ let i = this.gpuDevice, a = Po(e, t), o = a.width * a.height * 16, s = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
2973
2984
  this._gpuInputBuffers.color = i.createBuffer({
2974
2985
  label: "oidn-in-color",
2975
2986
  size: o,
@@ -3013,7 +3024,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3013
3024
  compute: {
3014
3025
  module: e.createShaderModule({
3015
3026
  label: "oidn-pack",
3016
- code: Wo
3027
+ code: Yo
3017
3028
  }),
3018
3029
  entryPoint: "main"
3019
3030
  }
@@ -3071,7 +3082,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3071
3082
  });
3072
3083
  let t = e.createShaderModule({
3073
3084
  label: "oidn-autoexposure",
3074
- code: Io
3085
+ code: Vo
3075
3086
  }), n = e.createPipelineLayout({ bindGroupLayouts: [this._lumLayout] });
3076
3087
  this._lumReducePipeline = e.createComputePipeline({
3077
3088
  label: "oidn-autoexposure-reduce",
@@ -3095,7 +3106,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3095
3106
  compute: {
3096
3107
  module: e.createShaderModule({
3097
3108
  label: "oidn-color-scale",
3098
- code: Lo
3109
+ code: Ho
3099
3110
  }),
3100
3111
  entryPoint: "main"
3101
3112
  }
@@ -3105,7 +3116,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3105
3116
  compute: {
3106
3117
  module: e.createShaderModule({
3107
3118
  label: "oidn-output-unpack",
3108
- code: Ho
3119
+ code: qo
3109
3120
  }),
3110
3121
  entryPoint: "main"
3111
3122
  }
@@ -3115,7 +3126,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3115
3126
  size: 4
3116
3127
  }), this._lumPartials = e.createBuffer({
3117
3128
  label: "oidn-autoexposure-partials",
3118
- size: Fo * 4,
3129
+ size: Bo * 4,
3119
3130
  usage: GPUBufferUsage.STORAGE
3120
3131
  }), this._lumParams = e.createBuffer({
3121
3132
  label: "oidn-autoexposure-params",
@@ -3160,21 +3171,21 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3160
3171
  e.queue.writeBuffer(this._inputScaleBuffer, 0, new Float32Array([1]));
3161
3172
  return;
3162
3173
  }
3163
- let r = ko(t, n);
3174
+ let r = Po(t, n);
3164
3175
  e.queue.writeBuffer(this._lumParams, 0, new Uint32Array([
3165
3176
  t * n,
3166
3177
  t,
3167
3178
  r.width,
3168
- Oo
3179
+ No
3169
3180
  ]));
3170
3181
  let i = e.createCommandEncoder({ label: "oidn-autoexposure" }), a = i.beginComputePass({ label: "oidn-autoexposure-reduce" });
3171
- a.setPipeline(this._lumReducePipeline), a.setBindGroup(0, this._lumBindGroup), a.dispatchWorkgroups(Fo, 1, 1), a.end();
3182
+ a.setPipeline(this._lumReducePipeline), a.setBindGroup(0, this._lumBindGroup), a.dispatchWorkgroups(Bo, 1, 1), a.end();
3172
3183
  let o = i.beginComputePass({ label: "oidn-autoexposure-finalize" });
3173
3184
  o.setPipeline(this._lumFinalizePipeline), o.setBindGroup(0, this._lumBindGroup), o.dispatchWorkgroups(1, 1, 1), o.end(), e.queue.submit([i.finish()]);
3174
3185
  }
3175
3186
  _applyColorScale(e, t) {
3176
3187
  if (!this._ensureScalePipelines(e)) return;
3177
- let n = Math.ceil(t / Ro), r = Math.min(n, zo), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
3188
+ let n = Math.ceil(t / Uo), r = Math.min(n, Wo), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
3178
3189
  o.setPipeline(this._colorScalePipeline), o.setBindGroup(0, this._colorScaleBindGroup), o.dispatchWorkgroups(r, i, 1), o.end(), e.queue.submit([a.finish()]);
3179
3190
  }
3180
3191
  get outputTexture() {
@@ -3201,7 +3212,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3201
3212
  width: t,
3202
3213
  height: n,
3203
3214
  depth: 1
3204
- }, r.type = fr, r.format = Or, r.colorSpace = xr, r.minFilter = X, r.magFilter = X, r.wrapS = ir, r.wrapT = ir, r.generateMipmaps = !1, r.flipY = !1, this._outTexture = r, this._outTexSize = {
3215
+ }, r.type = fr, r.format = kr, r.colorSpace = Sr, r.minFilter = Z, r.magFilter = Z, r.wrapS = ir, r.wrapT = ir, r.generateMipmaps = !1, r.flipY = !1, this._outTexture = r, this._outTexSize = {
3205
3216
  width: t,
3206
3217
  height: n
3207
3218
  };
@@ -3219,18 +3230,18 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3219
3230
  if (this._ensureOutputTexture(r, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
3220
3231
  let c = r.createBuffer({
3221
3232
  label: "oidn-unpack-params",
3222
- size: Vo,
3233
+ size: Ko,
3223
3234
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3224
3235
  });
3225
3236
  try {
3226
- let t = ko(this._gpuInputBufferSize.width, this._gpuInputBufferSize.height).width;
3237
+ let t = Po(this._gpuInputBufferSize.width, this._gpuInputBufferSize.height).width;
3227
3238
  r.queue.writeBuffer(c, 0, new Uint32Array([
3228
3239
  t,
3229
3240
  i,
3230
3241
  a,
3231
3242
  o,
3232
3243
  s,
3233
- Oo,
3244
+ No,
3234
3245
  0,
3235
3246
  0
3236
3247
  ]));
@@ -3260,7 +3271,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3260
3271
  }
3261
3272
  ]
3262
3273
  }), u = r.createCommandEncoder({ label: "oidn-output-unpack" }), d = u.beginComputePass({ label: "oidn-output-unpack" });
3263
- d.setPipeline(this._unpackPipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / Bo), Math.ceil(s / Bo), 1), d.end(), r.queue.submit([u.finish()]), n && (this._hasOutput = !0);
3274
+ d.setPipeline(this._unpackPipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / Go), Math.ceil(s / Go), 1), d.end(), r.queue.submit([u.finish()]), n && (this._hasOutput = !0);
3264
3275
  } finally {
3265
3276
  c.destroy();
3266
3277
  }
@@ -3292,7 +3303,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3292
3303
  },
3293
3304
  progress: (e, n, r) => {
3294
3305
  if (!e?.data || !r) return;
3295
- let { width: i, height: a } = this._gpuInputBufferSize, o = Math.max(r.x - Oo, 0), s = Math.max(r.y - Oo, 0), c = Math.min(r.x + r.width - Oo, i) - o, l = Math.min(r.y + r.height - Oo, a) - s;
3306
+ let { width: i, height: a } = this._gpuInputBufferSize, o = Math.max(r.x - No, 0), s = Math.max(r.y - No, 0), c = Math.min(r.x + r.width - No, i) - o, l = Math.min(r.y + r.height - No, a) - s;
3296
3307
  if (c <= 0 || l <= 0) return;
3297
3308
  let u = {
3298
3309
  x: o,
@@ -3313,7 +3324,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3313
3324
  }
3314
3325
  _displayGPUOutput({ data: e }) {
3315
3326
  if (!this.gpuDevice) {
3316
- Eo.error("gpuDevice not available for the output picture");
3327
+ jo.error("gpuDevice not available for the output picture");
3317
3328
  return;
3318
3329
  }
3319
3330
  let { width: t, height: n } = this._gpuInputBufferSize;
@@ -3325,7 +3336,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3325
3336
  });
3326
3337
  }
3327
3338
  abort() {
3328
- this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1, Eo.debug("denoise aborted"));
3339
+ this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1, jo.debug("denoise aborted"));
3329
3340
  }
3330
3341
  get hasOutput() {
3331
3342
  return this._hasOutput;
@@ -3336,13 +3347,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3336
3347
  setSize(e, t) {
3337
3348
  if (e <= 0 || t <= 0) throw Error(`Invalid dimensions: ${e}x${t}`);
3338
3349
  this._renderWidth = e, this._renderHeight = t, this._hasOutput = !1, this.lastDenoiseMs = 0, this._setupUNetDenoiser().catch((e) => {
3339
- Eo.error("reinitialize after size change failed:", e);
3350
+ jo.error("reinitialize after size change failed:", e);
3340
3351
  });
3341
3352
  }
3342
3353
  dispose() {
3343
- this.abort(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._releaseOutputTexture(), this._colorScalePipeline = null, this._lumReducePipeline = null, this._lumFinalizePipeline = null, this._lumLayout = null, this._unpackPipeline = null, this.unet = null, this._weights.clear(), this.state.abortController = null, this.removeAllListeners?.(), Eo.debug("disposed");
3354
+ this.abort(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._releaseOutputTexture(), this._colorScalePipeline = null, this._lumReducePipeline = null, this._lumFinalizePipeline = null, this._lumLayout = null, this._unpackPipeline = null, this.unet = null, this._weights.clear(), this.state.abortController = null, this.removeAllListeners?.(), jo.debug("disposed");
3344
3355
  }
3345
- }, Ko = Object.freeze({
3356
+ }, Zo = Object.freeze({
3346
3357
  maxLength: 8,
3347
3358
  smoothLength: 2,
3348
3359
  roughStart: .45,
@@ -3350,7 +3361,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3350
3361
  depthTolerance: .05,
3351
3362
  normalTolerance: .8,
3352
3363
  movedLength: 2
3353
- }), qo = 8, Jo = 304, Yo = 16, Xo = 1, Zo = 2, Qo = 4, $o = 1073741824, es = "\nstruct Params {\n size: vec2<u32>,\n reset: u32,\n flags: u32,\n maxLength: f32,\n smoothLength: f32,\n depthTolerance: f32,\n normalTolerance: f32,\n roughStart: f32,\n roughEnd: f32,\n samples: f32,\n historyScale: f32,\n camWorld: mat4x4<f32>,\n projInv: mat4x4<f32>,\n prevViewProj: mat4x4<f32>,\n prevCamPos: vec4<f32>,\n moved: vec4<u32>,\n movedLength: f32,\n prevCamDir: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> P: Params;\n\nfn finite3( v: vec3<f32> ) -> bool {\n let e = bitcast<vec3<u32>>( v ) & vec3<u32>( 0x7f800000u );\n return all( e != vec3<u32>( 0x7f800000u ) );\n}\n\n// [0,1]-encoded in and out, renormalised like FinalWrite's clean aux.\nfn mixNormal( h: vec3<f32>, c: vec3<f32>, t: f32 ) -> vec3<f32> {\n let m = mix( h * 2.0 - 1.0, c * 2.0 - 1.0, t );\n let l = length( m );\n return select( c, m / l * 0.5 + 0.5, l > 1e-4 );\n}\n", ts = es + `
3364
+ }), Qo = 8, $o = 304, es = 16, ts = 1, ns = 2, rs = 4, is = 1073741824, as = "\nstruct Params {\n size: vec2<u32>,\n reset: u32,\n flags: u32,\n maxLength: f32,\n smoothLength: f32,\n depthTolerance: f32,\n normalTolerance: f32,\n roughStart: f32,\n roughEnd: f32,\n samples: f32,\n historyScale: f32,\n camWorld: mat4x4<f32>,\n projInv: mat4x4<f32>,\n prevViewProj: mat4x4<f32>,\n prevCamPos: vec4<f32>,\n moved: vec4<u32>,\n movedLength: f32,\n prevCamDir: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> P: Params;\n\nfn finite3( v: vec3<f32> ) -> bool {\n let e = bitcast<vec3<u32>>( v ) & vec3<u32>( 0x7f800000u );\n return all( e != vec3<u32>( 0x7f800000u ) );\n}\n\n// [0,1]-encoded in and out, renormalised like FinalWrite's clean aux.\nfn mixNormal( h: vec3<f32>, c: vec3<f32>, t: f32 ) -> vec3<f32> {\n let m = mix( h * 2.0 - 1.0, c * 2.0 - 1.0, t );\n let l = length( m );\n return select( c, m / l * 0.5 + 0.5, l > 1e-4 );\n}\n", os = as + `
3354
3365
  @group(0) @binding(1) var geoCur: texture_2d<f32>;
3355
3366
  @group(0) @binding(2) var geoPrev: texture_2d<f32>;
3356
3367
  @group(0) @binding(3) var<storage, read_write> picked: array<i32>;
@@ -3376,7 +3387,7 @@ fn movedIndex( leaf: u32 ) -> i32 {
3376
3387
 
3377
3388
  }
3378
3389
 
3379
- @compute @workgroup_size(${qo}, ${qo})
3390
+ @compute @workgroup_size(${Qo}, ${Qo})
3380
3391
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3381
3392
 
3382
3393
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -3386,12 +3397,12 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3386
3397
  var pick = -1;
3387
3398
  var movedFlag = 0;
3388
3399
 
3389
- if ( P.reset == 0u && g.w < ${Wr.toFixed(1)} ) {
3400
+ if ( P.reset == 0u && g.w < ${Gr.toFixed(1)} ) {
3390
3401
 
3391
3402
  let size = vec2<f32>( P.size );
3392
3403
  let uv = ( vec2<f32>( gid.xy ) + 0.5 ) / size;
3393
3404
  // Depth is along the ray: from the camera, or from its image plane when orthographic.
3394
- let ortho = ( P.flags & ${Qo}u ) != 0u;
3405
+ let ortho = ( P.flags & ${rs}u ) != 0u;
3395
3406
  let ndc = vec2<f32>( uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0 );
3396
3407
  var origin = P.camWorld[ 3 ].xyz;
3397
3408
  var dir: vec3<f32>;
@@ -3415,7 +3426,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3415
3426
  let toPrev = movedToPrev[ u32( m ) ];
3416
3427
  wp = ( toPrev * vec4<f32>( wp, 1.0 ) ).xyz;
3417
3428
  n = normalize( ( toPrev * vec4<f32>( n, 0.0 ) ).xyz );
3418
- movedFlag = ${$o};
3429
+ movedFlag = ${is};
3419
3430
 
3420
3431
  }
3421
3432
 
@@ -3452,7 +3463,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3452
3463
  if ( pick >= 0 ) { atomicAdd( &copies[ u32( pick ) ], 1u ); }
3453
3464
 
3454
3465
  }
3455
- `, ns = es + `
3466
+ `, ss = as + `
3456
3467
  @group(0) @binding(1) var curColor: texture_2d<f32>;
3457
3468
  @group(0) @binding(2) var curAlbedo: texture_2d<f32>;
3458
3469
  @group(0) @binding(3) var curNormal: texture_2d<f32>;
@@ -3466,7 +3477,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3466
3477
  @group(0) @binding(11) var outAlbedo: texture_storage_2d<rgba32float, write>;
3467
3478
  @group(0) @binding(12) var outNormal: texture_storage_2d<rgba32float, write>;
3468
3479
 
3469
- @compute @workgroup_size(${qo}, ${qo})
3480
+ @compute @workgroup_size(${Qo}, ${Qo})
3470
3481
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3471
3482
 
3472
3483
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -3482,8 +3493,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3482
3493
  var ha = ca.xyz;
3483
3494
  var hn = cn.xyz;
3484
3495
  let raw = picked[ gid.y * P.size.x + gid.x ];
3485
- let movedPx = raw >= 0 && ( raw & ${$o} ) != 0;
3486
- let pick = select( raw, raw & ~${$o}, raw >= 0 );
3496
+ let movedPx = raw >= 0 && ( raw & ${is} ) != 0;
3497
+ let pick = select( raw, raw & ~${is}, raw >= 0 );
3487
3498
 
3488
3499
  if ( pick >= 0 ) {
3489
3500
 
@@ -3497,7 +3508,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3497
3508
  ha = a.xyz;
3498
3509
  hn = textureLoad( histNormal, q, 0 ).xyz;
3499
3510
  len = a.w;
3500
- if ( ( P.flags & ${Zo}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
3511
+ if ( ( P.flags & ${ns}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
3501
3512
 
3502
3513
  }
3503
3514
 
@@ -3511,11 +3522,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3511
3522
 
3512
3523
  textureStore( outColor, p, vec4<f32>( mix( hc, cur.xyz, t ), cur.w ) );
3513
3524
  textureStore( outAlbedo, p, vec4<f32>( mix( ha, ca.xyz, t ), newLen ) );
3514
- let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${Xo}u ) != 0u );
3525
+ let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${ts}u ) != 0u );
3515
3526
  textureStore( outNormal, p, vec4<f32>( n, cn.w ) );
3516
3527
 
3517
3528
  }
3518
- `, rs = es + `
3529
+ `, cs = as + `
3519
3530
  @group(0) @binding(1) var accColor: texture_2d<f32>;
3520
3531
  @group(0) @binding(2) var accAlbedo: texture_2d<f32>;
3521
3532
  @group(0) @binding(3) var accNormal: texture_2d<f32>;
@@ -3526,7 +3537,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3526
3537
  @group(0) @binding(8) var outAlbedo: texture_storage_2d<rgba32float, write>;
3527
3538
  @group(0) @binding(9) var outNormal: texture_storage_2d<rgba32float, write>;
3528
3539
 
3529
- @compute @workgroup_size(${qo}, ${qo})
3540
+ @compute @workgroup_size(${Qo}, ${Qo})
3530
3541
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3531
3542
 
3532
3543
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -3560,32 +3571,32 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3560
3571
  let t = P.samples / max( k + P.samples, 1e-6 );
3561
3572
  textureStore( outColor, p, vec4<f32>( mix( hc, ac.xyz, t ), ac.w ) );
3562
3573
  textureStore( outAlbedo, p, vec4<f32>( mix( ha, aa.xyz, t ), min( k + P.samples, P.maxLength ) ) );
3563
- let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${Xo}u ) != 0u );
3574
+ let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${ts}u ) != 0u );
3564
3575
  textureStore( outNormal, p, vec4<f32>( n, an.w ) );
3565
3576
 
3566
3577
  }
3567
- `, is = (e) => ({
3578
+ `, ls = (e) => ({
3568
3579
  binding: e,
3569
3580
  visibility: GPUShaderStage.COMPUTE,
3570
3581
  texture: { sampleType: "unfilterable-float" }
3571
- }), as = (e) => ({
3582
+ }), us = (e) => ({
3572
3583
  binding: e,
3573
3584
  visibility: GPUShaderStage.COMPUTE,
3574
3585
  storageTexture: {
3575
3586
  access: "write-only",
3576
3587
  format: "rgba32float"
3577
3588
  }
3578
- }), os = (e, t) => ({
3589
+ }), ds = (e, t) => ({
3579
3590
  binding: e,
3580
3591
  visibility: GPUShaderStage.COMPUTE,
3581
3592
  buffer: { type: t }
3582
- }), ss = class {
3593
+ }), fs = class {
3583
3594
  constructor(e) {
3584
3595
  this.device = e, this.settings = {
3585
- ...Ko,
3596
+ ...Zo,
3586
3597
  cleanAux: !1,
3587
3598
  splitCopies: !0
3588
- }, this.valid = !1, this.width = 0, this.height = 0, this._sets = null, this._current = 0, this._picked = null, this._copies = null, this._paramsBuffer = null, this._pipelines = null, this._movedLeaves = null, this._movedToPrev = null, this._movedCapacity = 0, this._movedCount = 0, this._paramData = new ArrayBuffer(Jo), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._prevViewProj = new Float32Array(16), this._prevCamPos = new Float32Array(4), this._prevCamDir = new Float32Array(4);
3599
+ }, this.valid = !1, this.width = 0, this.height = 0, this._sets = null, this._current = 0, this._picked = null, this._copies = null, this._paramsBuffer = null, this._pipelines = null, this._movedLeaves = null, this._movedToPrev = null, this._movedCapacity = 0, this._movedCount = 0, this._paramData = new ArrayBuffer($o), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._prevViewProj = new Float32Array(16), this._prevCamPos = new Float32Array(4), this._prevCamDir = new Float32Array(4);
3589
3600
  }
3590
3601
  get textures() {
3591
3602
  return this.valid ? this._sets[this._current] : null;
@@ -3693,23 +3704,23 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3693
3704
  }),
3694
3705
  layout: i
3695
3706
  };
3696
- }, n = os(0, "uniform");
3707
+ }, n = ds(0, "uniform");
3697
3708
  this._pipelines = {
3698
- select: t("oidn-history-select", ts, [
3709
+ select: t("oidn-history-select", os, [
3699
3710
  n,
3700
- is(1),
3701
- is(2),
3702
- os(3, "storage"),
3703
- os(4, "storage"),
3711
+ ls(1),
3712
+ ls(2),
3713
+ ds(3, "storage"),
3714
+ ds(4, "storage"),
3704
3715
  {
3705
3716
  binding: 5,
3706
3717
  visibility: GPUShaderStage.COMPUTE,
3707
3718
  texture: { sampleType: "uint" }
3708
3719
  },
3709
- os(6, "read-only-storage"),
3710
- os(7, "read-only-storage")
3720
+ ds(6, "read-only-storage"),
3721
+ ds(7, "read-only-storage")
3711
3722
  ]),
3712
- blend: t("oidn-history-blend", ns, [
3723
+ blend: t("oidn-history-blend", ss, [
3713
3724
  n,
3714
3725
  ...[
3715
3726
  1,
@@ -3719,14 +3730,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3719
3730
  5,
3720
3731
  6,
3721
3732
  7
3722
- ].map(is),
3723
- os(8, "read-only-storage"),
3724
- os(9, "read-only-storage"),
3725
- as(10),
3726
- as(11),
3727
- as(12)
3733
+ ].map(ls),
3734
+ ds(8, "read-only-storage"),
3735
+ ds(9, "read-only-storage"),
3736
+ us(10),
3737
+ us(11),
3738
+ us(12)
3728
3739
  ]),
3729
- merge: t("oidn-history-merge", rs, [
3740
+ merge: t("oidn-history-merge", cs, [
3730
3741
  n,
3731
3742
  ...[
3732
3743
  1,
@@ -3735,16 +3746,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3735
3746
  4,
3736
3747
  5,
3737
3748
  6
3738
- ].map(is),
3739
- as(7),
3740
- as(8),
3741
- as(9)
3749
+ ].map(ls),
3750
+ us(7),
3751
+ us(8),
3752
+ us(9)
3742
3753
  ])
3743
3754
  }, this._paramsBuffer = e.createBuffer({
3744
3755
  label: "oidn-history-params",
3745
- size: Jo,
3756
+ size: $o,
3746
3757
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3747
- }), this._growMoved(Yo);
3758
+ }), this._growMoved(es);
3748
3759
  }
3749
3760
  _growMoved(e) {
3750
3761
  this._movedLeaves?.destroy(), this._movedToPrev?.destroy();
@@ -3770,11 +3781,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3770
3781
  a.setPipeline(t), a.setBindGroup(0, this.device.createBindGroup({
3771
3782
  layout: n,
3772
3783
  entries: i
3773
- })), a.dispatchWorkgroups(Math.ceil(this.width / qo), Math.ceil(this.height / qo)), a.end();
3784
+ })), a.dispatchWorkgroups(Math.ceil(this.width / Qo), Math.ceil(this.height / Qo)), a.end();
3774
3785
  }
3775
3786
  _writeParams(e, t, n, r) {
3776
3787
  let i = this.settings, a = this._paramU32, o = this._paramF32;
3777
- a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? Xo : 0) | (i.splitCopies ? Zo : 0) | (e.orthographic ? Qo : 0), o[4] = i.maxLength, o[5] = i.smoothLength, o[6] = i.depthTolerance, o[7] = i.normalTolerance, o[8] = i.roughStart, o[9] = i.roughEnd, o[10] = n, o[11] = r, o.set(e.world, 12), o.set(e.projInv, 28), o.set(this._prevViewProj, 44), o.set(this._prevCamPos, 60), a[64] = this._movedCount, o[68] = i.movedLength, o.set(this._prevCamDir, 72), this.device.queue.writeBuffer(this._paramsBuffer, 0, this._paramData);
3788
+ a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? ts : 0) | (i.splitCopies ? ns : 0) | (e.orthographic ? rs : 0), o[4] = i.maxLength, o[5] = i.smoothLength, o[6] = i.depthTolerance, o[7] = i.normalTolerance, o[8] = i.roughStart, o[9] = i.roughEnd, o[10] = n, o[11] = r, o.set(e.world, 12), o.set(e.projInv, 28), o.set(this._prevViewProj, 44), o.set(this._prevCamPos, 60), a[64] = this._movedCount, o[68] = i.movedLength, o.set(this._prevCamDir, 72), this.device.queue.writeBuffer(this._paramsBuffer, 0, this._paramData);
3778
3789
  }
3779
3790
  _rememberCamera(e) {
3780
3791
  this._prevViewProj.set(e.viewProj), this._prevCamPos[0] = e.world[12], this._prevCamPos[1] = e.world[13], this._prevCamPos[2] = e.world[14];
@@ -3784,11 +3795,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3784
3795
  _releaseTextures() {
3785
3796
  this._sets?.forEach((e) => Object.values(e).forEach((e) => e.destroy())), this._picked?.destroy(), this._copies?.destroy(), this._sets = null, this._picked = null, this._copies = null, this.width = 0, this.height = 0, this.valid = !1;
3786
3797
  }
3787
- }, cs = "const e=Object.freeze({ADAPTER_SOFTWARE:`adapter.software`,ASSET_UNREACHABLE:`asset.unreachable`,ASSET_AMBIGUOUS_ENTRY:`asset.ambiguous_entry`,ASSET_ARCHIVE_TOO_LARGE:`asset.archive_too_large`,ASSET_ENTRY_TOO_LARGE:`asset.entry_too_large`,TEXTURE_BUILD_FAILED:`texture.build_failed`,TEXTURE_PROCESSING_FALLBACK:`texture.processing_fallback`,TEXTURE_LIMIT_EXCEEDED:`texture.limit_exceeded`,ENVIRONMENT_LOAD_FAILED:`environment.load_failed`,SETTING_UNKNOWN_KEY:`setting.unknown_key`,RENDER_SIZE_DECLINED:`render.size_declined`,STAGE_RENDER_FAILED:`stage.render_failed`,RENDER_RESERVE_CAPPED:`render.reserve_capped`,SCENE_MEMORY_BUDGET:`scene.memory_budget`,EMISSIVE_INSTANCES_COLLAPSED:`emissive.instances_collapsed`,REFIT_SHARED_GEOMETRY:`refit.shared_geometry`,VIEW_TRANSFORM_DISPLAY_MISMATCH:`viewTransform.display_mismatch`,VIEW_TRANSFORM_BAKE_FAILED:`viewTransform.bake_failed`,COLOR_CONFIG_LOAD_FAILED:`color.config_load_failed`,STORAGE_UNAVAILABLE:`storage.unavailable`,STORAGE_QUOTA_EXCEEDED:`storage.quota_exceeded`,STORAGE_WRITE_FAILED:`storage.write_failed`,STORAGE_READ_FAILED:`storage.read_failed`,STORAGE_ENTRY_CORRUPT:`storage.entry_corrupt`,STORAGE_CACHE_MISMATCH:`storage.cache_mismatch`,DENOISER_UNAVAILABLE:`denoiser.unavailable`,OUTPUT_SOURCE_FALLBACK:`output.source_fallback`,OUTPUT_TONEMAP_FALLBACK:`output.tonemap_fallback`,LIGHT_PLACEHOLDER_SKIPPED:`light.placeholder_skipped`,CAPABILITY_MISSING:`capability.missing`});Object.freeze({ERROR:`error`,WARNING:`warning`});const t=new Map;function n(e,t){return e.exclusive||t===`exclusive`&&e.shared>0?!1:(t===`exclusive`?e.exclusive=!0:e.shared++,!0)}function r(e,r,a){let o=t.get(e);o||(o={shared:0,exclusive:!1,queue:[]},t.set(e,o));let s=i(()=>{for(r===`exclusive`?o.exclusive=!1:o.shared--;o.queue.length&&n(o,o.queue[0].mode);)o.queue.shift().grant();!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e)});return o.queue.length===0&&n(o,r)?Promise.resolve(s):a?(!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e),Promise.resolve(null)):new Promise(e=>o.queue.push({mode:r,grant:()=>e(s)}))}function i(e){let t=!1;return()=>{t||(t=!0,e())}}const a=()=>typeof navigator<`u`&&navigator.locks?.request?navigator.locks:null;function o(e,{mode:t=`exclusive`,ifAvailable:n=!1}={}){let o=a();return o?new Promise((r,a)=>{o.request(e,{mode:t,ifAvailable:n},e=>{if(!e){r(null);return}return new Promise(e=>r(i(e)))}).catch(a)}):r(e,t,n)}async function s(){let e=a();if(!e)return new Set(t.keys());let{held:n=[]}=await e.query();return new Set(n.map(e=>e.name))}const c=new TextEncoder;function l(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function u(e){let t=typeof e==`string`?c.encode(e):e;return l(new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)))}async function d(e){return(await u(e)).slice(0,32)}var f=class{constructor(){this._handlers=new Map}addEventListener(e,t){this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t)}removeEventListener(e,t){this._handlers.get(e)?.delete(t)}dispatchEvent(e){for(let t of[...this._handlers.get(e.type)??[]])t.call(this,e)}},p=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}},m=class{constructor(e){this._ops=new p(e)}async call(e,t){return this._ops[e](t)}dispose(){this._ops.dispose()}};const h=Object.freeze({CACHE:`cache`,USER:`user`,SCRATCH:`scratch`}),g=Object.freeze({DOWNLOADS:`downloads`,ARCHIVES:`archives`,SCENES:`scenes`,CDF:`cdf`,SPILL:`spill`}),_=`meta.json`,v=100*1024**3,y=64*1024**2,b=8*1024**2,x=new TextEncoder;function S(e,{copy:t,transfer:n}){if(typeof e==`string`&&(e=x.encode(e)),e instanceof ArrayBuffer){if(!t||n)return{args:{buffer:e},list:[e]};let r=e.slice(0);return{args:{buffer:r},list:[r]}}if(!ArrayBuffer.isView(e))throw TypeError(`storage: write expects an ArrayBuffer, a typed array, a Blob or a string`);let{buffer:r,byteOffset:i,byteLength:a}=e,o=typeof SharedArrayBuffer<`u`&&r instanceof SharedArrayBuffer;if(!t)return{args:{buffer:r,byteOffset:i,byteLength:a},list:[]};if(o){let e=new Uint8Array(a);return e.set(new Uint8Array(r,i,a)),{args:{buffer:e.buffer},list:[e.buffer]}}if(n&&i===0&&a===r.byteLength)return{args:{buffer:r},list:[r]};let s=r.slice(i,i+a);return{args:{buffer:s},list:[s]}}async function C(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return JSON.parse(await n.text())}catch{return null}}async function*w(e){for await(let[t,n]of e.entries())n.kind===`directory`&&(yield[t,n])}var T=class{constructor(e,t,n,r,i){this.area=e,this.id=t,this.key=n.key,this.meta=n,this._dir=r,this._release=i}get bytes(){return this.meta.bytes}get extra(){return this.meta.extra??{}}async file(t){try{return await(await this._dir.getFileHandle(t)).getFile()}catch(n){return this.area.manager._issue(e.STORAGE_READ_FAILED,`could not read ${this.area.name}/${this.id}/${t}`,{error:n.message}),null}}async json(e){let t=await this.file(e);return t?JSON.parse(await t.text()):null}release(){this._release?.(),this._release=null}},E=class{constructor(e,t,n,r,i,{sizes:a={},append:o=!1}={}){this.area=e,this.id=t,this.key=n,this._info=r,this._release=i,this._writers=new Map,this._sizes={...a},this._append=o,this._done=!1,this._committedBytes=o?Object.values(a).reduce((e,t)=>e+t,0):0}get _transport(){return this.area.manager._transport}get _path(){return[this.area.name,this.id]}async _writer(e){let t=this._writers.get(e);if(!t){let n=this._append&&e in this._sizes,r=n&&(this._info.growable??[]).includes(e)?this._sizes[e]:void 0;t=this._transport.call(`openWriter`,{path:this._path,name:e,truncate:!n,length:r}),this._writers.set(e,t)}return(await t).id}async write(e,t,{at:n,transfer:r=!1}={}){this._assertOpen();let{args:i,list:a}=(typeof Blob<`u`&&t instanceof Blob?null:S(t,{copy:!0,transfer:r}))??S(await t.arrayBuffer(),{copy:!0,transfer:!0}),o=await this._writer(e);return this._transport.call(`write`,{id:o,at:n,...i},a)}async writeFile(e,t){this._assertOpen(),typeof Blob<`u`&&t instanceof Blob&&(t=await t.arrayBuffer());let{args:n,list:r}=S(t,{copy:!0,transfer:!0}),{size:i}=await this._transport.call(`writeFile`,{path:this._path,name:e,...n},r);return this._sizes[e]=i,i}writeJSON(e,t){return this.writeFile(e,JSON.stringify(t))}async writeStream(e,t,{onProgress:n=null,signal:r=null,batchBytes:i=b}={}){let a=t.getReader(),o=[],s=new Uint8Array(i),c=0,l=0,u=async()=>{if(c===0)return;let t=c===i?s:s.slice(0,c);s=new Uint8Array(i),c=0,o.push(this.write(e,t,{transfer:!0})),o.length>=4&&await o.shift()};try{for(;;){if(r?.aborted)throw r.reason??new DOMException(`aborted`,`AbortError`);let{done:e,value:t}=await a.read();if(e)break;let o=0;for(;o<t.length;){let e=Math.min(t.length-o,i-c);s.set(t.subarray(o,o+e),c),c+=e,o+=e,l+=e,c===i&&await u()}n?.(l)}return await u(),await Promise.all(o),l}catch(e){throw a.cancel().catch(()=>{}),await Promise.allSettled(o),e}}async commit(e={}){this._assertOpen(),this._done=!0;try{for(let[e,t]of this._writers){let{size:n}=await this._transport.call(`closeWriter`,{id:(await t).id});this._sizes[e]=n}this._writers.clear();let t=Date.now(),n={v:1,key:this.key,label:this._info.label??``,kind:this.area.kind,files:{...this._sizes},bytes:Object.values(this._sizes).reduce((e,t)=>e+t,0),createdAt:this._info.createdAt??t,lastUsed:t,pinned:this._info.pinned===!0,extra:{...this._info.extra,...e}},r=this._info.growable??[];r.length&&(n.growable=r);let{args:i,list:a}=S(JSON.stringify(n),{copy:!1});return await this._transport.call(`writeFile`,{path:this._path,name:_,...i},a),this.area.kind===h.CACHE&&this.area.manager._countCacheBytes(n.bytes-this._committedBytes),this.area.manager._changed(this.area.name),n}catch(e){throw await this._discard(),this.area.manager._writeFailed(this.area.name,e),e}finally{this._release?.(),this._release=null}}async abort(){if(!this._done){this._done=!0;try{this._append?await this._closeAll(!0):await this._discard()}finally{this._release?.(),this._release=null}}}async _closeAll(e){for(let t of this._writers.values())try{await this._transport.call(`closeWriter`,{id:(await t).id,abort:e})}catch{}this._writers.clear()}async _discard(){await this._closeAll(!0),await this.area._removeDir(this.id)}_assertOpen(){if(this._done)throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`)}},D=class{constructor(e,t,n){this.manager=e,this.name=t,this.kind=n}_lockName(e){return`${this.manager.namespace}:store:${this.name}:${e}`}async _dir(e=!1){try{return await this.manager._root.getDirectoryHandle(this.name,{create:e})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _entryDir(e,t=!1){let n=await this._dir(t);if(!n)return null;try{return await n.getDirectoryHandle(e,{create:t})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _removeDir(e){let t=await this._dir(!1);if(t)try{await t.removeEntry(e,{recursive:!0})}catch(e){if(e.name!==`NotFoundError`)throw e}}async _validMeta(e,t=null){let n=await C(e,_);if(!n||n.v!==1||typeof n.key!=`string`||t!==null&&n.key!==t)return null;let r=n.growable??[];for(let[t,i]of Object.entries(n.files??{}))try{let n=await(await e.getFileHandle(t)).getFile();if(n.size!==i&&!(r.includes(t)&&n.size>i))return null}catch{return null}return n}async open(t,{wait:n=!1}={}){let r=await d(t),i=await o(this._lockName(r),{mode:`shared`,ifAvailable:!n});if(!i)return null;try{let e=await this._entryDir(r),n=e?await this._validMeta(e,t):null;return n?(Date.now()-n.lastUsed>36e5&&this._touch(r,n),new T(this,r,n,e,i)):(i(),null)}catch(t){return i(),this.manager._issue(e.STORAGE_READ_FAILED,`could not open ${this.name} entry`,{error:t.message}),null}}async has(e){let t=await this.open(e);return t?.release(),!!t}_touch(e,t){let n={...t,lastUsed:Date.now()},{args:r,list:i}=S(JSON.stringify(n),{copy:!1});this.manager._transport.call(`writeFile`,{path:[this.name,e],name:_,...r},i).catch(()=>{}),t.lastUsed=n.lastUsed}async create(t,{label:n=``,pinned:r=!1,expectedBytes:i=0,extra:a={},growable:s=[]}={}){let c=await d(t),l=await o(this._lockName(c),{mode:`exclusive`});try{return i>0&&!await this.manager.ensureSpace(i,this.kind)?(l(),this.manager._issue(e.STORAGE_QUOTA_EXCEEDED,`no room for ${(i/1048576).toFixed(0)} MB in ${this.name}`,{area:this.name,expectedBytes:i}),null):(await this._removeDir(c),await this._entryDir(c,!0),new E(this,c,t,{label:n,pinned:r,extra:a,growable:s},l))}catch(e){return l(),this.manager._writeFailed(this.name,e),null}}async patchMeta(e,t){let n=await d(e),r=await o(this._lockName(n),{mode:`shared`,ifAvailable:!0});if(!r)return!1;try{let r=await this._entryDir(n),i=r?await this._validMeta(r,e):null;if(!i)return!1;let{args:a,list:o}=S(JSON.stringify({...i,...t,v:1,key:e}),{copy:!1});return await this.manager._transport.call(`writeFile`,{path:[this.name,n],name:_,...a},o),!0}finally{r()}}async edit(e){let t=await d(e),n=await o(this._lockName(t),{mode:`exclusive`});try{let r=await this._entryDir(t),i=r?await this._validMeta(r,e):null;if(!i)return n(),null;let a={label:i.label,pinned:i.pinned,extra:i.extra,createdAt:i.createdAt,growable:i.growable};return new E(this,t,e,a,n,{sizes:i.files,append:!0})}catch(e){return n(),this.manager._writeFailed(this.name,e),null}}async remove(e){return this.removeById(await d(e))}async removeById(e){let t=await o(this._lockName(e),{mode:`exclusive`,ifAvailable:!0});if(!t)return!1;try{return await this._removeDir(e),this.manager._changed(this.name),!0}finally{t()}}async list(){let e=await this._dir(!1);if(!e)return[];let t=[];for await(let[n,r]of w(e)){let e=await C(r,_);e?.v===1&&t.push({...e,id:n})}return t}async clear(){let e=0;for(let{id:t}of await this.list())await this.removeById(t)&&e++;return e}async sweep(){let e=await this._dir(!1);if(!e)return 0;let t=await s(),n=0;for await(let[r,i]of w(e))t.has(this._lockName(r))||await this._validMeta(i)||await this.removeById(r)&&n++;return n}},O=class extends f{constructor({root:e,transport:t,namespace:n}){super(),this.namespace=n,this._root=e,this._transport=t,this._areas=new Map,this._budget=null,this._cacheTotal=null;for(let e of Object.values(g))this.defineArea(e,{kind:e===g.SPILL?h.SCRATCH:h.CACHE})}defineArea(e,{kind:t=h.CACHE}={}){let n=this._areas.get(e);if(n){if(n.kind!==t)throw Error(`storage: area \"${e}\" is already defined as ${n.kind}`);return n}let r=new D(this,e,t);return this._areas.set(e,r),r}area(e){let t=this._areas.get(e);if(!t)throw Error(`storage: unknown area \"${e}\"`);return t}get areaNames(){return[...this._areas.keys()]}async estimate(){let e=typeof navigator<`u`?navigator.storage:null;if(!e?.estimate)return{quota:1/0,usage:0};let{quota:t=1/0,usage:n=0}=await e.estimate();return{quota:t,usage:n}}async persisted(){return await globalThis.navigator?.storage?.persisted?.()===!0}async persist(){let e=await globalThis.navigator?.storage?.persist?.()===!0;return this._changed(null),e}async budget(){if(this._budget!==null)return this._budget;let{quota:e}=await this.estimate();return Math.min(e*.3,v)}setBudget(e){this._budget=e===null?null:Math.max(0,e),this._changed(null)}async _cacheBytes(){let e=this._cacheTotal;return(!e||Date.now()-e.at>3e4)&&(e=this._cacheTotal={at:Date.now(),bytes:0,ready:null},e.ready=this._cacheEntries().then(t=>{e.bytes+=t.reduce((e,t)=>e+(t.meta.bytes??0),0)}),e.ready.catch(()=>{this._cacheTotal===e&&(this._cacheTotal=null)})),await e.ready,e.bytes}_countCacheBytes(e){this._cacheTotal&&(this._cacheTotal.bytes+=e)}async _cacheEntries(){let e=[];for(let t of this._areas.values())if(t.kind===h.CACHE)for(let n of await t.list())e.push({area:t,meta:n});return e}async usage(){let{quota:e,usage:t}=await this.estimate(),n={},r=0;for(let e of this._areas.values()){let t=await e.list(),i=t.reduce((e,t)=>e+(t.bytes??0),0);n[e.name]={kind:e.kind,bytes:i,entries:t.length},e.kind===h.CACHE&&(r+=i)}return{quota:e,usage:t,persisted:await this.persisted(),budget:await this.budget(),cacheBytes:r,areas:n}}async collect({freeBytes:e=null}={}){let t=await this._cacheEntries(),n=await this.budget(),r=this._cacheTotal={at:Date.now(),bytes:t.reduce((e,t)=>e+(t.meta.bytes??0),0),ready:null},i=e??Math.max(0,r.bytes-n);if(i<=0)return 0;let a=await s(),o=t.filter(({area:e,meta:t})=>!t.pinned&&!a.has(e._lockName(t.id))).sort((e,t)=>e.meta.lastUsed-t.meta.lastUsed),c=0;for(let{area:e,meta:t}of o){if(c>=i)break;await e.removeById(t.id)&&(c+=t.bytes??0,r.bytes-=t.bytes??0)}return c}async ensureSpace(e,t=h.CACHE){let n=async()=>{let{quota:n,usage:r}=await this.estimate(),i=e+y-(n-r);return t===h.CACHE?{free:i,budget:await this._cacheBytes()+e-await this.budget()}:{free:i,budget:0}},r=await n();return r.free<=0&&r.budget<=0?!0:(await this.collect({freeBytes:Math.max(r.free,r.budget)}),(await n()).free<=0)}async sweep(){let e=0;for(let t of this._areas.values())e+=await t.sweep(),t.kind===h.SCRATCH&&(e+=await t.clear());return e}_changed(e){this.dispatchEvent({type:`change`,area:e})}_issue(e,t,n={}){this.dispatchEvent({type:`issue`,code:e,message:t,detail:n})}_writeFailed(t,n){let r=n?.name===`QuotaExceededError`;this._issue(r?e.STORAGE_QUOTA_EXCEEDED:e.STORAGE_WRITE_FAILED,`${t}: ${n?.message??n}`,{area:t,error:n?.name})}dispose(){this._transport?.dispose(),this._transport=null,this._areas.clear()}};function k({namespace:e,root:t}){let n=new m(t);n.inline=!0;let r=new O({root:t,transport:n,namespace:e});return r.sweep().catch(()=>{}),r}const A=Object.freeze({IMMUTABLE:`immutable`,REVALIDATE:`revalidate`,NETWORK:`network`}),j=(e,t)=>({loaded:e,total:t,lengthComputable:t>0&&e<=t}),M=(e,t)=>e.headers?.get?.(t)??null,N=e=>e.reason??new DOMException(`aborted`,`AbortError`);function P(e){try{let t=new URL(e,globalThis.location?.href??`http://localhost/`).pathname;return decodeURIComponent(t.split(`/`).pop())||`download`}catch{return`download`}}async function F(e,{onProgress:t,signal:n}){let r=Number(M(e,`content-length`))||0,i=M(e,`content-type`)??``;if(!e.body)return new Blob([await e.arrayBuffer()],{type:i});let a=e.body.getReader(),o=[],s=0;for(;;){if(n?.aborted)throw a.cancel().catch(()=>{}),N(n);let{done:e,value:i}=await a.read();if(e)break;o.push(i),s+=i.length,t?.(j(s,r))}return new Blob(o,{type:i})}const I=(e,t,n)=>new File([e],t,{type:n||e.type,lastModified:e.lastModified??Date.now()}),L=()=>{};var R=class{constructor(e){this._storage=e,this._revalidating=new Set}get _area(){return this._storage?.area(g.DOWNLOADS)??null}async fetch(e,{key:t=e,name:n=P(e),policy:r=A.REVALIDATE,maxAgeMs:i=864e5,onProgress:a=null,signal:o=null,fetchOptions:s={}}={}){let c=this._area;if(c&&r!==A.NETWORK){let o=await c.open(t);if(o){let c=await o.file(`data`);if(c)return r===A.REVALIDATE&&Date.now()-(o.extra.checkedAt??0)>=i&&this._revalidate(e,t,n,o.extra,s),a?.(j(c.size,c.size)),{file:I(c,n,o.extra.contentType),release:()=>o.release(),fromCache:!0};o.release()}}return this._download(e,t,n,{onProgress:a,signal:o,fetchOptions:s,cache:!!c})}async has(e){return await this._area?.has(e)===!0}async _download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:o}){if(i?.aborted)throw N(i);let s=await fetch(e,{...a,signal:i});if(!s.ok)throw Error(`HTTP ${s.status} fetching ${e}`);let c=Number(M(s,`content-length`))||0,l={url:e,contentType:M(s,`content-type`)??``,lastModified:M(s,`last-modified`),contentLength:c||null,checkedAt:Date.now()},u=o&&s.body?await this._area.create(t,{label:n,expectedBytes:c}):null;if(!u)return{file:I(await F(s,{onProgress:r,signal:i}),n,l.contentType),release:L,fromCache:!1};try{await u.writeStream(`data`,s.body,{signal:i,onProgress:e=>r?.(j(e,c))}),await u.commit(l)}catch(o){if(await u.abort(),o?.name!==`QuotaExceededError`)throw o;return this._download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:!1})}let d=await this._area.open(t,{wait:!0}),f=d&&await d.file(`data`);if(!f)throw d?.release(),Error(`storage: ${n} vanished right after it was saved`);return{file:I(f,n,l.contentType),release:()=>d.release(),fromCache:!1}}async _revalidate(e,t,n,r,i){if(this._revalidating.has(t))return;this._revalidating.add(t);let a=!1;try{let t=new Headers(i?.headers);t.set(`Range`,`bytes=0-0`);let n=await fetch(e,{...i,headers:t});if(n.body?.cancel().catch(()=>{}),n.ok){let e=M(n,`last-modified`),t=n.status===206?Number(M(n,`content-range`)?.match(/\\/(\\d+)$/)?.[1])||null:Number(M(n,`content-length`))||null;a=!!(e&&r.lastModified&&e!==r.lastModified||t&&r.contentLength&&t!==r.contentLength)}}catch{}try{if(a){let{release:r}=await this._download(e,t,n,{fetchOptions:i,cache:!0});r()}else await this._area.patchMeta(t,{extra:{...r,checkedAt:Date.now()}})}catch{}finally{this._revalidating.delete(t)}}};let z={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`,storage:`auto`},B=null;async function V(){return B||(B=await import(z.ortRuntimeUrl),B.env.wasm.wasmPaths=z.ortWasmPaths,B.env.logLevel=`error`,B)}let H=null,U=null,W=null;function G(){return W??=(async()=>{if(z.storage===!1||!navigator.storage?.getDirectory)return new R(null);try{let e=await(await navigator.storage.getDirectory()).getDirectoryHandle(z.cacheNamespace,{create:!0}),t=k({namespace:z.cacheNamespace,root:e});return await K(t).catch(()=>{}),new R(t)}catch{return new R(null)}})(),W}async function K(e){let t=`${z.cacheNamespace}:ai-upscaler-models`;if(typeof indexedDB>`u`||!indexedDB.databases||!(await indexedDB.databases()).some(e=>e.name===t))return;let n=await new Promise((e,n)=>{let r=indexedDB.open(t);r.onerror=()=>n(r.error),r.onsuccess=()=>{let t=r.result;if(!t.objectStoreNames.contains(`models`)){t.close(),e([]);return}let i=[],a=t.transaction(`models`,`readonly`).objectStore(`models`).openCursor();a.onerror=()=>n(a.error),a.onsuccess=()=>{let n=a.result;if(!n){t.close(),e(i);return}i.push([n.key,n.value]),n.continue()}}}),r=e.area(`downloads`);for(let[e,t]of n){if(typeof e!=`string`||!(t instanceof ArrayBuffer)||await r.has(e))continue;let n=await r.create(e,{label:e.split(`/`).pop(),expectedBytes:t.byteLength});n&&(await n.write(`data`,t,{transfer:!0}),await n.commit({url:e,contentType:`application/octet-stream`,checkedAt:Date.now()}))}await new Promise(e=>{let n=indexedDB.deleteDatabase(t);n.onsuccess=n.onerror=n.onblocked=()=>e()})}async function q(e){let{file:t,release:n,fromCache:r}=await(await G()).fetch(e);try{let e=await t.arrayBuffer();return r&&console.log(`AI Upscaler Worker: model loaded from cache (${(e.byteLength/1024/1024).toFixed(1)}MB)`),e}finally{n()}}async function J(e,t){if(H&&U===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}H&&=(await H.release(),null);let[n,r]=await Promise.all([q(e),V()]);H=await r.InferenceSession.create(n,t),U=e;let i=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);i=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${i}`)}catch{}let a=(n.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${a}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:i})}async function Y(e,t,n,r){let i=await V(),a=H.inputNames[0],o=H.outputNames[0],s=new i.Tensor(`float32`,e,[1,3,n,t]),c=(await H.run({[a]:s}))[o].data;self.postMessage({type:`inferred`,outputData:c,id:r},[c.buffer])}self.onmessage=async e=>{let{type:t}=e.data;try{t===`load`?(e.data.ortRuntimeUrl&&(z.ortRuntimeUrl=e.data.ortRuntimeUrl),e.data.ortWasmPaths&&(z.ortWasmPaths=e.data.ortWasmPaths),e.data.cacheNamespace&&(z.cacheNamespace=e.data.cacheNamespace),e.data.storage!==void 0&&(z.storage=e.data.storage),await J(e.data.url,e.data.sessionOptions)):t===`infer`?await Y(e.data.tileData,e.data.width,e.data.height,e.data.id):t===`dispose`&&H&&(await H.release(),H=null,U=null)}catch(t){self.postMessage({type:`error`,message:t.message,id:e.data?.id})}};", ls = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", cs], { type: "text/javascript;charset=utf-8" });
3788
- function us(e) {
3798
+ }, ps = "const e=Object.freeze({ADAPTER_SOFTWARE:`adapter.software`,ADAPTER_UNAVAILABLE:`adapter.unavailable`,DEVICE_UNAVAILABLE:`device.unavailable`,WEBGPU_UNAVAILABLE:`webgpu.unavailable`,ASSET_UNREACHABLE:`asset.unreachable`,ASSET_AMBIGUOUS_ENTRY:`asset.ambiguous_entry`,ASSET_ARCHIVE_TOO_LARGE:`asset.archive_too_large`,ASSET_ENTRY_TOO_LARGE:`asset.entry_too_large`,TEXTURE_BUILD_FAILED:`texture.build_failed`,TEXTURE_PROCESSING_FALLBACK:`texture.processing_fallback`,TEXTURE_LIMIT_EXCEEDED:`texture.limit_exceeded`,ENVIRONMENT_LOAD_FAILED:`environment.load_failed`,SETTING_UNKNOWN_KEY:`setting.unknown_key`,RENDER_SIZE_DECLINED:`render.size_declined`,STAGE_RENDER_FAILED:`stage.render_failed`,RENDER_RESERVE_CAPPED:`render.reserve_capped`,SCENE_MEMORY_BUDGET:`scene.memory_budget`,EMISSIVE_INSTANCES_COLLAPSED:`emissive.instances_collapsed`,REFIT_SHARED_GEOMETRY:`refit.shared_geometry`,VIEW_TRANSFORM_DISPLAY_MISMATCH:`viewTransform.display_mismatch`,VIEW_TRANSFORM_BAKE_FAILED:`viewTransform.bake_failed`,COLOR_CONFIG_LOAD_FAILED:`color.config_load_failed`,STORAGE_UNAVAILABLE:`storage.unavailable`,STORAGE_QUOTA_EXCEEDED:`storage.quota_exceeded`,STORAGE_WRITE_FAILED:`storage.write_failed`,STORAGE_READ_FAILED:`storage.read_failed`,STORAGE_ENTRY_CORRUPT:`storage.entry_corrupt`,STORAGE_CACHE_MISMATCH:`storage.cache_mismatch`,DENOISER_UNAVAILABLE:`denoiser.unavailable`,OUTPUT_SOURCE_FALLBACK:`output.source_fallback`,OUTPUT_TONEMAP_FALLBACK:`output.tonemap_fallback`,LIGHT_PLACEHOLDER_SKIPPED:`light.placeholder_skipped`,CAPABILITY_MISSING:`capability.missing`});Object.freeze({ERROR:`error`,WARNING:`warning`});const t=new Map;function n(e,t){return e.exclusive||t===`exclusive`&&e.shared>0?!1:(t===`exclusive`?e.exclusive=!0:e.shared++,!0)}function r(e,r,a){let o=t.get(e);o||(o={shared:0,exclusive:!1,queue:[]},t.set(e,o));let s=i(()=>{for(r===`exclusive`?o.exclusive=!1:o.shared--;o.queue.length&&n(o,o.queue[0].mode);)o.queue.shift().grant();!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e)});return o.queue.length===0&&n(o,r)?Promise.resolve(s):a?(!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e),Promise.resolve(null)):new Promise(e=>o.queue.push({mode:r,grant:()=>e(s)}))}function i(e){let t=!1;return()=>{t||(t=!0,e())}}const a=()=>typeof navigator<`u`&&navigator.locks?.request?navigator.locks:null;function o(e,{mode:t=`exclusive`,ifAvailable:n=!1}={}){let o=a();return o?new Promise((r,a)=>{o.request(e,{mode:t,ifAvailable:n},e=>{if(!e){r(null);return}return new Promise(e=>r(i(e)))}).catch(a)}):r(e,t,n)}async function s(){let e=a();if(!e)return new Set(t.keys());let{held:n=[]}=await e.query();return new Set(n.map(e=>e.name))}const c=new TextEncoder;function l(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function u(e){let t=typeof e==`string`?c.encode(e):e;return l(new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)))}async function d(e){return(await u(e)).slice(0,32)}var f=class{constructor(){this._handlers=new Map}addEventListener(e,t){this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t)}removeEventListener(e,t){this._handlers.get(e)?.delete(t)}dispatchEvent(e){for(let t of[...this._handlers.get(e.type)??[]])t.call(this,e)}},p=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}},m=class{constructor(e){this._ops=new p(e)}async call(e,t){return this._ops[e](t)}dispose(){this._ops.dispose()}};const h=Object.freeze({CACHE:`cache`,USER:`user`,SCRATCH:`scratch`}),g=Object.freeze({DOWNLOADS:`downloads`,ARCHIVES:`archives`,SCENES:`scenes`,CDF:`cdf`,SPILL:`spill`}),_=`meta.json`,v=100*1024**3,y=64*1024**2,b=8*1024**2,x=new TextEncoder;function S(e,{copy:t,transfer:n}){if(typeof e==`string`&&(e=x.encode(e)),e instanceof ArrayBuffer){if(!t||n)return{args:{buffer:e},list:[e]};let r=e.slice(0);return{args:{buffer:r},list:[r]}}if(!ArrayBuffer.isView(e))throw TypeError(`storage: write expects an ArrayBuffer, a typed array, a Blob or a string`);let{buffer:r,byteOffset:i,byteLength:a}=e,o=typeof SharedArrayBuffer<`u`&&r instanceof SharedArrayBuffer;if(!t)return{args:{buffer:r,byteOffset:i,byteLength:a},list:[]};if(o){let e=new Uint8Array(a);return e.set(new Uint8Array(r,i,a)),{args:{buffer:e.buffer},list:[e.buffer]}}if(n&&i===0&&a===r.byteLength)return{args:{buffer:r},list:[r]};let s=r.slice(i,i+a);return{args:{buffer:s},list:[s]}}async function C(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return JSON.parse(await n.text())}catch{return null}}async function*w(e){for await(let[t,n]of e.entries())n.kind===`directory`&&(yield[t,n])}var T=class{constructor(e,t,n,r,i){this.area=e,this.id=t,this.key=n.key,this.meta=n,this._dir=r,this._release=i}get bytes(){return this.meta.bytes}get extra(){return this.meta.extra??{}}async file(t){try{return await(await this._dir.getFileHandle(t)).getFile()}catch(n){return this.area.manager._issue(e.STORAGE_READ_FAILED,`could not read ${this.area.name}/${this.id}/${t}`,{error:n.message}),null}}async json(e){let t=await this.file(e);return t?JSON.parse(await t.text()):null}release(){this._release?.(),this._release=null}},E=class{constructor(e,t,n,r,i,{sizes:a={},append:o=!1}={}){this.area=e,this.id=t,this.key=n,this._info=r,this._release=i,this._writers=new Map,this._sizes={...a},this._append=o,this._done=!1,this._committedBytes=o?Object.values(a).reduce((e,t)=>e+t,0):0}get _transport(){return this.area.manager._transport}get _path(){return[this.area.name,this.id]}async _writer(e){let t=this._writers.get(e);if(!t){let n=this._append&&e in this._sizes,r=n&&(this._info.growable??[]).includes(e)?this._sizes[e]:void 0;t=this._transport.call(`openWriter`,{path:this._path,name:e,truncate:!n,length:r}),this._writers.set(e,t)}return(await t).id}async write(e,t,{at:n,transfer:r=!1}={}){this._assertOpen();let{args:i,list:a}=(typeof Blob<`u`&&t instanceof Blob?null:S(t,{copy:!0,transfer:r}))??S(await t.arrayBuffer(),{copy:!0,transfer:!0}),o=await this._writer(e);return this._transport.call(`write`,{id:o,at:n,...i},a)}async writeFile(e,t){this._assertOpen(),typeof Blob<`u`&&t instanceof Blob&&(t=await t.arrayBuffer());let{args:n,list:r}=S(t,{copy:!0,transfer:!0}),{size:i}=await this._transport.call(`writeFile`,{path:this._path,name:e,...n},r);return this._sizes[e]=i,i}writeJSON(e,t){return this.writeFile(e,JSON.stringify(t))}async writeStream(e,t,{onProgress:n=null,signal:r=null,batchBytes:i=b}={}){let a=t.getReader(),o=[],s=new Uint8Array(i),c=0,l=0,u=async()=>{if(c===0)return;let t=c===i?s:s.slice(0,c);s=new Uint8Array(i),c=0,o.push(this.write(e,t,{transfer:!0})),o.length>=4&&await o.shift()};try{for(;;){if(r?.aborted)throw r.reason??new DOMException(`aborted`,`AbortError`);let{done:e,value:t}=await a.read();if(e)break;let o=0;for(;o<t.length;){let e=Math.min(t.length-o,i-c);s.set(t.subarray(o,o+e),c),c+=e,o+=e,l+=e,c===i&&await u()}n?.(l)}return await u(),await Promise.all(o),l}catch(e){throw a.cancel().catch(()=>{}),await Promise.allSettled(o),e}}async commit(e={}){this._assertOpen(),this._done=!0;try{for(let[e,t]of this._writers){let{size:n}=await this._transport.call(`closeWriter`,{id:(await t).id});this._sizes[e]=n}this._writers.clear();let t=Date.now(),n={v:1,key:this.key,label:this._info.label??``,kind:this.area.kind,files:{...this._sizes},bytes:Object.values(this._sizes).reduce((e,t)=>e+t,0),createdAt:this._info.createdAt??t,lastUsed:t,pinned:this._info.pinned===!0,extra:{...this._info.extra,...e}},r=this._info.growable??[];r.length&&(n.growable=r);let{args:i,list:a}=S(JSON.stringify(n),{copy:!1});return await this._transport.call(`writeFile`,{path:this._path,name:_,...i},a),this.area.kind===h.CACHE&&this.area.manager._countCacheBytes(n.bytes-this._committedBytes),this.area.manager._changed(this.area.name),n}catch(e){throw await this._discard(),this.area.manager._writeFailed(this.area.name,e),e}finally{this._release?.(),this._release=null}}async abort(){if(!this._done){this._done=!0;try{this._append?await this._closeAll(!0):await this._discard()}finally{this._release?.(),this._release=null}}}async _closeAll(e){for(let t of this._writers.values())try{await this._transport.call(`closeWriter`,{id:(await t).id,abort:e})}catch{}this._writers.clear()}async _discard(){await this._closeAll(!0),await this.area._removeDir(this.id)}_assertOpen(){if(this._done)throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`)}},D=class{constructor(e,t,n){this.manager=e,this.name=t,this.kind=n}_lockName(e){return`${this.manager.namespace}:store:${this.name}:${e}`}async _dir(e=!1){try{return await this.manager._root.getDirectoryHandle(this.name,{create:e})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _entryDir(e,t=!1){let n=await this._dir(t);if(!n)return null;try{return await n.getDirectoryHandle(e,{create:t})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _removeDir(e){let t=await this._dir(!1);if(t)try{await t.removeEntry(e,{recursive:!0})}catch(e){if(e.name!==`NotFoundError`)throw e}}async _validMeta(e,t=null){let n=await C(e,_);if(!n||n.v!==1||typeof n.key!=`string`||t!==null&&n.key!==t)return null;let r=n.growable??[];for(let[t,i]of Object.entries(n.files??{}))try{let n=await(await e.getFileHandle(t)).getFile();if(n.size!==i&&!(r.includes(t)&&n.size>i))return null}catch{return null}return n}async open(t,{wait:n=!1}={}){let r=await d(t),i=await o(this._lockName(r),{mode:`shared`,ifAvailable:!n});if(!i)return null;try{let e=await this._entryDir(r),n=e?await this._validMeta(e,t):null;return n?(Date.now()-n.lastUsed>36e5&&this._touch(r,n),new T(this,r,n,e,i)):(i(),null)}catch(t){return i(),this.manager._issue(e.STORAGE_READ_FAILED,`could not open ${this.name} entry`,{error:t.message}),null}}async has(e){let t=await this.open(e);return t?.release(),!!t}_touch(e,t){let n={...t,lastUsed:Date.now()},{args:r,list:i}=S(JSON.stringify(n),{copy:!1});this.manager._transport.call(`writeFile`,{path:[this.name,e],name:_,...r},i).catch(()=>{}),t.lastUsed=n.lastUsed}async create(t,{label:n=``,pinned:r=!1,expectedBytes:i=0,extra:a={},growable:s=[]}={}){let c=await d(t),l=await o(this._lockName(c),{mode:`exclusive`});try{return i>0&&!await this.manager.ensureSpace(i,this.kind)?(l(),this.manager._issue(e.STORAGE_QUOTA_EXCEEDED,`no room for ${(i/1048576).toFixed(0)} MB in ${this.name}`,{area:this.name,expectedBytes:i}),null):(await this._removeDir(c),await this._entryDir(c,!0),new E(this,c,t,{label:n,pinned:r,extra:a,growable:s},l))}catch(e){return l(),this.manager._writeFailed(this.name,e),null}}async patchMeta(e,t){let n=await d(e),r=await o(this._lockName(n),{mode:`shared`,ifAvailable:!0});if(!r)return!1;try{let r=await this._entryDir(n),i=r?await this._validMeta(r,e):null;if(!i)return!1;let{args:a,list:o}=S(JSON.stringify({...i,...t,v:1,key:e}),{copy:!1});return await this.manager._transport.call(`writeFile`,{path:[this.name,n],name:_,...a},o),!0}finally{r()}}async edit(e){let t=await d(e),n=await o(this._lockName(t),{mode:`exclusive`});try{let r=await this._entryDir(t),i=r?await this._validMeta(r,e):null;if(!i)return n(),null;let a={label:i.label,pinned:i.pinned,extra:i.extra,createdAt:i.createdAt,growable:i.growable};return new E(this,t,e,a,n,{sizes:i.files,append:!0})}catch(e){return n(),this.manager._writeFailed(this.name,e),null}}async remove(e){return this.removeById(await d(e))}async removeById(e){let t=await o(this._lockName(e),{mode:`exclusive`,ifAvailable:!0});if(!t)return!1;try{return await this._removeDir(e),this.manager._changed(this.name),!0}finally{t()}}async list(){let e=await this._dir(!1);if(!e)return[];let t=[];for await(let[n,r]of w(e)){let e=await C(r,_);e?.v===1&&t.push({...e,id:n})}return t}async clear(){let e=0;for(let{id:t}of await this.list())await this.removeById(t)&&e++;return e}async sweep(){let e=await this._dir(!1);if(!e)return 0;let t=await s(),n=0;for await(let[r,i]of w(e))t.has(this._lockName(r))||await this._validMeta(i)||await this.removeById(r)&&n++;return n}},O=class extends f{constructor({root:e,transport:t,namespace:n}){super(),this.namespace=n,this._root=e,this._transport=t,this._areas=new Map,this._budget=null,this._cacheTotal=null;for(let e of Object.values(g))this.defineArea(e,{kind:e===g.SPILL?h.SCRATCH:h.CACHE})}defineArea(e,{kind:t=h.CACHE}={}){let n=this._areas.get(e);if(n){if(n.kind!==t)throw Error(`storage: area \"${e}\" is already defined as ${n.kind}`);return n}let r=new D(this,e,t);return this._areas.set(e,r),r}area(e){let t=this._areas.get(e);if(!t)throw Error(`storage: unknown area \"${e}\"`);return t}get areaNames(){return[...this._areas.keys()]}async estimate(){let e=typeof navigator<`u`?navigator.storage:null;if(!e?.estimate)return{quota:1/0,usage:0};let{quota:t=1/0,usage:n=0}=await e.estimate();return{quota:t,usage:n}}async persisted(){return await globalThis.navigator?.storage?.persisted?.()===!0}async persist(){let e=await globalThis.navigator?.storage?.persist?.()===!0;return this._changed(null),e}async budget(){if(this._budget!==null)return this._budget;let{quota:e}=await this.estimate();return Math.min(e*.3,v)}setBudget(e){this._budget=e===null?null:Math.max(0,e),this._changed(null)}async _cacheBytes(){let e=this._cacheTotal;return(!e||Date.now()-e.at>3e4)&&(e=this._cacheTotal={at:Date.now(),bytes:0,ready:null},e.ready=this._cacheEntries().then(t=>{e.bytes+=t.reduce((e,t)=>e+(t.meta.bytes??0),0)}),e.ready.catch(()=>{this._cacheTotal===e&&(this._cacheTotal=null)})),await e.ready,e.bytes}_countCacheBytes(e){this._cacheTotal&&(this._cacheTotal.bytes+=e)}async _cacheEntries(){let e=[];for(let t of this._areas.values())if(t.kind===h.CACHE)for(let n of await t.list())e.push({area:t,meta:n});return e}async usage(){let{quota:e,usage:t}=await this.estimate(),n={},r=0;for(let e of this._areas.values()){let t=await e.list(),i=t.reduce((e,t)=>e+(t.bytes??0),0);n[e.name]={kind:e.kind,bytes:i,entries:t.length},e.kind===h.CACHE&&(r+=i)}return{quota:e,usage:t,persisted:await this.persisted(),budget:await this.budget(),cacheBytes:r,areas:n}}async collect({freeBytes:e=null}={}){let t=await this._cacheEntries(),n=await this.budget(),r=this._cacheTotal={at:Date.now(),bytes:t.reduce((e,t)=>e+(t.meta.bytes??0),0),ready:null},i=e??Math.max(0,r.bytes-n);if(i<=0)return 0;let a=await s(),o=t.filter(({area:e,meta:t})=>!t.pinned&&!a.has(e._lockName(t.id))).sort((e,t)=>e.meta.lastUsed-t.meta.lastUsed),c=0;for(let{area:e,meta:t}of o){if(c>=i)break;await e.removeById(t.id)&&(c+=t.bytes??0,r.bytes-=t.bytes??0)}return c}async ensureSpace(e,t=h.CACHE){let n=async()=>{let{quota:n,usage:r}=await this.estimate(),i=e+y-(n-r);return t===h.CACHE?{free:i,budget:await this._cacheBytes()+e-await this.budget()}:{free:i,budget:0}},r=await n();return r.free<=0&&r.budget<=0?!0:(await this.collect({freeBytes:Math.max(r.free,r.budget)}),(await n()).free<=0)}async sweep(){let e=0;for(let t of this._areas.values())e+=await t.sweep(),t.kind===h.SCRATCH&&(e+=await t.clear());return e}_changed(e){this.dispatchEvent({type:`change`,area:e})}_issue(e,t,n={}){this.dispatchEvent({type:`issue`,code:e,message:t,detail:n})}_writeFailed(t,n){let r=n?.name===`QuotaExceededError`;this._issue(r?e.STORAGE_QUOTA_EXCEEDED:e.STORAGE_WRITE_FAILED,`${t}: ${n?.message??n}`,{area:t,error:n?.name})}dispose(){this._transport?.dispose(),this._transport=null,this._areas.clear()}};function k({namespace:e,root:t}){let n=new m(t);n.inline=!0;let r=new O({root:t,transport:n,namespace:e});return r.sweep().catch(()=>{}),r}const A=Object.freeze({IMMUTABLE:`immutable`,REVALIDATE:`revalidate`,NETWORK:`network`}),j=(e,t)=>({loaded:e,total:t,lengthComputable:t>0&&e<=t}),M=(e,t)=>e.headers?.get?.(t)??null,N=e=>e.reason??new DOMException(`aborted`,`AbortError`);function P(e){try{let t=new URL(e,globalThis.location?.href??`http://localhost/`).pathname;return decodeURIComponent(t.split(`/`).pop())||`download`}catch{return`download`}}async function F(e,{onProgress:t,signal:n}){let r=Number(M(e,`content-length`))||0,i=M(e,`content-type`)??``;if(!e.body)return new Blob([await e.arrayBuffer()],{type:i});let a=e.body.getReader(),o=[],s=0;for(;;){if(n?.aborted)throw a.cancel().catch(()=>{}),N(n);let{done:e,value:i}=await a.read();if(e)break;o.push(i),s+=i.length,t?.(j(s,r))}return new Blob(o,{type:i})}const I=(e,t,n)=>new File([e],t,{type:n||e.type,lastModified:e.lastModified??Date.now()}),L=()=>{};var R=class{constructor(e){this._storage=e,this._revalidating=new Set}get _area(){return this._storage?.area(g.DOWNLOADS)??null}async fetch(e,{key:t=e,name:n=P(e),policy:r=A.REVALIDATE,maxAgeMs:i=864e5,onProgress:a=null,signal:o=null,fetchOptions:s={}}={}){let c=this._area;if(c&&r!==A.NETWORK){let o=await c.open(t);if(o){let c=await o.file(`data`);if(c)return r===A.REVALIDATE&&Date.now()-(o.extra.checkedAt??0)>=i&&this._revalidate(e,t,n,o.extra,s),a?.(j(c.size,c.size)),{file:I(c,n,o.extra.contentType),release:()=>o.release(),fromCache:!0};o.release()}}return this._download(e,t,n,{onProgress:a,signal:o,fetchOptions:s,cache:!!c})}async has(e){return await this._area?.has(e)===!0}async _download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:o}){if(i?.aborted)throw N(i);let s=await fetch(e,{...a,signal:i});if(!s.ok)throw Error(`HTTP ${s.status} fetching ${e}`);let c=Number(M(s,`content-length`))||0,l={url:e,contentType:M(s,`content-type`)??``,lastModified:M(s,`last-modified`),contentLength:c||null,checkedAt:Date.now()},u=o&&s.body?await this._area.create(t,{label:n,expectedBytes:c}):null;if(!u)return{file:I(await F(s,{onProgress:r,signal:i}),n,l.contentType),release:L,fromCache:!1};try{await u.writeStream(`data`,s.body,{signal:i,onProgress:e=>r?.(j(e,c))}),await u.commit(l)}catch(o){if(await u.abort(),o?.name!==`QuotaExceededError`)throw o;return this._download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:!1})}let d=await this._area.open(t,{wait:!0}),f=d&&await d.file(`data`);if(!f)throw d?.release(),Error(`storage: ${n} vanished right after it was saved`);return{file:I(f,n,l.contentType),release:()=>d.release(),fromCache:!1}}async _revalidate(e,t,n,r,i){if(this._revalidating.has(t))return;this._revalidating.add(t);let a=!1;try{let t=new Headers(i?.headers);t.set(`Range`,`bytes=0-0`);let n=await fetch(e,{...i,headers:t});if(n.body?.cancel().catch(()=>{}),n.ok){let e=M(n,`last-modified`),t=n.status===206?Number(M(n,`content-range`)?.match(/\\/(\\d+)$/)?.[1])||null:Number(M(n,`content-length`))||null;a=!!(e&&r.lastModified&&e!==r.lastModified||t&&r.contentLength&&t!==r.contentLength)}}catch{}try{if(a){let{release:r}=await this._download(e,t,n,{fetchOptions:i,cache:!0});r()}else await this._area.patchMeta(t,{extra:{...r,checkedAt:Date.now()}})}catch{}finally{this._revalidating.delete(t)}}};let z={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`,storage:`auto`},B=null;async function V(){return B||(B=await import(z.ortRuntimeUrl),B.env.wasm.wasmPaths=z.ortWasmPaths,B.env.logLevel=`error`,B)}let H=null,U=null,W=null;function G(){return W??=(async()=>{if(z.storage===!1||!navigator.storage?.getDirectory)return new R(null);try{let e=await(await navigator.storage.getDirectory()).getDirectoryHandle(z.cacheNamespace,{create:!0}),t=k({namespace:z.cacheNamespace,root:e});return await K(t).catch(()=>{}),new R(t)}catch{return new R(null)}})(),W}async function K(e){let t=`${z.cacheNamespace}:ai-upscaler-models`;if(typeof indexedDB>`u`||!indexedDB.databases||!(await indexedDB.databases()).some(e=>e.name===t))return;let n=await new Promise((e,n)=>{let r=indexedDB.open(t);r.onerror=()=>n(r.error),r.onsuccess=()=>{let t=r.result;if(!t.objectStoreNames.contains(`models`)){t.close(),e([]);return}let i=[],a=t.transaction(`models`,`readonly`).objectStore(`models`).openCursor();a.onerror=()=>n(a.error),a.onsuccess=()=>{let n=a.result;if(!n){t.close(),e(i);return}i.push([n.key,n.value]),n.continue()}}}),r=e.area(`downloads`);for(let[e,t]of n){if(typeof e!=`string`||!(t instanceof ArrayBuffer)||await r.has(e))continue;let n=await r.create(e,{label:e.split(`/`).pop(),expectedBytes:t.byteLength});n&&(await n.write(`data`,t,{transfer:!0}),await n.commit({url:e,contentType:`application/octet-stream`,checkedAt:Date.now()}))}await new Promise(e=>{let n=indexedDB.deleteDatabase(t);n.onsuccess=n.onerror=n.onblocked=()=>e()})}async function q(e){let{file:t,release:n,fromCache:r}=await(await G()).fetch(e);try{let e=await t.arrayBuffer();return r&&console.log(`AI Upscaler Worker: model loaded from cache (${(e.byteLength/1024/1024).toFixed(1)}MB)`),e}finally{n()}}async function J(e,t){if(H&&U===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}H&&=(await H.release(),null);let[n,r]=await Promise.all([q(e),V()]);H=await r.InferenceSession.create(n,t),U=e;let i=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);i=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${i}`)}catch{}let a=(n.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${a}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:i})}async function Y(e,t,n,r){let i=await V(),a=H.inputNames[0],o=H.outputNames[0],s=new i.Tensor(`float32`,e,[1,3,n,t]),c=(await H.run({[a]:s}))[o].data;self.postMessage({type:`inferred`,outputData:c,id:r},[c.buffer])}self.onmessage=async e=>{let{type:t}=e.data;try{t===`load`?(e.data.ortRuntimeUrl&&(z.ortRuntimeUrl=e.data.ortRuntimeUrl),e.data.ortWasmPaths&&(z.ortWasmPaths=e.data.ortWasmPaths),e.data.cacheNamespace&&(z.cacheNamespace=e.data.cacheNamespace),e.data.storage!==void 0&&(z.storage=e.data.storage),await J(e.data.url,e.data.sessionOptions)):t===`infer`?await Y(e.data.tileData,e.data.width,e.data.height,e.data.id):t===`dispose`&&H&&(await H.release(),H=null,U=null)}catch(t){self.postMessage({type:`error`,message:t.message,id:e.data?.id})}};", ms = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", ps], { type: "text/javascript;charset=utf-8" });
3799
+ function hs(e) {
3789
3800
  let t;
3790
3801
  try {
3791
- if (t = ls && (self.URL || self.webkitURL).createObjectURL(ls), !t) throw "";
3802
+ if (t = ms && (self.URL || self.webkitURL).createObjectURL(ms), !t) throw "";
3792
3803
  let n = new Worker(t, {
3793
3804
  type: "module",
3794
3805
  name: e?.name
@@ -3797,7 +3808,7 @@ function us(e) {
3797
3808
  (self.URL || self.webkitURL).revokeObjectURL(t);
3798
3809
  }), n;
3799
3810
  } catch {
3800
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(cs), {
3811
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(ps), {
3801
3812
  type: "module",
3802
3813
  name: e?.name
3803
3814
  });
@@ -3805,7 +3816,7 @@ function us(e) {
3805
3816
  }
3806
3817
  //#endregion
3807
3818
  //#region src/Passes/AIUpscaler.js
3808
- var ds = {
3819
+ var gs = {
3809
3820
  fast: {
3810
3821
  2: "2x-spanx2-ch48.onnx",
3811
3822
  4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
@@ -3819,17 +3830,17 @@ var ds = {
3819
3830
  4: "4xNomos2_hq_mosr_fp32.onnx"
3820
3831
  }
3821
3832
  };
3822
- function fs() {
3833
+ function _s() {
3823
3834
  let { upscalerModelBaseUrl: e } = it(), t = {};
3824
- for (let n in ds) {
3835
+ for (let n in gs) {
3825
3836
  t[n] = {};
3826
- for (let r in ds[n]) t[n][r] = e + ds[n][r];
3837
+ for (let r in gs[n]) t[n][r] = e + gs[n][r];
3827
3838
  }
3828
3839
  return t;
3829
3840
  }
3830
- var ps = {
3841
+ var vs = {
3831
3842
  get QUALITY_PRESETS() {
3832
- return fs();
3843
+ return _s();
3833
3844
  },
3834
3845
  TILE_SIZE: 512,
3835
3846
  TILE_OVERLAP: 16,
@@ -3840,17 +3851,17 @@ var ps = {
3840
3851
  }],
3841
3852
  graphOptimizationLevel: "all"
3842
3853
  }
3843
- }, ms = class extends ur {
3854
+ }, ys = class extends ur {
3844
3855
  constructor(e, t, n = {}) {
3845
3856
  if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
3846
- this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => $n), this.getSaturation = n.getSaturation || (() => 1), this.getDisplayGain = n.getDisplayGain || (() => null), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize || ps.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
3857
+ this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => $n), this.getSaturation = n.getSaturation || (() => 1), this.getDisplayGain = n.getDisplayGain || (() => null), this.getTransparentBackground = n.getTransparentBackground || (() => !1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize || vs.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
3847
3858
  isUpscaling: !1,
3848
3859
  isLoading: !1,
3849
3860
  abortController: null
3850
3861
  }, this._worker = null, this._currentModelUrl = null, this._tileId = 0, this._pendingWorkerHandlers = /* @__PURE__ */ new Map(), this._upscaledAlpha = null, this._upscaledAlphaWidth = 0, this._backupCanvas = null, this._baseWidth = e.width, this._baseHeight = e.height, this._toneMapper = null;
3851
3862
  }
3852
3863
  async _ensureSession() {
3853
- let e = ps.QUALITY_PRESETS[this.quality];
3864
+ let e = vs.QUALITY_PRESETS[this.quality];
3854
3865
  if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
3855
3866
  let t = e[this.scaleFactor];
3856
3867
  if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
@@ -3860,14 +3871,14 @@ var ps = {
3860
3871
  message: `Loading ${this.scaleFactor}x upscale model...`
3861
3872
  });
3862
3873
  try {
3863
- this._worker ||= new us(), await new Promise((e, n) => {
3874
+ this._worker ||= new hs(), await new Promise((e, n) => {
3864
3875
  let r = (t) => {
3865
3876
  t.data.type === "loaded" ? (this._worker.removeEventListener("message", r), t.data.tileSize && !this._tileSizeOverride && (this.tileSize = t.data.tileSize), console.log(`AI Upscaler: ${this.scaleFactor}x model loaded, backend: ${t.data.backend}, tileSize: ${this.tileSize}`), e()) : t.data.type === "error" && (this._worker.removeEventListener("message", r), n(Error(t.data.message)));
3866
3877
  }, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o, storage: s } = it();
3867
3878
  this._worker.addEventListener("message", r), this._worker.postMessage({
3868
3879
  type: "load",
3869
3880
  url: t,
3870
- sessionOptions: ps.SESSION_OPTIONS,
3881
+ sessionOptions: vs.SESSION_OPTIONS,
3871
3882
  ortRuntimeUrl: i,
3872
3883
  ortWasmPaths: a,
3873
3884
  cacheNamespace: o,
@@ -3942,7 +3953,7 @@ var ps = {
3942
3953
  alpha: !0
3943
3954
  });
3944
3955
  this._cacheUpscaledAlpha(t, n * i, r * i);
3945
- let o = ps.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
3956
+ let o = vs.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
3946
3957
  for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
3947
3958
  if (e.aborted) throw new DOMException("Aborted", "AbortError");
3948
3959
  let l = Math.min(u * c, Math.max(0, n - s)), p = Math.min(o * c, Math.max(0, r - s)), m = Math.min(s, n - l), h = Math.min(s, r - p), g = this._extractTile(t, l, p, m, h), _ = await this._inferTile(g, m, h), v = l * i, y = p * i, b = m * i, x = h * i, S = this._tensorToImageData(_, b, x, v, y);
@@ -3993,7 +4004,7 @@ var ps = {
3993
4004
  saturation: this.getSaturation(),
3994
4005
  gain: this.getDisplayGain()
3995
4006
  });
3996
- return this._toneMapper.release(), {
4007
+ return this._toneMapper.release(), this.getTransparentBackground() || i.fill(1, 3 * n * r), {
3997
4008
  planes: i,
3998
4009
  width: n,
3999
4010
  height: r,
@@ -4085,7 +4096,7 @@ var ps = {
4085
4096
  this.hdr = !!e;
4086
4097
  }
4087
4098
  setQuality(e) {
4088
- if (!ps.QUALITY_PRESETS[e]) {
4099
+ if (!vs.QUALITY_PRESETS[e]) {
4089
4100
  console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
4090
4101
  return;
4091
4102
  }
@@ -4108,9 +4119,9 @@ var ps = {
4108
4119
  async dispose() {
4109
4120
  this.abort(), this._cleanupPendingWorkerHandlers(), this._worker &&= (this._worker.postMessage({ type: "dispose" }), this._worker.terminate(), null), this._currentModelUrl = null, this._backupCanvas = null, this._upscaledAlpha = null, this.state.abortController = null, this._toneMapper?.dispose(), this._toneMapper = null, console.log("AIUpscaler disposed");
4110
4121
  }
4111
- }, hs = We("neural"), gs = 120, _s = 2, vs = 1, ys = 0, bs = 300, xs = 5, Ss = 3, Cs = 3, ws = 16, Ts = (e) => Math.max(0, 1 - e / ws), Es = class extends ur {
4122
+ }, bs = We("neural"), xs = 120, Ss = 2, Cs = 1, ws = 0, Ts = 300, Es = 5, Ds = 3, Os = 3, ks = 16, As = (e) => Math.max(0, 1 - e / ks), js = class extends ur {
4112
4123
  constructor({ renderer: e, mainCanvas: t, stages: n, pipeline: r, getExposure: i, getSaturation: a, getDisplayGain: o = null, issues: s = null }) {
4113
- super(), this.renderer = e, this._issues = s, this.mainCanvas = t, this.upscalerCanvas = this._createUpscalerCanvas(t), this.pipeline = r, this._stages = n, this._getExposure = i, this._getSaturation = a, this._getDisplayGain = o, this.denoiser = null, this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null, this.neuralRendering = !1, this.neuralRenderingSettings = {}, this._retouch = null, this._superResModule = null, this._neuralPostBusy = !1, this._postIsStillComplete = null, this._postRun = null, this._postRedo = null, this._postCancelled = !1, this._finalQuality = Qr.oidnQuality, this.finalDenoise = Qr.enableOIDN, this.continuousDenoise = Qr.continuousDenoise, this.continuousDenoiseInterval = Qr.continuousDenoiseInterval, this._lastCadenceAt = -Infinity, this._lastCadenceSamples = 0, this._failedRefreshes = 0, this._cadenceSuspended = !1, this._movingDenoiseMs = [], this._movingHopeless = !1, this._holdWhileMoving = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this.temporalHistory = Qr.oidnTemporalHistory, this._history = null, this._historyDirty = !0, this._knownResetCount = 0, this._seenTracedFrames = 0, this._viewProj = new Y(), this._historyCamera = {
4124
+ super(), this.renderer = e, this._issues = s, this.mainCanvas = t, this.upscalerCanvas = this._createUpscalerCanvas(t), this.pipeline = r, this._stages = n, this._getExposure = i, this._getSaturation = a, this._getDisplayGain = o, this.denoiser = null, this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null, this.neuralRendering = !1, this.neuralRenderingSettings = {}, this._retouch = null, this._superResModule = null, this._neuralPostBusy = !1, this._postIsStillComplete = null, this._postRun = null, this._postRedo = null, this._postCancelled = !1, this._finalQuality = $r.oidnQuality, this.finalDenoise = $r.enableOIDN, this.continuousDenoise = $r.continuousDenoise, this.continuousDenoiseInterval = $r.continuousDenoiseInterval, this._lastCadenceAt = -Infinity, this._lastCadenceSamples = 0, this._failedRefreshes = 0, this._cadenceSuspended = !1, this._movingDenoiseMs = [], this._movingHopeless = !1, this._holdWhileMoving = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this.temporalHistory = $r.oidnTemporalHistory, this._history = null, this._historyDirty = !0, this._knownResetCount = 0, this._seenTracedFrames = 0, this._viewProj = new yr(), this._historyCamera = {
4114
4125
  world: null,
4115
4126
  projInv: null,
4116
4127
  viewProj: null,
@@ -4119,7 +4130,7 @@ var ps = {
4119
4130
  count: 0,
4120
4131
  leaves: new Uint32Array(),
4121
4132
  toPrev: new Float32Array()
4122
- }, this._matA = new Y(), this._matB = new Y(), this._lastRenderWidth = 0, this._lastRenderHeight = 0, this._pendingStartUpscaler = null, this._pendingCloseDenoise = null, this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._denoiserTileHandler = null, this._denoiserErrorHandler = null, this._denoiserLoadHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null;
4133
+ }, this._matA = new yr(), this._matB = new yr(), this._lastRenderWidth = 0, this._lastRenderHeight = 0, this._pendingStartUpscaler = null, this._pendingCloseDenoise = null, this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._denoiserTileHandler = null, this._denoiserErrorHandler = null, this._denoiserLoadHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null;
4123
4134
  }
4124
4135
  _createUpscalerCanvas(e) {
4125
4136
  let t = e.parentNode;
@@ -4141,9 +4152,9 @@ var ps = {
4141
4152
  }
4142
4153
  setupDenoiser() {
4143
4154
  let e = this._stages.pathTracer;
4144
- this.denoiser = new Go(this.renderer, {
4145
- enableOIDN: Qr.enableOIDN,
4146
- oidnQuality: Qr.oidnQuality,
4155
+ this.denoiser = new Xo(this.renderer, {
4156
+ enableOIDN: $r.enableOIDN,
4157
+ oidnQuality: $r.oidnQuality,
4147
4158
  backendParams: () => ({
4148
4159
  device: this.renderer.backend.device,
4149
4160
  adapterInfo: null
@@ -4160,12 +4171,12 @@ var ps = {
4160
4171
  };
4161
4172
  }
4162
4173
  }), this._syncOIDNInUse(), this._denoiserStartHandler = (e) => this.dispatchEvent({
4163
- type: M.DENOISING_START,
4174
+ type: P.DENOISING_START,
4164
4175
  continuous: !!e.continuous
4165
4176
  }), this._denoiserEndHandler = (e) => {
4166
4177
  let t = !e.continuous || this.continuousDenoise && !this._cadenceSuspended;
4167
4178
  this.denoiser?.hasOutput && t && this._publishOutput(), this.dispatchEvent({
4168
- type: M.DENOISING_END,
4179
+ type: P.DENOISING_END,
4169
4180
  continuous: !!e.continuous
4170
4181
  });
4171
4182
  }, this._denoiserTileHandler = (e) => {
@@ -4178,7 +4189,7 @@ var ps = {
4178
4189
  asset: "oidn-weights",
4179
4190
  cause: String(e.error?.message ?? e.error)
4180
4191
  }), this.denoiser.addEventListener("start", this._denoiserStartHandler), this.denoiser.addEventListener("end", this._denoiserEndHandler), this.denoiser.addEventListener("tileProgress", this._denoiserTileHandler), this.denoiser.addEventListener("error", this._denoiserErrorHandler), this._denoiserLoadHandler = (e) => this.dispatchEvent({
4181
- type: M.DENOISER_LOADING,
4192
+ type: P.DENOISER_LOADING,
4182
4193
  loading: e.type === "loading"
4183
4194
  });
4184
4195
  for (let e of [
@@ -4187,16 +4198,16 @@ var ps = {
4187
4198
  "error"
4188
4199
  ]) this.denoiser.addEventListener(e, this._denoiserLoadHandler);
4189
4200
  this.denoiser.state?.isLoading && this.dispatchEvent({
4190
- type: M.DENOISER_LOADING,
4201
+ type: P.DENOISER_LOADING,
4191
4202
  loading: !0
4192
4203
  });
4193
4204
  }
4194
4205
  setupUpscaler() {
4195
4206
  if (!this.upscalerCanvas) return;
4196
4207
  let e = this._stages.pathTracer;
4197
- this.upscaler = new ms(this.upscalerCanvas, this.renderer, {
4198
- scaleFactor: Qr.upscalerScale || 2,
4199
- quality: Qr.upscalerQuality || "fast",
4208
+ this.upscaler = new ys(this.upscalerCanvas, this.renderer, {
4209
+ scaleFactor: $r.upscalerScale || 2,
4210
+ quality: $r.upscalerQuality || "fast",
4200
4211
  getSourceCanvas: () => this.renderer.domElement,
4201
4212
  refreshInput: () => {
4202
4213
  let e = this.pipeline?.context;
@@ -4210,22 +4221,23 @@ var ps = {
4210
4221
  getExposure: () => this._getEffectiveExposure(),
4211
4222
  getToneMapping: () => this._getToneMapping(),
4212
4223
  getSaturation: () => this._getSaturation(),
4213
- getDisplayGain: () => this._getDisplayGain?.() ?? null
4214
- }), this.upscaler.enabled = Qr.enableUpscaler || !1, this._upscalerResChangedHandler = (e) => this.dispatchEvent({
4215
- type: M.RESOLUTION_CHANGED,
4224
+ getDisplayGain: () => this._getDisplayGain?.() ?? null,
4225
+ getTransparentBackground: () => !!this._settings?.get("transparentBackground")
4226
+ }), this.upscaler.enabled = $r.enableUpscaler || !1, this._upscalerResChangedHandler = (e) => this.dispatchEvent({
4227
+ type: P.RESOLUTION_CHANGED,
4216
4228
  width: e.width,
4217
4229
  height: e.height
4218
- }), this._upscalerStartHandler = () => this.dispatchEvent({ type: M.UPSCALING_START }), this._upscalerProgressHandler = (e) => this.dispatchEvent({
4219
- type: M.UPSCALING_PROGRESS,
4230
+ }), this._upscalerStartHandler = () => this.dispatchEvent({ type: P.UPSCALING_START }), this._upscalerProgressHandler = (e) => this.dispatchEvent({
4231
+ type: P.UPSCALING_PROGRESS,
4220
4232
  progress: e.progress
4221
- }), this._upscalerEndHandler = () => this.dispatchEvent({ type: M.UPSCALING_END }), this.upscaler.addEventListener("resolution_changed", this._upscalerResChangedHandler), this.upscaler.addEventListener("start", this._upscalerStartHandler), this.upscaler.addEventListener("progress", this._upscalerProgressHandler), this.upscaler.addEventListener("end", this._upscalerEndHandler);
4233
+ }), this._upscalerEndHandler = () => this.dispatchEvent({ type: P.UPSCALING_END }), this.upscaler.addEventListener("resolution_changed", this._upscalerResChangedHandler), this.upscaler.addEventListener("start", this._upscalerStartHandler), this.upscaler.addEventListener("progress", this._upscalerProgressHandler), this.upscaler.addEventListener("end", this._upscalerEndHandler);
4222
4234
  }
4223
4235
  get denoiserStrategy() {
4224
4236
  return this.continuousDenoise ? "oidn" : this._stages.nrd?.enabled ? "nrd" : "none";
4225
4237
  }
4226
4238
  setDenoiserStrategy(e, t) {
4227
4239
  let n = this._stages;
4228
- Kr.includes(e) || (this._issues?.record(Ye.DENOISER_UNAVAILABLE, `'${e}' is not a live denoiser (${Kr.join(", ")}) — none is used`, { strategy: e }), e = "none"), e === "nrd" && this._isPanorama() && (this._issues?.record(Ye.DENOISER_UNAVAILABLE, "NRD cannot run in a panorama — oidn is used", { strategy: e }), e = "oidn"), this._clearDenoiserTextures(), n.nrd && (n.nrd.enabled = e === "nrd"), n.nrd?.enabled && (n.nrd.resetHistory?.(), this._applyNRDPreset(t || "medium")), this.setContinuousDenoise(e === "oidn");
4240
+ qr.includes(e) || (this._issues?.record(Ye.DENOISER_UNAVAILABLE, `'${e}' is not a live denoiser (${qr.join(", ")}) — none is used`, { strategy: e }), e = "none"), e === "nrd" && this._isPanorama() && (this._issues?.record(Ye.DENOISER_UNAVAILABLE, "NRD cannot run in a panorama — oidn is used", { strategy: e }), e = "oidn"), this._clearDenoiserTextures(), n.nrd && (n.nrd.enabled = e === "nrd"), n.nrd?.enabled && (n.nrd.resetHistory?.(), this._applyNRDPreset(t || "medium")), this.setContinuousDenoise(e === "oidn");
4229
4241
  }
4230
4242
  setAutoExposureEnabled(e, t) {
4231
4243
  this._stages.autoExposure?.setEnabled(e, t);
@@ -4248,8 +4260,8 @@ var ps = {
4248
4260
  get holdsWhileMoving() {
4249
4261
  if (!this._stages.pathTracer?.viewIsChanging || !this.continuousDenoise || this._cadenceSuspended || !this.denoiser?.enabled || this._movingHopeless) return !1;
4250
4262
  let e = this.movingCostMs, t = this._movingDenoiseMs.length;
4251
- e > bs * Ss && (this._movingHopeless = !0, this._syncGBufferStages());
4252
- let n = !this._movingHopeless && (t < 2 || e <= bs);
4263
+ e > Ts * Ds && (this._movingHopeless = !0, this._syncGBufferStages());
4264
+ let n = !this._movingHopeless && (t < 2 || e <= Ts);
4253
4265
  return this._holdWhileMoving = (this._holdWhileMoving === null || this._holdWhileMoving) && n, this._holdWhileMoving;
4254
4266
  }
4255
4267
  skipsTrace() {
@@ -4266,7 +4278,7 @@ var ps = {
4266
4278
  this.pipeline?.context?.removeTexture("oidn:output"), this.denoiser?.invalidateOutput();
4267
4279
  }
4268
4280
  _checkHeldFrameHealthy() {
4269
- !this.denoiser?.hasOutput || this._failedRefreshes < Cs || this._unpublishOutput();
4281
+ !this.denoiser?.hasOutput || this._failedRefreshes < Os || this._unpublishOutput();
4270
4282
  }
4271
4283
  tickContinuousDenoise(e) {
4272
4284
  let t = this.denoiser;
@@ -4276,12 +4288,12 @@ var ps = {
4276
4288
  if (!n) this._holdWhileMoving = null, this._movingDenoiseMs.length = 0;
4277
4289
  else if (!this.holdsWhileMoving) return !1;
4278
4290
  if (t.state.isDenoising || t.state.isLoading || !n && e <= this._lastCadenceSamples) return !1;
4279
- let r = performance.now(), i = n ? ys : this._lastCadenceSamples === 0 ? vs : _s, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
4291
+ let r = performance.now(), i = n ? ws : this._lastCadenceSamples === 0 ? Cs : Ss, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
4280
4292
  if (r - this._lastCadenceAt < a) return !1;
4281
- this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > gs && (this._cadenceDowngraded = !0);
4293
+ this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > xs && (this._cadenceDowngraded = !0);
4282
4294
  let o = this._cadenceDowngraded ? this.previewQuality() : this._finalQuality;
4283
4295
  return t.quality !== o && t.updateQuality(o), t.start({ continuous: !0 }).then((e) => {
4284
- this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > xs && this._movingDenoiseMs.shift());
4296
+ this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > Es && this._movingDenoiseMs.shift());
4285
4297
  }), !0;
4286
4298
  }
4287
4299
  previewQuality() {
@@ -4325,7 +4337,7 @@ var ps = {
4325
4337
  r && (this._ensureHistory().merge(r, t.frameCount, this._historyCameraNow(), {
4326
4338
  commit: !0,
4327
4339
  keepHistory: !this._historyDirty && !n,
4328
- historyScale: Ts(t.frameCount)
4340
+ historyScale: As(t.frameCount)
4329
4341
  }), this._historyDirty = !1);
4330
4342
  }
4331
4343
  afterReset() {
@@ -4367,9 +4379,9 @@ var ps = {
4367
4379
  let e = this._stages.pathTracer, t = this._history;
4368
4380
  if (!t?.valid || this._historyDirty || !this.historyActive || e.isComplete || e.resetCount !== this._knownResetCount || t.width !== this._lastRenderWidth || t.height !== this._lastRenderHeight) return null;
4369
4381
  if (e.frameCount <= 1) return t.textures;
4370
- if (e.frameCount >= ws) return null;
4382
+ if (e.frameCount >= ks) return null;
4371
4383
  let n = this._historyInputs();
4372
- return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Ts(e.frameCount) }) : null;
4384
+ return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: As(e.frameCount) }) : null;
4373
4385
  }
4374
4386
  _historyInputs() {
4375
4387
  let e = this._stages.pathTracer, t = this.pipeline?.context, n = this.renderer?.backend;
@@ -4394,7 +4406,7 @@ var ps = {
4394
4406
  return t.world = e.cameraWorldMatrix.value.elements, t.projInv = e.cameraProjectionMatrixInverse.value.elements, t.viewProj = this._viewProj.elements, t.orthographic = e.uniforms?.get("cameraProjection")?.value === Oe.orthographic, t;
4395
4407
  }
4396
4408
  _ensureHistory() {
4397
- return this._history ??= new ss(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
4409
+ return this._history ??= new fs(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
4398
4410
  }
4399
4411
  _releaseHistory() {
4400
4412
  this._history?.dispose(), this._history = null, this._historyDirty = !0, this._movedPlacements.clear();
@@ -4406,7 +4418,7 @@ var ps = {
4406
4418
  _restoreRenderDisplay() {
4407
4419
  let e = this.upscalerCanvas && this.upscalerCanvas.style.display !== "none";
4408
4420
  return this.upscalerCanvas && (this.upscalerCanvas.style.display = "none"), this.mainCanvas && (this.mainCanvas.style.opacity = "1"), e && this._lastRenderWidth && this._lastRenderHeight && this.dispatchEvent({
4409
- type: M.RESOLUTION_CHANGED,
4421
+ type: P.RESOLUTION_CHANGED,
4410
4422
  width: this._lastRenderWidth,
4411
4423
  height: this._lastRenderHeight
4412
4424
  }), !!e;
@@ -4432,15 +4444,15 @@ var ps = {
4432
4444
  return;
4433
4445
  }
4434
4446
  if (!this.pipeline?.context?.getTexture("oidn:output")) {
4435
- hs.warn("neural pass skipped: no denoised picture — it needs OIDN");
4447
+ bs.warn("neural pass skipped: no denoised picture — it needs OIDN");
4436
4448
  return;
4437
4449
  }
4438
- this._neuralPostBusy = !0, this.dispatchEvent({ type: M.UPSCALING_START });
4450
+ this._neuralPostBusy = !0, this.dispatchEvent({ type: P.UPSCALING_START });
4439
4451
  try {
4440
- let i = await import("./NeuralSuperRes-WNEXun9s.js").then((e) => e.t);
4452
+ let i = await import("./NeuralSuperRes-C4ymq68e.js").then((e) => e.t);
4441
4453
  this._superResModule = i;
4442
- let a = n ? await import("./NeuralRetouch-ClaMiKYg.js").then((e) => e.t) : null, o = this.denoiser?._outTexSize, s = (o?.width ?? 0) * (o?.height ?? 0), c = n && s <= a.RETOUCH_MAX_PIXELS;
4443
- if (n && !c && (hs.warn(`Neural rendering skipped: the render is ${(s / 1e6).toFixed(1)} MP, above the ${(a.RETOUCH_MAX_PIXELS / 1e6).toFixed(1)} MP the pass survives.` + (t ? " The upscale still ran." : "")), this._releaseNeuralRetouch()), !t && !c) {
4454
+ let a = n ? await import("./NeuralRetouch-BKQCsmEs.js").then((e) => e.t) : null, o = this.denoiser?._outTexSize, s = (o?.width ?? 0) * (o?.height ?? 0), c = n && s <= a.RETOUCH_MAX_PIXELS;
4455
+ if (n && !c && (bs.warn(`Neural rendering skipped: the render is ${(s / 1e6).toFixed(1)} MP, above the ${(a.RETOUCH_MAX_PIXELS / 1e6).toFixed(1)} MP the pass survives.` + (t ? " The upscale still ran." : "")), this._releaseNeuralRetouch()), !t && !c) {
4444
4456
  r && !this._postCancelled && await this.upscaler.start();
4445
4457
  return;
4446
4458
  }
@@ -4479,14 +4491,14 @@ var ps = {
4479
4491
  return;
4480
4492
  }
4481
4493
  this.mainCanvas && (this.mainCanvas.style.opacity = "0"), this.dispatchEvent({
4482
- type: M.RESOLUTION_CHANGED,
4494
+ type: P.RESOLUTION_CHANGED,
4483
4495
  width: d.width,
4484
4496
  height: d.height
4485
4497
  });
4486
4498
  } catch (e) {
4487
- hs.warn("neural pass failed", e);
4499
+ bs.warn("neural pass failed", e);
4488
4500
  } finally {
4489
- this._neuralPostBusy = !1, this.dispatchEvent({ type: M.UPSCALING_END });
4501
+ this._neuralPostBusy = !1, this.dispatchEvent({ type: P.UPSCALING_END });
4490
4502
  }
4491
4503
  }
4492
4504
  }
@@ -4512,7 +4524,7 @@ var ps = {
4512
4524
  }));
4513
4525
  }
4514
4526
  cancelPostPasses() {
4515
- this._postCancelled = !0, this.upscaler?.abort(), this._restoreRenderDisplay(), this.dispatchEvent({ type: M.UPSCALING_END });
4527
+ this._postCancelled = !0, this.upscaler?.abort(), this._restoreRenderDisplay(), this.dispatchEvent({ type: P.UPSCALING_END });
4516
4528
  }
4517
4529
  onRenderComplete({ isStillComplete: e }) {
4518
4530
  this._cleanupCompletionListener(), this._postIsStillComplete = null;
@@ -4550,7 +4562,7 @@ var ps = {
4550
4562
  "error"
4551
4563
  ]) this.denoiser.removeEventListener(e, this._denoiserLoadHandler);
4552
4564
  this.denoiser.state?.isLoading && this.dispatchEvent({
4553
- type: M.DENOISER_LOADING,
4565
+ type: P.DENOISER_LOADING,
4554
4566
  loading: !1
4555
4567
  });
4556
4568
  }
@@ -4637,16 +4649,16 @@ var ps = {
4637
4649
  e && (e.removeTexture("nrd:output"), e.removeTexture("oidn:output"));
4638
4650
  }
4639
4651
  _applyNRDPreset(e) {
4640
- let t = Zr[e];
4652
+ let t = Qr[e];
4641
4653
  if (!t) return;
4642
4654
  let n = {};
4643
- for (let e of Xr) n[e] = Yr[e];
4655
+ for (let e of Zr) n[e] = Xr[e];
4644
4656
  this._stages.nrd?.updateParameters({
4645
4657
  ...n,
4646
4658
  ...t
4647
4659
  });
4648
4660
  }
4649
- }, Ds = class {
4661
+ }, Ms = class {
4650
4662
  constructor() {
4651
4663
  this.layer = "hud", this.visible = !1, this._tileBounds = null, this._imageWidth = 1, this._imageHeight = 1, this.enabled = !0, this._borderColor = "rgba(255, 0, 0, 0.6)", this._borderWidthRatio = 1 / 540, this._borderWidthMin = 1.5, this._borderWidthMax = 4;
4652
4664
  }
@@ -4670,18 +4682,18 @@ var ps = {
4670
4682
  dispose() {
4671
4683
  this.visible = !1;
4672
4684
  }
4673
- }, Os = class {
4685
+ }, Ns = class {
4674
4686
  constructor(e, t) {
4675
4687
  this.layer = "scene", this._enabled = !0, this._scene = e, this._camera = t, this._build([]);
4676
4688
  }
4677
4689
  _build(e) {
4678
- this._orthographic = this._camera.isOrthographicCamera === !0, this._outlineNode = Vr(this._scene, this._camera, {
4690
+ this._orthographic = this._camera.isOrthographicCamera === !0, this._outlineNode = Hr(this._scene, this._camera, {
4679
4691
  selectedObjects: e,
4680
- edgeThickness: G(1),
4681
- edgeGlow: G(0)
4692
+ edgeThickness: q(1),
4693
+ edgeGlow: q(0)
4682
4694
  });
4683
- let t = G(3), n = G(new ar(16777215)), r = G(new ar(1640965)), { visibleEdge: i, hiddenEdge: a } = this._outlineNode, o = i.mul(n).add(a.mul(r)).mul(t), s = o.r.max(o.g).max(o.b).clamp(0, 1);
4684
- this._material = new vn(), this._material.colorNode = q(o, s), this._material.transparent = !0, this._material.blending = sr, this._material.blendEquation = er, this._material.blendSrc = Cr, this._material.blendDst = Cr, this._material.blendEquationAlpha = er, this._material.blendSrcAlpha = Cr, this._material.blendDstAlpha = Cr, this._material.toneMapped = !1, this._material.depthTest = !1, this._material.depthWrite = !1, this._quad = new yn(this._material);
4695
+ let t = q(3), n = q(new ar(16777215)), r = q(new ar(1640965)), { visibleEdge: i, hiddenEdge: a } = this._outlineNode, o = i.mul(n).add(a.mul(r)).mul(t), s = o.r.max(o.g).max(o.b).clamp(0, 1);
4696
+ this._material = new vn(), this._material.colorNode = Y(o, s), this._material.transparent = !0, this._material.blending = sr, this._material.blendEquation = er, this._material.blendSrc = wr, this._material.blendDst = wr, this._material.blendEquationAlpha = er, this._material.blendSrcAlpha = wr, this._material.blendDstAlpha = wr, this._material.toneMapped = !1, this._material.depthTest = !1, this._material.depthWrite = !1, this._quad = new yn(this._material);
4685
4697
  }
4686
4698
  setSelectedObjects(e) {
4687
4699
  this._outlineNode.selectedObjects = e;
@@ -4708,11 +4720,11 @@ var ps = {
4708
4720
  this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
4709
4721
  }
4710
4722
  };
4711
- function ks(e = !1) {
4723
+ function Ps(e = !1) {
4712
4724
  let t = document.createElement("canvas");
4713
4725
  return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
4714
4726
  }
4715
- function As(e, t = Infinity) {
4727
+ function Fs(e, t = Infinity) {
4716
4728
  let n = e?.getBoundingClientRect();
4717
4729
  if (!n || n.width === 0 || n.height === 0) return null;
4718
4730
  let r = Math.min(window.devicePixelRatio || 1, 2), i = Math.round(n.width * r), a = Math.round(n.height * r), o = t / Math.max(i, a);
@@ -4723,9 +4735,9 @@ function As(e, t = Infinity) {
4723
4735
  }
4724
4736
  //#endregion
4725
4737
  //#region src/managers/helpers/ViewOverlayRenderer.js
4726
- var js = 4096, Ms = class {
4738
+ var Is = 4096, Ls = class {
4727
4739
  constructor() {
4728
- this.canvas = ks(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
4740
+ this.canvas = Ps(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
4729
4741
  }
4730
4742
  async init({ device: e, sizeSource: t }) {
4731
4743
  this._sizeSource = t;
@@ -4735,14 +4747,14 @@ var js = 4096, Ms = class {
4735
4747
  alpha: !0,
4736
4748
  antialias: (window.devicePixelRatio || 1) < 2
4737
4749
  });
4738
- return await r.init(), e.onuncapturederror = n, r.outputColorSpace = jr, r.setPixelRatio(1), r.setClearColor(0, 0), r.autoClear = !1, this.renderer = r, this.syncSize(), this;
4750
+ return await r.init(), e.onuncapturederror = n, r.outputColorSpace = Mr, r.setPixelRatio(1), r.setClearColor(0, 0), r.autoClear = !1, this.renderer = r, this.syncSize(), this;
4739
4751
  }
4740
4752
  get isVisible() {
4741
4753
  return this._visible;
4742
4754
  }
4743
4755
  syncSize() {
4744
4756
  if (!this.renderer) return;
4745
- let e = As(this._sizeSource, js);
4757
+ let e = Fs(this._sizeSource, Is);
4746
4758
  !e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
4747
4759
  }
4748
4760
  begin() {
@@ -4754,18 +4766,18 @@ var js = 4096, Ms = class {
4754
4766
  dispose() {
4755
4767
  Me(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
4756
4768
  }
4757
- }, Ns = We("overlay"), Ps = (e, t) => e.visible && e.layer === t && e.render, Fs = class {
4769
+ }, Rs = We("overlay"), zs = (e, t) => e.visible && e.layer === t && e.render, Bs = class {
4758
4770
  constructor(e) {
4759
- this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = ks(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
4771
+ this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = Ps(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
4760
4772
  }
4761
4773
  async initViewRenderer({ device: e, sizeSource: t }) {
4762
4774
  if (!(!e || !t)) try {
4763
- this._viewOverlay = await new Ms().init({
4775
+ this._viewOverlay = await new Ls().init({
4764
4776
  device: e,
4765
4777
  sizeSource: t
4766
4778
  });
4767
4779
  } catch (e) {
4768
- Ns.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
4780
+ Rs.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
4769
4781
  }
4770
4782
  }
4771
4783
  gpuResources() {
@@ -4785,11 +4797,11 @@ var js = 4096, Ms = class {
4785
4797
  }
4786
4798
  setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
4787
4799
  this.setHelperScene(e);
4788
- let s = new Ds();
4789
- this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(M.RESOLUTION_CHANGED, (e) => {
4800
+ let s = new Ms();
4801
+ this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(P.RESOLUTION_CHANGED, (e) => {
4790
4802
  s.setRenderSize(e.width, e.height);
4791
4803
  }), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
4792
- let c = new Os(t, this.camera);
4804
+ let c = new Ns(t, this.camera);
4793
4805
  this.register("outline", c);
4794
4806
  }
4795
4807
  _wireDenoiserTileEvents(e, t) {
@@ -4801,7 +4813,7 @@ var js = 4096, Ms = class {
4801
4813
  }));
4802
4814
  }
4803
4815
  register(e, t) {
4804
- this._helpers.has(e) && (Ns.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
4816
+ this._helpers.has(e) && (Rs.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
4805
4817
  }
4806
4818
  unregister(e) {
4807
4819
  let t = this._helpers.get(e);
@@ -4839,16 +4851,16 @@ var js = 4096, Ms = class {
4839
4851
  }
4840
4852
  _renderSceneLayer(e) {
4841
4853
  this._helperScene?.render(e, this.camera);
4842
- for (let t of this._helpers.values()) Ps(t, "scene") && t.render(e, this.camera);
4854
+ for (let t of this._helpers.values()) zs(t, "scene") && t.render(e, this.camera);
4843
4855
  }
4844
4856
  _hasVisibleSceneOverlay() {
4845
4857
  if (this._helperScene?.isDrawing) return !0;
4846
- for (let e of this._helpers.values()) if (Ps(e, "scene")) return !0;
4858
+ for (let e of this._helpers.values()) if (zs(e, "scene")) return !0;
4847
4859
  return !1;
4848
4860
  }
4849
4861
  refreshHUD() {
4850
4862
  let e = this._hudCanvas, t = this._hudCtx, n = !1;
4851
- for (let e of this._helpers.values()) if (Ps(e, "hud")) {
4863
+ for (let e of this._helpers.values()) if (zs(e, "hud")) {
4852
4864
  n = !0;
4853
4865
  break;
4854
4866
  }
@@ -4857,10 +4869,10 @@ var js = 4096, Ms = class {
4857
4869
  return;
4858
4870
  }
4859
4871
  e.style.display !== "" && (e.style.display = "");
4860
- let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? As(e) : null;
4872
+ let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Fs(e) : null;
4861
4873
  if (a) {
4862
4874
  (e.width !== a.width || e.height !== a.height) && (e.width = a.width, e.height = a.height), t.clearRect(0, 0, a.width, a.height), t.save(), t.scale(a.width / r, a.height / i);
4863
- for (let e of this._helpers.values()) Ps(e, "hud") && e.render(t, r, i);
4875
+ for (let e of this._helpers.values()) zs(e, "hud") && e.render(t, r, i);
4864
4876
  t.restore(), e.style.display !== "" && (e.style.display = "");
4865
4877
  }
4866
4878
  }
@@ -4871,7 +4883,7 @@ var js = 4096, Ms = class {
4871
4883
  };
4872
4884
  //#endregion
4873
4885
  //#region src/managers/AnimationManager.js
4874
- function Is(e, t) {
4886
+ function Vs(e, t) {
4875
4887
  let n = [...e].filter((t) => {
4876
4888
  for (let n = t.parent; n; n = n.parent) if (e.has(n)) return !1;
4877
4889
  return !0;
@@ -4880,9 +4892,9 @@ function Is(e, t) {
4880
4892
  for (let e of n) e.traverse?.(() => i++);
4881
4893
  return i + n.length / 2 < r ? n : null;
4882
4894
  }
4883
- var Ls = class extends ur {
4895
+ var Hs = class extends ur {
4884
4896
  constructor() {
4885
- super(), this.mixer = null, this.timer = new Pr(), this.actions = [], this.isPlaying = !1, this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._meshPositions = null, this._tempVec = new Z(), this._skinnedCache = null, this._clipsCache = null, this._savedTimeScale = 1, this.onFinished = null, this._rigid = !1, this._plans = null, this._allPlan = null, this._activeClip = 0, this._slotOf = null, this._lastWorld = null, this._lastVisible = null, this._lastMeshWorld = null, this._lastMorphWeights = null, this.wakeCallback = null, this.applyPoseCallback = null;
4897
+ super(), this.mixer = null, this.timer = new Fr(), this.actions = [], this.isPlaying = !1, this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._meshPositions = null, this._tempVec = new Q(), this._skinnedCache = null, this._clipsCache = null, this._savedTimeScale = 1, this.onFinished = null, this._rigid = !1, this._plans = null, this._allPlan = null, this._activeClip = 0, this._slotOf = null, this._lastWorld = null, this._lastVisible = null, this._lastMeshWorld = null, this._lastMorphWeights = null, this.wakeCallback = null, this.applyPoseCallback = null;
4886
4898
  }
4887
4899
  init(e, t, n, r) {
4888
4900
  if (this.dispose(), !r || r.length === 0) return;
@@ -4915,7 +4927,7 @@ var Ls = class extends ur {
4915
4927
  }), this._plans = e.map((e) => {
4916
4928
  let r = /* @__PURE__ */ new Set(), i = !1, a = !1;
4917
4929
  for (let o of e.tracks) {
4918
- let { nodeName: e, propertyName: s } = Er.parseTrackName(o.name), c = e === "" || e === "." ? t : n.get(e);
4930
+ let { nodeName: e, propertyName: s } = Dr.parseTrackName(o.name), c = e === "" || e === "." ? t : n.get(e);
4919
4931
  if (!c) {
4920
4932
  a = !0;
4921
4933
  continue;
@@ -4934,7 +4946,7 @@ var Ls = class extends ur {
4934
4946
  visibility: i,
4935
4947
  cameras: [...s],
4936
4948
  nodes: a ? null : r,
4937
- roots: a ? null : Is(r, t)
4949
+ roots: a ? null : Vs(r, t)
4938
4950
  };
4939
4951
  }), this._allPlan = null, !this._rigid) return;
4940
4952
  this._slotOf = new Int32Array(this._meshes.length).fill(-1);
@@ -4953,7 +4965,7 @@ var Ls = class extends ur {
4953
4965
  visibility: n,
4954
4966
  cameras: [...t],
4955
4967
  nodes: r,
4956
- roots: r ? Is(r, this._mixerRoot) : null
4968
+ roots: r ? Vs(r, this._mixerRoot) : null
4957
4969
  };
4958
4970
  }
4959
4971
  return this._allPlan;
@@ -4988,17 +5000,17 @@ var Ls = class extends ur {
4988
5000
  if (!(!this.mixer || this.actions.length === 0)) {
4989
5001
  if (this.mixer.stopAllAction(), e === -1) for (let e of this.actions) e.play();
4990
5002
  else e >= 0 && e < this.actions.length && this.actions[e].play();
4991
- this._activeClip = e, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: M.ANIMATION_STARTED });
5003
+ this._activeClip = e, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: P.ANIMATION_STARTED });
4992
5004
  }
4993
5005
  }
4994
5006
  pause() {
4995
- this.mixer && (this.mixer.timeScale = 0, this.timer.reset(), this.isPlaying = !1, this.dispatchEvent({ type: M.ANIMATION_PAUSED }));
5007
+ this.mixer && (this.mixer.timeScale = 0, this.timer.reset(), this.isPlaying = !1, this.dispatchEvent({ type: P.ANIMATION_PAUSED }));
4996
5008
  }
4997
5009
  resume() {
4998
- this.mixer && (this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: M.ANIMATION_STARTED }));
5010
+ this.mixer && (this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: P.ANIMATION_STARTED }));
4999
5011
  }
5000
5012
  stop() {
5001
- this.mixer && (this.mixer.stopAllAction(), this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !1, this._rigid && (this._mixerRoot.updateMatrixWorld(!0), this._applyRigidPose(-1)), this.dispatchEvent({ type: M.ANIMATION_STOPPED }));
5013
+ this.mixer && (this.mixer.stopAllAction(), this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !1, this._rigid && (this._mixerRoot.updateMatrixWorld(!0), this._applyRigidPose(-1)), this.dispatchEvent({ type: P.ANIMATION_STOPPED }));
5002
5014
  }
5003
5015
  setSpeed(e) {
5004
5016
  this._savedTimeScale = e, this.mixer && this.isPlaying && (this.mixer.timeScale = e);
@@ -5085,19 +5097,19 @@ var Ls = class extends ur {
5085
5097
  dispose() {
5086
5098
  this.mixer &&= (this.mixer.stopAllAction(), this.mixer.uncacheRoot(this._mixerRoot), null), this.actions = [], this.isPlaying = !1, this.timer.reset(), this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._meshPositions = null, this._skinnedCache = null, this._clipsCache = null, this._rigid = !1, this._plans = null, this._allPlan = null, this._activeClip = 0, this._slotOf = null, this._lastWorld = null, this._lastVisible = null, this._lastMeshWorld = null, this._lastMorphWeights = null;
5087
5099
  }
5088
- }, Rs = new Z(0, 0, -1), zs = (e) => {
5100
+ }, Us = new Q(0, 0, -1), Ws = (e) => {
5089
5101
  for (; e.parent;) e = e.parent;
5090
5102
  return e.isScene ? e : null;
5091
- }, Bs = class {
5103
+ }, Gs = class {
5092
5104
  constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
5093
- this._app = r, this._orbitControls = n, this._camera = e, this._controls = new Hr(e, t), this._gizmoScene = new Mr(), this._gizmoScene.add(this._controls.getHelper()), this._attached = null, this._isDragging = !1, this._meshes = null, this._refitInFlight = !1, this._baselineComputed = !1, this._moved = /* @__PURE__ */ new Set(), this._tempForward = new Z(), this._lightTargetDistance = null, this._lastLightPosition = null, this._onDraggingChanged = this._onDraggingChanged.bind(this), this._onObjectChange = this._onObjectChange.bind(this), this._controls.addEventListener("dragging-changed", this._onDraggingChanged), this._controls.addEventListener("objectChange", this._onObjectChange);
5105
+ this._app = r, this._orbitControls = n, this._camera = e, this._controls = new Ur(e, t), this._gizmoScene = new Nr(), this._gizmoScene.add(this._controls.getHelper()), this._attached = null, this._isDragging = !1, this._meshes = null, this._refitInFlight = !1, this._baselineComputed = !1, this._moved = /* @__PURE__ */ new Set(), this._tempForward = new Q(), this._lightTargetDistance = null, this._lastLightPosition = null, this._onDraggingChanged = this._onDraggingChanged.bind(this), this._onObjectChange = this._onObjectChange.bind(this), this._controls.addEventListener("dragging-changed", this._onDraggingChanged), this._controls.addEventListener("objectChange", this._onObjectChange);
5094
5106
  }
5095
5107
  setMeshData(e) {
5096
5108
  this._meshes = e;
5097
- for (let e of this._moved) zs(e) || this._moved.delete(e);
5109
+ for (let e of this._moved) Ws(e) || this._moved.delete(e);
5098
5110
  }
5099
5111
  get movedObjects() {
5100
- return [...this._moved].filter((e) => zs(e));
5112
+ return [...this._moved].filter((e) => Ws(e));
5101
5113
  }
5102
5114
  noteMoved(e) {
5103
5115
  e && !e.isLight && this._moved.add(e);
@@ -5110,7 +5122,7 @@ var Ls = class extends ur {
5110
5122
  }
5111
5123
  setMode(e) {
5112
5124
  this._controls.setMode(e), this._app?.dispatchEvent({
5113
- type: M.TRANSFORM_MODE_CHANGED,
5125
+ type: P.TRANSFORM_MODE_CHANGED,
5114
5126
  mode: e
5115
5127
  }), this._app?.refreshFrame();
5116
5128
  }
@@ -5132,7 +5144,7 @@ var Ls = class extends ur {
5132
5144
  e.autoClear = !1, e.clearDepth(), e.setRenderTarget(null), e.render(this._gizmoScene, this._camera), e.autoClear = t;
5133
5145
  }
5134
5146
  _onDraggingChanged(e) {
5135
- this._isDragging = e.value, this._orbitControls && (this._orbitControls.enabled = !e.value), e.value ? this._app.dispatchEvent({ type: M.OBJECT_TRANSFORM_START }) : (this._attached?.isLight ? this._finalizeLightTransform() : this._recomputeAndRefit(), this._app.dispatchEvent({ type: M.OBJECT_TRANSFORM_END }));
5147
+ this._isDragging = e.value, this._orbitControls && (this._orbitControls.enabled = !e.value), e.value ? this._app.dispatchEvent({ type: P.OBJECT_TRANSFORM_START }) : (this._attached?.isLight ? this._finalizeLightTransform() : this._recomputeAndRefit(), this._app.dispatchEvent({ type: P.OBJECT_TRANSFORM_END }));
5136
5148
  }
5137
5149
  _onObjectChange() {
5138
5150
  this._app.needsReset = !0, this._app.wake(), this._attached?.isLight && this._syncLightDuringDrag();
@@ -5158,7 +5170,7 @@ var Ls = class extends ur {
5158
5170
  }
5159
5171
  _syncLightAim(e) {
5160
5172
  let t = this._tempForward.copy(e.target.position).sub(e.position), n = t.length();
5161
- n > 1e-4 ? (e.quaternion.setFromUnitVectors(Rs, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
5173
+ n > 1e-4 ? (e.quaternion.setFromUnitVectors(Us, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
5162
5174
  }
5163
5175
  _recomputeAndRefit() {
5164
5176
  if (!this._meshes || this._refitInFlight || !this._attached) return;
@@ -5194,7 +5206,7 @@ var Ls = class extends ur {
5194
5206
  dispose() {
5195
5207
  this._controls.removeEventListener("dragging-changed", this._onDraggingChanged), this._controls.removeEventListener("objectChange", this._onObjectChange), this.detach(), this._gizmoScene.remove(this._controls.getHelper()), this._controls.dispose(), this._meshes = null, this._moved.clear(), this._baselineComputed = !1, this._tempForward = null, this._lightTargetDistance = null, this._lastLightPosition = null, this._app = null, this._orbitControls = null, this._camera = null, this._controls = null, this._gizmoScene = null;
5196
5208
  }
5197
- }, Vs = class {
5209
+ }, Ks = class {
5198
5210
  constructor(e) {
5199
5211
  this.layer = "scene", this._transformManager = e, this._enabled = !0;
5200
5212
  }
@@ -5213,8 +5225,8 @@ var Ls = class extends ur {
5213
5225
  dispose() {
5214
5226
  this._enabled = !1;
5215
5227
  }
5216
- }, Hs = 1, Us = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5217
- function Ws(e, t) {
5228
+ }, qs = 1, Js = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5229
+ function Ys(e, t) {
5218
5230
  let n = [];
5219
5231
  for (; e && e !== t;) {
5220
5232
  let t = e.parent;
@@ -5223,12 +5235,12 @@ function Ws(e, t) {
5223
5235
  }
5224
5236
  return e === t ? n : null;
5225
5237
  }
5226
- function Gs(e, t) {
5238
+ function Xs(e, t) {
5227
5239
  let n = e;
5228
5240
  for (let e of t) if (n = n?.children[e], !n) return null;
5229
5241
  return n;
5230
5242
  }
5231
- function Ks(e) {
5243
+ function Zs(e) {
5232
5244
  return {
5233
5245
  key: e.assetLoader?.sceneSourceKey ?? null,
5234
5246
  name: e.sceneModel?.name ?? null,
@@ -5236,7 +5248,7 @@ function Ks(e) {
5236
5248
  materials: e.stages.pathTracer?.materialData.materialCount ?? 0
5237
5249
  };
5238
5250
  }
5239
- function qs(e) {
5251
+ function Qs(e) {
5240
5252
  let t = /* @__PURE__ */ new Map();
5241
5253
  for (let n of e.sceneMeshes) {
5242
5254
  let e = n.userData?.materialIndex;
@@ -5244,7 +5256,7 @@ function qs(e) {
5244
5256
  }
5245
5257
  return t;
5246
5258
  }
5247
- function Js(e) {
5259
+ function $s(e) {
5248
5260
  if (!e) return null;
5249
5261
  let t = e.status(), n = t.activeView, r = t.config?.id ?? n?.configId ?? null;
5250
5262
  return {
@@ -5259,15 +5271,15 @@ function Js(e) {
5259
5271
  context: t.context ?? null
5260
5272
  };
5261
5273
  }
5262
- function Ys(e) {
5263
- let t = e.meshScene, n = qs(e), r = [];
5274
+ function ec(e) {
5275
+ let t = e.meshScene, n = Qs(e), r = [];
5264
5276
  return t.traverse((e) => {
5265
- e !== t && e.visible === !1 && r.push(Ws(e, t));
5277
+ e !== t && e.visible === !1 && r.push(Ys(e, t));
5266
5278
  }), {
5267
5279
  v: 1,
5268
5280
  engine: Re,
5269
5281
  savedAt: Date.now(),
5270
- scene: Ks(e),
5282
+ scene: Zs(e),
5271
5283
  appended: t.children.filter((t) => t !== e.sceneModel && t.userData?.__rayzeeSceneObject).map((e) => ({
5272
5284
  name: e.userData.__rayzeeName ?? e.name,
5273
5285
  url: e.userData.__rayzeeSourceUrl ?? null,
@@ -5275,7 +5287,7 @@ function Ys(e) {
5275
5287
  })),
5276
5288
  settings: e.settings.serialize(),
5277
5289
  environment: e.environmentManager?.serialize() ?? null,
5278
- color: Js(e.color),
5290
+ color: $s(e.color),
5279
5291
  lights: e.lightManager.serialize(),
5280
5292
  cameras: e.cameraManager.serialize(),
5281
5293
  timeline: e.timeline?.serialize() ?? null,
@@ -5285,7 +5297,7 @@ function Ys(e) {
5285
5297
  })),
5286
5298
  hidden: r,
5287
5299
  moved: (e.transformManager?.movedObjects ?? []).map((e) => ({
5288
- path: Ws(e, t),
5300
+ path: Ys(e, t),
5289
5301
  name: e.name,
5290
5302
  position: e.position.toArray(),
5291
5303
  quaternion: e.quaternion.toArray(),
@@ -5293,15 +5305,15 @@ function Ys(e) {
5293
5305
  })).filter((e) => e.path)
5294
5306
  };
5295
5307
  }
5296
- function Xs(e, t, n) {
5308
+ function tc(e, t, n) {
5297
5309
  let r = e[t];
5298
5310
  r?.copy && (n?.isColor || n?.isVector2 || n?.isVector3) ? r.copy(n) : e[t] = n, e.needsUpdate = !0;
5299
5311
  }
5300
- async function Zs(e, t, n, r) {
5312
+ async function nc(e, t, n, r) {
5301
5313
  if (!t) return;
5302
5314
  let i = e.environmentManager;
5303
5315
  if (t.hdri && t.hdri !== i.hdriSource) {
5304
- let i = Us(t.hdri) ? t.hdri : await n({
5316
+ let i = Js(t.hdri) ? t.hdri : await n({
5305
5317
  kind: "environment",
5306
5318
  source: t.hdri
5307
5319
  });
@@ -5313,7 +5325,7 @@ async function Zs(e, t, n, r) {
5313
5325
  }
5314
5326
  await i.restore(t);
5315
5327
  }
5316
- async function Qs(e, t, n, r) {
5328
+ async function rc(e, t, n, r) {
5317
5329
  let i = e.color;
5318
5330
  if (!t || !i) return;
5319
5331
  let a = i.status(), o = a.activeView, s = !!t.view && !!o && o.display === t.view.display && o.view === t.view.view && (o.look ?? null) === t.view.look, c = a.config?.id ?? null, l = c ?? o?.configId ?? null;
@@ -5338,7 +5350,7 @@ async function Qs(e, t, n, r) {
5338
5350
  r("color", e.message, { config: t.config?.id ?? null });
5339
5351
  }
5340
5352
  }
5341
- async function $s(e, t, { resolve: n = async () => null } = {}) {
5353
+ async function ic(e, t, { resolve: n = async () => null } = {}) {
5342
5354
  if (t?.v !== 1) throw Error(`scene state version ${t?.v} is not 1`);
5343
5355
  let r = [], i = (e, t, n = {}) => r.push({
5344
5356
  section: e,
@@ -5359,11 +5371,11 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5359
5371
  i("appended", e.message, { name: n.name });
5360
5372
  }
5361
5373
  }
5362
- let a = Ks(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
5374
+ let a = Zs(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
5363
5375
  s || i("scene", "the loaded scene is not the one saved: objects and materials left as loaded", {
5364
5376
  saved: o,
5365
5377
  now: a
5366
- }), await Zs(e, t.environment, n, i), await Qs(e, t.color, n, i);
5378
+ }), await nc(e, t.environment, n, i), await rc(e, t.color, n, i);
5367
5379
  let c = e.settings.restore(t.settings);
5368
5380
  c.length && i("settings", "not settings in this engine", { keys: c });
5369
5381
  let l = e.lightManager.restore(t.lights);
@@ -5372,7 +5384,7 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5372
5384
  n && e.goboManager?.entries?.length && e.goboManager.setLightGobo(t.uuid, n.name, n), r && e.iesManager?.entries?.length && e.iesManager.setSpotLightProfile(t.uuid, r.name, r.intensity, { applyAutoCone: !1 });
5373
5385
  }
5374
5386
  if (s) {
5375
- let n = qs(e);
5387
+ let n = Qs(e);
5376
5388
  for (let r of t.materials ?? []) {
5377
5389
  let t = n.get(r.index);
5378
5390
  if (!t || (t.name ?? "") !== r.name) {
@@ -5383,17 +5395,17 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5383
5395
  continue;
5384
5396
  }
5385
5397
  for (let [n, i] of Object.entries(r.props)) {
5386
- let a = ye(i);
5387
- Xs(t, n, a), e.setMaterialProperty(r.index, n, a);
5398
+ let a = le(i);
5399
+ tc(t, n, a), e.setMaterialProperty(r.index, n, a);
5388
5400
  }
5389
5401
  }
5390
- let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => Gs(r, e)).filter(Boolean));
5402
+ let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => Xs(r, e)).filter(Boolean));
5391
5403
  r.traverse((e) => {
5392
5404
  e !== r && !e.isLight && (e.visible = !a.has(e));
5393
5405
  }), e.updateAllMeshVisibility();
5394
5406
  let o = [];
5395
5407
  for (let n of t.moved ?? []) {
5396
- let t = Gs(r, n.path);
5408
+ let t = Xs(r, n.path);
5397
5409
  if (!t || t.name !== n.name) {
5398
5410
  i("moved", "no such object", { name: n.name });
5399
5411
  continue;
@@ -5415,7 +5427,7 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5415
5427
  }
5416
5428
  //#endregion
5417
5429
  //#region src/PathTracerApp.js
5418
- var ec = We("engine"), tc = class extends w {
5430
+ var ac = We("engine"), oc = class extends w {
5419
5431
  constructor(e, t = {}) {
5420
5432
  super(e, t), this.setColorManagement(Zt), this.setStorageOpener(cn), this.settings.define("interactionRenderScale", {
5421
5433
  default: .5,
@@ -5423,16 +5435,16 @@ var ec = We("engine"), tc = class extends w {
5423
5435
  this.stages?.pathTracer?.interactionMode && this._requestRenderScale(this._interactionRenderScale());
5424
5436
  },
5425
5437
  reset: !1
5426
- }), this._container = t.container || null, this._animRefitInFlight = !1, this._emittersMoved = !1, this._pendingRenderScale = null, this.cameraManager = null, this.timeline = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new Ls();
5438
+ }), this._container = t.container || null, this._animRefitInFlight = !1, this._emittersMoved = !1, this._pendingRenderScale = null, this.cameraManager = null, this.timeline = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new Hs();
5427
5439
  }
5428
5440
  _createCamera() {
5429
- return this.cameraManager = new io(this.canvas), this.timeline = new uo({
5441
+ return this.cameraManager = new lo(this.canvas), this.timeline = new go({
5430
5442
  cameraManager: this.cameraManager,
5431
5443
  onReset: () => this.reset()
5432
5444
  }), this.cameraManager.camera;
5433
5445
  }
5434
5446
  _initAssetPipeline() {
5435
- super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Et), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-DYcRXeKE.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Ct);
5447
+ super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Et), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-_sJm5uaK.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Ct);
5436
5448
  let e = () => {
5437
5449
  this.needsReset = !0, this.stages.pathTracer?.enterInteractionMode(), this.wake();
5438
5450
  };
@@ -5440,10 +5452,10 @@ var ec = We("engine"), tc = class extends w {
5440
5452
  }
5441
5453
  _createExtraStages() {
5442
5454
  let { renderer: e, stages: t } = this;
5443
- return t.normalDepth = new $r(e, { pathTracer: t.pathTracer }), t.motionVector = new ei(e, this.camera, { pathTracer: t.pathTracer }), t.nrd = new Li(e, {
5455
+ return t.normalDepth = new ei(e, { pathTracer: t.pathTracer }), t.motionVector = new ti(e, this.camera, { pathTracer: t.pathTracer }), t.nrd = new zi(e, {
5444
5456
  enabled: !1,
5445
5457
  pathTracer: t.pathTracer
5446
- }), t.autoExposure = new la(e, { enabled: Ri.autoExposure }), t.localExposure = new Aa(e, { enabled: ua.localExposure }), [
5458
+ }), t.autoExposure = new pa(e, { enabled: Bi.autoExposure }), t.localExposure = new Fa(e, { enabled: ma.localExposure }), [
5447
5459
  t.normalDepth,
5448
5460
  t.motionVector,
5449
5461
  t.nrd,
@@ -5455,7 +5467,7 @@ var ec = We("engine"), tc = class extends w {
5455
5467
  super._initPipeline(), this.pipeline.eventBus.on("pathtracer:interactionStart", () => this._requestRenderScale(this._interactionRenderScale())), this.pipeline.eventBus.on("pathtracer:interactionEnd", () => this._applyRenderScale(1));
5456
5468
  }
5457
5469
  async _initManagers() {
5458
- await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-DcjItqKi.js").then((e) => e.n).then((e) => e.PhysicalSky)), this.stages.pathTracer.registerIntegrator(["bidirectional", "vcm"], (t) => new e(t)), this.stages.pathTracer.requestOutput("gBuffer"), this.interactionManager = new Fa({
5470
+ await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-bMHbm_7H.js").then((e) => e.n).then((e) => e.PhysicalSky)), this.stages.pathTracer.registerIntegrator(["bidirectional", "vcm"], (t) => new e(t)), this.stages.pathTracer.requestOutput("gBuffer"), this.interactionManager = new Ba({
5459
5471
  scene: this.meshScene,
5460
5472
  camera: this.camera,
5461
5473
  canvas: this.canvas,
@@ -5463,18 +5475,18 @@ var ec = We("engine"), tc = class extends w {
5463
5475
  pathTracer: null,
5464
5476
  floorPlane: this.assetLoader.floorPlane,
5465
5477
  isGeometryOnDisk: () => this.geometryOnDisk
5466
- }), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new fo(this.stages.pathTracer, {
5478
+ }), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new _o(this.stages.pathTracer, {
5467
5479
  onReset: () => this.reset(),
5468
5480
  issues: this._issues
5469
- }), this.iesManager = new wo(this.stages.pathTracer, {
5481
+ }), this.iesManager = new ko(this.stages.pathTracer, {
5470
5482
  onReset: () => this.reset(),
5471
5483
  issues: this._issues
5472
- }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new Bs({
5484
+ }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new Gs({
5473
5485
  camera: this.camera,
5474
5486
  canvas: this.canvas,
5475
5487
  orbitControls: this.cameraManager.controls,
5476
5488
  app: this
5477
- }), this.overlayManager.register("transform", new Vs(this.transformManager))), this.interactionManager.setDependencies({
5489
+ }), this.overlayManager.register("transform", new Ks(this.transformManager))), this.interactionManager.setDependencies({
5478
5490
  overlayManager: this.overlayManager,
5479
5491
  transformManager: this.transformManager,
5480
5492
  appDispatch: (e) => this.dispatchEvent(e),
@@ -5483,21 +5495,21 @@ var ec = We("engine"), tc = class extends w {
5483
5495
  }), this.denoisingManager.setOverlayManager(this.overlayManager), this.denoisingManager.setResetCallback(() => this.reset()), this.denoisingManager.setPostProcessRefreshCallback(() => this.requestPostProcessRefresh()), this.denoisingManager.setDisplayRefreshCallback(() => this._presentDisplay()), this.denoisingManager.setSettings(this.settings);
5484
5496
  }
5485
5497
  _wireEvents() {
5486
- this._addTrackedListener(this.cameraManager, M.CAMERA_SWITCHED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, M.AUTO_FOCUS_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, M.ORTHO_HEIGHT_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.timeline, M.TIMELINE_CHANGED, (e) => this.dispatchEvent(e)), this._forwardEvents(this.denoisingManager, [
5487
- M.DENOISING_START,
5488
- M.DENOISING_END,
5489
- M.DENOISER_LOADING,
5490
- M.UPSCALING_START,
5491
- M.UPSCALING_PROGRESS,
5492
- M.UPSCALING_END,
5493
- M.RESOLUTION_CHANGED
5498
+ this._addTrackedListener(this.cameraManager, P.CAMERA_SWITCHED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, P.AUTO_FOCUS_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, P.ORTHO_HEIGHT_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.timeline, P.TIMELINE_CHANGED, (e) => this.dispatchEvent(e)), this._forwardEvents(this.denoisingManager, [
5499
+ P.DENOISING_START,
5500
+ P.DENOISING_END,
5501
+ P.DENOISER_LOADING,
5502
+ P.UPSCALING_START,
5503
+ P.UPSCALING_PROGRESS,
5504
+ P.UPSCALING_END,
5505
+ P.RESOLUTION_CHANGED
5494
5506
  ]), this._setupAutoExposureListener(), this.animationManager.wakeCallback = () => this.wake(), this.animationManager.applyPoseCallback = (e) => this._applyAnimationPose(e), this._forwardEvents(this.animationManager, [
5495
- M.ANIMATION_STARTED,
5496
- M.ANIMATION_PAUSED,
5497
- M.ANIMATION_STOPPED
5498
- ]), this._addTrackedListener(this.animationManager, M.ANIMATION_PAUSED, () => {
5507
+ P.ANIMATION_STARTED,
5508
+ P.ANIMATION_PAUSED,
5509
+ P.ANIMATION_STOPPED
5510
+ ]), this._addTrackedListener(this.animationManager, P.ANIMATION_PAUSED, () => {
5499
5511
  this._animRefitInFlight = !1, this._refreshMovedEmitters();
5500
- }), this._addTrackedListener(this.animationManager, M.ANIMATION_STOPPED, () => {
5512
+ }), this._addTrackedListener(this.animationManager, P.ANIMATION_STOPPED, () => {
5501
5513
  this._animRefitInFlight = !1;
5502
5514
  }), this.cameraManager.initCallbacks({
5503
5515
  onResize: () => this.onResize(),
@@ -5526,7 +5538,7 @@ var ec = We("engine"), tc = class extends w {
5526
5538
  return {
5527
5539
  ...e,
5528
5540
  applyExposure: (t) => {
5529
- this.stages.autoExposure ? this.stages.autoExposure.setCompensation(t) : e.applyExposure(t);
5541
+ this.stages.autoExposure ? this.stages.autoExposure.setCompensation(t) : e.applyExposure(t), this.stages.compositor?.setBackdropExposure(t);
5530
5542
  },
5531
5543
  onCameraProjection: (e) => {
5532
5544
  this.cameraManager.applyProjection(e), e === "equirectangular" && this.denoisingManager?.requiresMotionVectors ? this.denoisingManager.setDenoiserStrategy("oidn") : this.denoisingManager?._syncGBufferStages?.();
@@ -5536,7 +5548,7 @@ var ec = We("engine"), tc = class extends w {
5536
5548
  _beginFrame() {
5537
5549
  if (this.timeline.update(), this.cameraManager.updateControls(), this._updateExposure(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
5538
5550
  let e = this.animationManager.update();
5539
- e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => ec.error("animation refit error:", e)).finally(() => {
5551
+ e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => ac.error("animation refit error:", e)).finally(() => {
5540
5552
  this._animRefitInFlight = !1;
5541
5553
  }));
5542
5554
  }
@@ -5561,7 +5573,14 @@ var ec = We("engine"), tc = class extends w {
5561
5573
  }
5562
5574
  _displayGain() {
5563
5575
  let e = this.stages.localExposure;
5564
- return e?.wantsBuild && e.build(this.pipeline.context), e?.toneGain() ?? null;
5576
+ e?.wantsBuild && e.build(this.pipeline.context);
5577
+ let t = e?.toneGain() ?? null;
5578
+ if (this.pipeline?.context.getState("pathtracer:backdrop") !== "color") return t;
5579
+ let { toneMappingExposure: n, toneMapping: r } = this.renderer;
5580
+ return {
5581
+ ...t,
5582
+ backdrop: M(this.settings.get("exposure") ?? 1, n, r)
5583
+ };
5565
5584
  }
5566
5585
  setLocalExposure(e) {
5567
5586
  let t = this.stages.localExposure;
@@ -5668,14 +5687,14 @@ var ec = We("engine"), tc = class extends w {
5668
5687
  return t && this._dispatchCamerasUpdated(), t;
5669
5688
  }
5670
5689
  exportSceneState() {
5671
- return Ys(this);
5690
+ return ec(this);
5672
5691
  }
5673
5692
  async importSceneState(e, t) {
5674
- return await $s(this, e, t);
5693
+ return await ic(this, e, t);
5675
5694
  }
5676
5695
  _dispatchCamerasUpdated() {
5677
5696
  this.dispatchEvent({
5678
- type: M.CAMERAS_UPDATED,
5697
+ type: P.CAMERAS_UPDATED,
5679
5698
  cameras: this.cameraManager.cameras,
5680
5699
  cameraNames: this.cameraManager.getCameraNames()
5681
5700
  });
@@ -5705,11 +5724,11 @@ var ec = We("engine"), tc = class extends w {
5705
5724
  let t = this.cameraManager, n = t.currentCameraIndex > 0 ? t.cameras[t.currentCameraIndex] : null, r = n?.userData?.__rayzeeSourceUuid, i = r && e.find((e) => e.uuid === r);
5706
5725
  if (!i) return !1;
5707
5726
  i.updateWorldMatrix(!0, !1);
5708
- let a = new Z();
5727
+ let a = new Q();
5709
5728
  i.matrixWorld.decompose(n.position, n.quaternion, a), n.scale.set(Math.sign(a.x) || 1, Math.sign(a.y) || 1, Math.sign(a.z) || 1), i.isPerspectiveCamera && (n.fov = i.fov);
5710
5729
  let o = t.camera, s = t.controls, c = s ? s.target.distanceTo(o.position) : 0;
5711
5730
  if (o.position.copy(n.position), o.quaternion.copy(n.quaternion), o.scale.copy(n.scale), o.isPerspectiveCamera && n.isPerspectiveCamera && (o.fov = n.fov), o.updateProjectionMatrix(), o.updateMatrixWorld(!0), s) {
5712
- let e = new Z(0, 0, -1).applyQuaternion(o.quaternion);
5731
+ let e = new Q(0, 0, -1).applyQuaternion(o.quaternion);
5713
5732
  s.target.copy(o.position).addScaledVector(e, c || 1);
5714
5733
  }
5715
5734
  return !0;
@@ -5759,7 +5778,7 @@ var ec = We("engine"), tc = class extends w {
5759
5778
  if (this.denoisingManager?.abort(this.canvas, { keepDisplay: e }), this.denoisingManager?.restoreBaseResolution()) {
5760
5779
  let e = this.denoisingManager._lastRenderWidth, t = this.denoisingManager._lastRenderHeight;
5761
5780
  this.dispatchEvent({
5762
- type: M.RESOLUTION_CHANGED,
5781
+ type: P.RESOLUTION_CHANGED,
5763
5782
  width: e,
5764
5783
  height: t
5765
5784
  });
@@ -5787,13 +5806,13 @@ var ec = We("engine"), tc = class extends w {
5787
5806
  if (e.length > 0) {
5788
5807
  let t = this.sceneModel || this.meshScene;
5789
5808
  this.animationManager.init(this.meshScene, t, this._sdf.meshes, e), this.animationManager.onFinished = () => {
5790
- this._animRefitInFlight = !1, this._refreshMovedEmitters(), this.dispatchEvent({ type: M.ANIMATION_FINISHED });
5809
+ this._animRefitInFlight = !1, this._refreshMovedEmitters(), this.dispatchEvent({ type: P.ANIMATION_FINISHED });
5791
5810
  };
5792
5811
  }
5793
5812
  this.transformManager?.setMeshData(this._sdf.meshes);
5794
5813
  }
5795
5814
  _setupDenoisingManager() {
5796
- this.denoisingManager = new Es({
5815
+ this.denoisingManager = new js({
5797
5816
  renderer: this.renderer,
5798
5817
  mainCanvas: this.canvas,
5799
5818
  stages: {
@@ -5815,9 +5834,9 @@ var ec = We("engine"), tc = class extends w {
5815
5834
  }
5816
5835
  _setupAutoExposureListener() {
5817
5836
  let e = this.stages.autoExposure;
5818
- e && (e.setCompensation(this.settings.get("exposure") ?? 1), this.stages.localExposure && (this.stages.localExposure.onChange = () => this._refreshFinished()), e.onChange = () => this._refreshFinished(), this._addTrackedListener(this.cameraManager, M.CAMERA_SWITCHED, () => e.resetHistory()), e.on("autoexposure:updated", ({ exposure: e, autoExposure: t, targetExposure: n, luminance: r }) => {
5837
+ e && (e.setCompensation(this.settings.get("exposure") ?? 1), this.stages.compositor.setBackdropExposure(this.settings.get("exposure") ?? 1), this.stages.localExposure && (this.stages.localExposure.onChange = () => this._refreshFinished()), e.onChange = () => this._refreshFinished(), this._addTrackedListener(this.cameraManager, P.CAMERA_SWITCHED, () => e.resetHistory()), e.on("autoexposure:updated", ({ exposure: e, autoExposure: t, targetExposure: n, luminance: r }) => {
5819
5838
  this.dispatchEvent({
5820
- type: M.AUTO_EXPOSURE_UPDATED,
5839
+ type: P.AUTO_EXPOSURE_UPDATED,
5821
5840
  exposure: e,
5822
5841
  autoExposure: t,
5823
5842
  targetExposure: n,
@@ -5845,7 +5864,7 @@ var ec = We("engine"), tc = class extends w {
5845
5864
  }, n && this.stages.autoExposure?.noteViewChanged());
5846
5865
  }
5847
5866
  async _setupOverlayManager() {
5848
- this.overlayManager = new Fs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
5867
+ this.overlayManager = new Bs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
5849
5868
  helperScene: this._sceneHelpers,
5850
5869
  meshScene: this.meshScene,
5851
5870
  pipeline: this.pipeline,
@@ -5876,15 +5895,15 @@ var ec = We("engine"), tc = class extends w {
5876
5895
  };
5877
5896
  //#endregion
5878
5897
  //#region src/Headless.js
5879
- async function nc(e) {
5880
- let t = await ic(e);
5898
+ async function sc(e) {
5899
+ let t = await lc(e);
5881
5900
  try {
5882
- return await rc(t, e);
5901
+ return await cc(t, e);
5883
5902
  } finally {
5884
5903
  t.dispose();
5885
5904
  }
5886
5905
  }
5887
- async function rc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
5906
+ async function cc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
5888
5907
  let o = e.denoisingManager;
5889
5908
  i && o && !o.finalDenoise && (o.applyOIDNEnabled(!0), o._syncGBufferStages());
5890
5909
  let s = await e.renderFrames(t, {
@@ -5903,8 +5922,8 @@ async function rc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire
5903
5922
  provenance: e.getProvenance()
5904
5923
  };
5905
5924
  }
5906
- async function ic({ canvas: e, model: t = null, width: n = 1920, height: r = 1080, strict: i = !0, deterministic: a = !0, settings: o = null, storage: s = !1, hostMemoryGB: c = void 0 } = {}) {
5907
- let l = new tc(e ?? null, {
5925
+ async function lc({ canvas: e, model: t = null, width: n = 1920, height: r = 1080, strict: i = !0, deterministic: a = !0, settings: o = null, storage: s = !1, hostMemoryGB: c = void 0 } = {}) {
5926
+ let l = new oc(e ?? null, {
5908
5927
  autoResize: !1,
5909
5928
  strict: i,
5910
5929
  storage: s,
@@ -5918,7 +5937,7 @@ async function ic({ canvas: e, model: t = null, width: n = 1920, height: r = 108
5918
5937
  }
5919
5938
  //#endregion
5920
5939
  //#region src/managers/VideoRenderManager.js
5921
- var ac = class {
5940
+ var uc = class {
5922
5941
  constructor(e) {
5923
5942
  this._app = e, this._cancelled = !1, this._rendering = !1;
5924
5943
  }
@@ -5959,7 +5978,7 @@ var ac = class {
5959
5978
  percent: (e + 1) / m * 100
5960
5979
  };
5961
5980
  l?.(p), d.dispatchEvent({
5962
- type: M.VIDEO_RENDER_PROGRESS,
5981
+ type: P.VIDEO_RENDER_PROGRESS,
5963
5982
  ...p
5964
5983
  });
5965
5984
  }
@@ -5969,7 +5988,7 @@ var ac = class {
5969
5988
  this._restoreState(g), this._rendering = !1;
5970
5989
  let e = !this._cancelled;
5971
5990
  u?.(e), d.dispatchEvent({
5972
- type: M.VIDEO_RENDER_COMPLETE,
5991
+ type: P.VIDEO_RENDER_COMPLETE,
5973
5992
  success: e
5974
5993
  });
5975
5994
  }
@@ -5994,13 +6013,13 @@ var ac = class {
5994
6013
  _waitForDenoise(e) {
5995
6014
  return new Promise((t) => {
5996
6015
  let n, r = () => {
5997
- e.removeEventListener(M.DENOISING_END, i), clearTimeout(n);
6016
+ e.removeEventListener(P.DENOISING_END, i), clearTimeout(n);
5998
6017
  }, i = () => {
5999
6018
  r(), t();
6000
6019
  };
6001
6020
  n = setTimeout(() => {
6002
6021
  console.warn("VideoRenderManager: Denoise timed out, skipping"), r(), t();
6003
- }, 3e4), e.addEventListener(M.DENOISING_END, i), e.denoisingManager.onRenderComplete({
6022
+ }, 3e4), e.addEventListener(P.DENOISING_END, i), e.denoisingManager.onRenderComplete({
6004
6023
  isStillComplete: () => !this._cancelled,
6005
6024
  context: e.pipeline?.context
6006
6025
  });
@@ -6032,4 +6051,4 @@ var ac = class {
6032
6051
  }
6033
6052
  };
6034
6053
  //#endregion
6035
- export { Ct as ARCHIVE_FORMATS, Ri as AUTO_EXPOSURE_DEFAULTS, Qa as AUTO_FOCUS_DEFAULTS, Ls as AnimationManager, qe as BVH_LEAF_MARKERS, io as CameraManager, co as CameraTrack, Zt as ColorManagement, zt as DEFAULT_LUT_SIZE, Jt as DEFAULT_MAX_EV, Gt as DEFAULT_MIN_EV, le as DEFAULT_SUN_PATH, ht as DEFAULT_VIEW, rt as DEFAULT_WORKING_SPACE, Qr as DENOISER_DEFAULTS, Kr as DENOISER_STRATEGIES, C as DOWNLOAD_POLICY, Es as DenoisingManager, d as DownloadCache, $e as ENGINE_AREAS, we as ENGINE_DEFAULTS, M as EngineEvents, Ze as EngineIssueError, fo as GoboManager, wo as IESManager, Ee as INTERACTIVE_RENDER_CONFIG, Ye as ISSUE_CODES, Xe as ISSUE_SEVERITY, Fa as InteractionManager, Je as IssueLog, Se as LEGACY_EVENT_NAMES, ua as LOCAL_EXPOSURE_DEFAULTS, Ge as LOG_LEVELS, S as LightManager, Ue as Logger, Le as MATERIAL_DEFAULTS, Ce as MATERIAL_VALUE_SOURCE, k as MAX_RESERVABLE_RENDER_SIZE, Ne as MAX_SCENE_BYTES, pt as MAX_TABLE_TRANSFORMS, Ae as MemoryLedger, Yr as NRD_DEFAULTS, qr as NRD_HIT_DIST_A, Jr as NRD_HIT_DIST_B, Xr as NRD_PRESET_KEYS, Zr as NRD_QUALITY_PRESETS, lt as OCIO_VIEW_BASE, Fs as OverlayManager, Te as PRODUCTION_RENDER_CONFIG, tc as PathTracerApp, l as PipelineContext, hn as RETOUCH_DEFAULTS, gn as RETOUCH_MAX_PIXELS, mn as RETOUCH_RANGES, w as RayzeeRenderer, x as RenderPipeline, u as RenderSettings, D as RenderStage, je as SAFE_SCENE_BYTES, Hs as SCENE_STATE_VERSION, b as SETTING_SOURCE, j as SKY_DEFAULTS, fn as SR_MAX_INPUT, pn as SR_SCALE, Qe as STORAGE_KIND, pe as StageExecutionMode, sn as StorageManager, Ke as TRIANGLE_DATA_LAYOUT, uo as TimelineManager, Bs as TransformManager, Re as VERSION, ot as VIEW_TRANSFORMS, he as VRAMTracker, ac as VideoRenderManager, rn as acquireLock, Vt as addAllOcioViews, Bt as addOcioView, dt as addViewTransform, tn as applyMatrixRGBA8, $t as bakeLut, _e as bufferBytes, Pt as buildOcioView, mt as buildToneMapWGSL, _ as cachedObjectURL, Kt as canvasColorSpaceFor, rc as captureHeadless, v as clearBindingAuditFindings, Ft as clearInputOverrides, at as configureAssets, Ve as configurePlatform, Mt as convertColor, Ot as convertEncodedRGBA8, en as convertPixelsF32, We as createLogger, ge as dayOfYearForMonth, De as deriveAlphaMode, y as describeAdapter, Dt as displayCanvasFit, Ie as estimateSceneBytes, Nt as extractMatrix, wt as extractSceneMetadata, T as fetchFile, yt as fileIdentity, Yt as findNativeLinearSpace, He as fmt, bt as folderIdentity, ye as fromPortable, nt as getActiveColorManagement, it as getAssetConfig, h as getBindingAuditFindings, Be as getPlatform, ut as getRegistryVersion, gt as getViewTransform, At as hasColorSpace, an as heldLockNames, vt as identityKey, Ht as isColorManaged, kt as isDataSpace, qt as isDataTexture, jt as linearToSrgb, Xt as listFileRules, Lt as listInputOverrides, st as listViewTransforms, xt as localFolder, nn as makeCpuSampler, It as measureBakeError, f as nameFromUrl, ft as onRegistryChange, ic as openHeadless, on as openStorage, un as openZip, St as parseSceneMetadata, Pe as probeAddressSpace, ln as readZipDirectory, ct as removeViewTransform, nc as renderHeadless, dn as renderUpscaled, Wt as resolveInputSpace, _t as sameIdentity, tt as setActiveColorManagement, m as setBindingAudit, Qt as setInputOverride, Ut as srgbToLinear, me as sunPosition, fe as textureBytes, Rt as textureInputSpace, de as timeForSunElevation, be as toPortable };
6054
+ export { Ct as ARCHIVE_FORMATS, Bi as AUTO_EXPOSURE_DEFAULTS, ro as AUTO_FOCUS_DEFAULTS, Hs as AnimationManager, qe as BVH_LEAF_MARKERS, lo as CameraManager, mo as CameraTrack, Zt as ColorManagement, zt as DEFAULT_LUT_SIZE, Jt as DEFAULT_MAX_EV, Gt as DEFAULT_MIN_EV, ge as DEFAULT_SUN_PATH, ht as DEFAULT_VIEW, rt as DEFAULT_WORKING_SPACE, $r as DENOISER_DEFAULTS, qr as DENOISER_STRATEGIES, C as DOWNLOAD_POLICY, js as DenoisingManager, d as DownloadCache, $e as ENGINE_AREAS, we as ENGINE_DEFAULTS, P as EngineEvents, Ze as EngineIssueError, _o as GoboManager, ko as IESManager, Ee as INTERACTIVE_RENDER_CONFIG, Ye as ISSUE_CODES, Xe as ISSUE_SEVERITY, Ba as InteractionManager, Je as IssueLog, Se as LEGACY_EVENT_NAMES, ma as LOCAL_EXPOSURE_DEFAULTS, Ge as LOG_LEVELS, S as LightManager, Ue as Logger, Le as MATERIAL_DEFAULTS, Ce as MATERIAL_VALUE_SOURCE, j as MAX_RESERVABLE_RENDER_SIZE, Ne as MAX_SCENE_BYTES, pt as MAX_TABLE_TRANSFORMS, Ae as MemoryLedger, Xr as NRD_DEFAULTS, Jr as NRD_HIT_DIST_A, Yr as NRD_HIT_DIST_B, Zr as NRD_PRESET_KEYS, Qr as NRD_QUALITY_PRESETS, lt as OCIO_VIEW_BASE, Bs as OverlayManager, Te as PRODUCTION_RENDER_CONFIG, oc as PathTracerApp, l as PipelineContext, hn as RETOUCH_DEFAULTS, gn as RETOUCH_MAX_PIXELS, mn as RETOUCH_RANGES, w as RayzeeRenderer, x as RenderPipeline, u as RenderSettings, k as RenderStage, je as SAFE_SCENE_BYTES, qs as SCENE_STATE_VERSION, b as SETTING_SOURCE, me as SKY_DEFAULTS, fn as SR_MAX_INPUT, pn as SR_SCALE, Qe as STORAGE_KIND, A as StageExecutionMode, sn as StorageManager, Ke as TRIANGLE_DATA_LAYOUT, go as TimelineManager, Gs as TransformManager, Re as VERSION, ot as VIEW_TRANSFORMS, _e as VRAMTracker, uc as VideoRenderManager, rn as acquireLock, Vt as addAllOcioViews, Bt as addOcioView, dt as addViewTransform, tn as applyMatrixRGBA8, $t as bakeLut, pe as bufferBytes, Pt as buildOcioView, mt as buildToneMapWGSL, _ as cachedObjectURL, Kt as canvasColorSpaceFor, cc as captureHeadless, v as clearBindingAuditFindings, Ft as clearInputOverrides, at as configureAssets, Ve as configurePlatform, Mt as convertColor, Ot as convertEncodedRGBA8, en as convertPixelsF32, We as createLogger, fe as dayOfYearForMonth, De as deriveAlphaMode, y as describeAdapter, Dt as displayCanvasFit, Ie as estimateSceneBytes, Nt as extractMatrix, wt as extractSceneMetadata, T as fetchFile, yt as fileIdentity, Yt as findNativeLinearSpace, He as fmt, bt as folderIdentity, le as fromPortable, nt as getActiveColorManagement, it as getAssetConfig, h as getBindingAuditFindings, Be as getPlatform, ut as getRegistryVersion, gt as getViewTransform, At as hasColorSpace, an as heldLockNames, vt as identityKey, Ht as isColorManaged, kt as isDataSpace, qt as isDataTexture, jt as linearToSrgb, Xt as listFileRules, Lt as listInputOverrides, st as listViewTransforms, xt as localFolder, nn as makeCpuSampler, It as measureBakeError, f as nameFromUrl, ft as onRegistryChange, lc as openHeadless, on as openStorage, un as openZip, St as parseSceneMetadata, Pe as probeAddressSpace, ln as readZipDirectory, ct as removeViewTransform, sc as renderHeadless, dn as renderUpscaled, Wt as resolveInputSpace, _t as sameIdentity, tt as setActiveColorManagement, m as setBindingAudit, Qt as setInputOverride, Ut as srgbToLinear, de as sunPosition, ce as textureBytes, Rt as textureInputSpace, se as timeForSunElevation, ye as toPortable };