rayzee 11.5.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.
package/dist/rayzee.es.js CHANGED
@@ -1,9 +1,9 @@
1
- import { t as e } from "./BidirectionalIntegrator-CJay8tXK.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-Dd-Dit0v.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-Cldt0mXi.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--ta6moJu.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";
@@ -19,8 +19,8 @@ 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-BHxhYzlD.js";
23
- import { i as gn, n as _n, r as vn } from "./NeuralRetouch-KqGVPV7u.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() {
@@ -2657,7 +2657,7 @@ var $a = class extends fr {
2657
2657
  let n = {
2658
2658
  index: t,
2659
2659
  name: e.name ?? "",
2660
- effects: ue(e.userData?.__rayzeeEffects) ?? null
2660
+ effects: Se(e.userData?.__rayzeeEffects) ?? null
2661
2661
  };
2662
2662
  return t === 0 || !e.userData?.__rayzeeUserCamera ? n : {
2663
2663
  ...n,
@@ -2690,7 +2690,7 @@ var $a = class extends fr {
2690
2690
  for (let r of e.cameras ?? []) {
2691
2691
  if (r.user) {
2692
2692
  let e = r.orthographic ? new Er(...r.frustum, r.near, r.far) : new Dr(r.fov, r.aspect, r.near, r.far);
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 = 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);
2694
2694
  continue;
2695
2695
  }
2696
2696
  let e = this.cameras[r.index];
@@ -2698,7 +2698,7 @@ var $a = class extends fr {
2698
2698
  t.push(r.name);
2699
2699
  continue;
2700
2700
  }
2701
- 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));
2702
2702
  }
2703
2703
  this._userCameraCounter = this.cameras.filter((e) => e.userData?.__rayzeeUserCamera).length, this.currentCameraIndex = n.get(e.current) ?? 0;
2704
2704
  let r = e.defaultView;
@@ -3295,11 +3295,19 @@ function Uo(e) {
3295
3295
  }
3296
3296
  //#endregion
3297
3297
  //#region src/Passes/OIDNDenoiser.js
3298
- var Wo = Ke("oidn"), Go = 16, Ko = null;
3299
- async function qo() {
3300
- 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
+ };
3301
3305
  }
3302
- var Jo = {
3306
+ var Jo = null;
3307
+ async function Yo() {
3308
+ return Jo ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Jo;
3309
+ }
3310
+ var Xo = {
3303
3311
  QUALITY_MODELS: {
3304
3312
  fast: {
3305
3313
  model: "rt_hdr_alb_nrm_small",
@@ -3323,9 +3331,9 @@ var Jo = {
3323
3331
  oidnQuality: "fast",
3324
3332
  tileSize: 1024
3325
3333
  }
3326
- }, Yo = .18, Xo = 256, Zo = 256, Qo = `
3327
- const WG: u32 = ${Xo}u;
3328
- 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;
3329
3337
 
3330
3338
  @group(0) @binding(0) var<storage, read> col: array<vec4<f32>>;
3331
3339
  @group(0) @binding(1) var<storage, read_write> partials: array<f32>;
@@ -3344,17 +3352,18 @@ fn treeSum( lid: u32 ) {
3344
3352
  }
3345
3353
  }
3346
3354
 
3347
- @compute @workgroup_size(${Xo})
3355
+ @compute @workgroup_size(${Qo})
3348
3356
  fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
3349
3357
  @builtin(local_invocation_id) lid: vec3<u32>,
3350
3358
  @builtin(workgroup_id) wid: vec3<u32> ) {
3351
3359
 
3360
+ // x: frame pixels, y: frame width, z: buffer width, w: border. The border is not metered.
3352
3361
  let total = params.x;
3353
3362
  var sum = 0.0;
3354
3363
  var i = gid.x;
3355
3364
  loop {
3356
3365
  if ( i >= total ) { break; }
3357
- let c = col[ i ].xyz;
3366
+ let c = col[ ( i / params.y + params.w ) * params.z + i % params.y + params.w ].xyz;
3358
3367
  let lum = 0.212671 * c.r + 0.71516 * c.g + 0.072169 * c.b;
3359
3368
  sum = sum + log2( max( lum, 0.0 ) + 0.0001 );
3360
3369
  i = i + WG * GROUPS;
@@ -3367,7 +3376,7 @@ fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
3367
3376
  if ( lid.x == 0u ) { partials[ wid.x ] = sdata[ 0 ]; }
3368
3377
  }
3369
3378
 
3370
- @compute @workgroup_size(${Xo})
3379
+ @compute @workgroup_size(${Qo})
3371
3380
  fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
3372
3381
 
3373
3382
  var v = 0.0;
@@ -3377,19 +3386,19 @@ fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
3377
3386
  treeSum( lid.x );
3378
3387
 
3379
3388
  if ( lid.x == 0u ) {
3380
- let scale = ${Yo} / exp2( sdata[ 0 ] / f32( params.x ) );
3389
+ let scale = ${Zo} / exp2( sdata[ 0 ] / f32( params.x ) );
3381
3390
  // Mirrors the CPU guard: a non-finite or non-positive scale means no scaling at all.
3382
3391
  scaleOut[ 0 ] = select( 1.0, scale, scale > 0.0 && scale < 3.4e38 );
3383
3392
  }
3384
3393
  }
3385
- `, $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 = `
3386
3395
  struct UnpackParams {
3387
3396
  srcWidth: u32,
3388
3397
  tileX: u32,
3389
3398
  tileY: u32,
3390
3399
  tileW: u32,
3391
3400
  tileH: u32,
3392
- pad0: u32,
3401
+ border: u32,
3393
3402
  pad1: u32,
3394
3403
  pad2: u32,
3395
3404
  };
@@ -3400,32 +3409,39 @@ struct UnpackParams {
3400
3409
  @group(0) @binding(3) var<storage, read> inColor: array<vec4<f32>>;
3401
3410
  @group(0) @binding(4) var dst: texture_storage_2d<rgba16float, write>;
3402
3411
 
3403
- @compute @workgroup_size(${ns}, ${ns})
3412
+ @compute @workgroup_size(${is}, ${is})
3404
3413
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3405
3414
 
3406
3415
  if ( gid.x >= P.tileW || gid.y >= P.tileH ) { return; }
3407
3416
 
3408
3417
  let px = P.tileX + gid.x;
3409
3418
  let py = P.tileY + gid.y;
3410
- let si = py * P.srcWidth + px;
3419
+ let si = ( py + P.border ) * P.srcWidth + px + P.border;
3411
3420
 
3412
3421
  // scaleBuf is the autoexposure factor the input was multiplied by; dividing it out returns
3413
3422
  // the renderer's units. Alpha rides through from the path tracer so a transparent background
3414
3423
  // survives the denoise.
3415
3424
  textureStore( dst, vec2<u32>( px, py ), vec4<f32>( src[ si ].xyz / scaleBuf[ 0 ], inColor[ si ].w ) );
3416
3425
  }
3417
- `, as = 8, os = `
3426
+ `, ss = 8, cs = `
3418
3427
  @group(0) @binding(0) var src: texture_2d<f32>;
3419
3428
  @group(0) @binding(1) var<storage, read_write> dst: array<vec4<f32>>;
3420
- @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
+ }
3421
3435
 
3422
- @compute @workgroup_size(${as}, ${as})
3436
+ @compute @workgroup_size(${ss}, ${ss})
3423
3437
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3424
3438
 
3425
3439
  if ( gid.x >= size.x || gid.y >= size.y ) { return; }
3426
- 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 );
3427
3443
  }
3428
- `, ss = class extends fr {
3444
+ `, ls = class extends fr {
3429
3445
  constructor(e, t = {}) {
3430
3446
  if (super(), !e) throw Error("OIDNDenoiser requires a renderer");
3431
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 = {
@@ -3439,7 +3455,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3439
3455
  width: 0,
3440
3456
  height: 0
3441
3457
  }, this.config = {
3442
- ...Jo.DEFAULT_OPTIONS,
3458
+ ...Xo.DEFAULT_OPTIONS,
3443
3459
  ...t
3444
3460
  }, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
3445
3461
  isDenoising: !1,
@@ -3460,7 +3476,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3460
3476
  }
3461
3477
  }
3462
3478
  expectsCleanAux(e = this.quality) {
3463
- let { QUALITY_MODELS: t } = Jo;
3479
+ let { QUALITY_MODELS: t } = Xo;
3464
3480
  return (t[e] || t.balance).cleanAux;
3465
3481
  }
3466
3482
  getRuntimeInfo() {
@@ -3475,8 +3491,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3475
3491
  _resolveTileSize() {
3476
3492
  let e = Math.max(this._renderWidth, this._renderHeight);
3477
3493
  if (!e) return this.maxTileSize;
3478
- let t = Math.ceil(e / Go) * Go;
3479
- 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);
3480
3499
  }
3481
3500
  _setupUNetDenoiser() {
3482
3501
  return this.state.isLoading ? (this._reloadPending = !0, Promise.resolve()) : (this._loading = this._loadUNet(), this._loading);
@@ -3514,9 +3533,9 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3514
3533
  let n;
3515
3534
  if (this.backendParamsGetter) {
3516
3535
  let e = this.backendParamsGetter();
3517
- 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;
3518
3537
  }
3519
- this.unet = await (await qo())(await this._fetchWeights(e), n, {
3538
+ this.unet = await (await Yo())(await this._fetchWeights(e), n, {
3520
3539
  aux: !0,
3521
3540
  hdr: !0,
3522
3541
  maxTileSize: t,
@@ -3528,14 +3547,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3528
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;
3529
3548
  }
3530
3549
  _generateTzaUrl() {
3531
- let { oidnWeightsBaseUrl: e } = ot(), { QUALITY_MODELS: t } = Jo;
3550
+ let { oidnWeightsBaseUrl: e } = ot(), { QUALITY_MODELS: t } = Xo;
3532
3551
  return `${e}${(t[this.quality] || t.balance).model}.tza`;
3533
3552
  }
3534
3553
  async updateConfiguration(e) {
3535
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());
3536
3555
  }
3537
3556
  async updateQuality(e) {
3538
- 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(", ")}`);
3539
3558
  await this.updateConfiguration({ oidnQuality: e });
3540
3559
  }
3541
3560
  async start({ continuous: e = !1 } = {}) {
@@ -3570,88 +3589,73 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3570
3589
  if (!r?.color) return Wo.warn("GPU textures not ready yet"), !1;
3571
3590
  let i = this.gpuDevice;
3572
3591
  if (!i) return Wo.warn("gpuDevice not available"), !1;
3573
- 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, {
3574
3595
  x: 0,
3575
3596
  y: 0,
3576
3597
  width: t,
3577
3598
  height: n
3578
3599
  }, !1);
3579
- let a = {
3580
- color: {
3581
- data: this._gpuInputBuffers.color,
3582
- width: t,
3583
- height: n
3584
- },
3585
- albedo: {
3586
- data: this._gpuInputBuffers.albedo,
3587
- width: t,
3588
- height: n
3589
- },
3590
- normal: {
3591
- data: this._gpuInputBuffers.normal,
3592
- width: t,
3593
- height: n
3594
- }
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)
3595
3608
  };
3596
- return this._executeWithAbortGPU(a, e);
3609
+ return this._executeWithAbortGPU(s, e);
3597
3610
  }
3598
3611
  _copyInputs(e, t, n, r) {
3599
- 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) => {
3600
- o ? (o.setBindGroup(0, e.createBindGroup({
3601
- layout: this._packLayout,
3602
- entries: [
3603
- {
3604
- binding: 0,
3605
- resource: t.createView()
3606
- },
3607
- {
3608
- binding: 1,
3609
- resource: { buffer: s }
3610
- },
3611
- {
3612
- binding: 2,
3613
- resource: { buffer: this._packParams }
3614
- }
3615
- ]
3616
- })), o.dispatchWorkgroups(Math.ceil(n / as), Math.ceil(r / as))) : i.copyTextureToBuffer({
3617
- texture: t,
3618
- mipLevel: 0
3619
- }, {
3620
- buffer: s,
3621
- offset: 0,
3622
- bytesPerRow: a,
3623
- rowsPerImage: r
3624
- }, {
3625
- width: n,
3626
- height: r,
3627
- depthOrArrayLayers: 1
3628
- });
3629
- };
3630
- 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()]);
3631
3635
  }
3632
3636
  _ensureGPUInputBuffers(e, t) {
3633
3637
  let { width: n, height: r } = this._gpuInputBufferSize;
3634
3638
  if (n === e && r === t && this._gpuInputBuffers.color) return;
3635
3639
  this._destroyGPUInputBuffers();
3636
- 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;
3637
3641
  this._gpuInputBuffers.color = i.createBuffer({
3638
3642
  label: "oidn-in-color",
3639
- size: a,
3640
- usage: o
3643
+ size: o,
3644
+ usage: s
3641
3645
  }), this._gpuInputBuffers.albedo = i.createBuffer({
3642
3646
  label: "oidn-in-albedo",
3643
- size: a,
3644
- usage: o
3647
+ size: o,
3648
+ usage: s
3645
3649
  }), this._gpuInputBuffers.normal = i.createBuffer({
3646
3650
  label: "oidn-in-normal",
3647
- size: a,
3648
- usage: o
3651
+ size: o,
3652
+ usage: s
3649
3653
  }), this._gpuInputBufferSize = {
3650
3654
  width: e,
3651
3655
  height: t
3652
3656
  };
3653
3657
  }
3654
- _beginPack(e, t, n, r) {
3658
+ _beginPack(e, t, n, r, i) {
3655
3659
  this._packPipeline ||= (this._packLayout = e.createBindGroupLayout({
3656
3660
  label: "oidn-pack",
3657
3661
  entries: [
@@ -3677,17 +3681,22 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3677
3681
  compute: {
3678
3682
  module: e.createShaderModule({
3679
3683
  label: "oidn-pack",
3680
- code: os
3684
+ code: cs
3681
3685
  }),
3682
3686
  entryPoint: "main"
3683
3687
  }
3684
- })), this._packParams || (this._packParams = e.createBuffer({
3688
+ })), this._packParams ??= e.createBuffer({
3685
3689
  label: "oidn-pack-size",
3686
- size: 8,
3690
+ size: 16,
3687
3691
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3688
- }), e.queue.writeBuffer(this._packParams, 0, new Uint32Array([n, r])));
3689
- let i = t.beginComputePass({ label: "oidn-pack" });
3690
- 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;
3691
3700
  }
3692
3701
  _destroyGPUInputBuffers() {
3693
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 = {
@@ -3730,7 +3739,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3730
3739
  });
3731
3740
  let t = e.createShaderModule({
3732
3741
  label: "oidn-autoexposure",
3733
- code: Qo
3742
+ code: es
3734
3743
  }), n = e.createPipelineLayout({ bindGroupLayouts: [this._lumLayout] });
3735
3744
  this._lumReducePipeline = e.createComputePipeline({
3736
3745
  label: "oidn-autoexposure-reduce",
@@ -3754,7 +3763,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3754
3763
  compute: {
3755
3764
  module: e.createShaderModule({
3756
3765
  label: "oidn-color-scale",
3757
- code: $o
3766
+ code: ts
3758
3767
  }),
3759
3768
  entryPoint: "main"
3760
3769
  }
@@ -3764,7 +3773,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3764
3773
  compute: {
3765
3774
  module: e.createShaderModule({
3766
3775
  label: "oidn-output-unpack",
3767
- code: is
3776
+ code: os
3768
3777
  }),
3769
3778
  entryPoint: "main"
3770
3779
  }
@@ -3774,7 +3783,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3774
3783
  size: 4
3775
3784
  }), this._lumPartials = e.createBuffer({
3776
3785
  label: "oidn-autoexposure-partials",
3777
- size: Zo * 4,
3786
+ size: $o * 4,
3778
3787
  usage: GPUBufferUsage.STORAGE
3779
3788
  }), this._lumParams = e.createBuffer({
3780
3789
  label: "oidn-autoexposure-params",
@@ -3813,26 +3822,27 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3813
3822
  }]
3814
3823
  }), !0;
3815
3824
  }
3816
- _computeInputScale(e, t) {
3825
+ _computeInputScale(e, t, n) {
3817
3826
  if (!this._ensureScalePipelines(e)) return;
3818
3827
  if (globalThis.__OIDN_NO_INPUT_SCALE) {
3819
3828
  e.queue.writeBuffer(this._inputScaleBuffer, 0, new Float32Array([1]));
3820
3829
  return;
3821
3830
  }
3831
+ let r = qo(t, n);
3822
3832
  e.queue.writeBuffer(this._lumParams, 0, new Uint32Array([
3833
+ t * n,
3823
3834
  t,
3824
- 0,
3825
- 0,
3826
- 0
3835
+ r.width,
3836
+ Ko
3827
3837
  ]));
3828
- let n = e.createCommandEncoder({ label: "oidn-autoexposure" }), r = n.beginComputePass({ label: "oidn-autoexposure-reduce" });
3829
- r.setPipeline(this._lumReducePipeline), r.setBindGroup(0, this._lumBindGroup), r.dispatchWorkgroups(Zo, 1, 1), r.end();
3830
- let i = n.beginComputePass({ label: "oidn-autoexposure-finalize" });
3831
- 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()]);
3832
3842
  }
3833
3843
  _applyColorScale(e, t) {
3834
3844
  if (!this._ensureScalePipelines(e)) return;
3835
- 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" });
3836
3846
  o.setPipeline(this._colorScalePipeline), o.setBindGroup(0, this._colorScaleBindGroup), o.dispatchWorkgroups(r, i, 1), o.end(), e.queue.submit([a.finish()]);
3837
3847
  }
3838
3848
  get outputTexture() {
@@ -3870,28 +3880,29 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3870
3880
  height: 0
3871
3881
  };
3872
3882
  }
3873
- _unpackToTexture(e, t, n, r = !0) {
3874
- let i = this.gpuDevice;
3875
- if (!i || !this._ensureScalePipelines(i)) return;
3876
- let { x: a, y: o, width: s, height: c } = n;
3877
- if (this._ensureOutputTexture(i, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
3878
- 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({
3879
3889
  label: "oidn-unpack-params",
3880
- size: rs,
3890
+ size: as,
3881
3891
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3882
3892
  });
3883
3893
  try {
3884
- 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([
3885
3896
  t,
3897
+ i,
3886
3898
  a,
3887
3899
  o,
3888
3900
  s,
3889
- c,
3890
- 0,
3901
+ Ko,
3891
3902
  0,
3892
3903
  0
3893
3904
  ]));
3894
- let n = i.createBindGroup({
3905
+ let l = r.createBindGroup({
3895
3906
  label: "oidn-output-unpack",
3896
3907
  layout: this._unpackPipeline.getBindGroupLayout(0),
3897
3908
  entries: [
@@ -3901,7 +3912,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3901
3912
  },
3902
3913
  {
3903
3914
  binding: 1,
3904
- resource: { buffer: l }
3915
+ resource: { buffer: c }
3905
3916
  },
3906
3917
  {
3907
3918
  binding: 2,
@@ -3916,10 +3927,10 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3916
3927
  resource: this._outGPUTexture.createView()
3917
3928
  }
3918
3929
  ]
3919
- }), u = i.createCommandEncoder({ label: "oidn-output-unpack" }), d = u.beginComputePass({ label: "oidn-output-unpack" });
3920
- 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);
3921
3932
  } finally {
3922
- l.destroy();
3933
+ c.destroy();
3923
3934
  }
3924
3935
  }
3925
3936
  _executeWithAbortGPU(e, t = !1) {
@@ -3932,11 +3943,15 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3932
3943
  this._tilesWritten = 0;
3933
3944
  let a = () => {
3934
3945
  i &&= (i(), null), r(new DOMException("Aborted", "AbortError"));
3935
- };
3936
- 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({
3937
3948
  ...e,
3949
+ scheduling: t ? "animation-frame" : "event-loop",
3950
+ error: (e) => {
3951
+ o.removeEventListener("abort", a), i = null, r(e);
3952
+ },
3938
3953
  done: async (e) => {
3939
- this.state.abortController.signal.removeEventListener("abort", a), i = null;
3954
+ o.removeEventListener("abort", a), i = null;
3940
3955
  try {
3941
3956
  this._tilesWritten === 0 && this._displayGPUOutput(e), n();
3942
3957
  } catch (e) {
@@ -3945,17 +3960,17 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3945
3960
  },
3946
3961
  progress: (e, n, r) => {
3947
3962
  if (!e?.data || !r) return;
3948
- let i = e.width, a = e.height, o = Math.min(r.width, i - r.x), s = Math.min(r.height, a - r.y);
3949
- if (o <= 0 || s <= 0) return;
3950
- let c = {
3951
- x: r.x,
3952
- y: r.y,
3953
- width: o,
3954
- 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
3955
3970
  };
3956
- this._unpackToTexture(e.data, i, c), this._tilesWritten++, this.dispatchEvent({
3971
+ this._unpackToTexture(e.data, u), this._tilesWritten++, this.dispatchEvent({
3957
3972
  type: "tileProgress",
3958
- tile: c,
3973
+ tile: u,
3959
3974
  imageWidth: i,
3960
3975
  imageHeight: a,
3961
3976
  continuous: t
@@ -3964,12 +3979,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3964
3979
  });
3965
3980
  });
3966
3981
  }
3967
- _displayGPUOutput({ data: e, width: t, height: n }) {
3982
+ _displayGPUOutput({ data: e }) {
3968
3983
  if (!this.gpuDevice) {
3969
3984
  Wo.error("gpuDevice not available for the output picture");
3970
3985
  return;
3971
3986
  }
3972
- this._unpackToTexture(e, t, {
3987
+ let { width: t, height: n } = this._gpuInputBufferSize;
3988
+ this._unpackToTexture(e, {
3973
3989
  x: 0,
3974
3990
  y: 0,
3975
3991
  width: t,
@@ -3994,7 +4010,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
3994
4010
  dispose() {
3995
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");
3996
4012
  }
3997
- }, cs = Object.freeze({
4013
+ }, us = Object.freeze({
3998
4014
  maxLength: 8,
3999
4015
  smoothLength: 2,
4000
4016
  roughStart: .45,
@@ -4002,7 +4018,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4002
4018
  depthTolerance: .05,
4003
4019
  normalTolerance: .8,
4004
4020
  movedLength: 2
4005
- }), 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 + `
4006
4022
  @group(0) @binding(1) var geoCur: texture_2d<f32>;
4007
4023
  @group(0) @binding(2) var geoPrev: texture_2d<f32>;
4008
4024
  @group(0) @binding(3) var<storage, read_write> picked: array<i32>;
@@ -4028,7 +4044,7 @@ fn movedIndex( leaf: u32 ) -> i32 {
4028
4044
 
4029
4045
  }
4030
4046
 
4031
- @compute @workgroup_size(${ls}, ${ls})
4047
+ @compute @workgroup_size(${ds}, ${ds})
4032
4048
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4033
4049
 
4034
4050
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -4043,7 +4059,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4043
4059
  let size = vec2<f32>( P.size );
4044
4060
  let uv = ( vec2<f32>( gid.xy ) + 0.5 ) / size;
4045
4061
  // Depth is along the ray: from the camera, or from its image plane when orthographic.
4046
- let ortho = ( P.flags & ${ms}u ) != 0u;
4062
+ let ortho = ( P.flags & ${gs}u ) != 0u;
4047
4063
  let ndc = vec2<f32>( uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0 );
4048
4064
  var origin = P.camWorld[ 3 ].xyz;
4049
4065
  var dir: vec3<f32>;
@@ -4067,7 +4083,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4067
4083
  let toPrev = movedToPrev[ u32( m ) ];
4068
4084
  wp = ( toPrev * vec4<f32>( wp, 1.0 ) ).xyz;
4069
4085
  n = normalize( ( toPrev * vec4<f32>( n, 0.0 ) ).xyz );
4070
- movedFlag = ${hs};
4086
+ movedFlag = ${_s};
4071
4087
 
4072
4088
  }
4073
4089
 
@@ -4104,7 +4120,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4104
4120
  if ( pick >= 0 ) { atomicAdd( &copies[ u32( pick ) ], 1u ); }
4105
4121
 
4106
4122
  }
4107
- `, vs = gs + `
4123
+ `, bs = vs + `
4108
4124
  @group(0) @binding(1) var curColor: texture_2d<f32>;
4109
4125
  @group(0) @binding(2) var curAlbedo: texture_2d<f32>;
4110
4126
  @group(0) @binding(3) var curNormal: texture_2d<f32>;
@@ -4118,7 +4134,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4118
4134
  @group(0) @binding(11) var outAlbedo: texture_storage_2d<rgba32float, write>;
4119
4135
  @group(0) @binding(12) var outNormal: texture_storage_2d<rgba32float, write>;
4120
4136
 
4121
- @compute @workgroup_size(${ls}, ${ls})
4137
+ @compute @workgroup_size(${ds}, ${ds})
4122
4138
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4123
4139
 
4124
4140
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -4134,8 +4150,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4134
4150
  var ha = ca.xyz;
4135
4151
  var hn = cn.xyz;
4136
4152
  let raw = picked[ gid.y * P.size.x + gid.x ];
4137
- let movedPx = raw >= 0 && ( raw & ${hs} ) != 0;
4138
- 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 );
4139
4155
 
4140
4156
  if ( pick >= 0 ) {
4141
4157
 
@@ -4149,7 +4165,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4149
4165
  ha = a.xyz;
4150
4166
  hn = textureLoad( histNormal, q, 0 ).xyz;
4151
4167
  len = a.w;
4152
- 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 ) ); }
4153
4169
 
4154
4170
  }
4155
4171
 
@@ -4163,11 +4179,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4163
4179
 
4164
4180
  textureStore( outColor, p, vec4<f32>( mix( hc, cur.xyz, t ), cur.w ) );
4165
4181
  textureStore( outAlbedo, p, vec4<f32>( mix( ha, ca.xyz, t ), newLen ) );
4166
- 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 );
4167
4183
  textureStore( outNormal, p, vec4<f32>( n, cn.w ) );
4168
4184
 
4169
4185
  }
4170
- `, ys = gs + `
4186
+ `, xs = vs + `
4171
4187
  @group(0) @binding(1) var accColor: texture_2d<f32>;
4172
4188
  @group(0) @binding(2) var accAlbedo: texture_2d<f32>;
4173
4189
  @group(0) @binding(3) var accNormal: texture_2d<f32>;
@@ -4178,7 +4194,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4178
4194
  @group(0) @binding(8) var outAlbedo: texture_storage_2d<rgba32float, write>;
4179
4195
  @group(0) @binding(9) var outNormal: texture_storage_2d<rgba32float, write>;
4180
4196
 
4181
- @compute @workgroup_size(${ls}, ${ls})
4197
+ @compute @workgroup_size(${ds}, ${ds})
4182
4198
  fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4183
4199
 
4184
4200
  if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
@@ -4212,32 +4228,32 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4212
4228
  let t = P.samples / max( k + P.samples, 1e-6 );
4213
4229
  textureStore( outColor, p, vec4<f32>( mix( hc, ac.xyz, t ), ac.w ) );
4214
4230
  textureStore( outAlbedo, p, vec4<f32>( mix( ha, aa.xyz, t ), min( k + P.samples, P.maxLength ) ) );
4215
- 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 );
4216
4232
  textureStore( outNormal, p, vec4<f32>( n, an.w ) );
4217
4233
 
4218
4234
  }
4219
- `, bs = (e) => ({
4235
+ `, Ss = (e) => ({
4220
4236
  binding: e,
4221
4237
  visibility: GPUShaderStage.COMPUTE,
4222
4238
  texture: { sampleType: "unfilterable-float" }
4223
- }), xs = (e) => ({
4239
+ }), Cs = (e) => ({
4224
4240
  binding: e,
4225
4241
  visibility: GPUShaderStage.COMPUTE,
4226
4242
  storageTexture: {
4227
4243
  access: "write-only",
4228
4244
  format: "rgba32float"
4229
4245
  }
4230
- }), Ss = (e, t) => ({
4246
+ }), ws = (e, t) => ({
4231
4247
  binding: e,
4232
4248
  visibility: GPUShaderStage.COMPUTE,
4233
4249
  buffer: { type: t }
4234
- }), Cs = class {
4250
+ }), Ts = class {
4235
4251
  constructor(e) {
4236
4252
  this.device = e, this.settings = {
4237
- ...cs,
4253
+ ...us,
4238
4254
  cleanAux: !1,
4239
4255
  splitCopies: !0
4240
- }, 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);
4241
4257
  }
4242
4258
  get textures() {
4243
4259
  return this.valid ? this._sets[this._current] : null;
@@ -4345,23 +4361,23 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4345
4361
  }),
4346
4362
  layout: i
4347
4363
  };
4348
- }, n = Ss(0, "uniform");
4364
+ }, n = ws(0, "uniform");
4349
4365
  this._pipelines = {
4350
- select: t("oidn-history-select", _s, [
4366
+ select: t("oidn-history-select", ys, [
4351
4367
  n,
4352
- bs(1),
4353
- bs(2),
4354
- Ss(3, "storage"),
4355
- Ss(4, "storage"),
4368
+ Ss(1),
4369
+ Ss(2),
4370
+ ws(3, "storage"),
4371
+ ws(4, "storage"),
4356
4372
  {
4357
4373
  binding: 5,
4358
4374
  visibility: GPUShaderStage.COMPUTE,
4359
4375
  texture: { sampleType: "uint" }
4360
4376
  },
4361
- Ss(6, "read-only-storage"),
4362
- Ss(7, "read-only-storage")
4377
+ ws(6, "read-only-storage"),
4378
+ ws(7, "read-only-storage")
4363
4379
  ]),
4364
- blend: t("oidn-history-blend", vs, [
4380
+ blend: t("oidn-history-blend", bs, [
4365
4381
  n,
4366
4382
  ...[
4367
4383
  1,
@@ -4371,14 +4387,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4371
4387
  5,
4372
4388
  6,
4373
4389
  7
4374
- ].map(bs),
4375
- Ss(8, "read-only-storage"),
4376
- Ss(9, "read-only-storage"),
4377
- xs(10),
4378
- xs(11),
4379
- 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)
4380
4396
  ]),
4381
- merge: t("oidn-history-merge", ys, [
4397
+ merge: t("oidn-history-merge", xs, [
4382
4398
  n,
4383
4399
  ...[
4384
4400
  1,
@@ -4387,16 +4403,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4387
4403
  4,
4388
4404
  5,
4389
4405
  6
4390
- ].map(bs),
4391
- xs(7),
4392
- xs(8),
4393
- xs(9)
4406
+ ].map(Ss),
4407
+ Cs(7),
4408
+ Cs(8),
4409
+ Cs(9)
4394
4410
  ])
4395
4411
  }, this._paramsBuffer = e.createBuffer({
4396
4412
  label: "oidn-history-params",
4397
- size: us,
4413
+ size: fs,
4398
4414
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
4399
- }), this._growMoved(ds);
4415
+ }), this._growMoved(ps);
4400
4416
  }
4401
4417
  _growMoved(e) {
4402
4418
  this._movedLeaves?.destroy(), this._movedToPrev?.destroy();
@@ -4422,11 +4438,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4422
4438
  a.setPipeline(t), a.setBindGroup(0, this.device.createBindGroup({
4423
4439
  layout: n,
4424
4440
  entries: i
4425
- })), 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();
4426
4442
  }
4427
4443
  _writeParams(e, t, n, r) {
4428
4444
  let i = this.settings, a = this._paramU32, o = this._paramF32;
4429
- 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);
4430
4446
  }
4431
4447
  _rememberCamera(e) {
4432
4448
  this._prevViewProj.set(e.viewProj), this._prevCamPos[0] = e.world[12], this._prevCamPos[1] = e.world[13], this._prevCamPos[2] = e.world[14];
@@ -4436,11 +4452,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
4436
4452
  _releaseTextures() {
4437
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;
4438
4454
  }
4439
- }, 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" });
4440
- 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) {
4441
4457
  let t;
4442
4458
  try {
4443
- if (t = Ts && (self.URL || self.webkitURL).createObjectURL(Ts), !t) throw "";
4459
+ if (t = Ds && (self.URL || self.webkitURL).createObjectURL(Ds), !t) throw "";
4444
4460
  let n = new Worker(t, {
4445
4461
  type: "module",
4446
4462
  name: e?.name
@@ -4449,7 +4465,7 @@ function Es(e) {
4449
4465
  (self.URL || self.webkitURL).revokeObjectURL(t);
4450
4466
  }), n;
4451
4467
  } catch {
4452
- return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(ws), {
4468
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Es), {
4453
4469
  type: "module",
4454
4470
  name: e?.name
4455
4471
  });
@@ -4457,7 +4473,7 @@ function Es(e) {
4457
4473
  }
4458
4474
  //#endregion
4459
4475
  //#region src/Passes/AIUpscaler.js
4460
- var Ds = {
4476
+ var ks = {
4461
4477
  fast: {
4462
4478
  2: "2x-spanx2-ch48.onnx",
4463
4479
  4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
@@ -4471,17 +4487,17 @@ var Ds = {
4471
4487
  4: "4xNomos2_hq_mosr_fp32.onnx"
4472
4488
  }
4473
4489
  };
4474
- function Os() {
4490
+ function As() {
4475
4491
  let { upscalerModelBaseUrl: e } = ot(), t = {};
4476
- for (let n in Ds) {
4492
+ for (let n in ks) {
4477
4493
  t[n] = {};
4478
- 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];
4479
4495
  }
4480
4496
  return t;
4481
4497
  }
4482
- var ks = {
4498
+ var js = {
4483
4499
  get QUALITY_PRESETS() {
4484
- return Os();
4500
+ return As();
4485
4501
  },
4486
4502
  TILE_SIZE: 512,
4487
4503
  TILE_OVERLAP: 16,
@@ -4492,17 +4508,17 @@ var ks = {
4492
4508
  }],
4493
4509
  graphOptimizationLevel: "all"
4494
4510
  }
4495
- }, As = class extends fr {
4511
+ }, Ms = class extends fr {
4496
4512
  constructor(e, t, n = {}) {
4497
4513
  if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
4498
- 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 = {
4499
4515
  isUpscaling: !1,
4500
4516
  isLoading: !1,
4501
4517
  abortController: null
4502
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;
4503
4519
  }
4504
4520
  async _ensureSession() {
4505
- let e = ks.QUALITY_PRESETS[this.quality];
4521
+ let e = js.QUALITY_PRESETS[this.quality];
4506
4522
  if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
4507
4523
  let t = e[this.scaleFactor];
4508
4524
  if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
@@ -4512,14 +4528,14 @@ var ks = {
4512
4528
  message: `Loading ${this.scaleFactor}x upscale model...`
4513
4529
  });
4514
4530
  try {
4515
- this._worker ||= new Es(), await new Promise((e, n) => {
4531
+ this._worker ||= new Os(), await new Promise((e, n) => {
4516
4532
  let r = (t) => {
4517
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)));
4518
4534
  }, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o, storage: s } = ot();
4519
4535
  this._worker.addEventListener("message", r), this._worker.postMessage({
4520
4536
  type: "load",
4521
4537
  url: t,
4522
- sessionOptions: ks.SESSION_OPTIONS,
4538
+ sessionOptions: js.SESSION_OPTIONS,
4523
4539
  ortRuntimeUrl: i,
4524
4540
  ortWasmPaths: a,
4525
4541
  cacheNamespace: o,
@@ -4594,7 +4610,7 @@ var ks = {
4594
4610
  alpha: !0
4595
4611
  });
4596
4612
  this._cacheUpscaledAlpha(t, n * i, r * i);
4597
- 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;
4598
4614
  for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
4599
4615
  if (e.aborted) throw new DOMException("Aborted", "AbortError");
4600
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);
@@ -4737,7 +4753,7 @@ var ks = {
4737
4753
  this.hdr = !!e;
4738
4754
  }
4739
4755
  setQuality(e) {
4740
- if (!ks.QUALITY_PRESETS[e]) {
4756
+ if (!js.QUALITY_PRESETS[e]) {
4741
4757
  console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
4742
4758
  return;
4743
4759
  }
@@ -4760,7 +4776,7 @@ var ks = {
4760
4776
  async dispose() {
4761
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");
4762
4778
  }
4763
- }, 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 {
4764
4780
  constructor({ renderer: e, mainCanvas: t, stages: n, pipeline: r, getExposure: i, getSaturation: a, getDisplayGain: o = null, issues: s = null }) {
4765
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 = {
4766
4782
  world: null,
@@ -4771,7 +4787,7 @@ var ks = {
4771
4787
  count: 0,
4772
4788
  leaves: new Uint32Array(),
4773
4789
  toPrev: new Float32Array()
4774
- }, 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;
4775
4791
  }
4776
4792
  _createUpscalerCanvas(e) {
4777
4793
  let t = e.parentNode;
@@ -4793,7 +4809,7 @@ var ks = {
4793
4809
  }
4794
4810
  setupDenoiser() {
4795
4811
  let e = this._stages.pathTracer;
4796
- this.denoiser = new ss(this.renderer, {
4812
+ this.denoiser = new ls(this.renderer, {
4797
4813
  enableOIDN: ei.enableOIDN,
4798
4814
  oidnQuality: ei.oidnQuality,
4799
4815
  backendParams: () => ({
@@ -4828,12 +4844,24 @@ var ks = {
4828
4844
  url: e.url,
4829
4845
  asset: "oidn-weights",
4830
4846
  cause: String(e.error?.message ?? e.error)
4831
- }), 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
+ });
4832
4860
  }
4833
4861
  setupUpscaler() {
4834
4862
  if (!this.upscalerCanvas) return;
4835
4863
  let e = this._stages.pathTracer;
4836
- this.upscaler = new As(this.upscalerCanvas, this.renderer, {
4864
+ this.upscaler = new Ms(this.upscalerCanvas, this.renderer, {
4837
4865
  scaleFactor: ei.upscalerScale || 2,
4838
4866
  quality: ei.upscalerQuality || "fast",
4839
4867
  getSourceCanvas: () => this.renderer.domElement,
@@ -4909,8 +4937,8 @@ var ks = {
4909
4937
  get holdsWhileMoving() {
4910
4938
  if (!this._stages.pathTracer?.viewIsChanging || !this.continuousDenoise || this._cadenceSuspended || !this.denoiser?.enabled || this._movingHopeless) return !1;
4911
4939
  let e = this.movingCostMs, t = this._movingDenoiseMs.length;
4912
- e > Is * Rs && (this._movingHopeless = !0, this._syncGBufferStages());
4913
- 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);
4914
4942
  return this._holdWhileMoving = (this._holdWhileMoving === null || this._holdWhileMoving) && n, this._holdWhileMoving;
4915
4943
  }
4916
4944
  skipsTrace() {
@@ -4927,7 +4955,7 @@ var ks = {
4927
4955
  this.pipeline?.context?.removeTexture("oidn:output"), this.denoiser?.invalidateOutput();
4928
4956
  }
4929
4957
  _checkHeldFrameHealthy() {
4930
- !this.denoiser?.hasOutput || this._failedRefreshes < zs || this._unpublishOutput();
4958
+ !this.denoiser?.hasOutput || this._failedRefreshes < Vs || this._unpublishOutput();
4931
4959
  }
4932
4960
  tickContinuousDenoise(e) {
4933
4961
  let t = this.denoiser;
@@ -4937,12 +4965,12 @@ var ks = {
4937
4965
  if (!n) this._holdWhileMoving = null, this._movingDenoiseMs.length = 0;
4938
4966
  else if (!this.holdsWhileMoving) return !1;
4939
4967
  if (t.state.isDenoising || t.state.isLoading || !n && e <= this._lastCadenceSamples) return !1;
4940
- 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);
4941
4969
  if (r - this._lastCadenceAt < a) return !1;
4942
- 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);
4943
4971
  let o = this._cadenceDowngraded ? this.previewQuality() : this._finalQuality;
4944
4972
  return t.quality !== o && t.updateQuality(o), t.start({ continuous: !0 }).then((e) => {
4945
- 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());
4946
4974
  }), !0;
4947
4975
  }
4948
4976
  previewQuality() {
@@ -4984,7 +5012,7 @@ var ks = {
4984
5012
  r && (this._ensureHistory().merge(r, t.frameCount, this._historyCameraNow(), {
4985
5013
  commit: !0,
4986
5014
  keepHistory: !this._historyDirty && !n,
4987
- historyScale: Vs(t.frameCount)
5015
+ historyScale: Us(t.frameCount)
4988
5016
  }), this._historyDirty = !1);
4989
5017
  }
4990
5018
  afterReset() {
@@ -5026,9 +5054,9 @@ var ks = {
5026
5054
  let e = this._stages.pathTracer, t = this._history;
5027
5055
  if (!t?.valid || this._historyDirty || !this.historyActive || e.isComplete || e.resetCount !== this._knownResetCount || t.width !== this._lastRenderWidth || t.height !== this._lastRenderHeight) return null;
5028
5056
  if (e.frameCount <= 1) return t.textures;
5029
- if (e.frameCount >= Bs) return null;
5057
+ if (e.frameCount >= Hs) return null;
5030
5058
  let n = this._historyInputs();
5031
- 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;
5032
5060
  }
5033
5061
  _historyInputs() {
5034
5062
  let e = this._stages.pathTracer, t = this.pipeline?.context, n = this.renderer?.backend;
@@ -5053,7 +5081,7 @@ var ks = {
5053
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;
5054
5082
  }
5055
5083
  _ensureHistory() {
5056
- 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;
5057
5085
  }
5058
5086
  _releaseHistory() {
5059
5087
  this._history?.dispose(), this._history = null, this._historyDirty = !0, this._movedPlacements.clear();
@@ -5091,15 +5119,15 @@ var ks = {
5091
5119
  return;
5092
5120
  }
5093
5121
  if (!this.pipeline?.context?.getTexture("oidn:output")) {
5094
- js.warn("neural pass skipped: no denoised picture — it needs OIDN");
5122
+ Ns.warn("neural pass skipped: no denoised picture — it needs OIDN");
5095
5123
  return;
5096
5124
  }
5097
5125
  this._neuralPostBusy = !0, this.dispatchEvent({ type: j.UPSCALING_START });
5098
5126
  try {
5099
- let i = await import("./NeuralSuperRes-BHxhYzlD.js").then((e) => e.t);
5127
+ let i = await import("./NeuralSuperRes-ChCiiilS.js").then((e) => e.t);
5100
5128
  this._superResModule = i;
5101
- let a = n ? await import("./NeuralRetouch-KqGVPV7u.js").then((e) => e.t) : null, o = this.denoiser?._outTexSize, s = (o?.width ?? 0) * (o?.height ?? 0), c = n && s <= a.RETOUCH_MAX_PIXELS;
5102
- if (n && !c && (js.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) {
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) {
5103
5131
  r && !this._postCancelled && await this.upscaler.start();
5104
5132
  return;
5105
5133
  }
@@ -5143,7 +5171,7 @@ var ks = {
5143
5171
  height: d.height
5144
5172
  });
5145
5173
  } catch (e) {
5146
- js.warn("neural pass failed", e);
5174
+ Ns.warn("neural pass failed", e);
5147
5175
  } finally {
5148
5176
  this._neuralPostBusy = !1, this.dispatchEvent({ type: j.UPSCALING_END });
5149
5177
  }
@@ -5201,7 +5229,21 @@ var ks = {
5201
5229
  this._unpublishOutput(), this._restoreRenderDisplay(), this._historyDirty = !0;
5202
5230
  }
5203
5231
  dispose() {
5204
- this._cleanupCompletionListener(), this._postIsStillComplete = null, 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);
5205
5247
  }
5206
5248
  setOverlayManager(e) {
5207
5249
  this._overlayManager = e;
@@ -5316,7 +5358,7 @@ var ks = {
5316
5358
  let t = qr[e];
5317
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));
5318
5360
  }
5319
- }, Us = class {
5361
+ }, Gs = class {
5320
5362
  constructor() {
5321
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;
5322
5364
  }
@@ -5340,7 +5382,7 @@ var ks = {
5340
5382
  dispose() {
5341
5383
  this.visible = !1;
5342
5384
  }
5343
- }, Ws = class {
5385
+ }, Ks = class {
5344
5386
  constructor(e, t) {
5345
5387
  this.layer = "scene", this._enabled = !0, this._scene = e, this._camera = t, this._build([]);
5346
5388
  }
@@ -5378,11 +5420,11 @@ var ks = {
5378
5420
  this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
5379
5421
  }
5380
5422
  };
5381
- function Gs(e = !1) {
5423
+ function qs(e = !1) {
5382
5424
  let t = document.createElement("canvas");
5383
5425
  return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
5384
5426
  }
5385
- function Ks(e, t = Infinity) {
5427
+ function Js(e, t = Infinity) {
5386
5428
  let n = e?.getBoundingClientRect();
5387
5429
  if (!n || n.width === 0 || n.height === 0) return null;
5388
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);
@@ -5393,9 +5435,9 @@ function Ks(e, t = Infinity) {
5393
5435
  }
5394
5436
  //#endregion
5395
5437
  //#region src/managers/helpers/ViewOverlayRenderer.js
5396
- var qs = 4096, Js = class {
5438
+ var Ys = 4096, Xs = class {
5397
5439
  constructor() {
5398
- 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;
5399
5441
  }
5400
5442
  async init({ device: e, sizeSource: t }) {
5401
5443
  this._sizeSource = t;
@@ -5412,7 +5454,7 @@ var qs = 4096, Js = class {
5412
5454
  }
5413
5455
  syncSize() {
5414
5456
  if (!this.renderer) return;
5415
- let e = Ks(this._sizeSource, qs);
5457
+ let e = Js(this._sizeSource, Ys);
5416
5458
  !e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
5417
5459
  }
5418
5460
  begin() {
@@ -5424,18 +5466,18 @@ var qs = 4096, Js = class {
5424
5466
  dispose() {
5425
5467
  Pe(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
5426
5468
  }
5427
- }, 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 {
5428
5470
  constructor(e) {
5429
- 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;
5430
5472
  }
5431
5473
  async initViewRenderer({ device: e, sizeSource: t }) {
5432
5474
  if (!(!e || !t)) try {
5433
- this._viewOverlay = await new Js().init({
5475
+ this._viewOverlay = await new Xs().init({
5434
5476
  device: e,
5435
5477
  sizeSource: t
5436
5478
  });
5437
5479
  } catch (e) {
5438
- 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;
5439
5481
  }
5440
5482
  }
5441
5483
  gpuResources() {
@@ -5455,11 +5497,11 @@ var qs = 4096, Js = class {
5455
5497
  }
5456
5498
  setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
5457
5499
  this.setHelperScene(e);
5458
- let s = new Us();
5500
+ let s = new Gs();
5459
5501
  this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(j.RESOLUTION_CHANGED, (e) => {
5460
5502
  s.setRenderSize(e.width, e.height);
5461
5503
  }), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
5462
- let c = new Ws(t, this.camera);
5504
+ let c = new Ks(t, this.camera);
5463
5505
  this.register("outline", c);
5464
5506
  }
5465
5507
  _wireDenoiserTileEvents(e, t) {
@@ -5471,7 +5513,7 @@ var qs = 4096, Js = class {
5471
5513
  }));
5472
5514
  }
5473
5515
  register(e, t) {
5474
- 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);
5475
5517
  }
5476
5518
  unregister(e) {
5477
5519
  let t = this._helpers.get(e);
@@ -5509,16 +5551,16 @@ var qs = 4096, Js = class {
5509
5551
  }
5510
5552
  _renderSceneLayer(e) {
5511
5553
  this._helperScene?.render(e, this.camera);
5512
- 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);
5513
5555
  }
5514
5556
  _hasVisibleSceneOverlay() {
5515
5557
  if (this._helperScene?.isDrawing) return !0;
5516
- 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;
5517
5559
  return !1;
5518
5560
  }
5519
5561
  refreshHUD() {
5520
5562
  let e = this._hudCanvas, t = this._hudCtx, n = !1;
5521
- for (let e of this._helpers.values()) if (Xs(e, "hud")) {
5563
+ for (let e of this._helpers.values()) if (Qs(e, "hud")) {
5522
5564
  n = !0;
5523
5565
  break;
5524
5566
  }
@@ -5527,10 +5569,10 @@ var qs = 4096, Js = class {
5527
5569
  return;
5528
5570
  }
5529
5571
  e.style.display !== "" && (e.style.display = "");
5530
- 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;
5531
5573
  if (a) {
5532
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);
5533
- 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);
5534
5576
  t.restore(), e.style.display !== "" && (e.style.display = "");
5535
5577
  }
5536
5578
  }
@@ -5541,7 +5583,7 @@ var qs = 4096, Js = class {
5541
5583
  };
5542
5584
  //#endregion
5543
5585
  //#region src/managers/AnimationManager.js
5544
- function Qs(e, t) {
5586
+ function ec(e, t) {
5545
5587
  let n = [...e].filter((t) => {
5546
5588
  for (let n = t.parent; n; n = n.parent) if (e.has(n)) return !1;
5547
5589
  return !0;
@@ -5550,7 +5592,7 @@ function Qs(e, t) {
5550
5592
  for (let e of n) e.traverse?.(() => i++);
5551
5593
  return i + n.length / 2 < r ? n : null;
5552
5594
  }
5553
- var $s = class extends fr {
5595
+ var tc = class extends fr {
5554
5596
  constructor() {
5555
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;
5556
5598
  }
@@ -5604,7 +5646,7 @@ var $s = class extends fr {
5604
5646
  visibility: i,
5605
5647
  cameras: [...s],
5606
5648
  nodes: a ? null : r,
5607
- roots: a ? null : Qs(r, t)
5649
+ roots: a ? null : ec(r, t)
5608
5650
  };
5609
5651
  }), this._allPlan = null, !this._rigid) return;
5610
5652
  this._slotOf = new Int32Array(this._meshes.length).fill(-1);
@@ -5623,7 +5665,7 @@ var $s = class extends fr {
5623
5665
  visibility: n,
5624
5666
  cameras: [...t],
5625
5667
  nodes: r,
5626
- roots: r ? Qs(r, this._mixerRoot) : null
5668
+ roots: r ? ec(r, this._mixerRoot) : null
5627
5669
  };
5628
5670
  }
5629
5671
  return this._allPlan;
@@ -5755,19 +5797,19 @@ var $s = class extends fr {
5755
5797
  dispose() {
5756
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;
5757
5799
  }
5758
- }, ec = new $(0, 0, -1), tc = (e) => {
5800
+ }, nc = new $(0, 0, -1), rc = (e) => {
5759
5801
  for (; e.parent;) e = e.parent;
5760
5802
  return e.isScene ? e : null;
5761
- }, nc = class {
5803
+ }, ic = class {
5762
5804
  constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
5763
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);
5764
5806
  }
5765
5807
  setMeshData(e) {
5766
5808
  this._meshes = e;
5767
- 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);
5768
5810
  }
5769
5811
  get movedObjects() {
5770
- return [...this._moved].filter((e) => tc(e));
5812
+ return [...this._moved].filter((e) => rc(e));
5771
5813
  }
5772
5814
  noteMoved(e) {
5773
5815
  e && !e.isLight && this._moved.add(e);
@@ -5828,7 +5870,7 @@ var $s = class extends fr {
5828
5870
  }
5829
5871
  _syncLightAim(e) {
5830
5872
  let t = this._tempForward.copy(e.target.position).sub(e.position), n = t.length();
5831
- 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;
5832
5874
  }
5833
5875
  _recomputeAndRefit() {
5834
5876
  if (!this._meshes || this._refitInFlight || !this._attached) return;
@@ -5864,7 +5906,7 @@ var $s = class extends fr {
5864
5906
  dispose() {
5865
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;
5866
5908
  }
5867
- }, rc = class {
5909
+ }, ac = class {
5868
5910
  constructor(e) {
5869
5911
  this.layer = "scene", this._transformManager = e, this._enabled = !0;
5870
5912
  }
@@ -5883,8 +5925,8 @@ var $s = class extends fr {
5883
5925
  dispose() {
5884
5926
  this._enabled = !1;
5885
5927
  }
5886
- }, ic = 1, ac = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5887
- function oc(e, t) {
5928
+ }, oc = 1, sc = (e) => typeof e == "string" && /^https?:\/\//.test(e);
5929
+ function cc(e, t) {
5888
5930
  let n = [];
5889
5931
  for (; e && e !== t;) {
5890
5932
  let t = e.parent;
@@ -5893,12 +5935,12 @@ function oc(e, t) {
5893
5935
  }
5894
5936
  return e === t ? n : null;
5895
5937
  }
5896
- function sc(e, t) {
5938
+ function lc(e, t) {
5897
5939
  let n = e;
5898
5940
  for (let e of t) if (n = n?.children[e], !n) return null;
5899
5941
  return n;
5900
5942
  }
5901
- function cc(e) {
5943
+ function uc(e) {
5902
5944
  return {
5903
5945
  key: e.assetLoader?.sceneSourceKey ?? null,
5904
5946
  name: e.sceneModel?.name ?? null,
@@ -5906,7 +5948,7 @@ function cc(e) {
5906
5948
  materials: e.stages.pathTracer?.materialData.materialCount ?? 0
5907
5949
  };
5908
5950
  }
5909
- function lc(e) {
5951
+ function dc(e) {
5910
5952
  let t = /* @__PURE__ */ new Map();
5911
5953
  for (let n of e.sceneMeshes) {
5912
5954
  let e = n.userData?.materialIndex;
@@ -5914,7 +5956,7 @@ function lc(e) {
5914
5956
  }
5915
5957
  return t;
5916
5958
  }
5917
- function uc(e) {
5959
+ function fc(e) {
5918
5960
  if (!e) return null;
5919
5961
  let t = e.status(), n = t.activeView, r = t.config?.id ?? n?.configId ?? null;
5920
5962
  return {
@@ -5929,15 +5971,15 @@ function uc(e) {
5929
5971
  context: t.context ?? null
5930
5972
  };
5931
5973
  }
5932
- function dc(e) {
5933
- let t = e.meshScene, n = lc(e), r = [];
5974
+ function pc(e) {
5975
+ let t = e.meshScene, n = dc(e), r = [];
5934
5976
  return t.traverse((e) => {
5935
- e !== t && e.visible === !1 && r.push(oc(e, t));
5977
+ e !== t && e.visible === !1 && r.push(cc(e, t));
5936
5978
  }), {
5937
5979
  v: 1,
5938
5980
  engine: Be,
5939
5981
  savedAt: Date.now(),
5940
- scene: cc(e),
5982
+ scene: uc(e),
5941
5983
  appended: t.children.filter((t) => t !== e.sceneModel && t.userData?.__rayzeeSceneObject).map((e) => ({
5942
5984
  name: e.userData.__rayzeeName ?? e.name,
5943
5985
  url: e.userData.__rayzeeSourceUrl ?? null,
@@ -5945,7 +5987,7 @@ function dc(e) {
5945
5987
  })),
5946
5988
  settings: e.settings.serialize(),
5947
5989
  environment: e.environmentManager?.serialize() ?? null,
5948
- color: uc(e.color),
5990
+ color: fc(e.color),
5949
5991
  lights: e.lightManager.serialize(),
5950
5992
  cameras: e.cameraManager.serialize(),
5951
5993
  timeline: e.timeline?.serialize() ?? null,
@@ -5955,7 +5997,7 @@ function dc(e) {
5955
5997
  })),
5956
5998
  hidden: r,
5957
5999
  moved: (e.transformManager?.movedObjects ?? []).map((e) => ({
5958
- path: oc(e, t),
6000
+ path: cc(e, t),
5959
6001
  name: e.name,
5960
6002
  position: e.position.toArray(),
5961
6003
  quaternion: e.quaternion.toArray(),
@@ -5963,15 +6005,15 @@ function dc(e) {
5963
6005
  })).filter((e) => e.path)
5964
6006
  };
5965
6007
  }
5966
- function fc(e, t, n) {
6008
+ function mc(e, t, n) {
5967
6009
  let r = e[t];
5968
6010
  r?.copy && (n?.isColor || n?.isVector2 || n?.isVector3) ? r.copy(n) : e[t] = n, e.needsUpdate = !0;
5969
6011
  }
5970
- async function pc(e, t, n, r) {
6012
+ async function hc(e, t, n, r) {
5971
6013
  if (!t) return;
5972
6014
  let i = e.environmentManager;
5973
6015
  if (t.hdri && t.hdri !== i.hdriSource) {
5974
- let i = ac(t.hdri) ? t.hdri : await n({
6016
+ let i = sc(t.hdri) ? t.hdri : await n({
5975
6017
  kind: "environment",
5976
6018
  source: t.hdri
5977
6019
  });
@@ -5983,7 +6025,7 @@ async function pc(e, t, n, r) {
5983
6025
  }
5984
6026
  await i.restore(t);
5985
6027
  }
5986
- async function mc(e, t, n, r) {
6028
+ async function gc(e, t, n, r) {
5987
6029
  let i = e.color;
5988
6030
  if (!t || !i) return;
5989
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;
@@ -6008,7 +6050,7 @@ async function mc(e, t, n, r) {
6008
6050
  r("color", e.message, { config: t.config?.id ?? null });
6009
6051
  }
6010
6052
  }
6011
- async function hc(e, t, { resolve: n = async () => null } = {}) {
6053
+ async function _c(e, t, { resolve: n = async () => null } = {}) {
6012
6054
  if (t?.v !== 1) throw Error(`scene state version ${t?.v} is not 1`);
6013
6055
  let r = [], i = (e, t, n = {}) => r.push({
6014
6056
  section: e,
@@ -6029,11 +6071,11 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6029
6071
  i("appended", e.message, { name: n.name });
6030
6072
  }
6031
6073
  }
6032
- 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;
6033
6075
  s || i("scene", "the loaded scene is not the one saved: objects and materials left as loaded", {
6034
6076
  saved: o,
6035
6077
  now: a
6036
- }), 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);
6037
6079
  let c = e.settings.restore(t.settings);
6038
6080
  c.length && i("settings", "not settings in this engine", { keys: c });
6039
6081
  let l = e.lightManager.restore(t.lights);
@@ -6042,7 +6084,7 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6042
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 });
6043
6085
  }
6044
6086
  if (s) {
6045
- let n = lc(e);
6087
+ let n = dc(e);
6046
6088
  for (let r of t.materials ?? []) {
6047
6089
  let t = n.get(r.index);
6048
6090
  if (!t || (t.name ?? "") !== r.name) {
@@ -6053,17 +6095,17 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6053
6095
  continue;
6054
6096
  }
6055
6097
  for (let [n, i] of Object.entries(r.props)) {
6056
- let a = me(i);
6057
- 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);
6058
6100
  }
6059
6101
  }
6060
- 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));
6061
6103
  r.traverse((e) => {
6062
6104
  e !== r && !e.isLight && (e.visible = !a.has(e));
6063
6105
  }), e.updateAllMeshVisibility();
6064
6106
  let o = [];
6065
6107
  for (let n of t.moved ?? []) {
6066
- let t = sc(r, n.path);
6108
+ let t = lc(r, n.path);
6067
6109
  if (!t || t.name !== n.name) {
6068
6110
  i("moved", "no such object", { name: n.name });
6069
6111
  continue;
@@ -6085,7 +6127,7 @@ async function hc(e, t, { resolve: n = async () => null } = {}) {
6085
6127
  }
6086
6128
  //#endregion
6087
6129
  //#region src/PathTracerApp.js
6088
- var gc = Ke("engine"), _c = class extends w {
6130
+ var vc = Ke("engine"), yc = class extends w {
6089
6131
  constructor(e, t = {}) {
6090
6132
  super(e, t), this.setColorManagement($t), this.setStorageOpener(un), this.settings.define("interactionRenderScale", {
6091
6133
  default: .5,
@@ -6093,7 +6135,7 @@ var gc = Ke("engine"), _c = class extends w {
6093
6135
  this.stages?.pathTracer?.interactionMode && this._requestRenderScale(this._interactionRenderScale());
6094
6136
  },
6095
6137
  reset: !1
6096
- }), 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();
6097
6139
  }
6098
6140
  _createCamera() {
6099
6141
  return this.cameraManager = new Co(this.canvas), this.timeline = new ko({
@@ -6102,7 +6144,7 @@ var gc = Ke("engine"), _c = class extends w {
6102
6144
  }), this.cameraManager.camera;
6103
6145
  }
6104
6146
  _initAssetPipeline() {
6105
- super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Ot), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-29Nl1567.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);
6106
6148
  let e = () => {
6107
6149
  this.needsReset = !0, this.stages.pathTracer?.enterInteractionMode(), this.wake();
6108
6150
  };
@@ -6129,7 +6171,7 @@ var gc = Ke("engine"), _c = class extends w {
6129
6171
  super._initPipeline(), this.pipeline.eventBus.on("pathtracer:interactionStart", () => this._requestRenderScale(this._interactionRenderScale())), this.pipeline.eventBus.on("pathtracer:interactionEnd", () => this._applyRenderScale(1));
6130
6172
  }
6131
6173
  async _initManagers() {
6132
- await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-CUWrTcmT.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({
6133
6175
  scene: this.meshScene,
6134
6176
  camera: this.camera,
6135
6177
  canvas: this.canvas,
@@ -6143,12 +6185,12 @@ var gc = Ke("engine"), _c = class extends w {
6143
6185
  }), this.iesManager = new Ho(this.stages.pathTracer, {
6144
6186
  onReset: () => this.reset(),
6145
6187
  issues: this._issues
6146
- }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new nc({
6188
+ }), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new ic({
6147
6189
  camera: this.camera,
6148
6190
  canvas: this.canvas,
6149
6191
  orbitControls: this.cameraManager.controls,
6150
6192
  app: this
6151
- }), this.overlayManager.register("transform", new rc(this.transformManager))), this.interactionManager.setDependencies({
6193
+ }), this.overlayManager.register("transform", new ac(this.transformManager))), this.interactionManager.setDependencies({
6152
6194
  overlayManager: this.overlayManager,
6153
6195
  transformManager: this.transformManager,
6154
6196
  appDispatch: (e) => this.dispatchEvent(e),
@@ -6160,6 +6202,7 @@ var gc = Ke("engine"), _c = class extends w {
6160
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, [
6161
6203
  j.DENOISING_START,
6162
6204
  j.DENOISING_END,
6205
+ j.DENOISER_LOADING,
6163
6206
  j.UPSCALING_START,
6164
6207
  j.UPSCALING_PROGRESS,
6165
6208
  j.UPSCALING_END,
@@ -6215,7 +6258,7 @@ var gc = Ke("engine"), _c = class extends w {
6215
6258
  _beginFrame() {
6216
6259
  if (this.timeline.update(), this.cameraManager.updateControls(), this._updateExposure(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
6217
6260
  let e = this.animationManager.update();
6218
- 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(() => {
6219
6262
  this._animRefitInFlight = !1;
6220
6263
  }));
6221
6264
  }
@@ -6347,10 +6390,10 @@ var gc = Ke("engine"), _c = class extends w {
6347
6390
  return t && this._dispatchCamerasUpdated(), t;
6348
6391
  }
6349
6392
  exportSceneState() {
6350
- return dc(this);
6393
+ return pc(this);
6351
6394
  }
6352
6395
  async importSceneState(e, t) {
6353
- return await hc(this, e, t);
6396
+ return await _c(this, e, t);
6354
6397
  }
6355
6398
  _dispatchCamerasUpdated() {
6356
6399
  this.dispatchEvent({
@@ -6472,7 +6515,7 @@ var gc = Ke("engine"), _c = class extends w {
6472
6515
  this.transformManager?.setMeshData(this._sdf.meshes);
6473
6516
  }
6474
6517
  _setupDenoisingManager() {
6475
- this.denoisingManager = new Hs({
6518
+ this.denoisingManager = new Ws({
6476
6519
  renderer: this.renderer,
6477
6520
  mainCanvas: this.canvas,
6478
6521
  stages: {
@@ -6528,7 +6571,7 @@ var gc = Ke("engine"), _c = class extends w {
6528
6571
  }, n && this.stages.autoExposure?.noteViewChanged());
6529
6572
  }
6530
6573
  async _setupOverlayManager() {
6531
- this.overlayManager = new Zs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
6574
+ this.overlayManager = new $s(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
6532
6575
  helperScene: this._sceneHelpers,
6533
6576
  meshScene: this.meshScene,
6534
6577
  pipeline: this.pipeline,
@@ -6559,15 +6602,15 @@ var gc = Ke("engine"), _c = class extends w {
6559
6602
  };
6560
6603
  //#endregion
6561
6604
  //#region src/Headless.js
6562
- async function vc(e) {
6563
- let t = await bc(e);
6605
+ async function bc(e) {
6606
+ let t = await Sc(e);
6564
6607
  try {
6565
- return await yc(t, e);
6608
+ return await xc(t, e);
6566
6609
  } finally {
6567
6610
  t.dispose();
6568
6611
  }
6569
6612
  }
6570
- 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 } = {}) {
6571
6614
  let o = e.denoisingManager;
6572
6615
  i && o && !o.finalDenoise && (o.applyOIDNEnabled(!0), o._syncGBufferStages());
6573
6616
  let s = await e.renderFrames(t, {
@@ -6586,8 +6629,8 @@ async function yc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire
6586
6629
  provenance: e.getProvenance()
6587
6630
  };
6588
6631
  }
6589
- 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 } = {}) {
6590
- 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, {
6591
6634
  autoResize: !1,
6592
6635
  strict: i,
6593
6636
  storage: s,
@@ -6601,7 +6644,7 @@ async function bc({ canvas: e, model: t = null, width: n = 1920, height: r = 108
6601
6644
  }
6602
6645
  //#endregion
6603
6646
  //#region src/managers/VideoRenderManager.js
6604
- var xc = class {
6647
+ var Cc = class {
6605
6648
  constructor(e) {
6606
6649
  this._app = e, this._cancelled = !1, this._rendering = !1;
6607
6650
  }
@@ -6715,4 +6758,4 @@ var xc = class {
6715
6758
  }
6716
6759
  };
6717
6760
  //#endregion
6718
- 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 };