rayzee 11.4.0 → 11.6.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 (28) hide show
  1. package/README.md +1 -0
  2. package/dist/{ArchiveImporter-Cgyx5AF7.js → ArchiveImporter-iofnC8zB.js} +2 -2
  3. package/dist/{BidirectionalIntegrator-BKF-cwH2.js → BidirectionalIntegrator-CqAilt2I.js} +289 -289
  4. package/dist/{EngineEvents-Ci8dVWCP.js → EngineEvents-CLckhYbL.js} +1 -0
  5. package/dist/{NeuralRetouch-C3Q2XqbF.js → NeuralRetouch-DFI4pOjO.js} +2 -2
  6. package/dist/{NeuralSuperRes-DV5TtURP.js → NeuralSuperRes-ChCiiilS.js} +3 -3
  7. package/dist/{PathTracer-D3MvEaZK.js → PathTracer-BX4sJLx7.js} +3194 -3162
  8. package/dist/{PhysicalSky-CY4jiz6a.js → PhysicalSky-Biv39eTA.js} +1 -1
  9. package/dist/{RayzeeRenderer-D23m6NqG.js → RayzeeRenderer-D8XRKU3A.js} +406 -437
  10. package/dist/{ToneMapGPU-CTDBvmmS.js → ToneMapGPU-sAs8wdgI.js} +14 -1
  11. package/dist/addons/archives.es.js +1 -1
  12. package/dist/addons/bidirectional.es.js +1 -1
  13. package/dist/addons/physical-sky.es.js +1 -1
  14. package/dist/rayzee-core.es.js +5 -5
  15. package/dist/rayzee.es.js +544 -460
  16. package/dist/rayzee.umd.js +63 -55
  17. package/dist/{sceneCachePolicy-AKOEu2lf.js → sceneCachePolicy-W5PLbzuR.js} +2 -2
  18. package/package.json +2 -2
  19. package/src/EngineEvents.js +2 -0
  20. package/src/Passes/AIUpscaler.js +15 -12
  21. package/src/Passes/OIDNDenoiser.js +106 -98
  22. package/src/PathTracerApp.js +2 -2
  23. package/src/Processor/TextureReadback.js +18 -1
  24. package/src/Processor/ToneMapGPU.js +22 -3
  25. package/src/RayzeeRenderer.js +4 -4
  26. package/src/Stages/LocalExposure.js +25 -2
  27. package/src/Stages/PathTracer.js +2 -10
  28. package/src/managers/DenoisingManager.js +97 -19
package/dist/rayzee.es.js CHANGED
@@ -1,9 +1,9 @@
1
- import { t as e } from "./BidirectionalIntegrator-BKF-cwH2.js";
1
+ import { t as e } from "./BidirectionalIntegrator-CqAilt2I.js";
2
2
  import { $t as t, Ft as n, Pt as r, Yt as i, en as a, jt as o, nn as s, rt as c, wt as l } from "./SolarLimb-bZE6y63S.js";
3
- import { _ as u, a as d, c as f, d as p, f as m, g as h, h as g, i as _, l as v, m as y, n as b, o as x, p as S, r as ee, s as C, t as w, u as T } from "./RayzeeRenderer-D23m6NqG.js";
4
- import { $ as E, B as te, Et as D, H as ne, K as re, L as ie, N as ae, Ot as O, P as k, Q as oe, R as se, Tt as A, X as ce, Z as le, _t as ue, dt as de, et as fe, ft as pe, gt as me, ht as he, kt as ge, lt as _e, nt as ve, pt as ye, tt as be, ut as xe, wt as Se, z as Ce } from "./PathTracer-D3MvEaZK.js";
5
- import { n as we, t as j } from "./EngineEvents-Ci8dVWCP.js";
6
- import { D as Te, G as Ee, J as De, K as Oe, O as ke, W as Ae, Y as je, a as Me, c as Ne, et as Pe, i as Fe, m as Ie, ot as Le, p as Re, q as ze, r as Be, tt as Ve, x as He, y as Ue } from "./sceneCachePolicy-AKOEu2lf.js";
3
+ import { _ as u, a as d, c as f, d as p, f as m, g as h, h as g, i as _, l as v, m as y, n as b, o as x, p as S, r as ee, s as C, t as w, u as T } from "./RayzeeRenderer-D8XRKU3A.js";
4
+ import { $ as E, At as D, B as O, Dt as k, Et as te, F as ne, H as re, I as ie, J as A, Ot as ae, Q as oe, V as se, W as ce, _t as le, dt as ue, et as de, ft as fe, ht as pe, it as me, jt as he, mt as ge, nt as _e, pt as ve, rt as ye, tt as be, vt as xe, yt as Se, z as Ce } from "./PathTracer-BX4sJLx7.js";
5
+ import { n as we, t as j } from "./EngineEvents-CLckhYbL.js";
6
+ import { D as Te, G as Ee, J as De, K as Oe, O as ke, W as Ae, Y as je, a as Me, c as Ne, et as Pe, i as Fe, m as Ie, ot as Le, p as Re, q as ze, r as Be, tt as Ve, x as He, y as Ue } from "./sceneCachePolicy-W5PLbzuR.js";
7
7
  import { i as We, n as Ge, r as Ke, t as qe } from "./Logger-dDDGj9Av.js";
8
8
  import { f as Je, r as Ye } from "./BufferLayout-xPRH9jYD.js";
9
9
  import { i as Xe, n as Ze, r as Qe, t as $e } from "./EngineIssues-CIZnXHsF.js";
@@ -14,13 +14,13 @@ import { n as ot, t as st } from "./AssetConfig-DSEntE65.js";
14
14
  import { a as ct, d as lt, g as ut, i as dt, l as ft, o as pt, p as mt, r as ht, s as gt, t as _t, u as vt } from "./ViewTransforms-CYN7bq2w.js";
15
15
  import { a as yt, i as bt, n as xt, r as St } from "./identity-C1cLD1C0.js";
16
16
  import { a as Ct, n as wt, r as Tt, t as Et } from "./SceneMetadata-D2Sh-0e-.js";
17
- import { t as Dt } from "./ToneMapGPU-CTDBvmmS.js";
17
+ import { t as Dt } from "./ToneMapGPU-sAs8wdgI.js";
18
18
  import { t as Ot } from "./FileFormats-sPGJeCRc.js";
19
19
  import { A as kt, C as At, D as jt, E as Mt, O as Nt, S as Pt, T as Ft, _ as It, a as Lt, b as Rt, c as zt, d as Bt, f as Vt, g as Ht, h as Ut, i as Wt, k as Gt, l as Kt, m as qt, n as Jt, o as Yt, p as Xt, r as Zt, s as Qt, t as $t, u as en, v as tn, w as nn, x as rn, y as an } from "./ColorManagement-oeEk7oSu.js";
20
20
  import { c as on, l as sn, n as cn, o as ln, t as un } from "./openStorage-Fe9BoS1_.js";
21
21
  import { n as dn, t as fn } from "./ZipReader-gDSWr0I5.js";
22
- import { i as pn, n as mn, r as hn } from "./NeuralSuperRes-DV5TtURP.js";
23
- import { i as gn, n as _n, r as vn } from "./NeuralRetouch-C3Q2XqbF.js";
22
+ import { i as pn, n as mn, r as hn } from "./NeuralSuperRes-ChCiiilS.js";
23
+ import { i as gn, n as _n, r as vn } from "./NeuralRetouch-DFI4pOjO.js";
24
24
  import { ExternalTexture as yn, MeshBasicNodeMaterial as bn, QuadMesh as xn, ReadbackBuffer as Sn, RenderTarget as Cn, StorageTexture as wn, TextureNode as M, WebGPURenderer as Tn } from "three/webgpu";
25
25
  import { Fn as En, If as N, Loop as Dn, Return as On, abs as kn, atan as An, atomicAdd as jn, atomicLoad as Mn, atomicStore as Nn, attributeArray as Pn, dot as Fn, exp as In, exp2 as Ln, float as P, floatBitsToUint as Rn, floor as zn, fract as Bn, int as F, ivec2 as I, localId as L, log2 as Vn, max as R, min as Hn, mix as z, normalize as Un, pow as Wn, round as Gn, saturate as B, select as V, smoothstep as Kn, sqrt as qn, storage as Jn, textureLoad as H, textureStore as U, toneMappingExposure as Yn, uint as W, uniform as G, uvec2 as Xn, uvec4 as Zn, vec2 as K, vec3 as q, vec4 as J, wgslFn as Qn, workgroupArray as $n, workgroupBarrier as er, workgroupId as Y } from "three/tsl";
26
26
  import { ACESFilmicToneMapping as tr, AddEquation as nr, AnimationMixer as rr, Box2 as ir, Box3 as ar, ClampToEdgeWrapping as or, Color as sr, Controls as cr, CustomBlending as lr, DataArrayTexture as ur, DataTexture as dr, EventDispatcher as fr, FloatType as pr, HalfFloatType as mr, InterpolateSmooth as hr, LinearFilter as X, LoopOnce as gr, LoopRepeat as _r, MathUtils as vr, Matrix3 as yr, Matrix4 as br, Mesh as xr, MeshBasicMaterial as Sr, NearestFilter as Z, NoColorSpace as Cr, NumberKeyframeTrack as wr, OneFactor as Tr, OrthographicCamera as Er, PerspectiveCamera as Dr, PropertyBinding as Or, Quaternion as kr, RGBAFormat as Q, 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 $, Vector4 as zr, VectorKeyframeTrack as Br } from "three";
@@ -151,14 +151,14 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
151
151
  showAsvgfHeatmap: !1,
152
152
  nrdQualityPreset: "medium",
153
153
  nrdDebugMode: 0
154
- }, ti = class extends O {
154
+ }, ti = class extends D {
155
155
  constructor(e, t = {}) {
156
156
  super("NormalDepth", {
157
157
  ...t,
158
- executionMode: ge.ALWAYS
159
- }), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = G(new br(), "mat4"), this.cameraProjectionMatrixInverse = G(new br(), "mat4"), this.cameraRay = oe(), this.resolutionWidth = G(t.width || 1), this.resolutionHeight = G(t.height || 1);
158
+ executionMode: he.ALWAYS
159
+ }), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = G(new br(), "mat4"), this.cameraProjectionMatrixInverse = G(new br(), "mat4"), this.cameraRay = de(), this.resolutionWidth = G(t.width || 1), this.resolutionHeight = G(t.height || 1);
160
160
  let n = t.width || 1, r = t.height || 1;
161
- this._outputStorageTex = new wn(A, A), this._outputStorageTex.type = mr, this._outputStorageTex.format = Q, this._outputStorageTex.minFilter = Z, this._outputStorageTex.magFilter = Z, this._shadingStorageTex = new wn(A, A), this._shadingStorageTex.type = mr, this._shadingStorageTex.format = Q, this._shadingStorageTex.minFilter = Z, this._shadingStorageTex.magFilter = Z, this._shadingRT = new Cn(n, r, {
161
+ this._outputStorageTex = new wn(k, k), this._outputStorageTex.type = mr, this._outputStorageTex.format = Q, this._outputStorageTex.minFilter = Z, this._outputStorageTex.magFilter = Z, this._shadingStorageTex = new wn(k, k), this._shadingStorageTex.type = mr, this._shadingStorageTex.format = Q, this._shadingStorageTex.minFilter = Z, this._shadingStorageTex.magFilter = Z, this._shadingRT = new Cn(n, r, {
162
162
  type: mr,
163
163
  format: Q,
164
164
  minFilter: Z,
@@ -191,32 +191,32 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
191
191
  let t = e.sceneStorageNodes?.();
192
192
  t && (this._triStorageNode = t.triangles, this._bvhStorageNode = t.bvh);
193
193
  }
194
- return t && !this._matStorageNode && (this._matStorageNode = Jn(t, "vec4", t.count).toReadOnly()), this._linearBuckets && te(this._linearBuckets, e.materialData?.linearBuckets), this._lastTriAttr = e.triangleGeoAttr || this._lastTriAttr, this._lastBvhAttr = e.bvhStorageAttr || this._lastBvhAttr, this._lastMatAttr = t || this._lastMatAttr, !!(this._triStorageNode && this._bvhStorageNode && this._matStorageNode);
194
+ return t && !this._matStorageNode && (this._matStorageNode = Jn(t, "vec4", t.count).toReadOnly()), this._linearBuckets && re(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);
195
195
  }
196
196
  _buildCompute() {
197
197
  let e = this._triStorageNode, n = this._bvhStorageNode, r = this._matStorageNode;
198
- this._linearBuckets = ae(this.pathTracer?.materialData?.linearBuckets);
198
+ this._linearBuckets = ne(this.pathTracer?.materialData?.linearBuckets);
199
199
  let o = {
200
- srgbBuckets: ae(null),
200
+ srgbBuckets: ne(null),
201
201
  linearBuckets: this._linearBuckets,
202
202
  shadowAlbedoMaps: null,
203
203
  goboMaps: null,
204
204
  iesProfiles: null,
205
205
  alphaShadows: null
206
206
  }, c = this.cameraWorldMatrix, u = this.cameraProjectionMatrixInverse, d = this.resolutionWidth, f = this.resolutionHeight, p = this._outputStorageTex, m = this._shadingStorageTex, h = this._leafStorageTex;
207
- this._computeNode = he(En(([o, c]) => {
207
+ this._computeNode = le(En(([o, c]) => {
208
208
  let u = F(Y.x).mul(8).add(F(L.x)), g = F(Y.y).mul(8).add(F(L.y));
209
209
  N(u.lessThan(F(d)).and(g.lessThan(F(f))), () => {
210
- let _ = t(ce(K(P(u).add(.5).div(d), P(g).add(.5).div(f)), o, c, this.cameraRay)), v = i.wrap(re(_, n, e)), y = v.normal.mul(.5).add(.5), b = Hn(v.dst, P(65504)), x = v.didHit.select(J(y, b), J(0, 0, 0, P(Wr)));
210
+ let _ = t(oe(K(P(u).add(.5).div(d), P(g).add(.5).div(f)), o, c, this.cameraRay)), v = i.wrap(A(_, n, e)), y = v.normal.mul(.5).add(.5), b = Hn(v.dst, P(65504)), x = v.didHit.select(J(y, b), J(0, 0, 0, P(Wr)));
211
211
  U(p, Xn(W(u), W(g)), x).toWriteOnly(), h && U(h, Xn(W(u), W(g)), Zn(W(v.instanceLeaf.add(1)), 0, 0, 0)).toWriteOnly();
212
212
  let S = v.normal.toVar(), ee = P(1).toVar();
213
213
  N(v.didHit, () => {
214
- let t = a.wrap(l(v.materialIndex, r)).toVar(), i = s.wrap(k(v.uv, t)).toVar(), o = J(0).toVar();
214
+ let t = a.wrap(l(v.materialIndex, r)).toVar(), i = s.wrap(ie(v.uv, t)).toVar(), o = J(0).toVar();
215
215
  N(t.normalMapIndex.greaterThanEqual(F(0)), () => {
216
- o.assign(ne(e, v.triangleIndex, v.normal, t.normalTransform, n, v.instanceLeaf));
216
+ o.assign(ce(e, v.triangleIndex, v.normal, t.normalTransform, n, v.instanceLeaf));
217
217
  });
218
- let c = Ce(v.normal, t, i, o).toVar();
219
- S.assign(ie(c, t, i)), ee.assign(se(t, i).y.clamp(.05, 1));
218
+ let c = se(v.normal, t, i, o).toVar();
219
+ S.assign(Ce(c, t, i)), ee.assign(O(t, i).y.clamp(.05, 1));
220
220
  });
221
221
  let C = v.didHit.select(J(S.mul(.5).add(.5), ee), J(0, 0, 0, 1));
222
222
  U(m, Xn(W(u), W(g)), C).toWriteOnly();
@@ -265,7 +265,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
265
265
  reallocateReservedStorage() {
266
266
  this._computeNode?.dispose(), this._computeNode = null, this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose();
267
267
  let e = () => {
268
- let e = new wn(A, A);
268
+ let e = new wn(k, k);
269
269
  return e.type = mr, e.format = Q, e.minFilter = Z, e.magFilter = Z, e;
270
270
  };
271
271
  this._outputStorageTex = e(), this._shadingStorageTex = e(), this._leafStorageTex &&= (this._leafStorageTex.dispose(), this._makeLeafStorage()), this._computeBuilt = !1;
@@ -284,20 +284,20 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
284
284
  this._leafRT ? e.setTexture("pathtracer:instanceLeaf", this._leafRT.texture) : e.getTexture("pathtracer:instanceLeaf") && e.removeTexture("pathtracer:instanceLeaf");
285
285
  }
286
286
  _makeLeafStorage() {
287
- let e = new wn(A, A);
287
+ let e = new wn(k, k);
288
288
  return e.type = Lr, e.format = jr, e.minFilter = Z, e.magFilter = Z, e;
289
289
  }
290
290
  dispose() {
291
291
  this._computeNode?.dispose(), this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose(), this._shadingRT?.dispose(), this._leafStorageTex?.dispose(), this._leafRT?.dispose(), this._rtA?.dispose(), this._rtB?.dispose();
292
292
  }
293
- }, ni = class extends O {
293
+ }, ni = class extends D {
294
294
  constructor(e, t, n = {}) {
295
295
  super("MotionVector", {
296
296
  ...n,
297
- executionMode: ge.ALWAYS
297
+ executionMode: he.ALWAYS
298
298
  }), this.renderer = e, this.camera = t, this.pathTracer = n.pathTracer || null;
299
299
  let r = n.width || 1, i = n.height || 1;
300
- this.prevViewProjectionMatrix = new br(), this.currentViewProjectionMatrix = new br(), this.matricesInitialized = !1, this.isFirstFrame = !0, this.frameCount = 0, this.cameraWorldMatrix = G(new br(), "mat4"), this.cameraProjectionMatrixInverse = G(new br(), "mat4"), this.cameraRay = oe(), this.prevVP = G(new br(), "mat4"), this.isFirstFrameU = G(1), this.deltaTime = G(1 / 60), this.velocityScale = G(1), this.resolutionWidth = G(r), this.resolutionHeight = G(i), this._normalDepthTexNode = new M(), this._screenSpaceStorageTex = new wn(A, A), this._screenSpaceStorageTex.type = mr, this._screenSpaceStorageTex.format = Q, this._screenSpaceStorageTex.minFilter = Z, this._screenSpaceStorageTex.magFilter = Z, this._worldSpaceStorageTex = new wn(A, A), this._worldSpaceStorageTex.type = mr, this._worldSpaceStorageTex.format = Q, this._worldSpaceStorageTex.minFilter = Z, this._worldSpaceStorageTex.magFilter = Z, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0));
300
+ this.prevViewProjectionMatrix = new br(), this.currentViewProjectionMatrix = new br(), this.matricesInitialized = !1, this.isFirstFrame = !0, this.frameCount = 0, this.cameraWorldMatrix = G(new br(), "mat4"), this.cameraProjectionMatrixInverse = G(new br(), "mat4"), this.cameraRay = de(), this.prevVP = G(new br(), "mat4"), this.isFirstFrameU = G(1), this.deltaTime = G(1 / 60), this.velocityScale = G(1), this.resolutionWidth = G(r), this.resolutionHeight = G(i), this._normalDepthTexNode = new M(), this._screenSpaceStorageTex = new wn(k, k), this._screenSpaceStorageTex.type = mr, this._screenSpaceStorageTex.format = Q, this._screenSpaceStorageTex.minFilter = Z, this._screenSpaceStorageTex.magFilter = Z, this._worldSpaceStorageTex = new wn(k, k), this._worldSpaceStorageTex.type = mr, this._worldSpaceStorageTex.format = Q, this._worldSpaceStorageTex.minFilter = Z, this._worldSpaceStorageTex.magFilter = Z, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0));
301
301
  let a = {
302
302
  type: mr,
303
303
  format: Q,
@@ -315,7 +315,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
315
315
  N(s.lessThan(F(i)).and(c.lessThan(F(a))), () => {
316
316
  let l = H(e, I(s, c)).w, u = K(P(s).add(.5).div(i), P(c).add(.5).div(a)), d = J(0, 0, l, 1).toVar();
317
317
  N(l.lessThan(P(6e4)), () => {
318
- let e = le(u, l, t, n, this.cameraRay), i = r.mul(J(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));
318
+ let e = E(u, l, t, n, this.cameraRay), i = r.mul(J(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));
319
319
  d.assign(c.select(J(s, l, 1), J(P(1e3), P(1e3), l, 0)));
320
320
  }), U(o, Xn(W(s), W(c)), d).toWriteOnly();
321
321
  });
@@ -336,7 +336,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
336
336
  N(u.lessThan(F(s)).and(d.lessThan(F(c))), () => {
337
337
  let f = H(e, I(u, d)).w, p = J(0, 0, 0, 0).toVar();
338
338
  N(i.lessThan(.5).and(f.lessThan(P(6e4))), () => {
339
- let e = K(P(u).add(.5).div(s), P(d).add(.5).div(c)), i = le(e, f, t, n, this.cameraRay), l = r.mul(J(i, 1)), m = l.xy.div(l.w), h = K(m.x.mul(.5).add(.5), m.y.mul(-.5).add(.5)), g = h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)), _ = e.sub(h), v = q(_.x.div(a).mul(o), _.y.div(a).mul(o), 0);
339
+ let e = K(P(u).add(.5).div(s), P(d).add(.5).div(c)), i = E(e, f, t, n, this.cameraRay), l = r.mul(J(i, 1)), m = l.xy.div(l.w), h = K(m.x.mul(.5).add(.5), m.y.mul(-.5).add(.5)), g = h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)), _ = e.sub(h), v = q(_.x.div(a).mul(o), _.y.div(a).mul(o), 0);
340
340
  p.assign(g.select(J(v, 1), J(0, 0, 0, .5)));
341
341
  }), U(l, Xn(W(u), W(d)), p).toWriteOnly();
342
342
  });
@@ -402,7 +402,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
402
402
  reallocateReservedStorage() {
403
403
  this._screenSpaceComputeNode?.dispose(), this._worldSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this._worldSpaceStorageTex?.dispose();
404
404
  let e = () => {
405
- let e = new wn(A, A);
405
+ let e = new wn(k, k);
406
406
  return e.type = mr, e.format = Q, e.minFilter = Z, e.magFilter = Z, e;
407
407
  };
408
408
  this._screenSpaceStorageTex = e(), this._worldSpaceStorageTex = e(), this._buildScreenSpaceCompute(), this._buildWorldSpaceCompute();
@@ -410,14 +410,14 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
410
410
  dispose() {
411
411
  this._screenSpaceComputeNode?.dispose(), this._worldSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this._worldSpaceStorageTex?.dispose(), this.screenSpaceTarget?.dispose(), this.worldSpaceTarget?.dispose(), this._normalDepthTexNode?.dispose();
412
412
  }
413
- }, ri = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), ii = (e) => q(ri(e.x), ri(e.y), ri(e.z)), ai = class extends O {
413
+ }, ri = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), ii = (e) => q(ri(e.x), ri(e.y), ri(e.z)), ai = class extends D {
414
414
  constructor(e, t = {}) {
415
415
  super("ASVGF", {
416
416
  ...t,
417
- executionMode: ge.PER_CYCLE
417
+ executionMode: he.PER_CYCLE
418
418
  }), this.renderer = e, this.temporalAlpha = G(t.temporalAlpha ?? qr.medium.temporalAlpha), this.gradientStrength = G(t.gradientStrength ?? qr.medium.gradientStrength), this.gradientSigmaScale = G(t.gradientSigmaScale ?? qr.medium.gradientSigmaScale), this.gradientNoiseFloor = G(t.gradientNoiseFloor ?? qr.medium.gradientNoiseFloor), this.maxAccumFrames = G(t.maxAccumFrames ?? qr.medium.maxAccumFrames), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this.temporalEnabledU = G(1), this.forceResetU = G(0), this._colorTexNode = new M(), this._albedoTexNode = new M(), this._motionTexNode = new M(), this._normalDepthTexNode = new M(), this._prevNormalDepthTexNode = new M(), this._readTemporalTexNode = new M(), this._gradientReadTexNode = new M();
419
419
  let n = t.width || 1, r = t.height || 1;
420
- this._temporalTexA = new wn(A, A), this._temporalTexA.type = pr, this._temporalTexA.format = Q, this._temporalTexA.minFilter = X, this._temporalTexA.magFilter = X, this._temporalTexB = new wn(A, A), this._temporalTexB.type = pr, this._temporalTexB.format = Q, this._temporalTexB.minFilter = X, this._temporalTexB.magFilter = X, this._outputModulatedTex = new wn(A, A), this._outputModulatedTex.type = pr, this._outputModulatedTex.format = Q, this._outputModulatedTex.minFilter = X, this._outputModulatedTex.magFilter = X, this._gradientStorageTex = new wn(A, A), this._gradientStorageTex.type = mr, this._gradientStorageTex.format = Q, this._gradientStorageTex.minFilter = X, this._gradientStorageTex.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._demodulatedRT = new Cn(n, r, {
420
+ this._temporalTexA = new wn(k, k), this._temporalTexA.type = pr, this._temporalTexA.format = Q, this._temporalTexA.minFilter = X, this._temporalTexA.magFilter = X, this._temporalTexB = new wn(k, k), this._temporalTexB.type = pr, this._temporalTexB.format = Q, this._temporalTexB.minFilter = X, this._temporalTexB.magFilter = X, this._outputModulatedTex = new wn(k, k), this._outputModulatedTex.type = pr, this._outputModulatedTex.format = Q, this._outputModulatedTex.minFilter = X, this._outputModulatedTex.magFilter = X, this._gradientStorageTex = new wn(k, k), this._gradientStorageTex.type = mr, this._gradientStorageTex.format = Q, this._gradientStorageTex.minFilter = X, this._gradientStorageTex.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._demodulatedRT = new Cn(n, r, {
421
421
  type: pr,
422
422
  format: Q,
423
423
  minFilter: X,
@@ -438,7 +438,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
438
438
  magFilter: X,
439
439
  depthBuffer: !1,
440
440
  stencilBuffer: !1
441
- }), this.currentMoments = 0, this._compiled = !1, this._needsWarmReset = !1, this._dispatchX = Math.ceil(n / 8), this._dispatchY = Math.ceil(r / 8), this._buildGradientCompute(), this._buildTemporalCompute(), this.showHeatmap = !1, this.debugMode = G(0, "int"), this._heatmapStorageTex = new wn(A, A), this._heatmapStorageTex.type = pr, this._heatmapStorageTex.format = Q, this._heatmapStorageTex.minFilter = Z, this._heatmapStorageTex.magFilter = Z, this.heatmapTarget = new Cn(n, r, {
441
+ }), this.currentMoments = 0, this._compiled = !1, this._needsWarmReset = !1, this._dispatchX = Math.ceil(n / 8), this._dispatchY = Math.ceil(r / 8), this._buildGradientCompute(), this._buildTemporalCompute(), this.showHeatmap = !1, this.debugMode = G(0, "int"), this._heatmapStorageTex = new wn(k, k), this._heatmapStorageTex.type = pr, this._heatmapStorageTex.format = Q, this._heatmapStorageTex.minFilter = Z, this._heatmapStorageTex.magFilter = Z, this.heatmapTarget = new Cn(n, r, {
442
442
  type: pr,
443
443
  format: Q,
444
444
  minFilter: Z,
@@ -502,12 +502,12 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
502
502
  N(f.greaterThan(.5).and(p.lessThan(.5)), () => {
503
503
  let e = H(r, v), t = e.w.greaterThan(.5), n = P(g).sub(e.x.mul(m)), c = P(_).sub(e.y.mul(h)), f = n.greaterThanEqual(0).and(n.lessThan(P(m))).and(c.greaterThanEqual(0)).and(c.lessThan(P(h)));
504
504
  N(t.and(f), () => {
505
- let e = H(i, v), t = e.xyz.mul(2).sub(1), r = e.w, f = F(n), p = F(c), g = f.add(F(1)), _ = p.add(F(1)), y = n.sub(P(f)), b = c.sub(P(p)), S = f.clamp(F(0), F(m).sub(1)), E = g.clamp(F(0), F(m).sub(1)), te = p.clamp(F(0), F(h).sub(1)), D = _.clamp(F(0), F(h).sub(1)), ne = P(1).sub(y).mul(P(1).sub(b)), re = y.mul(P(1).sub(b)), ie = P(1).sub(y).mul(b), ae = y.mul(b), O = (e, n, i) => {
505
+ let e = H(i, v), t = e.xyz.mul(2).sub(1), r = e.w, f = F(n), p = F(c), g = f.add(F(1)), _ = p.add(F(1)), y = n.sub(P(f)), b = c.sub(P(p)), S = f.clamp(F(0), F(m).sub(1)), E = g.clamp(F(0), F(m).sub(1)), D = p.clamp(F(0), F(h).sub(1)), O = _.clamp(F(0), F(h).sub(1)), k = P(1).sub(y).mul(P(1).sub(b)), te = y.mul(P(1).sub(b)), ne = P(1).sub(y).mul(b), re = y.mul(b), ie = (e, n, i) => {
506
506
  let o = H(a, I(e, n)), s = o.xyz.mul(2).sub(1), c = o.w, l = Wn(Fn(t, s).clamp(0, 1), P(16)), u = In(kn(r.sub(c)).div(R(r, P(.001))).div(P(.05)).negate());
507
507
  return i.mul(l).mul(u);
508
- }, k = O(S, te, ne), oe = O(E, te, re), se = O(S, D, ie), A = O(E, D, ae), ce = k.add(oe).add(se).add(A);
508
+ }, A = ie(S, D, k), ae = ie(E, D, te), oe = ie(S, O, ne), se = ie(E, O, re), ce = A.add(ae).add(oe).add(se);
509
509
  N(ce.greaterThan(P(.01)), () => {
510
- let e = H(o, I(S, te)), t = H(o, I(E, te)), n = H(o, I(S, D)), r = H(o, I(E, D)), i = P(1).div(ce), a = e.xyz.mul(k).add(t.xyz.mul(oe)).add(n.xyz.mul(se)).add(r.xyz.mul(A)).mul(i), c = e.w.mul(k).add(t.w.mul(oe)).add(n.w.mul(se)).add(r.w.mul(A)).mul(i), f = H(s, v).x.mul(d).clamp(0, 1), p = ii(z(a, C, z(R(P(1).div(c.add(1)), u), P(1), f))), m = Hn(c.add(1), l);
510
+ let e = H(o, I(S, D)), t = H(o, I(E, D)), n = H(o, I(S, O)), r = H(o, I(E, O)), i = P(1).div(ce), a = e.xyz.mul(A).add(t.xyz.mul(ae)).add(n.xyz.mul(oe)).add(r.xyz.mul(se)).mul(i), c = e.w.mul(A).add(t.w.mul(ae)).add(n.w.mul(oe)).add(r.w.mul(se)).mul(i), f = H(s, v).x.mul(d).clamp(0, 1), p = ii(z(a, C, z(R(P(1).div(c.add(1)), u), P(1), f))), m = Hn(c.add(1), l);
511
511
  w.assign(J(p, m)), T.assign(J(p.mul(ee), x));
512
512
  });
513
513
  });
@@ -594,7 +594,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
594
594
  reallocateReservedStorage() {
595
595
  this._gradientNode?.dispose(), this._temporalNodeA?.dispose(), this._temporalNodeB?.dispose(), this._heatmapComputeNode?.dispose(), this._temporalTexA?.dispose(), this._temporalTexB?.dispose(), this._outputModulatedTex?.dispose(), this._gradientStorageTex?.dispose(), this._heatmapStorageTex?.dispose();
596
596
  let e = (e, t) => {
597
- let n = new wn(A, A);
597
+ let n = new wn(k, k);
598
598
  return n.type = e, n.format = Q, n.minFilter = t, n.magFilter = t, n;
599
599
  };
600
600
  this._temporalTexA = e(pr, X), this._temporalTexB = e(pr, X), this._outputModulatedTex = e(pr, X), this._gradientStorageTex = e(mr, X), this._heatmapStorageTex = e(pr, Z), this._buildGradientCompute(), this._buildTemporalCompute(), this._buildHeatmapCompute(), this._compiled = !1, this.currentMoments = 0, this._needsWarmReset = !0;
@@ -705,17 +705,17 @@ function Hi(e) {
705
705
  let t = Math.imul(e | 0, 2654435761) >>> 0;
706
706
  return t ^= t >>> 15, t = Math.imul(t, 2246822507) >>> 0, t ^= t >>> 13, t = Math.imul(t, 3266489909) >>> 0, t ^= t >>> 16, t / 4294967296;
707
707
  }
708
- var Ui = class extends O {
708
+ var Ui = class extends D {
709
709
  constructor(e, t = {}) {
710
710
  super("NRD", {
711
711
  ...t,
712
- executionMode: ge.PER_CYCLE
712
+ executionMode: he.PER_CYCLE
713
713
  }), this.renderer = e, this.pathTracer = t.pathTracer || null, this.settings = {
714
714
  ...Xr,
715
715
  ...t.settings || {}
716
716
  }, this._releaseHitDistance = this.pathTracer?.requestOutput?.("hitDistance", { encode: (e, t) => e.div(R(t.mul(.1).add(3), P(1e-4))).clamp(0, 1) }) ?? null;
717
717
  let n = t.width || 1, r = t.height || 1;
718
- 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 zr(1, 0, 0, 1), "vec4"), this.rotBlur = G(new zr(1, 0, 0, 1), "vec4"), this.rotPost = G(new zr(1, 0, 0, 1), "vec4"), this.camWorld = G(new br(), "mat4"), this.camProjInv = G(new br(), "mat4"), this.camView = G(new br(), "mat4"), this.prevCamView = G(new br(), "mat4"), this.camPos = G(new $(), "vec3"), this.prevCamPos = G(new $(), "vec3"), this.viewVector = G(new $(), "vec3"), this.prevViewVector = G(new $(), "vec3"), this.cameraRay = oe(), this.u = {};
718
+ 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 zr(1, 0, 0, 1), "vec4"), this.rotBlur = G(new zr(1, 0, 0, 1), "vec4"), this.rotPost = G(new zr(1, 0, 0, 1), "vec4"), this.camWorld = G(new br(), "mat4"), this.camProjInv = G(new br(), "mat4"), this.camView = G(new br(), "mat4"), this.prevCamView = G(new br(), "mat4"), this.camPos = G(new $(), "vec3"), this.prevCamPos = G(new $(), "vec3"), this.viewVector = G(new $(), "vec3"), this.prevViewVector = G(new $(), "vec3"), this.cameraRay = de(), this.u = {};
719
719
  for (let e of [
720
720
  "maxAccum",
721
721
  "maxFast",
@@ -753,7 +753,7 @@ var Ui = class extends O {
753
753
  }), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n / yi), this._dispatchY = Math.ceil(r / yi), this._buildKernels();
754
754
  }
755
755
  _allocStorage() {
756
- let e = () => D(mr);
756
+ let e = () => ae(mr);
757
757
  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();
758
758
  }
759
759
  _disposeStorage() {
@@ -785,13 +785,13 @@ var Ui = class extends O {
785
785
  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;
786
786
  }
787
787
  _worldPosAt(e, t, n, r) {
788
- return le(e, t, n, r, this.cameraRay);
788
+ return E(e, t, n, r, this.cameraRay);
789
789
  }
790
790
  _viewVector(e, t, n) {
791
- return V(E(this.cameraRay.cameraProjection), n, Un(t.sub(e)));
791
+ return V(be(this.cameraRay.cameraProjection), n, Un(t.sub(e)));
792
792
  }
793
793
  _frustumSize(e) {
794
- return this.minRectDimMulUnproject.mul(V(E(this.cameraRay.cameraProjection), P(1), e));
794
+ return this.minRectDimMulUnproject.mul(V(be(this.cameraRay.cameraProjection), P(1), e));
795
795
  }
796
796
  _pixelUv(e, t) {
797
797
  return K(P(e).add(.5).div(this.resW), P(t).add(.5).div(this.resH));
@@ -891,27 +891,27 @@ var Ui = class extends O {
891
891
  } : (e) => H(p, e), C = En(([n, r]) => {
892
892
  let s = F(Y.x).mul(yi).add(F(L.x)), c = F(Y.y).mul(yi).add(F(L.y));
893
893
  N(s.lessThan(F(b)).and(c.lessThan(F(x))), () => {
894
- let l = I(s, c), p = Xn(W(s), W(c)), C = H(u, l).w.toVar(), w = C.greaterThanEqual(Gr), T = H(d, l).toVar(), E = Un(T.xyz.mul(2).sub(1)).toVar(), te = T.w.clamp(.05, 1).toVar(), D = P(Gr).toVar(), ne = ee(l).toVar();
894
+ let l = I(s, c), p = Xn(W(s), W(c)), C = H(u, l).w.toVar(), w = C.greaterThanEqual(Gr), T = H(d, l).toVar(), E = Un(T.xyz.mul(2).sub(1)).toVar(), D = T.w.clamp(.05, 1).toVar(), O = P(Gr).toVar(), k = ee(l).toVar();
895
895
  N(w.not(), () => {
896
896
  let e = this._pixelUv(s, c), p = this._worldPosAt(e, C, n, r).toVar();
897
- D.assign(v.mul(J(p, 1)).z.abs()), N(_.greaterThan(0), () => {
898
- let s = Fn(E, this._viewVector(p, y, this.viewVector)).abs().toVar(), c = this._frustumSize(D).toVar(), m = S.add(1), h = t ? R(S, P(10)) : H(f, l).y.add(S), C = (t ? P(1).div(h.add(1)) : this._advancedNonLinear(h)).toVar(), w = Ei(te, .5).toVar(), T = D.mul(Yr).add(3), re = ne.w.toVar(), ie = B(re.mul(T).div(c)), ae = P(1).sub(this._handover(m)), O = (t ? ie.div(m) : ie.mul(C)).mul(ae), k = o.minBlurRadius.mul(B(P(2).sub(h.div(R(o.maxAccum, 1))))), oe = R(B(qn(B(O)).mul(i)).mul(_).mul(w), k.mul(w)).toVar(), se = Mi(o.planeDistSensitivity, c, p, E).toVar(), A = Oi(C, o.lobeAngleFraction, te, o.lobeVolumePercent).div(a).toVar(), ce = ki(te, o.roughnessFraction.mul(a)).toVar(), le = ji(re, C).toVar(), ue = o.minHitDistanceWeight.mul(a).mul(w);
897
+ O.assign(v.mul(J(p, 1)).z.abs()), N(_.greaterThan(0), () => {
898
+ let s = Fn(E, this._viewVector(p, y, this.viewVector)).abs().toVar(), c = this._frustumSize(O).toVar(), m = S.add(1), h = t ? R(S, P(10)) : H(f, l).y.add(S), C = (t ? P(1).div(h.add(1)) : this._advancedNonLinear(h)).toVar(), w = Ei(D, .5).toVar(), T = O.mul(Yr).add(3), te = k.w.toVar(), ne = B(te.mul(T).div(c)), re = P(1).sub(this._handover(m)), ie = (t ? ne.div(m) : ne.mul(C)).mul(re), A = o.minBlurRadius.mul(B(P(2).sub(h.div(R(o.maxAccum, 1))))), ae = R(B(qn(B(ie)).mul(i)).mul(_).mul(w), A.mul(w)).toVar(), oe = Mi(o.planeDistSensitivity, c, p, E).toVar(), se = Oi(C, o.lobeAngleFraction, D, o.lobeVolumePercent).div(a).toVar(), ce = ki(D, o.roughnessFraction.mul(a)).toVar(), le = ji(te, C).toVar(), ue = o.minHitDistanceWeight.mul(a).mul(w);
899
899
  t || (ue = ue.mul(C)), ue = ue.toVar();
900
900
  let de = K(1);
901
901
  if (!t) {
902
902
  let e = v.mul(J(E, 0)).xy;
903
903
  de = z(K(1).sub(e.abs()), K(1), s), de = de.div(R(de.x, de.y));
904
904
  }
905
- let fe = de.mul(K(P(1).div(b), P(1).div(x))).mul(oe).toVar(), pe = P(1).toVar();
905
+ let fe = de.mul(K(P(1).div(b), P(1).div(x))).mul(ae).toVar(), pe = P(1).toVar();
906
906
  for (let t = 0; t < Si.length; t++) {
907
907
  let i = Si[t], a = e.add(Bi(g, K(i[0], i[1])).mul(fe)), o = Ni(a), s = V(o.x.notEqual(a.x).or(o.y.notEqual(a.y)), P(1), P(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 = Ti(Fn(E, Un(p.xyz.mul(2).sub(1))));
908
- s.mulAssign(Ci(m, A, P(0))), s.mulAssign(Ci(p.w, ce.x, ce.y)), s.mulAssign(Ci(Fn(E, f), se.x, se.y)), s.assign(V(l.greaterThanEqual(Gr), P(0), s));
908
+ s.mulAssign(Ci(m, se, P(0))), s.mulAssign(Ci(p.w, ce.x, ce.y)), s.mulAssign(Ci(Fn(E, f), oe.x, oe.y)), s.assign(V(l.greaterThanEqual(Gr), P(0), s));
909
909
  let h = Vi(s, ee(c));
910
- s.mulAssign(ue.add(wi(h.w, le.x, le.y))), pe.addAssign(s), ne.addAssign(h.mul(s));
910
+ s.mulAssign(ue.add(wi(h.w, le.x, le.y))), pe.addAssign(s), k.addAssign(h.mul(s));
911
911
  }
912
- ne.divAssign(R(pe, 1e-6)), t || ne.assign(J(ne.xyz, re));
912
+ k.divAssign(R(pe, 1e-6)), t || k.assign(J(k.xyz, te));
913
913
  });
914
- }), U(m, p, ne).toWriteOnly(), e === "post" && U(h, p, J(E, D)).toWriteOnly();
914
+ }), U(m, p, k).toWriteOnly(), e === "post" && U(h, p, J(E, O)).toWriteOnly();
915
915
  });
916
916
  });
917
917
  return this._dispatchOf(C);
@@ -924,23 +924,23 @@ var Ui = class extends O {
924
924
  N(ee.greaterThanEqual(Gr), () => {
925
925
  U(l, g, C).toWriteOnly(), U(u, g, J(0)).toWriteOnly(), On();
926
926
  });
927
- let w = e.maxAccum.mul(P(1).sub(v)).toVar(), T = e.maxFast.mul(P(1).sub(v)).toVar(), E = H(n, h), te = Un(E.xyz.mul(2).sub(1)).toVar(), D = E.w.clamp(.05, 1).toVar(), ne = this._pixelUv(x, S), re = this._worldPosAt(ne, ee, y, b).toVar(), ie = d.mul(J(re, 1)).z.abs().toVar(), ae = Fn(te, this._viewVector(re, p, this.viewVector)).abs().toVar(), O = this._frustumSize(ie).toVar(), k = q(0).toVar();
928
- k.addAssign(te.mul(.25));
927
+ let w = e.maxAccum.mul(P(1).sub(v)).toVar(), T = e.maxFast.mul(P(1).sub(v)).toVar(), E = H(n, h), D = Un(E.xyz.mul(2).sub(1)).toVar(), O = E.w.clamp(.05, 1).toVar(), k = this._pixelUv(x, S), te = this._worldPosAt(k, ee, y, b).toVar(), ne = d.mul(J(te, 1)).z.abs().toVar(), re = Fn(D, this._viewVector(te, p, this.viewVector)).abs().toVar(), ie = this._frustumSize(ne).toVar(), A = q(0).toVar();
928
+ A.addAssign(D.mul(.25));
929
929
  for (let e = -1; e <= 0; e++) for (let r = -1; r <= 0; r++) {
930
930
  if (r === 0 && e === 0) continue;
931
931
  let i = this._clampCoord(x.add(r), S.add(e)), a = Un(H(n, i).xyz.mul(2).sub(1)), o = H(t, i).w.lessThan(Gr);
932
- k.addAssign(V(o, a, te).mul(.25));
932
+ A.addAssign(V(o, a, D).mul(.25));
933
933
  }
934
- let oe = H(r, h), se = ne.sub(oe.xy).toVar(), A = f.mul(J(re, 1)).z.abs().toVar(), ce = this._bilinear(se), le = O.mul(B(e.disocclusionThreshold.div(R(ae, .05)))).sub(oi).toVar(), ue = P(1).sub(v), de = [], fe = [];
934
+ let ae = H(r, h), oe = k.sub(ae.xy).toVar(), se = f.mul(J(te, 1)).z.abs().toVar(), ce = this._bilinear(oe), le = ie.mul(B(e.disocclusionThreshold.div(R(re, .05)))).sub(oi).toVar(), ue = P(1).sub(v), de = [], fe = [];
935
935
  for (let e = 0; e < 4; e++) {
936
- let t = H(c, ce.taps[e]), n = V(Fn(t.xyz, k).greaterThan(_i), P(1), P(0)), r = V(t.w.sub(A).abs().lessThanEqual(le), P(1), P(0)), i = V(t.w.lessThan(Gr), P(1), P(0));
936
+ let t = H(c, ce.taps[e]), n = V(Fn(t.xyz, A).greaterThan(_i), P(1), P(0)), r = V(t.w.sub(se).abs().lessThanEqual(le), P(1), P(0)), i = V(t.w.lessThan(Gr), P(1), P(0));
937
937
  de.push(n.mul(r).mul(i).mul(ce.inScreen[e]).mul(ue).toVar()), fe.push(H(s, ce.taps[e]).x);
938
938
  }
939
- let pe = ce.customWeights(de).map((e) => e.toVar()), me = de[0].add(de[1]).add(de[2]).add(de[3]).greaterThan(3.5).toVar(), he = de[0].add(de[1].mul(2)).add(de[2].mul(4)).add(de[3].mul(8)), ge = this._applyCustomWeights(fe, pe, P(0)).toVar(), _e = Fn(te, this._viewVector(re, m, this.prevViewVector)).abs().add(.001).div(ae.add(.001)).toVar();
939
+ let pe = ce.customWeights(de).map((e) => e.toVar()), me = de[0].add(de[1]).add(de[2]).add(de[3]).greaterThan(3.5).toVar(), he = de[0].add(de[1].mul(2)).add(de[2].mul(4)).add(de[3].mul(8)), ge = this._applyCustomWeights(fe, pe, P(0)).toVar(), _e = Fn(D, this._viewVector(te, m, this.prevViewVector)).abs().add(.001).div(re.add(.001)).toVar();
940
940
  _e.assign(z(P(.1), P(1), B(_e.mul(_e))));
941
941
  let ve = qn(B(ce.filter(de))).mul(_e).toVar();
942
942
  ge.assign(ge.mul(z(ve, P(1), P(1).div(ge.add(1))))), ge.assign(Hn(ge, w));
943
- let ye = Ri(this._sampleHistory((e) => H(a, e), se, ce, pe, me)).toVar(), be = R(this._applyCustomWeights(ce.taps.map((e) => H(o, e).x), pe, P(0)), 0).toVar(), xe = _.add(1), Se = this._handover(xe).toVar(), Ce = ge.mul(P(1).sub(Se)), we = xe.div(xe.add(Ce)).toVar(), j = P(1).div(P(1).add(Ei(D, .25).mul(.5).mul(w))), Te = J(z(ye.xyz, C.xyz, we), z(ye.w, C.w, R(we, j))).toVar(), Ee = e.fireflyMinRelativeScale.add(P(mi).div(ge.add(1))).toVar(), De = ge.mul(e.maxBlurRadius).mul(hi).toVar();
943
+ let ye = Ri(this._sampleHistory((e) => H(a, e), oe, ce, pe, me)).toVar(), be = R(this._applyCustomWeights(ce.taps.map((e) => H(o, e).x), pe, P(0)), 0).toVar(), xe = _.add(1), Se = this._handover(xe).toVar(), Ce = ge.mul(P(1).sub(Se)), we = xe.div(xe.add(Ce)).toVar(), j = P(1).div(P(1).add(Ei(O, .25).mul(.5).mul(w))), Te = J(z(ye.xyz, C.xyz, we), z(ye.w, C.w, R(we, j))).toVar(), Ee = e.fireflyMinRelativeScale.add(P(mi).div(ge.add(1))).toVar(), De = ge.mul(e.maxBlurRadius).mul(hi).toVar();
944
944
  De.assign(De.div(De.add(1)).mul(P(1).sub(Se)));
945
945
  let Oe = z(Te.x, Hn(Te.x, ye.x.mul(Ee)), De);
946
946
  Te.assign(Li(Te, Oe));
@@ -961,37 +961,37 @@ var Ui = class extends O {
961
961
  let e = H(r, h);
962
962
  U(a, g, e).toWriteOnly(), U(o, g, J(e.x, 0, 0, 0)).toWriteOnly(), On();
963
963
  });
964
- 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), ee = Un(S.xyz.mul(2).sub(1)).toVar(), C = S.w.clamp(.05, 1).toVar(), w = this._pixelUv(p, m), T = this._worldPosAt(w, _, d, f).toVar(), E = s.mul(J(T, 1)).z.abs(), te = this._frustumSize(E).toVar(), D = H(r, h).toVar(), ne = P(1).div(b.add(1)).toVar(), re = E.mul(Yr).add(3), ie = B(D.w.mul(re).div(te)), ae = D.w.toVar(), O = Gn(V(b.lessThan(e.historyFixFrameNum), P(1), P(0)).mul(.5).mul(2 / ui).mul(e.historyFixStride).mul(z(P(.25).add(qn(ie).mul(.75)), P(1), ne))).toVar();
965
- N(O.notEqual(0), () => {
966
- let a = Oi(ne, e.lobeAngleFraction, C, e.lobeVolumePercent).toVar(), o = Mi(e.planeDistSensitivity, te, T, ee).toVar(), s = ji(ae, ne).toVar(), u = Ai(C.mul(C), qn(e.roughnessFraction), ci).toVar(), p = P(1).add(y).toVar();
967
- D.mulAssign(p);
964
+ 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), ee = Un(S.xyz.mul(2).sub(1)).toVar(), C = S.w.clamp(.05, 1).toVar(), w = this._pixelUv(p, m), T = this._worldPosAt(w, _, d, f).toVar(), E = s.mul(J(T, 1)).z.abs(), D = this._frustumSize(E).toVar(), O = H(r, h).toVar(), k = P(1).div(b.add(1)).toVar(), te = E.mul(Yr).add(3), ne = B(O.w.mul(te).div(D)), re = O.w.toVar(), ie = Gn(V(b.lessThan(e.historyFixFrameNum), P(1), P(0)).mul(.5).mul(2 / ui).mul(e.historyFixStride).mul(z(P(.25).add(qn(ne).mul(.75)), P(1), k))).toVar();
965
+ N(ie.notEqual(0), () => {
966
+ let a = Oi(k, e.lobeAngleFraction, C, e.lobeVolumePercent).toVar(), o = Mi(e.planeDistSensitivity, D, T, ee).toVar(), s = ji(re, k).toVar(), u = Ai(C.mul(C), qn(e.roughnessFraction), ci).toVar(), p = P(1).add(y).toVar();
967
+ O.mulAssign(p);
968
968
  for (let e = -ui; e <= ui; e++) for (let m = -ui; m <= ui; m++) {
969
969
  if (m === 0 && e === 0 || Math.abs(m) + Math.abs(e) === ui * 2) continue;
970
- let h = Ni(w.add(K(m, e).mul(O).mul(K(P(1).div(c), P(1).div(l))))), g = this._uvToCoord(h), _ = H(t, g).w, v = this._worldPosAt(h, _, d, f), y = H(n, g), b = wi(Ti(Fn(Un(y.xyz.mul(2).sub(1)), ee)), a, P(0)).toVar();
970
+ let h = Ni(w.add(K(m, e).mul(ie).mul(K(P(1).div(c), P(1).div(l))))), g = this._uvToCoord(h), _ = H(t, g).w, v = this._worldPosAt(h, _, d, f), y = H(n, g), b = wi(Ti(Fn(Un(y.xyz.mul(2).sub(1)), ee)), a, P(0)).toVar();
971
971
  b.mulAssign(wi(y.w.mul(y.w), u.x, u.y)), b.mulAssign(P(1).add(H(i, g).y)), b.mulAssign(Ci(Fn(ee, v), o.x, o.y)), b.assign(V(_.greaterThanEqual(Gr), P(0), b));
972
972
  let x = Vi(b, H(r, g));
973
- b.mulAssign(wi(x.w, s.x, s.y)), p.addAssign(b), D.addAssign(x.mul(b));
973
+ b.mulAssign(wi(x.w, s.x, s.y)), p.addAssign(b), O.addAssign(x.mul(b));
974
974
  }
975
- D.divAssign(R(p, 1e-6));
975
+ O.divAssign(R(p, 1e-6));
976
976
  });
977
- let k = D.x.toVar(), oe = B(y.div(R(e.historyFixFrameNum, oi))), se = z(k, v.x, oe).toVar();
978
- U(o, g, J(se, 0, 0, 0)).toWriteOnly();
979
- let A = se.toVar(), ce = se.mul(se).toVar(), le = P(0).toVar(), ue = P(0).toVar(), de = (e, n, r) => {
980
- let a = this._clampCoord(p.add(e), m.add(n)), o = H(t, a).w, s = V(o.greaterThanEqual(Gr), se, H(i, a).x);
981
- Math.abs(e) <= di && Math.abs(n) <= di && (A.addAssign(s), ce.addAssign(s.mul(s))), r && (le.addAssign(s), ue.addAssign(s.mul(s)));
977
+ let A = O.x.toVar(), ae = B(y.div(R(e.historyFixFrameNum, oi))), oe = z(A, v.x, ae).toVar();
978
+ U(o, g, J(oe, 0, 0, 0)).toWriteOnly();
979
+ let se = oe.toVar(), ce = oe.mul(oe).toVar(), le = P(0).toVar(), ue = P(0).toVar(), de = (e, n, r) => {
980
+ let a = this._clampCoord(p.add(e), m.add(n)), o = H(t, a).w, s = V(o.greaterThanEqual(Gr), oe, H(i, a).x);
981
+ Math.abs(e) <= di && Math.abs(n) <= di && (se.addAssign(s), ce.addAssign(s.mul(s))), r && (le.addAssign(s), ue.addAssign(s.mul(s)));
982
982
  }, fe = e.antiFirefly.greaterThan(.5);
983
983
  for (let e = -di; e <= di; e++) for (let t = -di; t <= di; t++) t === 0 && e === 0 || de(t, e, Math.abs(t) > 1 || Math.abs(e) > 1);
984
984
  N(fe, () => {
985
985
  for (let e = -fi; e <= fi; e++) for (let t = -fi; t <= fi; t++) Math.abs(t) <= di && Math.abs(e) <= di || de(t, e, !0);
986
986
  }), N(fe, () => {
987
987
  let e = 1 / ((fi * 2 + 1) ** 2 - 9), t = le.mul(e), n = zi(t, ue.mul(e)).mul(pi);
988
- k.assign(z(k.clamp(t.sub(n), t.add(n)), k, x));
988
+ A.assign(z(A.clamp(t.sub(n), t.add(n)), A, x));
989
989
  });
990
990
  {
991
- let t = 1 / (di * 2 + 1) ** 2, n = A.mul(t), r = zi(n, ce.mul(t)).mul(e.fastClampSigmaScale), i = k.clamp(n.sub(r), n.add(r)), a = V(e.maxFast.lessThan(e.maxAccum), P(1), P(0)), o = z(P(1).div(P(1).add(a.mul(y).mul(2))), P(1), x);
992
- k.assign(z(i, k, o));
991
+ let t = 1 / (di * 2 + 1) ** 2, n = se.mul(t), r = zi(n, ce.mul(t)).mul(e.fastClampSigmaScale), i = A.clamp(n.sub(r), n.add(r)), a = V(e.maxFast.lessThan(e.maxAccum), P(1), P(0)), o = z(P(1).div(P(1).add(a.mul(y).mul(2))), P(1), x);
992
+ A.assign(z(i, A, o));
993
993
  }
994
- U(a, g, Li(D, k)).toWriteOnly();
994
+ U(a, g, Li(O, A)).toWriteOnly();
995
995
  });
996
996
  });
997
997
  return this._dispatchOf(d);
@@ -1005,34 +1005,34 @@ var Ui = class extends O {
1005
1005
  N(y.greaterThanEqual(Gr), () => {
1006
1006
  U(d, p, b).toWriteOnly(), U(e, p, J(H(s, f).x, 0, 0, 0)).toWriteOnly(), U(u, p, J(0, 1, 0, 0)).toWriteOnly(), On();
1007
1007
  });
1008
- let x = H(a, f).w.clamp(.05, 1), S = this._pixelUv(_, v), ee = H(o, f), C = S.sub(ee.xy).toVar(), w = H(c, f).toVar(), T = w.y.toVar(), E = W(w.z.add(.5)).toVar(), te = w.w.greaterThan(.5), D = this._bilinear(C), ne = [
1008
+ let x = H(a, f).w.clamp(.05, 1), S = this._pixelUv(_, v), ee = H(o, f), C = S.sub(ee.xy).toVar(), w = H(c, f).toVar(), T = w.y.toVar(), E = W(w.z.add(.5)).toVar(), D = w.w.greaterThan(.5), O = this._bilinear(C), k = [
1009
1009
  1,
1010
1010
  2,
1011
1011
  4,
1012
1012
  8
1013
- ].map((e) => V(E.bitAnd(W(e)).notEqual(W(0)), P(1), P(0))), re = D.customWeights(ne).map((e) => e.toVar()), ie = qn(B(D.filter(ne))).toVar(), ae = H(s, f).toVar(), O = ae.x.toVar(), k = O.toVar(), oe = O.mul(O).toVar();
1013
+ ].map((e) => V(E.bitAnd(W(e)).notEqual(W(0)), P(1), P(0))), te = O.customWeights(k).map((e) => e.toVar()), ne = qn(B(O.filter(k))).toVar(), re = H(s, f).toVar(), ie = re.x.toVar(), A = ie.toVar(), ae = ie.mul(ie).toVar();
1014
1014
  for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
1015
1015
  if (t === 0 && e === 0) continue;
1016
- let n = this._clampCoord(_.add(t), v.add(e)), r = H(i, n).w, a = V(r.greaterThanEqual(Gr), O, H(s, n).x);
1017
- k.addAssign(a), oe.addAssign(a.mul(a));
1016
+ let n = this._clampCoord(_.add(t), v.add(e)), r = H(i, n).w, a = V(r.greaterThanEqual(Gr), ie, H(s, n).x);
1017
+ A.addAssign(a), ae.addAssign(a.mul(a));
1018
1018
  }
1019
- k.divAssign(9), oe.divAssign(9);
1020
- let se = zi(k, oe).toVar();
1019
+ A.divAssign(9), ae.divAssign(9);
1020
+ let oe = zi(A, ae).toVar();
1021
1021
  N(T.lessThan(t.historyFixFrameNum), () => {
1022
- O.assign(Hn(O, k.mul(P(1.2).add(P(1).div(T.add(1))))));
1022
+ ie.assign(Hn(ie, A.mul(P(1.2).add(P(1).div(T.add(1))))));
1023
1023
  });
1024
- let A = R(this._sampleHistory((e) => H(l, e), C, D, re, te).x, 0).toVar(), ce = se.mul(t.antilag.x), le = t.antilag.y.mul(4), ue = A.clamp(k.sub(ce), k.add(ce)), de = A.sub(ue).abs().div(R(A, ue).add(oi)), fe = P(1).div(P(1).add(de.mul(T.mul(ie)).div(le))).toVar(), pe = Hn(T, t.historyFixFrameNum);
1024
+ let se = R(this._sampleHistory((e) => H(l, e), C, O, te, D).x, 0).toVar(), ce = oe.mul(t.antilag.x), le = t.antilag.y.mul(4), ue = se.clamp(A.sub(ce), A.add(ce)), de = se.sub(ue).abs().div(R(se, ue).add(oi)), fe = P(1).div(P(1).add(de.mul(T.mul(ne)).div(le))).toVar(), pe = Hn(T, t.historyFixFrameNum);
1025
1025
  T.assign(z(pe, T, fe));
1026
- let me = m.add(1), he = this._handover(me), ge = ie.mul(P(1).sub(this._advancedNonLinear(T.mul(P(1).sub(he)).div(me)))).mul(fe).toVar(), _e = P(1).add(ge.mul(6)), ve = t.stabilizationStrength.mul(P(1).sub(h)), ye = z(O, A.clamp(k.sub(se.mul(_e)), k.add(se.mul(_e))), Hn(ge, ve)).toVar();
1027
- ae.assign(Li(ae, ye)), U(e, p, J(ye, 0, 0, 0)).toWriteOnly();
1026
+ let me = m.add(1), he = this._handover(me), ge = ne.mul(P(1).sub(this._advancedNonLinear(T.mul(P(1).sub(he)).div(me)))).mul(fe).toVar(), _e = P(1).add(ge.mul(6)), ve = t.stabilizationStrength.mul(P(1).sub(h)), ye = z(ie, se.clamp(A.sub(oe.mul(_e)), A.add(oe.mul(_e))), Hn(ge, ve)).toVar();
1027
+ re.assign(Li(re, ye)), U(e, p, J(ye, 0, 0, 0)).toWriteOnly();
1028
1028
  let be = t.maxAccum.mul(P(1).sub(h));
1029
1029
  U(u, p, J(Hn(T.add(1), be), x, 0, 0)).toWriteOnly();
1030
- let xe = H(r, f), Se = J(Fi(ae.xyz).mul(R(xe.xyz, q(Kr))), b.w).toVar();
1030
+ let xe = H(r, f), Se = J(Fi(re.xyz).mul(R(xe.xyz, q(Kr))), b.w).toVar();
1031
1031
  N(g.equal(F(1)), () => {
1032
1032
  let e = B(T.div(R(t.maxAccum, 1)));
1033
1033
  Se.assign(J(P(1).sub(e), e, .2, 1));
1034
1034
  }).ElseIf(g.equal(F(2)), () => {
1035
- Se.assign(J(q(ae.w), 1));
1035
+ Se.assign(J(q(re.w), 1));
1036
1036
  }).ElseIf(g.equal(F(3)), () => {
1037
1037
  Se.assign(J(q(x), 1));
1038
1038
  }).ElseIf(g.equal(F(4)), () => {
@@ -1124,14 +1124,14 @@ var Ui = class extends O {
1124
1124
  for (let [e, t] of this._placeholders) e.dispose(), t.dispose();
1125
1125
  this._placeholders.clear();
1126
1126
  }
1127
- }, Wi = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), Gi = /* @__PURE__ */ Qn("\n fn temporalAccumulate(\n lum: f32,\n prevMean: f32,\n prevMeanSq: f32,\n alpha: f32,\n spatialVariance: f32,\n varianceBoost: f32\n ) -> vec4f {\n\n let newMean = prevMean + ( lum - prevMean ) * alpha;\n let newMeanSq = prevMeanSq + ( lum * lum - prevMeanSq ) * alpha;\n let temporalVariance = max( newMeanSq - newMean * newMean, 0.0 );\n\n return vec4f(\n newMean,\n newMeanSq,\n temporalVariance * varianceBoost,\n spatialVariance * varianceBoost\n );\n\n }\n"), Ki = class extends O {
1127
+ }, Wi = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), Gi = /* @__PURE__ */ Qn("\n fn temporalAccumulate(\n lum: f32,\n prevMean: f32,\n prevMeanSq: f32,\n alpha: f32,\n spatialVariance: f32,\n varianceBoost: f32\n ) -> vec4f {\n\n let newMean = prevMean + ( lum - prevMean ) * alpha;\n let newMeanSq = prevMeanSq + ( lum * lum - prevMeanSq ) * alpha;\n let temporalVariance = max( newMeanSq - newMean * newMean, 0.0 );\n\n return vec4f(\n newMean,\n newMeanSq,\n temporalVariance * varianceBoost,\n spatialVariance * varianceBoost\n );\n\n }\n"), Ki = class extends D {
1128
1128
  constructor(e, t = {}) {
1129
1129
  super("VarianceEstimation", {
1130
1130
  ...t,
1131
- executionMode: ge.ALWAYS
1131
+ executionMode: he.ALWAYS
1132
1132
  }), this.renderer = e, this.inputTextureName = t.inputTextureName || "pathtracer:color", this.varianceBoost = G(t.varianceBoost ?? 1), this.temporalAlpha = G(t.temporalAlpha ?? .1), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this._colorTexNode = new M();
1133
1133
  let n = t.width || 1, r = t.height || 1;
1134
- this._storageTexA = new wn(A, A), this._storageTexA.type = pr, this._storageTexA.format = Q, this._storageTexA.minFilter = X, this._storageTexA.magFilter = X, this._storageTexB = new wn(A, A), this._storageTexB.type = pr, this._storageTexB.format = Q, this._storageTexB.minFilter = X, this._storageTexB.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._outputTarget = new Cn(n, r, {
1134
+ this._storageTexA = new wn(k, k), this._storageTexA.type = pr, this._storageTexA.format = Q, this._storageTexA.minFilter = X, this._storageTexA.magFilter = X, this._storageTexB = new wn(k, k), this._storageTexB.type = pr, this._storageTexB.format = Q, this._storageTexB.minFilter = X, this._storageTexB.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._outputTarget = new Cn(n, r, {
1135
1135
  type: pr,
1136
1136
  format: Q,
1137
1137
  minFilter: X,
@@ -1209,7 +1209,7 @@ var Ui = class extends O {
1209
1209
  reallocateReservedStorage() {
1210
1210
  this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose();
1211
1211
  let e = () => {
1212
- let e = new wn(A, A);
1212
+ let e = new wn(k, k);
1213
1213
  return e.type = pr, e.format = Q, e.minFilter = X, e.magFilter = X, e;
1214
1214
  };
1215
1215
  this._storageTexA = e(), this._storageTexB = e(), this._buildCompute(), this._compiled = !1;
@@ -1217,14 +1217,14 @@ var Ui = class extends O {
1217
1217
  dispose() {
1218
1218
  this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose(), this._outputTarget?.dispose(), this._colorTexNode?.dispose(), this._readTexNodeA?.dispose(), this._readTexNodeB?.dispose();
1219
1219
  }
1220
- }, qi = /* @__PURE__ */ Qn("\n fn bilateralWeight(\n centerLum: f32, sLum: f32,\n centerNormal: vec3f, sNormal: vec3f,\n centerDepth: f32, sDepth: f32,\n centerColor: vec3f, sColor: vec3f,\n kernelW: f32,\n sigmaL: f32, phiNorm: f32, phiDep: f32, phiCol: f32\n ) -> f32 {\n\n let lumW = exp( -abs( centerLum - sLum ) / sigmaL );\n // clamp dot to [0,1]: miss-ray normals decode to (-1,-1,-1) with\n // dot=3 → pow saturates to +inf → inf*0 = NaN. See project_tsl_pitfalls.\n // max(phiNorm, 1e-6): pow(0.0, 0.0) is undefined in WGSL and returned NaN on ~12%\n // of pixels when phiNormal was set to 0.\n let normW = pow( clamp( dot( centerNormal, sNormal ), 0.0, 1.0 ), max( phiNorm, 1e-6 ) );\n let depW = exp( -abs( centerDepth - sDepth ) / max( centerDepth * phiDep, 0.001 ) );\n let maxDiff = max( max( abs( centerColor.x - sColor.x ),\n abs( centerColor.y - sColor.y ) ),\n abs( centerColor.z - sColor.z ) );\n let avgLum = max( ( centerLum + sLum ) * 0.5, 0.0001 );\n let colW = exp( -( maxDiff / avgLum ) / max( phiCol, 0.0001 ) );\n return kernelW * lumW * normW * depW * colW;\n\n }\n"), Ji = class extends O {
1220
+ }, qi = /* @__PURE__ */ Qn("\n fn bilateralWeight(\n centerLum: f32, sLum: f32,\n centerNormal: vec3f, sNormal: vec3f,\n centerDepth: f32, sDepth: f32,\n centerColor: vec3f, sColor: vec3f,\n kernelW: f32,\n sigmaL: f32, phiNorm: f32, phiDep: f32, phiCol: f32\n ) -> f32 {\n\n let lumW = exp( -abs( centerLum - sLum ) / sigmaL );\n // clamp dot to [0,1]: miss-ray normals decode to (-1,-1,-1) with\n // dot=3 → pow saturates to +inf → inf*0 = NaN. See project_tsl_pitfalls.\n // max(phiNorm, 1e-6): pow(0.0, 0.0) is undefined in WGSL and returned NaN on ~12%\n // of pixels when phiNormal was set to 0.\n let normW = pow( clamp( dot( centerNormal, sNormal ), 0.0, 1.0 ), max( phiNorm, 1e-6 ) );\n let depW = exp( -abs( centerDepth - sDepth ) / max( centerDepth * phiDep, 0.001 ) );\n let maxDiff = max( max( abs( centerColor.x - sColor.x ),\n abs( centerColor.y - sColor.y ) ),\n abs( centerColor.z - sColor.z ) );\n let avgLum = max( ( centerLum + sLum ) * 0.5, 0.0001 );\n let colW = exp( -( maxDiff / avgLum ) / max( phiCol, 0.0001 ) );\n return kernelW * lumW * normW * depW * colW;\n\n }\n"), Ji = class extends D {
1221
1221
  constructor(e, t = {}) {
1222
1222
  super("BilateralFiltering", {
1223
1223
  ...t,
1224
- executionMode: ge.ALWAYS
1224
+ executionMode: he.ALWAYS
1225
1225
  }), this.renderer = e, this.inputTextureName = t.inputTextureName || "asvgf:demodulated", this.normalDepthTextureName = t.normalDepthTextureName || "pathtracer:normalDepth", this.shadingNormalTextureName = t.shadingNormalTextureName || "pathtracer:shadingNormal", this.albedoTextureName = t.albedoTextureName || "pathtracer:albedo", this.varianceTextureName = t.varianceTextureName || "variance:output", this.iterations = t.iterations ?? 4, this.phiColor = G(t.phiColor ?? .5), this.phiNormal = G(t.phiNormal ?? 128), this.phiDepth = G(t.phiDepth ?? .05), this.phiLuminance = G(t.phiLuminance ?? 4), this.spatialVarianceWeight = G(t.spatialVarianceWeight ?? 1), this.stepSizeU = G(1, "int"), this.isLastIterationU = G(0, "int"), this.isFirstIterationU = G(1, "int"), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this._readTexNode = new M(), this._normalDepthTexNode = new M(), this._shadingNormalTexNode = new M(), this._albedoTexNode = new M(), this._varianceTexNode = new M(), this._srcAlphaTexNode = new M();
1226
1226
  let n = t.width || 1, r = t.height || 1;
1227
- this._storageTexA = new wn(A, A), this._storageTexA.type = mr, this._storageTexA.format = Q, this._storageTexA.minFilter = X, this._storageTexA.magFilter = X, this._storageTexB = new wn(A, A), this._storageTexB.type = mr, this._storageTexB.format = Q, this._storageTexB.minFilter = X, this._storageTexB.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._outputTarget = new Cn(n, r, {
1227
+ this._storageTexA = new wn(k, k), this._storageTexA.type = mr, this._storageTexA.format = Q, this._storageTexA.minFilter = X, this._storageTexA.magFilter = X, this._storageTexB = new wn(k, k), this._storageTexB.type = mr, this._storageTexB.format = Q, this._storageTexB.minFilter = X, this._storageTexB.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._outputTarget = new Cn(n, r, {
1228
1228
  type: mr,
1229
1229
  format: Q,
1230
1230
  minFilter: X,
@@ -1267,15 +1267,15 @@ var Ui = class extends O {
1267
1267
  return En(() => {
1268
1268
  let y = F(Y.x).mul(8).add(F(L.x)), b = F(Y.y).mul(8).add(F(L.y));
1269
1269
  N(y.lessThan(F(g)).and(b.lessThan(F(_))), () => {
1270
- let x = I(y, b), S = H(t, x), ee = S.xyz, C = H(n, x), w = H(r, x).xyz.mul(2).sub(1), T = C.w, E = o(ee), te = R(H(i, x).xyz, q(Kr)), D = R(o(te), P(Kr)).toVar(), ne = h.equal(F(1)), re = (e) => {
1270
+ let x = I(y, b), S = H(t, x), ee = S.xyz, C = H(n, x), w = H(r, x).xyz.mul(2).sub(1), T = C.w, E = o(ee), D = R(H(i, x).xyz, q(Kr)), O = R(o(D), P(Kr)).toVar(), k = h.equal(F(1)), te = (e) => {
1271
1271
  let t = H(a, e);
1272
1272
  return z(t.z, R(t.z, t.w), f);
1273
- }, ie = ne.select(re(x), S.w.mul(S.w)).toVar(), ae = d.mul(qn(R(ie, P(0)))).div(D).add(P(1e-4)), O = q(0).toVar(), k = P(0).toVar(), oe = P(0).toVar();
1273
+ }, ne = k.select(te(x), S.w.mul(S.w)).toVar(), re = d.mul(qn(R(ne, P(0)))).div(O).add(P(1e-4)), ie = q(0).toVar(), A = P(0).toVar(), ae = P(0).toVar();
1274
1274
  for (let e = 0; e < 5; e++) for (let i = 0; i < 5; i++) {
1275
- let a = i - 2, s = e - 2, d = v[e * 5 + i], f = y.add(p.mul(a)).clamp(F(0), F(g).sub(1)), m = b.add(p.mul(s)).clamp(F(0), F(_).sub(1)), h = H(t, I(f, m)), x = h.xyz, S = H(n, I(f, m)), C = H(r, I(f, m)).xyz.mul(2).sub(1), te = S.w, D = qi(E, o(x), w, C, T, te, ee, x, P(d), ae, l, u, c), ie = ne.select(re(I(f, m)), h.w.mul(h.w));
1276
- O.addAssign(x.mul(D)), k.addAssign(D), oe.addAssign(D.mul(D).mul(R(ie, P(0))));
1275
+ let a = i - 2, s = e - 2, d = v[e * 5 + i], f = y.add(p.mul(a)).clamp(F(0), F(g).sub(1)), m = b.add(p.mul(s)).clamp(F(0), F(_).sub(1)), h = H(t, I(f, m)), x = h.xyz, S = H(n, I(f, m)), C = H(r, I(f, m)).xyz.mul(2).sub(1), D = S.w, O = qi(E, o(x), w, C, T, D, ee, x, P(d), re, l, u, c), ne = k.select(te(I(f, m)), h.w.mul(h.w));
1276
+ ie.addAssign(x.mul(O)), A.addAssign(O), ae.addAssign(O.mul(O).mul(R(ne, P(0))));
1277
1277
  }
1278
- let se = O.div(R(k, P(1e-4))), A = oe.div(R(k.mul(k), P(1e-8))), ce = m.equal(F(1)), le = ce.select(se.mul(te), se), ue = ce.select(H(s, x).w, qn(R(A, P(0))));
1278
+ let oe = ie.div(R(A, P(1e-4))), se = ae.div(R(A.mul(A), P(1e-8))), ce = m.equal(F(1)), le = ce.select(oe.mul(D), oe), ue = ce.select(H(s, x).w, qn(R(se, P(0))));
1279
1279
  U(e, Xn(W(y), W(b)), J(le, ue)).toWriteOnly();
1280
1280
  });
1281
1281
  })().compute([
@@ -1323,7 +1323,7 @@ var Ui = class extends O {
1323
1323
  reallocateReservedStorage() {
1324
1324
  this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose();
1325
1325
  let e = () => {
1326
- let e = new wn(A, A);
1326
+ let e = new wn(k, k);
1327
1327
  return e.type = mr, e.format = Q, e.minFilter = X, e.magFilter = X, e;
1328
1328
  };
1329
1329
  this._storageTexA = e(), this._storageTexB = e(), this._buildCompute(), this._compiled = !1;
@@ -1357,11 +1357,11 @@ var Ui = class extends O {
1357
1357
  6 / 256,
1358
1358
  4 / 256,
1359
1359
  1 / 256
1360
- ], ea = class extends O {
1360
+ ], ea = class extends D {
1361
1361
  constructor(e, t = {}) {
1362
1362
  super("EdgeAwareFiltering", {
1363
1363
  ...t,
1364
- executionMode: ge.PER_CYCLE
1364
+ executionMode: he.PER_CYCLE
1365
1365
  }), this.renderer = e, this.filterStrength = G(t.filterStrength ?? 1), this.phiLuminance = G(t.phiLuminance ?? 1), this.phiNormal = G(t.phiNormal ?? 64), this.phiDepth = G(t.phiDepth ?? .1), this.iterations = t.atrousIterations ?? t.edgeAtrousIterations ?? 5, this.stepSizeU = G(1, "int"), this.isLastIterationU = G(0, "int"), this.isFirstIterationU = G(1, "int"), this.varianceHistoryU = G(0, "int"), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this._colorTexNode = new M(), this._ndTexNode = new M(), this._snTexNode = new M(), this._albedoTexNode = new M(), this._varTexNode = new M(), this._readTexNode = new M();
1366
1366
  let n = t.width || 1, r = t.height || 1;
1367
1367
  this._demodTex = this._makeStorageTex(), this._storageTexA = this._makeStorageTex(), this._storageTexB = this._makeStorageTex(), this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this.outputTarget = new Cn(n, r, {
@@ -1374,7 +1374,7 @@ var Ui = class extends O {
1374
1374
  }), this._compiled = !1, this._dispatchX = Math.ceil(n / 16), this._dispatchY = Math.ceil(r / 16), this._buildCompute();
1375
1375
  }
1376
1376
  _makeStorageTex() {
1377
- let e = new wn(A, A);
1377
+ let e = new wn(k, k);
1378
1378
  return e.type = pr, e.format = Q, e.minFilter = X, e.magFilter = X, e;
1379
1379
  }
1380
1380
  _buildCompute() {
@@ -1403,15 +1403,15 @@ var Ui = class extends O {
1403
1403
  return En(() => {
1404
1404
  let v = F(Y.x).mul(16).add(F(L.x)), y = F(Y.y).mul(16).add(F(L.y));
1405
1405
  N(v.lessThan(F(g)).and(y.lessThan(F(_))), () => {
1406
- let b = I(v, y), x = H(t, b), S = x.xyz, ee = o(S), C = H(r, b).w, w = H(i, b).xyz.mul(2).sub(1), T = C.lessThan(P(Yi)), E = V(T, P(1), P(0)), te = H(a, b).xyz, D = V(T, R(te, q(Kr)), q(1)), ne = R(o(D), P(Kr)), re = m.equal(F(1)), ie = h.lessThan(F(Qi)), ae = (e) => {
1406
+ let b = I(v, y), x = H(t, b), S = x.xyz, ee = o(S), C = H(r, b).w, w = H(i, b).xyz.mul(2).sub(1), T = C.lessThan(P(Yi)), E = V(T, P(1), P(0)), D = H(a, b).xyz, O = V(T, R(D, q(Kr)), q(1)), k = R(o(O), P(Kr)), te = m.equal(F(1)), ne = h.lessThan(F(Qi)), re = (e) => {
1407
1407
  let t = H(s, e);
1408
- return V(ie, R(t.z, t.w), t.z);
1409
- }, O = re.select(ae(b), x.w.mul(x.w)).toVar(), k = l.mul(qn(R(O, P(0)))).div(ne).add(P(1e-4)), oe = q(0).toVar(), se = P(0).toVar(), A = P(0).toVar();
1408
+ return V(ne, R(t.z, t.w), t.z);
1409
+ }, ie = te.select(re(b), x.w.mul(x.w)).toVar(), A = l.mul(qn(R(ie, P(0)))).div(k).add(P(1e-4)), ae = q(0).toVar(), oe = P(0).toVar(), se = P(0).toVar();
1410
1410
  for (let e = 0; e < 5; e++) for (let n = 0; n < 5; n++) {
1411
- let a = n - 2, s = e - 2, c = $i[e * 5 + n], l = I(v.add(f.mul(a)).clamp(F(0), F(g).sub(1)), y.add(f.mul(s)).clamp(F(0), F(_).sub(1))), p = H(t, l), m = p.xyz, h = o(m), b = H(r, l).w, x = H(i, l).xyz.mul(2).sub(1), S = V(b.lessThan(P(Yi)), P(1), P(0)), T = ee.sub(h).abs().div(k).negate().exp(), te = Wn(Fn(w, x).clamp(0, 1), u), D = C.sub(b).abs().div(R(C.mul(d), P(.001))).negate().exp(), ne = E.mul(S), ie = E.oneMinus().mul(S.oneMinus()), O = ne.add(ie), ce = z(P(1), te.mul(D), ne), le = P(c).mul(T).mul(ce).mul(O), ue = re.select(ae(l), p.w.mul(p.w));
1412
- oe.addAssign(m.mul(le)), se.addAssign(le), A.addAssign(le.mul(le).mul(R(ue, P(0))));
1411
+ let a = n - 2, s = e - 2, c = $i[e * 5 + n], l = I(v.add(f.mul(a)).clamp(F(0), F(g).sub(1)), y.add(f.mul(s)).clamp(F(0), F(_).sub(1))), p = H(t, l), m = p.xyz, h = o(m), b = H(r, l).w, x = H(i, l).xyz.mul(2).sub(1), S = V(b.lessThan(P(Yi)), P(1), P(0)), T = ee.sub(h).abs().div(A).negate().exp(), D = Wn(Fn(w, x).clamp(0, 1), u), O = C.sub(b).abs().div(R(C.mul(d), P(.001))).negate().exp(), k = E.mul(S), ne = E.oneMinus().mul(S.oneMinus()), ie = k.add(ne), ce = z(P(1), D.mul(O), k), le = P(c).mul(T).mul(ce).mul(ie), ue = te.select(re(l), p.w.mul(p.w));
1412
+ ae.addAssign(m.mul(le)), oe.addAssign(le), se.addAssign(le.mul(le).mul(R(ue, P(0))));
1413
1413
  }
1414
- let ce = oe.div(R(se, P(1e-4))), le = A.div(R(se.mul(se), P(1e-8))), ue = p.equal(F(1)), de = H(n, b).xyz, fe = z(de, ce.mul(D), c), pe = ue.select(fe, ce), me = ue.select(H(n, b).w, qn(R(le, P(0))));
1414
+ let ce = ae.div(R(oe, P(1e-4))), le = se.div(R(oe.mul(oe), P(1e-8))), ue = p.equal(F(1)), de = H(n, b).xyz, fe = z(de, ce.mul(O), c), pe = ue.select(fe, ce), me = ue.select(H(n, b).w, qn(R(le, P(0))));
1415
1415
  U(e, Xn(W(v), W(y)), J(pe, me)).toWriteOnly();
1416
1416
  });
1417
1417
  })().compute([
@@ -1505,11 +1505,11 @@ function wa(e, t) {
1505
1505
  let n = new yr().set(...e).invert().elements;
1506
1506
  return t.set(xa[0] * n[0] + xa[1] * n[1] + xa[2] * n[2], xa[0] * n[3] + xa[1] * n[4] + xa[2] * n[5], xa[0] * n[6] + xa[1] * n[7] + xa[2] * n[8]);
1507
1507
  }
1508
- var Ta = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ea = class extends O {
1508
+ var Ta = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ea = class extends D {
1509
1509
  constructor(e, t = {}) {
1510
1510
  super("AutoExposure", {
1511
1511
  ...t,
1512
- executionMode: ge.ALWAYS
1512
+ executionMode: he.ALWAYS
1513
1513
  }), this.renderer = e, this.metering = t.metering ?? ta.autoExposureMetering, this.meteringPoint = new Rr(.5, .5), this.keyValue = t.keyValue ?? ta.autoExposureKeyValue, this.minExposure = t.minExposure ?? ta.autoExposureMinExposure, this.maxExposure = t.maxExposure ?? ta.autoExposureMaxExposure, this.adaptSpeedBright = t.adaptSpeedBright ?? ta.autoExposureAdaptSpeedBright, this.adaptSpeedDark = t.adaptSpeedDark ?? ta.autoExposureAdaptSpeedDark, this.centerWeight = t.centerWeight ?? 8, this.strength = t.strength ?? ta.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 Rr()), this._pointU = G(new Rr(.5, .5)), this._lumWeightsU = G(new $().fromArray(xa)), this._widthU = G(1, "int"), this._heightU = G(1, "int"), this._strideU = G(1, "int"), this._gridXU = G(ra, "int"), this._gridYU = G(ra, "int"), this._inputNode = new M(), this._workingMatrix = void 0, this._histogram = Pn(oa, "uint").toAtomic(), this._result = Pn(1, "vec4"), this._readback = new Sn(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 = {
1514
1514
  restarts: -1,
1515
1515
  samples: -1
@@ -1739,19 +1739,19 @@ var Ta = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ea = class extends O {
1739
1739
  localExposureHighlightContrast: .6,
1740
1740
  localExposureShadowContrast: 1,
1741
1741
  localExposureDetailStrength: 1
1742
- }, Oa = 128, ka = (Oa / 2) ** 2, Aa = 32, ja = -16, Ma = 16, Na = -40, Pa = 40, Fa = 256, Ia = 32, La = .6, Ra = 50, za = Math.log2(.18), Ba = 2 ** -24, Va = Math.ceil(Se / Oa), Ha = Math.ceil(Se / Ia), Ua = [
1742
+ }, Oa = 128, ka = (Oa / 2) ** 2, Aa = 32, ja = -16, Ma = 16, Na = -40, Pa = 40, Fa = 256, Ia = 32, La = .6, Ra = 50, za = Math.log2(.18), Ba = 2 ** -24, Va = Math.ceil(te / Oa), Ha = Math.ceil(te / Ia), Ua = [
1743
1743
  .2126,
1744
1744
  .7152,
1745
1745
  .0722
1746
1746
  ], Wa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ga = (e, t, n) => Math.min(Math.max(e, t), n);
1747
1747
  function Ka(e, t, n, r, i, a, o) {
1748
- let s = Math.min(Math.log2(Math.max(a, Ba)), Pa), c = e[6], l = e[7], u = Ga(r * e[2] - .5, 0, c - 1), d = Ga(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 = Ga(r * e[0] - .5, 0, b - 1), ee = Ga(i * e[1] - .5, 0, x - 1), C = Ga((s + e[8] - ja) / (Ma - ja), 0, 1) * (Aa - 1), w = Math.floor(S), T = Math.floor(ee), E = Math.floor(C), te = S - w, D = ee - T, ne = C - E, re = 0, ie = 0;
1748
+ let s = Math.min(Math.log2(Math.max(a, Ba)), Pa), c = e[6], l = e[7], u = Ga(r * e[2] - .5, 0, c - 1), d = Ga(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 = Ga(r * e[0] - .5, 0, b - 1), ee = Ga(i * e[1] - .5, 0, x - 1), C = Ga((s + e[8] - ja) / (Ma - ja), 0, 1) * (Aa - 1), w = Math.floor(S), T = Math.floor(ee), E = Math.floor(C), D = S - w, O = ee - T, k = C - E, te = 0, ne = 0;
1749
1749
  for (let e = 0; e < 8; e++) {
1750
- let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? te : 1 - te) * (r ? D : 1 - D) * (i ? ne : 1 - ne), o = ((Math.min(T + r, x - 1) * b + Math.min(w + n, b - 1)) * Aa + Math.min(E + i, Aa - 1)) * 2;
1751
- re += t[o] * a, ie += t[o + 1] * a;
1750
+ let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? D : 1 - D) * (r ? O : 1 - O) * (i ? k : 1 - k), o = ((Math.min(T + r, x - 1) * b + Math.min(w + n, b - 1)) * Aa + Math.min(E + i, Aa - 1)) * 2;
1751
+ te += t[o] * a, ne += t[o + 1] * a;
1752
1752
  }
1753
- let ae = ie * ka < .001 ? y : re / ie, O = ae + (y - ae) * e[12] + o, k = s + o, oe = O > e[13] ? e[9] : e[10];
1754
- return 2 ** (e[13] + (O - e[13]) * oe + (k - O) * e[11] - k);
1753
+ let re = ne * ka < .001 ? y : te / ne, ie = re + (y - re) * e[12] + o, A = s + o, ae = ie > e[13] ? e[9] : e[10];
1754
+ return 2 ** (e[13] + (ie - e[13]) * ae + (A - ie) * e[11] - A);
1755
1755
  }
1756
1756
  var qa = `
1757
1757
  @group(1) @binding(0) var<storage, read> leGrid: array<vec2<f32>>;
@@ -1790,11 +1790,11 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1790
1790
  let contrast = select( le[ 2 ].z, le[ 2 ].y, base > le[ 3 ].y );
1791
1791
  return exp2( le[ 3 ].y + ( base - le[ 3 ].y ) * contrast + ( y - base ) * le[ 2 ].w - y );
1792
1792
  }
1793
- `, Ja = class extends O {
1793
+ `, Ja = class extends D {
1794
1794
  constructor(e, t = {}) {
1795
1795
  super("LocalExposure", {
1796
1796
  ...t,
1797
- executionMode: ge.ALWAYS
1797
+ executionMode: he.ALWAYS
1798
1798
  }), this.renderer = e, this.highlightContrast = t.highlightContrast ?? Da.localExposureHighlightContrast, this.shadowContrast = t.shadowContrast ?? Da.localExposureShadowContrast, this.detailStrength = t.detailStrength ?? Da.localExposureDetailStrength, this.onChange = null, this._grid = Pn(Va * Va * Aa, "vec2"), this._blur = Pn(Ha * Ha, "float"), this._blurTmp = Pn(Ha * Ha, "float"), this._inputNode = new M(), 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 = [
1799
1799
  new zr(),
1800
1800
  new zr(),
@@ -1999,8 +1999,8 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
1999
1999
  let t = e & 1, r = e >> 1 & 1, i = e >> 2, a = (t ? ee : ee.oneMinus()).mul(r ? C : C.oneMinus()).mul(i ? w : w.oneMinus()), o = b.add(F(t)).min(_.x.sub(F(1))), s = x.add(F(r)).min(_.y.sub(F(1))), c = S.add(F(i)).min(F(Aa - 1));
2000
2000
  T.addAssign(n.element(W(s.mul(_.x).add(o).mul(F(Aa)).add(c))).mul(a));
2001
2001
  }
2002
- let E = z(V(T.y.mul(ka).lessThan(.001), g, T.x.div(T.y)), g, s.x).add(l).toVar(), te = c.add(l), D = V(E.greaterThan(s.y), o.y, o.z);
2003
- return Ln(s.y.add(E.sub(s.y).mul(D)).add(te.sub(E).mul(o.w)).sub(te));
2002
+ let E = z(V(T.y.mul(ka).lessThan(.001), g, T.x.div(T.y)), g, s.x).add(l).toVar(), D = c.add(l), O = V(E.greaterThan(s.y), o.y, o.z);
2003
+ return Ln(s.y.add(E.sub(s.y).mul(O)).add(D.sub(E).mul(o.w)).sub(D));
2004
2004
  })(e, t);
2005
2005
  }
2006
2006
  toneGain() {
@@ -2012,10 +2012,11 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
2012
2012
  size: 64,
2013
2013
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
2014
2014
  }), e.device.queue.writeBuffer(this._paramsBuffer, 0, this._params);
2015
- let r = this._params.slice();
2015
+ let r = this._params.slice(), i = () => Promise.all([this.renderer.getArrayBufferAsync(this._grid.value), this.renderer.getArrayBufferAsync(this._blur.value)]);
2016
2016
  return {
2017
2017
  key: "local-exposure",
2018
2018
  wgsl: qa,
2019
+ device: e.device,
2019
2020
  entries: [
2020
2021
  {
2021
2022
  binding: 0,
@@ -2031,8 +2032,32 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
2031
2032
  }
2032
2033
  ],
2033
2034
  cpu: async () => {
2034
- let [e, t] = await Promise.all([this.renderer.getArrayBufferAsync(this._grid.value), this.renderer.getArrayBufferAsync(this._blur.value)]), n = new Float32Array(e), i = new Float32Array(t);
2035
- return (e, t, a, o) => Ka(r, n, i, e, t, a, o);
2035
+ let [e, t] = await i(), n = new Float32Array(e), a = new Float32Array(t);
2036
+ return (e, t, i, o) => Ka(r, n, a, e, t, i, o);
2037
+ },
2038
+ copyTo: async (e) => {
2039
+ let [t, n] = await i(), a = [
2040
+ [t, GPUBufferUsage.STORAGE],
2041
+ [n, GPUBufferUsage.STORAGE],
2042
+ [r, GPUBufferUsage.UNIFORM]
2043
+ ].map(([t, n]) => {
2044
+ let r = e.createBuffer({
2045
+ label: "local-exposure-copy",
2046
+ size: t.byteLength,
2047
+ usage: n | GPUBufferUsage.COPY_DST
2048
+ });
2049
+ return e.queue.writeBuffer(r, 0, t), r;
2050
+ });
2051
+ return {
2052
+ key: "local-exposure",
2053
+ wgsl: qa,
2054
+ device: e,
2055
+ entries: a.map((e, t) => ({
2056
+ binding: t,
2057
+ resource: { buffer: e }
2058
+ })),
2059
+ destroy: () => a.forEach((e) => e.destroy())
2060
+ };
2036
2061
  }
2037
2062
  };
2038
2063
  }
@@ -2632,7 +2657,7 @@ var $a = class extends fr {
2632
2657
  let n = {
2633
2658
  index: t,
2634
2659
  name: e.name ?? "",
2635
- effects: ue(e.userData?.__rayzeeEffects) ?? null
2660
+ effects: Se(e.userData?.__rayzeeEffects) ?? null
2636
2661
  };
2637
2662
  return t === 0 || !e.userData?.__rayzeeUserCamera ? n : {
2638
2663
  ...n,
@@ -2665,7 +2690,7 @@ var $a = class extends fr {
2665
2690
  for (let r of e.cameras ?? []) {
2666
2691
  if (r.user) {
2667
2692
  let e = r.orthographic ? new Er(...r.frustum, r.near, r.far) : new Dr(r.fov, r.aspect, r.near, r.far);
2668
- 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 = me(r.effects), r.orbitTarget && (e.userData.__rayzeeOrbitTarget = new $().fromArray(r.orbitTarget)), n.set(r.index, this.cameras.length), this.cameras.push(e);
2693
+ 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 = xe(r.effects), r.orbitTarget && (e.userData.__rayzeeOrbitTarget = new $().fromArray(r.orbitTarget)), n.set(r.index, this.cameras.length), this.cameras.push(e);
2669
2694
  continue;
2670
2695
  }
2671
2696
  let e = this.cameras[r.index];
@@ -2673,7 +2698,7 @@ var $a = class extends fr {
2673
2698
  t.push(r.name);
2674
2699
  continue;
2675
2700
  }
2676
- n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = me(r.effects));
2701
+ n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = xe(r.effects));
2677
2702
  }
2678
2703
  this._userCameraCounter = this.cameras.filter((e) => e.userData?.__rayzeeUserCamera).length, this.currentCameraIndex = n.get(e.current) ?? 0;
2679
2704
  let r = e.defaultView;
@@ -3270,11 +3295,19 @@ function Uo(e) {
3270
3295
  }
3271
3296
  //#endregion
3272
3297
  //#region src/Passes/OIDNDenoiser.js
3273
- var Wo = Ke("oidn"), Go = 16, Ko = null;
3274
- async function qo() {
3275
- return Ko ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Ko;
3298
+ var Wo = Ke("oidn"), Go = 16, Ko = 16;
3299
+ function qo(e, t) {
3300
+ let n = (e) => Math.ceil((e + 2 * Ko) / Go) * Go;
3301
+ return {
3302
+ width: n(e),
3303
+ height: n(t)
3304
+ };
3305
+ }
3306
+ var Jo = null;
3307
+ async function Yo() {
3308
+ return Jo ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Jo;
3276
3309
  }
3277
- var Jo = {
3310
+ var Xo = {
3278
3311
  QUALITY_MODELS: {
3279
3312
  fast: {
3280
3313
  model: "rt_hdr_alb_nrm_small",
@@ -3298,9 +3331,9 @@ var Jo = {
3298
3331
  oidnQuality: "fast",
3299
3332
  tileSize: 1024
3300
3333
  }
3301
- }, Yo = .18, Xo = 256, Zo = 256, Qo = `
3302
- const WG: u32 = ${Xo}u;
3303
- const GROUPS: u32 = ${Zo}u;
3334
+ }, Zo = .18, Qo = 256, $o = 256, es = `
3335
+ const WG: u32 = ${Qo}u;
3336
+ const GROUPS: u32 = ${$o}u;
3304
3337
 
3305
3338
  @group(0) @binding(0) var<storage, read> col: array<vec4<f32>>;
3306
3339
  @group(0) @binding(1) var<storage, read_write> partials: array<f32>;
@@ -3319,17 +3352,18 @@ fn treeSum( lid: u32 ) {
3319
3352
  }
3320
3353
  }
3321
3354
 
3322
- @compute @workgroup_size(${Xo})
3355
+ @compute @workgroup_size(${Qo})
3323
3356
  fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
3324
3357
  @builtin(local_invocation_id) lid: vec3<u32>,
3325
3358
  @builtin(workgroup_id) wid: vec3<u32> ) {
3326
3359
 
3360
+ // x: frame pixels, y: frame width, z: buffer width, w: border. The border is not metered.
3327
3361
  let total = params.x;
3328
3362
  var sum = 0.0;
3329
3363
  var i = gid.x;
3330
3364
  loop {
3331
3365
  if ( i >= total ) { break; }
3332
- let c = col[ i ].xyz;
3366
+ let c = col[ ( i / params.y + params.w ) * params.z + i % params.y + params.w ].xyz;
3333
3367
  let lum = 0.212671 * c.r + 0.71516 * c.g + 0.072169 * c.b;
3334
3368
  sum = sum + log2( max( lum, 0.0 ) + 0.0001 );
3335
3369
  i = i + WG * GROUPS;
@@ -3342,7 +3376,7 @@ fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
3342
3376
  if ( lid.x == 0u ) { partials[ wid.x ] = sdata[ 0 ]; }
3343
3377
  }
3344
3378
 
3345
- @compute @workgroup_size(${Xo})
3379
+ @compute @workgroup_size(${Qo})
3346
3380
  fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
3347
3381
 
3348
3382
  var v = 0.0;
@@ -3352,19 +3386,19 @@ fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
3352
3386
  treeSum( lid.x );
3353
3387
 
3354
3388
  if ( lid.x == 0u ) {
3355
- let scale = ${Yo} / exp2( sdata[ 0 ] / f32( params.x ) );
3389
+ let scale = ${Zo} / exp2( sdata[ 0 ] / f32( params.x ) );
3356
3390
  // Mirrors the CPU guard: a non-finite or non-positive scale means no scaling at all.
3357
3391
  scaleOut[ 0 ] = select( 1.0, scale, scale > 0.0 && scale < 3.4e38 );
3358
3392
  }
3359
3393
  }
3360
- `, $o = "\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", es = 64, ts = 32768, ns = 16, rs = 32, is = `
3394
+ `, ts = "\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", ns = 64, rs = 32768, is = 16, as = 32, os = `
3361
3395
  struct UnpackParams {
3362
3396
  srcWidth: u32,
3363
3397
  tileX: u32,
3364
3398
  tileY: u32,
3365
3399
  tileW: u32,
3366
3400
  tileH: u32,
3367
- pad0: u32,
3401
+ border: u32,
3368
3402
  pad1: u32,
3369
3403
  pad2: u32,
3370
3404
  };
@@ -3375,32 +3409,39 @@ struct UnpackParams {
3375
3409
  @group(0) @binding(3) var<storage, read> inColor: array<vec4<f32>>;
3376
3410
  @group(0) @binding(4) var dst: texture_storage_2d<rgba16float, write>;
3377
3411
 
3378
- @compute @workgroup_size(${ns}, ${ns})
3412
+ @compute @workgroup_size(${is}, ${is})
3379
3413
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3380
3414
 
3381
3415
  if ( gid.x >= P.tileW || gid.y >= P.tileH ) { return; }
3382
3416
 
3383
3417
  let px = P.tileX + gid.x;
3384
3418
  let py = P.tileY + gid.y;
3385
- let si = py * P.srcWidth + px;
3419
+ let si = ( py + P.border ) * P.srcWidth + px + P.border;
3386
3420
 
3387
3421
  // scaleBuf is the autoexposure factor the input was multiplied by; dividing it out returns
3388
3422
  // the renderer's units. Alpha rides through from the path tracer so a transparent background
3389
3423
  // survives the denoise.
3390
3424
  textureStore( dst, vec2<u32>( px, py ), vec4<f32>( src[ si ].xyz / scaleBuf[ 0 ], inColor[ si ].w ) );
3391
3425
  }
3392
- `, as = 8, os = `
3426
+ `, ss = 8, cs = `
3393
3427
  @group(0) @binding(0) var src: texture_2d<f32>;
3394
3428
  @group(0) @binding(1) var<storage, read_write> dst: array<vec4<f32>>;
3395
- @group(0) @binding(2) var<uniform> size: vec2<u32>;
3429
+ @group(0) @binding(2) var<uniform> size: vec4<u32>; // buffer w, h; frame w, h
3430
+
3431
+ fn mirror( i: i32, n: i32 ) -> i32 {
3432
+ let m = abs( i );
3433
+ return clamp( select( m, 2 * n - 2 - m, m >= n ), 0, n - 1 );
3434
+ }
3396
3435
 
3397
- @compute @workgroup_size(${as}, ${as})
3436
+ @compute @workgroup_size(${ss}, ${ss})
3398
3437
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3399
3438
 
3400
3439
  if ( gid.x >= size.x || gid.y >= size.y ) { return; }
3401
- dst[ gid.y * size.x + gid.x ] = textureLoad( src, gid.xy, 0 );
3440
+ let p = vec2<i32>( gid.xy ) - ${Ko};
3441
+ let s = vec2<i32>( mirror( p.x, i32( size.z ) ), mirror( p.y, i32( size.w ) ) );
3442
+ dst[ gid.y * size.x + gid.x ] = textureLoad( src, s, 0 );
3402
3443
  }
3403
- `, ss = class extends fr {
3444
+ `, ls = class extends fr {
3404
3445
  constructor(e, t = {}) {
3405
3446
  if (super(), !e) throw Error("OIDNDenoiser requires a renderer");
3406
3447
  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 = {
@@ -3414,7 +3455,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3414
3455
  width: 0,
3415
3456
  height: 0
3416
3457
  }, this.config = {
3417
- ...Jo.DEFAULT_OPTIONS,
3458
+ ...Xo.DEFAULT_OPTIONS,
3418
3459
  ...t
3419
3460
  }, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
3420
3461
  isDenoising: !1,
@@ -3435,7 +3476,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3435
3476
  }
3436
3477
  }
3437
3478
  expectsCleanAux(e = this.quality) {
3438
- let { QUALITY_MODELS: t } = Jo;
3479
+ let { QUALITY_MODELS: t } = Xo;
3439
3480
  return (t[e] || t.balance).cleanAux;
3440
3481
  }
3441
3482
  getRuntimeInfo() {
@@ -3450,8 +3491,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3450
3491
  _resolveTileSize() {
3451
3492
  let e = Math.max(this._renderWidth, this._renderHeight);
3452
3493
  if (!e) return this.maxTileSize;
3453
- let t = Math.ceil(e / Go) * Go;
3454
- return t <= this.maxTileSize ? t : Math.max(Go, Math.floor(this.maxTileSize / Go) * Go);
3494
+ if (e <= this.maxTileSize) {
3495
+ let e = qo(this._renderWidth, this._renderHeight);
3496
+ return Math.max(e.width, e.height);
3497
+ }
3498
+ return Math.max(Go, Math.floor(this.maxTileSize / Go) * Go);
3455
3499
  }
3456
3500
  _setupUNetDenoiser() {
3457
3501
  return this.state.isLoading ? (this._reloadPending = !0, Promise.resolve()) : (this._loading = this._loadUNet(), this._loading);
@@ -3489,9 +3533,9 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3489
3533
  let n;
3490
3534
  if (this.backendParamsGetter) {
3491
3535
  let e = this.backendParamsGetter();
3492
- this.gpuDevice = e?.device ?? null, n = e?.device ? e : void 0;
3536
+ this.gpuDevice = e?.device ?? null, n = e?.device ? { device: e.device } : void 0;
3493
3537
  }
3494
- this.unet = await (await qo())(await this._fetchWeights(e), n, {
3538
+ this.unet = await (await Yo())(await this._fetchWeights(e), n, {
3495
3539
  aux: !0,
3496
3540
  hdr: !0,
3497
3541
  maxTileSize: t,
@@ -3503,14 +3547,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3503
3547
  return t || (t = m().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;
3504
3548
  }
3505
3549
  _generateTzaUrl() {
3506
- let { oidnWeightsBaseUrl: e } = ot(), { QUALITY_MODELS: t } = Jo;
3550
+ let { oidnWeightsBaseUrl: e } = ot(), { QUALITY_MODELS: t } = Xo;
3507
3551
  return `${e}${(t[this.quality] || t.balance).model}.tza`;
3508
3552
  }
3509
3553
  async updateConfiguration(e) {
3510
3554
  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());
3511
3555
  }
3512
3556
  async updateQuality(e) {
3513
- if (!Object.prototype.hasOwnProperty.call(Jo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Jo.QUALITY_MODELS).join(", ")}`);
3557
+ if (!Object.prototype.hasOwnProperty.call(Xo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Xo.QUALITY_MODELS).join(", ")}`);
3514
3558
  await this.updateConfiguration({ oidnQuality: e });
3515
3559
  }
3516
3560
  async start({ continuous: e = !1 } = {}) {
@@ -3545,88 +3589,73 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3545
3589
  if (!r?.color) return Wo.warn("GPU textures not ready yet"), !1;
3546
3590
  let i = this.gpuDevice;
3547
3591
  if (!i) return Wo.warn("gpuDevice not available"), !1;
3548
- this._ensureGPUInputBuffers(t, n), this._copyInputs(i, r, t, n), this._computeInputScale(i, t * n), this._applyColorScale(i, t * n), !e && !this._hasOutput && this._unpackToTexture(this._gpuInputBuffers.color, t, {
3592
+ this._ensureGPUInputBuffers(t, n), this._copyInputs(i, r, t, n);
3593
+ let a = qo(t, n);
3594
+ this._computeInputScale(i, t, n), this._applyColorScale(i, a.width * a.height), !e && !this._hasOutput && this._unpackToTexture(this._gpuInputBuffers.color, {
3549
3595
  x: 0,
3550
3596
  y: 0,
3551
3597
  width: t,
3552
3598
  height: n
3553
3599
  }, !1);
3554
- let a = {
3555
- color: {
3556
- data: this._gpuInputBuffers.color,
3557
- width: t,
3558
- height: n
3559
- },
3560
- albedo: {
3561
- data: this._gpuInputBuffers.albedo,
3562
- width: t,
3563
- height: n
3564
- },
3565
- normal: {
3566
- data: this._gpuInputBuffers.normal,
3567
- width: t,
3568
- height: n
3569
- }
3600
+ let o = (e) => ({
3601
+ data: e,
3602
+ width: a.width,
3603
+ height: a.height
3604
+ }), s = {
3605
+ color: o(this._gpuInputBuffers.color),
3606
+ albedo: o(this._gpuInputBuffers.albedo),
3607
+ normal: o(this._gpuInputBuffers.normal)
3570
3608
  };
3571
- return this._executeWithAbortGPU(a, e);
3609
+ return this._executeWithAbortGPU(s, e);
3572
3610
  }
3573
3611
  _copyInputs(e, t, n, r) {
3574
- let i = e.createCommandEncoder({ label: "oidn-tex-to-buf" }), a = n * 16, o = a % 256 == 0 ? null : this._beginPack(e, i, n, r), s = (t, s) => {
3575
- o ? (o.setBindGroup(0, e.createBindGroup({
3576
- layout: this._packLayout,
3577
- entries: [
3578
- {
3579
- binding: 0,
3580
- resource: t.createView()
3581
- },
3582
- {
3583
- binding: 1,
3584
- resource: { buffer: s }
3585
- },
3586
- {
3587
- binding: 2,
3588
- resource: { buffer: this._packParams }
3589
- }
3590
- ]
3591
- })), o.dispatchWorkgroups(Math.ceil(n / as), Math.ceil(r / as))) : i.copyTextureToBuffer({
3592
- texture: t,
3593
- mipLevel: 0
3594
- }, {
3595
- buffer: s,
3596
- offset: 0,
3597
- bytesPerRow: a,
3598
- rowsPerImage: r
3599
- }, {
3600
- width: n,
3601
- height: r,
3602
- depthOrArrayLayers: 1
3603
- });
3604
- };
3605
- s(t.color, this._gpuInputBuffers.color), s(t.albedo, this._gpuInputBuffers.albedo), s(t.normal, this._gpuInputBuffers.normal), o?.end(), e.queue.submit([i.finish()]);
3612
+ let i = qo(n, r), a = e.createCommandEncoder({ label: "oidn-tex-to-buf" }), o = this._beginPack(e, a, i, n, r);
3613
+ for (let n of [
3614
+ "color",
3615
+ "albedo",
3616
+ "normal"
3617
+ ]) o.setBindGroup(0, e.createBindGroup({
3618
+ layout: this._packLayout,
3619
+ entries: [
3620
+ {
3621
+ binding: 0,
3622
+ resource: t[n].createView()
3623
+ },
3624
+ {
3625
+ binding: 1,
3626
+ resource: { buffer: this._gpuInputBuffers[n] }
3627
+ },
3628
+ {
3629
+ binding: 2,
3630
+ resource: { buffer: this._packParams }
3631
+ }
3632
+ ]
3633
+ })), o.dispatchWorkgroups(Math.ceil(i.width / ss), Math.ceil(i.height / ss));
3634
+ o.end(), e.queue.submit([a.finish()]);
3606
3635
  }
3607
3636
  _ensureGPUInputBuffers(e, t) {
3608
3637
  let { width: n, height: r } = this._gpuInputBufferSize;
3609
3638
  if (n === e && r === t && this._gpuInputBuffers.color) return;
3610
3639
  this._destroyGPUInputBuffers();
3611
- let i = this.gpuDevice, a = e * t * 16, o = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
3640
+ let i = this.gpuDevice, a = qo(e, t), o = a.width * a.height * 16, s = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
3612
3641
  this._gpuInputBuffers.color = i.createBuffer({
3613
3642
  label: "oidn-in-color",
3614
- size: a,
3615
- usage: o
3643
+ size: o,
3644
+ usage: s
3616
3645
  }), this._gpuInputBuffers.albedo = i.createBuffer({
3617
3646
  label: "oidn-in-albedo",
3618
- size: a,
3619
- usage: o
3647
+ size: o,
3648
+ usage: s
3620
3649
  }), this._gpuInputBuffers.normal = i.createBuffer({
3621
3650
  label: "oidn-in-normal",
3622
- size: a,
3623
- usage: o
3651
+ size: o,
3652
+ usage: s
3624
3653
  }), this._gpuInputBufferSize = {
3625
3654
  width: e,
3626
3655
  height: t
3627
3656
  };
3628
3657
  }
3629
- _beginPack(e, t, n, r) {
3658
+ _beginPack(e, t, n, r, i) {
3630
3659
  this._packPipeline ||= (this._packLayout = e.createBindGroupLayout({
3631
3660
  label: "oidn-pack",
3632
3661
  entries: [
@@ -3652,17 +3681,22 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3652
3681
  compute: {
3653
3682
  module: e.createShaderModule({
3654
3683
  label: "oidn-pack",
3655
- code: os
3684
+ code: cs
3656
3685
  }),
3657
3686
  entryPoint: "main"
3658
3687
  }
3659
- })), this._packParams || (this._packParams = e.createBuffer({
3688
+ })), this._packParams ??= e.createBuffer({
3660
3689
  label: "oidn-pack-size",
3661
- size: 8,
3690
+ size: 16,
3662
3691
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3663
- }), e.queue.writeBuffer(this._packParams, 0, new Uint32Array([n, r])));
3664
- let i = t.beginComputePass({ label: "oidn-pack" });
3665
- return i.setPipeline(this._packPipeline), i;
3692
+ }), e.queue.writeBuffer(this._packParams, 0, new Uint32Array([
3693
+ n.width,
3694
+ n.height,
3695
+ r,
3696
+ i
3697
+ ]));
3698
+ let a = t.beginComputePass({ label: "oidn-pack" });
3699
+ return a.setPipeline(this._packPipeline), a;
3666
3700
  }
3667
3701
  _destroyGPUInputBuffers() {
3668
3702
  this._gpuInputBuffers.color?.destroy(), this._gpuInputBuffers.albedo?.destroy(), this._gpuInputBuffers.normal?.destroy(), this._packParams?.destroy(), this._colorScaleBindGroup = null, this._lumBindGroup = null, this._lumPartials?.destroy(), this._lumPartials = null, this._lumParams?.destroy(), this._lumParams = null, this._inputScaleBuffer?.destroy(), this._inputScaleBuffer = null, this._gpuInputBuffers = {
@@ -3705,7 +3739,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3705
3739
  });
3706
3740
  let t = e.createShaderModule({
3707
3741
  label: "oidn-autoexposure",
3708
- code: Qo
3742
+ code: es
3709
3743
  }), n = e.createPipelineLayout({ bindGroupLayouts: [this._lumLayout] });
3710
3744
  this._lumReducePipeline = e.createComputePipeline({
3711
3745
  label: "oidn-autoexposure-reduce",
@@ -3729,7 +3763,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3729
3763
  compute: {
3730
3764
  module: e.createShaderModule({
3731
3765
  label: "oidn-color-scale",
3732
- code: $o
3766
+ code: ts
3733
3767
  }),
3734
3768
  entryPoint: "main"
3735
3769
  }
@@ -3739,7 +3773,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3739
3773
  compute: {
3740
3774
  module: e.createShaderModule({
3741
3775
  label: "oidn-output-unpack",
3742
- code: is
3776
+ code: os
3743
3777
  }),
3744
3778
  entryPoint: "main"
3745
3779
  }
@@ -3749,7 +3783,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3749
3783
  size: 4
3750
3784
  }), this._lumPartials = e.createBuffer({
3751
3785
  label: "oidn-autoexposure-partials",
3752
- size: Zo * 4,
3786
+ size: $o * 4,
3753
3787
  usage: GPUBufferUsage.STORAGE
3754
3788
  }), this._lumParams = e.createBuffer({
3755
3789
  label: "oidn-autoexposure-params",
@@ -3788,26 +3822,27 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3788
3822
  }]
3789
3823
  }), !0;
3790
3824
  }
3791
- _computeInputScale(e, t) {
3825
+ _computeInputScale(e, t, n) {
3792
3826
  if (!this._ensureScalePipelines(e)) return;
3793
3827
  if (globalThis.__OIDN_NO_INPUT_SCALE) {
3794
3828
  e.queue.writeBuffer(this._inputScaleBuffer, 0, new Float32Array([1]));
3795
3829
  return;
3796
3830
  }
3831
+ let r = qo(t, n);
3797
3832
  e.queue.writeBuffer(this._lumParams, 0, new Uint32Array([
3833
+ t * n,
3798
3834
  t,
3799
- 0,
3800
- 0,
3801
- 0
3835
+ r.width,
3836
+ Ko
3802
3837
  ]));
3803
- let n = e.createCommandEncoder({ label: "oidn-autoexposure" }), r = n.beginComputePass({ label: "oidn-autoexposure-reduce" });
3804
- r.setPipeline(this._lumReducePipeline), r.setBindGroup(0, this._lumBindGroup), r.dispatchWorkgroups(Zo, 1, 1), r.end();
3805
- let i = n.beginComputePass({ label: "oidn-autoexposure-finalize" });
3806
- i.setPipeline(this._lumFinalizePipeline), i.setBindGroup(0, this._lumBindGroup), i.dispatchWorkgroups(1, 1, 1), i.end(), e.queue.submit([n.finish()]);
3838
+ let i = e.createCommandEncoder({ label: "oidn-autoexposure" }), a = i.beginComputePass({ label: "oidn-autoexposure-reduce" });
3839
+ a.setPipeline(this._lumReducePipeline), a.setBindGroup(0, this._lumBindGroup), a.dispatchWorkgroups($o, 1, 1), a.end();
3840
+ let o = i.beginComputePass({ label: "oidn-autoexposure-finalize" });
3841
+ o.setPipeline(this._lumFinalizePipeline), o.setBindGroup(0, this._lumBindGroup), o.dispatchWorkgroups(1, 1, 1), o.end(), e.queue.submit([i.finish()]);
3807
3842
  }
3808
3843
  _applyColorScale(e, t) {
3809
3844
  if (!this._ensureScalePipelines(e)) return;
3810
- let n = Math.ceil(t / es), r = Math.min(n, ts), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
3845
+ let n = Math.ceil(t / ns), r = Math.min(n, rs), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
3811
3846
  o.setPipeline(this._colorScalePipeline), o.setBindGroup(0, this._colorScaleBindGroup), o.dispatchWorkgroups(r, i, 1), o.end(), e.queue.submit([a.finish()]);
3812
3847
  }
3813
3848
  get outputTexture() {
@@ -3845,28 +3880,29 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3845
3880
  height: 0
3846
3881
  };
3847
3882
  }
3848
- _unpackToTexture(e, t, n, r = !0) {
3849
- let i = this.gpuDevice;
3850
- if (!i || !this._ensureScalePipelines(i)) return;
3851
- let { x: a, y: o, width: s, height: c } = n;
3852
- if (this._ensureOutputTexture(i, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
3853
- let l = i.createBuffer({
3883
+ _unpackToTexture(e, t, n = !0) {
3884
+ let r = this.gpuDevice;
3885
+ if (!r || !this._ensureScalePipelines(r)) return;
3886
+ let { x: i, y: a, width: o, height: s } = t;
3887
+ if (this._ensureOutputTexture(r, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
3888
+ let c = r.createBuffer({
3854
3889
  label: "oidn-unpack-params",
3855
- size: rs,
3890
+ size: as,
3856
3891
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3857
3892
  });
3858
3893
  try {
3859
- i.queue.writeBuffer(l, 0, new Uint32Array([
3894
+ let t = qo(this._gpuInputBufferSize.width, this._gpuInputBufferSize.height).width;
3895
+ r.queue.writeBuffer(c, 0, new Uint32Array([
3860
3896
  t,
3897
+ i,
3861
3898
  a,
3862
3899
  o,
3863
3900
  s,
3864
- c,
3865
- 0,
3901
+ Ko,
3866
3902
  0,
3867
3903
  0
3868
3904
  ]));
3869
- let n = i.createBindGroup({
3905
+ let l = r.createBindGroup({
3870
3906
  label: "oidn-output-unpack",
3871
3907
  layout: this._unpackPipeline.getBindGroupLayout(0),
3872
3908
  entries: [
@@ -3876,7 +3912,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3876
3912
  },
3877
3913
  {
3878
3914
  binding: 1,
3879
- resource: { buffer: l }
3915
+ resource: { buffer: c }
3880
3916
  },
3881
3917
  {
3882
3918
  binding: 2,
@@ -3891,10 +3927,10 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3891
3927
  resource: this._outGPUTexture.createView()
3892
3928
  }
3893
3929
  ]
3894
- }), u = i.createCommandEncoder({ label: "oidn-output-unpack" }), d = u.beginComputePass({ label: "oidn-output-unpack" });
3895
- d.setPipeline(this._unpackPipeline), d.setBindGroup(0, n), d.dispatchWorkgroups(Math.ceil(s / ns), Math.ceil(c / ns), 1), d.end(), i.queue.submit([u.finish()]), r && (this._hasOutput = !0);
3930
+ }), u = r.createCommandEncoder({ label: "oidn-output-unpack" }), d = u.beginComputePass({ label: "oidn-output-unpack" });
3931
+ d.setPipeline(this._unpackPipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / is), Math.ceil(s / is), 1), d.end(), r.queue.submit([u.finish()]), n && (this._hasOutput = !0);
3896
3932
  } finally {
3897
- l.destroy();
3933
+ c.destroy();
3898
3934
  }
3899
3935
  }
3900
3936
  _executeWithAbortGPU(e, t = !1) {
@@ -3907,11 +3943,15 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3907
3943
  this._tilesWritten = 0;
3908
3944
  let a = () => {
3909
3945
  i &&= (i(), null), r(new DOMException("Aborted", "AbortError"));
3910
- };
3911
- this.state.abortController.signal.addEventListener("abort", a, { once: !0 }), i = this.unet.tileExecute({
3946
+ }, o = this.state.abortController.signal;
3947
+ o.addEventListener("abort", a, { once: !0 }), i = this.unet.tileExecute({
3912
3948
  ...e,
3949
+ scheduling: t ? "animation-frame" : "event-loop",
3950
+ error: (e) => {
3951
+ o.removeEventListener("abort", a), i = null, r(e);
3952
+ },
3913
3953
  done: async (e) => {
3914
- this.state.abortController.signal.removeEventListener("abort", a), i = null;
3954
+ o.removeEventListener("abort", a), i = null;
3915
3955
  try {
3916
3956
  this._tilesWritten === 0 && this._displayGPUOutput(e), n();
3917
3957
  } catch (e) {
@@ -3920,17 +3960,17 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3920
3960
  },
3921
3961
  progress: (e, n, r) => {
3922
3962
  if (!e?.data || !r) return;
3923
- let i = e.width, a = e.height, o = Math.min(r.width, i - r.x), s = Math.min(r.height, a - r.y);
3924
- if (o <= 0 || s <= 0) return;
3925
- let c = {
3926
- x: r.x,
3927
- y: r.y,
3928
- width: o,
3929
- height: s
3963
+ let { width: i, height: a } = this._gpuInputBufferSize, o = Math.max(r.x - Ko, 0), s = Math.max(r.y - Ko, 0), c = Math.min(r.x + r.width - Ko, i) - o, l = Math.min(r.y + r.height - Ko, a) - s;
3964
+ if (c <= 0 || l <= 0) return;
3965
+ let u = {
3966
+ x: o,
3967
+ y: s,
3968
+ width: c,
3969
+ height: l
3930
3970
  };
3931
- this._unpackToTexture(e.data, i, c), this._tilesWritten++, this.dispatchEvent({
3971
+ this._unpackToTexture(e.data, u), this._tilesWritten++, this.dispatchEvent({
3932
3972
  type: "tileProgress",
3933
- tile: c,
3973
+ tile: u,
3934
3974
  imageWidth: i,
3935
3975
  imageHeight: a,
3936
3976
  continuous: t
@@ -3939,12 +3979,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3939
3979
  });
3940
3980
  });
3941
3981
  }
3942
- _displayGPUOutput({ data: e, width: t, height: n }) {
3982
+ _displayGPUOutput({ data: e }) {
3943
3983
  if (!this.gpuDevice) {
3944
3984
  Wo.error("gpuDevice not available for the output picture");
3945
3985
  return;
3946
3986
  }
3947
- this._unpackToTexture(e, t, {
3987
+ let { width: t, height: n } = this._gpuInputBufferSize;
3988
+ this._unpackToTexture(e, {
3948
3989
  x: 0,
3949
3990
  y: 0,
3950
3991
  width: t,
@@ -3969,7 +4010,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3969
4010
  dispose() {
3970
4011
  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?.(), Wo.debug("disposed");
3971
4012
  }
3972
- }, cs = Object.freeze({
4013
+ }, us = Object.freeze({
3973
4014
  maxLength: 8,
3974
4015
  smoothLength: 2,
3975
4016
  roughStart: .45,
@@ -3977,7 +4018,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3977
4018
  depthTolerance: .05,
3978
4019
  normalTolerance: .8,
3979
4020
  movedLength: 2
3980
- }), ls = 8, us = 304, ds = 16, fs = 1, ps = 2, ms = 4, hs = 1073741824, gs = "\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", _s = gs + `
4021
+ }), ds = 8, fs = 304, ps = 16, ms = 1, hs = 2, gs = 4, _s = 1073741824, vs = "\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", ys = vs + `
3981
4022
  @group(0) @binding(1) var geoCur: texture_2d<f32>;
3982
4023
  @group(0) @binding(2) var geoPrev: texture_2d<f32>;
3983
4024
  @group(0) @binding(3) var<storage, read_write> picked: array<i32>;
@@ -4003,7 +4044,7 @@ fn movedIndex( leaf: u32 ) -> i32 {
4003
4044
 
4004
4045
  }
4005
4046
 
4006
- @compute @workgroup_size(${ls}, ${ls})
4047
+ @compute @workgroup_size(${ds}, ${ds})
4007
4048
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4008
4049
 
4009
4050
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -4018,7 +4059,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4018
4059
  let size = vec2<f32>( P.size );
4019
4060
  let uv = ( vec2<f32>( gid.xy ) + 0.5 ) / size;
4020
4061
  // Depth is along the ray: from the camera, or from its image plane when orthographic.
4021
- let ortho = ( P.flags & ${ms}u ) != 0u;
4062
+ let ortho = ( P.flags & ${gs}u ) != 0u;
4022
4063
  let ndc = vec2<f32>( uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0 );
4023
4064
  var origin = P.camWorld[ 3 ].xyz;
4024
4065
  var dir: vec3<f32>;
@@ -4042,7 +4083,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4042
4083
  let toPrev = movedToPrev[ u32( m ) ];
4043
4084
  wp = ( toPrev * vec4<f32>( wp, 1.0 ) ).xyz;
4044
4085
  n = normalize( ( toPrev * vec4<f32>( n, 0.0 ) ).xyz );
4045
- movedFlag = ${hs};
4086
+ movedFlag = ${_s};
4046
4087
 
4047
4088
  }
4048
4089
 
@@ -4079,7 +4120,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4079
4120
  if ( pick >= 0 ) { atomicAdd( &copies[ u32( pick ) ], 1u ); }
4080
4121
 
4081
4122
  }
4082
- `, vs = gs + `
4123
+ `, bs = vs + `
4083
4124
  @group(0) @binding(1) var curColor: texture_2d<f32>;
4084
4125
  @group(0) @binding(2) var curAlbedo: texture_2d<f32>;
4085
4126
  @group(0) @binding(3) var curNormal: texture_2d<f32>;
@@ -4093,7 +4134,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4093
4134
  @group(0) @binding(11) var outAlbedo: texture_storage_2d<rgba32float, write>;
4094
4135
  @group(0) @binding(12) var outNormal: texture_storage_2d<rgba32float, write>;
4095
4136
 
4096
- @compute @workgroup_size(${ls}, ${ls})
4137
+ @compute @workgroup_size(${ds}, ${ds})
4097
4138
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4098
4139
 
4099
4140
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -4109,8 +4150,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4109
4150
  var ha = ca.xyz;
4110
4151
  var hn = cn.xyz;
4111
4152
  let raw = picked[ gid.y * P.size.x + gid.x ];
4112
- let movedPx = raw >= 0 && ( raw & ${hs} ) != 0;
4113
- let pick = select( raw, raw & ~${hs}, raw >= 0 );
4153
+ let movedPx = raw >= 0 && ( raw & ${_s} ) != 0;
4154
+ let pick = select( raw, raw & ~${_s}, raw >= 0 );
4114
4155
 
4115
4156
  if ( pick >= 0 ) {
4116
4157
 
@@ -4124,7 +4165,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4124
4165
  ha = a.xyz;
4125
4166
  hn = textureLoad( histNormal, q, 0 ).xyz;
4126
4167
  len = a.w;
4127
- if ( ( P.flags & ${ps}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
4168
+ if ( ( P.flags & ${hs}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
4128
4169
 
4129
4170
  }
4130
4171
 
@@ -4138,11 +4179,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4138
4179
 
4139
4180
  textureStore( outColor, p, vec4<f32>( mix( hc, cur.xyz, t ), cur.w ) );
4140
4181
  textureStore( outAlbedo, p, vec4<f32>( mix( ha, ca.xyz, t ), newLen ) );
4141
- let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${fs}u ) != 0u );
4182
+ let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${ms}u ) != 0u );
4142
4183
  textureStore( outNormal, p, vec4<f32>( n, cn.w ) );
4143
4184
 
4144
4185
  }
4145
- `, ys = gs + `
4186
+ `, xs = vs + `
4146
4187
  @group(0) @binding(1) var accColor: texture_2d<f32>;
4147
4188
  @group(0) @binding(2) var accAlbedo: texture_2d<f32>;
4148
4189
  @group(0) @binding(3) var accNormal: texture_2d<f32>;
@@ -4153,7 +4194,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4153
4194
  @group(0) @binding(8) var outAlbedo: texture_storage_2d<rgba32float, write>;
4154
4195
  @group(0) @binding(9) var outNormal: texture_storage_2d<rgba32float, write>;
4155
4196
 
4156
- @compute @workgroup_size(${ls}, ${ls})
4197
+ @compute @workgroup_size(${ds}, ${ds})
4157
4198
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4158
4199
 
4159
4200
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -4187,32 +4228,32 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4187
4228
  let t = P.samples / max( k + P.samples, 1e-6 );
4188
4229
  textureStore( outColor, p, vec4<f32>( mix( hc, ac.xyz, t ), ac.w ) );
4189
4230
  textureStore( outAlbedo, p, vec4<f32>( mix( ha, aa.xyz, t ), min( k + P.samples, P.maxLength ) ) );
4190
- let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${fs}u ) != 0u );
4231
+ let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${ms}u ) != 0u );
4191
4232
  textureStore( outNormal, p, vec4<f32>( n, an.w ) );
4192
4233
 
4193
4234
  }
4194
- `, bs = (e) => ({
4235
+ `, Ss = (e) => ({
4195
4236
  binding: e,
4196
4237
  visibility: GPUShaderStage.COMPUTE,
4197
4238
  texture: { sampleType: "unfilterable-float" }
4198
- }), xs = (e) => ({
4239
+ }), Cs = (e) => ({
4199
4240
  binding: e,
4200
4241
  visibility: GPUShaderStage.COMPUTE,
4201
4242
  storageTexture: {
4202
4243
  access: "write-only",
4203
4244
  format: "rgba32float"
4204
4245
  }
4205
- }), Ss = (e, t) => ({
4246
+ }), ws = (e, t) => ({
4206
4247
  binding: e,
4207
4248
  visibility: GPUShaderStage.COMPUTE,
4208
4249
  buffer: { type: t }
4209
- }), Cs = class {
4250
+ }), Ts = class {
4210
4251
  constructor(e) {
4211
4252
  this.device = e, this.settings = {
4212
- ...cs,
4253
+ ...us,
4213
4254
  cleanAux: !1,
4214
4255
  splitCopies: !0
4215
- }, 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(us), 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);
4256
+ }, 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(fs), 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);
4216
4257
  }
4217
4258
  get textures() {
4218
4259
  return this.valid ? this._sets[this._current] : null;
@@ -4320,23 +4361,23 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4320
4361
  }),
4321
4362
  layout: i
4322
4363
  };
4323
- }, n = Ss(0, "uniform");
4364
+ }, n = ws(0, "uniform");
4324
4365
  this._pipelines = {
4325
- select: t("oidn-history-select", _s, [
4366
+ select: t("oidn-history-select", ys, [
4326
4367
  n,
4327
- bs(1),
4328
- bs(2),
4329
- Ss(3, "storage"),
4330
- Ss(4, "storage"),
4368
+ Ss(1),
4369
+ Ss(2),
4370
+ ws(3, "storage"),
4371
+ ws(4, "storage"),
4331
4372
  {
4332
4373
  binding: 5,
4333
4374
  visibility: GPUShaderStage.COMPUTE,
4334
4375
  texture: { sampleType: "uint" }
4335
4376
  },
4336
- Ss(6, "read-only-storage"),
4337
- Ss(7, "read-only-storage")
4377
+ ws(6, "read-only-storage"),
4378
+ ws(7, "read-only-storage")
4338
4379
  ]),
4339
- blend: t("oidn-history-blend", vs, [
4380
+ blend: t("oidn-history-blend", bs, [
4340
4381
  n,
4341
4382
  ...[
4342
4383
  1,
@@ -4346,14 +4387,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4346
4387
  5,
4347
4388
  6,
4348
4389
  7
4349
- ].map(bs),
4350
- Ss(8, "read-only-storage"),
4351
- Ss(9, "read-only-storage"),
4352
- xs(10),
4353
- xs(11),
4354
- xs(12)
4390
+ ].map(Ss),
4391
+ ws(8, "read-only-storage"),
4392
+ ws(9, "read-only-storage"),
4393
+ Cs(10),
4394
+ Cs(11),
4395
+ Cs(12)
4355
4396
  ]),
4356
- merge: t("oidn-history-merge", ys, [
4397
+ merge: t("oidn-history-merge", xs, [
4357
4398
  n,
4358
4399
  ...[
4359
4400
  1,
@@ -4362,16 +4403,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4362
4403
  4,
4363
4404
  5,
4364
4405
  6
4365
- ].map(bs),
4366
- xs(7),
4367
- xs(8),
4368
- xs(9)
4406
+ ].map(Ss),
4407
+ Cs(7),
4408
+ Cs(8),
4409
+ Cs(9)
4369
4410
  ])
4370
4411
  }, this._paramsBuffer = e.createBuffer({
4371
4412
  label: "oidn-history-params",
4372
- size: us,
4413
+ size: fs,
4373
4414
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
4374
- }), this._growMoved(ds);
4415
+ }), this._growMoved(ps);
4375
4416
  }
4376
4417
  _growMoved(e) {
4377
4418
  this._movedLeaves?.destroy(), this._movedToPrev?.destroy();
@@ -4397,11 +4438,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4397
4438
  a.setPipeline(t), a.setBindGroup(0, this.device.createBindGroup({
4398
4439
  layout: n,
4399
4440
  entries: i
4400
- })), a.dispatchWorkgroups(Math.ceil(this.width / ls), Math.ceil(this.height / ls)), a.end();
4441
+ })), a.dispatchWorkgroups(Math.ceil(this.width / ds), Math.ceil(this.height / ds)), a.end();
4401
4442
  }
4402
4443
  _writeParams(e, t, n, r) {
4403
4444
  let i = this.settings, a = this._paramU32, o = this._paramF32;
4404
- a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? fs : 0) | (i.splitCopies ? ps : 0) | (e.orthographic ? ms : 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);
4445
+ a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? ms : 0) | (i.splitCopies ? hs : 0) | (e.orthographic ? gs : 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);
4405
4446
  }
4406
4447
  _rememberCamera(e) {
4407
4448
  this._prevViewProj.set(e.viewProj), this._prevCamPos[0] = e.world[12], this._prevCamPos[1] = e.world[13], this._prevCamPos[2] = e.world[14];
@@ -4411,11 +4452,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4411
4452
  _releaseTextures() {
4412
4453
  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;
4413
4454
  }
4414
- }, ws = "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})}};", Ts = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", ws], { type: "text/javascript;charset=utf-8" });
4415
- function Es(e) {
4455
+ }, Es = "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})}};", Ds = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Es], { type: "text/javascript;charset=utf-8" });
4456
+ function Os(e) {
4416
4457
  let t;
4417
4458
  try {
4418
- if (t = Ts && (self.URL || self.webkitURL).createObjectURL(Ts), !t) throw "";
4459
+ if (t = Ds && (self.URL || self.webkitURL).createObjectURL(Ds), !t) throw "";
4419
4460
  let n = new Worker(t, {
4420
4461
  type: "module",
4421
4462
  name: e?.name
@@ -4424,7 +4465,7 @@ function Es(e) {
4424
4465
  (self.URL || self.webkitURL).revokeObjectURL(t);
4425
4466
  }), n;
4426
4467
  } catch {
4427
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(ws), {
4468
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Es), {
4428
4469
  type: "module",
4429
4470
  name: e?.name
4430
4471
  });
@@ -4432,7 +4473,7 @@ function Es(e) {
4432
4473
  }
4433
4474
  //#endregion
4434
4475
  //#region src/Passes/AIUpscaler.js
4435
- var Ds = {
4476
+ var ks = {
4436
4477
  fast: {
4437
4478
  2: "2x-spanx2-ch48.onnx",
4438
4479
  4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
@@ -4446,17 +4487,17 @@ var Ds = {
4446
4487
  4: "4xNomos2_hq_mosr_fp32.onnx"
4447
4488
  }
4448
4489
  };
4449
- function Os() {
4490
+ function As() {
4450
4491
  let { upscalerModelBaseUrl: e } = ot(), t = {};
4451
- for (let n in Ds) {
4492
+ for (let n in ks) {
4452
4493
  t[n] = {};
4453
- for (let r in Ds[n]) t[n][r] = e + Ds[n][r];
4494
+ for (let r in ks[n]) t[n][r] = e + ks[n][r];
4454
4495
  }
4455
4496
  return t;
4456
4497
  }
4457
- var ks = {
4498
+ var js = {
4458
4499
  get QUALITY_PRESETS() {
4459
- return Os();
4500
+ return As();
4460
4501
  },
4461
4502
  TILE_SIZE: 512,
4462
4503
  TILE_OVERLAP: 16,
@@ -4467,17 +4508,17 @@ var ks = {
4467
4508
  }],
4468
4509
  graphOptimizationLevel: "all"
4469
4510
  }
4470
- }, As = class extends fr {
4511
+ }, Ms = class extends fr {
4471
4512
  constructor(e, t, n = {}) {
4472
4513
  if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
4473
- 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 || (() => tr), 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 || ks.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
4514
+ 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 || (() => tr), 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 || js.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
4474
4515
  isUpscaling: !1,
4475
4516
  isLoading: !1,
4476
4517
  abortController: null
4477
- }, this._worker = null, this._currentModelUrl = null, this._tileId = 0, this._pendingWorkerHandlers = /* @__PURE__ */ new Set(), this._upscaledAlpha = null, this._upscaledAlphaWidth = 0, this._backupCanvas = null, this._baseWidth = e.width, this._baseHeight = e.height, this._toneMapper = null;
4518
+ }, 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;
4478
4519
  }
4479
4520
  async _ensureSession() {
4480
- let e = ks.QUALITY_PRESETS[this.quality];
4521
+ let e = js.QUALITY_PRESETS[this.quality];
4481
4522
  if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
4482
4523
  let t = e[this.scaleFactor];
4483
4524
  if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
@@ -4487,14 +4528,14 @@ var ks = {
4487
4528
  message: `Loading ${this.scaleFactor}x upscale model...`
4488
4529
  });
4489
4530
  try {
4490
- this._worker ||= new Es(), await new Promise((e, n) => {
4531
+ this._worker ||= new Os(), await new Promise((e, n) => {
4491
4532
  let r = (t) => {
4492
4533
  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)));
4493
4534
  }, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o, storage: s } = ot();
4494
4535
  this._worker.addEventListener("message", r), this._worker.postMessage({
4495
4536
  type: "load",
4496
4537
  url: t,
4497
- sessionOptions: ks.SESSION_OPTIONS,
4538
+ sessionOptions: js.SESSION_OPTIONS,
4498
4539
  ortRuntimeUrl: i,
4499
4540
  ortWasmPaths: a,
4500
4541
  cacheNamespace: o,
@@ -4511,30 +4552,30 @@ var ks = {
4511
4552
  }
4512
4553
  }
4513
4554
  }
4514
- async start() {
4555
+ async start(e = null) {
4515
4556
  if (!this.enabled || this.state.isUpscaling || this.state.isLoading) return !1;
4516
4557
  this.dispatchEvent({ type: "start" });
4517
- let e = performance.now(), t = await this.execute();
4518
- if (t) {
4558
+ let t = performance.now(), n = await this.execute(e);
4559
+ if (n) {
4519
4560
  this.renderer?.resetState?.();
4520
- let t = performance.now() - e;
4521
- console.log(`AI Upscaler: ${this.scaleFactor}x upscale completed in ${t.toFixed(1)}ms`);
4561
+ let e = performance.now() - t;
4562
+ console.log(`AI Upscaler: ${this.scaleFactor}x upscale completed in ${e.toFixed(1)}ms`);
4522
4563
  }
4523
- return t;
4564
+ return n;
4524
4565
  }
4525
4566
  _revealOutput() {
4526
4567
  this.output.style.display = "block", this.input.style.opacity = "0";
4527
4568
  }
4528
- async execute() {
4569
+ async execute(e = null) {
4529
4570
  if (!this.enabled) return !1;
4530
- this.state.abortController = new AbortController(), this.state.isUpscaling = !0, this.hdr && this.getGPUTextures ? this._capturedSource = await this._captureSourceHDR() : this._capturedSource = this._captureSource(), this._createBackup(this._capturedSource);
4531
- let e = this._capturedSource.width * this.scaleFactor, t = this._capturedSource.height * this.scaleFactor;
4532
- this.output.width = e, this.output.height = t;
4533
- let n = this.output.getContext("2d", {
4571
+ this.state.abortController = new AbortController(), this.state.isUpscaling = !0, e ? this._capturedSource = e : this.hdr && this.getGPUTextures ? this._capturedSource = await this._captureSourceHDR() : this._capturedSource = this._captureSource(), this._createBackup(this._capturedSource);
4572
+ let t = this._capturedSource.width * this.scaleFactor, n = this._capturedSource.height * this.scaleFactor;
4573
+ this.output.width = t, this.output.height = n;
4574
+ let r = this.output.getContext("2d", {
4534
4575
  willReadFrequently: !0,
4535
4576
  alpha: !0
4536
4577
  });
4537
- n.imageSmoothingEnabled = !0, n.imageSmoothingQuality = "high", n.drawImage(this._backupCanvas, 0, 0, e, t), this._revealOutput();
4578
+ r.imageSmoothingEnabled = !0, r.imageSmoothingQuality = "high", r.drawImage(this._backupCanvas, 0, 0, t, n), this._revealOutput();
4538
4579
  try {
4539
4580
  return await this._ensureSession(), await this._runUpscale(), this.dispatchEvent({
4540
4581
  type: "resolution_changed",
@@ -4569,7 +4610,7 @@ var ks = {
4569
4610
  alpha: !0
4570
4611
  });
4571
4612
  this._cacheUpscaledAlpha(t, n * i, r * i);
4572
- let o = ks.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
4613
+ let o = js.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
4573
4614
  for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
4574
4615
  if (e.aborted) throw new DOMException("Aborted", "AbortError");
4575
4616
  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);
@@ -4650,7 +4691,7 @@ var ks = {
4650
4691
  let o = (e) => {
4651
4692
  e.data.id === r && (this._worker.removeEventListener("message", o), this._pendingWorkerHandlers.delete(o), e.data.type === "inferred" ? i(e.data.outputData) : e.data.type === "error" && a(Error(e.data.message)));
4652
4693
  };
4653
- this._pendingWorkerHandlers.add(o), this._worker.addEventListener("message", o), this._worker.postMessage({
4694
+ this._pendingWorkerHandlers.set(o, a), this._worker.addEventListener("message", o), this._worker.postMessage({
4654
4695
  type: "infer",
4655
4696
  tileData: e,
4656
4697
  width: t,
@@ -4712,7 +4753,7 @@ var ks = {
4712
4753
  this.hdr = !!e;
4713
4754
  }
4714
4755
  setQuality(e) {
4715
- if (!ks.QUALITY_PRESETS[e]) {
4756
+ if (!js.QUALITY_PRESETS[e]) {
4716
4757
  console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
4717
4758
  return;
4718
4759
  }
@@ -4729,15 +4770,15 @@ var ks = {
4729
4770
  this._baseWidth = e, this._baseHeight = t;
4730
4771
  }
4731
4772
  _cleanupPendingWorkerHandlers() {
4732
- if (this._worker) for (let e of this._pendingWorkerHandlers) this._worker.removeEventListener("message", e);
4773
+ for (let [e, t] of this._pendingWorkerHandlers) this._worker?.removeEventListener("message", e), t(new DOMException("Aborted", "AbortError"));
4733
4774
  this._pendingWorkerHandlers.clear();
4734
4775
  }
4735
4776
  async dispose() {
4736
4777
  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");
4737
4778
  }
4738
- }, js = Ke("neural"), Ms = 120, Ns = 2, Ps = 1, Fs = 0, Is = 300, Ls = 5, Rs = 3, zs = 3, Bs = 16, Vs = (e) => Math.max(0, 1 - e / Bs), Hs = class extends fr {
4779
+ }, Ns = Ke("neural"), Ps = 120, Fs = 2, Is = 1, Ls = 0, Rs = 300, zs = 5, Bs = 3, Vs = 3, Hs = 16, Us = (e) => Math.max(0, 1 - e / Hs), Ws = class extends fr {
4739
4780
  constructor({ renderer: e, mainCanvas: t, stages: n, pipeline: r, getExposure: i, getSaturation: a, getDisplayGain: o = null, issues: s = null }) {
4740
- 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._finalQuality = ei.oidnQuality, this.finalDenoise = ei.enableOIDN, this.continuousDenoise = ei.continuousDenoise, this.continuousDenoiseInterval = ei.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 = ei.oidnTemporalHistory, this._history = null, this._historyDirty = !0, this._knownResetCount = 0, this._seenTracedFrames = 0, this._viewProj = new br(), this._historyCamera = {
4781
+ 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 = ei.oidnQuality, this.finalDenoise = ei.enableOIDN, this.continuousDenoise = ei.continuousDenoise, this.continuousDenoiseInterval = ei.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 = ei.oidnTemporalHistory, this._history = null, this._historyDirty = !0, this._knownResetCount = 0, this._seenTracedFrames = 0, this._viewProj = new br(), this._historyCamera = {
4741
4782
  world: null,
4742
4783
  projInv: null,
4743
4784
  viewProj: null,
@@ -4746,7 +4787,7 @@ var ks = {
4746
4787
  count: 0,
4747
4788
  leaves: new Uint32Array(),
4748
4789
  toPrev: new Float32Array()
4749
- }, this._matA = new br(), this._matB = new br(), 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._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null;
4790
+ }, this._matA = new br(), this._matB = new br(), 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;
4750
4791
  }
4751
4792
  _createUpscalerCanvas(e) {
4752
4793
  let t = e.parentNode;
@@ -4768,7 +4809,7 @@ var ks = {
4768
4809
  }
4769
4810
  setupDenoiser() {
4770
4811
  let e = this._stages.pathTracer;
4771
- this.denoiser = new ss(this.renderer, {
4812
+ this.denoiser = new ls(this.renderer, {
4772
4813
  enableOIDN: ei.enableOIDN,
4773
4814
  oidnQuality: ei.oidnQuality,
4774
4815
  backendParams: () => ({
@@ -4803,12 +4844,24 @@ var ks = {
4803
4844
  url: e.url,
4804
4845
  asset: "oidn-weights",
4805
4846
  cause: String(e.error?.message ?? e.error)
4806
- }), this.denoiser.addEventListener("start", this._denoiserStartHandler), this.denoiser.addEventListener("end", this._denoiserEndHandler), this.denoiser.addEventListener("tileProgress", this._denoiserTileHandler), this.denoiser.addEventListener("error", this._denoiserErrorHandler);
4847
+ }), 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({
4848
+ type: j.DENOISER_LOADING,
4849
+ loading: e.type === "loading"
4850
+ });
4851
+ for (let e of [
4852
+ "loading",
4853
+ "loaded",
4854
+ "error"
4855
+ ]) this.denoiser.addEventListener(e, this._denoiserLoadHandler);
4856
+ this.denoiser.state?.isLoading && this.dispatchEvent({
4857
+ type: j.DENOISER_LOADING,
4858
+ loading: !0
4859
+ });
4807
4860
  }
4808
4861
  setupUpscaler() {
4809
4862
  if (!this.upscalerCanvas) return;
4810
4863
  let e = this._stages.pathTracer;
4811
- this.upscaler = new As(this.upscalerCanvas, this.renderer, {
4864
+ this.upscaler = new Ms(this.upscalerCanvas, this.renderer, {
4812
4865
  scaleFactor: ei.upscalerScale || 2,
4813
4866
  quality: ei.upscalerQuality || "fast",
4814
4867
  getSourceCanvas: () => this.renderer.domElement,
@@ -4884,8 +4937,8 @@ var ks = {
4884
4937
  get holdsWhileMoving() {
4885
4938
  if (!this._stages.pathTracer?.viewIsChanging || !this.continuousDenoise || this._cadenceSuspended || !this.denoiser?.enabled || this._movingHopeless) return !1;
4886
4939
  let e = this.movingCostMs, t = this._movingDenoiseMs.length;
4887
- e > Is * Rs && (this._movingHopeless = !0, this._syncGBufferStages());
4888
- let n = !this._movingHopeless && (t < 2 || e <= Is);
4940
+ e > Rs * Bs && (this._movingHopeless = !0, this._syncGBufferStages());
4941
+ let n = !this._movingHopeless && (t < 2 || e <= Rs);
4889
4942
  return this._holdWhileMoving = (this._holdWhileMoving === null || this._holdWhileMoving) && n, this._holdWhileMoving;
4890
4943
  }
4891
4944
  skipsTrace() {
@@ -4902,7 +4955,7 @@ var ks = {
4902
4955
  this.pipeline?.context?.removeTexture("oidn:output"), this.denoiser?.invalidateOutput();
4903
4956
  }
4904
4957
  _checkHeldFrameHealthy() {
4905
- !this.denoiser?.hasOutput || this._failedRefreshes < zs || this._unpublishOutput();
4958
+ !this.denoiser?.hasOutput || this._failedRefreshes < Vs || this._unpublishOutput();
4906
4959
  }
4907
4960
  tickContinuousDenoise(e) {
4908
4961
  let t = this.denoiser;
@@ -4912,12 +4965,12 @@ var ks = {
4912
4965
  if (!n) this._holdWhileMoving = null, this._movingDenoiseMs.length = 0;
4913
4966
  else if (!this.holdsWhileMoving) return !1;
4914
4967
  if (t.state.isDenoising || t.state.isLoading || !n && e <= this._lastCadenceSamples) return !1;
4915
- let r = performance.now(), i = n ? Fs : this._lastCadenceSamples === 0 ? Ps : Ns, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
4968
+ let r = performance.now(), i = n ? Ls : this._lastCadenceSamples === 0 ? Is : Fs, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
4916
4969
  if (r - this._lastCadenceAt < a) return !1;
4917
- this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > Ms && (this._cadenceDowngraded = !0);
4970
+ this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > Ps && (this._cadenceDowngraded = !0);
4918
4971
  let o = this._cadenceDowngraded ? this.previewQuality() : this._finalQuality;
4919
4972
  return t.quality !== o && t.updateQuality(o), t.start({ continuous: !0 }).then((e) => {
4920
- this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > Ls && this._movingDenoiseMs.shift());
4973
+ this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > zs && this._movingDenoiseMs.shift());
4921
4974
  }), !0;
4922
4975
  }
4923
4976
  previewQuality() {
@@ -4959,7 +5012,7 @@ var ks = {
4959
5012
  r && (this._ensureHistory().merge(r, t.frameCount, this._historyCameraNow(), {
4960
5013
  commit: !0,
4961
5014
  keepHistory: !this._historyDirty && !n,
4962
- historyScale: Vs(t.frameCount)
5015
+ historyScale: Us(t.frameCount)
4963
5016
  }), this._historyDirty = !1);
4964
5017
  }
4965
5018
  afterReset() {
@@ -5001,9 +5054,9 @@ var ks = {
5001
5054
  let e = this._stages.pathTracer, t = this._history;
5002
5055
  if (!t?.valid || this._historyDirty || !this.historyActive || e.isComplete || e.resetCount !== this._knownResetCount || t.width !== this._lastRenderWidth || t.height !== this._lastRenderHeight) return null;
5003
5056
  if (e.frameCount <= 1) return t.textures;
5004
- if (e.frameCount >= Bs) return null;
5057
+ if (e.frameCount >= Hs) return null;
5005
5058
  let n = this._historyInputs();
5006
- return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Vs(e.frameCount) }) : null;
5059
+ return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Us(e.frameCount) }) : null;
5007
5060
  }
5008
5061
  _historyInputs() {
5009
5062
  let e = this._stages.pathTracer, t = this.pipeline?.context, n = this.renderer?.backend;
@@ -5028,7 +5081,7 @@ var ks = {
5028
5081
  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 === Ae.orthographic, t;
5029
5082
  }
5030
5083
  _ensureHistory() {
5031
- return this._history ??= new Cs(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
5084
+ return this._history ??= new Ts(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
5032
5085
  }
5033
5086
  _releaseHistory() {
5034
5087
  this._history?.dispose(), this._history = null, this._historyDirty = !0, this._movedPlacements.clear();
@@ -5049,67 +5102,76 @@ var ks = {
5049
5102
  this._neuralUpscaler?.dispose(), this._neuralUpscaler = null, this._superResModule?.releaseDenoisedReader();
5050
5103
  }
5051
5104
  setNeuralRendering(e, t = null) {
5105
+ let n = this.neuralRendering !== !!e;
5052
5106
  this.neuralRendering = !!e, t && (this.neuralRenderingSettings = {
5053
5107
  ...this.neuralRenderingSettings,
5054
5108
  ...t
5055
- }), this.neuralRendering || (this._releaseNeuralRetouch(), this._restoreRenderDisplay());
5109
+ }), this.neuralRendering || (this._releaseNeuralRetouch(), this._restoreRenderDisplay()), n && this._redoPostPasses();
5056
5110
  }
5057
5111
  _releaseNeuralRetouch() {
5058
5112
  this._retouch?.dispose(), this._retouch = null;
5059
5113
  }
5060
5114
  async _runNeuralPost(e) {
5061
- let t = this.upscaler?.enabled && this.upscalerBackend === "neural", n = this.neuralRendering;
5115
+ let t = this.upscaler?.enabled && this.upscalerBackend === "neural", n = this.neuralRendering, r = this.upscaler?.enabled && !t;
5062
5116
  if (!(!t && !n) && !this._neuralPostBusy) {
5063
5117
  if (!this.upscalerCanvas) {
5064
5118
  this._recordNoOverlayCanvas("neural");
5065
5119
  return;
5066
5120
  }
5067
5121
  if (!this.pipeline?.context?.getTexture("oidn:output")) {
5068
- js.warn("neural pass skipped: no denoised picture — it needs OIDN");
5122
+ Ns.warn("neural pass skipped: no denoised picture — it needs OIDN");
5069
5123
  return;
5070
5124
  }
5071
5125
  this._neuralPostBusy = !0, this.dispatchEvent({ type: j.UPSCALING_START });
5072
5126
  try {
5073
- let r = await import("./NeuralSuperRes-DV5TtURP.js").then((e) => e.t);
5074
- this._superResModule = r;
5075
- let i = n ? await import("./NeuralRetouch-C3Q2XqbF.js").then((e) => e.t) : null, a = this.denoiser?._outTexSize, o = (a?.width ?? 0) * (a?.height ?? 0), s = n && o <= i.RETOUCH_MAX_PIXELS;
5076
- if (n && !s && (js.warn(`Neural rendering skipped: the render is ${(o / 1e6).toFixed(1)} MP, above the ${(i.RETOUCH_MAX_PIXELS / 1e6).toFixed(1)} MP the pass survives.` + (t ? " The upscale still ran." : "")), this._releaseNeuralRetouch()), !t && !s) return;
5077
- let c = {
5127
+ let i = await import("./NeuralSuperRes-ChCiiilS.js").then((e) => e.t);
5128
+ this._superResModule = i;
5129
+ let a = n ? await import("./NeuralRetouch-DFI4pOjO.js").then((e) => e.t) : null, o = this.denoiser?._outTexSize, s = (o?.width ?? 0) * (o?.height ?? 0), c = n && s <= a.RETOUCH_MAX_PIXELS;
5130
+ if (n && !c && (Ns.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) {
5131
+ r && !this._postCancelled && await this.upscaler.start();
5132
+ return;
5133
+ }
5134
+ let l = {
5078
5135
  exposure: this._getEffectiveExposure(),
5079
5136
  toneMapping: this._getToneMapping(),
5080
5137
  saturation: this._getSaturation?.() ?? 1,
5081
5138
  gain: this._getDisplayGain?.() ?? null
5082
- }, l = await r.readDenoisedHalf(this.denoiser);
5083
- t && (this._neuralUpscaler && (this._neuralUpscaler.inputWidth !== l.width || this._neuralUpscaler.inputHeight !== l.height) && this._releaseNeuralUpscaler(), this._neuralUpscaler ||= await r.NeuralSuperRes.create({
5084
- width: l.width,
5085
- height: l.height
5139
+ }, u = await i.readDenoisedHalf(this.denoiser);
5140
+ t && (this._neuralUpscaler && (this._neuralUpscaler.inputWidth !== u.width || this._neuralUpscaler.inputHeight !== u.height) && this._releaseNeuralUpscaler(), this._neuralUpscaler ||= await i.NeuralSuperRes.create({
5141
+ width: u.width,
5142
+ height: u.height
5086
5143
  }));
5087
- let u = l;
5088
- if (s) {
5089
- let e = await i.enhanceFrame({
5090
- source: u,
5144
+ let d = u;
5145
+ if (c) {
5146
+ let e = await a.enhanceFrame({
5147
+ source: d,
5091
5148
  settings: this.neuralRenderingSettings,
5092
5149
  instance: this._retouch,
5093
- exposure: c.exposure,
5094
- tone: t ? null : c
5150
+ exposure: l.exposure,
5151
+ tone: t ? null : l
5095
5152
  });
5096
- this._retouch = e.instance, u = e;
5153
+ this._retouch = e.instance, d = e;
5097
5154
  }
5098
- if (t && (u = await this._neuralUpscaler.upscaleToRGBA8(u, c)), !e()) {
5155
+ if (t && (d = await this._neuralUpscaler.upscaleToRGBA8(d, l)), !e()) {
5099
5156
  this.dropDisplay();
5100
5157
  return;
5101
5158
  }
5102
- if (r.presentRGBA8(this.upscalerCanvas, u.rgba8, u.width, u.height), !e()) {
5159
+ if (this._postRedo || this._postCancelled) return;
5160
+ if (r) {
5161
+ await this.upscaler.start(new ImageData(d.rgba8, d.width, d.height));
5162
+ return;
5163
+ }
5164
+ if (i.presentRGBA8(this.upscalerCanvas, d.rgba8, d.width, d.height), !e()) {
5103
5165
  this.dropDisplay();
5104
5166
  return;
5105
5167
  }
5106
5168
  this.mainCanvas && (this.mainCanvas.style.opacity = "0"), this.dispatchEvent({
5107
5169
  type: j.RESOLUTION_CHANGED,
5108
- width: u.width,
5109
- height: u.height
5170
+ width: d.width,
5171
+ height: d.height
5110
5172
  });
5111
5173
  } catch (e) {
5112
- js.warn("neural pass failed", e);
5174
+ Ns.warn("neural pass failed", e);
5113
5175
  } finally {
5114
5176
  this._neuralPostBusy = !1, this.dispatchEvent({ type: j.UPSCALING_END });
5115
5177
  }
@@ -5127,16 +5189,22 @@ var ks = {
5127
5189
  let t = await e.start();
5128
5190
  return t && this._onDisplayRefresh?.(), t && e.hasOutput;
5129
5191
  }
5192
+ _runPostPasses(e) {
5193
+ this._postIsStillComplete = e, this._postCancelled = !1, this.neuralRendering || this.upscaler?.enabled && this.upscalerBackend === "neural" ? this._postRun = this._runNeuralPost(e) : this._postRun = this.upscaler?.enabled ? this.upscaler.start() : null;
5194
+ }
5195
+ _redoPostPasses() {
5196
+ let e = this._postIsStillComplete;
5197
+ !e?.() || this._postRedo || (this.upscaler?.abort(), this._postCancelled = !1, this._postRedo = Promise.resolve(this._postRun).catch(() => {}).then(() => {
5198
+ this._postRedo = null, !(this._postCancelled || this._postIsStillComplete !== e || !e()) && (this._restoreRenderDisplay(), this._runPostPasses(e));
5199
+ }));
5200
+ }
5201
+ cancelPostPasses() {
5202
+ this._postCancelled = !0, this.upscaler?.abort(), this._restoreRenderDisplay(), this.dispatchEvent({ type: j.UPSCALING_END });
5203
+ }
5130
5204
  onRenderComplete({ isStillComplete: e }) {
5131
- this._cleanupCompletionListener();
5205
+ this._cleanupCompletionListener(), this._postIsStillComplete = null;
5132
5206
  let t = this.finalDenoise ? "final" : this.continuousDenoise ? "refresh" : null, n = () => {
5133
- if (this.denoiser?.removeEventListener("end", n), this._pendingStartUpscaler = null, e()) {
5134
- if (t && this._onDisplayRefresh?.(), this.neuralRendering || this.upscaler?.enabled && this.upscalerBackend === "neural") {
5135
- this._runNeuralPost(e);
5136
- return;
5137
- }
5138
- this.upscaler?.enabled && this.upscaler.start();
5139
- }
5207
+ this.denoiser?.removeEventListener("end", n), this._pendingStartUpscaler = null, e() && (t && this._onDisplayRefresh?.(), this._runPostPasses(e));
5140
5208
  };
5141
5209
  if (!t) {
5142
5210
  n();
@@ -5153,7 +5221,7 @@ var ks = {
5153
5221
  } else r();
5154
5222
  }
5155
5223
  abort(e, { keepDisplay: t = !1 } = {}) {
5156
- this._cleanupCompletionListener(), this._restoreRenderDisplay(), e && e !== this.mainCanvas && (e.style.opacity = "1"), this.upscaler && this.upscaler.abort();
5224
+ this._cleanupCompletionListener(), this._postIsStillComplete = null, this._restoreRenderDisplay(), e && e !== this.mainCanvas && (e.style.opacity = "1"), this.upscaler && this.upscaler.abort();
5157
5225
  let n = !!this._stages.pathTracer?.viewIsChanging, r = t && this.continuousDenoise && !this._cadenceSuspended && !!this.denoiser?.hasOutput && (!n || this.holdsWhileMoving);
5158
5226
  this.denoiser && !r && (this.denoiser.enabled && this.denoiser.abort(), this._unpublishOutput()), this._resetCadence();
5159
5227
  }
@@ -5161,7 +5229,21 @@ var ks = {
5161
5229
  this._unpublishOutput(), this._restoreRenderDisplay(), this._historyDirty = !0;
5162
5230
  }
5163
5231
  dispose() {
5164
- this._cleanupCompletionListener(), this._releaseNeuralUpscaler(), this._releaseNeuralRetouch(), this._unpublishOutput(), this._releaseHistory(), this.denoiser &&= (this._denoiserStartHandler && this.denoiser.removeEventListener("start", this._denoiserStartHandler), this._denoiserEndHandler && this.denoiser.removeEventListener("end", this._denoiserEndHandler), this._denoiserTileHandler && this.denoiser.removeEventListener("tileProgress", this._denoiserTileHandler), this._denoiserErrorHandler && this.denoiser.removeEventListener("error", this._denoiserErrorHandler), this.denoiser.dispose(), null), this.upscaler && (this._upscalerResChangedHandler && this.upscaler.removeEventListener("resolution_changed", this._upscalerResChangedHandler), this._upscalerStartHandler && this.upscaler.removeEventListener("start", this._upscalerStartHandler), this._upscalerProgressHandler && this.upscaler.removeEventListener("progress", this._upscalerProgressHandler), this._upscalerEndHandler && this.upscaler.removeEventListener("end", this._upscalerEndHandler), this.upscaler.dispose(), this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null), this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._denoiserTileHandler = null, this._denoiserErrorHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this._getExposure = null, this._getSaturation = null, this._getDisplayGain = null, this._issues = null, this.upscalerCanvas?.parentNode && (this.upscalerCanvas.parentNode.removeChild(this.upscalerCanvas), this.upscalerCanvas = null);
5232
+ if (this._cleanupCompletionListener(), this._postIsStillComplete = null, this._releaseNeuralUpscaler(), this._releaseNeuralRetouch(), this._unpublishOutput(), this._releaseHistory(), this.denoiser) {
5233
+ if (this._denoiserStartHandler && this.denoiser.removeEventListener("start", this._denoiserStartHandler), this._denoiserEndHandler && this.denoiser.removeEventListener("end", this._denoiserEndHandler), this._denoiserTileHandler && this.denoiser.removeEventListener("tileProgress", this._denoiserTileHandler), this._denoiserErrorHandler && this.denoiser.removeEventListener("error", this._denoiserErrorHandler), this._denoiserLoadHandler) {
5234
+ for (let e of [
5235
+ "loading",
5236
+ "loaded",
5237
+ "error"
5238
+ ]) this.denoiser.removeEventListener(e, this._denoiserLoadHandler);
5239
+ this.denoiser.state?.isLoading && this.dispatchEvent({
5240
+ type: j.DENOISER_LOADING,
5241
+ loading: !1
5242
+ });
5243
+ }
5244
+ this.denoiser.dispose(), this.denoiser = null;
5245
+ }
5246
+ this.upscaler && (this._upscalerResChangedHandler && this.upscaler.removeEventListener("resolution_changed", this._upscalerResChangedHandler), this._upscalerStartHandler && this.upscaler.removeEventListener("start", this._upscalerStartHandler), this._upscalerProgressHandler && this.upscaler.removeEventListener("progress", this._upscalerProgressHandler), this._upscalerEndHandler && this.upscaler.removeEventListener("end", this._upscalerEndHandler), this.upscaler.dispose(), this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = 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, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this._getExposure = null, this._getSaturation = null, this._getDisplayGain = null, this._issues = null, this.upscalerCanvas?.parentNode && (this.upscalerCanvas.parentNode.removeChild(this.upscalerCanvas), this.upscalerCanvas = null);
5165
5247
  }
5166
5248
  setOverlayManager(e) {
5167
5249
  this._overlayManager = e;
@@ -5215,7 +5297,8 @@ var ks = {
5215
5297
  this._setTileHelper(e);
5216
5298
  }
5217
5299
  setUpscalerEnabled(e) {
5218
- this.upscaler ? this.upscaler.enabled = e : e && this._recordNoOverlayCanvas("upscaler"), e || this._restoreRenderDisplay();
5300
+ let t = !!this.upscaler && this.upscaler.enabled !== !!e;
5301
+ this.upscaler ? this.upscaler.enabled = e : e && this._recordNoOverlayCanvas("upscaler"), e || this._restoreRenderDisplay(), t && this._redoPostPasses();
5219
5302
  }
5220
5303
  setUpscalerScaleFactor(e) {
5221
5304
  this.upscaler?.setScaleFactor(e);
@@ -5275,7 +5358,7 @@ var ks = {
5275
5358
  let t = qr[e];
5276
5359
  t && (this._stages.asvgf?.updateParameters(t), this._stages.bilateralFilter?.updateParameters(t), this._stages.variance && t.varianceBoost !== void 0 && (this._stages.variance.varianceBoost.value = t.varianceBoost));
5277
5360
  }
5278
- }, Us = class {
5361
+ }, Gs = class {
5279
5362
  constructor() {
5280
5363
  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;
5281
5364
  }
@@ -5299,7 +5382,7 @@ var ks = {
5299
5382
  dispose() {
5300
5383
  this.visible = !1;
5301
5384
  }
5302
- }, Ws = class {
5385
+ }, Ks = class {
5303
5386
  constructor(e, t) {
5304
5387
  this.layer = "scene", this._enabled = !0, this._scene = e, this._camera = t, this._build([]);
5305
5388
  }
@@ -5337,11 +5420,11 @@ var ks = {
5337
5420
  this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
5338
5421
  }
5339
5422
  };
5340
- function Gs(e = !1) {
5423
+ function qs(e = !1) {
5341
5424
  let t = document.createElement("canvas");
5342
5425
  return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
5343
5426
  }
5344
- function Ks(e, t = Infinity) {
5427
+ function Js(e, t = Infinity) {
5345
5428
  let n = e?.getBoundingClientRect();
5346
5429
  if (!n || n.width === 0 || n.height === 0) return null;
5347
5430
  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);
@@ -5352,9 +5435,9 @@ function Ks(e, t = Infinity) {
5352
5435
  }
5353
5436
  //#endregion
5354
5437
  //#region src/managers/helpers/ViewOverlayRenderer.js
5355
- var qs = 4096, Js = class {
5438
+ var Ys = 4096, Xs = class {
5356
5439
  constructor() {
5357
- this.canvas = Gs(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
5440
+ this.canvas = qs(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
5358
5441
  }
5359
5442
  async init({ device: e, sizeSource: t }) {
5360
5443
  this._sizeSource = t;
@@ -5371,7 +5454,7 @@ var qs = 4096, Js = class {
5371
5454
  }
5372
5455
  syncSize() {
5373
5456
  if (!this.renderer) return;
5374
- let e = Ks(this._sizeSource, qs);
5457
+ let e = Js(this._sizeSource, Ys);
5375
5458
  !e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
5376
5459
  }
5377
5460
  begin() {
@@ -5383,18 +5466,18 @@ var qs = 4096, Js = class {
5383
5466
  dispose() {
5384
5467
  Pe(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
5385
5468
  }
5386
- }, Ys = Ke("overlay"), Xs = (e, t) => e.visible && e.layer === t && e.render, Zs = class {
5469
+ }, Zs = Ke("overlay"), Qs = (e, t) => e.visible && e.layer === t && e.render, $s = class {
5387
5470
  constructor(e) {
5388
- this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = Gs(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
5471
+ this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = qs(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
5389
5472
  }
5390
5473
  async initViewRenderer({ device: e, sizeSource: t }) {
5391
5474
  if (!(!e || !t)) try {
5392
- this._viewOverlay = await new Js().init({
5475
+ this._viewOverlay = await new Xs().init({
5393
5476
  device: e,
5394
5477
  sizeSource: t
5395
5478
  });
5396
5479
  } catch (e) {
5397
- Ys.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
5480
+ Zs.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
5398
5481
  }
5399
5482
  }
5400
5483
  gpuResources() {
@@ -5414,11 +5497,11 @@ var qs = 4096, Js = class {
5414
5497
  }
5415
5498
  setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
5416
5499
  this.setHelperScene(e);
5417
- let s = new Us();
5500
+ let s = new Gs();
5418
5501
  this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(j.RESOLUTION_CHANGED, (e) => {
5419
5502
  s.setRenderSize(e.width, e.height);
5420
5503
  }), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
5421
- let c = new Ws(t, this.camera);
5504
+ let c = new Ks(t, this.camera);
5422
5505
  this.register("outline", c);
5423
5506
  }
5424
5507
  _wireDenoiserTileEvents(e, t) {
@@ -5430,7 +5513,7 @@ var qs = 4096, Js = class {
5430
5513
  }));
5431
5514
  }
5432
5515
  register(e, t) {
5433
- this._helpers.has(e) && (Ys.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
5516
+ this._helpers.has(e) && (Zs.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
5434
5517
  }
5435
5518
  unregister(e) {
5436
5519
  let t = this._helpers.get(e);
@@ -5468,16 +5551,16 @@ var qs = 4096, Js = class {
5468
5551
  }
5469
5552
  _renderSceneLayer(e) {
5470
5553
  this._helperScene?.render(e, this.camera);
5471
- for (let t of this._helpers.values()) Xs(t, "scene") && t.render(e, this.camera);
5554
+ for (let t of this._helpers.values()) Qs(t, "scene") && t.render(e, this.camera);
5472
5555
  }
5473
5556
  _hasVisibleSceneOverlay() {
5474
5557
  if (this._helperScene?.isDrawing) return !0;
5475
- for (let e of this._helpers.values()) if (Xs(e, "scene")) return !0;
5558
+ for (let e of this._helpers.values()) if (Qs(e, "scene")) return !0;
5476
5559
  return !1;
5477
5560
  }
5478
5561
  refreshHUD() {
5479
5562
  let e = this._hudCanvas, t = this._hudCtx, n = !1;
5480
- for (let e of this._helpers.values()) if (Xs(e, "hud")) {
5563
+ for (let e of this._helpers.values()) if (Qs(e, "hud")) {
5481
5564
  n = !0;
5482
5565
  break;
5483
5566
  }
@@ -5486,10 +5569,10 @@ var qs = 4096, Js = class {
5486
5569
  return;
5487
5570
  }
5488
5571
  e.style.display !== "" && (e.style.display = "");
5489
- let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Ks(e) : null;
5572
+ let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Js(e) : null;
5490
5573
  if (a) {
5491
5574
  (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);
5492
- for (let e of this._helpers.values()) Xs(e, "hud") && e.render(t, r, i);
5575
+ for (let e of this._helpers.values()) Qs(e, "hud") && e.render(t, r, i);
5493
5576
  t.restore(), e.style.display !== "" && (e.style.display = "");
5494
5577
  }
5495
5578
  }
@@ -5500,7 +5583,7 @@ var qs = 4096, Js = class {
5500
5583
  };
5501
5584
  //#endregion
5502
5585
  //#region src/managers/AnimationManager.js
5503
- function Qs(e, t) {
5586
+ function ec(e, t) {
5504
5587
  let n = [...e].filter((t) => {
5505
5588
  for (let n = t.parent; n; n = n.parent) if (e.has(n)) return !1;
5506
5589
  return !0;
@@ -5509,7 +5592,7 @@ function Qs(e, t) {
5509
5592
  for (let e of n) e.traverse?.(() => i++);
5510
5593
  return i + n.length / 2 < r ? n : null;
5511
5594
  }
5512
- var $s = class extends fr {
5595
+ var tc = class extends fr {
5513
5596
  constructor() {
5514
5597
  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 $(), 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;
5515
5598
  }
@@ -5563,7 +5646,7 @@ var $s = class extends fr {
5563
5646
  visibility: i,
5564
5647
  cameras: [...s],
5565
5648
  nodes: a ? null : r,
5566
- roots: a ? null : Qs(r, t)
5649
+ roots: a ? null : ec(r, t)
5567
5650
  };
5568
5651
  }), this._allPlan = null, !this._rigid) return;
5569
5652
  this._slotOf = new Int32Array(this._meshes.length).fill(-1);
@@ -5582,7 +5665,7 @@ var $s = class extends fr {
5582
5665
  visibility: n,
5583
5666
  cameras: [...t],
5584
5667
  nodes: r,
5585
- roots: r ? Qs(r, this._mixerRoot) : null
5668
+ roots: r ? ec(r, this._mixerRoot) : null
5586
5669
  };
5587
5670
  }
5588
5671
  return this._allPlan;
@@ -5714,19 +5797,19 @@ var $s = class extends fr {
5714
5797
  dispose() {
5715
5798
  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;
5716
5799
  }
5717
- }, ec = new $(0, 0, -1), tc = (e) => {
5800
+ }, nc = new $(0, 0, -1), rc = (e) => {
5718
5801
  for (; e.parent;) e = e.parent;
5719
5802
  return e.isScene ? e : null;
5720
- }, nc = class {
5803
+ }, ic = class {
5721
5804
  constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
5722
5805
  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 $(), 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);
5723
5806
  }
5724
5807
  setMeshData(e) {
5725
5808
  this._meshes = e;
5726
- for (let e of this._moved) tc(e) || this._moved.delete(e);
5809
+ for (let e of this._moved) rc(e) || this._moved.delete(e);
5727
5810
  }
5728
5811
  get movedObjects() {
5729
- return [...this._moved].filter((e) => tc(e));
5812
+ return [...this._moved].filter((e) => rc(e));
5730
5813
  }
5731
5814
  noteMoved(e) {
5732
5815
  e && !e.isLight && this._moved.add(e);
@@ -5787,7 +5870,7 @@ var $s = class extends fr {
5787
5870
  }
5788
5871
  _syncLightAim(e) {
5789
5872
  let t = this._tempForward.copy(e.target.position).sub(e.position), n = t.length();
5790
- n > 1e-4 ? (e.quaternion.setFromUnitVectors(ec, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
5873
+ n > 1e-4 ? (e.quaternion.setFromUnitVectors(nc, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
5791
5874
  }
5792
5875
  _recomputeAndRefit() {
5793
5876
  if (!this._meshes || this._refitInFlight || !this._attached) return;
@@ -5823,7 +5906,7 @@ var $s = class extends fr {
5823
5906
  dispose() {
5824
5907
  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;
5825
5908
  }
5826
- }, rc = class {
5909
+ }, ac = class {
5827
5910
  constructor(e) {
5828
5911
  this.layer = "scene", this._transformManager = e, this._enabled = !0;
5829
5912
  }
@@ -5842,8 +5925,8 @@ var $s = class extends fr {
5842
5925
  dispose() {
5843
5926
  this._enabled = !1;
5844
5927
  }
5845
- }, ic = 1, ac = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5846
- function oc(e, t) {
5928
+ }, oc = 1, sc = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5929
+ function cc(e, t) {
5847
5930
  let n = [];
5848
5931
  for (; e && e !== t;) {
5849
5932
  let t = e.parent;
@@ -5852,12 +5935,12 @@ function oc(e, t) {
5852
5935
  }
5853
5936
  return e === t ? n : null;
5854
5937
  }
5855
- function sc(e, t) {
5938
+ function lc(e, t) {
5856
5939
  let n = e;
5857
5940
  for (let e of t) if (n = n?.children[e], !n) return null;
5858
5941
  return n;
5859
5942
  }
5860
- function cc(e) {
5943
+ function uc(e) {
5861
5944
  return {
5862
5945
  key: e.assetLoader?.sceneSourceKey ?? null,
5863
5946
  name: e.sceneModel?.name ?? null,
@@ -5865,7 +5948,7 @@ function cc(e) {
5865
5948
  materials: e.stages.pathTracer?.materialData.materialCount ?? 0
5866
5949
  };
5867
5950
  }
5868
- function lc(e) {
5951
+ function dc(e) {
5869
5952
  let t = /* @__PURE__ */ new Map();
5870
5953
  for (let n of e.sceneMeshes) {
5871
5954
  let e = n.userData?.materialIndex;
@@ -5873,7 +5956,7 @@ function lc(e) {
5873
5956
  }
5874
5957
  return t;
5875
5958
  }
5876
- function uc(e) {
5959
+ function fc(e) {
5877
5960
  if (!e) return null;
5878
5961
  let t = e.status(), n = t.activeView, r = t.config?.id ?? n?.configId ?? null;
5879
5962
  return {
@@ -5888,15 +5971,15 @@ function uc(e) {
5888
5971
  context: t.context ?? null
5889
5972
  };
5890
5973
  }
5891
- function dc(e) {
5892
- let t = e.meshScene, n = lc(e), r = [];
5974
+ function pc(e) {
5975
+ let t = e.meshScene, n = dc(e), r = [];
5893
5976
  return t.traverse((e) => {
5894
- e !== t && e.visible === !1 && r.push(oc(e, t));
5977
+ e !== t && e.visible === !1 && r.push(cc(e, t));
5895
5978
  }), {
5896
5979
  v: 1,
5897
5980
  engine: Be,
5898
5981
  savedAt: Date.now(),
5899
- scene: cc(e),
5982
+ scene: uc(e),
5900
5983
  appended: t.children.filter((t) => t !== e.sceneModel && t.userData?.__rayzeeSceneObject).map((e) => ({
5901
5984
  name: e.userData.__rayzeeName ?? e.name,
5902
5985
  url: e.userData.__rayzeeSourceUrl ?? null,
@@ -5904,7 +5987,7 @@ function dc(e) {
5904
5987
  })),
5905
5988
  settings: e.settings.serialize(),
5906
5989
  environment: e.environmentManager?.serialize() ?? null,
5907
- color: uc(e.color),
5990
+ color: fc(e.color),
5908
5991
  lights: e.lightManager.serialize(),
5909
5992
  cameras: e.cameraManager.serialize(),
5910
5993
  timeline: e.timeline?.serialize() ?? null,
@@ -5914,7 +5997,7 @@ function dc(e) {
5914
5997
  })),
5915
5998
  hidden: r,
5916
5999
  moved: (e.transformManager?.movedObjects ?? []).map((e) => ({
5917
- path: oc(e, t),
6000
+ path: cc(e, t),
5918
6001
  name: e.name,
5919
6002
  position: e.position.toArray(),
5920
6003
  quaternion: e.quaternion.toArray(),
@@ -5922,15 +6005,15 @@ function dc(e) {
5922
6005
  })).filter((e) => e.path)
5923
6006
  };
5924
6007
  }
5925
- function fc(e, t, n) {
6008
+ function mc(e, t, n) {
5926
6009
  let r = e[t];
5927
6010
  r?.copy && (n?.isColor || n?.isVector2 || n?.isVector3) ? r.copy(n) : e[t] = n, e.needsUpdate = !0;
5928
6011
  }
5929
- async function pc(e, t, n, r) {
6012
+ async function hc(e, t, n, r) {
5930
6013
  if (!t) return;
5931
6014
  let i = e.environmentManager;
5932
6015
  if (t.hdri && t.hdri !== i.hdriSource) {
5933
- let i = ac(t.hdri) ? t.hdri : await n({
6016
+ let i = sc(t.hdri) ? t.hdri : await n({
5934
6017
  kind: "environment",
5935
6018
  source: t.hdri
5936
6019
  });
@@ -5942,7 +6025,7 @@ async function pc(e, t, n, r) {
5942
6025
  }
5943
6026
  await i.restore(t);
5944
6027
  }
5945
- async function mc(e, t, n, r) {
6028
+ async function gc(e, t, n, r) {
5946
6029
  let i = e.color;
5947
6030
  if (!t || !i) return;
5948
6031
  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;
@@ -5967,7 +6050,7 @@ async function mc(e, t, n, r) {
5967
6050
  r("color", e.message, { config: t.config?.id ?? null });
5968
6051
  }
5969
6052
  }
5970
- async function hc(e, t, { resolve: n = async () => null } = {}) {
6053
+ async function _c(e, t, { resolve: n = async () => null } = {}) {
5971
6054
  if (t?.v !== 1) throw Error(`scene state version ${t?.v} is not 1`);
5972
6055
  let r = [], i = (e, t, n = {}) => r.push({
5973
6056
  section: e,
@@ -5988,11 +6071,11 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
5988
6071
  i("appended", e.message, { name: n.name });
5989
6072
  }
5990
6073
  }
5991
- let a = cc(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
6074
+ let a = uc(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
5992
6075
  s || i("scene", "the loaded scene is not the one saved: objects and materials left as loaded", {
5993
6076
  saved: o,
5994
6077
  now: a
5995
- }), await pc(e, t.environment, n, i), await mc(e, t.color, n, i);
6078
+ }), await hc(e, t.environment, n, i), await gc(e, t.color, n, i);
5996
6079
  let c = e.settings.restore(t.settings);
5997
6080
  c.length && i("settings", "not settings in this engine", { keys: c });
5998
6081
  let l = e.lightManager.restore(t.lights);
@@ -6001,7 +6084,7 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6001
6084
  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 });
6002
6085
  }
6003
6086
  if (s) {
6004
- let n = lc(e);
6087
+ let n = dc(e);
6005
6088
  for (let r of t.materials ?? []) {
6006
6089
  let t = n.get(r.index);
6007
6090
  if (!t || (t.name ?? "") !== r.name) {
@@ -6012,17 +6095,17 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6012
6095
  continue;
6013
6096
  }
6014
6097
  for (let [n, i] of Object.entries(r.props)) {
6015
- let a = me(i);
6016
- fc(t, n, a), e.setMaterialProperty(r.index, n, a);
6098
+ let a = xe(i);
6099
+ mc(t, n, a), e.setMaterialProperty(r.index, n, a);
6017
6100
  }
6018
6101
  }
6019
- let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => sc(r, e)).filter(Boolean));
6102
+ let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => lc(r, e)).filter(Boolean));
6020
6103
  r.traverse((e) => {
6021
6104
  e !== r && !e.isLight && (e.visible = !a.has(e));
6022
6105
  }), e.updateAllMeshVisibility();
6023
6106
  let o = [];
6024
6107
  for (let n of t.moved ?? []) {
6025
- let t = sc(r, n.path);
6108
+ let t = lc(r, n.path);
6026
6109
  if (!t || t.name !== n.name) {
6027
6110
  i("moved", "no such object", { name: n.name });
6028
6111
  continue;
@@ -6044,7 +6127,7 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6044
6127
  }
6045
6128
  //#endregion
6046
6129
  //#region src/PathTracerApp.js
6047
- var gc = Ke("engine"), _c = class extends w {
6130
+ var vc = Ke("engine"), yc = class extends w {
6048
6131
  constructor(e, t = {}) {
6049
6132
  super(e, t), this.setColorManagement($t), this.setStorageOpener(un), this.settings.define("interactionRenderScale", {
6050
6133
  default: .5,
@@ -6052,7 +6135,7 @@ var gc = Ke("engine"), _c = class extends w {
6052
6135
  this.stages?.pathTracer?.interactionMode && this._requestRenderScale(this._interactionRenderScale());
6053
6136
  },
6054
6137
  reset: !1
6055
- }), 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 $s();
6138
+ }), 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 tc();
6056
6139
  }
6057
6140
  _createCamera() {
6058
6141
  return this.cameraManager = new Co(this.canvas), this.timeline = new ko({
@@ -6061,7 +6144,7 @@ var gc = Ke("engine"), _c = class extends w {
6061
6144
  }), this.cameraManager.camera;
6062
6145
  }
6063
6146
  _initAssetPipeline() {
6064
- super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Ot), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-Cgyx5AF7.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Tt);
6147
+ super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Ot), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-iofnC8zB.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Tt);
6065
6148
  let e = () => {
6066
6149
  this.needsReset = !0, this.stages.pathTracer?.enterInteractionMode(), this.wake();
6067
6150
  };
@@ -6088,7 +6171,7 @@ var gc = Ke("engine"), _c = class extends w {
6088
6171
  super._initPipeline(), this.pipeline.eventBus.on("pathtracer:interactionStart", () => this._requestRenderScale(this._interactionRenderScale())), this.pipeline.eventBus.on("pathtracer:interactionEnd", () => this._applyRenderScale(1));
6089
6172
  }
6090
6173
  async _initManagers() {
6091
- await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-CY4jiz6a.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 $a({
6174
+ await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-Biv39eTA.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 $a({
6092
6175
  scene: this.meshScene,
6093
6176
  camera: this.camera,
6094
6177
  canvas: this.canvas,
@@ -6102,12 +6185,12 @@ var gc = Ke("engine"), _c = class extends w {
6102
6185
  }), this.iesManager = new Ho(this.stages.pathTracer, {
6103
6186
  onReset: () => this.reset(),
6104
6187
  issues: this._issues
6105
- }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new nc({
6188
+ }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new ic({
6106
6189
  camera: this.camera,
6107
6190
  canvas: this.canvas,
6108
6191
  orbitControls: this.cameraManager.controls,
6109
6192
  app: this
6110
- }), this.overlayManager.register("transform", new rc(this.transformManager))), this.interactionManager.setDependencies({
6193
+ }), this.overlayManager.register("transform", new ac(this.transformManager))), this.interactionManager.setDependencies({
6111
6194
  overlayManager: this.overlayManager,
6112
6195
  transformManager: this.transformManager,
6113
6196
  appDispatch: (e) => this.dispatchEvent(e),
@@ -6119,6 +6202,7 @@ var gc = Ke("engine"), _c = class extends w {
6119
6202
  this._addTrackedListener(this.cameraManager, j.CAMERA_SWITCHED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, j.AUTO_FOCUS_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, j.ORTHO_HEIGHT_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.timeline, j.TIMELINE_CHANGED, (e) => this.dispatchEvent(e)), this._forwardEvents(this.denoisingManager, [
6120
6203
  j.DENOISING_START,
6121
6204
  j.DENOISING_END,
6205
+ j.DENOISER_LOADING,
6122
6206
  j.UPSCALING_START,
6123
6207
  j.UPSCALING_PROGRESS,
6124
6208
  j.UPSCALING_END,
@@ -6174,7 +6258,7 @@ var gc = Ke("engine"), _c = class extends w {
6174
6258
  _beginFrame() {
6175
6259
  if (this.timeline.update(), this.cameraManager.updateControls(), this._updateExposure(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
6176
6260
  let e = this.animationManager.update();
6177
- e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => gc.error("animation refit error:", e)).finally(() => {
6261
+ e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => vc.error("animation refit error:", e)).finally(() => {
6178
6262
  this._animRefitInFlight = !1;
6179
6263
  }));
6180
6264
  }
@@ -6306,10 +6390,10 @@ var gc = Ke("engine"), _c = class extends w {
6306
6390
  return t && this._dispatchCamerasUpdated(), t;
6307
6391
  }
6308
6392
  exportSceneState() {
6309
- return dc(this);
6393
+ return pc(this);
6310
6394
  }
6311
6395
  async importSceneState(e, t) {
6312
- return await hc(this, e, t);
6396
+ return await _c(this, e, t);
6313
6397
  }
6314
6398
  _dispatchCamerasUpdated() {
6315
6399
  this.dispatchEvent({
@@ -6431,7 +6515,7 @@ var gc = Ke("engine"), _c = class extends w {
6431
6515
  this.transformManager?.setMeshData(this._sdf.meshes);
6432
6516
  }
6433
6517
  _setupDenoisingManager() {
6434
- this.denoisingManager = new Hs({
6518
+ this.denoisingManager = new Ws({
6435
6519
  renderer: this.renderer,
6436
6520
  mainCanvas: this.canvas,
6437
6521
  stages: {
@@ -6487,7 +6571,7 @@ var gc = Ke("engine"), _c = class extends w {
6487
6571
  }, n && this.stages.autoExposure?.noteViewChanged());
6488
6572
  }
6489
6573
  async _setupOverlayManager() {
6490
- this.overlayManager = new Zs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
6574
+ this.overlayManager = new $s(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
6491
6575
  helperScene: this._sceneHelpers,
6492
6576
  meshScene: this.meshScene,
6493
6577
  pipeline: this.pipeline,
@@ -6518,15 +6602,15 @@ var gc = Ke("engine"), _c = class extends w {
6518
6602
  };
6519
6603
  //#endregion
6520
6604
  //#region src/Headless.js
6521
- async function vc(e) {
6522
- let t = await bc(e);
6605
+ async function bc(e) {
6606
+ let t = await Sc(e);
6523
6607
  try {
6524
- return await yc(t, e);
6608
+ return await xc(t, e);
6525
6609
  } finally {
6526
6610
  t.dispose();
6527
6611
  }
6528
6612
  }
6529
- async function yc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
6613
+ async function xc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
6530
6614
  let o = e.denoisingManager;
6531
6615
  i && o && !o.finalDenoise && (o.applyOIDNEnabled(!0), o._syncGBufferStages());
6532
6616
  let s = await e.renderFrames(t, {
@@ -6545,8 +6629,8 @@ async function yc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire
6545
6629
  provenance: e.getProvenance()
6546
6630
  };
6547
6631
  }
6548
- async function bc({ 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 } = {}) {
6549
- let l = new _c(e ?? null, {
6632
+ async function Sc({ 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 } = {}) {
6633
+ let l = new yc(e ?? null, {
6550
6634
  autoResize: !1,
6551
6635
  strict: i,
6552
6636
  storage: s,
@@ -6560,7 +6644,7 @@ async function bc({ canvas: e, model: t = null, width: n = 1920, height: r = 108
6560
6644
  }
6561
6645
  //#endregion
6562
6646
  //#region src/managers/VideoRenderManager.js
6563
- var xc = class {
6647
+ var Cc = class {
6564
6648
  constructor(e) {
6565
6649
  this._app = e, this._cancelled = !1, this._rendering = !1;
6566
6650
  }
@@ -6674,4 +6758,4 @@ var xc = class {
6674
6758
  }
6675
6759
  };
6676
6760
  //#endregion
6677
- export { Tt as ARCHIVE_FORMATS, qr as ASVGF_QUALITY_PRESETS, ta as AUTO_EXPOSURE_DEFAULTS, _o as AUTO_FOCUS_DEFAULTS, $s as AnimationManager, Ye as BVH_LEAF_MARKERS, Co as CameraManager, Do as CameraTrack, $t as ColorManagement, Vt as DEFAULT_LUT_SIZE, Xt as DEFAULT_MAX_EV, qt as DEFAULT_MIN_EV, _e as DEFAULT_SUN_PATH, _t as DEFAULT_VIEW, at as DEFAULT_WORKING_SPACE, ei as DENOISER_DEFAULTS, C as DOWNLOAD_POLICY, Hs as DenoisingManager, f as DownloadCache, tt as ENGINE_AREAS, Ee as ENGINE_DEFAULTS, j as EngineEvents, $e as EngineIssueError, Ao as GoboManager, Ho as IESManager, Oe as INTERACTIVE_RENDER_CONFIG, Ze as ISSUE_CODES, Qe as ISSUE_SEVERITY, $a as InteractionManager, Xe as IssueLog, we as LEGACY_EVENT_NAMES, Da as LOCAL_EXPOSURE_DEFAULTS, qe as LOG_LEVELS, ee as LightManager, Ge as Logger, ze as MATERIAL_DEFAULTS, Te as MATERIAL_VALUE_SOURCE, Se as MAX_RESERVABLE_RENDER_SIZE, Fe as MAX_SCENE_BYTES, ht as MAX_TABLE_TRANSFORMS, Me as MemoryLedger, Xr as NRD_DEFAULTS, Jr as NRD_HIT_DIST_A, Yr as NRD_HIT_DIST_B, Zr as NRD_PRESET_KEYS, Qr as NRD_QUALITY_PRESETS, dt as OCIO_VIEW_BASE, Zs as OverlayManager, De as PRODUCTION_RENDER_CONFIG, _c as PathTracerApp, u as PipelineContext, _n as RETOUCH_DEFAULTS, vn as RETOUCH_MAX_PIXELS, gn as RETOUCH_RANGES, w as RayzeeRenderer, S as RenderPipeline, d as RenderSettings, O as RenderStage, Ne as SAFE_SCENE_BYTES, ic as SCENE_STATE_VERSION, x as SETTING_SOURCE, xe as SKY_DEFAULTS, mn as SR_MAX_INPUT, hn as SR_SCALE, et as STORAGE_KIND, ge as StageExecutionMode, ln as StorageManager, Je as TRIANGLE_DATA_LAYOUT, ko as TimelineManager, nc as TransformManager, Be as VERSION, ct as VIEW_TRANSFORMS, fe as VRAMTracker, xc as VideoRenderManager, on as acquireLock, Ut as addAllOcioViews, Ht as addOcioView, pt as addViewTransform, rn as applyMatrixRGBA8, tn as bakeLut, be as bufferBytes, It as buildOcioView, gt as buildToneMapWGSL, v as cachedObjectURL, Jt as canvasColorSpaceFor, yc as captureHeadless, y as clearBindingAuditFindings, Lt as clearInputOverrides, st as configureAssets, Ue as configurePlatform, Pt as convertColor, At as convertEncodedRGBA8, nn as convertPixelsF32, Ke as createLogger, de as dayOfYearForMonth, ke as deriveAlphaMode, b as describeAdapter, kt as displayCanvasFit, Re as estimateSceneBytes, Ft as extractMatrix, Et as extractSceneMetadata, T as fetchFile, xt as fileIdentity, Zt as findNativeLinearSpace, We as fmt, St as folderIdentity, me as fromPortable, it as getActiveColorManagement, ot as getAssetConfig, g as getBindingAuditFindings, He as getPlatform, ft as getRegistryVersion, vt as getViewTransform, Mt as hasColorSpace, sn as heldLockNames, bt as identityKey, Wt as isColorManaged, jt as isDataSpace, Yt as isDataTexture, Nt as linearToSrgb, Qt as listFileRules, zt as listInputOverrides, lt as listViewTransforms, Ct as localFolder, an as makeCpuSampler, Rt as measureBakeError, p as nameFromUrl, mt as onRegistryChange, bc as openHeadless, cn as openStorage, fn as openZip, wt as parseSceneMetadata, Ie as probeAddressSpace, dn as readZipDirectory, ut as removeViewTransform, vc as renderHeadless, pn as renderUpscaled, Kt as resolveInputSpace, yt as sameIdentity, rt as setActiveColorManagement, h as setBindingAudit, en as setInputOverride, Gt as srgbToLinear, pe as sunPosition, ve as textureBytes, Bt as textureInputSpace, ye as timeForSunElevation, ue as toPortable };
6761
+ export { Tt as ARCHIVE_FORMATS, qr as ASVGF_QUALITY_PRESETS, ta as AUTO_EXPOSURE_DEFAULTS, _o as AUTO_FOCUS_DEFAULTS, tc as AnimationManager, Ye as BVH_LEAF_MARKERS, Co as CameraManager, Do as CameraTrack, $t as ColorManagement, Vt as DEFAULT_LUT_SIZE, Xt as DEFAULT_MAX_EV, qt as DEFAULT_MIN_EV, ue as DEFAULT_SUN_PATH, _t as DEFAULT_VIEW, at as DEFAULT_WORKING_SPACE, ei as DENOISER_DEFAULTS, C as DOWNLOAD_POLICY, Ws as DenoisingManager, f as DownloadCache, tt as ENGINE_AREAS, Ee as ENGINE_DEFAULTS, j as EngineEvents, $e as EngineIssueError, Ao as GoboManager, Ho as IESManager, Oe as INTERACTIVE_RENDER_CONFIG, Ze as ISSUE_CODES, Qe as ISSUE_SEVERITY, $a as InteractionManager, Xe as IssueLog, we as LEGACY_EVENT_NAMES, Da as LOCAL_EXPOSURE_DEFAULTS, qe as LOG_LEVELS, ee as LightManager, Ge as Logger, ze as MATERIAL_DEFAULTS, Te as MATERIAL_VALUE_SOURCE, te as MAX_RESERVABLE_RENDER_SIZE, Fe as MAX_SCENE_BYTES, ht as MAX_TABLE_TRANSFORMS, Me as MemoryLedger, Xr as NRD_DEFAULTS, Jr as NRD_HIT_DIST_A, Yr as NRD_HIT_DIST_B, Zr as NRD_PRESET_KEYS, Qr as NRD_QUALITY_PRESETS, dt as OCIO_VIEW_BASE, $s as OverlayManager, De as PRODUCTION_RENDER_CONFIG, yc as PathTracerApp, u as PipelineContext, _n as RETOUCH_DEFAULTS, vn as RETOUCH_MAX_PIXELS, gn as RETOUCH_RANGES, w as RayzeeRenderer, S as RenderPipeline, d as RenderSettings, D as RenderStage, Ne as SAFE_SCENE_BYTES, oc as SCENE_STATE_VERSION, x as SETTING_SOURCE, fe as SKY_DEFAULTS, mn as SR_MAX_INPUT, hn as SR_SCALE, et as STORAGE_KIND, he as StageExecutionMode, ln as StorageManager, Je as TRIANGLE_DATA_LAYOUT, ko as TimelineManager, ic as TransformManager, Be as VERSION, ct as VIEW_TRANSFORMS, _e as VRAMTracker, Cc as VideoRenderManager, on as acquireLock, Ut as addAllOcioViews, Ht as addOcioView, pt as addViewTransform, rn as applyMatrixRGBA8, tn as bakeLut, ye as bufferBytes, It as buildOcioView, gt as buildToneMapWGSL, v as cachedObjectURL, Jt as canvasColorSpaceFor, xc as captureHeadless, y as clearBindingAuditFindings, Lt as clearInputOverrides, st as configureAssets, Ue as configurePlatform, Pt as convertColor, At as convertEncodedRGBA8, nn as convertPixelsF32, Ke as createLogger, ve as dayOfYearForMonth, ke as deriveAlphaMode, b as describeAdapter, kt as displayCanvasFit, Re as estimateSceneBytes, Ft as extractMatrix, Et as extractSceneMetadata, T as fetchFile, xt as fileIdentity, Zt as findNativeLinearSpace, We as fmt, St as folderIdentity, xe as fromPortable, it as getActiveColorManagement, ot as getAssetConfig, g as getBindingAuditFindings, He as getPlatform, ft as getRegistryVersion, vt as getViewTransform, Mt as hasColorSpace, sn as heldLockNames, bt as identityKey, Wt as isColorManaged, jt as isDataSpace, Yt as isDataTexture, Nt as linearToSrgb, Qt as listFileRules, zt as listInputOverrides, lt as listViewTransforms, Ct as localFolder, an as makeCpuSampler, Rt as measureBakeError, p as nameFromUrl, mt as onRegistryChange, Sc as openHeadless, cn as openStorage, fn as openZip, wt as parseSceneMetadata, Ie as probeAddressSpace, dn as readZipDirectory, ut as removeViewTransform, bc as renderHeadless, pn as renderUpscaled, Kt as resolveInputSpace, yt as sameIdentity, rt as setActiveColorManagement, h as setBindingAudit, en as setInputOverride, Gt as srgbToLinear, ge as sunPosition, me as textureBytes, Bt as textureInputSpace, pe as timeForSunElevation, Se as toPortable };