rayzee 11.7.0 → 11.9.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 (79) hide show
  1. package/README.md +31 -6
  2. package/dist/{ArchiveImporter-DYcRXeKE.js → ArchiveImporter-BJxszU_k.js} +2353 -1356
  3. package/dist/{BidirectionalIntegrator-BvjRpbTP.js → BidirectionalIntegrator-DWg66vAd.js} +302 -301
  4. package/dist/{BufferLayout-xPRH9jYD.js → BufferLayout-Bzgccg1o.js} +1 -0
  5. package/dist/{ColorManagement-oeEk7oSu.js → ColorManagement-B_HjAiy2.js} +1 -1
  6. package/dist/{EngineIssues-CIZnXHsF.js → EngineIssues-CfJiBaNj.js} +19 -8
  7. package/dist/{NeuralRetouch-ClaMiKYg.js → NeuralRetouch-BD9E-Yht.js} +2 -2
  8. package/dist/{NeuralSuperRes-WNEXun9s.js → NeuralSuperRes-C8Mf3tJX.js} +2 -2
  9. package/dist/{PathTracer-B9wZPPVL.js → PathTracer-DeE9UJ1n.js} +3530 -3402
  10. package/dist/{PhysicalSky-DcjItqKi.js → PhysicalSky-cKy75-oR.js} +45 -45
  11. package/dist/{RayzeeRenderer-p-NeE6E2.js → RayzeeRenderer-CzLyBA3G.js} +378 -374
  12. package/dist/SceneMetadata-C17UfOEp.js +183 -0
  13. package/dist/{SolarLimb-bZE6y63S.js → SolarLimb-DRYy8tln.js} +184 -172
  14. package/dist/{ToneMapGPU-sAs8wdgI.js → ToneMapGPU-4GPwoG_c.js} +13 -6
  15. package/dist/addons/archives.es.js +1 -1
  16. package/dist/addons/bidirectional.es.js +1 -1
  17. package/dist/addons/color.es.js +1 -1
  18. package/dist/addons/physical-sky.es.js +1 -1
  19. package/dist/addons/storage.es.js +1 -1
  20. package/dist/{openStorage-Fe9BoS1_.js → openStorage-CdyVjmps.js} +1 -1
  21. package/dist/rayzee-core.es.js +7 -7
  22. package/dist/rayzee.es.js +821 -794
  23. package/dist/rayzee.umd.js +112 -103
  24. package/dist/{sceneCachePolicy-B9w3BnaP.js → sceneCachePolicy-ywbGKHD3.js} +9 -6
  25. package/package.json +1 -1
  26. package/src/EngineDefaults.js +1 -0
  27. package/src/EngineIssues.js +21 -6
  28. package/src/Passes/AIUpscaler.js +4 -0
  29. package/src/Passes/OIDNDenoiser.js +8 -6
  30. package/src/Passes/OIDNTemporalHistory.js +1 -1
  31. package/src/PathTracerApp.js +10 -1
  32. package/src/Processor/ArchiveImporter.js +106 -27
  33. package/src/Processor/AssetLoader.js +22 -0
  34. package/src/Processor/BufferLayout.js +3 -3
  35. package/src/Processor/GeometryExtractor.js +12 -4
  36. package/src/Processor/LightSerializer.js +6 -2
  37. package/src/Processor/MaterialPacking.js +2 -2
  38. package/src/Processor/PBRT/PBRTMaterials.js +49 -13
  39. package/src/Processor/PBRT/PBRTParser.js +144 -22
  40. package/src/Processor/PBRT/PBRTSceneBuilder.js +287 -67
  41. package/src/Processor/PBRT/PBRTTextureBake.js +191 -9
  42. package/src/Processor/PBRT/index.js +19 -4
  43. package/src/Processor/PlatformImageLoader.js +9 -0
  44. package/src/Processor/SceneProcessor.js +42 -26
  45. package/src/Processor/TextureCreator.js +44 -4
  46. package/src/Processor/ToneMapCPU.js +34 -5
  47. package/src/Processor/ToneMapGPU.js +15 -9
  48. package/src/Processor/USD/USDScene.js +981 -17
  49. package/src/RayzeeRenderer.js +85 -28
  50. package/src/Stages/AutoExposure.js +21 -8
  51. package/src/Stages/Compositor.js +39 -1
  52. package/src/Stages/DenoiserSettings.js +0 -4
  53. package/src/Stages/LocalExposure.js +44 -18
  54. package/src/Stages/NRD.js +53 -24
  55. package/src/Stages/NormalDepth.js +12 -6
  56. package/src/Stages/PathTracer.js +27 -1
  57. package/src/Stages/PathTracerStage.js +14 -2
  58. package/src/Storage/SceneGraphCodec.js +6 -3
  59. package/src/TSL/BVHTraversal.js +33 -20
  60. package/src/TSL/CameraRay.js +12 -1
  61. package/src/TSL/Common.js +25 -8
  62. package/src/TSL/DebugKernel.js +3 -2
  63. package/src/TSL/Displacement.js +66 -113
  64. package/src/TSL/FinalWriteKernel.js +4 -7
  65. package/src/TSL/GenerateKernel.js +6 -2
  66. package/src/TSL/LightSplatKernel.js +7 -4
  67. package/src/TSL/LightsCore.js +6 -2
  68. package/src/TSL/LightsDirect.js +33 -11
  69. package/src/TSL/LightsSampling.js +45 -12
  70. package/src/TSL/SceneResources.js +19 -0
  71. package/src/TSL/ShadeKernel.js +3 -4
  72. package/src/TSL/Struct.js +1 -0
  73. package/src/integrators/BidirectionalIntegrator.js +1 -0
  74. package/src/managers/CameraManager.js +9 -0
  75. package/src/managers/DenoisingManager.js +1 -0
  76. package/src/managers/InteractionManager.js +6 -0
  77. package/src/managers/MaterialDataManager.js +11 -0
  78. package/src/managers/UniformManager.js +3 -1
  79. package/dist/SceneMetadata-D2Sh-0e-.js +0 -110
package/dist/rayzee.es.js CHANGED
@@ -1,34 +1,34 @@
1
- import { t as e } from "./BidirectionalIntegrator-BvjRpbTP.js";
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";
1
+ import { t as e } from "./BidirectionalIntegrator-DWg66vAd.js";
2
+ import { Ft as t, Pt as n, Xt as r, en as i, rn as a, rt as o, tn as s, wt as c } from "./SolarLimb-DRYy8tln.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-CzLyBA3G.js";
4
+ import { $ as E, At as D, B as O, F as k, H as ee, I as te, J as ne, Mt as A, Nt as j, Ot as re, Q as M, V as ie, W as ae, _t as oe, at as se, bt as ce, dt as le, et as N, gt as ue, ht as de, it as fe, kt as pe, 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-DeE9UJ1n.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-ywbGKHD3.js";
7
7
  import { i as He, n as Ue, r as We, t as Ge } from "./Logger-dDDGj9Av.js";
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";
8
+ import { f as Ke, r as qe } from "./BufferLayout-Bzgccg1o.js";
9
+ import { i as Je, n as Ye, r as Xe, t as Ze } from "./EngineIssues-CfJiBaNj.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-C17UfOEp.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-B_HjAiy2.js";
20
+ import { c as rn, l as an, n as on, o as sn, t as cn } from "./openStorage-CdyVjmps.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-C8Mf3tJX.js";
23
+ import { i as mn, n as hn, r as gn } from "./NeuralRetouch-BD9E-Yht.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 = Object.freeze([
32
32
  "none",
33
33
  "nrd",
34
34
  "oidn"
@@ -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
+ }, $r = class extends A {
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: j.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(pe, pe), this._outputStorageTex.type = fr, this._outputStorageTex.format = kr, this._outputStorageTex.minFilter = Z, this._outputStorageTex.magFilter = Z, this._shadingStorageTex = new Sn(pe, pe), 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,37 +135,42 @@ 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 && ee(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
- let e = this._triStorageNode, n = this._bvhStorageNode, r = this._matStorageNode;
142
- this._linearBuckets = te(this.pathTracer?.materialData?.linearBuckets);
143
- let s = {
144
- srgbBuckets: te(null),
141
+ let e = this._triStorageNode, t = this._bvhStorageNode, n = this._matStorageNode;
142
+ this._linearBuckets = k(this.pathTracer?.materialData?.linearBuckets);
143
+ let o = {
144
+ srgbBuckets: k(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(([o, 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)), o, l, this.cameraRay), v = _.direction.toVar(), y = M(v, this.cameraRay.clipStart, o, this.cameraRay.cameraProjection).toVar(), b = i({
155
+ origin: _.origin.add(v.mul(y)),
156
+ direction: v
157
+ }), x = r.wrap(ne(b, t, 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 r = s.wrap(c(x.materialIndex, n)).toVar(), i = a.wrap(te(x.uv, r)).toVar(), o = Y(0).toVar();
162
+ F(r.normalMapIndex.greaterThanEqual(R(0)), () => {
163
+ o.assign(ae(e, x.triangleIndex, x.normal, r.normalTransform, t, 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 = ie(x.normal, r, i, o).toVar();
166
+ T.assign(xe(l, r, i)), D.assign(O(r, i).y.clamp(.05, 1));
167
+ let u = B(r.emissive.x, B(r.emissive.y, r.emissive.z)).mul(r.emissiveIntensity).greaterThan(0);
168
+ D.assign(U(u, D.negate(), D));
164
169
  });
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();
170
+ let k = x.didHit.select(Y(T.mul(.5).add(.5), D), Y(0, 0, 0, 1));
171
+ G(m, Jn(K(u), K(g)), k).toWriteOnly();
167
172
  });
168
- })(l, u), s).compute([
173
+ })(l, u), o).compute([
169
174
  this._dispatchX,
170
175
  this._dispatchY,
171
176
  1
@@ -209,17 +214,17 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
209
214
  reallocateReservedStorage() {
210
215
  this._computeNode?.dispose(), this._computeNode = null, this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose();
211
216
  let e = () => {
212
- let e = new Sn(O, O);
213
- return e.type = fr, e.format = Or, e.minFilter = X, e.magFilter = X, e;
217
+ let e = new Sn(pe, pe);
218
+ return e.type = fr, e.format = kr, e.minFilter = Z, e.magFilter = Z, e;
214
219
  };
215
220
  this._outputStorageTex = e(), this._shadingStorageTex = e(), this._leafStorageTex &&= (this._leafStorageTex.dispose(), this._makeLeafStorage()), this._computeBuilt = !1;
216
221
  }
217
222
  setInstanceLeafOutput(e) {
218
223
  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,
224
+ type: Lr,
225
+ format: jr,
226
+ minFilter: Z,
227
+ magFilter: Z,
223
228
  depthBuffer: !1,
224
229
  stencilBuffer: !1
225
230
  })) : (this._leafStorageTex.dispose(), this._leafRT.dispose(), this._leafStorageTex = null, this._leafRT = null));
@@ -228,24 +233,24 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
228
233
  this._leafRT ? e.setTexture("pathtracer:instanceLeaf", this._leafRT.texture) : e.getTexture("pathtracer:instanceLeaf") && e.removeTexture("pathtracer:instanceLeaf");
229
234
  }
230
235
  _makeLeafStorage() {
231
- let e = new Sn(O, O);
232
- return e.type = Ir, e.format = Ar, e.minFilter = X, e.magFilter = X, e;
236
+ let e = new Sn(pe, pe);
237
+ return e.type = Lr, e.format = jr, e.minFilter = Z, e.magFilter = Z, e;
233
238
  }
234
239
  dispose() {
235
240
  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
241
  }
237
- }, ei = class extends D {
242
+ }, ei = class extends A {
238
243
  constructor(e, t, n = {}) {
239
244
  super("MotionVector", {
240
245
  ...n,
241
- executionMode: pe.ALWAYS
246
+ executionMode: j.ALWAYS
242
247
  }), this.renderer = e, this.camera = t, this.pathTracer = n.pathTracer || null;
243
248
  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, {
249
+ 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(pe, pe), 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
250
  type: fr,
246
- format: Or,
247
- minFilter: X,
248
- magFilter: X,
251
+ format: kr,
252
+ minFilter: Z,
253
+ magFilter: Z,
249
254
  depthBuffer: !1,
250
255
  stencilBuffer: !1
251
256
  }), this._dispatchX = Math.ceil(r / 16), this._dispatchY = Math.ceil(i / 16), this._buildScreenSpaceCompute();
@@ -253,13 +258,13 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
253
258
  _buildScreenSpaceCompute() {
254
259
  let e = this._normalDepthTexNode, t = this.cameraWorldMatrix, n = this.cameraProjectionMatrixInverse, r = this.prevVP, i = this.resolutionWidth, a = this.resolutionHeight, o = this._screenSpaceStorageTex;
255
260
  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();
261
+ let s = R(X.x).mul(16).add(R(z.x)), c = R(X.y).mul(16).add(R(z.y));
262
+ F(s.lessThan(R(i)).and(c.lessThan(R(a))), () => {
263
+ 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();
264
+ F(l.lessThan(L(6e4)), () => {
265
+ let e = N(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));
266
+ d.assign(c.select(Y(s, l, 1), Y(L(1e3), L(1e3), l, 0)));
267
+ }), G(o, Jn(K(s), K(c)), d).toWriteOnly();
263
268
  });
264
269
  })(t, n).compute([
265
270
  this._dispatchX,
@@ -301,13 +306,13 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
301
306
  }
302
307
  reallocateReservedStorage() {
303
308
  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();
309
+ let e = new Sn(pe, pe);
310
+ e.type = fr, e.format = kr, e.minFilter = Z, e.magFilter = Z, this._screenSpaceStorageTex = e, this._buildScreenSpaceCompute();
306
311
  }
307
312
  dispose() {
308
313
  this._screenSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this.screenSpaceTarget?.dispose(), this._normalDepthTexNode?.dispose();
309
314
  }
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 = {
315
+ }, 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, mi = .04, hi = .1 * mi, gi = 16, _i = 16, vi = {
311
316
  pre: {
312
317
  radiusScale: 1,
313
318
  fractionScale: 2
@@ -320,7 +325,7 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
320
325
  radiusScale: 2,
321
326
  fractionScale: .5
322
327
  }
323
- }, hi = .25 * Math.SQRT2, gi = [
328
+ }, yi = .25 * Math.SQRT2, bi = [
324
329
  [
325
330
  -1,
326
331
  0,
@@ -342,62 +347,62 @@ var Ur = 65504, Wr = 6e4, Gr = .01, Kr = Object.freeze([
342
347
  1
343
348
  ],
344
349
  [
345
- -hi,
346
- hi,
350
+ -yi,
351
+ yi,
347
352
  .5
348
353
  ],
349
354
  [
350
- hi,
351
- hi,
355
+ yi,
356
+ yi,
352
357
  .5
353
358
  ],
354
359
  [
355
- hi,
356
- -hi,
360
+ yi,
361
+ -yi,
357
362
  .5
358
363
  ],
359
364
  [
360
- -hi,
361
- -hi,
365
+ -yi,
366
+ -yi,
362
367
  .5
363
368
  ]
364
- ], _i = (e, t, n) => Wn(0, 1, F(1).sub(e.mul(t).add(n).abs())), vi = (e, t, n) => {
369
+ ], xi = (e, t, n) => Wn(0, 1, L(1).sub(e.mul(t).add(n).abs())), Si = (e, t, n) => {
365
370
  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());
376
- }, 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) => {
371
+ return L(1).div(r.mul(r).sub(r).add(1));
372
+ }, Ci = (e) => V(L(1.570796), L(1.395402), H(e)).mul(Gn(H(L(1).sub(e)))), wi = (e, t) => L(1).sub(Pn(e.mul(e).mul(-200))).mul(Hn(H(e), t)), Ti = (e, t) => H(e).mul(Gn(t.div(L(1).sub(t).add(ti)))), Ei = (e, t, n, r) => {
373
+ let i = B(On(Ti(n, r.mul(V(H(t), L(1), e)))), L(ni));
374
+ return L(1).div(i);
375
+ }, Di = (e, t) => {
376
+ let n = L(1).div(V(L(ri), L(1), H(e.mul(t))));
377
+ return J(n, e.mul(n).negate());
378
+ }, Oi = (e, t, n) => {
379
+ let r = L(1).div(V(L(n), L(1), V(e.mul(e), e, H(t))));
380
+ return J(r, e.mul(r).negate());
381
+ }, ki = (e, t) => {
382
+ let n = L(1).div(t);
383
+ return J(n, e.mul(n).negate());
384
+ }, Ai = (e, t, n, r) => {
385
+ let i = L(1).div(e.mul(t));
386
+ return J(i, I(r, n).mul(i).negate());
387
+ }, ji = (e) => J(1).sub(J(1).sub(Ln(e.mul(.5)).mul(2)).abs()).min(.99999), Mi = (e) => Xn(I(e, Xn(.25, .5, .25)), I(e, Xn(.5, 0, -.5)), I(e, Xn(-.25, .5, -.25))), Ni = (e) => {
383
388
  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) {
389
+ return B(Xn(t.add(e.y), e.x.add(e.z), t.sub(e.y)), Xn(0));
390
+ }, Pi = (e, t) => t.add(ti).div(e.add(ti)), Fi = (e, t) => Y(e.xyz.mul(Pi(e.x, t)), e.w), Ii = (e) => Y(Mi(Ni(e.xyz)), H(e.w)), Li = (e, t) => Gn(t.sub(e.mul(e)).abs()), Ri = (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))), zi = (e) => e.mul(1 - mi).add(mi), Bi = (e) => B(e.x, B(e.y, e.z)).lessThan(hi), Vi = (e) => e.z.greaterThan(gi - .5), Hi = (e) => e.lessThan(0), Ui = (e) => e.abs().clamp(.05, 1), Wi = (e, t) => U(e.equal(0), Y(0), t);
391
+ function Gi(e) {
387
392
  let t = Math.imul(e | 0, 2654435761) >>> 0;
388
393
  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
394
  }
390
- var Li = class extends D {
395
+ var Ki = class extends A {
391
396
  constructor(e, t = {}) {
392
397
  super("NRD", {
393
398
  ...t,
394
- executionMode: pe.PER_CYCLE
399
+ executionMode: j.PER_CYCLE
395
400
  }), this.renderer = e, this.pathTracer = t.pathTracer || null, this.settings = {
396
401
  ...Yr,
397
402
  ...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;
403
+ }, 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
404
  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 = {};
405
+ 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
406
  for (let e of [
402
407
  "maxAccum",
403
408
  "maxFast",
@@ -417,25 +422,25 @@ var Li = class extends D {
417
422
  "disocclusionThreshold",
418
423
  "lobeVolumePercent",
419
424
  "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();
425
+ ]) this.u[e] = q(0);
426
+ 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
427
  let i = () => {
423
- let e = new lr(new Float32Array(4), 1, 1, Or, dr);
428
+ let e = new lr(new Float32Array(4), 1, 1, kr, dr);
424
429
  e.needsUpdate = !0;
425
430
  let t = new Cn(e);
426
431
  return this._placeholders.set(t, e), t;
427
432
  };
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, {
433
+ 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
434
  type: fr,
430
- format: Or,
435
+ format: kr,
431
436
  minFilter: mr,
432
437
  magFilter: mr,
433
438
  depthBuffer: !1,
434
439
  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();
440
+ }), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n / _i), this._dispatchY = Math.ceil(r / _i), this._buildKernels();
436
441
  }
437
442
  _allocStorage() {
438
- let e = () => A(fr);
443
+ let e = () => D(fr);
439
444
  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
445
  }
441
446
  _disposeStorage() {
@@ -467,32 +472,35 @@ var Li = class extends D {
467
472
  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
473
  }
469
474
  _worldPosAt(e, t, n, r) {
470
- return E(e, t, n, r, this.cameraRay);
475
+ return N(e, t, n, r, this.cameraRay);
471
476
  }
472
477
  _viewVector(e, t, n) {
473
- return V(ve(this.cameraRay.cameraProjection), n, Vn(t.sub(e)));
478
+ return U(he(this.cameraRay.cameraProjection), n, Vn(t.sub(e)));
474
479
  }
475
480
  _frustumSize(e) {
476
- return this.minRectDimMulUnproject.mul(V(ve(this.cameraRay.cameraProjection), F(1), e));
481
+ return this.minRectDimMulUnproject.mul(U(he(this.cameraRay.cameraProjection), L(1), e));
477
482
  }
478
483
  _pixelUv(e, t) {
479
- return K(F(e).add(.5).div(this.resW), F(t).add(.5).div(this.resH));
484
+ return J(L(e).add(.5).div(this.resW), L(t).add(.5).div(this.resH));
480
485
  }
481
486
  _clampCoord(e, t) {
482
- return Rn(e.clamp(I(0), I(this.resW).sub(1)), t.clamp(I(0), I(this.resH).sub(1)));
487
+ return Rn(e.clamp(R(0), R(this.resW).sub(1)), t.clamp(R(0), R(this.resH).sub(1)));
483
488
  }
484
489
  _uvToCoord(e) {
485
- return this._clampCoord(I(e.x.mul(this.resW)), I(e.y.mul(this.resH)));
490
+ return this._clampCoord(R(e.x.mul(this.resW)), R(e.y.mul(this.resH)));
486
491
  }
487
492
  _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)));
493
+ 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));
494
+ return L(1).div(L(1).add(r.mul(e)));
490
495
  }
491
496
  _handover(e) {
492
- return B(e.div(R(this.u.handoverFrames, 1)));
497
+ return H(e.div(B(this.u.handoverFrames, 1)));
498
+ }
499
+ _excluded(e, t, n, r) {
500
+ return e.greaterThanEqual(Gr).or(Hi(t)).or(n.and(r.not()));
493
501
  }
494
502
  _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));
503
+ 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
504
  return {
497
505
  f: r,
498
506
  taps: [
@@ -508,22 +516,22 @@ var Li = class extends D {
508
516
  o(i.add(1), a.add(1))
509
517
  ],
510
518
  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),
519
+ e[0].mul(L(1).sub(r.x)).mul(L(1).sub(r.y)),
520
+ e[1].mul(r.x).mul(L(1).sub(r.y)),
521
+ e[2].mul(L(1).sub(r.x)).mul(r.y),
514
522
  e[3].mul(r.x).mul(r.y)
515
523
  ],
516
- filter: (e) => z(z(e[0], e[1], r.x), z(e[2], e[3], r.x), r.y)
524
+ filter: (e) => V(V(e[0], e[1], r.x), V(e[2], e[3], r.x), r.y)
517
525
  };
518
526
  }
519
527
  _applyCustomWeights(e, t, n) {
520
528
  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)));
529
+ return U(i.lessThan(1e-4), n, r.div(B(i, 1e-4)));
522
530
  }
523
531
  _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 = [
532
+ let a = Y(0).toVar();
533
+ return F(i, () => {
534
+ let n = H(t).mul(J(this.resW, this.resH)), r = In(n.sub(.5)).add(.5), i = H(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
535
  s.x,
528
536
  c.x,
529
537
  l.x,
@@ -533,15 +541,15 @@ var Li = class extends D {
533
541
  c.y,
534
542
  l.y,
535
543
  u.y
536
- ], p = I(r.x).sub(1), m = I(r.y).sub(1), h = q(0).toVar(), g = F(0).toVar();
544
+ ], p = R(r.x).sub(1), m = R(r.y).sub(1), h = Y(0).toVar(), g = L(0).toVar();
537
545
  for (let t = 0; t < 4; t++) for (let n = 0; n < 4; n++) {
538
546
  if ((n === 0 || n === 3) && (t === 0 || t === 3)) continue;
539
547
  let r = d[n].mul(f[t]);
540
548
  h.addAssign(e(this._clampCoord(p.add(n), m.add(t))).mul(r)), g.addAssign(r);
541
549
  }
542
- a.assign(V(g.lessThan(1e-4), q(0), h.div(R(g, 1e-4))));
550
+ a.assign(U(g.lessThan(1e-4), Y(0), h.div(B(g, 1e-4))));
543
551
  }).Else(() => {
544
- a.assign(this._applyCustomWeights(n.taps.map((t) => e(t)), r, q(0)));
552
+ a.assign(this._applyCustomWeights(n.taps.map((t) => e(t)), r, Y(0)));
545
553
  }), a;
546
554
  }
547
555
  _buildKernels() {
@@ -561,119 +569,122 @@ var Li = class extends D {
561
569
  this._dispatchY,
562
570
  1
563
571
  ], [
564
- Q,
565
- Q,
572
+ _i,
573
+ _i,
566
574
  1
567
575
  ]);
568
576
  }
569
577
  _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(), () => {
578
- 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);
583
- 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));
578
+ let r = e === "pre", { radiusScale: i, fractionScale: a } = vi[e], s = 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 : r ? this._tmpA : this._hist, h = this._geomPrev, g = r ? this.rotPre : e === "blur" ? this.rotBlur : this.rotPost, _ = r ? s.prepassBlurRadius : s.maxBlurRadius, v = this.camView, y = this.camPos, b = this.resW, x = this.resH, S = this.inputFrames, C = r ? (e, r) => Y(Mi(t(W(c, e).xyz.div(zi(r.xyz)))), n(r.w, o).min(1)) : (e) => W(p, e), w = Tn(([t, n]) => {
579
+ let o = R(X.x).mul(_i).add(R(z.x)), c = R(X.y).mul(_i).add(R(z.y));
580
+ F(o.lessThan(R(b)).and(c.lessThan(R(x))), () => {
581
+ let p = Rn(o, c), w = Jn(K(o), K(c)), T = W(u, p).w.toVar(), E = T.greaterThanEqual(Gr), D = W(d, p).toVar(), O = Vn(D.xyz.mul(2).sub(1)).toVar(), k = Ui(D.w).toVar(), ee = L(Gr).toVar(), te = r ? W(l, p) : null, ne = (r ? Bi(te) : Vi(W(f, p))).toVar(), A = C(p, te).toVar();
582
+ F(E.not(), () => {
583
+ let e = this._pixelUv(o, c), m = this._worldPosAt(e, T, t, n).toVar();
584
+ ee.assign(v.mul(Y(m, 1)).z.abs()), F(_.greaterThan(0).and(Hi(D.w).not()), () => {
585
+ let o = I(O, this._viewVector(m, y, this.viewVector)).abs().toVar(), c = this._frustumSize(ee).toVar(), h = S.add(1), w = r ? B(S, L(10)) : W(f, p).y.add(S), T = (r ? L(1).div(w.add(1)) : this._advancedNonLinear(w)).toVar(), E = wi(k, .5).toVar(), D = ee.mul(Jr).add(3), te = A.w.toVar(), j = H(te.mul(D).div(c)), re = L(1).sub(this._handover(h)), M = (r ? j.div(h) : j.mul(T)).mul(re), ie = s.minBlurRadius.mul(H(L(2).sub(w.div(B(s.maxAccum, 1))))), ae = B(H(Gn(H(M)).mul(i)).mul(_).mul(E), ie.mul(E)).toVar(), oe = Ai(s.planeDistSensitivity, c, m, O).toVar(), se = Ei(T, s.lobeAngleFraction, k, s.lobeVolumePercent).div(a).toVar(), ce = Di(k, s.roughnessFraction.mul(a)).toVar(), le = ki(te, T).toVar(), N = s.minHitDistanceWeight.mul(a).mul(E);
586
+ r || (N = N.mul(T)), N = N.toVar();
587
+ let ue = J(1);
588
+ if (!r) {
589
+ let e = v.mul(Y(O, 0)).xy;
590
+ ue = V(J(1).sub(e.abs()), J(1), o), ue = ue.div(B(ue.x, ue.y));
586
591
  }
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));
592
+ let de = ue.mul(J(L(1).div(b), L(1).div(x))).mul(ae).toVar(), fe = L(1).toVar();
593
+ for (let i = 0; i < bi.length; i++) {
594
+ let a = bi[i], o = e.add(Ri(g, J(a[0], a[1])).mul(de)), s = ji(o), c = U(s.x.notEqual(o.x).or(s.y.notEqual(o.y)), L(1), L(Math.exp(-.66 * a[2] * a[2]))).toVar(), p = this._uvToCoord(s), m = W(u, p).w, h = this._worldPosAt(s, m, t, n), _ = W(d, p), v = Ci(I(O, Vn(_.xyz.mul(2).sub(1))));
595
+ c.mulAssign(xi(v, se, L(0))), c.mulAssign(xi(Ui(_.w), ce.x, ce.y)), c.mulAssign(xi(I(O, h), oe.x, oe.y));
596
+ let y = r ? W(l, p) : null, b = r ? Bi(y) : Vi(W(f, p));
597
+ c.assign(U(this._excluded(m, _.w, b, ne), L(0), c));
598
+ let x = Wi(c, C(p, y));
599
+ c.mulAssign(N.add(Si(x.w, le.x, le.y))), fe.addAssign(c), A.addAssign(x.mul(c));
593
600
  }
594
- k.divAssign(R(fe, 1e-6)), t || k.assign(q(k.xyz, te));
601
+ A.divAssign(B(fe, 1e-6)), r || A.assign(Y(A.xyz, te));
595
602
  });
596
- }), U(m, p, k).toWriteOnly(), e === "post" && U(h, p, q(D, O)).toWriteOnly();
603
+ }), G(m, w, A).toWriteOnly(), e === "post" && G(h, w, Y(O, ee)).toWriteOnly();
597
604
  });
598
605
  });
599
606
  return this._dispatchOf(w);
600
607
  }
601
608
  _buildTemporalAccumulation() {
602
- 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();
609
+ 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._albedoTexNode, f = this.camView, p = this.prevCamView, m = this.camPos, h = this.prevCamPos, g = this.resW, _ = this.resH, v = this.inputFrames, y = this.resetU, b = Tn(([b, x]) => {
610
+ let S = R(X.x).mul(_i).add(R(z.x)), C = R(X.y).mul(_i).add(R(z.y));
611
+ F(S.lessThan(R(g)).and(C.lessThan(R(_))), () => {
612
+ let g = Rn(S, C), _ = Jn(K(S), K(C)), w = W(t, g).w, T = W(i, g).toVar();
613
+ F(w.greaterThanEqual(Gr), () => {
614
+ G(l, _, T).toWriteOnly(), G(u, _, Y(0)).toWriteOnly(), Dn();
608
615
  });
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));
616
+ let E = e.maxAccum.mul(L(1).sub(y)).toVar(), D = e.maxFast.mul(L(1).sub(y)).toVar(), O = W(n, g), k = Vn(O.xyz.mul(2).sub(1)).toVar(), ee = Ui(O.w).toVar(), te = this._pixelUv(S, C), ne = this._worldPosAt(te, w, b, x).toVar(), A = f.mul(Y(ne, 1)).z.abs().toVar(), j = I(k, this._viewVector(ne, m, this.viewVector)).abs().toVar(), re = this._frustumSize(A).toVar(), M = Xn(0).toVar();
617
+ M.addAssign(k.mul(.25));
611
618
  for (let e = -1; e <= 0; e++) for (let r = -1; r <= 0; r++) {
612
619
  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));
620
+ let i = this._clampCoord(S.add(r), C.add(e)), a = Vn(W(n, i).xyz.mul(2).sub(1)), o = W(t, i).w.lessThan(Gr);
621
+ M.addAssign(U(o, a, k).mul(.25));
615
622
  }
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 = [];
623
+ let ie = W(r, g), ae = te.sub(ie.xy).toVar(), oe = p.mul(Y(ne, 1)).z.abs().toVar(), se = this._bilinear(ae), ce = re.mul(H(e.disocclusionThreshold.div(B(j, .05)))).sub(ti).toVar(), le = L(1).sub(y), N = [], ue = [];
617
624
  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);
625
+ let t = W(c, se.taps[e]), n = U(I(t.xyz, M).greaterThan(fi), 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));
626
+ N.push(n.mul(r).mul(i).mul(se.inScreen[e]).mul(le).toVar()), ue.push(W(s, se.taps[e]).x);
620
627
  }
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();
628
+ let de = se.customWeights(N).map((e) => e.toVar()), fe = N[0].add(N[1]).add(N[2]).add(N[3]).greaterThan(3.5).toVar(), pe = N[0].add(N[1].mul(2)).add(N[2].mul(4)).add(N[3].mul(8)), me = this._applyCustomWeights(ue, de, L(0)).toVar(), he = I(k, this._viewVector(ne, h, this.prevViewVector)).abs().add(.001).div(j.add(.001)).toVar();
629
+ he.assign(V(L(.1), L(1), H(he.mul(he))));
630
+ let ge = Gn(H(se.filter(N))).mul(he).toVar();
631
+ me.assign(me.mul(V(ge, L(1), L(1).div(me.add(1))))), me.assign(Bn(me, E));
632
+ let _e = Ii(this._sampleHistory((e) => W(a, e), ae, se, de, fe)).toVar(), ve = B(this._applyCustomWeights(se.taps.map((e) => W(o, e).x), de, L(0)), 0).toVar(), ye = v.add(1), be = this._handover(ye).toVar(), xe = me.mul(L(1).sub(be)), Se = ye.div(ye.add(xe)).toVar(), P = L(1).div(L(1).add(wi(ee, .25).mul(.5).mul(E))), Ce = Y(V(_e.xyz, T.xyz, Se), V(_e.w, T.w, B(Se, P))).toVar(), we = e.fireflyMinRelativeScale.add(L(li).div(me.add(1))).toVar(), Te = me.mul(e.maxBlurRadius).mul(ui).toVar();
633
+ Te.assign(Te.div(Te.add(1)).mul(L(1).sub(be)));
634
+ let Ee = V(Ce.x, Bn(Ce.x, _e.x.mul(we)), Te);
635
+ Ce.assign(Fi(Ce, Ee));
636
+ let De = L(1.2).add(L(1).div(me.add(1)));
637
+ Ce.assign(Y(Ce.xyz, V(Ce.w, Bn(Ce.w, _e.w.mul(De)), Te))), G(l, _, Ce).toWriteOnly();
638
+ let Oe = Bn(me, D).mul(L(1).sub(be)), ke = ye.div(ye.add(Oe)), Ae = V(ve, T.x, ke).toVar(), je = Bn(Ae, _e.x.mul(we).mul(di));
639
+ Ae.assign(V(Ae, je, Te));
640
+ let Me = U(Bi(W(d, g)), L(gi), L(0));
641
+ G(u, _, Y(Ae, me, pe.add(Me), U(fe, L(1), L(0)))).toWriteOnly();
633
642
  });
634
643
  });
635
- return this._dispatchOf(y);
644
+ return this._dispatchOf(b);
636
645
  }
637
646
  _buildHistoryFix() {
638
647
  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();
648
+ let p = R(X.x).mul(_i).add(R(z.x)), m = R(X.y).mul(_i).add(R(z.y));
649
+ F(p.lessThan(R(c)).and(m.lessThan(R(l))), () => {
650
+ let h = Rn(p, m), g = Jn(K(p), K(m)), _ = W(t, h).w;
651
+ F(_.greaterThanEqual(Gr), () => {
652
+ let e = W(r, h);
653
+ G(a, g, e).toWriteOnly(), G(o, g, Y(e.x, 0, 0, 0)).toWriteOnly(), Dn();
645
654
  });
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
- 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));
655
+ 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 = Ui(S.w).toVar(), T = this._pixelUv(p, m), E = this._worldPosAt(T, _, d, f).toVar(), D = s.mul(Y(E, 1)).z.abs(), O = this._frustumSize(D).toVar(), k = W(r, h).toVar(), ee = L(1).div(b.add(1)).toVar(), te = D.mul(Jr).add(3), ne = H(k.w.mul(te).div(O)), A = k.w.toVar(), j = Un(U(b.lessThan(e.historyFixFrameNum), L(1), L(0)).mul(.5).mul(2 / ai).mul(e.historyFixStride).mul(V(L(.25).add(Gn(ne).mul(.75)), L(1), ee))).toVar(), re = Hi(S.w).toVar();
656
+ F(j.notEqual(0).and(re.not()), () => {
657
+ let a = Ei(ee, e.lobeAngleFraction, w, e.lobeVolumePercent).toVar(), o = Ai(e.planeDistSensitivity, O, E, C).toVar(), s = ki(A, ee).toVar(), u = Oi(w.mul(w), Gn(e.roughnessFraction), ri).toVar(), p = Vi(v).toVar(), m = L(1).add(y).toVar();
658
+ k.mulAssign(m);
659
+ for (let e = -ai; e <= ai; e++) for (let h = -ai; h <= ai; h++) {
660
+ if (h === 0 && e === 0 || Math.abs(h) + Math.abs(e) === ai * 2) continue;
661
+ let g = ji(T.add(J(h, e).mul(j).mul(J(L(1).div(c), L(1).div(l))))), _ = this._uvToCoord(g), v = W(t, _).w, y = this._worldPosAt(g, v, d, f), b = W(n, _), x = Si(Ci(I(Vn(b.xyz.mul(2).sub(1)), C)), a, L(0)).toVar(), S = Ui(b.w);
662
+ x.mulAssign(Si(S.mul(S), u.x, u.y));
663
+ let w = W(i, _);
664
+ x.mulAssign(L(1).add(w.y)), x.mulAssign(xi(I(C, y), o.x, o.y)), x.assign(U(this._excluded(v, b.w, Vi(w), p), L(0), x));
665
+ let E = Wi(x, W(r, _));
666
+ x.mulAssign(Si(E.w, s.x, s.y)), m.addAssign(x), k.addAssign(E.mul(x));
656
667
  }
657
- O.divAssign(R(p, 1e-6));
668
+ k.divAssign(B(m, 1e-6));
658
669
  });
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));
670
+ let M = k.x.toVar(), ie = H(y.div(B(e.historyFixFrameNum, ti))), ae = V(M, v.x, ie).toVar();
671
+ G(o, g, Y(ae, 0, 0, 0)).toWriteOnly();
672
+ let oe = ae.toVar(), se = ae.mul(ae).toVar(), ce = L(0).toVar(), le = L(0).toVar(), N = (e, n, r) => {
673
+ 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);
674
+ Math.abs(e) <= oi && Math.abs(n) <= oi && (oe.addAssign(s), se.addAssign(s.mul(s))), r && (ce.addAssign(s), le.addAssign(s.mul(s)));
675
+ }, ue = e.antiFirefly.greaterThan(.5);
676
+ for (let e = -oi; e <= oi; e++) for (let t = -oi; t <= oi; t++) t === 0 && e === 0 || N(t, e, Math.abs(t) > 1 || Math.abs(e) > 1);
677
+ F(ue, () => {
678
+ for (let e = -si; e <= si; e++) for (let t = -si; t <= si; t++) Math.abs(t) <= oi && Math.abs(e) <= oi || N(t, e, !0);
679
+ }), F(ue, () => {
680
+ let e = 1 / ((si * 2 + 1) ** 2 - 9), t = ce.mul(e), n = Li(t, le.mul(e)).mul(ci);
681
+ M.assign(V(M.clamp(t.sub(n), t.add(n)), M, x));
671
682
  });
672
683
  {
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));
684
+ let t = 1 / (oi * 2 + 1) ** 2, n = oe.mul(t), r = Li(n, se.mul(t)).mul(e.fastClampSigmaScale), i = M.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);
685
+ M.assign(V(i, M, o));
675
686
  }
676
- U(a, g, ji(O, A)).toWriteOnly();
687
+ G(a, g, U(re, k, Fi(k, M))).toWriteOnly();
677
688
  });
678
689
  });
679
690
  return this._dispatchOf(d);
@@ -681,56 +692,56 @@ var Li = class extends D {
681
692
  _buildTemporalStabilization(e) {
682
693
  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
694
  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();
695
+ let _ = R(X.x).mul(_i).add(R(z.x)), v = R(X.y).mul(_i).add(R(z.y));
696
+ F(_.lessThan(R(f)).and(v.lessThan(R(p))), () => {
697
+ let f = Rn(_, v), p = Jn(K(_), K(v)), y = W(i, f).w, b = W(n, f).toVar();
698
+ F(y.greaterThanEqual(Gr), () => {
699
+ 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
700
  });
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 = [
701
+ let x = W(a, f).w, S = Ui(x), C = this._pixelUv(_, v), w = W(o, f), T = C.sub(w.xy).toVar(), E = W(c, f).toVar(), D = E.y.toVar(), O = K(E.z.add(.5)).toVar(), k = E.w.greaterThan(.5), ee = this._bilinear(T), te = [
691
702
  1,
692
703
  2,
693
704
  4,
694
705
  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();
706
+ ].map((e) => U(O.bitAnd(K(e)).notEqual(K(0)), L(1), L(0))), ne = ee.customWeights(te).map((e) => e.toVar()), A = Gn(H(ee.filter(te))).toVar(), j = W(s, f).toVar(), re = j.x.toVar(), M = re.toVar(), ie = re.mul(re).toVar();
696
707
  for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
697
708
  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));
709
+ let n = this._clampCoord(_.add(t), v.add(e)), r = W(i, n).w, a = U(r.greaterThanEqual(Gr), re, W(s, n).x);
710
+ M.addAssign(a), ie.addAssign(a.mul(a));
700
711
  }
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))))));
712
+ M.divAssign(9), ie.divAssign(9);
713
+ let ae = Li(M, ie).toVar();
714
+ F(D.lessThan(t.historyFixFrameNum).and(Hi(x).not()), () => {
715
+ re.assign(Bn(re, M.mul(L(1.2).add(L(1).div(D.add(1))))));
705
716
  });
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)), () => {
721
- 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();
717
+ let oe = B(this._sampleHistory((e) => W(l, e), T, ee, ne, k).x, 0).toVar(), se = ae.mul(t.antilag.x), ce = t.antilag.y.mul(4), le = oe.clamp(M.sub(se), M.add(se)), N = oe.sub(le).abs().div(B(oe, le).add(ti)), ue = L(1).div(L(1).add(N.mul(D.mul(A)).div(ce))).toVar(), de = Bn(D, t.historyFixFrameNum);
718
+ D.assign(V(de, D, ue));
719
+ let fe = m.add(1), pe = this._handover(fe), me = A.mul(L(1).sub(this._advancedNonLinear(D.mul(L(1).sub(pe)).div(fe)))).mul(ue).toVar(), he = L(1).add(me.mul(6)), ge = t.stabilizationStrength.mul(L(1).sub(h)), _e = V(re, oe.clamp(M.sub(ae.mul(he)), M.add(ae.mul(he))), Bn(me, ge)).toVar();
720
+ j.assign(Fi(j, _e)), G(e, p, Y(_e, 0, 0, 0)).toWriteOnly();
721
+ let ve = t.maxAccum.mul(L(1).sub(h));
722
+ G(u, p, Y(Bn(D.add(1), ve), S, 0, 0)).toWriteOnly();
723
+ let ye = W(r, f), be = Y(Ni(j.xyz).mul(zi(ye.xyz)), b.w).toVar();
724
+ F(g.equal(R(1)), () => {
725
+ let e = H(D.div(B(t.maxAccum, 1)));
726
+ be.assign(Y(L(1).sub(e), e, .2, 1));
727
+ }).ElseIf(g.equal(R(2)), () => {
728
+ be.assign(Y(Xn(j.w), 1));
729
+ }).ElseIf(g.equal(R(3)), () => {
730
+ be.assign(Y(Xn(S), 1));
731
+ }).ElseIf(g.equal(R(4)), () => {
732
+ let e = E.x.div(E.x.add(1));
733
+ be.assign(Y(Xn(e), 1));
734
+ }).ElseIf(g.equal(R(5)), () => {
735
+ be.assign(Y(Xn(L(O.bitAnd(K(15))).div(15)), 1));
736
+ }), G(d, p, be).toWriteOnly();
726
737
  });
727
738
  })().compute([
728
739
  this._dispatchX,
729
740
  this._dispatchY,
730
741
  1
731
742
  ], [
732
- Q,
733
- Q,
743
+ _i,
744
+ _i,
734
745
  1
735
746
  ]);
736
747
  }
@@ -750,7 +761,7 @@ var Li = class extends D {
750
761
  }
751
762
  _updateRotators(e) {
752
763
  let t = (t, n) => {
753
- let r = Ii(e * 3 + n) * Math.PI * 2;
764
+ let r = Gi(e * 3 + n) * Math.PI * 2;
754
765
  t.value.set(Math.cos(r), Math.sin(r), -Math.sin(r), Math.cos(r));
755
766
  };
756
767
  t(this.rotPre, 0), t(this.rotBlur, 1), t(this.rotPost, 2);
@@ -777,7 +788,7 @@ var Li = class extends D {
777
788
  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
789
  }
779
790
  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);
791
+ this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e / _i), this._dispatchY = Math.ceil(t / _i);
781
792
  let n = [
782
793
  this._dispatchX,
783
794
  this._dispatchY,
@@ -806,7 +817,7 @@ var Li = class extends D {
806
817
  for (let [e, t] of this._placeholders) e.dispose(), t.dispose();
807
818
  this._placeholders.clear();
808
819
  }
809
- }, Ri = {
820
+ }, qi = {
810
821
  autoExposure: !1,
811
822
  autoExposureMetering: "center",
812
823
  autoExposureStrength: .3,
@@ -815,120 +826,124 @@ var Li = class extends D {
815
826
  autoExposureMaxExposure: 2 ** 8,
816
827
  autoExposureAdaptSpeedBright: 3,
817
828
  autoExposureAdaptSpeedDark: 1
818
- }, zi = [
829
+ }, Ji = [
819
830
  "average",
820
831
  "center",
821
832
  "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 = [
833
+ ], Yi = 64, Xi = 8, Zi = 8, Qi = 256, $i = -16, ea = (12 - $i) / Qi, ta = 2 ** -24, na = 65536, ra = 256, ia = 128, aa = 1.5, oa = .01, sa = .06, ca = .25, la = 4, ua = .3, da = 1.5, fa = 3, pa = [
823
834
  .2126,
824
835
  .7152,
825
836
  .0722
826
- ];
827
- function aa(e, t, n, r, i) {
837
+ ], ma = .999, ha = {
838
+ transparent: 0,
839
+ environment: 1,
840
+ color: 2
841
+ };
842
+ function ga(e, t, n, r, i) {
828
843
  let a = t - e;
829
844
  if (a === 0 || !(n > 0)) return e;
830
845
  let o = Math.max(a < 0 ? r : i, .001);
831
846
  if (n === Infinity) return t;
832
- let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n / Xi)));
847
+ let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n / aa)));
833
848
  return e + Math.sign(a) * s;
834
849
  }
835
- function oa(e, t, n) {
850
+ function _a(e, t, n) {
836
851
  let r = Math.abs(e);
837
- return e * (r <= na ? n : r >= ra ? 1 : n + (1 - n) * (r - na) / (ra - na)) + n * (t - e);
852
+ return e * (r <= da ? n : r >= fa ? 1 : n + (1 - n) * (r - da) / (fa - da)) + n * (t - e);
838
853
  }
839
- function sa(e, t) {
840
- if (!e) return t.fromArray(ia);
854
+ function va(e, t) {
855
+ if (!e) return t.fromArray(pa);
841
856
  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]);
857
+ return t.set(pa[0] * n[0] + pa[1] * n[1] + pa[2] * n[2], pa[0] * n[3] + pa[1] * n[4] + pa[2] * n[5], pa[0] * n[6] + pa[1] * n[7] + pa[2] * n[8]);
843
858
  }
844
- var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
859
+ var ya = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, ba = class extends A {
845
860
  constructor(e, t = {}) {
846
861
  super("AutoExposure", {
847
862
  ...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 = {
863
+ executionMode: j.ALWAYS
864
+ }), this.renderer = e, this.metering = t.metering ?? qi.autoExposureMetering, this.meteringPoint = new Rr(.5, .5), this.keyValue = t.keyValue ?? qi.autoExposureKeyValue, this.minExposure = t.minExposure ?? qi.autoExposureMinExposure, this.maxExposure = t.maxExposure ?? qi.autoExposureMaxExposure, this.adaptSpeedBright = t.adaptSpeedBright ?? qi.autoExposureAdaptSpeedBright, this.adaptSpeedDark = t.adaptSpeedDark ?? qi.autoExposureAdaptSpeedDark, this.centerWeight = t.centerWeight ?? 8, this.strength = t.strength ?? qi.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(pa)), this._backdropModeU = q(ha.transparent, "int"), this._widthU = q(1, "int"), this._heightU = q(1, "int"), this._strideU = q(1, "int"), this._gridXU = q(Yi, "int"), this._gridYU = q(Yi, "int"), this._inputNode = new Cn(), this._workingMatrix = void 0, this._histogram = Mn(Qi, "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
865
  restarts: -1,
851
866
  samples: -1
852
867
  }, this._stale = !1, this._disposed = !1;
853
868
  }
854
869
  _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;
870
+ 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
871
  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();
872
+ let d = z.y.mul(K(Zi)).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(Zi)), y = L(0).toVar(), b = L(0).toVar();
858
873
  En({
859
- start: h.add(I(L.y)),
860
- end: g,
874
+ start: g.add(R(z.y)),
875
+ end: _,
861
876
  type: "int",
862
877
  condition: "<",
863
- update: _,
878
+ update: v,
864
879
  name: "py"
865
880
  }, ({ py: t }) => {
866
881
  En({
867
- start: p.add(I(L.x)),
868
- end: m,
882
+ start: m.add(R(z.x)),
883
+ end: h,
869
884
  type: "int",
870
885
  condition: "<",
871
- update: _,
886
+ update: v,
872
887
  name: "px"
873
888
  }, ({ 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);
889
+ 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(ha.environment)), L(1), U(u.equal(R(ha.color)), U(o.greaterThanEqual(ma), L(1), L(0)), o));
890
+ y.addAssign(U(a, i.clamp(0, 1e6), L(0)).mul(c)), b.addAssign(c);
876
891
  });
877
892
  });
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))));
893
+ let x = Zn("float", Zi * Zi), S = Zn("float", Zi * Zi);
894
+ x.element(d).assign(y), S.element(d).assign(b), Qn();
895
+ for (let e = Zi * Zi >> 1; e > 0; e >>= 1) F(d.lessThan(K(e)), () => {
896
+ x.element(d).addAssign(x.element(d.add(K(e)))), S.element(d).addAssign(S.element(d.add(K(e))));
882
897
  }), 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)), () => {
898
+ F(d.equal(K(0)), () => {
899
+ let e = x.element(K(0)).toVar(), i = S.element(K(0)).toVar(), a = (e) => e.div(v).mul(R(Zi)).add(Bn(e.mod(v), R(Zi))), o = L(a(h.sub(m)).mul(a(_.sub(g))));
900
+ F(i.greaterThan(0).and(e.greaterThan(i.mul(ta))), () => {
901
+ let a = K(zn(e.div(i)).sub($i).div(ea).floor().clamp(0, Qi - 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(na).add(.5));
902
+ F(u.greaterThan(K(0)), () => {
888
903
  kn(t.element(a), u);
889
904
  });
890
905
  });
891
906
  });
892
907
  })().compute([
893
- Bi,
894
- Bi,
908
+ Yi,
909
+ Yi,
895
910
  1
896
911
  ], [
897
- Hi,
898
- Hi,
912
+ Zi,
913
+ Zi,
899
914
  1
900
915
  ]);
901
916
  }
902
917
  _buildResolveKernel() {
903
918
  let e = this._histogram, t = this._result, n = this._lowU, r = this._highU;
904
919
  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);
920
+ let i = z.x, a = L(An(e.element(i))).toVar();
921
+ jn(e.element(i), K(0));
922
+ let o = Zn("float", Qi), s = Zn("float", Qi);
908
923
  o.element(i).assign(a), Qn();
909
- for (let e = 1; e < Ui; e <<= 1) {
924
+ for (let e = 1; e < Qi; e <<= 1) {
910
925
  let t = o.element(i).toVar();
911
- N(i.greaterThanEqual(W(e)), () => {
912
- t.addAssign(o.element(i.sub(W(e))));
926
+ F(i.greaterThanEqual(K(e)), () => {
927
+ t.addAssign(o.element(i.sub(K(e))));
913
928
  }), Qn(), o.element(i).assign(t), Qn();
914
929
  }
915
- let c = o.element(W(Ui - 1)).toVar(), l = o.element(i).toVar();
930
+ let c = o.element(K(Qi - 1)).toVar(), l = o.element(i).toVar();
916
931
  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))));
932
+ let u = B(Bn(l, c.mul(r)).sub(B(l.sub(a), c.mul(n))), 0);
933
+ o.element(i).assign(u), s.element(i).assign(u.mul(L(i).add(.5).mul(ea).add($i))), Qn();
934
+ for (let e = Qi >> 1; e > 0; e >>= 1) F(i.lessThan(K(e)), () => {
935
+ o.element(i).addAssign(o.element(i.add(K(e)))), s.element(i).addAssign(s.element(i.add(K(e))));
921
936
  }), 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));
937
+ F(i.equal(K(0)), () => {
938
+ let e = o.element(K(0));
939
+ t.element(K(0)).assign(Y(s.element(K(0)).div(B(e, 1e-6)), c.div(na), e.div(na), 1));
925
940
  });
926
941
  })().compute([
927
942
  1,
928
943
  1,
929
944
  1
930
945
  ], [
931
- Ui,
946
+ Qi,
932
947
  1,
933
948
  1
934
949
  ]);
@@ -940,7 +955,7 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
940
955
  if (!this.enabled) return;
941
956
  let t = e.getState("pathtracer:samples") ?? 0;
942
957
  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;
958
+ let n = this._meteredAt, r = this._stale || this._targetEV === null || n.restarts !== this._restarts || t - n.samples >= ya(t), i = t < this.holdSamples && this._targetEV !== null && !this._stale;
944
959
  r && !i && this._meter(e, t);
945
960
  }
946
961
  e.setState("autoexposure:value", this.renderer.toneMappingExposure), e.setState("autoexposure:avgLuminance", this.luminance);
@@ -955,13 +970,13 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
955
970
  if (!n || r < 1 || i < 1 || this._disposed) return null;
956
971
  this._meteredAt.restarts = this._restarts, this._meteredAt.samples = t, this._stale = !1;
957
972
  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);
973
+ a !== this._workingMatrix && (this._workingMatrix = a, va(a, this._lumWeightsU.value));
974
+ let o = Math.min(Yi, Math.max(1, Math.floor(r / Xi))), s = Math.min(Yi, Math.max(1, Math.floor(i / Xi))), c = r / o * (i / s);
960
975
  this._gridXU.value = o, this._gridYU.value = s, this._kernels[0].dispatchSize = [
961
976
  o,
962
977
  s,
963
978
  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);
979
+ ], this._strideU.value = Math.max(1, Math.round(Math.sqrt(c / ra))), this._widthU.value = r, this._heightU.value = i, this._backdropModeU.value = ha[e.getState("pathtracer:backdrop")] ?? ha.transparent, this._updateMeteringPattern(r / i), this._inputNode.value = n, this.renderer.compute(this._kernels);
965
980
  let l = this._generation, u = {
966
981
  restarts: this._restarts,
967
982
  moves: this._viewMoves
@@ -977,7 +992,7 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
977
992
  let t = this._falloffU.value, n = this._pointU.value;
978
993
  if (this.metering === "average") t.set(0, 0);
979
994
  else if (this.metering === "spot") {
980
- t.set(Yi * e * e, Yi), n.copy(this.meteringPoint);
995
+ t.set(ia * e * e, ia), n.copy(this.meteringPoint);
981
996
  return;
982
997
  } else t.set(this.centerWeight, this.centerWeight);
983
998
  n.set(.5, .5);
@@ -986,25 +1001,25 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
986
1001
  let [n, r, i] = e;
987
1002
  if (!this.enabled || !(r > 0 && i > 0) || !Number.isFinite(n)) return null;
988
1003
  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;
1004
+ 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 + ua, this._landed = t;
1005
+ let o = this._aim(), s = this._targetEV === null || Math.abs(o - this._targetEV) > oa;
991
1006
  return this._targetEV = o, (s || this.settling) && this.onChange?.(), n;
992
1007
  }
993
1008
  update(e = performance.now()) {
994
- let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3, $i), n = this.advance(t, this._accumulating);
1009
+ let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3, ca), n = this.advance(t, this._accumulating);
995
1010
  return this._lastUpdate = this.settling || this._clock <= this._movingUntil ? e : null, n;
996
1011
  }
997
1012
  advance(e, t = !1) {
998
1013
  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()));
1014
+ e > 0 && e !== Infinity && (this._clock += e, this._clock <= this._movingUntil && (this._roomEV += (this._viewEV - this._roomEV) * (1 - Math.exp(-Math.min(e, ca) / la)), this._targetEV = this._aim()));
1000
1015
  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);
1016
+ return this._snap || this.instant ? (this._exposureEV = this._targetEV, this._snap = !1) : (this._exposureEV = t ? n + (this._targetEV - n) * (1 - Math.exp(-e / sa)) : ga(n, this._targetEV, e, this.adaptSpeedBright, this.adaptSpeedDark), Math.abs(this._targetEV - this._exposureEV) <= oa && (this._exposureEV = this._targetEV)), this._exposureEV === n ? !1 : (this._apply(), !0);
1002
1017
  }
1003
1018
  _inRange(e) {
1004
1019
  return Math.min(Math.max(e, Math.log2(this.minExposure)), Math.log2(this.maxExposure));
1005
1020
  }
1006
1021
  _aim() {
1007
- return this._inRange(oa(this._roomEV, this._viewEV, this.strength));
1022
+ return this._inRange(_a(this._roomEV, this._viewEV, this.strength));
1008
1023
  }
1009
1024
  noteViewChanged() {
1010
1025
  this._viewMoves++;
@@ -1047,7 +1062,7 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
1047
1062
  }
1048
1063
  updateParameters(e) {
1049
1064
  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);
1065
+ t !== void 0 && Ji.includes(t) && (this.metering = t), e.meteringPoint && this.meteringPoint.set(e.meteringPoint.x, e.meteringPoint.y);
1051
1066
  for (let t of [
1052
1067
  "keyValue",
1053
1068
  "minExposure",
@@ -1070,32 +1085,32 @@ var ca = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, la = class extends D {
1070
1085
  for (let e of this._kernels) e.dispose();
1071
1086
  this._readback.dispose(), this._inputNode.dispose();
1072
1087
  }
1073
- }, ua = {
1088
+ }, xa = {
1074
1089
  localExposure: !1,
1075
1090
  localExposureHighlightContrast: .6,
1076
1091
  localExposureShadowContrast: 1,
1077
1092
  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 = [
1093
+ }, Sa = 128, Ca = (Sa / 2) ** 2, $ = 32, wa = -16, Ta = 16, Ea = -40, Da = 40, Oa = 256, ka = 32, Aa = .6, ja = 50, Ma = Math.log2(.18), Na = .999, Pa = 2 ** -24, Fa = Math.ceil(re / Sa), Ia = Math.ceil(re / ka), La = [
1079
1094
  .2126,
1080
1095
  .7152,
1081
1096
  .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;
1097
+ ], Ra = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, za = (e, t, n) => Math.min(Math.max(e, t), n);
1098
+ function Ba(e, t, n, r, i, a, o) {
1099
+ let s = Math.min(Math.log2(Math.max(a, Pa)), Da), c = e[6], l = e[7], u = za(r * e[2] - .5, 0, c - 1), d = za(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 = za(r * e[0] - .5, 0, b - 1), C = za(i * e[1] - .5, 0, x - 1), w = za((s + e[8] - wa) / (Ta - wa), 0, 1) * ($ - 1), T = Math.floor(S), E = Math.floor(C), D = Math.floor(w), O = S - T, k = C - E, ee = w - D, te = 0, ne = 0;
1085
1100
  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;
1101
+ let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? O : 1 - O) * (r ? k : 1 - k) * (i ? ee : 1 - ee), o = ((Math.min(E + r, x - 1) * b + Math.min(T + n, b - 1)) * $ + Math.min(D + i, $ - 1)) * 2;
1087
1102
  te += t[o] * a, ne += t[o + 1] * a;
1088
1103
  }
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);
1104
+ let A = ne * Ca < .001 ? y : te / ne, j = A + (y - A) * e[12] + o, re = s + o, M = j > e[13] ? e[9] : e[10];
1105
+ return 2 ** (e[13] + (j - e[13]) * M + (re - j) * e[11] - re);
1091
1106
  }
1092
- var ka = `
1107
+ var Va = `
1093
1108
  @group(1) @binding(0) var<storage, read> leGrid: array<vec2<f32>>;
1094
1109
  @group(1) @binding(1) var<storage, read> leBlur: array<f32>;
1095
1110
  @group(1) @binding(2) var<uniform> le: array<vec4<f32>, 4>;
1096
1111
 
1097
1112
  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 );
1113
+ let logL = min( log2( max( dot( linear, vec3<f32>( ${La.join(", ")} ) ), ${Pa} ) ), ${Da}.0 );
1099
1114
  let logExposure = log2( exposure );
1100
1115
 
1101
1116
  let bs = vec2<i32>( le[ 1 ].zw );
@@ -1109,7 +1124,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1109
1124
 
1110
1125
  let cs = vec2<i32>( le[ 1 ].xy );
1111
1126
  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;
1127
+ let gz = clamp( ( logL + le[ 2 ].x - (${wa}.0) ) / ${Ta - wa}.0, 0.0, 1.0 ) * ${$ - 1}.0;
1113
1128
  let g0 = vec3<i32>( vec2<i32>( floor( gp ) ), i32( floor( gz ) ) );
1114
1129
  let gf = vec3<f32>( gp - floor( gp ), gz - floor( gz ) );
1115
1130
  var acc = vec2<f32>( 0.0 );
@@ -1120,26 +1135,26 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1120
1135
  acc += leGrid[ ( c.y * cs.x + c.x ) * ${$} + c.z ] * ( wv.x * wv.y * wv.z );
1121
1136
  }
1122
1137
 
1123
- let bilateral = select( acc.x / acc.y, blurred, acc.y * ${fa}.0 < 1e-3 );
1138
+ let bilateral = select( acc.x / acc.y, blurred, acc.y * ${Ca}.0 < 1e-3 );
1124
1139
  let base = mix( bilateral, blurred, le[ 3 ].x ) + logExposure;
1125
1140
  let y = logL + logExposure;
1126
1141
  let contrast = select( le[ 2 ].z, le[ 2 ].y, base > le[ 3 ].y );
1127
1142
  return exp2( le[ 3 ].y + ( base - le[ 3 ].y ) * contrast + ( y - base ) * le[ 2 ].w - y );
1128
1143
  }
1129
- `, Aa = class extends D {
1144
+ `, Ha = class extends A {
1130
1145
  constructor(e, t = {}) {
1131
1146
  super("LocalExposure", {
1132
1147
  ...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 = [
1148
+ executionMode: j.ALWAYS
1149
+ }), this.renderer = e, this.highlightContrast = t.highlightContrast ?? xa.localExposureHighlightContrast, this.shadowContrast = t.shadowContrast ?? xa.localExposureShadowContrast, this.detailStrength = t.detailStrength ?? xa.localExposureDetailStrength, this.onChange = null, this._grid = Mn(Fa * Fa * $, "vec2"), this._blur = Mn(Ia * Ia, "float"), this._blurSource = Mn(Ia * Ia, "vec2"), this._blurTmp = Mn(Ia * Ia, "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 = [
1150
+ new zr(),
1151
+ new zr(),
1152
+ new zr(),
1153
+ new zr()
1154
+ ].map((e) => q(e)), this._params = new Float32Array(16), this._kernels = [
1140
1155
  this._buildGridKernel(),
1141
1156
  this._buildBlurSourceKernel(),
1142
- this._buildBlurKernel(this._blur, this._blurTmp, !0),
1157
+ this._buildBlurKernel(this._blurSource, this._blurTmp, !0),
1143
1158
  this._buildBlurKernel(this._blurTmp, this._blur, !1)
1144
1159
  ], this._built = !1, this._restarts = 0, this._builtAt = {
1145
1160
  restarts: -1,
@@ -1147,41 +1162,41 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1147
1162
  }, this._stale = !1, this._paramsBuffer = null, this._disposed = !1;
1148
1163
  }
1149
1164
  _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;
1165
+ 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(...La, 0).xyz;
1151
1166
  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));
1167
+ let c = z.y.mul(K(16)).add(z.x), l = Zn("uint", $).toAtomic(), u = Zn("uint", $).toAtomic();
1168
+ F(c.lessThan(K($)), () => {
1169
+ jn(l.element(c), K(0)), jn(u.element(c), K(0));
1155
1170
  }), 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)));
1171
+ let d = R(X.x).mul(R(Sa)).add(R(z.x).mul(R(8))), f = R(X.y).mul(R(Sa)).add(R(z.y).mul(R(8)));
1157
1172
  En({
1158
- start: I(0),
1159
- end: I(8),
1173
+ start: R(0),
1174
+ end: R(8),
1160
1175
  type: "int",
1161
1176
  condition: "<",
1162
1177
  update: 2,
1163
1178
  name: "ty"
1164
1179
  }, ({ ty: t }) => {
1165
1180
  En({
1166
- start: I(0),
1167
- end: I(8),
1181
+ start: R(0),
1182
+ end: R(8),
1168
1183
  type: "int",
1169
1184
  condition: "<",
1170
1185
  update: 2,
1171
1186
  name: "tx"
1172
1187
  }, ({ 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)));
1188
+ let c = d.add(i), p = f.add(t);
1189
+ F(c.lessThan(n).and(p.lessThan(r)), () => {
1190
+ 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(Na)), 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();
1191
+ F(Fn(S).bitAnd(K(2139095040)).notEqual(K(2139095040)).and(x.greaterThan(0)), () => {
1192
+ let e = zn(B(S, Pa)).clamp(Ea, Da).toVar(), t = e.add(a).sub(wa).div(Ta - wa).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(Ea).mul(Oa);
1193
+ kn(l.element(n), K(s.mul(o).add(.5))), kn(u.element(n), K(o.mul(Oa).add(.5))), kn(l.element(r), K(s.mul(i).add(.5))), kn(u.element(r), K(i.mul(Oa).add(.5)));
1179
1194
  });
1180
1195
  });
1181
1196
  });
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));
1197
+ }), Qn(), F(c.lessThan(K($)), () => {
1198
+ let e = L(An(u.element(c))).div(Oa), n = L(An(l.element(c))).div(Oa).add(e.mul(Ea)), r = K(X.y).mul(K(i)).add(K(X.x));
1199
+ t.element(r.mul(K($)).add(c)).assign(J(n, e).div(Ca));
1185
1200
  });
1186
1201
  })().compute([
1187
1202
  1,
@@ -1194,40 +1209,40 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1194
1209
  ]);
1195
1210
  }
1196
1211
  _buildBlurSourceKernel() {
1197
- let e = this._inputNode, t = this._blur, n = this._widthU, r = this._heightU, i = this._blurWU, a = q(...Ta, 0).xyz;
1212
+ let e = this._inputNode, t = this._blurSource, n = this._widthU, r = this._heightU, i = this._blurWU, a = this._sceneOnlyU.greaterThan(R(0)), o = Y(...La, 0).xyz;
1198
1213
  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();
1214
+ let s = z.y.mul(K(8)).add(z.x), c = R(X.x).mul(R(ka)), l = R(X.y).mul(R(ka)), u = L(0).toVar(), d = L(0).toVar(), f = L(0).toVar();
1200
1215
  En({
1201
- start: I(L.y),
1202
- end: I(va),
1216
+ start: R(z.y),
1217
+ end: R(ka),
1203
1218
  type: "int",
1204
1219
  condition: "<",
1205
1220
  update: 8,
1206
1221
  name: "by"
1207
1222
  }, ({ by: t }) => {
1208
1223
  En({
1209
- start: I(L.x),
1210
- end: I(va),
1224
+ start: R(z.x),
1225
+ end: R(ka),
1211
1226
  type: "int",
1212
1227
  condition: "<",
1213
1228
  update: 8,
1214
1229
  name: "bx"
1215
1230
  }, ({ 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)));
1231
+ let s = c.add(i), p = l.add(t);
1232
+ F(s.lessThan(n).and(p.lessThan(r)), () => {
1233
+ 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(Na)), L(0), L(1));
1234
+ 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
1235
  });
1221
1236
  });
1222
1237
  });
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))));
1238
+ let p = Zn("float", 64), m = Zn("float", 64), h = Zn("float", 64);
1239
+ p.element(s).assign(u), m.element(s).assign(d), h.element(s).assign(f), Qn();
1240
+ for (let e = 32; e > 0; e >>= 1) F(s.lessThan(K(e)), () => {
1241
+ 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
1242
  }), 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));
1243
+ F(s.equal(K(0)), () => {
1244
+ let e = zn(B(p.element(K(0)).div(B(m.element(K(0)), 1)), Pa)).clamp(Ea, Da), n = U(a, m.element(K(0)).div(B(h.element(K(0)), 1)), L(1)).toVar();
1245
+ t.element(K(R(X.y).mul(i).add(R(X.x)))).assign(J(e.mul(n), n));
1231
1246
  });
1232
1247
  })().compute([
1233
1248
  1,
@@ -1242,23 +1257,25 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1242
1257
  _buildBlurKernel(e, t, n) {
1243
1258
  let r = this._blurWU, i = this._blurHU, a = this._radiusU;
1244
1259
  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();
1260
+ let o = R(X.x).mul(R(8)).add(R(z.x)), s = R(X.y).mul(R(8)).add(R(z.y));
1261
+ F(o.lessThan(r).and(s.lessThan(i)), () => {
1262
+ let c = n ? r : i, l = n ? o : s, u = R(a.ceil()), d = J(0).toVar(), f = L(0).toVar();
1248
1263
  En({
1249
1264
  start: u.negate(),
1250
- end: u.add(I(1)),
1265
+ end: u.add(R(1)),
1251
1266
  type: "int",
1252
1267
  condition: "<",
1253
1268
  name: "o"
1254
1269
  }, ({ 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)));
1270
+ 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();
1271
+ F(m.greaterThanEqual(c), () => {
1272
+ m.assign(p.sub(m).sub(R(1)));
1258
1273
  });
1259
1274
  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));
1275
+ d.addAssign(e.element(K(h)).mul(u)), f.addAssign(u);
1276
+ });
1277
+ let p = d.div(f).toVar();
1278
+ t.element(K(s.mul(r).add(o))).assign(n ? p : p.x.div(B(p.y, 1e-30)));
1262
1279
  });
1263
1280
  })().compute([
1264
1281
  1,
@@ -1276,14 +1293,14 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1276
1293
  render(e) {
1277
1294
  if (!this.enabled) return;
1278
1295
  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);
1296
+ (this._stale || !this._built || n.restarts !== this._restarts || t - n.samples >= Ra(t)) && this.build(e);
1280
1297
  }
1281
1298
  build(e = this.context) {
1282
1299
  let t = e?.getTexture("pathtracer:color"), n = t?.image?.width | 0, r = t?.image?.height | 0;
1283
1300
  if (!t || n < 1 || r < 1 || this._disposed) return !1;
1284
1301
  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 = [
1302
+ let i = Math.min(Fa, Math.ceil(n / Sa)), a = Math.min(Fa, Math.ceil(r / Sa)), o = Math.min(Ia, Math.ceil(n / ka)), s = Math.min(Ia, Math.ceil(r / ka)), c = Math.log2(Math.max(this.renderer.toneMappingExposure, 1e-6));
1303
+ 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, ja / 100 * o), this._logExposureU.value = c, this._sceneOnlyU.value = +(e.getState("pathtracer:backdrop") === "color"), this._kernels[0].dispatchSize = [
1287
1304
  i,
1288
1305
  a,
1289
1306
  1
@@ -1296,10 +1313,10 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1296
1313
  Math.ceil(s / 8),
1297
1314
  1
1298
1315
  ], this.renderer.compute(this._kernels), this._params.set([
1299
- n / da,
1300
- r / da,
1301
- n / va,
1302
- r / va,
1316
+ n / Sa,
1317
+ r / Sa,
1318
+ n / ka,
1319
+ r / ka,
1303
1320
  i,
1304
1321
  a,
1305
1322
  o,
@@ -1309,7 +1326,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1309
1326
  }
1310
1327
  _writeParams() {
1311
1328
  let e = this._params;
1312
- e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] = ya, e[13] = xa;
1329
+ e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] = Aa, e[13] = Ma;
1313
1330
  for (let t = 0; t < 4; t++) this._p[t].value.fromArray(e, t * 4);
1314
1331
  this.onChange?.();
1315
1332
  }
@@ -1328,15 +1345,15 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1328
1345
  this.enabled !== e && (this.enabled = e, this._stale = !0, this.onChange?.());
1329
1346
  }
1330
1347
  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;
1348
+ let n = Kn(this._grid.value, "vec2", Fa * Fa * $).toReadOnly(), r = Kn(this._blur.value, "float", Ia * Ia).toReadOnly(), [i, a, o, s] = this._p;
1332
1349
  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();
1350
+ let c = zn(B(I(e, Y(...La, 0).xyz), Pa)).min(Da).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(wa).div(Ta - wa).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
1351
  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));
1352
+ 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));
1353
+ E.addAssign(n.element(K(s.mul(_.x).add(o).mul(R($)).add(c))).mul(a));
1337
1354
  }
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);
1339
- return Pn(s.y.add(D.sub(s.y).mul(O)).add(ee.sub(D).mul(o.w)).sub(ee));
1355
+ let D = V(U(E.y.mul(Ca).lessThan(.001), g, E.x.div(E.y)), g, s.x).add(l).toVar(), O = c.add(l), k = U(D.greaterThan(s.y), o.y, o.z);
1356
+ return Pn(s.y.add(D.sub(s.y).mul(k)).add(O.sub(D).mul(o.w)).sub(O));
1340
1357
  })(e, t);
1341
1358
  }
1342
1359
  toneGain() {
@@ -1351,7 +1368,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1351
1368
  let r = this._params.slice(), i = () => Promise.all([this.renderer.getArrayBufferAsync(this._grid.value), this.renderer.getArrayBufferAsync(this._blur.value)]);
1352
1369
  return {
1353
1370
  key: "local-exposure",
1354
- wgsl: ka,
1371
+ wgsl: Va,
1355
1372
  device: e.device,
1356
1373
  entries: [
1357
1374
  {
@@ -1369,7 +1386,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1369
1386
  ],
1370
1387
  cpu: async () => {
1371
1388
  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);
1389
+ return (e, t, i, o) => Ba(r, n, a, e, t, i, o);
1373
1390
  },
1374
1391
  copyTo: async (e) => {
1375
1392
  let [t, n] = await i(), a = [
@@ -1386,7 +1403,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1386
1403
  });
1387
1404
  return {
1388
1405
  key: "local-exposure",
1389
- wgsl: ka,
1406
+ wgsl: Va,
1390
1407
  device: e,
1391
1408
  entries: a.map((e, t) => ({
1392
1409
  binding: t,
@@ -1404,16 +1421,16 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1404
1421
  for (let e of this._kernels) e.dispose();
1405
1422
  this._inputNode.dispose(), this._paramsBuffer?.destroy(), this._paramsBuffer = null;
1406
1423
  }
1407
- }, ja = new Z(), Ma = new Z();
1408
- function Na(e, t) {
1409
- return Ma.subVectors(e, t.position).dot(t.getWorldDirection(ja));
1424
+ }, Ua = new Q(), Wa = new Q();
1425
+ function Ga(e, t) {
1426
+ return Wa.subVectors(e, t.position).dot(t.getWorldDirection(Ua));
1410
1427
  }
1411
- function Pa(e, t, n = !1) {
1412
- return n ? e.distance : Na(e.point, t);
1428
+ function Ka(e, t, n = !1) {
1429
+ return n ? e.distance : Ga(e.point, t);
1413
1430
  }
1414
- var Fa = class extends ur {
1431
+ var qa = class extends ur {
1415
1432
  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;
1433
+ 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
1434
  }
1418
1435
  setDependencies({ overlayManager: e, transformManager: t, appDispatch: n, orbitControls: r, helperScene: i }) {
1419
1436
  this._overlayManager = e || null, this._transformManager = t || null, this._appDispatch = n || null, this._orbitControls = r || null, this._helperScene = i || null;
@@ -1421,7 +1438,7 @@ var Fa = class extends ur {
1421
1438
  select(e) {
1422
1439
  let t = this._overlayManager?.getHelper("outline");
1423
1440
  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,
1441
+ type: P.OBJECT_SELECTED,
1425
1442
  object: e || null
1426
1443
  });
1427
1444
  }
@@ -1445,7 +1462,7 @@ var Fa = class extends ur {
1445
1462
  this.raycaster.setFromCamera(t, this.camera);
1446
1463
  let n = this._intersectScene();
1447
1464
  if (n.length > 0) {
1448
- let e = n[0], t = this.pathTracer?.cameraProjection?.value === Oe.equirectangular, r = Pa(e, this.camera, t);
1465
+ let e = n[0], t = this.pathTracer?.cameraProjection?.value === Oe.equirectangular, r = Ka(e, this.camera, t);
1449
1466
  this.showFocusPoint(e.point), this.toggleFocusMode(), this.dispatchEvent({
1450
1467
  type: "focusChanged",
1451
1468
  distance: r / this.assetLoader.getSceneScale(),
@@ -1454,7 +1471,7 @@ var Fa = class extends ur {
1454
1471
  }
1455
1472
  }
1456
1473
  showFocusPoint(e) {
1457
- this.focusPointIndicator && this.scene.remove(this.focusPointIndicator), this.focusPointIndicator = new yr(new Nr(this.assetLoader.getSceneScale() * .02, 16, 16), new br({
1474
+ this.focusPointIndicator && this.scene.remove(this.focusPointIndicator), this.focusPointIndicator = new br(new Pr(this.assetLoader.getSceneScale() * .02, 16, 16), new xr({
1458
1475
  color: 65280,
1459
1476
  transparent: !0,
1460
1477
  opacity: .8,
@@ -1585,7 +1602,8 @@ var Fa = class extends ur {
1585
1602
  };
1586
1603
  }
1587
1604
  _intersectScene() {
1588
- return this.isGeometryOnDisk?.() ? [] : this.raycaster.intersectObjects(this.scene.children, !0);
1605
+ let e = this.camera.userData?.clipStart ?? 0;
1606
+ return this.raycaster.near = e > 0 && !this.camera.isOrthographicCamera ? e / Math.max(this.raycaster.ray.direction.dot(this.camera.getWorldDirection(Ua)), 1e-4) : 0, this.isGeometryOnDisk?.() ? [] : this.raycaster.intersectObjects(this.scene.children, !0);
1589
1607
  }
1590
1608
  pickSurface(e, t) {
1591
1609
  return this.raycaster.setFromCamera({
@@ -1620,35 +1638,35 @@ var Fa = class extends ur {
1620
1638
  wireAppEvents(e) {
1621
1639
  this.addEventListener("objectSelected", (t) => {
1622
1640
  this.select(t.object), e.refreshFrame(), e.dispatchEvent({
1623
- type: M.OBJECT_SELECTED,
1641
+ type: P.OBJECT_SELECTED,
1624
1642
  object: t.object,
1625
1643
  uuid: t.uuid
1626
1644
  });
1627
1645
  }), this.addEventListener("objectDeselected", (t) => {
1628
1646
  this.select(null), e.refreshFrame(), e.dispatchEvent({
1629
- type: M.OBJECT_DESELECTED,
1647
+ type: P.OBJECT_DESELECTED,
1630
1648
  object: t.object,
1631
1649
  uuid: t.uuid
1632
1650
  });
1633
1651
  }), this.addEventListener("selectModeChanged", (t) => {
1634
1652
  e.dispatchEvent({
1635
- type: M.SELECT_MODE_CHANGED,
1653
+ type: P.SELECT_MODE_CHANGED,
1636
1654
  enabled: t.enabled
1637
1655
  });
1638
1656
  }), this.addEventListener("objectDoubleClicked", (t) => {
1639
1657
  this.select(t.object), e.refreshFrame(), e.dispatchEvent({
1640
- type: M.OBJECT_DOUBLE_CLICKED,
1658
+ type: P.OBJECT_DOUBLE_CLICKED,
1641
1659
  object: t.object,
1642
1660
  uuid: t.uuid
1643
1661
  });
1644
1662
  }), this.addEventListener("focusChanged", (t) => {
1645
1663
  e.settings.set("focusDistance", t.worldDistance), e.dispatchEvent({
1646
- type: M.FOCUS_CHANGED,
1664
+ type: P.FOCUS_CHANGED,
1647
1665
  distance: t.distance
1648
1666
  });
1649
1667
  }), this.addEventListener("afPointPlaced", (t) => {
1650
1668
  e.dispatchEvent({
1651
- type: M.AF_POINT_PLACED,
1669
+ type: P.AF_POINT_PLACED,
1652
1670
  point: t.point
1653
1671
  });
1654
1672
  });
@@ -1656,7 +1674,7 @@ var Fa = class extends ur {
1656
1674
  dispose() {
1657
1675
  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
1676
  }
1659
- }, Ia = 8, La = 4, Ra = .25, za = _r.degToRad(89), Ba = .25, Va = {
1677
+ }, Ja = 8, Ya = 4, Xa = .25, Za = _r.degToRad(89), Qa = .25, $a = {
1660
1678
  KeyD: [
1661
1679
  1,
1662
1680
  0,
@@ -1707,15 +1725,15 @@ var Fa = class extends ur {
1707
1725
  0,
1708
1726
  -1
1709
1727
  ]
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 {
1728
+ }, eo = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=textbox], [role=combobox], [role=listbox], [role=menu], [role=menuitem]", to = (e) => e.shiftKey ? Ya : e.altKey ? Xa : 1, no = { type: "change" }, ro = { type: "start" }, io = new Q(), ao = new Q(), oo = new Q(), so = new Q(), co = new Or(), lo = class extends or {
1711
1729
  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);
1730
+ super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 / Ja, 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
1731
  }
1714
1732
  get active() {
1715
1733
  return this.enabled && this.orbit.enabled;
1716
1734
  }
1717
1735
  fitSpeed(e) {
1718
- this.speed = (e > 0 ? e : 1) / Ia;
1736
+ this.speed = (e > 0 ? e : 1) / Ja;
1719
1737
  }
1720
1738
  connect(e) {
1721
1739
  super.connect(e);
@@ -1735,34 +1753,34 @@ var Fa = class extends ur {
1735
1753
  if (!this._held.size || !this.active) return !1;
1736
1754
  let t = 0, n = 0, r = 0;
1737
1755
  for (let e of this._held) {
1738
- let [i, a, o] = Va[e];
1756
+ let [i, a, o] = $a[e];
1739
1757
  t += i, n += a, r += o;
1740
1758
  }
1741
1759
  if (!t && !n && !r) return !1;
1742
1760
  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;
1761
+ return ao.set(1, 0, 0).applyQuaternion(i.quaternion), io.crossVectors(i.up, ao).normalize(), ao.crossVectors(io, i.up), oo.set(0, 0, 0).addScaledVector(ao, t).addScaledVector(io, n).addScaledVector(i.up, r).normalize().multiplyScalar(this.speed * this._factor * e), i.position.add(oo), this.orbit.target.add(oo), i.updateMatrixWorld(), this.dispatchEvent(no), !0;
1744
1762
  }
1745
1763
  _elapsed() {
1746
- let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3, Ba);
1764
+ let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3, Qa);
1747
1765
  return this._lastTime = e, t;
1748
1766
  }
1749
1767
  _look(e, t) {
1750
1768
  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);
1769
+ n.quaternion.premultiply(co.setFromAxisAngle(n.up, e * a)), n.getWorldDirection(io);
1770
+ let o = Math.asin(_r.clamp(io.dot(n.up), -1, 1)), s = _r.clamp(o + t * a, -Za, Za);
1771
+ n.quaternion.multiply(co.setFromAxisAngle(so.set(1, 0, 0), s - o)), n.updateMatrixWorld(), r.copy(n.position).addScaledVector(n.getWorldDirection(io), i), this.dispatchEvent(no);
1754
1772
  }
1755
1773
  _onKeyDown(e) {
1756
- if (!(!this.active || e.defaultPrevented || e.target?.closest?.(Ha))) {
1774
+ if (!(!this.active || e.defaultPrevented || e.target?.closest?.(eo))) {
1757
1775
  if (e.metaKey || e.ctrlKey) {
1758
1776
  this.release();
1759
1777
  return;
1760
1778
  }
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))));
1779
+ this._factor = to(e), $a[e.code] && (e.preventDefault(), !this._held.has(e.code) && (this._held.add(e.code), this._held.size === 1 && (this._lastTime = performance.now(), this.dispatchEvent(ro))));
1762
1780
  }
1763
1781
  }
1764
1782
  _onKeyUp(e) {
1765
- this._factor = Ua(e), this._held.delete(e.code);
1783
+ this._factor = to(e), this._held.delete(e.code);
1766
1784
  }
1767
1785
  release() {
1768
1786
  this._held.clear(), this._factor = 1;
@@ -1783,25 +1801,25 @@ var Fa = class extends ur {
1783
1801
  _onPointerUp(e) {
1784
1802
  this._drag?.id === e.pointerId && (this._drag = null, this.domElement.releasePointerCapture?.(e.pointerId));
1785
1803
  }
1786
- }, Qa = {
1804
+ }, uo = {
1787
1805
  autoFocusMode: "auto",
1788
1806
  afScreenPoint: {
1789
1807
  x: .5,
1790
1808
  y: .5
1791
1809
  },
1792
1810
  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 {
1811
+ }, fo = .05, po = 10, mo = .5, ho = Object.freeze(new Q(1, 1, 1)), go = (e) => e?.isOrthographicCamera ? (e.top - e.bottom) / e.zoom : null, _o = class extends ur {
1794
1812
  constructor(e) {
1795
1813
  super();
1796
1814
  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;
1815
+ 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 lo(this.camera, e, this.controls), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this._userCameraCounter = 0, this.autoFocusMode = uo.autoFocusMode, this.afScreenPoint = { ...uo.afScreenPoint }, this.afSmoothingFactor = uo.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
1816
  }
1799
1817
  setCameras(e) {
1800
- this.cameras = e, this._userCameraCounter = 0, this.resetAutoFocus();
1818
+ this.cameras = e, this._userCameraCounter = 0, this.camera.userData.clipStart = 0, this.resetAutoFocus();
1801
1819
  }
1802
1820
  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;
1821
+ 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);
1822
+ 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
1823
  }
1806
1824
  removeCamera(e) {
1807
1825
  if (!Number.isInteger(e) || e <= 0 || e >= this.cameras.length || !this.cameras[e]?.userData?.__rayzeeUserCamera) return !1;
@@ -1854,12 +1872,12 @@ var Fa = class extends ur {
1854
1872
  target: this.controls ? this.controls.target.clone() : null
1855
1873
  }), this.currentCameraIndex = e, e === 0 && this._defaultCameraState) {
1856
1874
  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());
1875
+ this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ?? ho), 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
1876
  } else this._placeAt(this.cameras[e], t);
1859
1877
  this.resetAutoFocus();
1860
1878
  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,
1879
+ this._showOrthographic(o ? o.orthoHeight : go(a)), this._applyEffects(o), n?.(), r?.(), this.dispatchEvent({
1880
+ type: P.CAMERA_SWITCHED,
1863
1881
  cameraIndex: e,
1864
1882
  effects: this._captureEffects(),
1865
1883
  fov: this.camera.fov,
@@ -1873,15 +1891,15 @@ var Fa = class extends ur {
1873
1891
  return;
1874
1892
  }
1875
1893
  this._placeAt(e, this._getSettings?.("focusDistance"));
1876
- let t = ro(e);
1894
+ let t = go(e);
1877
1895
  this.camera.orthographic && this._setView(!0, t ? t / 2 : this.camera.orthoHalfHeight), this._onReset?.();
1878
1896
  }
1879
1897
  _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;
1898
+ 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
1899
  let n = e.userData?.__rayzeeOrbitTarget;
1882
1900
  if (n) this.controls.target.copy(n);
1883
1901
  else {
1884
- let n = new Z(0, 0, -1).applyQuaternion(e.quaternion);
1902
+ let n = new Q(0, 0, -1).applyQuaternion(e.quaternion);
1885
1903
  this.controls.target.copy(this.camera.position).addScaledVector(n, t || 5);
1886
1904
  }
1887
1905
  this.controls.update();
@@ -1903,7 +1921,7 @@ var Fa = class extends ur {
1903
1921
  }
1904
1922
  }
1905
1923
  get orthoHeight() {
1906
- return ro(this.camera);
1924
+ return go(this.camera);
1907
1925
  }
1908
1926
  setOrthoHeight(e) {
1909
1927
  e > 0 && (this._setView(this.camera.orthographic, e / 2), this._onReset?.());
@@ -1922,7 +1940,7 @@ var Fa = class extends ur {
1922
1940
  if (!this.camera.orthographic) return;
1923
1941
  let e = this.orthoHeight;
1924
1942
  e !== this._reportedOrthoHeight && (this._reportedOrthoHeight = e, this.dispatchEvent({
1925
- type: M.ORTHO_HEIGHT_UPDATED,
1943
+ type: P.ORTHO_HEIGHT_UPDATED,
1926
1944
  height: e
1927
1945
  }));
1928
1946
  }
@@ -1938,7 +1956,7 @@ var Fa = class extends ur {
1938
1956
  let r = this.interactionManager?.pickSurface(0, 0);
1939
1957
  if (!r) return;
1940
1958
  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();
1959
+ n.target.copy(this.camera.position).addScaledVector(this.camera.getWorldDirection(new Q()), i), n.update();
1942
1960
  }
1943
1961
  get navigationMode() {
1944
1962
  return this.walkControls.enabled ? "walk" : "orbit";
@@ -1970,6 +1988,7 @@ var Fa = class extends ur {
1970
1988
  fov: e.fov,
1971
1989
  near: e.near,
1972
1990
  far: e.far,
1991
+ clipStart: e.userData.clipStart ?? 0,
1973
1992
  zoom: e.zoom,
1974
1993
  orthographic: !!e.orthographic,
1975
1994
  orthoHalfHeight: e.orthoHalfHeight,
@@ -1993,7 +2012,7 @@ var Fa = class extends ur {
1993
2012
  let n = {
1994
2013
  index: t,
1995
2014
  name: e.name ?? "",
1996
- effects: be(e.userData?.__rayzeeEffects) ?? null
2015
+ effects: ye(e.userData?.__rayzeeEffects) ?? null
1997
2016
  };
1998
2017
  return t === 0 || !e.userData?.__rayzeeUserCamera ? n : {
1999
2018
  ...n,
@@ -2009,6 +2028,7 @@ var Fa = class extends ur {
2009
2028
  aspect: e.aspect ?? null,
2010
2029
  near: e.near,
2011
2030
  far: e.far,
2031
+ clipStart: e.userData.clipStart ?? 0,
2012
2032
  zoom: e.zoom,
2013
2033
  position: e.position.toArray(),
2014
2034
  quaternion: e.quaternion.toArray(),
@@ -2025,8 +2045,8 @@ var Fa = class extends ur {
2025
2045
  let n = /* @__PURE__ */ new Map();
2026
2046
  for (let r of e.cameras ?? []) {
2027
2047
  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);
2048
+ let e = r.orthographic ? new Tr(...r.frustum, r.near, r.far) : new Er(r.fov, r.aspect, r.near, r.far);
2049
+ 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 = ce(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
2050
  continue;
2031
2051
  }
2032
2052
  let e = this.cameras[r.index];
@@ -2034,26 +2054,26 @@ var Fa = class extends ur {
2034
2054
  t.push(r.name);
2035
2055
  continue;
2036
2056
  }
2037
- n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = ye(r.effects));
2057
+ n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = ce(r.effects));
2038
2058
  }
2039
2059
  this._userCameraCounter = this.cameras.filter((e) => e.userData?.__rayzeeUserCamera).length, this.currentCameraIndex = n.get(e.current) ?? 0;
2040
2060
  let r = e.defaultView;
2041
2061
  this._defaultCameraState = r ? {
2042
- position: new Z().fromArray(r.position),
2043
- quaternion: new Dr().fromArray(r.quaternion),
2044
- scale: new Z().fromArray(r.scale),
2062
+ position: new Q().fromArray(r.position),
2063
+ quaternion: new Or().fromArray(r.quaternion),
2064
+ scale: new Q().fromArray(r.scale),
2045
2065
  fov: r.fov,
2046
2066
  near: r.near,
2047
2067
  far: r.far,
2048
- target: r.target ? new Z().fromArray(r.target) : null
2068
+ target: r.target ? new Q().fromArray(r.target) : null
2049
2069
  } : null, e.navigationMode && this.setNavigationMode(e.navigationMode);
2050
2070
  let i = e.view;
2051
2071
  if (i) {
2052
2072
  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();
2073
+ 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
2074
  }
2055
2075
  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,
2076
+ type: P.CAMERA_SWITCHED,
2057
2077
  cameraIndex: this.currentCameraIndex,
2058
2078
  effects: this._captureEffects(),
2059
2079
  fov: this.camera.fov,
@@ -2097,36 +2117,36 @@ var Fa = class extends ur {
2097
2117
  let c = i;
2098
2118
  if (c?.isReady && c.renderMode?.value === 1 && c.frameCount > 0 && !c.isComplete) return;
2099
2119
  let l = this._pickFocusPoint(c.resetCount), u;
2100
- if (l) u = Na(l, this.camera), this._lastValidFocusDistance = u;
2120
+ if (l) u = Ga(l, this.camera), this._lastValidFocusDistance = u;
2101
2121
  else if (this._lastValidFocusDistance !== null) u = this._lastValidFocusDistance;
2102
2122
  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;
2123
+ let e = this.controls ? Ga(this.controls.target, this.camera) : 0;
2124
+ u = e > 0 ? e : po * (n?.getSceneScale() || 1), this._lastValidFocusDistance = u;
2105
2125
  }
2106
2126
  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);
2127
+ this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance > mo ? this._smoothedFocusDistance = u : this._smoothedFocusDistance += this.afSmoothingFactor * (u - this._smoothedFocusDistance);
2108
2128
  let f = r, p = this._smoothedFocusDistance;
2109
2129
  if (d || f === 0 || Math.abs(p - f) / Math.max(f, .001) > .001) {
2110
2130
  a(p);
2111
2131
  let e = n?.getSceneScale() || 1;
2112
2132
  this.dispatchEvent({
2113
- type: M.AUTO_FOCUS_UPDATED,
2133
+ type: P.AUTO_FOCUS_UPDATED,
2114
2134
  distance: p / e,
2115
2135
  worldDistance: p
2116
2136
  });
2117
2137
  let t = Math.abs(p - f) / Math.max(f, .001);
2118
- d ? s?.() : t > $a && o?.();
2138
+ d ? s?.() : t > fo && o?.();
2119
2139
  }
2120
2140
  }
2121
2141
  _pickFocusPoint(e) {
2122
2142
  let t = this.camera, { x: n, y: r } = this.afScreenPoint, i = this._afPick ??= {
2123
- point: new Z(),
2143
+ point: new Q(),
2124
2144
  hit: !1,
2125
2145
  resetCount: NaN,
2126
2146
  x: NaN,
2127
2147
  y: NaN,
2128
- view: new Y(),
2129
- projection: new Y()
2148
+ view: new yr(),
2149
+ projection: new yr()
2130
2150
  };
2131
2151
  if (this._afPointDirty || e !== i.resetCount || n !== i.x || r !== i.y || !i.view.equals(t.matrixWorld) || !i.projection.equals(t.projectionMatrix)) {
2132
2152
  let a = this.interactionManager.pickSurface(n * 2 - 1, 1 - r * 2);
@@ -2149,7 +2169,7 @@ var Fa = class extends ur {
2149
2169
  dispose() {
2150
2170
  this.walkControls?.dispose(), this.controls?.removeEventListener("change", this._reportOrthoHeight), this.controls?.dispose();
2151
2171
  }
2152
- }, ao = .001, oo = 2, so = (e, t, n, r) => new e(t, n, r, pr).createInterpolant(), co = class {
2172
+ }, vo = .001, yo = 2, bo = (e, t, n, r) => new e(t, n, r, pr).createInterpolant(), xo = class {
2153
2173
  constructor(e, t) {
2154
2174
  this._cameraManager = e, this._onChange = t, this.keys = [], this._nextId = 1, this._interpolants = null;
2155
2175
  }
@@ -2159,7 +2179,7 @@ var Fa = class extends ur {
2159
2179
  get duration() {
2160
2180
  return this.keys.length ? this.keys[this.keys.length - 1].time : 0;
2161
2181
  }
2162
- addKey(e = this.keys.length ? this.duration + oo : 0) {
2182
+ addKey(e = this.keys.length ? this.duration + yo : 0) {
2163
2183
  return this.add(this._cameraManager.captureView(), e);
2164
2184
  }
2165
2185
  updateKey(e) {
@@ -2173,13 +2193,13 @@ var Fa = class extends ur {
2173
2193
  let n = {
2174
2194
  id: this._nextId++,
2175
2195
  time: t,
2176
- ...lo(e)
2196
+ ...So(e)
2177
2197
  };
2178
2198
  return this.keys.push(n), this._changed(), n;
2179
2199
  }
2180
2200
  update(e, t) {
2181
2201
  let n = this.get(e);
2182
- n && (Object.assign(n, lo(t)), this._changed());
2202
+ n && (Object.assign(n, So(t)), this._changed());
2183
2203
  }
2184
2204
  setTime(e, t) {
2185
2205
  let n = this.get(e);
@@ -2205,8 +2225,8 @@ var Fa = class extends ur {
2205
2225
  this.keys = (e ?? []).map((e) => ({
2206
2226
  id: this._nextId++,
2207
2227
  time: e.time,
2208
- position: new Z().fromArray(e.position),
2209
- target: new Z().fromArray(e.target),
2228
+ position: new Q().fromArray(e.position),
2229
+ target: new Q().fromArray(e.target),
2210
2230
  fov: e.fov,
2211
2231
  orthoHeight: e.orthoHeight
2212
2232
  })), this._changed();
@@ -2218,8 +2238,8 @@ var Fa = class extends ur {
2218
2238
  return this.keys.find((t) => t.id === e);
2219
2239
  }
2220
2240
  sample(e, t = {
2221
- position: new Z(),
2222
- target: new Z(),
2241
+ position: new Q(),
2242
+ target: new Q(),
2223
2243
  fov: 0,
2224
2244
  orthoHeight: 0
2225
2245
  }) {
@@ -2229,7 +2249,7 @@ var Fa = class extends ur {
2229
2249
  }
2230
2250
  _build() {
2231
2251
  let e = [];
2232
- for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] + ao) : t.time);
2252
+ for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] + vo) : t.time);
2233
2253
  let t = e[0], n = e[e.length - 1], r = this.keys;
2234
2254
  if (r.length > 1) {
2235
2255
  let i = r.length;
@@ -2243,17 +2263,17 @@ var Fa = class extends ur {
2243
2263
  return {
2244
2264
  start: t,
2245
2265
  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)))
2266
+ position: bo(Br, ".position", e, i((e) => e.position)),
2267
+ target: bo(Br, ".target", e, i((e) => e.target)),
2268
+ fov: bo(Cr, ".fov", e, r.map((e) => e.fov)),
2269
+ logHeight: bo(Cr, ".orthoHeight", e, r.map((e) => Math.log(e.orthoHeight)))
2250
2270
  };
2251
2271
  }
2252
2272
  _changed() {
2253
2273
  this.keys.sort((e, t) => e.time - t.time), this._interpolants = null, this._onChange?.();
2254
2274
  }
2255
2275
  };
2256
- function lo({ position: e, target: t, fov: n, orthoHeight: r }) {
2276
+ function So({ position: e, target: t, fov: n, orthoHeight: r }) {
2257
2277
  return {
2258
2278
  position: e.clone(),
2259
2279
  target: t.clone(),
@@ -2263,9 +2283,9 @@ function lo({ position: e, target: t, fov: n, orthoHeight: r }) {
2263
2283
  }
2264
2284
  //#endregion
2265
2285
  //#region src/managers/timeline/TimelineManager.js
2266
- var uo = class extends ur {
2286
+ var Co = class extends ur {
2267
2287
  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);
2288
+ super(), this._cameraManager = e, this._onReset = t, this.camera = new xo(e, () => this._changed("camera")), this._playback = null, this._timer = new Fr(), typeof document < "u" && this._timer.connect(document);
2269
2289
  }
2270
2290
  get duration() {
2271
2291
  return this.camera.duration;
@@ -2314,18 +2334,18 @@ var uo = class extends ur {
2314
2334
  }
2315
2335
  _changed(e) {
2316
2336
  this.dispatchEvent({
2317
- type: M.TIMELINE_CHANGED,
2337
+ type: P.TIMELINE_CHANGED,
2318
2338
  track: e
2319
2339
  });
2320
2340
  }
2321
- }, fo = class {
2341
+ }, wo = class {
2322
2342
  constructor(e, t = {}) {
2323
2343
  this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._size = 256;
2324
2344
  }
2325
2345
  async loadLibrary(e, { size: t = 256 } = {}) {
2326
2346
  if (!Array.isArray(e) || e.length === 0) return [];
2327
2347
  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");
2348
+ let n = await Promise.all(e.map((e) => To(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
2329
2349
  s.width = r, s.height = i;
2330
2350
  let c = s.getContext("2d", { willReadFrequently: !0 }), l = performance.now();
2331
2351
  for (let e = 0; e < a; e++) {
@@ -2334,7 +2354,7 @@ var uo = class extends ur {
2334
2354
  o.set(t.data, e * r * i * 4), performance.now() - l > 16 && (await new Promise((e) => setTimeout(e, 0)), l = performance.now());
2335
2355
  }
2336
2356
  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;
2357
+ u.minFilter = mr, u.magFilter = mr, u.format = kr, u.type = Ir, u.generateMipmaps = !1, u.needsUpdate = !0;
2338
2358
  let d = this.texture;
2339
2359
  return this.texture = u, this.entries = e.map((e, t) => ({
2340
2360
  name: e.name,
@@ -2357,7 +2377,7 @@ var uo = class extends ur {
2357
2377
  o.userData.gobo = {
2358
2378
  name: e.name,
2359
2379
  index: e.index,
2360
- intensity: mo(r),
2380
+ intensity: Eo(r),
2361
2381
  inverted: !!i,
2362
2382
  scale: Math.max(1e-4, a)
2363
2383
  };
@@ -2399,7 +2419,7 @@ var uo = class extends ur {
2399
2419
  return t && t.isSpotLight ? t : null;
2400
2420
  }
2401
2421
  };
2402
- async function po(e) {
2422
+ async function To(e) {
2403
2423
  let t = await _(e);
2404
2424
  try {
2405
2425
  return await new Promise((n, r) => {
@@ -2410,22 +2430,22 @@ async function po(e) {
2410
2430
  t.release();
2411
2431
  }
2412
2432
  }
2413
- function mo(e) {
2433
+ function Eo(e) {
2414
2434
  return Math.max(0, Math.min(1, e));
2415
2435
  }
2416
2436
  //#endregion
2417
2437
  //#region src/Processor/IESParser.js
2418
- function ho(e, t = "ies") {
2438
+ function Do(e, t = "ies") {
2419
2439
  let n = e.search(/TILT\s*=/i);
2420
2440
  if (n < 0) throw Error(`IES (${t}): missing TILT line`);
2421
2441
  let r = e.indexOf("\n", n);
2422
2442
  if (r < 0) throw Error(`IES (${t}): truncated TILT line`);
2423
2443
  let i = e.slice(n, r).match(/TILT\s*=\s*(\w+)/i), a = i ? i[1].toUpperCase() : "NONE", o = e.slice(r);
2424
2444
  if (a === "INCLUDE") {
2425
- let e = bo(o), t = 2 + 2 * Number(e[1]);
2426
- o = xo(o, t);
2445
+ let e = Mo(o), t = 2 + 2 * Number(e[1]);
2446
+ o = No(o, t);
2427
2447
  }
2428
- let s = bo(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
2448
+ let s = Mo(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
2429
2449
  l(), l(), l(), l();
2430
2450
  let g = l();
2431
2451
  if (l(), l(), !Number.isFinite(p) || p <= 0) throw Error(`IES (${t}): invalid vertical angle count ${p}`);
@@ -2451,34 +2471,34 @@ function ho(e, t = "ies") {
2451
2471
  name: t
2452
2472
  };
2453
2473
  }
2454
- function go(e, t, n) {
2474
+ function Oo(e, t, n) {
2455
2475
  if (t === 0 && n === 90) {
2456
2476
  let t = e % 180;
2457
2477
  return t > 90 ? 180 - t : t;
2458
2478
  }
2459
2479
  return t === 0 && n === 180 ? e > 180 ? 360 - e : e : t === 90 && n === 270 ? e >= 90 && e <= 270 ? e : (540 - e) % 360 : e;
2460
2480
  }
2461
- function _o(e, t, n) {
2481
+ function ko(e, t, n) {
2462
2482
  let r = new Uint8Array(t * n), { verticalAngles: i, horizontalAngles: a, candela: o, maxCandela: s, photometricType: c } = e;
2463
2483
  if (s <= 0) return r;
2464
2484
  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);
2485
+ if (m) return Fo(o[e][0], o[t][0], n);
2466
2486
  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);
2487
+ let i = Po(a, r), s = Math.min(i + 1, a.length - 1), c = a[s] - a[i], l = c > 0 ? (r - a[i]) / c : 0;
2488
+ return Fo(Fo(o[e][i], o[e][s], l), Fo(o[t][i], o[t][s], l), n);
2469
2489
  };
2470
2490
  for (let e = 0; e < n; e++) {
2471
2491
  let a = (e + .5) / n, o = l ? a * 180 : u + a * (d - u);
2472
2492
  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;
2493
+ let c = Po(i, o), m = Math.min(c + 1, i.length - 1), g = i[m] - i[c], _ = g > 0 ? (o - i[c]) / g : 0;
2474
2494
  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));
2495
+ let i = (n + .5) / t, a = l ? Oo(i * 360, f, p) : f + i * (p - f), o = Math.min(1, Math.max(0, h(c, m, _, a) / s));
2476
2496
  r[e * t + n] = Math.round(o * 255);
2477
2497
  }
2478
2498
  }
2479
2499
  return r;
2480
2500
  }
2481
- function vo(e, t = .1) {
2501
+ function Ao(e, t = .1) {
2482
2502
  let { verticalAngles: n, horizontalAngles: r, candela: i, maxCandela: a } = e, o = Math.PI / 4;
2483
2503
  if (a <= 0 || !n?.length) return o;
2484
2504
  let s = a * t, c = r.length, l = n[n.length - 1], u = !1;
@@ -2493,7 +2513,7 @@ function vo(e, t = .1) {
2493
2513
  let d = l * Math.PI / 180;
2494
2514
  return Math.min(Math.max(d, 5 * Math.PI / 180), 89 * Math.PI / 180);
2495
2515
  }
2496
- function yo(e, t, n = .7) {
2516
+ function jo(e, t, n = .7) {
2497
2517
  let { verticalAngles: r, horizontalAngles: i, candela: a, maxCandela: o } = e;
2498
2518
  if (o <= 0 || !r?.length || t <= 0) return 0;
2499
2519
  let s = o * n, c = i.length, l = 0;
@@ -2506,15 +2526,15 @@ function yo(e, t, n = .7) {
2506
2526
  let u = t * 180 / Math.PI, d = u > 0 ? 1 - l / u : 0;
2507
2527
  return Math.min(Math.max(d, 0), 1);
2508
2528
  }
2509
- function bo(e) {
2529
+ function Mo(e) {
2510
2530
  return e.split(/\s+/).filter((e) => e.length > 0);
2511
2531
  }
2512
- function xo(e, t) {
2532
+ function No(e, t) {
2513
2533
  let n = /\S+/g, r = 0;
2514
2534
  for (; n.exec(e) !== null;) if (r++, r === t) return e.slice(n.lastIndex);
2515
2535
  return "";
2516
2536
  }
2517
- function So(e, t) {
2537
+ function Po(e, t) {
2518
2538
  if (t <= e[0]) return 0;
2519
2539
  if (t >= e[e.length - 1]) return e.length - 1;
2520
2540
  let n = 0, r = e.length - 1;
@@ -2524,12 +2544,12 @@ function So(e, t) {
2524
2544
  }
2525
2545
  return n;
2526
2546
  }
2527
- function Co(e, t, n) {
2547
+ function Fo(e, t, n) {
2528
2548
  return e + (t - e) * n;
2529
2549
  }
2530
2550
  //#endregion
2531
2551
  //#region src/managers/IESManager.js
2532
- var wo = class {
2552
+ var Io = class {
2533
2553
  constructor(e, t = {}) {
2534
2554
  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
2555
  }
@@ -2538,11 +2558,11 @@ var wo = class {
2538
2558
  this._gridWidth = t, this._gridHeight = n;
2539
2559
  let r = (await Promise.all(e.map(async (e) => {
2540
2560
  try {
2541
- let { file: r, release: i } = await p().fetch(e.url), a = ho(await r.text().finally(i), e.name);
2561
+ let { file: r, release: i } = await p().fetch(e.url), a = Do(await r.text().finally(i), e.name);
2542
2562
  return {
2543
2563
  it: e,
2544
2564
  profile: a,
2545
- grid: _o(a, t, n)
2565
+ grid: ko(a, t, n)
2546
2566
  };
2547
2567
  } catch (t) {
2548
2568
  return this._issues?.warn(Ye.ASSET_UNREACHABLE, `IES profile "${e.name}" could not be loaded: ${t.message}`, {
@@ -2560,19 +2580,19 @@ var wo = class {
2560
2580
  let r = t[e];
2561
2581
  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
2582
  }
2563
- let i = r[e].profile, c = vo(i);
2583
+ let i = r[e].profile, c = Ao(i);
2564
2584
  s.push({
2565
2585
  name: r[e].it.name,
2566
2586
  index: e,
2567
2587
  maxCandela: i.maxCandela,
2568
2588
  photometricType: i.photometricType,
2569
2589
  suggestedAngle: c,
2570
- suggestedPenumbra: yo(i, c),
2590
+ suggestedPenumbra: jo(i, c),
2571
2591
  lumens: i.lumens
2572
2592
  });
2573
2593
  }
2574
2594
  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;
2595
+ c.format = kr, c.type = Ir, c.minFilter = mr, c.magFilter = mr, c.generateMipmaps = !1, c.needsUpdate = !0;
2576
2596
  let l = this.texture;
2577
2597
  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
2598
  name: e,
@@ -2603,7 +2623,7 @@ var wo = class {
2603
2623
  l = Number.isFinite(e.lumens) ? e.lumens : null, i.userData.ies = {
2604
2624
  name: e.name,
2605
2625
  index: e.index,
2606
- intensity: To(n),
2626
+ intensity: Lo(n),
2607
2627
  fixtureLumens: l
2608
2628
  }, 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
2629
  }
@@ -2626,24 +2646,24 @@ var wo = class {
2626
2646
  return t && t.isSpotLight ? t : null;
2627
2647
  }
2628
2648
  };
2629
- function To(e) {
2649
+ function Lo(e) {
2630
2650
  return Math.max(0, Math.min(1, e));
2631
2651
  }
2632
2652
  //#endregion
2633
2653
  //#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;
2654
+ var Ro = We("oidn"), zo = 16, Bo = 16;
2655
+ function Vo(e, t) {
2656
+ let n = (e) => Math.ceil((e + 2 * Bo) / zo) * zo;
2637
2657
  return {
2638
2658
  width: n(e),
2639
2659
  height: n(t)
2640
2660
  };
2641
2661
  }
2642
- var Ao = null;
2643
- async function jo() {
2644
- return Ao ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Ao;
2662
+ var Ho = null;
2663
+ async function Uo() {
2664
+ return Ho ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Ho;
2645
2665
  }
2646
- var Mo = {
2666
+ var Wo = {
2647
2667
  QUALITY_MODELS: {
2648
2668
  fast: {
2649
2669
  model: "rt_hdr_alb_nrm_small",
@@ -2667,9 +2687,9 @@ var Mo = {
2667
2687
  oidnQuality: "fast",
2668
2688
  tileSize: 1024
2669
2689
  }
2670
- }, No = .18, Po = 256, Fo = 256, Io = `
2671
- const WG: u32 = ${Po}u;
2672
- const GROUPS: u32 = ${Fo}u;
2690
+ }, Go = .18, Ko = 256, qo = 256, Jo = `
2691
+ const WG: u32 = ${Ko}u;
2692
+ const GROUPS: u32 = ${qo}u;
2673
2693
 
2674
2694
  @group(0) @binding(0) var<storage, read> col: array<vec4<f32>>;
2675
2695
  @group(0) @binding(1) var<storage, read_write> partials: array<f32>;
@@ -2688,7 +2708,7 @@ fn treeSum( lid: u32 ) {
2688
2708
  }
2689
2709
  }
2690
2710
 
2691
- @compute @workgroup_size(${Po})
2711
+ @compute @workgroup_size(${Ko})
2692
2712
  fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
2693
2713
  @builtin(local_invocation_id) lid: vec3<u32>,
2694
2714
  @builtin(workgroup_id) wid: vec3<u32> ) {
@@ -2712,7 +2732,7 @@ fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
2712
2732
  if ( lid.x == 0u ) { partials[ wid.x ] = sdata[ 0 ]; }
2713
2733
  }
2714
2734
 
2715
- @compute @workgroup_size(${Po})
2735
+ @compute @workgroup_size(${Ko})
2716
2736
  fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
2717
2737
 
2718
2738
  var v = 0.0;
@@ -2722,12 +2742,12 @@ fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
2722
2742
  treeSum( lid.x );
2723
2743
 
2724
2744
  if ( lid.x == 0u ) {
2725
- let scale = ${No} / exp2( sdata[ 0 ] / f32( params.x ) );
2745
+ let scale = ${Go} / exp2( sdata[ 0 ] / f32( params.x ) );
2726
2746
  // Mirrors the CPU guard: a non-finite or non-positive scale means no scaling at all.
2727
2747
  scaleOut[ 0 ] = select( 1.0, scale, scale > 0.0 && scale < 3.4e38 );
2728
2748
  }
2729
2749
  }
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 = `
2750
+ `, Yo = "\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", Xo = 64, Zo = 32768, Qo = 16, $o = 32, es = `
2731
2751
  struct UnpackParams {
2732
2752
  srcWidth: u32,
2733
2753
  tileX: u32,
@@ -2745,7 +2765,7 @@ struct UnpackParams {
2745
2765
  @group(0) @binding(3) var<storage, read> inColor: array<vec4<f32>>;
2746
2766
  @group(0) @binding(4) var dst: texture_storage_2d<rgba16float, write>;
2747
2767
 
2748
- @compute @workgroup_size(${Bo}, ${Bo})
2768
+ @compute @workgroup_size(${Qo}, ${Qo})
2749
2769
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2750
2770
 
2751
2771
  if ( gid.x >= P.tileW || gid.y >= P.tileH ) { return; }
@@ -2759,7 +2779,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2759
2779
  // survives the denoise.
2760
2780
  textureStore( dst, vec2<u32>( px, py ), vec4<f32>( src[ si ].xyz / scaleBuf[ 0 ], inColor[ si ].w ) );
2761
2781
  }
2762
- `, Uo = 8, Wo = `
2782
+ `, ts = 8, ns = `
2763
2783
  @group(0) @binding(0) var src: texture_2d<f32>;
2764
2784
  @group(0) @binding(1) var<storage, read_write> dst: array<vec4<f32>>;
2765
2785
  @group(0) @binding(2) var<uniform> size: vec4<u32>; // buffer w, h; frame w, h
@@ -2769,15 +2789,15 @@ fn mirror( i: i32, n: i32 ) -> i32 {
2769
2789
  return clamp( select( m, 2 * n - 2 - m, m >= n ), 0, n - 1 );
2770
2790
  }
2771
2791
 
2772
- @compute @workgroup_size(${Uo}, ${Uo})
2792
+ @compute @workgroup_size(${ts}, ${ts})
2773
2793
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2774
2794
 
2775
2795
  if ( gid.x >= size.x || gid.y >= size.y ) { return; }
2776
- let p = vec2<i32>( gid.xy ) - ${Oo};
2796
+ let p = vec2<i32>( gid.xy ) - ${Bo};
2777
2797
  let s = vec2<i32>( mirror( p.x, i32( size.z ) ), mirror( p.y, i32( size.w ) ) );
2778
2798
  dst[ gid.y * size.x + gid.x ] = textureLoad( src, s, 0 );
2779
2799
  }
2780
- `, Go = class extends ur {
2800
+ `, rs = class extends ur {
2781
2801
  constructor(e, t = {}) {
2782
2802
  if (super(), !e) throw Error("OIDNDenoiser requires a renderer");
2783
2803
  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 +2811,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2791
2811
  width: 0,
2792
2812
  height: 0
2793
2813
  }, this.config = {
2794
- ...Mo.DEFAULT_OPTIONS,
2814
+ ...Wo.DEFAULT_OPTIONS,
2795
2815
  ...t
2796
2816
  }, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
2797
2817
  isDenoising: !1,
2798
2818
  isLoading: !1,
2799
2819
  abortController: null
2800
2820
  }, 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({
2821
+ Ro.error("init failed:", e), this.dispatchEvent({
2802
2822
  type: "error",
2803
2823
  error: e
2804
2824
  });
@@ -2812,7 +2832,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2812
2832
  }
2813
2833
  }
2814
2834
  expectsCleanAux(e = this.quality) {
2815
- let { QUALITY_MODELS: t } = Mo;
2835
+ let { QUALITY_MODELS: t } = Wo;
2816
2836
  return (t[e] || t.balance).cleanAux;
2817
2837
  }
2818
2838
  getRuntimeInfo() {
@@ -2826,8 +2846,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2826
2846
  }
2827
2847
  _resolveTileSize() {
2828
2848
  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);
2849
+ let e = Vo(this._renderWidth, this._renderHeight), t = Vo(this.maxTileSize, this.maxTileSize);
2850
+ return e.width * e.height <= t.width * t.height ? Math.max(e.width, e.height) : Math.max(zo, Math.floor(this.maxTileSize / zo) * zo);
2831
2851
  }
2832
2852
  _setupUNetDenoiser() {
2833
2853
  return this.state.isLoading ? (this._reloadPending = !0, Promise.resolve()) : (this._loading = this._loadUNet(), this._loading);
@@ -2841,7 +2861,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2841
2861
  try {
2842
2862
  await this._loadUNetWeights();
2843
2863
  } catch (e) {
2844
- Eo.error("UNet weights failed to load:", e), this.dispatchEvent({
2864
+ Ro.error("UNet weights failed to load:", e), this.dispatchEvent({
2845
2865
  type: "error",
2846
2866
  error: /* @__PURE__ */ Error(`Denoiser loading failed: ${e.message}`),
2847
2867
  url: this._generateTzaUrl()
@@ -2850,7 +2870,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2850
2870
  this.state.isLoading = !1;
2851
2871
  }
2852
2872
  } while (this._reloadPending);
2853
- if (this._pendingStart && this.unet && this.enabled) {
2873
+ if (this._pendingStart && this.enabled) {
2854
2874
  let e = this._pendingStartContinuous;
2855
2875
  this._pendingStart = !1, this._pendingStartContinuous = !1, this.start({ continuous: e });
2856
2876
  }
@@ -2867,26 +2887,26 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2867
2887
  let e = this.backendParamsGetter();
2868
2888
  this.gpuDevice = e?.device ?? null, n = e?.device ? { device: e.device } : void 0;
2869
2889
  }
2870
- this.unet = await (await jo())(await this._fetchWeights(e), n, {
2890
+ this.unet = await (await Uo())(await this._fetchWeights(e), n, {
2871
2891
  aux: !0,
2872
2892
  hdr: !0,
2873
2893
  maxTileSize: t,
2874
2894
  dynamicTile: !1
2875
- }), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), Eo.debug("UNet weights loaded:", e);
2895
+ }), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), Ro.debug("UNet weights loaded:", e);
2876
2896
  }
2877
2897
  _fetchWeights(e) {
2878
2898
  let t = this._weights.get(e);
2879
2899
  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
2900
  }
2881
2901
  _generateTzaUrl() {
2882
- let { oidnWeightsBaseUrl: e } = it(), { QUALITY_MODELS: t } = Mo;
2902
+ let { oidnWeightsBaseUrl: e } = it(), { QUALITY_MODELS: t } = Wo;
2883
2903
  return `${e}${(t[this.quality] || t.balance).model}.tza`;
2884
2904
  }
2885
2905
  async updateConfiguration(e) {
2886
2906
  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
2907
  }
2888
2908
  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(", ")}`);
2909
+ if (!Object.prototype.hasOwnProperty.call(Wo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Wo.QUALITY_MODELS).join(", ")}`);
2890
2910
  await this.updateConfiguration({ oidnQuality: e });
2891
2911
  }
2892
2912
  async start({ continuous: e = !1 } = {}) {
@@ -2897,16 +2917,15 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2897
2917
  continuous: e
2898
2918
  });
2899
2919
  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;
2920
+ return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t, Ro.debug(`denoise complete in ${He.ms(this.lastDenoiseMs)} · quality ${this.quality}`)), n;
2901
2921
  }
2902
2922
  async execute(e = !1) {
2903
- if (!this.enabled || !this.unet) return !1;
2904
2923
  let t = ++this._runId;
2905
2924
  this.state.abortController = new AbortController(), this.state.isDenoising = !0;
2906
2925
  try {
2907
- return await this._executeUNetGPU(e) !== !1;
2926
+ return !this.enabled || !this.unet ? !1 : await this._executeUNetGPU(e) !== !1;
2908
2927
  } catch (e) {
2909
- return e.name === "AbortError" ? Eo.debug("denoise aborted") : Eo.error("denoise error:", e), !1;
2928
+ return e.name === "AbortError" ? Ro.debug("denoise aborted") : Ro.error("denoise error:", e), !1;
2910
2929
  } finally {
2911
2930
  this._runId === t && (this.state.isDenoising = !1, this.state.abortController = null), this.dispatchEvent({
2912
2931
  type: "end",
@@ -2916,13 +2935,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2916
2935
  }
2917
2936
  async _executeUNetGPU(e = !1) {
2918
2937
  let t = this._renderWidth, n = this._renderHeight;
2919
- if (!this.getGPUTextures) return Eo.warn("GPU mode enabled but getGPUTextures not provided"), !1;
2938
+ if (!this.getGPUTextures) return Ro.warn("GPU mode enabled but getGPUTextures not provided"), !1;
2920
2939
  let r = this.getGPUTextures({ continuous: e });
2921
- if (!r?.color) return Eo.warn("GPU textures not ready yet"), !1;
2940
+ if (!r?.color) return Ro.warn("GPU textures not ready yet"), !1;
2922
2941
  let i = this.gpuDevice;
2923
- if (!i) return Eo.warn("gpuDevice not available"), !1;
2942
+ if (!i) return Ro.warn("gpuDevice not available"), !1;
2924
2943
  this._ensureGPUInputBuffers(t, n), this._copyInputs(i, r, t, n);
2925
- let a = ko(t, n);
2944
+ let a = Vo(t, n);
2926
2945
  this._computeInputScale(i, t, n), this._applyColorScale(i, a.width * a.height), !e && !this._hasOutput && this._unpackToTexture(this._gpuInputBuffers.color, {
2927
2946
  x: 0,
2928
2947
  y: 0,
@@ -2941,7 +2960,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2941
2960
  return this._executeWithAbortGPU(s, e);
2942
2961
  }
2943
2962
  _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);
2963
+ let i = Vo(n, r), a = e.createCommandEncoder({ label: "oidn-tex-to-buf" }), o = this._beginPack(e, a, i, n, r);
2945
2964
  for (let n of [
2946
2965
  "color",
2947
2966
  "albedo",
@@ -2962,14 +2981,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
2962
2981
  resource: { buffer: this._packParams }
2963
2982
  }
2964
2983
  ]
2965
- })), o.dispatchWorkgroups(Math.ceil(i.width / Uo), Math.ceil(i.height / Uo));
2984
+ })), o.dispatchWorkgroups(Math.ceil(i.width / ts), Math.ceil(i.height / ts));
2966
2985
  o.end(), e.queue.submit([a.finish()]);
2967
2986
  }
2968
2987
  _ensureGPUInputBuffers(e, t) {
2969
2988
  let { width: n, height: r } = this._gpuInputBufferSize;
2970
2989
  if (n === e && r === t && this._gpuInputBuffers.color) return;
2971
2990
  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;
2991
+ let i = this.gpuDevice, a = Vo(e, t), o = a.width * a.height * 16, s = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
2973
2992
  this._gpuInputBuffers.color = i.createBuffer({
2974
2993
  label: "oidn-in-color",
2975
2994
  size: o,
@@ -3013,7 +3032,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3013
3032
  compute: {
3014
3033
  module: e.createShaderModule({
3015
3034
  label: "oidn-pack",
3016
- code: Wo
3035
+ code: ns
3017
3036
  }),
3018
3037
  entryPoint: "main"
3019
3038
  }
@@ -3071,7 +3090,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3071
3090
  });
3072
3091
  let t = e.createShaderModule({
3073
3092
  label: "oidn-autoexposure",
3074
- code: Io
3093
+ code: Jo
3075
3094
  }), n = e.createPipelineLayout({ bindGroupLayouts: [this._lumLayout] });
3076
3095
  this._lumReducePipeline = e.createComputePipeline({
3077
3096
  label: "oidn-autoexposure-reduce",
@@ -3095,7 +3114,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3095
3114
  compute: {
3096
3115
  module: e.createShaderModule({
3097
3116
  label: "oidn-color-scale",
3098
- code: Lo
3117
+ code: Yo
3099
3118
  }),
3100
3119
  entryPoint: "main"
3101
3120
  }
@@ -3105,7 +3124,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3105
3124
  compute: {
3106
3125
  module: e.createShaderModule({
3107
3126
  label: "oidn-output-unpack",
3108
- code: Ho
3127
+ code: es
3109
3128
  }),
3110
3129
  entryPoint: "main"
3111
3130
  }
@@ -3115,7 +3134,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3115
3134
  size: 4
3116
3135
  }), this._lumPartials = e.createBuffer({
3117
3136
  label: "oidn-autoexposure-partials",
3118
- size: Fo * 4,
3137
+ size: qo * 4,
3119
3138
  usage: GPUBufferUsage.STORAGE
3120
3139
  }), this._lumParams = e.createBuffer({
3121
3140
  label: "oidn-autoexposure-params",
@@ -3160,21 +3179,21 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3160
3179
  e.queue.writeBuffer(this._inputScaleBuffer, 0, new Float32Array([1]));
3161
3180
  return;
3162
3181
  }
3163
- let r = ko(t, n);
3182
+ let r = Vo(t, n);
3164
3183
  e.queue.writeBuffer(this._lumParams, 0, new Uint32Array([
3165
3184
  t * n,
3166
3185
  t,
3167
3186
  r.width,
3168
- Oo
3187
+ Bo
3169
3188
  ]));
3170
3189
  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();
3190
+ a.setPipeline(this._lumReducePipeline), a.setBindGroup(0, this._lumBindGroup), a.dispatchWorkgroups(qo, 1, 1), a.end();
3172
3191
  let o = i.beginComputePass({ label: "oidn-autoexposure-finalize" });
3173
3192
  o.setPipeline(this._lumFinalizePipeline), o.setBindGroup(0, this._lumBindGroup), o.dispatchWorkgroups(1, 1, 1), o.end(), e.queue.submit([i.finish()]);
3174
3193
  }
3175
3194
  _applyColorScale(e, t) {
3176
3195
  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" });
3196
+ let n = Math.ceil(t / Xo), r = Math.min(n, Zo), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
3178
3197
  o.setPipeline(this._colorScalePipeline), o.setBindGroup(0, this._colorScaleBindGroup), o.dispatchWorkgroups(r, i, 1), o.end(), e.queue.submit([a.finish()]);
3179
3198
  }
3180
3199
  get outputTexture() {
@@ -3201,7 +3220,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3201
3220
  width: t,
3202
3221
  height: n,
3203
3222
  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 = {
3223
+ }, 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
3224
  width: t,
3206
3225
  height: n
3207
3226
  };
@@ -3219,18 +3238,18 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3219
3238
  if (this._ensureOutputTexture(r, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
3220
3239
  let c = r.createBuffer({
3221
3240
  label: "oidn-unpack-params",
3222
- size: Vo,
3241
+ size: $o,
3223
3242
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3224
3243
  });
3225
3244
  try {
3226
- let t = ko(this._gpuInputBufferSize.width, this._gpuInputBufferSize.height).width;
3245
+ let t = Vo(this._gpuInputBufferSize.width, this._gpuInputBufferSize.height).width;
3227
3246
  r.queue.writeBuffer(c, 0, new Uint32Array([
3228
3247
  t,
3229
3248
  i,
3230
3249
  a,
3231
3250
  o,
3232
3251
  s,
3233
- Oo,
3252
+ Bo,
3234
3253
  0,
3235
3254
  0
3236
3255
  ]));
@@ -3260,7 +3279,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3260
3279
  }
3261
3280
  ]
3262
3281
  }), 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);
3282
+ d.setPipeline(this._unpackPipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / Qo), Math.ceil(s / Qo), 1), d.end(), r.queue.submit([u.finish()]), n && (this._hasOutput = !0);
3264
3283
  } finally {
3265
3284
  c.destroy();
3266
3285
  }
@@ -3292,7 +3311,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3292
3311
  },
3293
3312
  progress: (e, n, r) => {
3294
3313
  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;
3314
+ let { width: i, height: a } = this._gpuInputBufferSize, o = Math.max(r.x - Bo, 0), s = Math.max(r.y - Bo, 0), c = Math.min(r.x + r.width - Bo, i) - o, l = Math.min(r.y + r.height - Bo, a) - s;
3296
3315
  if (c <= 0 || l <= 0) return;
3297
3316
  let u = {
3298
3317
  x: o,
@@ -3313,7 +3332,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3313
3332
  }
3314
3333
  _displayGPUOutput({ data: e }) {
3315
3334
  if (!this.gpuDevice) {
3316
- Eo.error("gpuDevice not available for the output picture");
3335
+ Ro.error("gpuDevice not available for the output picture");
3317
3336
  return;
3318
3337
  }
3319
3338
  let { width: t, height: n } = this._gpuInputBufferSize;
@@ -3325,7 +3344,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3325
3344
  });
3326
3345
  }
3327
3346
  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"));
3347
+ this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1, Ro.debug("denoise aborted"));
3329
3348
  }
3330
3349
  get hasOutput() {
3331
3350
  return this._hasOutput;
@@ -3336,13 +3355,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3336
3355
  setSize(e, t) {
3337
3356
  if (e <= 0 || t <= 0) throw Error(`Invalid dimensions: ${e}x${t}`);
3338
3357
  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);
3358
+ Ro.error("reinitialize after size change failed:", e);
3340
3359
  });
3341
3360
  }
3342
3361
  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");
3362
+ 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?.(), Ro.debug("disposed");
3344
3363
  }
3345
- }, Ko = Object.freeze({
3364
+ }, is = Object.freeze({
3346
3365
  maxLength: 8,
3347
3366
  smoothLength: 2,
3348
3367
  roughStart: .45,
@@ -3350,7 +3369,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3350
3369
  depthTolerance: .05,
3351
3370
  normalTolerance: .8,
3352
3371
  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 + `
3372
+ }), as = 8, os = 304, ss = 16, cs = 1, ls = 2, us = 4, ds = 1073741824, fs = "\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", ps = fs + `
3354
3373
  @group(0) @binding(1) var geoCur: texture_2d<f32>;
3355
3374
  @group(0) @binding(2) var geoPrev: texture_2d<f32>;
3356
3375
  @group(0) @binding(3) var<storage, read_write> picked: array<i32>;
@@ -3376,7 +3395,7 @@ fn movedIndex( leaf: u32 ) -> i32 {
3376
3395
 
3377
3396
  }
3378
3397
 
3379
- @compute @workgroup_size(${qo}, ${qo})
3398
+ @compute @workgroup_size(${as}, ${as})
3380
3399
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3381
3400
 
3382
3401
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -3386,12 +3405,12 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3386
3405
  var pick = -1;
3387
3406
  var movedFlag = 0;
3388
3407
 
3389
- if ( P.reset == 0u && g.w < ${Wr.toFixed(1)} ) {
3408
+ if ( P.reset == 0u && g.w < ${Gr.toFixed(1)} ) {
3390
3409
 
3391
3410
  let size = vec2<f32>( P.size );
3392
3411
  let uv = ( vec2<f32>( gid.xy ) + 0.5 ) / size;
3393
3412
  // Depth is along the ray: from the camera, or from its image plane when orthographic.
3394
- let ortho = ( P.flags & ${Qo}u ) != 0u;
3413
+ let ortho = ( P.flags & ${us}u ) != 0u;
3395
3414
  let ndc = vec2<f32>( uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0 );
3396
3415
  var origin = P.camWorld[ 3 ].xyz;
3397
3416
  var dir: vec3<f32>;
@@ -3415,7 +3434,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3415
3434
  let toPrev = movedToPrev[ u32( m ) ];
3416
3435
  wp = ( toPrev * vec4<f32>( wp, 1.0 ) ).xyz;
3417
3436
  n = normalize( ( toPrev * vec4<f32>( n, 0.0 ) ).xyz );
3418
- movedFlag = ${$o};
3437
+ movedFlag = ${ds};
3419
3438
 
3420
3439
  }
3421
3440
 
@@ -3452,7 +3471,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3452
3471
  if ( pick >= 0 ) { atomicAdd( &copies[ u32( pick ) ], 1u ); }
3453
3472
 
3454
3473
  }
3455
- `, ns = es + `
3474
+ `, ms = fs + `
3456
3475
  @group(0) @binding(1) var curColor: texture_2d<f32>;
3457
3476
  @group(0) @binding(2) var curAlbedo: texture_2d<f32>;
3458
3477
  @group(0) @binding(3) var curNormal: texture_2d<f32>;
@@ -3466,7 +3485,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3466
3485
  @group(0) @binding(11) var outAlbedo: texture_storage_2d<rgba32float, write>;
3467
3486
  @group(0) @binding(12) var outNormal: texture_storage_2d<rgba32float, write>;
3468
3487
 
3469
- @compute @workgroup_size(${qo}, ${qo})
3488
+ @compute @workgroup_size(${as}, ${as})
3470
3489
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3471
3490
 
3472
3491
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -3482,8 +3501,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3482
3501
  var ha = ca.xyz;
3483
3502
  var hn = cn.xyz;
3484
3503
  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 );
3504
+ let movedPx = raw >= 0 && ( raw & ${ds} ) != 0;
3505
+ let pick = select( raw, raw & ~${ds}, raw >= 0 );
3487
3506
 
3488
3507
  if ( pick >= 0 ) {
3489
3508
 
@@ -3497,13 +3516,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3497
3516
  ha = a.xyz;
3498
3517
  hn = textureLoad( histNormal, q, 0 ).xyz;
3499
3518
  len = a.w;
3500
- if ( ( P.flags & ${Zo}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
3519
+ if ( ( P.flags & ${ls}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
3501
3520
 
3502
3521
  }
3503
3522
 
3504
3523
  }
3505
3524
 
3506
- let rough = textureLoad( shading, p, 0 ).w;
3525
+ let rough = abs( textureLoad( shading, p, 0 ).w );
3507
3526
  var cap = mix( P.smoothLength, P.maxLength, smoothstep( P.roughStart, P.roughEnd, rough ) );
3508
3527
  if ( movedPx ) { cap = min( cap, P.movedLength ); }
3509
3528
  let newLen = min( len + 1.0, cap );
@@ -3511,11 +3530,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3511
3530
 
3512
3531
  textureStore( outColor, p, vec4<f32>( mix( hc, cur.xyz, t ), cur.w ) );
3513
3532
  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 );
3533
+ let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${cs}u ) != 0u );
3515
3534
  textureStore( outNormal, p, vec4<f32>( n, cn.w ) );
3516
3535
 
3517
3536
  }
3518
- `, rs = es + `
3537
+ `, hs = fs + `
3519
3538
  @group(0) @binding(1) var accColor: texture_2d<f32>;
3520
3539
  @group(0) @binding(2) var accAlbedo: texture_2d<f32>;
3521
3540
  @group(0) @binding(3) var accNormal: texture_2d<f32>;
@@ -3526,7 +3545,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3526
3545
  @group(0) @binding(8) var outAlbedo: texture_storage_2d<rgba32float, write>;
3527
3546
  @group(0) @binding(9) var outNormal: texture_storage_2d<rgba32float, write>;
3528
3547
 
3529
- @compute @workgroup_size(${qo}, ${qo})
3548
+ @compute @workgroup_size(${as}, ${as})
3530
3549
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3531
3550
 
3532
3551
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -3560,32 +3579,32 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3560
3579
  let t = P.samples / max( k + P.samples, 1e-6 );
3561
3580
  textureStore( outColor, p, vec4<f32>( mix( hc, ac.xyz, t ), ac.w ) );
3562
3581
  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 );
3582
+ let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${cs}u ) != 0u );
3564
3583
  textureStore( outNormal, p, vec4<f32>( n, an.w ) );
3565
3584
 
3566
3585
  }
3567
- `, is = (e) => ({
3586
+ `, gs = (e) => ({
3568
3587
  binding: e,
3569
3588
  visibility: GPUShaderStage.COMPUTE,
3570
3589
  texture: { sampleType: "unfilterable-float" }
3571
- }), as = (e) => ({
3590
+ }), _s = (e) => ({
3572
3591
  binding: e,
3573
3592
  visibility: GPUShaderStage.COMPUTE,
3574
3593
  storageTexture: {
3575
3594
  access: "write-only",
3576
3595
  format: "rgba32float"
3577
3596
  }
3578
- }), os = (e, t) => ({
3597
+ }), vs = (e, t) => ({
3579
3598
  binding: e,
3580
3599
  visibility: GPUShaderStage.COMPUTE,
3581
3600
  buffer: { type: t }
3582
- }), ss = class {
3601
+ }), ys = class {
3583
3602
  constructor(e) {
3584
3603
  this.device = e, this.settings = {
3585
- ...Ko,
3604
+ ...is,
3586
3605
  cleanAux: !1,
3587
3606
  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);
3607
+ }, 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(os), 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
3608
  }
3590
3609
  get textures() {
3591
3610
  return this.valid ? this._sets[this._current] : null;
@@ -3693,23 +3712,23 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3693
3712
  }),
3694
3713
  layout: i
3695
3714
  };
3696
- }, n = os(0, "uniform");
3715
+ }, n = vs(0, "uniform");
3697
3716
  this._pipelines = {
3698
- select: t("oidn-history-select", ts, [
3717
+ select: t("oidn-history-select", ps, [
3699
3718
  n,
3700
- is(1),
3701
- is(2),
3702
- os(3, "storage"),
3703
- os(4, "storage"),
3719
+ gs(1),
3720
+ gs(2),
3721
+ vs(3, "storage"),
3722
+ vs(4, "storage"),
3704
3723
  {
3705
3724
  binding: 5,
3706
3725
  visibility: GPUShaderStage.COMPUTE,
3707
3726
  texture: { sampleType: "uint" }
3708
3727
  },
3709
- os(6, "read-only-storage"),
3710
- os(7, "read-only-storage")
3728
+ vs(6, "read-only-storage"),
3729
+ vs(7, "read-only-storage")
3711
3730
  ]),
3712
- blend: t("oidn-history-blend", ns, [
3731
+ blend: t("oidn-history-blend", ms, [
3713
3732
  n,
3714
3733
  ...[
3715
3734
  1,
@@ -3719,14 +3738,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3719
3738
  5,
3720
3739
  6,
3721
3740
  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)
3741
+ ].map(gs),
3742
+ vs(8, "read-only-storage"),
3743
+ vs(9, "read-only-storage"),
3744
+ _s(10),
3745
+ _s(11),
3746
+ _s(12)
3728
3747
  ]),
3729
- merge: t("oidn-history-merge", rs, [
3748
+ merge: t("oidn-history-merge", hs, [
3730
3749
  n,
3731
3750
  ...[
3732
3751
  1,
@@ -3735,16 +3754,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3735
3754
  4,
3736
3755
  5,
3737
3756
  6
3738
- ].map(is),
3739
- as(7),
3740
- as(8),
3741
- as(9)
3757
+ ].map(gs),
3758
+ _s(7),
3759
+ _s(8),
3760
+ _s(9)
3742
3761
  ])
3743
3762
  }, this._paramsBuffer = e.createBuffer({
3744
3763
  label: "oidn-history-params",
3745
- size: Jo,
3764
+ size: os,
3746
3765
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3747
- }), this._growMoved(Yo);
3766
+ }), this._growMoved(ss);
3748
3767
  }
3749
3768
  _growMoved(e) {
3750
3769
  this._movedLeaves?.destroy(), this._movedToPrev?.destroy();
@@ -3770,11 +3789,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3770
3789
  a.setPipeline(t), a.setBindGroup(0, this.device.createBindGroup({
3771
3790
  layout: n,
3772
3791
  entries: i
3773
- })), a.dispatchWorkgroups(Math.ceil(this.width / qo), Math.ceil(this.height / qo)), a.end();
3792
+ })), a.dispatchWorkgroups(Math.ceil(this.width / as), Math.ceil(this.height / as)), a.end();
3774
3793
  }
3775
3794
  _writeParams(e, t, n, r) {
3776
3795
  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);
3796
+ a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? cs : 0) | (i.splitCopies ? ls : 0) | (e.orthographic ? us : 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
3797
  }
3779
3798
  _rememberCamera(e) {
3780
3799
  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 +3803,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3784
3803
  _releaseTextures() {
3785
3804
  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
3805
  }
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) {
3806
+ }, bs = "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`,ASSET_PARAMETERS_IGNORED:`asset.parameters_ignored`,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})}};", xs = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", bs], { type: "text/javascript;charset=utf-8" });
3807
+ function Ss(e) {
3789
3808
  let t;
3790
3809
  try {
3791
- if (t = ls && (self.URL || self.webkitURL).createObjectURL(ls), !t) throw "";
3810
+ if (t = xs && (self.URL || self.webkitURL).createObjectURL(xs), !t) throw "";
3792
3811
  let n = new Worker(t, {
3793
3812
  type: "module",
3794
3813
  name: e?.name
@@ -3797,7 +3816,7 @@ function us(e) {
3797
3816
  (self.URL || self.webkitURL).revokeObjectURL(t);
3798
3817
  }), n;
3799
3818
  } catch {
3800
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(cs), {
3819
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(bs), {
3801
3820
  type: "module",
3802
3821
  name: e?.name
3803
3822
  });
@@ -3805,7 +3824,7 @@ function us(e) {
3805
3824
  }
3806
3825
  //#endregion
3807
3826
  //#region src/Passes/AIUpscaler.js
3808
- var ds = {
3827
+ var Cs = {
3809
3828
  fast: {
3810
3829
  2: "2x-spanx2-ch48.onnx",
3811
3830
  4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
@@ -3819,17 +3838,17 @@ var ds = {
3819
3838
  4: "4xNomos2_hq_mosr_fp32.onnx"
3820
3839
  }
3821
3840
  };
3822
- function fs() {
3841
+ function ws() {
3823
3842
  let { upscalerModelBaseUrl: e } = it(), t = {};
3824
- for (let n in ds) {
3843
+ for (let n in Cs) {
3825
3844
  t[n] = {};
3826
- for (let r in ds[n]) t[n][r] = e + ds[n][r];
3845
+ for (let r in Cs[n]) t[n][r] = e + Cs[n][r];
3827
3846
  }
3828
3847
  return t;
3829
3848
  }
3830
- var ps = {
3849
+ var Ts = {
3831
3850
  get QUALITY_PRESETS() {
3832
- return fs();
3851
+ return ws();
3833
3852
  },
3834
3853
  TILE_SIZE: 512,
3835
3854
  TILE_OVERLAP: 16,
@@ -3840,17 +3859,17 @@ var ps = {
3840
3859
  }],
3841
3860
  graphOptimizationLevel: "all"
3842
3861
  }
3843
- }, ms = class extends ur {
3862
+ }, Es = class extends ur {
3844
3863
  constructor(e, t, n = {}) {
3845
3864
  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 = {
3865
+ 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 || Ts.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
3847
3866
  isUpscaling: !1,
3848
3867
  isLoading: !1,
3849
3868
  abortController: null
3850
3869
  }, 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
3870
  }
3852
3871
  async _ensureSession() {
3853
- let e = ps.QUALITY_PRESETS[this.quality];
3872
+ let e = Ts.QUALITY_PRESETS[this.quality];
3854
3873
  if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
3855
3874
  let t = e[this.scaleFactor];
3856
3875
  if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
@@ -3860,14 +3879,14 @@ var ps = {
3860
3879
  message: `Loading ${this.scaleFactor}x upscale model...`
3861
3880
  });
3862
3881
  try {
3863
- this._worker ||= new us(), await new Promise((e, n) => {
3882
+ this._worker ||= new Ss(), await new Promise((e, n) => {
3864
3883
  let r = (t) => {
3865
3884
  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
3885
  }, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o, storage: s } = it();
3867
3886
  this._worker.addEventListener("message", r), this._worker.postMessage({
3868
3887
  type: "load",
3869
3888
  url: t,
3870
- sessionOptions: ps.SESSION_OPTIONS,
3889
+ sessionOptions: Ts.SESSION_OPTIONS,
3871
3890
  ortRuntimeUrl: i,
3872
3891
  ortWasmPaths: a,
3873
3892
  cacheNamespace: o,
@@ -3942,7 +3961,7 @@ var ps = {
3942
3961
  alpha: !0
3943
3962
  });
3944
3963
  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;
3964
+ let o = Ts.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
3965
  for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
3947
3966
  if (e.aborted) throw new DOMException("Aborted", "AbortError");
3948
3967
  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 +4012,7 @@ var ps = {
3993
4012
  saturation: this.getSaturation(),
3994
4013
  gain: this.getDisplayGain()
3995
4014
  });
3996
- return this._toneMapper.release(), {
4015
+ return this._toneMapper.release(), this.getTransparentBackground() || i.fill(1, 3 * n * r), {
3997
4016
  planes: i,
3998
4017
  width: n,
3999
4018
  height: r,
@@ -4085,7 +4104,7 @@ var ps = {
4085
4104
  this.hdr = !!e;
4086
4105
  }
4087
4106
  setQuality(e) {
4088
- if (!ps.QUALITY_PRESETS[e]) {
4107
+ if (!Ts.QUALITY_PRESETS[e]) {
4089
4108
  console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
4090
4109
  return;
4091
4110
  }
@@ -4108,9 +4127,9 @@ var ps = {
4108
4127
  async dispose() {
4109
4128
  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
4129
  }
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 {
4130
+ }, Ds = We("neural"), Os = 120, ks = 2, As = 1, js = 0, Ms = 300, Ns = 5, Ps = 3, Fs = 3, Is = 16, Ls = (e) => Math.max(0, 1 - e / Is), Rs = class extends ur {
4112
4131
  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 = {
4132
+ 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 yr(), this._historyCamera = {
4114
4133
  world: null,
4115
4134
  projInv: null,
4116
4135
  viewProj: null,
@@ -4119,7 +4138,7 @@ var ps = {
4119
4138
  count: 0,
4120
4139
  leaves: new Uint32Array(),
4121
4140
  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;
4141
+ }, 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
4142
  }
4124
4143
  _createUpscalerCanvas(e) {
4125
4144
  let t = e.parentNode;
@@ -4141,7 +4160,7 @@ var ps = {
4141
4160
  }
4142
4161
  setupDenoiser() {
4143
4162
  let e = this._stages.pathTracer;
4144
- this.denoiser = new Go(this.renderer, {
4163
+ this.denoiser = new rs(this.renderer, {
4145
4164
  enableOIDN: Qr.enableOIDN,
4146
4165
  oidnQuality: Qr.oidnQuality,
4147
4166
  backendParams: () => ({
@@ -4160,12 +4179,12 @@ var ps = {
4160
4179
  };
4161
4180
  }
4162
4181
  }), this._syncOIDNInUse(), this._denoiserStartHandler = (e) => this.dispatchEvent({
4163
- type: M.DENOISING_START,
4182
+ type: P.DENOISING_START,
4164
4183
  continuous: !!e.continuous
4165
4184
  }), this._denoiserEndHandler = (e) => {
4166
4185
  let t = !e.continuous || this.continuousDenoise && !this._cadenceSuspended;
4167
4186
  this.denoiser?.hasOutput && t && this._publishOutput(), this.dispatchEvent({
4168
- type: M.DENOISING_END,
4187
+ type: P.DENOISING_END,
4169
4188
  continuous: !!e.continuous
4170
4189
  });
4171
4190
  }, this._denoiserTileHandler = (e) => {
@@ -4178,7 +4197,7 @@ var ps = {
4178
4197
  asset: "oidn-weights",
4179
4198
  cause: String(e.error?.message ?? e.error)
4180
4199
  }), 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,
4200
+ type: P.DENOISER_LOADING,
4182
4201
  loading: e.type === "loading"
4183
4202
  });
4184
4203
  for (let e of [
@@ -4187,14 +4206,14 @@ var ps = {
4187
4206
  "error"
4188
4207
  ]) this.denoiser.addEventListener(e, this._denoiserLoadHandler);
4189
4208
  this.denoiser.state?.isLoading && this.dispatchEvent({
4190
- type: M.DENOISER_LOADING,
4209
+ type: P.DENOISER_LOADING,
4191
4210
  loading: !0
4192
4211
  });
4193
4212
  }
4194
4213
  setupUpscaler() {
4195
4214
  if (!this.upscalerCanvas) return;
4196
4215
  let e = this._stages.pathTracer;
4197
- this.upscaler = new ms(this.upscalerCanvas, this.renderer, {
4216
+ this.upscaler = new Es(this.upscalerCanvas, this.renderer, {
4198
4217
  scaleFactor: Qr.upscalerScale || 2,
4199
4218
  quality: Qr.upscalerQuality || "fast",
4200
4219
  getSourceCanvas: () => this.renderer.domElement,
@@ -4210,15 +4229,16 @@ var ps = {
4210
4229
  getExposure: () => this._getEffectiveExposure(),
4211
4230
  getToneMapping: () => this._getToneMapping(),
4212
4231
  getSaturation: () => this._getSaturation(),
4213
- getDisplayGain: () => this._getDisplayGain?.() ?? null
4232
+ getDisplayGain: () => this._getDisplayGain?.() ?? null,
4233
+ getTransparentBackground: () => !!this._settings?.get("transparentBackground")
4214
4234
  }), this.upscaler.enabled = Qr.enableUpscaler || !1, this._upscalerResChangedHandler = (e) => this.dispatchEvent({
4215
- type: M.RESOLUTION_CHANGED,
4235
+ type: P.RESOLUTION_CHANGED,
4216
4236
  width: e.width,
4217
4237
  height: e.height
4218
- }), this._upscalerStartHandler = () => this.dispatchEvent({ type: M.UPSCALING_START }), this._upscalerProgressHandler = (e) => this.dispatchEvent({
4219
- type: M.UPSCALING_PROGRESS,
4238
+ }), this._upscalerStartHandler = () => this.dispatchEvent({ type: P.UPSCALING_START }), this._upscalerProgressHandler = (e) => this.dispatchEvent({
4239
+ type: P.UPSCALING_PROGRESS,
4220
4240
  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);
4241
+ }), 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
4242
  }
4223
4243
  get denoiserStrategy() {
4224
4244
  return this.continuousDenoise ? "oidn" : this._stages.nrd?.enabled ? "nrd" : "none";
@@ -4248,8 +4268,8 @@ var ps = {
4248
4268
  get holdsWhileMoving() {
4249
4269
  if (!this._stages.pathTracer?.viewIsChanging || !this.continuousDenoise || this._cadenceSuspended || !this.denoiser?.enabled || this._movingHopeless) return !1;
4250
4270
  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);
4271
+ e > Ms * Ps && (this._movingHopeless = !0, this._syncGBufferStages());
4272
+ let n = !this._movingHopeless && (t < 2 || e <= Ms);
4253
4273
  return this._holdWhileMoving = (this._holdWhileMoving === null || this._holdWhileMoving) && n, this._holdWhileMoving;
4254
4274
  }
4255
4275
  skipsTrace() {
@@ -4266,7 +4286,7 @@ var ps = {
4266
4286
  this.pipeline?.context?.removeTexture("oidn:output"), this.denoiser?.invalidateOutput();
4267
4287
  }
4268
4288
  _checkHeldFrameHealthy() {
4269
- !this.denoiser?.hasOutput || this._failedRefreshes < Cs || this._unpublishOutput();
4289
+ !this.denoiser?.hasOutput || this._failedRefreshes < Fs || this._unpublishOutput();
4270
4290
  }
4271
4291
  tickContinuousDenoise(e) {
4272
4292
  let t = this.denoiser;
@@ -4276,12 +4296,12 @@ var ps = {
4276
4296
  if (!n) this._holdWhileMoving = null, this._movingDenoiseMs.length = 0;
4277
4297
  else if (!this.holdsWhileMoving) return !1;
4278
4298
  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);
4299
+ let r = performance.now(), i = n ? js : this._lastCadenceSamples === 0 ? As : ks, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
4280
4300
  if (r - this._lastCadenceAt < a) return !1;
4281
- this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > gs && (this._cadenceDowngraded = !0);
4301
+ this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > Os && (this._cadenceDowngraded = !0);
4282
4302
  let o = this._cadenceDowngraded ? this.previewQuality() : this._finalQuality;
4283
4303
  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());
4304
+ this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > Ns && this._movingDenoiseMs.shift());
4285
4305
  }), !0;
4286
4306
  }
4287
4307
  previewQuality() {
@@ -4325,7 +4345,7 @@ var ps = {
4325
4345
  r && (this._ensureHistory().merge(r, t.frameCount, this._historyCameraNow(), {
4326
4346
  commit: !0,
4327
4347
  keepHistory: !this._historyDirty && !n,
4328
- historyScale: Ts(t.frameCount)
4348
+ historyScale: Ls(t.frameCount)
4329
4349
  }), this._historyDirty = !1);
4330
4350
  }
4331
4351
  afterReset() {
@@ -4367,9 +4387,9 @@ var ps = {
4367
4387
  let e = this._stages.pathTracer, t = this._history;
4368
4388
  if (!t?.valid || this._historyDirty || !this.historyActive || e.isComplete || e.resetCount !== this._knownResetCount || t.width !== this._lastRenderWidth || t.height !== this._lastRenderHeight) return null;
4369
4389
  if (e.frameCount <= 1) return t.textures;
4370
- if (e.frameCount >= ws) return null;
4390
+ if (e.frameCount >= Is) return null;
4371
4391
  let n = this._historyInputs();
4372
- return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Ts(e.frameCount) }) : null;
4392
+ return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Ls(e.frameCount) }) : null;
4373
4393
  }
4374
4394
  _historyInputs() {
4375
4395
  let e = this._stages.pathTracer, t = this.pipeline?.context, n = this.renderer?.backend;
@@ -4394,7 +4414,7 @@ var ps = {
4394
4414
  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
4415
  }
4396
4416
  _ensureHistory() {
4397
- return this._history ??= new ss(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
4417
+ return this._history ??= new ys(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
4398
4418
  }
4399
4419
  _releaseHistory() {
4400
4420
  this._history?.dispose(), this._history = null, this._historyDirty = !0, this._movedPlacements.clear();
@@ -4406,7 +4426,7 @@ var ps = {
4406
4426
  _restoreRenderDisplay() {
4407
4427
  let e = this.upscalerCanvas && this.upscalerCanvas.style.display !== "none";
4408
4428
  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,
4429
+ type: P.RESOLUTION_CHANGED,
4410
4430
  width: this._lastRenderWidth,
4411
4431
  height: this._lastRenderHeight
4412
4432
  }), !!e;
@@ -4432,15 +4452,15 @@ var ps = {
4432
4452
  return;
4433
4453
  }
4434
4454
  if (!this.pipeline?.context?.getTexture("oidn:output")) {
4435
- hs.warn("neural pass skipped: no denoised picture — it needs OIDN");
4455
+ Ds.warn("neural pass skipped: no denoised picture — it needs OIDN");
4436
4456
  return;
4437
4457
  }
4438
- this._neuralPostBusy = !0, this.dispatchEvent({ type: M.UPSCALING_START });
4458
+ this._neuralPostBusy = !0, this.dispatchEvent({ type: P.UPSCALING_START });
4439
4459
  try {
4440
- let i = await import("./NeuralSuperRes-WNEXun9s.js").then((e) => e.t);
4460
+ let i = await import("./NeuralSuperRes-C8Mf3tJX.js").then((e) => e.t);
4441
4461
  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) {
4462
+ let a = n ? await import("./NeuralRetouch-BD9E-Yht.js").then((e) => e.t) : null, o = this.denoiser?._outTexSize, s = (o?.width ?? 0) * (o?.height ?? 0), c = n && s <= a.RETOUCH_MAX_PIXELS;
4463
+ if (n && !c && (Ds.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
4464
  r && !this._postCancelled && await this.upscaler.start();
4445
4465
  return;
4446
4466
  }
@@ -4479,14 +4499,14 @@ var ps = {
4479
4499
  return;
4480
4500
  }
4481
4501
  this.mainCanvas && (this.mainCanvas.style.opacity = "0"), this.dispatchEvent({
4482
- type: M.RESOLUTION_CHANGED,
4502
+ type: P.RESOLUTION_CHANGED,
4483
4503
  width: d.width,
4484
4504
  height: d.height
4485
4505
  });
4486
4506
  } catch (e) {
4487
- hs.warn("neural pass failed", e);
4507
+ Ds.warn("neural pass failed", e);
4488
4508
  } finally {
4489
- this._neuralPostBusy = !1, this.dispatchEvent({ type: M.UPSCALING_END });
4509
+ this._neuralPostBusy = !1, this.dispatchEvent({ type: P.UPSCALING_END });
4490
4510
  }
4491
4511
  }
4492
4512
  }
@@ -4512,7 +4532,7 @@ var ps = {
4512
4532
  }));
4513
4533
  }
4514
4534
  cancelPostPasses() {
4515
- this._postCancelled = !0, this.upscaler?.abort(), this._restoreRenderDisplay(), this.dispatchEvent({ type: M.UPSCALING_END });
4535
+ this._postCancelled = !0, this.upscaler?.abort(), this._restoreRenderDisplay(), this.dispatchEvent({ type: P.UPSCALING_END });
4516
4536
  }
4517
4537
  onRenderComplete({ isStillComplete: e }) {
4518
4538
  this._cleanupCompletionListener(), this._postIsStillComplete = null;
@@ -4550,7 +4570,7 @@ var ps = {
4550
4570
  "error"
4551
4571
  ]) this.denoiser.removeEventListener(e, this._denoiserLoadHandler);
4552
4572
  this.denoiser.state?.isLoading && this.dispatchEvent({
4553
- type: M.DENOISER_LOADING,
4573
+ type: P.DENOISER_LOADING,
4554
4574
  loading: !1
4555
4575
  });
4556
4576
  }
@@ -4646,7 +4666,7 @@ var ps = {
4646
4666
  ...t
4647
4667
  });
4648
4668
  }
4649
- }, Ds = class {
4669
+ }, zs = class {
4650
4670
  constructor() {
4651
4671
  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
4672
  }
@@ -4670,18 +4690,18 @@ var ps = {
4670
4690
  dispose() {
4671
4691
  this.visible = !1;
4672
4692
  }
4673
- }, Os = class {
4693
+ }, Bs = class {
4674
4694
  constructor(e, t) {
4675
4695
  this.layer = "scene", this._enabled = !0, this._scene = e, this._camera = t, this._build([]);
4676
4696
  }
4677
4697
  _build(e) {
4678
- this._orthographic = this._camera.isOrthographicCamera === !0, this._outlineNode = Vr(this._scene, this._camera, {
4698
+ this._orthographic = this._camera.isOrthographicCamera === !0, this._outlineNode = Hr(this._scene, this._camera, {
4679
4699
  selectedObjects: e,
4680
- edgeThickness: G(1),
4681
- edgeGlow: G(0)
4700
+ edgeThickness: q(1),
4701
+ edgeGlow: q(0)
4682
4702
  });
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);
4703
+ 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);
4704
+ 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
4705
  }
4686
4706
  setSelectedObjects(e) {
4687
4707
  this._outlineNode.selectedObjects = e;
@@ -4708,11 +4728,11 @@ var ps = {
4708
4728
  this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
4709
4729
  }
4710
4730
  };
4711
- function ks(e = !1) {
4731
+ function Vs(e = !1) {
4712
4732
  let t = document.createElement("canvas");
4713
4733
  return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
4714
4734
  }
4715
- function As(e, t = Infinity) {
4735
+ function Hs(e, t = Infinity) {
4716
4736
  let n = e?.getBoundingClientRect();
4717
4737
  if (!n || n.width === 0 || n.height === 0) return null;
4718
4738
  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 +4743,9 @@ function As(e, t = Infinity) {
4723
4743
  }
4724
4744
  //#endregion
4725
4745
  //#region src/managers/helpers/ViewOverlayRenderer.js
4726
- var js = 4096, Ms = class {
4746
+ var Us = 4096, Ws = class {
4727
4747
  constructor() {
4728
- this.canvas = ks(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
4748
+ this.canvas = Vs(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
4729
4749
  }
4730
4750
  async init({ device: e, sizeSource: t }) {
4731
4751
  this._sizeSource = t;
@@ -4735,14 +4755,14 @@ var js = 4096, Ms = class {
4735
4755
  alpha: !0,
4736
4756
  antialias: (window.devicePixelRatio || 1) < 2
4737
4757
  });
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;
4758
+ 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
4759
  }
4740
4760
  get isVisible() {
4741
4761
  return this._visible;
4742
4762
  }
4743
4763
  syncSize() {
4744
4764
  if (!this.renderer) return;
4745
- let e = As(this._sizeSource, js);
4765
+ let e = Hs(this._sizeSource, Us);
4746
4766
  !e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
4747
4767
  }
4748
4768
  begin() {
@@ -4754,18 +4774,18 @@ var js = 4096, Ms = class {
4754
4774
  dispose() {
4755
4775
  Me(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
4756
4776
  }
4757
- }, Ns = We("overlay"), Ps = (e, t) => e.visible && e.layer === t && e.render, Fs = class {
4777
+ }, Gs = We("overlay"), Ks = (e, t) => e.visible && e.layer === t && e.render, qs = class {
4758
4778
  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;
4779
+ this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = Vs(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
4760
4780
  }
4761
4781
  async initViewRenderer({ device: e, sizeSource: t }) {
4762
4782
  if (!(!e || !t)) try {
4763
- this._viewOverlay = await new Ms().init({
4783
+ this._viewOverlay = await new Ws().init({
4764
4784
  device: e,
4765
4785
  sizeSource: t
4766
4786
  });
4767
4787
  } catch (e) {
4768
- Ns.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
4788
+ Gs.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
4769
4789
  }
4770
4790
  }
4771
4791
  gpuResources() {
@@ -4785,11 +4805,11 @@ var js = 4096, Ms = class {
4785
4805
  }
4786
4806
  setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
4787
4807
  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) => {
4808
+ let s = new zs();
4809
+ this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(P.RESOLUTION_CHANGED, (e) => {
4790
4810
  s.setRenderSize(e.width, e.height);
4791
4811
  }), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
4792
- let c = new Os(t, this.camera);
4812
+ let c = new Bs(t, this.camera);
4793
4813
  this.register("outline", c);
4794
4814
  }
4795
4815
  _wireDenoiserTileEvents(e, t) {
@@ -4801,7 +4821,7 @@ var js = 4096, Ms = class {
4801
4821
  }));
4802
4822
  }
4803
4823
  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);
4824
+ this._helpers.has(e) && (Gs.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
4805
4825
  }
4806
4826
  unregister(e) {
4807
4827
  let t = this._helpers.get(e);
@@ -4839,16 +4859,16 @@ var js = 4096, Ms = class {
4839
4859
  }
4840
4860
  _renderSceneLayer(e) {
4841
4861
  this._helperScene?.render(e, this.camera);
4842
- for (let t of this._helpers.values()) Ps(t, "scene") && t.render(e, this.camera);
4862
+ for (let t of this._helpers.values()) Ks(t, "scene") && t.render(e, this.camera);
4843
4863
  }
4844
4864
  _hasVisibleSceneOverlay() {
4845
4865
  if (this._helperScene?.isDrawing) return !0;
4846
- for (let e of this._helpers.values()) if (Ps(e, "scene")) return !0;
4866
+ for (let e of this._helpers.values()) if (Ks(e, "scene")) return !0;
4847
4867
  return !1;
4848
4868
  }
4849
4869
  refreshHUD() {
4850
4870
  let e = this._hudCanvas, t = this._hudCtx, n = !1;
4851
- for (let e of this._helpers.values()) if (Ps(e, "hud")) {
4871
+ for (let e of this._helpers.values()) if (Ks(e, "hud")) {
4852
4872
  n = !0;
4853
4873
  break;
4854
4874
  }
@@ -4857,10 +4877,10 @@ var js = 4096, Ms = class {
4857
4877
  return;
4858
4878
  }
4859
4879
  e.style.display !== "" && (e.style.display = "");
4860
- let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? As(e) : null;
4880
+ let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Hs(e) : null;
4861
4881
  if (a) {
4862
4882
  (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);
4883
+ for (let e of this._helpers.values()) Ks(e, "hud") && e.render(t, r, i);
4864
4884
  t.restore(), e.style.display !== "" && (e.style.display = "");
4865
4885
  }
4866
4886
  }
@@ -4871,7 +4891,7 @@ var js = 4096, Ms = class {
4871
4891
  };
4872
4892
  //#endregion
4873
4893
  //#region src/managers/AnimationManager.js
4874
- function Is(e, t) {
4894
+ function Js(e, t) {
4875
4895
  let n = [...e].filter((t) => {
4876
4896
  for (let n = t.parent; n; n = n.parent) if (e.has(n)) return !1;
4877
4897
  return !0;
@@ -4880,9 +4900,9 @@ function Is(e, t) {
4880
4900
  for (let e of n) e.traverse?.(() => i++);
4881
4901
  return i + n.length / 2 < r ? n : null;
4882
4902
  }
4883
- var Ls = class extends ur {
4903
+ var Ys = class extends ur {
4884
4904
  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;
4905
+ 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
4906
  }
4887
4907
  init(e, t, n, r) {
4888
4908
  if (this.dispose(), !r || r.length === 0) return;
@@ -4915,7 +4935,7 @@ var Ls = class extends ur {
4915
4935
  }), this._plans = e.map((e) => {
4916
4936
  let r = /* @__PURE__ */ new Set(), i = !1, a = !1;
4917
4937
  for (let o of e.tracks) {
4918
- let { nodeName: e, propertyName: s } = Er.parseTrackName(o.name), c = e === "" || e === "." ? t : n.get(e);
4938
+ let { nodeName: e, propertyName: s } = Dr.parseTrackName(o.name), c = e === "" || e === "." ? t : n.get(e);
4919
4939
  if (!c) {
4920
4940
  a = !0;
4921
4941
  continue;
@@ -4934,7 +4954,7 @@ var Ls = class extends ur {
4934
4954
  visibility: i,
4935
4955
  cameras: [...s],
4936
4956
  nodes: a ? null : r,
4937
- roots: a ? null : Is(r, t)
4957
+ roots: a ? null : Js(r, t)
4938
4958
  };
4939
4959
  }), this._allPlan = null, !this._rigid) return;
4940
4960
  this._slotOf = new Int32Array(this._meshes.length).fill(-1);
@@ -4953,7 +4973,7 @@ var Ls = class extends ur {
4953
4973
  visibility: n,
4954
4974
  cameras: [...t],
4955
4975
  nodes: r,
4956
- roots: r ? Is(r, this._mixerRoot) : null
4976
+ roots: r ? Js(r, this._mixerRoot) : null
4957
4977
  };
4958
4978
  }
4959
4979
  return this._allPlan;
@@ -4988,17 +5008,17 @@ var Ls = class extends ur {
4988
5008
  if (!(!this.mixer || this.actions.length === 0)) {
4989
5009
  if (this.mixer.stopAllAction(), e === -1) for (let e of this.actions) e.play();
4990
5010
  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 });
5011
+ this._activeClip = e, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: P.ANIMATION_STARTED });
4992
5012
  }
4993
5013
  }
4994
5014
  pause() {
4995
- this.mixer && (this.mixer.timeScale = 0, this.timer.reset(), this.isPlaying = !1, this.dispatchEvent({ type: M.ANIMATION_PAUSED }));
5015
+ this.mixer && (this.mixer.timeScale = 0, this.timer.reset(), this.isPlaying = !1, this.dispatchEvent({ type: P.ANIMATION_PAUSED }));
4996
5016
  }
4997
5017
  resume() {
4998
- this.mixer && (this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: M.ANIMATION_STARTED }));
5018
+ this.mixer && (this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: P.ANIMATION_STARTED }));
4999
5019
  }
5000
5020
  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 }));
5021
+ 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
5022
  }
5003
5023
  setSpeed(e) {
5004
5024
  this._savedTimeScale = e, this.mixer && this.isPlaying && (this.mixer.timeScale = e);
@@ -5085,19 +5105,19 @@ var Ls = class extends ur {
5085
5105
  dispose() {
5086
5106
  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
5107
  }
5088
- }, Rs = new Z(0, 0, -1), zs = (e) => {
5108
+ }, Xs = new Q(0, 0, -1), Zs = (e) => {
5089
5109
  for (; e.parent;) e = e.parent;
5090
5110
  return e.isScene ? e : null;
5091
- }, Bs = class {
5111
+ }, Qs = class {
5092
5112
  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);
5113
+ 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
5114
  }
5095
5115
  setMeshData(e) {
5096
5116
  this._meshes = e;
5097
- for (let e of this._moved) zs(e) || this._moved.delete(e);
5117
+ for (let e of this._moved) Zs(e) || this._moved.delete(e);
5098
5118
  }
5099
5119
  get movedObjects() {
5100
- return [...this._moved].filter((e) => zs(e));
5120
+ return [...this._moved].filter((e) => Zs(e));
5101
5121
  }
5102
5122
  noteMoved(e) {
5103
5123
  e && !e.isLight && this._moved.add(e);
@@ -5110,7 +5130,7 @@ var Ls = class extends ur {
5110
5130
  }
5111
5131
  setMode(e) {
5112
5132
  this._controls.setMode(e), this._app?.dispatchEvent({
5113
- type: M.TRANSFORM_MODE_CHANGED,
5133
+ type: P.TRANSFORM_MODE_CHANGED,
5114
5134
  mode: e
5115
5135
  }), this._app?.refreshFrame();
5116
5136
  }
@@ -5132,7 +5152,7 @@ var Ls = class extends ur {
5132
5152
  e.autoClear = !1, e.clearDepth(), e.setRenderTarget(null), e.render(this._gizmoScene, this._camera), e.autoClear = t;
5133
5153
  }
5134
5154
  _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 }));
5155
+ 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
5156
  }
5137
5157
  _onObjectChange() {
5138
5158
  this._app.needsReset = !0, this._app.wake(), this._attached?.isLight && this._syncLightDuringDrag();
@@ -5158,7 +5178,7 @@ var Ls = class extends ur {
5158
5178
  }
5159
5179
  _syncLightAim(e) {
5160
5180
  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;
5181
+ n > 1e-4 ? (e.quaternion.setFromUnitVectors(Xs, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
5162
5182
  }
5163
5183
  _recomputeAndRefit() {
5164
5184
  if (!this._meshes || this._refitInFlight || !this._attached) return;
@@ -5194,7 +5214,7 @@ var Ls = class extends ur {
5194
5214
  dispose() {
5195
5215
  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
5216
  }
5197
- }, Vs = class {
5217
+ }, $s = class {
5198
5218
  constructor(e) {
5199
5219
  this.layer = "scene", this._transformManager = e, this._enabled = !0;
5200
5220
  }
@@ -5213,8 +5233,8 @@ var Ls = class extends ur {
5213
5233
  dispose() {
5214
5234
  this._enabled = !1;
5215
5235
  }
5216
- }, Hs = 1, Us = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5217
- function Ws(e, t) {
5236
+ }, ec = 1, tc = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5237
+ function nc(e, t) {
5218
5238
  let n = [];
5219
5239
  for (; e && e !== t;) {
5220
5240
  let t = e.parent;
@@ -5223,12 +5243,12 @@ function Ws(e, t) {
5223
5243
  }
5224
5244
  return e === t ? n : null;
5225
5245
  }
5226
- function Gs(e, t) {
5246
+ function rc(e, t) {
5227
5247
  let n = e;
5228
5248
  for (let e of t) if (n = n?.children[e], !n) return null;
5229
5249
  return n;
5230
5250
  }
5231
- function Ks(e) {
5251
+ function ic(e) {
5232
5252
  return {
5233
5253
  key: e.assetLoader?.sceneSourceKey ?? null,
5234
5254
  name: e.sceneModel?.name ?? null,
@@ -5236,7 +5256,7 @@ function Ks(e) {
5236
5256
  materials: e.stages.pathTracer?.materialData.materialCount ?? 0
5237
5257
  };
5238
5258
  }
5239
- function qs(e) {
5259
+ function ac(e) {
5240
5260
  let t = /* @__PURE__ */ new Map();
5241
5261
  for (let n of e.sceneMeshes) {
5242
5262
  let e = n.userData?.materialIndex;
@@ -5244,7 +5264,7 @@ function qs(e) {
5244
5264
  }
5245
5265
  return t;
5246
5266
  }
5247
- function Js(e) {
5267
+ function oc(e) {
5248
5268
  if (!e) return null;
5249
5269
  let t = e.status(), n = t.activeView, r = t.config?.id ?? n?.configId ?? null;
5250
5270
  return {
@@ -5259,15 +5279,15 @@ function Js(e) {
5259
5279
  context: t.context ?? null
5260
5280
  };
5261
5281
  }
5262
- function Ys(e) {
5263
- let t = e.meshScene, n = qs(e), r = [];
5282
+ function sc(e) {
5283
+ let t = e.meshScene, n = ac(e), r = [];
5264
5284
  return t.traverse((e) => {
5265
- e !== t && e.visible === !1 && r.push(Ws(e, t));
5285
+ e !== t && e.visible === !1 && r.push(nc(e, t));
5266
5286
  }), {
5267
5287
  v: 1,
5268
5288
  engine: Re,
5269
5289
  savedAt: Date.now(),
5270
- scene: Ks(e),
5290
+ scene: ic(e),
5271
5291
  appended: t.children.filter((t) => t !== e.sceneModel && t.userData?.__rayzeeSceneObject).map((e) => ({
5272
5292
  name: e.userData.__rayzeeName ?? e.name,
5273
5293
  url: e.userData.__rayzeeSourceUrl ?? null,
@@ -5275,7 +5295,7 @@ function Ys(e) {
5275
5295
  })),
5276
5296
  settings: e.settings.serialize(),
5277
5297
  environment: e.environmentManager?.serialize() ?? null,
5278
- color: Js(e.color),
5298
+ color: oc(e.color),
5279
5299
  lights: e.lightManager.serialize(),
5280
5300
  cameras: e.cameraManager.serialize(),
5281
5301
  timeline: e.timeline?.serialize() ?? null,
@@ -5285,7 +5305,7 @@ function Ys(e) {
5285
5305
  })),
5286
5306
  hidden: r,
5287
5307
  moved: (e.transformManager?.movedObjects ?? []).map((e) => ({
5288
- path: Ws(e, t),
5308
+ path: nc(e, t),
5289
5309
  name: e.name,
5290
5310
  position: e.position.toArray(),
5291
5311
  quaternion: e.quaternion.toArray(),
@@ -5293,15 +5313,15 @@ function Ys(e) {
5293
5313
  })).filter((e) => e.path)
5294
5314
  };
5295
5315
  }
5296
- function Xs(e, t, n) {
5316
+ function cc(e, t, n) {
5297
5317
  let r = e[t];
5298
5318
  r?.copy && (n?.isColor || n?.isVector2 || n?.isVector3) ? r.copy(n) : e[t] = n, e.needsUpdate = !0;
5299
5319
  }
5300
- async function Zs(e, t, n, r) {
5320
+ async function lc(e, t, n, r) {
5301
5321
  if (!t) return;
5302
5322
  let i = e.environmentManager;
5303
5323
  if (t.hdri && t.hdri !== i.hdriSource) {
5304
- let i = Us(t.hdri) ? t.hdri : await n({
5324
+ let i = tc(t.hdri) ? t.hdri : await n({
5305
5325
  kind: "environment",
5306
5326
  source: t.hdri
5307
5327
  });
@@ -5313,7 +5333,7 @@ async function Zs(e, t, n, r) {
5313
5333
  }
5314
5334
  await i.restore(t);
5315
5335
  }
5316
- async function Qs(e, t, n, r) {
5336
+ async function uc(e, t, n, r) {
5317
5337
  let i = e.color;
5318
5338
  if (!t || !i) return;
5319
5339
  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 +5358,7 @@ async function Qs(e, t, n, r) {
5338
5358
  r("color", e.message, { config: t.config?.id ?? null });
5339
5359
  }
5340
5360
  }
5341
- async function $s(e, t, { resolve: n = async () => null } = {}) {
5361
+ async function dc(e, t, { resolve: n = async () => null } = {}) {
5342
5362
  if (t?.v !== 1) throw Error(`scene state version ${t?.v} is not 1`);
5343
5363
  let r = [], i = (e, t, n = {}) => r.push({
5344
5364
  section: e,
@@ -5359,11 +5379,11 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5359
5379
  i("appended", e.message, { name: n.name });
5360
5380
  }
5361
5381
  }
5362
- let a = Ks(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
5382
+ let a = ic(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
5363
5383
  s || i("scene", "the loaded scene is not the one saved: objects and materials left as loaded", {
5364
5384
  saved: o,
5365
5385
  now: a
5366
- }), await Zs(e, t.environment, n, i), await Qs(e, t.color, n, i);
5386
+ }), await lc(e, t.environment, n, i), await uc(e, t.color, n, i);
5367
5387
  let c = e.settings.restore(t.settings);
5368
5388
  c.length && i("settings", "not settings in this engine", { keys: c });
5369
5389
  let l = e.lightManager.restore(t.lights);
@@ -5372,7 +5392,7 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5372
5392
  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
5393
  }
5374
5394
  if (s) {
5375
- let n = qs(e);
5395
+ let n = ac(e);
5376
5396
  for (let r of t.materials ?? []) {
5377
5397
  let t = n.get(r.index);
5378
5398
  if (!t || (t.name ?? "") !== r.name) {
@@ -5383,17 +5403,17 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5383
5403
  continue;
5384
5404
  }
5385
5405
  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);
5406
+ let a = ce(i);
5407
+ cc(t, n, a), e.setMaterialProperty(r.index, n, a);
5388
5408
  }
5389
5409
  }
5390
- let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => Gs(r, e)).filter(Boolean));
5410
+ let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => rc(r, e)).filter(Boolean));
5391
5411
  r.traverse((e) => {
5392
5412
  e !== r && !e.isLight && (e.visible = !a.has(e));
5393
5413
  }), e.updateAllMeshVisibility();
5394
5414
  let o = [];
5395
5415
  for (let n of t.moved ?? []) {
5396
- let t = Gs(r, n.path);
5416
+ let t = rc(r, n.path);
5397
5417
  if (!t || t.name !== n.name) {
5398
5418
  i("moved", "no such object", { name: n.name });
5399
5419
  continue;
@@ -5415,7 +5435,7 @@ async function $s(e, t, { resolve: n = async () => null } = {}) {
5415
5435
  }
5416
5436
  //#endregion
5417
5437
  //#region src/PathTracerApp.js
5418
- var ec = We("engine"), tc = class extends w {
5438
+ var fc = We("engine"), pc = class extends w {
5419
5439
  constructor(e, t = {}) {
5420
5440
  super(e, t), this.setColorManagement(Zt), this.setStorageOpener(cn), this.settings.define("interactionRenderScale", {
5421
5441
  default: .5,
@@ -5423,16 +5443,16 @@ var ec = We("engine"), tc = class extends w {
5423
5443
  this.stages?.pathTracer?.interactionMode && this._requestRenderScale(this._interactionRenderScale());
5424
5444
  },
5425
5445
  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();
5446
+ }), 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 Ys();
5427
5447
  }
5428
5448
  _createCamera() {
5429
- return this.cameraManager = new io(this.canvas), this.timeline = new uo({
5449
+ return this.cameraManager = new _o(this.canvas), this.timeline = new Co({
5430
5450
  cameraManager: this.cameraManager,
5431
5451
  onReset: () => this.reset()
5432
5452
  }), this.cameraManager.camera;
5433
5453
  }
5434
5454
  _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);
5455
+ super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Et), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-BJxszU_k.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Ct);
5436
5456
  let e = () => {
5437
5457
  this.needsReset = !0, this.stages.pathTracer?.enterInteractionMode(), this.wake();
5438
5458
  };
@@ -5440,10 +5460,10 @@ var ec = We("engine"), tc = class extends w {
5440
5460
  }
5441
5461
  _createExtraStages() {
5442
5462
  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, {
5463
+ return t.normalDepth = new $r(e, { pathTracer: t.pathTracer }), t.motionVector = new ei(e, this.camera, { pathTracer: t.pathTracer }), t.nrd = new Ki(e, {
5444
5464
  enabled: !1,
5445
5465
  pathTracer: t.pathTracer
5446
- }), t.autoExposure = new la(e, { enabled: Ri.autoExposure }), t.localExposure = new Aa(e, { enabled: ua.localExposure }), [
5466
+ }), t.autoExposure = new ba(e, { enabled: qi.autoExposure }), t.localExposure = new Ha(e, { enabled: xa.localExposure }), [
5447
5467
  t.normalDepth,
5448
5468
  t.motionVector,
5449
5469
  t.nrd,
@@ -5455,7 +5475,7 @@ var ec = We("engine"), tc = class extends w {
5455
5475
  super._initPipeline(), this.pipeline.eventBus.on("pathtracer:interactionStart", () => this._requestRenderScale(this._interactionRenderScale())), this.pipeline.eventBus.on("pathtracer:interactionEnd", () => this._applyRenderScale(1));
5456
5476
  }
5457
5477
  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({
5478
+ await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-cKy75-oR.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 qa({
5459
5479
  scene: this.meshScene,
5460
5480
  camera: this.camera,
5461
5481
  canvas: this.canvas,
@@ -5463,18 +5483,18 @@ var ec = We("engine"), tc = class extends w {
5463
5483
  pathTracer: null,
5464
5484
  floorPlane: this.assetLoader.floorPlane,
5465
5485
  isGeometryOnDisk: () => this.geometryOnDisk
5466
- }), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new fo(this.stages.pathTracer, {
5486
+ }), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new wo(this.stages.pathTracer, {
5467
5487
  onReset: () => this.reset(),
5468
5488
  issues: this._issues
5469
- }), this.iesManager = new wo(this.stages.pathTracer, {
5489
+ }), this.iesManager = new Io(this.stages.pathTracer, {
5470
5490
  onReset: () => this.reset(),
5471
5491
  issues: this._issues
5472
- }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new Bs({
5492
+ }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new Qs({
5473
5493
  camera: this.camera,
5474
5494
  canvas: this.canvas,
5475
5495
  orbitControls: this.cameraManager.controls,
5476
5496
  app: this
5477
- }), this.overlayManager.register("transform", new Vs(this.transformManager))), this.interactionManager.setDependencies({
5497
+ }), this.overlayManager.register("transform", new $s(this.transformManager))), this.interactionManager.setDependencies({
5478
5498
  overlayManager: this.overlayManager,
5479
5499
  transformManager: this.transformManager,
5480
5500
  appDispatch: (e) => this.dispatchEvent(e),
@@ -5483,21 +5503,21 @@ var ec = We("engine"), tc = class extends w {
5483
5503
  }), 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
5504
  }
5485
5505
  _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
5506
+ 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, [
5507
+ P.DENOISING_START,
5508
+ P.DENOISING_END,
5509
+ P.DENOISER_LOADING,
5510
+ P.UPSCALING_START,
5511
+ P.UPSCALING_PROGRESS,
5512
+ P.UPSCALING_END,
5513
+ P.RESOLUTION_CHANGED
5494
5514
  ]), 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, () => {
5515
+ P.ANIMATION_STARTED,
5516
+ P.ANIMATION_PAUSED,
5517
+ P.ANIMATION_STOPPED
5518
+ ]), this._addTrackedListener(this.animationManager, P.ANIMATION_PAUSED, () => {
5499
5519
  this._animRefitInFlight = !1, this._refreshMovedEmitters();
5500
- }), this._addTrackedListener(this.animationManager, M.ANIMATION_STOPPED, () => {
5520
+ }), this._addTrackedListener(this.animationManager, P.ANIMATION_STOPPED, () => {
5501
5521
  this._animRefitInFlight = !1;
5502
5522
  }), this.cameraManager.initCallbacks({
5503
5523
  onResize: () => this.onResize(),
@@ -5526,7 +5546,7 @@ var ec = We("engine"), tc = class extends w {
5526
5546
  return {
5527
5547
  ...e,
5528
5548
  applyExposure: (t) => {
5529
- this.stages.autoExposure ? this.stages.autoExposure.setCompensation(t) : e.applyExposure(t);
5549
+ this.stages.autoExposure ? this.stages.autoExposure.setCompensation(t) : e.applyExposure(t), this.stages.compositor?.setBackdropExposure(t);
5530
5550
  },
5531
5551
  onCameraProjection: (e) => {
5532
5552
  this.cameraManager.applyProjection(e), e === "equirectangular" && this.denoisingManager?.requiresMotionVectors ? this.denoisingManager.setDenoiserStrategy("oidn") : this.denoisingManager?._syncGBufferStages?.();
@@ -5536,7 +5556,7 @@ var ec = We("engine"), tc = class extends w {
5536
5556
  _beginFrame() {
5537
5557
  if (this.timeline.update(), this.cameraManager.updateControls(), this._updateExposure(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
5538
5558
  let e = this.animationManager.update();
5539
- e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => ec.error("animation refit error:", e)).finally(() => {
5559
+ e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => fc.error("animation refit error:", e)).finally(() => {
5540
5560
  this._animRefitInFlight = !1;
5541
5561
  }));
5542
5562
  }
@@ -5561,7 +5581,14 @@ var ec = We("engine"), tc = class extends w {
5561
5581
  }
5562
5582
  _displayGain() {
5563
5583
  let e = this.stages.localExposure;
5564
- return e?.wantsBuild && e.build(this.pipeline.context), e?.toneGain() ?? null;
5584
+ e?.wantsBuild && e.build(this.pipeline.context);
5585
+ let t = e?.toneGain() ?? null;
5586
+ if (this.pipeline?.context.getState("pathtracer:backdrop") !== "color") return t;
5587
+ let { toneMappingExposure: n, toneMapping: r } = this.renderer;
5588
+ return {
5589
+ ...t,
5590
+ backdrop: le(this.settings.get("exposure") ?? 1, n, r)
5591
+ };
5565
5592
  }
5566
5593
  setLocalExposure(e) {
5567
5594
  let t = this.stages.localExposure;
@@ -5668,14 +5695,14 @@ var ec = We("engine"), tc = class extends w {
5668
5695
  return t && this._dispatchCamerasUpdated(), t;
5669
5696
  }
5670
5697
  exportSceneState() {
5671
- return Ys(this);
5698
+ return sc(this);
5672
5699
  }
5673
5700
  async importSceneState(e, t) {
5674
- return await $s(this, e, t);
5701
+ return await dc(this, e, t);
5675
5702
  }
5676
5703
  _dispatchCamerasUpdated() {
5677
5704
  this.dispatchEvent({
5678
- type: M.CAMERAS_UPDATED,
5705
+ type: P.CAMERAS_UPDATED,
5679
5706
  cameras: this.cameraManager.cameras,
5680
5707
  cameraNames: this.cameraManager.getCameraNames()
5681
5708
  });
@@ -5705,11 +5732,11 @@ var ec = We("engine"), tc = class extends w {
5705
5732
  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
5733
  if (!i) return !1;
5707
5734
  i.updateWorldMatrix(!0, !1);
5708
- let a = new Z();
5735
+ let a = new Q();
5709
5736
  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
5737
  let o = t.camera, s = t.controls, c = s ? s.target.distanceTo(o.position) : 0;
5711
5738
  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);
5739
+ let e = new Q(0, 0, -1).applyQuaternion(o.quaternion);
5713
5740
  s.target.copy(o.position).addScaledVector(e, c || 1);
5714
5741
  }
5715
5742
  return !0;
@@ -5759,7 +5786,7 @@ var ec = We("engine"), tc = class extends w {
5759
5786
  if (this.denoisingManager?.abort(this.canvas, { keepDisplay: e }), this.denoisingManager?.restoreBaseResolution()) {
5760
5787
  let e = this.denoisingManager._lastRenderWidth, t = this.denoisingManager._lastRenderHeight;
5761
5788
  this.dispatchEvent({
5762
- type: M.RESOLUTION_CHANGED,
5789
+ type: P.RESOLUTION_CHANGED,
5763
5790
  width: e,
5764
5791
  height: t
5765
5792
  });
@@ -5787,13 +5814,13 @@ var ec = We("engine"), tc = class extends w {
5787
5814
  if (e.length > 0) {
5788
5815
  let t = this.sceneModel || this.meshScene;
5789
5816
  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 });
5817
+ this._animRefitInFlight = !1, this._refreshMovedEmitters(), this.dispatchEvent({ type: P.ANIMATION_FINISHED });
5791
5818
  };
5792
5819
  }
5793
5820
  this.transformManager?.setMeshData(this._sdf.meshes);
5794
5821
  }
5795
5822
  _setupDenoisingManager() {
5796
- this.denoisingManager = new Es({
5823
+ this.denoisingManager = new Rs({
5797
5824
  renderer: this.renderer,
5798
5825
  mainCanvas: this.canvas,
5799
5826
  stages: {
@@ -5815,9 +5842,9 @@ var ec = We("engine"), tc = class extends w {
5815
5842
  }
5816
5843
  _setupAutoExposureListener() {
5817
5844
  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 }) => {
5845
+ 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
5846
  this.dispatchEvent({
5820
- type: M.AUTO_EXPOSURE_UPDATED,
5847
+ type: P.AUTO_EXPOSURE_UPDATED,
5821
5848
  exposure: e,
5822
5849
  autoExposure: t,
5823
5850
  targetExposure: n,
@@ -5845,7 +5872,7 @@ var ec = We("engine"), tc = class extends w {
5845
5872
  }, n && this.stages.autoExposure?.noteViewChanged());
5846
5873
  }
5847
5874
  async _setupOverlayManager() {
5848
- this.overlayManager = new Fs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
5875
+ this.overlayManager = new qs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
5849
5876
  helperScene: this._sceneHelpers,
5850
5877
  meshScene: this.meshScene,
5851
5878
  pipeline: this.pipeline,
@@ -5876,15 +5903,15 @@ var ec = We("engine"), tc = class extends w {
5876
5903
  };
5877
5904
  //#endregion
5878
5905
  //#region src/Headless.js
5879
- async function nc(e) {
5880
- let t = await ic(e);
5906
+ async function mc(e) {
5907
+ let t = await gc(e);
5881
5908
  try {
5882
- return await rc(t, e);
5909
+ return await hc(t, e);
5883
5910
  } finally {
5884
5911
  t.dispose();
5885
5912
  }
5886
5913
  }
5887
- async function rc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
5914
+ async function hc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
5888
5915
  let o = e.denoisingManager;
5889
5916
  i && o && !o.finalDenoise && (o.applyOIDNEnabled(!0), o._syncGBufferStages());
5890
5917
  let s = await e.renderFrames(t, {
@@ -5903,8 +5930,8 @@ async function rc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire
5903
5930
  provenance: e.getProvenance()
5904
5931
  };
5905
5932
  }
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, {
5933
+ async function gc({ 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 } = {}) {
5934
+ let l = new pc(e ?? null, {
5908
5935
  autoResize: !1,
5909
5936
  strict: i,
5910
5937
  storage: s,
@@ -5918,7 +5945,7 @@ async function ic({ canvas: e, model: t = null, width: n = 1920, height: r = 108
5918
5945
  }
5919
5946
  //#endregion
5920
5947
  //#region src/managers/VideoRenderManager.js
5921
- var ac = class {
5948
+ var _c = class {
5922
5949
  constructor(e) {
5923
5950
  this._app = e, this._cancelled = !1, this._rendering = !1;
5924
5951
  }
@@ -5959,7 +5986,7 @@ var ac = class {
5959
5986
  percent: (e + 1) / m * 100
5960
5987
  };
5961
5988
  l?.(p), d.dispatchEvent({
5962
- type: M.VIDEO_RENDER_PROGRESS,
5989
+ type: P.VIDEO_RENDER_PROGRESS,
5963
5990
  ...p
5964
5991
  });
5965
5992
  }
@@ -5969,7 +5996,7 @@ var ac = class {
5969
5996
  this._restoreState(g), this._rendering = !1;
5970
5997
  let e = !this._cancelled;
5971
5998
  u?.(e), d.dispatchEvent({
5972
- type: M.VIDEO_RENDER_COMPLETE,
5999
+ type: P.VIDEO_RENDER_COMPLETE,
5973
6000
  success: e
5974
6001
  });
5975
6002
  }
@@ -5994,13 +6021,13 @@ var ac = class {
5994
6021
  _waitForDenoise(e) {
5995
6022
  return new Promise((t) => {
5996
6023
  let n, r = () => {
5997
- e.removeEventListener(M.DENOISING_END, i), clearTimeout(n);
6024
+ e.removeEventListener(P.DENOISING_END, i), clearTimeout(n);
5998
6025
  }, i = () => {
5999
6026
  r(), t();
6000
6027
  };
6001
6028
  n = setTimeout(() => {
6002
6029
  console.warn("VideoRenderManager: Denoise timed out, skipping"), r(), t();
6003
- }, 3e4), e.addEventListener(M.DENOISING_END, i), e.denoisingManager.onRenderComplete({
6030
+ }, 3e4), e.addEventListener(P.DENOISING_END, i), e.denoisingManager.onRenderComplete({
6004
6031
  isStillComplete: () => !this._cancelled,
6005
6032
  context: e.pipeline?.context
6006
6033
  });
@@ -6032,4 +6059,4 @@ var ac = class {
6032
6059
  }
6033
6060
  };
6034
6061
  //#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 };
6062
+ export { Ct as ARCHIVE_FORMATS, qi as AUTO_EXPOSURE_DEFAULTS, uo as AUTO_FOCUS_DEFAULTS, Ys as AnimationManager, qe as BVH_LEAF_MARKERS, _o as CameraManager, xo 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, Qr as DENOISER_DEFAULTS, Kr as DENOISER_STRATEGIES, C as DOWNLOAD_POLICY, Rs as DenoisingManager, d as DownloadCache, $e as ENGINE_AREAS, we as ENGINE_DEFAULTS, P as EngineEvents, Ze as EngineIssueError, wo as GoboManager, Io as IESManager, Ee as INTERACTIVE_RENDER_CONFIG, Ye as ISSUE_CODES, Xe as ISSUE_SEVERITY, qa as InteractionManager, Je as IssueLog, Se as LEGACY_EVENT_NAMES, xa as LOCAL_EXPOSURE_DEFAULTS, Ge as LOG_LEVELS, S as LightManager, Ue as Logger, Le as MATERIAL_DEFAULTS, Ce as MATERIAL_VALUE_SOURCE, re 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, qs as OverlayManager, Te as PRODUCTION_RENDER_CONFIG, pc 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, A as RenderStage, je as SAFE_SCENE_BYTES, ec 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, j as StageExecutionMode, sn as StorageManager, Ke as TRIANGLE_DATA_LAYOUT, Co as TimelineManager, Qs as TransformManager, Re as VERSION, ot as VIEW_TRANSFORMS, _e as VRAMTracker, _c as VideoRenderManager, rn as acquireLock, Vt as addAllOcioViews, Bt as addOcioView, dt as addViewTransform, tn as applyMatrixRGBA8, $t as bakeLut, fe as bufferBytes, Pt as buildOcioView, mt as buildToneMapWGSL, _ as cachedObjectURL, Kt as canvasColorSpaceFor, hc 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, de 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, ce 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, gc as openHeadless, on as openStorage, un as openZip, St as parseSceneMetadata, Pe as probeAddressSpace, ln as readZipDirectory, ct as removeViewTransform, mc as renderHeadless, dn as renderUpscaled, Wt as resolveInputSpace, _t as sameIdentity, tt as setActiveColorManagement, m as setBindingAudit, Qt as setInputOverride, Ut as srgbToLinear, ue as sunPosition, se as textureBytes, Rt as textureInputSpace, oe as timeForSunElevation, ye as toPortable };