rayzee 7.4.0 → 7.4.1

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
@@ -989,8 +989,8 @@ var wr = class {
989
989
  albedo: this.writeAlbedo
990
990
  };
991
991
  }
992
- copyToReadTargets(e) {
993
- this._srcRegion.max.set(this.renderWidth, this.renderHeight), e.copyTextureToTexture(this.writeColor, this.readTarget.textures[0], this._srcRegion), e.copyTextureToTexture(this.writeNormalDepth, this.readTarget.textures[1], this._srcRegion), e.copyTextureToTexture(this.writeAlbedo, this.readTarget.textures[2], this._srcRegion);
992
+ copyToReadTargets(e, t = !0) {
993
+ this._srcRegion.max.set(this.renderWidth, this.renderHeight), e.copyTextureToTexture(this.writeColor, this.readTarget.textures[0], this._srcRegion), t && (e.copyTextureToTexture(this.writeNormalDepth, this.readTarget.textures[1], this._srcRegion), e.copyTextureToTexture(this.writeAlbedo, this.readTarget.textures[2], this._srcRegion));
994
994
  }
995
995
  clear(e) {
996
996
  if (!this.readTarget || !e) return;
@@ -7094,15 +7094,12 @@ var ws = 4, Ts = class extends qn {
7094
7094
  dispose() {
7095
7095
  this._attrs = {}, this.rayBuffer = null, this.rngBuffer = null, this.hitBuffer = null, this.capacity = 0;
7096
7096
  }
7097
- }, js = (e, t) => e.element(ks(t, Es.ORIGIN_META)).xyz, Ms = (e, t) => e.element(ks(t, Es.DIR_FLAGS)).xyz, Ns = (e, t) => ee(e.element(ks(t, Es.DIR_FLAGS)).w), Ps = (e, t) => e.element(ks(t, Es.THROUGHPUT_PDF)).xyz, Fs = (e, t) => e.element(ks(t, Es.THROUGHPUT_PDF)).w, Is = (e, t) => e.element(ks(t, Es.RADIANCE_ALPHA)), Ls = (e, t) => {
7098
- let n = B(e).mul(2);
7099
- return t === 0 ? n : n.add(t);
7100
- }, Rs = (e, t, n, r, i) => e.element(Ls(t, 0)).assign(H(fe(U(n.x, n.y)), fe(U(n.z, r)), pe(U(i.x, i.y)), pe(U(i.z, 0)))), zs = (e, t) => e.element(Ls(t, 0)), Bs = (e, t, n, r, i, a, o) => e.element(Ls(t, 1)).assign(H(B(n), B(r), pe(U(i, a)), B(o))), Vs = (e) => {
7097
+ }, js = (e, t) => e.element(ks(t, Es.ORIGIN_META)).xyz, Ms = (e, t) => e.element(ks(t, Es.DIR_FLAGS)).xyz, Ns = (e, t) => ee(e.element(ks(t, Es.DIR_FLAGS)).w), Ps = (e, t) => e.element(ks(t, Es.THROUGHPUT_PDF)).xyz, Fs = (e, t) => e.element(ks(t, Es.THROUGHPUT_PDF)).w, Is = (e, t) => e.element(ks(t, Es.RADIANCE_ALPHA)), Ls = (e) => B(e).mul(1), Rs = (e, t, n, r, i) => e.element(Ls(t)).assign(H(fe(U(n.x, n.y)), fe(U(n.z, r)), pe(U(i.x, i.y)), pe(U(i.z, 0)))), zs = (e, t) => e.element(Ls(t)), Bs = (e) => {
7101
7098
  let t = Ne(e.x), n = Ne(e.y);
7102
7099
  return G(W(t.x, t.y, n.x).mul(.5).add(.5), n.y);
7103
- }, Hs = (e) => W(Pe(e.z), Pe(e.w).x), Us = (e, t, n, r, i) => e.element(ks(t, Es.ORIGIN_META)).assign(G(n, je(B(r).bitOr(B(i).shiftLeft(8))))), Ws = (e, t, n, r) => e.element(ks(t, Es.DIR_FLAGS)).assign(G(n, je(r))), Gs = (e, t, n, r) => e.element(ks(t, Es.THROUGHPUT_PDF)).assign(G(n, r)), Ks = (e, t, n) => e.element(ks(t, Es.RADIANCE_ALPHA)).assign(n), qs = (e, t) => e.element(ks(t, Ds.DIST_TRI_BARY)).x, Js = (e, t) => ee(e.element(ks(t, Ds.DIST_TRI_BARY)).y), Ys = (e, t) => e.element(ks(t, Ds.DIST_TRI_BARY)).zw, Xs = (e, t) => e.element(ks(t, Ds.NORMAL_MAT)).xyz, Zs = (e, t) => B(ee(e.element(ks(t, Ds.NORMAL_MAT)).w).bitAnd(65535)), Qs = (e, t) => ee(e.element(ks(t, Ds.NORMAL_MAT)).w).shiftRight(16), $s = (e, t, n, r, i, a, o, s, c) => {
7100
+ }, Vs = (e) => W(Pe(e.z), Pe(e.w).x), Hs = (e, t, n, r, i) => e.element(ks(t, Es.ORIGIN_META)).assign(G(n, je(B(r).bitOr(B(i).shiftLeft(8))))), Us = (e, t, n, r) => e.element(ks(t, Es.DIR_FLAGS)).assign(G(n, je(r))), Ws = (e, t, n, r) => e.element(ks(t, Es.THROUGHPUT_PDF)).assign(G(n, r)), Gs = (e, t, n) => e.element(ks(t, Es.RADIANCE_ALPHA)).assign(n), Ks = (e, t) => e.element(ks(t, Ds.DIST_TRI_BARY)).x, qs = (e, t) => ee(e.element(ks(t, Ds.DIST_TRI_BARY)).y), Js = (e, t) => e.element(ks(t, Ds.DIST_TRI_BARY)).zw, Ys = (e, t) => e.element(ks(t, Ds.NORMAL_MAT)).xyz, Xs = (e, t) => B(ee(e.element(ks(t, Ds.NORMAL_MAT)).w).bitAnd(65535)), Zs = (e, t, n, r, i, a, o, s, c) => {
7104
7101
  e.element(ks(t, Ds.DIST_TRI_BARY)).assign(G(n, je(r), i, a)), e.element(ks(t, Ds.NORMAL_MAT)).assign(G(o, je(s.bitOr(c.shiftLeft(16)))));
7105
- }, ec = (e, t) => {
7102
+ }, Qs = (e, t) => {
7106
7103
  let n = e.element(ks(t, Es.MEDIUM_STACK)), r = ee(n.x);
7107
7104
  return {
7108
7105
  stackDepth: r.bitAnd(255),
@@ -7112,17 +7109,17 @@ var ws = 4, Ts = class extends qn {
7112
7109
  ior2: n.z,
7113
7110
  ior3: n.w
7114
7111
  };
7115
- }, tc = (e, t, n, r, i, a, o, s = B(0)) => e.element(ks(t, Es.MEDIUM_STACK)).assign(G(je(n.bitOr(r.shiftLeft(8)).bitOr(s.shiftLeft(16))), i, a, o)), nc = (e, t) => e.element(ks(t, Es.MEDIUM_SIGMA_A)).xyz, rc = (e, t, n) => e.element(ks(t, Es.MEDIUM_SIGMA_A)).assign(G(n, 0)), ic = (e, t) => N(ee(e.element(ks(t, Es.ORIGIN_META)).w).bitAnd(255)), ac = (e, t) => N(ee(e.element(ks(t, Es.ORIGIN_META)).w).shiftRight(8).bitAnd(255)), oc = (e, t) => {
7112
+ }, $s = (e, t, n, r, i, a, o, s = B(0)) => e.element(ks(t, Es.MEDIUM_STACK)).assign(G(je(n.bitOr(r.shiftLeft(8)).bitOr(s.shiftLeft(16))), i, a, o)), ec = (e, t) => e.element(ks(t, Es.MEDIUM_SIGMA_A)).xyz, tc = (e, t, n) => e.element(ks(t, Es.MEDIUM_SIGMA_A)).assign(G(n, 0)), nc = (e, t) => N(ee(e.element(ks(t, Es.ORIGIN_META)).w).bitAnd(255)), rc = (e, t) => N(ee(e.element(ks(t, Es.ORIGIN_META)).w).shiftRight(8).bitAnd(255)), ic = (e, t) => {
7116
7113
  let n = e.element(ks(t, Es.SSS_SIGMA_S));
7117
7114
  return {
7118
7115
  sigmaS: n.xyz,
7119
7116
  g: n.w
7120
7117
  };
7121
- }, sc = (e, t, n, r) => e.element(ks(t, Es.SSS_SIGMA_S)).assign(G(n, r)), cc = {
7118
+ }, ac = (e, t, n, r) => e.element(ks(t, Es.SSS_SIGMA_S)).assign(G(n, r)), oc = {
7122
7119
  ACTIVE_RAY_COUNT: 0,
7123
7120
  ENTERING_COUNT: 1,
7124
7121
  COUNT: 2
7125
- }, lc = {
7122
+ }, sc = {
7126
7123
  BOUNCE_MASK: 255,
7127
7124
  ACTIVE: 256,
7128
7125
  SPECULAR: 512,
@@ -7132,12 +7129,12 @@ var ws = 4, Ts = class extends qn {
7132
7129
  HAS_HIT_OPAQUE: 65536,
7133
7130
  AUX_LOCKED: 1 << 17,
7134
7131
  REDIRECTED: 1 << 18
7135
- }, uc = class {
7132
+ }, cc = class {
7136
7133
  constructor(e = 0) {
7137
7134
  this.capacity = 0, this.counters = null, this.activeIndices = null, this.activeIndicesRO = null, this.pingPong = 0, e > 0 && this.allocate(e);
7138
7135
  }
7139
7136
  allocate(e) {
7140
- this.dispose(), this.capacity = e, this._countersAttr = new o(new Uint32Array(cc.COUNT), 1), this.counters = Ce(this._countersAttr, "uint").toAtomic(), this.MAX_BOUNCE_SNAPSHOTS = 32, this._bounceCountsAttr = new o(new Uint32Array(this.MAX_BOUNCE_SNAPSHOTS), 1), this.bounceCounts = Ce(this._bounceCountsAttr, "uint");
7137
+ this.dispose(), this.capacity = e, this._countersAttr = new o(new Uint32Array(oc.COUNT), 1), this.counters = Ce(this._countersAttr, "uint").toAtomic(), this.MAX_BOUNCE_SNAPSHOTS = 32, this._bounceCountsAttr = new o(new Uint32Array(this.MAX_BOUNCE_SNAPSHOTS), 1), this.bounceCounts = Ce(this._bounceCountsAttr, "uint");
7141
7138
  let t = new o(new Uint32Array(e), 1), n = new o(new Uint32Array(e), 1);
7142
7139
  this._attrA = t, this._attrB = n, this.activeIndices = {
7143
7140
  a: Ce(t, "uint"),
@@ -7146,7 +7143,7 @@ var ws = 4, Ts = class extends qn {
7146
7143
  a: Ce(t, "uint").toReadOnly(),
7147
7144
  b: Ce(n, "uint").toReadOnly()
7148
7145
  }, this.pingPong = 0;
7149
- let r = cc.COUNT * 4 + e * 4 * 2;
7146
+ let r = oc.COUNT * 4 + e * 4 * 2;
7150
7147
  console.log(`QueueManager: Allocated capacity=${e}, total=${(r / (1024 * 1024)).toFixed(1)} MB`);
7151
7148
  }
7152
7149
  resize(e) {
@@ -7182,12 +7179,12 @@ var ws = 4, Ts = class extends qn {
7182
7179
  dispose() {
7183
7180
  this.counters = null, this.activeIndices = null, this.activeIndicesRO = null, this.capacity = 0;
7184
7181
  }
7185
- }, dc = {
7182
+ }, lc = {
7186
7183
  [Ft]: 4,
7187
7184
  [It]: 3,
7188
7185
  [Lt]: 2,
7189
7186
  [Bt]: 1
7190
- }, fc = {
7187
+ }, uc = {
7191
7188
  [q]: 4,
7192
7189
  [ut]: 2,
7193
7190
  [Qt]: 1,
@@ -7197,25 +7194,28 @@ var ws = 4, Ts = class extends qn {
7197
7194
  [$t]: 4,
7198
7195
  [dt]: 4
7199
7196
  };
7200
- function pc(e) {
7201
- return (dc[e.format] ?? 4) * (fc[e.type] ?? 4);
7197
+ function dc(e) {
7198
+ return (lc[e.format] ?? 4) * (uc[e.type] ?? 4);
7202
7199
  }
7203
- function mc(e) {
7200
+ function fc(e) {
7204
7201
  return e?.array?.byteLength || 0;
7205
7202
  }
7206
- function hc(e) {
7203
+ function pc(e) {
7207
7204
  if (!e) return 0;
7208
7205
  if (e.isRenderTarget) {
7209
7206
  let t = e.textures?.length ? e.textures : [e.texture], n = e.width || 0, r = e.height || 0, i = e.depth || 1, a = 0;
7210
- for (let e of t) e && (a += n * r * i * pc(e));
7207
+ for (let e of t) e && (a += n * r * i * dc(e));
7211
7208
  return a;
7212
7209
  }
7213
7210
  let t = e.image || {}, n = t.width ?? e.width ?? 0, r = t.height ?? e.height ?? 0, i = t.depth ?? 1;
7214
- return n * r * i * pc(e);
7211
+ return n * r * i * dc(e);
7215
7212
  }
7216
- var gc = class {
7217
- constructor() {
7218
- this._providers = [], this.current = 0, this.peak = 0, this.byCategory = {};
7213
+ var mc = class {
7214
+ constructor(e = null) {
7215
+ this._providers = [], this._renderer = e, this.current = 0, this.peak = 0, this.byCategory = {};
7216
+ }
7217
+ setRenderer(e) {
7218
+ this._renderer = e;
7219
7219
  }
7220
7220
  register(e, t) {
7221
7221
  this._providers.push({
@@ -7244,7 +7244,22 @@ var gc = class {
7244
7244
  };
7245
7245
  }
7246
7246
  _resourceBytes(e, t) {
7247
- return e ? typeof e.bytes == "number" && !e.isTexture && !e.isRenderTarget ? e.bytes : e.array && e.array.byteLength != null ? t.has(e.array) ? 0 : (t.add(e.array), e.array.byteLength) : e.isRenderTarget || e.isTexture ? t.has(e) ? 0 : (t.add(e), hc(e)) : 0 : 0;
7247
+ return e ? typeof e.bytes == "number" && !e.isTexture && !e.isRenderTarget ? e.bytes : e.array && e.array.byteLength != null ? t.has(e.array) ? 0 : (t.add(e.array), e.array.byteLength) : e.isRenderTarget || e.isTexture ? t.has(e) ? 0 : (t.add(e), this._residentTextureBytes(e)) : 0 : 0;
7248
+ }
7249
+ _isResident(e) {
7250
+ let t = this._renderer?.backend;
7251
+ if (!t || typeof t.get != "function") return !0;
7252
+ if (typeof t.has == "function" && !t.has(e)) return !1;
7253
+ let n = t.get(e);
7254
+ return !!(n && (n.texture || n.gpuTexture));
7255
+ }
7256
+ _residentTextureBytes(e) {
7257
+ if (e.isRenderTarget) {
7258
+ let t = e.textures?.length ? e.textures : [e.texture], n = e.width || 0, r = e.height || 0, i = e.depth || 1, a = 0;
7259
+ for (let e of t) e && this._isResident(e) && (a += n * r * i * dc(e));
7260
+ return a;
7261
+ }
7262
+ return this._isResident(e) ? pc(e) : 0;
7248
7263
  }
7249
7264
  resetPeak() {
7250
7265
  this.peak = this.current;
@@ -7253,7 +7268,7 @@ var gc = class {
7253
7268
  let e = (e) => (e / 1048576).toFixed(1), t = Object.entries(this.byCategory).map(([t, n]) => `${t}=${e(n)}`);
7254
7269
  return `VRAM current=${e(this.current)}MB peak=${e(this.peak)}MB [${t.join(" ")}]`;
7255
7270
  }
7256
- }, _c = {
7271
+ }, hc = {
7257
7272
  generate: [
7258
7273
  16,
7259
7274
  16,
@@ -7299,10 +7314,10 @@ var gc = class {
7299
7314
  16,
7300
7315
  1
7301
7316
  ]
7302
- }, vc = class {
7317
+ }, gc = class {
7303
7318
  constructor(e) {
7304
7319
  this.renderer = e, this.kernels = /* @__PURE__ */ new Map(), this.workgroupSizes = /* @__PURE__ */ new Map(), this.timing = /* @__PURE__ */ new Map(), this.profiling = !1, this.profile = /* @__PURE__ */ new Map();
7305
- for (let [e, t] of Object.entries(_c)) this.workgroupSizes.set(e, t);
7320
+ for (let [e, t] of Object.entries(hc)) this.workgroupSizes.set(e, t);
7306
7321
  }
7307
7322
  register(e, t) {
7308
7323
  this.kernels.set(e, t), this.timing.set(e, {
@@ -7396,7 +7411,7 @@ var gc = class {
7396
7411
  dispose() {
7397
7412
  this.kernels.clear(), this.timing.clear(), this.profile.clear();
7398
7413
  }
7399
- }, yc = 32, bc = 512, xc = 4, Sc = 8, Cc = 1e8, wc = () => y("int", yc).toVar(), Tc = K("\n fn RayTriangleGeometry( rayOrigin: vec3f, rayDir: vec3f, pA: vec3f, pB: vec3f, pC: vec3f, closestHitDst: f32, woopParams: vec4f ) -> vec4f {\n\n // Returns vec4(t, u, v, hit) where hit > 0.5 means intersection.\n // woopParams: (Sx, Sy, Sz, bitcast<f32>(packed kx|ky<<2|kz<<4))\n var result = vec4f( 1e20f, 0.0f, 0.0f, 0.0f );\n\n let Sx = woopParams.x;\n let Sy = woopParams.y;\n let Sz = woopParams.z;\n // Packed as regular f32 (values 0–42), not bitcast — avoids subnormal FTZ on Apple GPUs.\n let packed = i32( woopParams.w );\n let kx = packed & 3;\n let ky = ( packed >> 2 ) & 3;\n let kz = ( packed >> 4 ) & 3;\n\n let A = pA - rayOrigin;\n let B = pB - rayOrigin;\n let C = pC - rayOrigin;\n\n let Akz = A[ kz ];\n let Bkz = B[ kz ];\n let Ckz = C[ kz ];\n\n let Ax = A[ kx ] - Sx * Akz;\n let Ay = A[ ky ] - Sy * Akz;\n let Bx = B[ kx ] - Sx * Bkz;\n let By = B[ ky ] - Sy * Bkz;\n let Cx = C[ kx ] - Sx * Ckz;\n let Cy = C[ ky ] - Sy * Ckz;\n\n // Edge function tests — all three must share sign (or be exactly zero) for hit.\n let U = Cx * By - Cy * Bx;\n let V = Ax * Cy - Ay * Cx;\n let W = Bx * Ay - By * Ax;\n\n let neg = U < 0.0f || V < 0.0f || W < 0.0f;\n let pos = U > 0.0f || V > 0.0f || W > 0.0f;\n if ( !( neg && pos ) ) {\n\n let det = U + V + W;\n if ( det != 0.0f ) {\n\n let T = U * ( Sz * Akz ) + V * ( Sz * Bkz ) + W * ( Sz * Ckz );\n\n // Sign-aware bounds check on t (multiply both sides by sign(det) once).\n let detSign = select( -1.0f, 1.0f, det > 0.0f );\n let tSigned = T * detSign;\n let detAbs = abs( det );\n\n if ( tSigned > 0.0f && tSigned < closestHitDst * detAbs ) {\n\n // Match Möller-Trumbore convention: u = weight of B, v = weight of C.\n // In Woop's edge functions, U → weight of A, V → weight of B, W → weight of C.\n let invDet = 1.0f / det;\n result = vec4f( T * invDet, V * invDet, W * invDet, 1.0f );\n\n }\n\n }\n\n }\n\n return result;\n\n }\n"), Ec = K("\n fn computeWoopRayParams( rayDir: vec3f ) -> vec4f {\n\n let absDir = abs( rayDir );\n\n // kz = argmax(|dir|)\n var kz: i32 = 0;\n if ( absDir.y >= absDir.x ) { kz = 1; }\n if ( absDir.z >= absDir[ u32( kz ) ] ) { kz = 2; }\n\n var kx: i32 = ( kz + 1 ) % 3;\n var ky: i32 = ( kx + 1 ) % 3;\n\n // Preserve triangle winding when the dominant axis component is negative.\n if ( rayDir[ u32( kz ) ] < 0.0f ) {\n let tmp = kx;\n kx = ky;\n ky = tmp;\n }\n\n let dz = rayDir[ u32( kz ) ];\n let Sx = rayDir[ u32( kx ) ] / dz;\n let Sy = rayDir[ u32( ky ) ] / dz;\n let Sz = 1.0f / dz;\n\n let packed = kx | ( ky << 2 ) | ( kz << 4 );\n return vec4f( Sx, Sy, Sz, f32( packed ) );\n\n }\n"), Dc = K("\n fn fastRayAABBDst( rayOrigin: vec3f, invDir: vec3f, boxMin: vec3f, boxMax: vec3f ) -> f32 {\n\n let t1 = ( boxMin - rayOrigin ) * invDir;\n let t2 = ( boxMax - rayOrigin ) * invDir;\n\n let tmin = min( t1, t2 );\n let tmax = max( t1, t2 );\n\n let tNear = max( max( tmin.x, tmin.y ), tmin.z );\n let tFar = min( min( tmax.x, tmax.y ), tmax.z ) * 1.00000024f; // Robust traversal: 2 ULP padding (Ize 2013)\n\n let isHit = tNear <= tFar && tFar > 0.0f;\n return select( 1e20f, max( tNear, 0.0f ), isHit );\n\n }\n"), Oc = f(([e, t, n, r]) => {
7414
+ }, _c = 32, vc = 512, yc = 4, bc = 8, xc = 1e8, Sc = () => y("int", _c).toVar(), Cc = K("\n fn RayTriangleGeometry( rayOrigin: vec3f, rayDir: vec3f, pA: vec3f, pB: vec3f, pC: vec3f, closestHitDst: f32, woopParams: vec4f ) -> vec4f {\n\n // Returns vec4(t, u, v, hit) where hit > 0.5 means intersection.\n // woopParams: (Sx, Sy, Sz, bitcast<f32>(packed kx|ky<<2|kz<<4))\n var result = vec4f( 1e20f, 0.0f, 0.0f, 0.0f );\n\n let Sx = woopParams.x;\n let Sy = woopParams.y;\n let Sz = woopParams.z;\n // Packed as regular f32 (values 0–42), not bitcast — avoids subnormal FTZ on Apple GPUs.\n let packed = i32( woopParams.w );\n let kx = packed & 3;\n let ky = ( packed >> 2 ) & 3;\n let kz = ( packed >> 4 ) & 3;\n\n let A = pA - rayOrigin;\n let B = pB - rayOrigin;\n let C = pC - rayOrigin;\n\n let Akz = A[ kz ];\n let Bkz = B[ kz ];\n let Ckz = C[ kz ];\n\n let Ax = A[ kx ] - Sx * Akz;\n let Ay = A[ ky ] - Sy * Akz;\n let Bx = B[ kx ] - Sx * Bkz;\n let By = B[ ky ] - Sy * Bkz;\n let Cx = C[ kx ] - Sx * Ckz;\n let Cy = C[ ky ] - Sy * Ckz;\n\n // Edge function tests — all three must share sign (or be exactly zero) for hit.\n let U = Cx * By - Cy * Bx;\n let V = Ax * Cy - Ay * Cx;\n let W = Bx * Ay - By * Ax;\n\n let neg = U < 0.0f || V < 0.0f || W < 0.0f;\n let pos = U > 0.0f || V > 0.0f || W > 0.0f;\n if ( !( neg && pos ) ) {\n\n let det = U + V + W;\n if ( det != 0.0f ) {\n\n let T = U * ( Sz * Akz ) + V * ( Sz * Bkz ) + W * ( Sz * Ckz );\n\n // Sign-aware bounds check on t (multiply both sides by sign(det) once).\n let detSign = select( -1.0f, 1.0f, det > 0.0f );\n let tSigned = T * detSign;\n let detAbs = abs( det );\n\n if ( tSigned > 0.0f && tSigned < closestHitDst * detAbs ) {\n\n // Match Möller-Trumbore convention: u = weight of B, v = weight of C.\n // In Woop's edge functions, U → weight of A, V → weight of B, W → weight of C.\n let invDet = 1.0f / det;\n result = vec4f( T * invDet, V * invDet, W * invDet, 1.0f );\n\n }\n\n }\n\n }\n\n return result;\n\n }\n"), wc = K("\n fn computeWoopRayParams( rayDir: vec3f ) -> vec4f {\n\n let absDir = abs( rayDir );\n\n // kz = argmax(|dir|)\n var kz: i32 = 0;\n if ( absDir.y >= absDir.x ) { kz = 1; }\n if ( absDir.z >= absDir[ u32( kz ) ] ) { kz = 2; }\n\n var kx: i32 = ( kz + 1 ) % 3;\n var ky: i32 = ( kx + 1 ) % 3;\n\n // Preserve triangle winding when the dominant axis component is negative.\n if ( rayDir[ u32( kz ) ] < 0.0f ) {\n let tmp = kx;\n kx = ky;\n ky = tmp;\n }\n\n let dz = rayDir[ u32( kz ) ];\n let Sx = rayDir[ u32( kx ) ] / dz;\n let Sy = rayDir[ u32( ky ) ] / dz;\n let Sz = 1.0f / dz;\n\n let packed = kx | ( ky << 2 ) | ( kz << 4 );\n return vec4f( Sx, Sy, Sz, f32( packed ) );\n\n }\n"), Tc = K("\n fn fastRayAABBDst( rayOrigin: vec3f, invDir: vec3f, boxMin: vec3f, boxMax: vec3f ) -> f32 {\n\n let t1 = ( boxMin - rayOrigin ) * invDir;\n let t2 = ( boxMax - rayOrigin ) * invDir;\n\n let tmin = min( t1, t2 );\n let tmax = max( t1, t2 );\n\n let tNear = max( max( tmin.x, tmin.y ), tmin.z );\n let tFar = min( min( tmax.x, tmax.y ), tmax.z ) * 1.00000024f; // Robust traversal: 2 ULP padding (Ize 2013)\n\n let isHit = tNear <= tFar && tFar > 0.0f;\n return select( 1e20f, max( tNear, 0.0f ), isHit );\n\n }\n"), Ec = f(([e, t, n, r]) => {
7400
7415
  let i = r ?? T(!1), a = mi({
7401
7416
  didHit: !1,
7402
7417
  dst: M(0x56bc75e2d63100000),
@@ -7407,12 +7422,12 @@ var gc = class {
7407
7422
  meshIndex: N(-1),
7408
7423
  boxTests: N(0),
7409
7424
  triTests: N(0)
7410
- }).toVar(), o = N(-1).toVar(), s = M(0).toVar(), c = M(0).toVar(), l = wc(), u = N(1).toVar();
7425
+ }).toVar(), o = N(-1).toVar(), s = M(0).toVar(), c = M(0).toVar(), l = Sc(), u = N(1).toVar();
7411
7426
  l.element(N(0)).assign(N(0));
7412
- let f = I(W(1), ve(e.direction), de(e.direction, W(0))), h = I(W(1).div(e.direction), W(Cc).mul(f), ae(_(e.direction), W(1e-8))).toVar(), g = e.origin, v = e.direction, y = Ec({ rayDir: v }).toVar(), b = N(0).toVar();
7413
- return m(u.greaterThan(N(0)).and(b.lessThan(N(bc))), () => {
7427
+ let f = I(W(1), ve(e.direction), de(e.direction, W(0))), h = I(W(1).div(e.direction), W(xc).mul(f), ae(_(e.direction), W(1e-8))).toVar(), g = e.origin, v = e.direction, y = wc({ rayDir: v }).toVar(), b = N(0).toVar();
7428
+ return m(u.greaterThan(N(0)).and(b.lessThan(N(vc))), () => {
7414
7429
  b.addAssign(1), u.subAssign(1);
7415
- let e = l.element(u).toVar(), r = $(t, e, N(0), N(xc));
7430
+ let e = l.element(u).toVar(), r = $(t, e, N(0), N(yc));
7416
7431
  a.boxTests.addAssign(1), p(r.w.lessThan(0), () => {
7417
7432
  p(r.w.greaterThan(M(-1.5)), () => {
7418
7433
  let e = N(r.x).toVar(), t = N(r.y).toVar();
@@ -7421,7 +7436,7 @@ var gc = class {
7421
7436
  end: t
7422
7437
  }, ({ i: t }) => {
7423
7438
  a.triTests.addAssign(1);
7424
- let r = e.add(t).toVar(), l = $(n, r, N(0), N(Sc)).xyz, u = $(n, r, N(1), N(Sc)).xyz, d = $(n, r, N(2), N(Sc)).xyz, f = Tc({
7439
+ let r = e.add(t).toVar(), l = $(n, r, N(0), N(bc)).xyz, u = $(n, r, N(1), N(bc)).xyz, d = $(n, r, N(2), N(bc)).xyz, f = Cc({
7425
7440
  rayOrigin: g,
7426
7441
  rayDir: v,
7427
7442
  pA: l,
@@ -7431,7 +7446,7 @@ var gc = class {
7431
7446
  woopParams: y
7432
7447
  });
7433
7448
  p(f.w.greaterThan(.5), () => {
7434
- let e = f.x, t = f.y, l = f.z, u = $(n, r, N(3), N(Sc)).xyz, d = $(n, r, N(4), N(Sc)).xyz, m = $(n, r, N(5), N(Sc)), h = m.xyz, g = N(m.w).toVar(), _ = M(1).sub(t).sub(l), y = v.dot(L(u.mul(_).add(d.mul(t)).add(h.mul(l))));
7449
+ let e = f.x, t = f.y, l = f.z, u = $(n, r, N(3), N(bc)).xyz, d = $(n, r, N(4), N(bc)).xyz, m = $(n, r, N(5), N(bc)), h = m.xyz, g = N(m.w).toVar(), _ = M(1).sub(t).sub(l), y = v.dot(L(u.mul(_).add(d.mul(t)).add(h.mul(l))));
7435
7450
  p(i.or(g.equal(N(2))).or(g.equal(N(0)).and(y.lessThan(-1e-4))).or(g.equal(N(1)).and(y.greaterThan(1e-4))), () => {
7436
7451
  a.didHit.assign(!0), a.dst.assign(e), o.assign(r), s.assign(t), c.assign(l);
7437
7452
  });
@@ -7440,17 +7455,17 @@ var gc = class {
7440
7455
  d();
7441
7456
  });
7442
7457
  }).Else(() => {
7443
- p(r.z.greaterThan(.5).and(u.lessThan(N(yc))), () => {
7458
+ p(r.z.greaterThan(.5).and(u.lessThan(N(_c))), () => {
7444
7459
  l.element(u).assign(N(r.x)), u.addAssign(1);
7445
7460
  });
7446
7461
  });
7447
7462
  }).Else(() => {
7448
- let n = $(t, e, N(1), N(xc)), i = $(t, e, N(2), N(xc)), o = $(t, e, N(3), N(xc)), s = N(r.w).toVar(), c = N(n.w).toVar(), d = Dc({
7463
+ let n = $(t, e, N(1), N(yc)), i = $(t, e, N(2), N(yc)), o = $(t, e, N(3), N(yc)), s = N(r.w).toVar(), c = N(n.w).toVar(), d = Tc({
7449
7464
  rayOrigin: g,
7450
7465
  invDir: h,
7451
7466
  boxMin: r.xyz,
7452
7467
  boxMax: n.xyz
7453
- }).toVar(), f = Dc({
7468
+ }).toVar(), f = Tc({
7454
7469
  rayOrigin: g,
7455
7470
  invDir: h,
7456
7471
  boxMin: i.xyz,
@@ -7458,21 +7473,21 @@ var gc = class {
7458
7473
  }).toVar();
7459
7474
  p(le(d, f).lessThan(a.dst), () => {
7460
7475
  let e = d.lessThan(f);
7461
- p(R(e, f, d).lessThan(a.dst).and(u.lessThan(N(yc))), () => {
7476
+ p(R(e, f, d).lessThan(a.dst).and(u.lessThan(N(_c))), () => {
7462
7477
  l.element(u).assign(R(e, c, s)), u.addAssign(1);
7463
- }), p(u.lessThan(N(yc)), () => {
7478
+ }), p(u.lessThan(N(_c)), () => {
7464
7479
  l.element(u).assign(R(e, s, c)), u.addAssign(1);
7465
7480
  });
7466
7481
  });
7467
7482
  });
7468
7483
  }), p(a.didHit, () => {
7469
7484
  a.hitPoint.assign(e.origin.add(e.direction.mul(a.dst)));
7470
- let t = M(1).sub(s).sub(c), r = $(n, o, N(3), N(Sc)).xyz, i = $(n, o, N(4), N(Sc)).xyz, l = $(n, o, N(5), N(Sc)).xyz;
7485
+ let t = M(1).sub(s).sub(c), r = $(n, o, N(3), N(bc)).xyz, i = $(n, o, N(4), N(bc)).xyz, l = $(n, o, N(5), N(bc)).xyz;
7471
7486
  a.normal.assign(L(r.mul(t).add(i.mul(s)).add(l.mul(c))));
7472
- let u = $(n, o, N(6), N(Sc)), d = $(n, o, N(7), N(Sc));
7487
+ let u = $(n, o, N(6), N(bc)), d = $(n, o, N(7), N(bc));
7473
7488
  a.uv.assign(u.xy.mul(t).add(u.zw.mul(s)).add(d.xy.mul(c))), a.materialIndex.assign(N(d.z)), a.meshIndex.assign(N(d.w)), a.triangleIndex.assign(o);
7474
7489
  }), a;
7475
- }), kc = f(([e, t, n, r]) => {
7490
+ }), Dc = f(([e, t, n, r]) => {
7476
7491
  let i = mi({
7477
7492
  didHit: !1,
7478
7493
  dst: r,
@@ -7483,12 +7498,12 @@ var gc = class {
7483
7498
  meshIndex: N(-1),
7484
7499
  boxTests: N(0),
7485
7500
  triTests: N(0)
7486
- }).toVar(), a = wc(), o = N(1).toVar();
7501
+ }).toVar(), a = Sc(), o = N(1).toVar();
7487
7502
  a.element(N(0)).assign(N(0));
7488
- let s = I(W(1), ve(e.direction), de(e.direction, W(0))), c = I(W(1).div(e.direction), W(Cc).mul(s), ae(_(e.direction), W(1e-8))).toVar(), l = Ec({ rayDir: e.direction }).toVar(), u = N(0).toVar();
7489
- return m(o.greaterThan(N(0)).and(i.didHit.not()).and(u.lessThan(N(bc))), () => {
7503
+ let s = I(W(1), ve(e.direction), de(e.direction, W(0))), c = I(W(1).div(e.direction), W(xc).mul(s), ae(_(e.direction), W(1e-8))).toVar(), l = wc({ rayDir: e.direction }).toVar(), u = N(0).toVar();
7504
+ return m(o.greaterThan(N(0)).and(i.didHit.not()).and(u.lessThan(N(vc))), () => {
7490
7505
  u.addAssign(1), o.subAssign(1);
7491
- let r = a.element(o).toVar(), s = $(t, r, N(0), N(xc));
7506
+ let r = a.element(o).toVar(), s = $(t, r, N(0), N(yc));
7492
7507
  p(s.w.lessThan(0), () => {
7493
7508
  p(s.w.greaterThan(M(-1.5)), () => {
7494
7509
  let t = N(s.x).toVar(), r = N(s.y).toVar();
@@ -7496,7 +7511,7 @@ var gc = class {
7496
7511
  start: N(0),
7497
7512
  end: r
7498
7513
  }, ({ i: r }) => {
7499
- let a = t.add(r).toVar(), o = $(n, a, N(0), N(Sc)).xyz, s = $(n, a, N(1), N(Sc)).xyz, c = $(n, a, N(2), N(Sc)).xyz, u = Tc({
7514
+ let a = t.add(r).toVar(), o = $(n, a, N(0), N(bc)).xyz, s = $(n, a, N(1), N(bc)).xyz, c = $(n, a, N(2), N(bc)).xyz, u = Cc({
7500
7515
  rayOrigin: e.origin,
7501
7516
  rayDir: e.direction,
7502
7517
  pA: o,
@@ -7506,22 +7521,22 @@ var gc = class {
7506
7521
  woopParams: l
7507
7522
  });
7508
7523
  p(u.w.greaterThan(.5), () => {
7509
- let t = $(n, a, N(7), N(Sc));
7524
+ let t = $(n, a, N(7), N(bc));
7510
7525
  i.didHit.assign(!0), i.dst.assign(u.x), i.materialIndex.assign(N(t.z)), i.meshIndex.assign(N(t.w)), i.hitPoint.assign(e.origin.add(e.direction.mul(u.x))), i.uv.assign(U(u.y, u.z)), i.triangleIndex.assign(a), d();
7511
7526
  });
7512
7527
  });
7513
7528
  }).Else(() => {
7514
- p(s.z.greaterThan(.5).and(o.lessThan(N(yc))), () => {
7529
+ p(s.z.greaterThan(.5).and(o.lessThan(N(_c))), () => {
7515
7530
  a.element(o).assign(N(s.x)), o.addAssign(1);
7516
7531
  });
7517
7532
  });
7518
7533
  }).Else(() => {
7519
- let n = $(t, r, N(1), N(xc)), l = $(t, r, N(2), N(xc)), u = $(t, r, N(3), N(xc)), d = N(s.w).toVar(), f = N(n.w).toVar(), m = Dc({
7534
+ let n = $(t, r, N(1), N(yc)), l = $(t, r, N(2), N(yc)), u = $(t, r, N(3), N(yc)), d = N(s.w).toVar(), f = N(n.w).toVar(), m = Tc({
7520
7535
  rayOrigin: e.origin,
7521
7536
  invDir: c,
7522
7537
  boxMin: s.xyz,
7523
7538
  boxMax: n.xyz
7524
- }).toVar(), h = Dc({
7539
+ }).toVar(), h = Tc({
7525
7540
  rayOrigin: e.origin,
7526
7541
  invDir: c,
7527
7542
  boxMin: l.xyz,
@@ -7529,15 +7544,15 @@ var gc = class {
7529
7544
  }).toVar();
7530
7545
  p(le(m, h).lessThan(i.dst), () => {
7531
7546
  let e = m.lessThan(h);
7532
- p(R(e, h, m).lessThan(i.dst).and(o.lessThan(N(yc))), () => {
7547
+ p(R(e, h, m).lessThan(i.dst).and(o.lessThan(N(_c))), () => {
7533
7548
  a.element(o).assign(R(e, f, d)), o.addAssign(1);
7534
- }), p(o.lessThan(N(yc)), () => {
7549
+ }), p(o.lessThan(N(_c)), () => {
7535
7550
  a.element(o).assign(R(e, d, f)), o.addAssign(1);
7536
7551
  });
7537
7552
  });
7538
7553
  });
7539
7554
  }), i;
7540
- }), Ac = f(([e, t, n, r, i, a, o, s, c, l, u]) => {
7555
+ }), Oc = f(([e, t, n, r, i, a, o, s, c, l, u]) => {
7541
7556
  let d = W(e.xy, 1), f = r.mul(G(d, 1)), m = L(ce(n[0].xyz, n[1].xyz, n[2].xyz).mul(f.xyz.div(f.w))).toVar(), h = W(n[3]).toVar(), g = h.toVar(), _ = m.toVar();
7542
7557
  return p(i.and(a.greaterThan(0)).and(o.lessThan(64)).and(s.greaterThan(.001)), () => {
7543
7558
  let e = a.div(o).mul(.001).mul(c).mul(l), r = Ln(t), i = r.x.mul(u.max(.01)), d = r.y, f = L(W(n[0])), p = L(W(n[1])), v = f.mul(i).add(p.mul(d)).mul(e);
@@ -7547,7 +7562,7 @@ var gc = class {
7547
7562
  direction: _
7548
7563
  });
7549
7564
  });
7550
- function jc(e) {
7565
+ function kc(e) {
7551
7566
  let { rayBufferRW: t, rngBufferRW: n, gBufferRW: r, resolution: i, frame: a, cameraWorldMatrix: o, cameraProjectionMatrixInverse: s, enableDOF: c, focalLength: l, aperture: u, focusDistance: d, sceneScale: m, apertureScale: h, anamorphicRatio: g, renderWidth: _, renderHeight: v, transmissiveBounces: y, transparentBackground: b, auxGBufferEnabled: x } = e, S = x.greaterThan(B(0));
7552
7567
  return f(() => {
7553
7568
  let e = N(ze.x).mul(16).add(N(oe.x)), f = N(ze.y).mul(16).add(N(oe.y));
@@ -7558,51 +7573,51 @@ function jc(e) {
7558
7573
  pixelCoord: _,
7559
7574
  rayIndex: N(0),
7560
7575
  frame: a
7561
- }).toVar() }).toVar(), T = Wn(_, N(0), N(1), w, i, a).toVar(), E = U(2).div(i), D = T.sub(.5).mul(E), O = C.add(D), k = ui.wrap(Ac(O, w, o, s, c, l, u, d, m, h, g));
7562
- Us(t, x, k.origin, N(0), N(0)), Ws(t, x, k.direction, B(lc.ACTIVE)), Gs(t, x, G(1, 1, 1, 0).xyz, M(0)), Ks(t, x, G(W(0), R(b, M(1), M(0)))), p(S, () => {
7563
- Rs(r, B(v), W(0, 0, 1), M(1), W(0)), Bs(r, B(v), B(0), B(0), M(0), M(0), B(0));
7564
- }), tc(t, x, B(0), B(y), M(1), M(1), M(1)), n.element(x).assign(w);
7576
+ }).toVar() }).toVar(), T = Wn(_, N(0), N(1), w, i, a).toVar(), E = U(2).div(i), D = T.sub(.5).mul(E), O = C.add(D), k = ui.wrap(Oc(O, w, o, s, c, l, u, d, m, h, g));
7577
+ Hs(t, x, k.origin, N(0), N(0)), Us(t, x, k.direction, B(sc.ACTIVE)), Ws(t, x, G(1, 1, 1, 0).xyz, M(0)), Gs(t, x, G(W(0), R(b, M(1), M(0)))), p(S, () => {
7578
+ Rs(r, B(v), W(0, 0, 1), M(1), W(0));
7579
+ }), $s(t, x, B(0), B(y), M(1), M(1), M(1)), n.element(x).assign(w);
7565
7580
  });
7566
7581
  });
7567
7582
  }
7568
7583
  //#endregion
7569
7584
  //#region src/TSL/ExtendKernel.js
7570
- function Mc(e) {
7585
+ function Ac(e) {
7571
7586
  let { bvhBuffer: t, triangleBuffer: n, materialBuffer: r, rayBufferRO: i, hitBufferRW: a, activeIndicesRO: o, counters: s, maxRayCount: c } = e;
7572
7587
  return f(() => {
7573
- let e = re, r = s ? S(s.element(B(cc.ENTERING_COUNT))) : c;
7588
+ let e = re, r = s ? S(s.element(B(oc.ENTERING_COUNT))) : c;
7574
7589
  p(e.greaterThanEqual(r), () => {
7575
7590
  h();
7576
7591
  });
7577
7592
  let l = o.element(e), u = ui({
7578
7593
  origin: js(i, l).toVar(),
7579
7594
  direction: Ms(i, l).toVar()
7580
- }), d = ec(i, l).stackDepth.greaterThan(B(0)), f = mi.wrap(Oc(u, t, n, d)).toVar();
7581
- $s(a, l, f.dst, B(f.triangleIndex), f.uv.x, f.uv.y, f.normal, B(f.materialIndex), B(f.meshIndex));
7595
+ }), d = Qs(i, l).stackDepth.greaterThan(B(0)), f = mi.wrap(Ec(u, t, n, d)).toVar();
7596
+ Zs(a, l, f.dst, B(f.triangleIndex), f.uv.x, f.uv.y, f.normal, B(f.materialIndex), B(f.meshIndex));
7582
7597
  });
7583
7598
  }
7584
7599
  //#endregion
7585
7600
  //#region src/TSL/Environment.js
7586
- var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, environmentMatrix: mat4x4f ) -> vec2f {\n let d = normalize( ( environmentMatrix * vec4f( direction, 0.0f ) ).xyz );\n var uv = vec2f( atan2( d.z, d.x ), acos( d.y ) );\n uv = uv / vec2f( 6.28318530717958647692f, 3.14159265358979323846f );\n uv.x = uv.x + 0.5f;\n uv.y = 1.0f - uv.y;\n return uv;\n }\n"), Pc = /* @__PURE__ */ K("\n fn equirectUvToDirection( uv: vec2f, environmentMatrix: mat4x4f ) -> vec3f {\n let adjustedUv = vec2f( uv.x - 0.5f, 1.0f - uv.y );\n let theta = adjustedUv.x * 6.28318530717958647692f;\n let phi = adjustedUv.y * 3.14159265358979323846f;\n let sinPhi = sin( phi );\n let localDir = vec3f( sinPhi * cos( theta ), cos( phi ), sinPhi * sin( theta ) );\n return normalize( ( transpose( environmentMatrix ) * vec4f( localDir, 0.0f ) ).xyz );\n }\n"), Fc = f(([e, t, n, r, i, a]) => {
7601
+ var jc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, environmentMatrix: mat4x4f ) -> vec2f {\n let d = normalize( ( environmentMatrix * vec4f( direction, 0.0f ) ).xyz );\n var uv = vec2f( atan2( d.z, d.x ), acos( d.y ) );\n uv = uv / vec2f( 6.28318530717958647692f, 3.14159265358979323846f );\n uv.x = uv.x + 0.5f;\n uv.y = 1.0f - uv.y;\n return uv;\n }\n"), Mc = /* @__PURE__ */ K("\n fn equirectUvToDirection( uv: vec2f, environmentMatrix: mat4x4f ) -> vec3f {\n let adjustedUv = vec2f( uv.x - 0.5f, 1.0f - uv.y );\n let theta = adjustedUv.x * 6.28318530717958647692f;\n let phi = adjustedUv.y * 3.14159265358979323846f;\n let sinPhi = sin( phi );\n let localDir = vec3f( sinPhi * cos( theta ), cos( phi ), sinPhi * sin( theta ) );\n return normalize( ( transpose( environmentMatrix ) * vec4f( localDir, 0.0f ) ).xyz );\n }\n"), Nc = f(([e, t, n, r, i, a]) => {
7587
7602
  let o = G(0).toVar();
7588
7603
  return p(r.equal(0), () => {
7589
7604
  o.assign(G(0));
7590
7605
  }).Else(() => {
7591
- let s = Nc({
7606
+ let s = jc({
7592
7607
  direction: t,
7593
7608
  environmentMatrix: n
7594
7609
  }).toVar(), c = ke(e, s, 0).rgb.toVar(), l = ye(s.y.mul(Math.PI)).toVar(), u = A(c, Ni).mul(l), d = F(M(0), u.sub(i)).div(r), f = l.greaterThan(0).select(M(1).div(M(2 * Math.PI * Math.PI).mul(l)), M(0)), p = M(a.x).mul(M(a.y)).mul(d).mul(f);
7595
7610
  o.assign(G(c, p));
7596
7611
  }), o;
7597
- }), Ic = f(([e, t, n, r, i, a, o, s, c]) => {
7598
- let l = N(o.x).toVar(), u = o.y, d = E(s.x.mul(u.sub(1)), 0, u.sub(1)), f = N(te(d)), p = le(f.add(1), N(u).sub(1)), m = ne(d), h = I(t.load(P(l, f)).x, t.load(P(l, p)).x, m).toVar(), g = o.x, _ = o.y, v = E(s.y.mul(g.sub(1)), 0, g.sub(1)), y = E(h.mul(_.sub(1)), 0, _.sub(1)), b = N(te(v)), x = N(te(y)), S = le(b.add(1), N(g).sub(1)), C = le(x.add(1), N(_).sub(1)), w = ne(v), T = ne(y), D = t.load(P(b, x)).x, O = t.load(P(S, x)).x, k = t.load(P(b, C)).x, j = t.load(P(S, C)).x, ee = U(I(I(D, O, w), I(k, j, w), T).toVar(), h).toVar(), re = Pc({
7612
+ }), Pc = f(([e, t, n, r, i, a, o, s, c]) => {
7613
+ let l = N(o.x).toVar(), u = o.y, d = E(s.x.mul(u.sub(1)), 0, u.sub(1)), f = N(te(d)), p = le(f.add(1), N(u).sub(1)), m = ne(d), h = I(t.load(P(l, f)).x, t.load(P(l, p)).x, m).toVar(), g = o.x, _ = o.y, v = E(s.y.mul(g.sub(1)), 0, g.sub(1)), y = E(h.mul(_.sub(1)), 0, _.sub(1)), b = N(te(v)), x = N(te(y)), S = le(b.add(1), N(g).sub(1)), C = le(x.add(1), N(_).sub(1)), w = ne(v), T = ne(y), D = t.load(P(b, x)).x, O = t.load(P(S, x)).x, k = t.load(P(b, C)).x, j = t.load(P(S, C)).x, ee = U(I(I(D, O, w), I(k, j, w), T).toVar(), h).toVar(), re = Mc({
7599
7614
  uv: ee,
7600
7615
  environmentMatrix: n
7601
7616
  }).toVar(), ie = ke(e, ee, 0).rgb.mul(r).toVar();
7602
7617
  c.assign(ie);
7603
7618
  let ae = ye(ee.y.mul(Math.PI)).toVar(), oe = A(ie.div(r), Ni).mul(ae), se = F(M(0), oe.sub(a)).div(i), ce = ae.greaterThan(0).select(M(1).div(M(2 * Math.PI * Math.PI).mul(ae)), M(0));
7604
7619
  return G(re, M(o.x).mul(M(o.y)).mul(se).mul(ce));
7605
- }), Lc = /* @__PURE__ */ K("\n fn sampleEnvironment(\n tex: texture_2d<f32>,\n samp: sampler,\n direction: vec3f,\n environmentMatrix: mat4x4f,\n environmentIntensity: f32,\n enableEnvironmentLight: f32\n ) -> vec4f {\n if ( enableEnvironmentLight < 0.5 ) { return vec4f( 0.0 ); }\n let uv = equirectDirectionToUv( direction, environmentMatrix );\n let texSample = textureSampleLevel( tex, samp, uv, 0.0 );\n return texSample * environmentIntensity;\n }\n", [Nc]), Rc = f(([e, t, n, r]) => {
7620
+ }), Fc = /* @__PURE__ */ K("\n fn sampleEnvironment(\n tex: texture_2d<f32>,\n samp: sampler,\n direction: vec3f,\n environmentMatrix: mat4x4f,\n environmentIntensity: f32,\n enableEnvironmentLight: f32\n ) -> vec4f {\n if ( enableEnvironmentLight < 0.5 ) { return vec4f( 0.0 ); }\n let uv = equirectDirectionToUv( direction, environmentMatrix );\n let texSample = textureSampleLevel( tex, samp, uv, 0.0 );\n return texSample * environmentIntensity;\n }\n", [jc]), Ic = f(([e, t, n, r]) => {
7606
7621
  let i = t.toConst(), a = e.toVar();
7607
7622
  a.y.subAssign(r);
7608
7623
  let o = n.mul(n).toConst(), s = a.dot(i).toConst(), c = a.dot(a).sub(o).toConst(), l = s.mul(s).sub(c).toConst(), u = t.toVar();
@@ -7617,13 +7632,13 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7617
7632
  u.assign(a.add(i.mul(le(t, r))).div(n));
7618
7633
  });
7619
7634
  }), u;
7620
- }), zc = f(([e, t, n, r, i, a]) => {
7635
+ }), Lc = f(([e, t, n, r, i, a]) => {
7621
7636
  let o = t.toVar();
7622
7637
  return p(n, () => {
7623
7638
  let n = W(e.x, e.y.sub(a), e.z);
7624
- o.assign(Rc(n, t, r, i));
7639
+ o.assign(Ic(n, t, r, i));
7625
7640
  }), o;
7626
- }), Bc = f(([e, t]) => {
7641
+ }), Rc = f(([e, t]) => {
7627
7642
  let n = W(0).toVar();
7628
7643
  return p(e.roughness.greaterThan(.98).and(e.metalness.lessThan(.02)).and(e.transmission.equal(0)).and(e.clearcoat.equal(0)).and(e.iridescence.equal(0)), () => {
7629
7644
  n.assign(e.color.rgb.mul(M(1).sub(e.metalness)).mul(Di));
@@ -7647,10 +7662,10 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7647
7662
  n.assign(d);
7648
7663
  });
7649
7664
  }), n;
7650
- }), Vc = f(([e, t, n, r]) => Bc(r, vi.wrap(Wi(n, e, t)))), Hc = f(([e, t]) => {
7665
+ }), zc = f(([e, t, n, r]) => Rc(r, vi.wrap(Wi(n, e, t)))), Bc = f(([e, t]) => {
7651
7666
  let n = E(I(ca(t.ior).mul(t.specularColor), t.color.rgb, t.metalness).mul(t.specularIntensity), W(0), W(1)).toVar(), r = la(e.NoH, t.roughness), i = fa(e.NoV, e.NoL, t.roughness), a = ia(e.VoH, n), o = r.mul(i).mul(a).div(F(M(4).mul(e.NoV).mul(e.NoL), ki)), s = yi.wrap(pa(n, e.NoV, t.roughness)), c = o.mul(s.compensation), l = W(1).sub(s.E_total).mul(M(1).sub(t.metalness)).mul(t.color.rgb).div(Ei).add(c), u = F(t.clearcoatRoughness, ji), d = la(e.NoH, u), f = fa(e.NoV, e.NoL, u), p = ra(e.VoH, M(.04)), m = d.mul(f).mul(p).div(F(M(4).mul(e.NoV).mul(e.NoL), ki)), h = M(1).sub(t.clearcoat.mul(p).mul(M(2).sub(p)));
7652
7667
  return l.mul(h).add(W(m).mul(t.clearcoat));
7653
- }), Uc = 2 * Ei, Wc = f(([e, t, n, r]) => {
7668
+ }), Vc = 2 * Ei, Hc = f(([e, t, n, r]) => {
7654
7669
  let i = T(!1).toVar(), a = W(0, 1, 0).toVar(), o = W(0).toVar(), s = M(0).toVar(), c = M(0).toVar(), l = N(2).toVar();
7655
7670
  return p(e.area.greaterThan(0), () => {
7656
7671
  let u = e.position.add(e.u.mul(n.x.mul(2).sub(1))).add(e.v.mul(n.y.mul(2).sub(1))).sub(t).toVar(), d = A(u, u).toVar();
@@ -7666,7 +7681,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7666
7681
  pdf: c,
7667
7682
  lightType: l
7668
7683
  });
7669
- }), Gc = f(([e, t, n]) => {
7684
+ }), Uc = f(([e, t, n]) => {
7670
7685
  let r = T(!1).toVar(), i = W(0, 1, 0).toVar(), a = W(0).toVar(), o = M(0).toVar(), s = M(0).toVar(), c = N(3).toVar(), l = e.position.sub(t).toVar(), u = A(l, l).toVar();
7671
7686
  return p(u.greaterThanEqual(1e-20), () => {
7672
7687
  let t = xe(u).toVar(), c = l.div(t).toVar(), d = A(c.negate(), e.direction).toVar(), f = D(e.angle).toVar();
@@ -7690,7 +7705,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7690
7705
  pdf: s,
7691
7706
  lightType: c
7692
7707
  });
7693
- }), Kc = f(([e, t, n]) => {
7708
+ }), Wc = f(([e, t, n]) => {
7694
7709
  let r = T(!1).toVar(), i = W(0, 1, 0).toVar(), a = W(0).toVar(), o = M(0).toVar(), s = M(0).toVar(), c = N(2).toVar(), l = e.position.sub(t).toVar(), u = A(l, l).toVar();
7695
7710
  return p(u.greaterThanEqual(1e-20), () => {
7696
7711
  let t = xe(u).toVar(), d = l.div(t), f = xo({
@@ -7707,7 +7722,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7707
7722
  pdf: s,
7708
7723
  lightType: c
7709
7724
  });
7710
- }), qc = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, h]) => {
7725
+ }), Gc = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, h]) => {
7711
7726
  let g = T(!1).toVar(), v = W(0, 1, 0).toVar(), y = W(0).toVar(), b = M(0).toVar(), x = M(0).toVar(), S = N(2).toVar(), C = s.add(l).add(d).add(h).toVar();
7712
7727
  return p(C.greaterThan(N(0)), () => {
7713
7728
  let w = M(0).toVar(), E = N(0).toVar(), k = N(-1).toVar(), A = N(-1).toVar(), j = M(0).toVar();
@@ -7783,7 +7798,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7783
7798
  p(i.not().and(t.greaterThanEqual(m)).and(t.lessThan(m.add(l))), () => {
7784
7799
  let o = uo.wrap(_o(c, t.sub(m)));
7785
7800
  p(o.intensity.greaterThan(0), () => {
7786
- let t = U(r.y, Y(a)).toVar(), s = mo.wrap(Wc(o, e, t, n));
7801
+ let t = U(r.y, Y(a)).toVar(), s = mo.wrap(Hc(o, e, t, n));
7787
7802
  g.assign(s.valid), v.assign(s.direction), y.assign(s.emission), b.assign(s.distance), x.assign(s.pdf), S.assign(s.lightType), i.assign(T(!0));
7788
7803
  });
7789
7804
  }), m.addAssign(l);
@@ -7791,7 +7806,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7791
7806
  p(i.not().and(t.greaterThanEqual(m)).and(t.lessThan(m.add(d))), () => {
7792
7807
  let r = fo.wrap(vo(u, t.sub(m)));
7793
7808
  p(r.intensity.greaterThan(0), () => {
7794
- let t = mo.wrap(Kc(r, e, n));
7809
+ let t = mo.wrap(Wc(r, e, n));
7795
7810
  g.assign(t.valid), v.assign(t.direction), y.assign(t.emission), b.assign(t.distance), x.assign(t.pdf), S.assign(t.lightType), i.assign(T(!0));
7796
7811
  });
7797
7812
  }), m.addAssign(d);
@@ -7799,7 +7814,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7799
7814
  p(i.not().and(t.greaterThanEqual(m)).and(t.lessThan(m.add(h))), () => {
7800
7815
  let r = po.wrap(yo(f, t.sub(m)));
7801
7816
  p(r.intensity.greaterThan(0), () => {
7802
- let t = mo.wrap(Gc(r, e, n));
7817
+ let t = mo.wrap(Uc(r, e, n));
7803
7818
  g.assign(t.valid), v.assign(t.direction), y.assign(t.emission), b.assign(t.distance), x.assign(t.pdf), S.assign(t.lightType), i.assign(T(!0));
7804
7819
  });
7805
7820
  });
@@ -7809,21 +7824,21 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7809
7824
  p(k.equal(N(0)).and(A.greaterThanEqual(N(0))), () => {
7810
7825
  let n = lo.wrap(go(o, A)), i = L(n.direction).toVar(), s = M(1).toVar();
7811
7826
  p(n.angle.greaterThan(0), () => {
7812
- let e = D(n.angle.mul(.5)).toVar(), t = I(e, M(1), r.y).toVar(), o = xe(F(M(0), M(1).sub(t.mul(t)))).toVar(), c = M(Uc).mul(Y(a)).toVar(), l = L(n.direction).toVar(), u = L(O(R(_(l.x).greaterThan(.9), W(0, 1, 0), W(1, 0, 0)), l)).toVar(), d = O(l, u).toVar();
7827
+ let e = D(n.angle.mul(.5)).toVar(), t = I(e, M(1), r.y).toVar(), o = xe(F(M(0), M(1).sub(t.mul(t)))).toVar(), c = M(Vc).mul(Y(a)).toVar(), l = L(n.direction).toVar(), u = L(O(R(_(l.x).greaterThan(.9), W(0, 1, 0), W(1, 0, 0)), l)).toVar(), d = O(l, u).toVar();
7813
7828
  i.assign(L(l.mul(t).add(u.mul(D(c)).add(d.mul(ye(c))).mul(o))));
7814
- let f = M(Uc).mul(F(M(1).sub(e), 1e-10));
7829
+ let f = M(Vc).mul(F(M(1).sub(e), 1e-10));
7815
7830
  s.assign(M(1).div(f));
7816
7831
  });
7817
7832
  let c = Eo(n, e);
7818
7833
  v.assign(i), y.assign(n.color.mul(n.intensity).mul(c)), b.assign(1e6), x.assign(s.mul(t)), S.assign(N(0)), g.assign(T(!0));
7819
7834
  }), p(k.equal(N(1)).and(A.greaterThanEqual(N(0))), () => {
7820
- let n = uo.wrap(_o(c, A)), i = U(r.y, Y(a)).toVar(), o = mo.wrap(Wc(n, e, i, t));
7835
+ let n = uo.wrap(_o(c, A)), i = U(r.y, Y(a)).toVar(), o = mo.wrap(Hc(n, e, i, t));
7821
7836
  g.assign(o.valid), v.assign(o.direction), y.assign(o.emission), b.assign(o.distance), x.assign(o.pdf), S.assign(o.lightType);
7822
7837
  }), p(k.equal(N(2)).and(A.greaterThanEqual(N(0))), () => {
7823
- let n = fo.wrap(vo(u, A)), r = mo.wrap(Kc(n, e, t));
7838
+ let n = fo.wrap(vo(u, A)), r = mo.wrap(Wc(n, e, t));
7824
7839
  g.assign(r.valid), v.assign(r.direction), y.assign(r.emission), b.assign(r.distance), x.assign(r.pdf), S.assign(r.lightType);
7825
7840
  }), p(k.equal(N(3)).and(A.greaterThanEqual(N(0))), () => {
7826
- let n = po.wrap(yo(f, A)), r = mo.wrap(Gc(n, e, t));
7841
+ let n = po.wrap(yo(f, A)), r = mo.wrap(Uc(n, e, t));
7827
7842
  g.assign(r.valid), v.assign(r.direction), y.assign(r.emission), b.assign(r.distance), x.assign(r.pdf), S.assign(r.lightType);
7828
7843
  });
7829
7844
  });
@@ -7835,7 +7850,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7835
7850
  pdf: x,
7836
7851
  lightType: S
7837
7852
  });
7838
- }), Jc = f(([e, t]) => {
7853
+ }), Kc = f(([e, t]) => {
7839
7854
  let n = t.NoV, r = t.NoL.toVar(), i = t.NoH, a = M(1).sub(e.metalness).mul(M(1).sub(e.transmission)).toVar(), o = M(1).sub(a.mul(M(1).sub(e.metalness))).toVar(), s = a.add(o).toVar(), c = M(0).toVar();
7840
7855
  return p(s.greaterThan(0), () => {
7841
7856
  let t = M(1).div(F(s, 1e-10)).toVar();
@@ -7846,8 +7861,8 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7846
7861
  c.addAssign(o.mul(ma(i, n, t)));
7847
7862
  });
7848
7863
  }), F(c, 1e-8);
7849
- }), Yc = f(([e, t, n, r]) => Jc(r, vi.wrap(Wi(n, e, t)))), Xc = f(([e, t, n, r, i, a, o, s, c, l, u, d, h, g, _, v, y, b, x, S, C, w, E, D, O, k, j, ee, te]) => {
7850
- let ne = W(0).toVar(), re = W(0).toVar(), P = e.add(t.mul(.001)).toVar(), ie = f(([e, t, n]) => ro(e, t, n, kc, b, x, S));
7864
+ }), qc = f(([e, t, n, r]) => Kc(r, vi.wrap(Wi(n, e, t)))), Jc = f(([e, t, n, r, i, a, o, s, c, l, u, d, h, g, _, v, y, b, x, S, C, w, E, D, O, k, j, ee, te]) => {
7865
+ let ne = W(0).toVar(), re = W(0).toVar(), P = e.add(t.mul(.001)).toVar(), ie = f(([e, t, n]) => ro(e, t, n, Dc, b, x, S));
7851
7866
  return p(n.emissiveIntensity.lessThanEqual(10), () => {
7852
7867
  let f = W(1).toVar(), b = Ti.wrap(Yi(n.roughness, n.metalness, s, f)), x = b.useBRDFSampling.toVar(), S = b.useLightSampling.toVar(), ae = b.brdfWeight.toVar(), oe = b.lightWeight.toVar(), se = u.add(h).add(_).add(y).toVar(), ce = M(.001).mul(M(1).add(M(s).mul(.5))).toVar(), I = se.greaterThan(N(0)).toVar(), ue = M(0).toVar();
7853
7868
  p(S.and(I), () => {
@@ -7865,7 +7880,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7865
7880
  }).ElseIf(I, () => {
7866
7881
  pe.assign(T(!0));
7867
7882
  }), p(pe, () => {
7868
- let e = U(de, Y(c)).toVar(), i = mo.wrap(qc(P, t, n, e, s, c, l, u, d, h, g, _, v, y));
7883
+ let e = U(de, Y(c)).toVar(), i = mo.wrap(Gc(P, t, n, e, s, c, l, u, d, h, g, _, v, y));
7869
7884
  p(i.valid.and(i.pdf.greaterThan(0)), () => {
7870
7885
  let e = F(M(0), A(t, i.direction)).toVar(), a = i.emission.x.add(i.emission.y).add(i.emission.z);
7871
7886
  p(e.greaterThan(0).and(a.mul(e).greaterThan(ce)).and(bo({
@@ -7874,7 +7889,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7874
7889
  })), () => {
7875
7890
  let a = le(i.distance.sub(.001), M(1e3)), o = ie(P, i.direction, a);
7876
7891
  p(o.greaterThan(0).or(te), () => {
7877
- let a = vi.wrap(Wi(t, r, i.direction)), s = Bc(n, a), c = Jc(n, a).toVar(), l = M(1).toVar();
7892
+ let a = vi.wrap(Wi(t, r, i.direction)), s = Rc(n, a), c = Kc(n, a).toVar(), l = M(1).toVar();
7878
7893
  p(c.greaterThan(0).and(x), () => {
7879
7894
  let e = i.pdf.mul(oe), t = c.mul(ae);
7880
7895
  p(i.lightType.equal(N(1)), () => {
@@ -7941,7 +7956,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7941
7956
  });
7942
7957
  });
7943
7958
  }), p(ee, () => {
7944
- let e = U(Y(c).toVar(), Y(c).toVar()).toVar(), i = W(0).toVar(), a = Ic(C, D, E, w, O, k, j, e, i).toVar(), o = a.xyz.toVar(), s = a.w.toVar();
7959
+ let e = U(Y(c).toVar(), Y(c).toVar()).toVar(), i = W(0).toVar(), a = Pc(C, D, E, w, O, k, j, e, i).toVar(), o = a.xyz.toVar(), s = a.w.toVar();
7945
7960
  p(s.greaterThan(0), () => {
7946
7961
  let e = F(M(0), A(t, o)).toVar();
7947
7962
  p(e.greaterThan(0).and(bo({
@@ -7950,7 +7965,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7950
7965
  })), () => {
7951
7966
  let a = ie(P, o, M(1e3));
7952
7967
  p(a.greaterThan(0).or(te), () => {
7953
- let c = vi.wrap(Wi(t, r, o)), l = Bc(n, c), u = Jc(n, c).toVar(), d = R(u.greaterThan(0), Hi({
7968
+ let c = vi.wrap(Wi(t, r, o)), l = Rc(n, c), u = Kc(n, c).toVar(), d = R(u.greaterThan(0), Hi({
7954
7969
  pdf1: s,
7955
7970
  pdf2: u
7956
7971
  }), M(1)).toVar(), f = i.mul(l).mul(e).mul(d).div(F(s, 1e-10));
@@ -7965,17 +7980,17 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7965
7980
  shadowed: ne,
7966
7981
  unoccluded: re
7967
7982
  });
7968
- }), Zc = f(([e, t, n, r, i, a]) => {
7983
+ }), Yc = f(([e, t, n, r, i, a]) => {
7969
7984
  let o = R(a, r, M(1).div(r)).toVar(), s = e.add(t.mul(o)).toVar(), c = A(s, s).toVar(), l = R(c.greaterThan(ki), s.div(xe(c)), n).toVar();
7970
7985
  p(A(l, n).lessThan(0), () => {
7971
7986
  l.assign(l.negate());
7972
7987
  });
7973
7988
  let u = _(A(e, l)), d = _(A(t, l)).toVar(), f = _(A(n, l)).toVar(), m = la(f, i), h = u.add(d.mul(o)).toVar(), g = h.mul(h), v = d.mul(o).mul(o).div(F(g, ki));
7974
7989
  return m.mul(f).mul(v);
7975
- }), Qc = f(([e, t, n, r]) => {
7990
+ }), Xc = f(([e, t, n, r]) => {
7976
7991
  let i = e.add(t).toVar(), a = A(i, i).toVar();
7977
7992
  return ma(F(A(n, R(a.greaterThan(ki), i.div(xe(a)), n)), 0), F(A(n, e), 0), r);
7978
- }), $c = f(([e]) => {
7993
+ }), Zc = f(([e]) => {
7979
7994
  let t = e.specularImportance.toVar(), n = t.greaterThan(.001).toVar(), r = e.diffuseImportance.toVar(), i = r.greaterThan(.001).toVar(), a = e.transmissionImportance.toVar(), o = a.greaterThan(.001).toVar(), s = e.clearcoatImportance.toVar(), c = s.greaterThan(.001).toVar(), l = t.add(r).add(a).add(s).toVar();
7980
7995
  return p(l.lessThan(.001), () => {
7981
7996
  t.assign(0), r.assign(1), a.assign(0), s.assign(0), l.assign(1), n.assign(T(!1)), i.assign(T(!0)), o.assign(T(!1)), c.assign(T(!1));
@@ -7995,7 +8010,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
7995
8010
  useTransmission: o,
7996
8011
  useClearcoat: c
7997
8012
  });
7998
- }), el = f(([e, t]) => {
8013
+ }), Qc = f(([e, t]) => {
7999
8014
  let n = N(2).toVar(), r = M(0).toVar(), i = T(!1).toVar();
8000
8015
  return p(e.useSpecular.and(i.not()), () => {
8001
8016
  r.addAssign(e.specularWeight), p(t.lessThan(r), () => {
@@ -8012,20 +8027,20 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8012
8027
  }), p(e.useClearcoat.and(i.not()), () => {
8013
8028
  n.assign(4);
8014
8029
  }), n;
8015
- }), tl = f(([e]) => F(e, 0).mul(Di)), nl = f(([e, t, n, r, i, a, o, s]) => {
8030
+ }), $c = f(([e]) => F(e, 0).mul(Di)), el = f(([e, t, n, r, i, a, o, s]) => {
8016
8031
  let c = W(0).toVar(), l = W(0).toVar(), u = M(0).toVar(), d = M(0).toVar(), f = M(0).toVar();
8017
8032
  return p(s.diffuseImportance.greaterThanEqual(0).and(s.specularImportance.greaterThanEqual(0)).and(s.transmissionImportance.greaterThanEqual(0)).and(s.clearcoatImportance.greaterThanEqual(0)).not(), () => {
8018
8033
  let e = U(Y(o).toVar(), Y(o).toVar());
8019
8034
  c.assign(xa(t, e)), l.assign(n.color.xyz), u.assign(1), d.assign(1);
8020
8035
  }).Else(() => {
8021
- let m = wi.wrap($c(s).toVar()), h = Y(o).toVar(), g = U(Y(o).toVar(), Y(o).toVar()).toVar(), v = el(m, h).toVar(), y = W(0).toVar(), b = M(0).toVar(), x = W(0).toVar();
8036
+ let m = wi.wrap(Zc(s).toVar()), h = Y(o).toVar(), g = U(Y(o).toVar(), Y(o).toVar()).toVar(), v = Qc(m, h).toVar(), y = W(0).toVar(), b = M(0).toVar(), x = W(0).toVar();
8022
8037
  p(v.equal(N(1)), () => {
8023
8038
  y.assign(r), b.assign(i), x.assign(a);
8024
8039
  }).ElseIf(v.equal(N(2)), () => {
8025
- y.assign(xa(t, g)), b.assign(tl(F(A(t, y), 0))), x.assign(Vc(e, y, t, n));
8040
+ y.assign(xa(t, g)), b.assign($c(F(A(t, y), 0))), x.assign(zc(e, y, t, n));
8026
8041
  }).ElseIf(v.equal(N(3)), () => {
8027
8042
  let r = A(e, t).greaterThan(0), i = Na.wrap(za(e, t, n.ior, n.roughness, r, n.dispersion, g, o, M(0)).toVar());
8028
- y.assign(i.direction), b.assign(i.pdf), x.assign(Vc(e, y, t, n));
8043
+ y.assign(i.direction), b.assign(i.pdf), x.assign(zc(e, y, t, n));
8029
8044
  }).Else(() => {
8030
8045
  y.assign(r), b.assign(i), x.assign(a);
8031
8046
  });
@@ -8034,12 +8049,12 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8034
8049
  let r = ma(F(A(t, L(e.add(y))), .001), F(A(t, e), .001), n.roughness);
8035
8050
  T.addAssign(m.specularWeight.mul(r));
8036
8051
  }), p(m.useDiffuse, () => {
8037
- T.addAssign(m.diffuseWeight.mul(tl(C)));
8052
+ T.addAssign(m.diffuseWeight.mul($c(C)));
8038
8053
  }), p(m.useTransmission.and(n.transmission.greaterThan(0)), () => {
8039
8054
  let r = A(e, t).greaterThan(0);
8040
- T.addAssign(m.transmissionWeight.mul(Zc(e, y, t, n.ior, n.roughness, r)));
8055
+ T.addAssign(m.transmissionWeight.mul(Yc(e, y, t, n.ior, n.roughness, r)));
8041
8056
  }), p(m.useClearcoat.and(n.clearcoat.greaterThan(0)), () => {
8042
- T.addAssign(m.clearcoatWeight.mul(Qc(e, y, t, n.clearcoatRoughness)));
8057
+ T.addAssign(m.clearcoatWeight.mul(Xc(e, y, t, n.clearcoatRoughness)));
8043
8058
  }), b.assign(F(b, Mi)), T.assign(F(T, Mi));
8044
8059
  let E = b.div(T).toVar(), D = R(v.equal(N(3)), w, C);
8045
8060
  c.assign(y), l.assign(x.mul(D).mul(E).div(b)), u.assign(E), d.assign(b), f.assign(T);
@@ -8050,7 +8065,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8050
8065
  pdf: d,
8051
8066
  combinedPdf: f
8052
8067
  });
8053
- }), rl = f(([e, t, n, r, i, a, o, s, c, l]) => {
8068
+ }), tl = f(([e, t, n, r, i, a, o, s, c, l]) => {
8054
8069
  let u = W(0).toVar(), d = W(0).toVar(), f = M(0).toVar(), m = s.toVar();
8055
8070
  p(o.not(), () => {
8056
8071
  p(c, () => {
@@ -8079,7 +8094,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8079
8094
  xi: g
8080
8095
  }));
8081
8096
  let r = E(A(t, u), 0, 1);
8082
- f.assign(r.mul(Di)), d.assign(Vc(e, u, t, n));
8097
+ f.assign(r.mul(Di)), d.assign(zc(e, u, t, n));
8083
8098
  }).ElseIf(h.lessThan(y), () => {
8084
8099
  let i = Ui({ N: t }), a = Sa({
8085
8100
  V: i.transpose().mul(e),
@@ -8088,7 +8103,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8088
8103
  });
8089
8104
  _.assign(i.mul(a));
8090
8105
  let o = E(A(t, _), .001, 1);
8091
- u.assign(he(e.negate(), _)), f.assign(ma(o, S, n.roughness)), d.assign(Vc(e, u, t, n));
8106
+ u.assign(he(e.negate(), _)), f.assign(ma(o, S, n.roughness)), d.assign(zc(e, u, t, n));
8092
8107
  }).ElseIf(h.lessThan(b), () => {
8093
8108
  _.assign(ya({
8094
8109
  N: t,
@@ -8102,9 +8117,9 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8102
8117
  u.assign(ba({
8103
8118
  N: t,
8104
8119
  xi: r
8105
- })), o.assign(E(A(t, u), 0, 1)), f.assign(o.mul(Di)), d.assign(Vc(e, u, t, n));
8120
+ })), o.assign(E(A(t, u), 0, 1)), f.assign(o.mul(Di)), d.assign(zc(e, u, t, n));
8106
8121
  }).Else(() => {
8107
- f.assign(ua(i, n.sheenRoughness).mul(i).div(M(4).mul(a))), f.assign(F(f, Mi)), d.assign(Vc(e, u, t, n));
8122
+ f.assign(ua(i, n.sheenRoughness).mul(i).div(M(4).mul(a))), f.assign(F(f, Mi)), d.assign(zc(e, u, t, n));
8108
8123
  });
8109
8124
  }).ElseIf(h.lessThan(x), () => {
8110
8125
  let i = E(n.clearcoatRoughness, ji, 1);
@@ -8114,16 +8129,16 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8114
8129
  Xi: r
8115
8130
  }));
8116
8131
  let a = E(A(t, _), 0, 1);
8117
- u.assign(he(e.negate(), _)), f.assign(ma(a, S, i)), f.assign(F(f, Mi)), d.assign(Vc(e, u, t, n));
8132
+ u.assign(he(e.negate(), _)), f.assign(ma(a, S, i)), f.assign(F(f, Mi)), d.assign(zc(e, u, t, n));
8118
8133
  }).Else(() => {
8119
8134
  let a = A(e, t).greaterThan(0), o = Na.wrap(za(e, t, n.ior, n.roughness, a, n.dispersion, r, i, M(0)));
8120
- u.assign(o.direction), f.assign(F(o.pdf, Mi)), d.assign(Vc(e, u, t, n));
8135
+ u.assign(o.direction), f.assign(F(o.pdf, Mi)), d.assign(zc(e, u, t, n));
8121
8136
  }), f.assign(F(f, Mi)), hi({
8122
8137
  direction: u,
8123
8138
  value: d,
8124
8139
  pdf: f
8125
8140
  });
8126
- }), il = /* @__PURE__ */ K("\n fn regularizePathContribution( contribution: vec3f, pathLength: f32, fireflyThreshold: f32, frame: i32 ) -> vec3f {\n let threshold = calculateFireflyThreshold( fireflyThreshold, i32( pathLength ), frame );\n return applySoftSuppressionRGB( contribution, threshold, 0.5f );\n }\n", [Gi, qi]), al = /* @__PURE__ */ K("\n fn computeNDCDepth( worldPos: vec3f, cameraProjectionMatrix: mat4x4f, cameraViewMatrix: mat4x4f ) -> f32 {\n let clipPos = cameraProjectionMatrix * cameraViewMatrix * vec4f( worldPos, 1.0f );\n let ndcDepth = clipPos.z / clipPos.w * 0.5f + 0.5f;\n return clamp( ndcDepth, 0.0f, 1.0f );\n }\n"), ol = f(([e, t, n, r, i, a, o]) => {
8141
+ }), nl = /* @__PURE__ */ K("\n fn regularizePathContribution( contribution: vec3f, pathLength: f32, fireflyThreshold: f32, frame: i32 ) -> vec3f {\n let threshold = calculateFireflyThreshold( fireflyThreshold, i32( pathLength ), frame );\n return applySoftSuppressionRGB( contribution, threshold, 0.5f );\n }\n", [Gi, qi]), rl = /* @__PURE__ */ K("\n fn computeNDCDepth( worldPos: vec3f, cameraProjectionMatrix: mat4x4f, cameraViewMatrix: mat4x4f ) -> f32 {\n let clipPos = cameraProjectionMatrix * cameraViewMatrix * vec4f( worldPos, 1.0f );\n let ndcDepth = clipPos.z / clipPos.w * 0.5f + 0.5f;\n return clamp( ndcDepth, 0.0f, 1.0f );\n }\n"), il = f(([e, t, n, r, i, a, o]) => {
8127
8142
  let s = M(1).toVar();
8128
8143
  return p(e.greaterThanEqual(N(3)), () => {
8129
8144
  let c = F(F(F(t.x, t.y), t.z), 0).toVar();
@@ -8174,11 +8189,11 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8174
8189
  });
8175
8190
  });
8176
8191
  }), s;
8177
- }), sl = Cn({
8192
+ }), al = Cn({
8178
8193
  brdf: "vec3",
8179
8194
  L: "vec3",
8180
8195
  pdf: "float"
8181
- }), cl = f(([e, t, n, r, i]) => {
8196
+ }), ol = f(([e, t, n, r, i]) => {
8182
8197
  let a = t.normal, o = e.direction.negate(), s = F(n.clearcoatRoughness, ji), c = F(n.roughness, ji), l = M(1).sub(c).mul(M(.5).add(M(.5).mul(n.metalness))).toVar(), u = n.clearcoat.mul(M(1).sub(s)).toVar(), d = M(1).sub(l).mul(M(1).sub(n.metalness)).toVar(), f = l.add(u).add(d);
8183
8198
  l.divAssign(f), u.divAssign(f), d.divAssign(f);
8184
8199
  let m = Y(i), h = W(0).toVar(), g = W(0).toVar();
@@ -8201,22 +8216,22 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8201
8216
  })), g.assign(L(o.add(h)));
8202
8217
  });
8203
8218
  let _ = vi.wrap(Wi(a, o, h)), v = la(_.NoH, s).mul(_.NoH).div(M(4).mul(_.VoH)).mul(u), y = la(_.NoH, c).mul(_.NoH).div(M(4).mul(_.VoH)).mul(l), b = _.NoL.div(Ei).mul(d), x = F(v.add(y).add(b), .001);
8204
- return sl({
8205
- brdf: Hc(_, n),
8219
+ return al({
8220
+ brdf: Bc(_, n),
8206
8221
  L: h,
8207
8222
  pdf: x
8208
8223
  });
8209
- }), ll = 32, ul = 16, dl = 5, fl = 1 / 1024, pl = 8, ml = Cn({
8224
+ }), sl = 32, cl = 16, ll = 5, ul = 1 / 1024, dl = 8, fl = Cn({
8210
8225
  hitPoint: "vec3",
8211
8226
  uv: "vec2",
8212
8227
  normal: "vec3",
8213
8228
  height: "float"
8214
- }), hl = f(([e, t, n, r, i, a]) => {
8215
- let o = t.hitPoint.toVar(), s = t.uv.toVar(), c = t.normal.toVar(), l = M(0).toVar(), u = t.triangleIndex, d = $(n, u, N(0), N(pl)).xyz.toVar(), f = $(n, u, N(1), N(pl)).xyz, h = $(n, u, N(2), N(pl)).xyz, g = $(n, u, N(6), N(pl)).toVar(), v = $(n, u, N(7), N(pl)), y = g.xy.toVar(), b = g.zw, x = v.xy, S = f.sub(d).toVar(), C = h.sub(d).toVar(), w = b.sub(y).toVar(), T = x.sub(y).toVar(), E = w.x.mul(T.y).sub(T.x.mul(w.y)).toVar();
8229
+ }), pl = f(([e, t, n, r, i, a]) => {
8230
+ let o = t.hitPoint.toVar(), s = t.uv.toVar(), c = t.normal.toVar(), l = M(0).toVar(), u = t.triangleIndex, d = $(n, u, N(0), N(dl)).xyz.toVar(), f = $(n, u, N(1), N(dl)).xyz, h = $(n, u, N(2), N(dl)).xyz, g = $(n, u, N(6), N(dl)).toVar(), v = $(n, u, N(7), N(dl)), y = g.xy.toVar(), b = g.zw, x = v.xy, S = f.sub(d).toVar(), C = h.sub(d).toVar(), w = b.sub(y).toVar(), T = x.sub(y).toVar(), E = w.x.mul(T.y).sub(T.x.mul(w.y)).toVar();
8216
8231
  return p(_(E).greaterThan(1e-8), () => {
8217
8232
  let n = M(1).div(E), u = S.mul(T.y).sub(C.mul(w.y)).mul(n).toVar(), d = C.mul(w.x).sub(S.mul(T.x)).mul(n).toVar(), f = t.normal.toVar(), h = i.displacementScale.div(M(10)), g = e.direction, v = A(g, f).toVar(), y = g.sub(f.mul(v)).toVar(), b = A(u, u), x = A(u, d), D = A(d, d), O = b.mul(D).sub(x.mul(x)).toVar();
8218
8233
  p(_(O).greaterThan(1e-10), () => {
8219
- let e = M(1).div(O), n = A(y, u), S = A(y, d), C = U(D.mul(n).sub(x.mul(S)).mul(e), b.mul(S).sub(x.mul(n)).mul(e)).toVar(), w = v.toVar(), T = F(_(w), .001), E = h.div(T).toVar(), k = N(a.equal(N(0)).select(N(ll), N(ul))).toVar(), j = E.negate().toVar(), ee = E.sub(j).div(M(k)).toVar(), te = j.toVar(), ne = j.toVar(), re = N(0).toVar();
8234
+ let e = M(1).div(O), n = A(y, u), S = A(y, d), C = U(D.mul(n).sub(x.mul(S)).mul(e), b.mul(S).sub(x.mul(n)).mul(e)).toVar(), w = v.toVar(), T = F(_(w), .001), E = h.div(T).toVar(), k = N(a.equal(N(0)).select(N(sl), N(cl))).toVar(), j = E.negate().toVar(), ee = E.sub(j).div(M(k)).toVar(), te = j.toVar(), ne = j.toVar(), re = N(0).toVar();
8220
8235
  m({
8221
8236
  start: N(0),
8222
8237
  end: k,
@@ -8235,7 +8250,7 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8235
8250
  let e = te.toVar(), n = ne.toVar();
8236
8251
  m({
8237
8252
  start: N(0),
8238
- end: N(dl),
8253
+ end: N(ll),
8239
8254
  type: "int",
8240
8255
  condition: "<"
8241
8256
  }, () => {
@@ -8246,17 +8261,17 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8246
8261
  e.assign(a);
8247
8262
  });
8248
8263
  });
8249
- let a = e.add(n).mul(.5).toVar(), _ = t.uv.add(C.mul(a)).toVar(), v = t.hitPoint.add(g.mul(a)), y = Qa(r, i.displacementMapIndex, _, i.displacementTransform), b = y.sub(.5).mul(h), x = M(fl), S = y, T = Qa(r, i.displacementMapIndex, _.add(U(x, 0)), i.displacementTransform), E = Qa(r, i.displacementMapIndex, _.add(U(0, x)), i.displacementTransform), D = L(u).toVar(), O = L(d).toVar(), k = T.sub(S).mul(h), A = E.sub(S).mul(h), j = L(f.sub(D.mul(k)).sub(O.mul(A)));
8264
+ let a = e.add(n).mul(.5).toVar(), _ = t.uv.add(C.mul(a)).toVar(), v = t.hitPoint.add(g.mul(a)), y = Qa(r, i.displacementMapIndex, _, i.displacementTransform), b = y.sub(.5).mul(h), x = M(ul), S = y, T = Qa(r, i.displacementMapIndex, _.add(U(x, 0)), i.displacementTransform), E = Qa(r, i.displacementMapIndex, _.add(U(0, x)), i.displacementTransform), D = L(u).toVar(), O = L(d).toVar(), k = T.sub(S).mul(h), A = E.sub(S).mul(h), j = L(f.sub(D.mul(k)).sub(O.mul(A)));
8250
8265
  o.assign(v), s.assign(_), c.assign(j), l.assign(b);
8251
8266
  });
8252
8267
  });
8253
- }), ml({
8268
+ }), fl({
8254
8269
  hitPoint: o,
8255
8270
  uv: s,
8256
8271
  normal: c,
8257
8272
  height: l
8258
8273
  });
8259
- }), gl = Cn({
8274
+ }), ml = Cn({
8260
8275
  position: "vec3",
8261
8276
  normal: "vec3",
8262
8277
  emission: "vec3",
@@ -8266,40 +8281,40 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8266
8281
  area: "float",
8267
8282
  cosThetaLight: "float",
8268
8283
  valid: "bool"
8269
- }), _l = Cn({
8284
+ }), hl = Cn({
8270
8285
  contribution: "vec3",
8271
8286
  hasEmissive: "bool",
8272
8287
  emissionOnly: "vec3",
8273
8288
  distance: "float"
8274
- }), vl = f(([e, t, n, r]) => {
8289
+ }), gl = f(([e, t, n, r]) => {
8275
8290
  let i = xe(r.x), a = M(1).sub(i), o = r.y.mul(i), s = M(1).sub(a).sub(o);
8276
8291
  return e.mul(a).add(t.mul(o)).add(n.mul(s));
8277
- }), yl = f(([e, t, n]) => ie(O(t.sub(e), n.sub(e))).mul(.5)), bl = f(([e, t, n, r]) => {
8292
+ }), _l = f(([e, t, n]) => ie(O(t.sub(e), n.sub(e))).mul(.5)), vl = f(([e, t, n, r]) => {
8278
8293
  let i = L(e.sub(r)), a = L(t.sub(r)), o = L(n.sub(r)), s = _(A(i, O(a, o))), c = M(1).add(A(a, o)).add(A(i, o)).add(A(i, a));
8279
8294
  return F(M(2).mul(b(s, F(c, M(1e-10)))), M(0));
8280
- }), xl = f(([e, t, n, r]) => {
8295
+ }), yl = f(([e, t, n, r]) => {
8281
8296
  let i = t.sub(e), a = n.sub(e), o = n.sub(t), s = F(A(i, i), F(A(a, a), A(o, o))), c = O(i, a), l = A(c, c), u = T(!1).toVar();
8282
8297
  return p(l.greaterThan(1e-20), () => {
8283
8298
  let t = A(c, r.sub(e)), n = t.mul(t).div(l);
8284
8299
  u.assign(s.greaterThan(n));
8285
8300
  }), u;
8286
- }), Sl = Cn({
8301
+ }), bl = Cn({
8287
8302
  direction: "vec3",
8288
8303
  position: "vec3",
8289
8304
  solidAngle: "float",
8290
8305
  valid: "bool"
8291
- }), Cl = f(([e]) => {
8306
+ }), xl = f(([e]) => {
8292
8307
  let t = ie(e);
8293
8308
  return R(t.greaterThan(1e-10), e.div(t), W(0));
8294
- }), wl = f(([e, t, n, r, i]) => {
8295
- let a = Sl({
8309
+ }), Sl = f(([e, t, n, r, i]) => {
8310
+ let a = bl({
8296
8311
  direction: W(0),
8297
8312
  position: W(0),
8298
8313
  solidAngle: M(0),
8299
8314
  valid: !1
8300
- }).toVar(), o = L(e.sub(r)), s = L(t.sub(r)), c = L(n.sub(r)), l = bl(e, t, n, r);
8315
+ }).toVar(), o = L(e.sub(r)), s = L(t.sub(r)), c = L(n.sub(r)), l = vl(e, t, n, r);
8301
8316
  return a.solidAngle.assign(l), p(l.greaterThan(1e-7), () => {
8302
- let u = E(A(Cl(O(o, s)), Cl(O(o, c))), -1, 1), d = xe(F(M(1).sub(u.mul(u)), 0)), f = v(u), m = i.x.mul(l).sub(f), h = ye(m), g = D(m), y = E(A(o, s), -1, 1), b = g.sub(u), x = h.add(d.mul(y)), S = x.mul(g).sub(b.mul(h)).mul(u).sub(x), C = x.mul(h).add(b.mul(g)).mul(d), w = E(R(_(C).greaterThan(1e-10), S.div(C), M(1)), -1, 1), T = A(c, o), k = Cl(c.sub(o.mul(T))), j = xe(F(M(1).sub(w.mul(w)), 0)), ee = L(o.mul(w).add(k.mul(j))), te = A(ee, s), ne = M(1).sub(i.y.mul(M(1).sub(te))), re = xe(F(M(1).sub(ne.mul(ne)), 0)), N = Cl(ee.sub(s.mul(te))), P = L(s.mul(ne).add(N.mul(re))), ie = L(O(t.sub(e), n.sub(e))), ae = A(ie, P);
8317
+ let u = E(A(xl(O(o, s)), xl(O(o, c))), -1, 1), d = xe(F(M(1).sub(u.mul(u)), 0)), f = v(u), m = i.x.mul(l).sub(f), h = ye(m), g = D(m), y = E(A(o, s), -1, 1), b = g.sub(u), x = h.add(d.mul(y)), S = x.mul(g).sub(b.mul(h)).mul(u).sub(x), C = x.mul(h).add(b.mul(g)).mul(d), w = E(R(_(C).greaterThan(1e-10), S.div(C), M(1)), -1, 1), T = A(c, o), k = xl(c.sub(o.mul(T))), j = xe(F(M(1).sub(w.mul(w)), 0)), ee = L(o.mul(w).add(k.mul(j))), te = A(ee, s), ne = M(1).sub(i.y.mul(M(1).sub(te))), re = xe(F(M(1).sub(ne.mul(ne)), 0)), N = xl(ee.sub(s.mul(te))), P = L(s.mul(ne).add(N.mul(re))), ie = L(O(t.sub(e), n.sub(e))), ae = A(ie, P);
8303
8318
  p(_(ae).greaterThan(1e-10), () => {
8304
8319
  let t = A(ie, e.sub(r)).div(ae);
8305
8320
  p(t.greaterThan(0), () => {
@@ -8307,15 +8322,15 @@ var Nc = /* @__PURE__ */ K("\n fn equirectDirectionToUv( direction: vec3f, envir
8307
8322
  });
8308
8323
  });
8309
8324
  }), a;
8310
- }), Tl = f(([e, t, n, r]) => {
8325
+ }), Cl = f(([e, t, n, r]) => {
8311
8326
  let i = n.sub(t), a = r.sub(t), o = e.sub(t), s = A(i, i), c = A(i, a), l = A(a, a), u = A(o, i), d = A(o, a), f = M(1).div(F(s.mul(l).sub(c.mul(c)), M(1e-10))), p = l.mul(u).sub(c.mul(d)).mul(f), m = s.mul(d).sub(c.mul(u)).mul(f);
8312
8327
  return W(M(1).sub(p).sub(m), p, m);
8313
- }), El = f(([e, t, n, r]) => {
8328
+ }), wl = f(([e, t, n, r]) => {
8314
8329
  let i = xe(r.x), a = M(1).sub(i), o = r.y.mul(i), s = M(1).sub(a).sub(o);
8315
8330
  return L(e.mul(a).add(t.mul(o)).add(n.mul(s)));
8316
8331
  });
8317
8332
  f(([e]) => e.emissiveIntensity.greaterThan(0).and(ie(e.emissive).greaterThan(0)));
8318
- var Dl = 8, Ol = 2, kl = Cn({
8333
+ var Tl = 8, El = 2, Dl = Cn({
8319
8334
  v0: "vec3",
8320
8335
  v1: "vec3",
8321
8336
  v2: "vec3",
@@ -8323,9 +8338,9 @@ var Dl = 8, Ol = 2, kl = Cn({
8323
8338
  n1: "vec3",
8324
8339
  n2: "vec3",
8325
8340
  materialIndex: "int"
8326
- }), Al = f(([e, t]) => {
8327
- let n = $(t, e, N(0), N(Dl)), r = $(t, e, N(1), N(Dl)), i = $(t, e, N(2), N(Dl)), a = $(t, e, N(3), N(Dl)), o = $(t, e, N(4), N(Dl)), s = $(t, e, N(5), N(Dl)), c = $(t, e, N(7), N(Dl));
8328
- return kl({
8341
+ }), Ol = f(([e, t]) => {
8342
+ let n = $(t, e, N(0), N(Tl)), r = $(t, e, N(1), N(Tl)), i = $(t, e, N(2), N(Tl)), a = $(t, e, N(3), N(Tl)), o = $(t, e, N(4), N(Tl)), s = $(t, e, N(5), N(Tl)), c = $(t, e, N(7), N(Tl));
8343
+ return Dl({
8329
8344
  v0: n.xyz,
8330
8345
  v1: r.xyz,
8331
8346
  v2: i.xyz,
@@ -8334,27 +8349,27 @@ var Dl = 8, Ol = 2, kl = Cn({
8334
8349
  n2: s.xyz,
8335
8350
  materialIndex: N(c.z)
8336
8351
  });
8337
- }), jl = f(([e, t, n, r, i, a, o]) => {
8338
- let s = kl.wrap(Al(e, i)), c = yl(s.v0, s.v1, s.v2), l = $(a, s.materialIndex, N(Fi.EMISSIVE_ROUGHNESS), Pi), u = $(a, s.materialIndex, N(Fi.IOR_TRANSMISSION), Pi), d = F(l.x.mul(.2126).add(l.y.mul(.7152)).add(l.z.mul(.0722)).mul(u.a).mul(c), M(1e-10)).div(F(o, M(1e-10))), f = M(0).toVar();
8339
- return p(xl(s.v0, s.v1, s.v2, r), () => {
8340
- let e = bl(s.v0, s.v1, s.v2, r);
8352
+ }), kl = f(([e, t, n, r, i, a, o]) => {
8353
+ let s = Dl.wrap(Ol(e, i)), c = _l(s.v0, s.v1, s.v2), l = $(a, s.materialIndex, N(Fi.EMISSIVE_ROUGHNESS), Pi), u = $(a, s.materialIndex, N(Fi.IOR_TRANSMISSION), Pi), d = F(l.x.mul(.2126).add(l.y.mul(.7152)).add(l.z.mul(.0722)).mul(u.a).mul(c), M(1e-10)).div(F(o, M(1e-10))), f = M(0).toVar();
8354
+ return p(yl(s.v0, s.v1, s.v2, r), () => {
8355
+ let e = vl(s.v0, s.v1, s.v2, r);
8341
8356
  f.assign(d.div(F(e, M(1e-10))));
8342
8357
  }).Else(() => {
8343
8358
  let e = L(O(s.v1.sub(s.v0), s.v2.sub(s.v0))), r = F(A(n.negate(), e), .001), i = t.mul(t), a = d.div(c);
8344
8359
  f.assign(a.mul(i).div(r));
8345
8360
  }), F(f, Mi);
8346
- }), Ml = f(([e, t, n, r]) => {
8361
+ }), Al = f(([e, t, n, r]) => {
8347
8362
  let i = N(0).toVar(), a = n.sub(1).toVar();
8348
8363
  return m(i.lessThan(a), () => {
8349
- let n = i.add(a).div(2).toVar(), o = e.element(t.add(n.mul(N(Ol)))).b;
8364
+ let n = i.add(a).div(2).toVar(), o = e.element(t.add(n.mul(N(El)))).b;
8350
8365
  p(o.lessThan(r), () => {
8351
8366
  i.assign(n.add(1));
8352
8367
  }).Else(() => {
8353
8368
  a.assign(n);
8354
8369
  });
8355
8370
  }), i;
8356
- }), Nl = f(([e, t, n, r, i, a, o, s]) => {
8357
- let c = gl({
8371
+ }), jl = f(([e, t, n, r, i, a, o, s]) => {
8372
+ let c = ml({
8358
8373
  position: W(0),
8359
8374
  normal: W(0),
8360
8375
  emission: W(0),
@@ -8366,40 +8381,40 @@ var Dl = 8, Ol = 2, kl = Cn({
8366
8381
  valid: !1
8367
8382
  }).toVar();
8368
8383
  return p(a.greaterThan(N(0)), () => {
8369
- let l = Ml(r, i, a, Y(n)).toVar(), u = i.add(l.mul(N(Ol))), d = r.element(u), f = r.element(u.add(1)), m = N(d.r), h = F(d.g, M(1e-10)), g = f.xyz, _ = f.w, v = kl.wrap(Al(m, s)), y = U(Y(n).toVar(), Y(n).toVar()), b = L(O(v.v1.sub(v.v0), v.v2.sub(v.v0)));
8370
- p(xl(v.v0, v.v1, v.v2, e), () => {
8371
- let n = Sl.wrap(wl(v.v0, v.v1, v.v2, e, y));
8384
+ let l = Al(r, i, a, Y(n)).toVar(), u = i.add(l.mul(N(El))), d = r.element(u), f = r.element(u.add(1)), m = N(d.r), h = F(d.g, M(1e-10)), g = f.xyz, _ = f.w, v = Dl.wrap(Ol(m, s)), y = U(Y(n).toVar(), Y(n).toVar()), b = L(O(v.v1.sub(v.v0), v.v2.sub(v.v0)));
8385
+ p(yl(v.v0, v.v1, v.v2, e), () => {
8386
+ let n = bl.wrap(Sl(v.v0, v.v1, v.v2, e, y));
8372
8387
  p(n.valid.and(n.solidAngle.greaterThan(1e-7)), () => {
8373
8388
  let r = n.direction, i = n.position, a = A(r, t), s = A(r, b.negate());
8374
8389
  p(a.greaterThan(0).and(s.greaterThan(0)), () => {
8375
- let t = Tl(i, v.v0, v.v1, v.v2), a = L(v.n0.mul(t.x).add(v.n1.mul(t.y)).add(v.n2.mul(t.z))), l = ie(i.sub(e)), u = h.div(F(o, M(1e-10))).div(n.solidAngle);
8390
+ let t = Cl(i, v.v0, v.v1, v.v2), a = L(v.n0.mul(t.x).add(v.n1.mul(t.y)).add(v.n2.mul(t.z))), l = ie(i.sub(e)), u = h.div(F(o, M(1e-10))).div(n.solidAngle);
8376
8391
  c.position.assign(i), c.normal.assign(a), c.emission.assign(g), c.direction.assign(r), c.distance.assign(l), c.pdf.assign(F(u, Mi)), c.area.assign(_), c.cosThetaLight.assign(s), c.valid.assign(!0);
8377
8392
  });
8378
8393
  });
8379
8394
  }).Else(() => {
8380
- let n = vl(v.v0, v.v1, v.v2, y), r = El(v.n0, v.n1, v.n2, y), i = n.sub(e), a = A(i, i), s = xe(a), l = i.div(s), u = A(l, t), d = A(l, r.negate());
8395
+ let n = gl(v.v0, v.v1, v.v2, y), r = wl(v.n0, v.n1, v.n2, y), i = n.sub(e), a = A(i, i), s = xe(a), l = i.div(s), u = A(l, t), d = A(l, r.negate());
8381
8396
  p(u.greaterThan(0).and(d.greaterThan(0)), () => {
8382
8397
  let e = h.div(F(o, M(1e-10)).mul(_)).mul(a).div(d);
8383
8398
  c.position.assign(n), c.normal.assign(r), c.emission.assign(g), c.direction.assign(l), c.distance.assign(s), c.pdf.assign(F(e, Mi)), c.area.assign(_), c.cosThetaLight.assign(d), c.valid.assign(!0);
8384
8399
  });
8385
8400
  });
8386
8401
  }), c;
8387
- }), Pl = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, m]) => {
8388
- let h = _l({
8402
+ }), Ml = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, m]) => {
8403
+ let h = hl({
8389
8404
  contribution: W(0),
8390
8405
  hasEmissive: !1,
8391
8406
  emissionOnly: W(0),
8392
8407
  distance: M(0)
8393
8408
  }).toVar();
8394
8409
  return p(i.greaterThan(N(1)).and(r.roughness.greaterThan(.9)).and(r.metalness.lessThan(.1)).not(), () => {
8395
- let i = gl.wrap(Nl(e, t, a, s, c, l, u, d));
8410
+ let i = ml.wrap(jl(e, t, a, s, c, l, u, d));
8396
8411
  p(i.valid.and(i.pdf.greaterThan(0)), () => {
8397
8412
  h.hasEmissive.assign(!0), h.emissionOnly.assign(i.emission), h.distance.assign(i.distance);
8398
8413
  let a = F(M(0), A(t, i.direction));
8399
8414
  p(a.greaterThan(0), () => {
8400
8415
  let s = m(e, t, r), c = e.add(s), l = i.distance.sub(.001), u = f(c, i.direction, l);
8401
8416
  p(u.greaterThan(0), () => {
8402
- let e = vi.wrap(Wi(t, n, i.direction)), s = Bc(r, e), c = Jc(r, e), l = R(c.greaterThan(0), Vi({
8417
+ let e = vi.wrap(Wi(t, n, i.direction)), s = Rc(r, e), c = Kc(r, e), l = R(c.greaterThan(0), Vi({
8403
8418
  pdf1: i.pdf,
8404
8419
  pdf2: c
8405
8420
  }), M(1));
@@ -8408,11 +8423,11 @@ var Dl = 8, Ol = 2, kl = Cn({
8408
8423
  });
8409
8424
  });
8410
8425
  }), h;
8411
- }), Fl = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, p]) => _l.wrap(Pl(e, t, n, r, i, a, o, s, c, l, u, d, f, p)).contribution), Il = 4, Ll = 2, Rl = 32, zl = f(([e, t, n, r]) => R(t.greaterThan(r), M(1), t.mul(r).add(e.mul(n)))), Bl = f(([e, t, n, r]) => R(t.greaterThan(r), M(0), e.mul(r).sub(t.mul(n)))), Vl = f(([e, t, n, r, i, a]) => {
8412
- let o = e.add(n).mul(.5), s = ie(n.sub(e)), c = a.sub(o), l = F(A(c, c), M(1e-12)), u = F(l, s.mul(.5)), d = A(r, c.div(xe(l))), f = xe(F(M(1).sub(d.mul(d)), M(0))), p = s.mul(s).mul(.25), m = E(p.div(l), M(0), M(1)), h = R(l.lessThan(p), M(-1), xe(F(M(1).sub(m), M(0)))), g = xe(F(M(1).sub(h.mul(h)), M(0))), _ = xe(F(M(1).sub(i.mul(i)), M(0))), v = zl(f, d, _, i), y = zl(Bl(f, d, _, i), v, g, h);
8426
+ }), Nl = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, p]) => hl.wrap(Ml(e, t, n, r, i, a, o, s, c, l, u, d, f, p)).contribution), Pl = 4, Fl = 2, Il = 32, Ll = f(([e, t, n, r]) => R(t.greaterThan(r), M(1), t.mul(r).add(e.mul(n)))), Rl = f(([e, t, n, r]) => R(t.greaterThan(r), M(0), e.mul(r).sub(t.mul(n)))), zl = f(([e, t, n, r, i, a]) => {
8427
+ let o = e.add(n).mul(.5), s = ie(n.sub(e)), c = a.sub(o), l = F(A(c, c), M(1e-12)), u = F(l, s.mul(.5)), d = A(r, c.div(xe(l))), f = xe(F(M(1).sub(d.mul(d)), M(0))), p = s.mul(s).mul(.25), m = E(p.div(l), M(0), M(1)), h = R(l.lessThan(p), M(-1), xe(F(M(1).sub(m), M(0)))), g = xe(F(M(1).sub(h.mul(h)), M(0))), _ = xe(F(M(1).sub(i.mul(i)), M(0))), v = Ll(f, d, _, i), y = Ll(Rl(f, d, _, i), v, g, h);
8413
8428
  return F(R(y.greaterThan(M(0)), t.mul(y).div(u), M(0)), M(0));
8414
- }), Hl = f(([e, t, n, r, i, a, o]) => {
8415
- let s = gl({
8429
+ }), Bl = f(([e, t, n, r, i, a, o]) => {
8430
+ let s = ml({
8416
8431
  position: W(0),
8417
8432
  normal: W(0),
8418
8433
  emission: W(0),
@@ -8423,12 +8438,12 @@ var Dl = 8, Ol = 2, kl = Cn({
8423
8438
  cosThetaLight: M(0),
8424
8439
  valid: !1
8425
8440
  }).toVar(), c = M(1).toVar(), l = N(0).toVar(), u = T(!1).toVar();
8426
- return m(Rl, () => {
8427
- let t = l.mul(N(Il)), i = r.element(t.add(N(1))), a = r.element(t.add(N(2)));
8441
+ return m(Il, () => {
8442
+ let t = l.mul(N(Pl)), i = r.element(t.add(N(1))), a = r.element(t.add(N(2)));
8428
8443
  p(i.w.greaterThan(.5), () => {
8429
8444
  u.assign(T(!0)), d();
8430
8445
  });
8431
- let o = N(a.x), s = N(a.y), f = o.mul(N(Il)), m = r.element(f), h = r.element(f.add(N(1))), g = s.mul(N(Il)), _ = r.element(g), v = r.element(g.add(N(1))), y = r.element(f.add(N(3))), b = r.element(g.add(N(3))), x = Vl(m.xyz, m.w, h.xyz, y.xyz, y.w, e), S = Vl(_.xyz, _.w, v.xyz, b.xyz, b.w, e), C = x.add(S);
8446
+ let o = N(a.x), s = N(a.y), f = o.mul(N(Pl)), m = r.element(f), h = r.element(f.add(N(1))), g = s.mul(N(Pl)), _ = r.element(g), v = r.element(g.add(N(1))), y = r.element(f.add(N(3))), b = r.element(g.add(N(3))), x = zl(m.xyz, m.w, h.xyz, y.xyz, y.w, e), S = zl(_.xyz, _.w, v.xyz, b.xyz, b.w, e), C = x.add(S);
8432
8447
  p(C.lessThanEqual(M(0)), () => {
8433
8448
  l.assign(o);
8434
8449
  }).Else(() => {
@@ -8440,44 +8455,44 @@ var Dl = 8, Ol = 2, kl = Cn({
8440
8455
  });
8441
8456
  });
8442
8457
  }), p(u, () => {
8443
- let u = l.mul(N(Il)), f = r.element(u), h = r.element(u.add(N(2))), g = N(h.x), _ = N(h.y), v = F(f.w, M(1e-10)), y = Y(n).mul(v), b = M(0).toVar(), x = g.add(_.sub(N(1))).toVar(), S = M(1e-10).toVar();
8458
+ let u = l.mul(N(Pl)), f = r.element(u), h = r.element(u.add(N(2))), g = N(h.x), _ = N(h.y), v = F(f.w, M(1e-10)), y = Y(n).mul(v), b = M(0).toVar(), x = g.add(_.sub(N(1))).toVar(), S = M(1e-10).toVar();
8444
8459
  m({
8445
8460
  start: N(0),
8446
8461
  end: _
8447
8462
  }, ({ i: e }) => {
8448
- let t = g.add(e), n = a.add(t.mul(N(Ll))), r = F(i.element(n).g, M(0));
8463
+ let t = g.add(e), n = a.add(t.mul(N(Fl))), r = F(i.element(n).g, M(0));
8449
8464
  b.addAssign(r), p(b.greaterThanEqual(y).and(r.greaterThan(M(0))), () => {
8450
8465
  x.assign(t), S.assign(r), d();
8451
8466
  });
8452
8467
  }), c.mulAssign(S.div(v));
8453
- let C = a.add(x.mul(N(Ll))), w = i.element(C), T = i.element(C.add(N(1))), E = N(w.r), D = T.xyz, k = T.w, j = kl.wrap(Al(E, o)), ee = U(Y(n).toVar(), Y(n).toVar()), te = L(O(j.v1.sub(j.v0), j.v2.sub(j.v0)));
8454
- p(xl(j.v0, j.v1, j.v2, e), () => {
8455
- let n = Sl.wrap(wl(j.v0, j.v1, j.v2, e, ee));
8468
+ let C = a.add(x.mul(N(Fl))), w = i.element(C), T = i.element(C.add(N(1))), E = N(w.r), D = T.xyz, k = T.w, j = Dl.wrap(Ol(E, o)), ee = U(Y(n).toVar(), Y(n).toVar()), te = L(O(j.v1.sub(j.v0), j.v2.sub(j.v0)));
8469
+ p(yl(j.v0, j.v1, j.v2, e), () => {
8470
+ let n = bl.wrap(Sl(j.v0, j.v1, j.v2, e, ee));
8456
8471
  p(n.valid.and(n.solidAngle.greaterThan(M(1e-7))), () => {
8457
8472
  let r = n.direction, i = n.position, a = A(r, t), o = A(r, te.negate());
8458
8473
  p(a.greaterThan(M(0)).and(o.greaterThan(M(0))), () => {
8459
- let t = Tl(i, j.v0, j.v1, j.v2), a = L(j.n0.mul(t.x).add(j.n1.mul(t.y)).add(j.n2.mul(t.z))), l = ie(i.sub(e)), u = c.div(F(n.solidAngle, M(1e-10)));
8474
+ let t = Cl(i, j.v0, j.v1, j.v2), a = L(j.n0.mul(t.x).add(j.n1.mul(t.y)).add(j.n2.mul(t.z))), l = ie(i.sub(e)), u = c.div(F(n.solidAngle, M(1e-10)));
8460
8475
  s.position.assign(i), s.normal.assign(a), s.emission.assign(D), s.direction.assign(r), s.distance.assign(l), s.pdf.assign(F(u, Mi)), s.area.assign(k), s.cosThetaLight.assign(o), s.valid.assign(!0);
8461
8476
  });
8462
8477
  });
8463
8478
  }).Else(() => {
8464
- let n = vl(j.v0, j.v1, j.v2, ee), r = El(j.n0, j.n1, j.n2, ee), i = n.sub(e), a = A(i, i), o = xe(a), l = i.div(o), u = A(l, t), d = A(l, r.negate());
8479
+ let n = gl(j.v0, j.v1, j.v2, ee), r = wl(j.n0, j.n1, j.n2, ee), i = n.sub(e), a = A(i, i), o = xe(a), l = i.div(o), u = A(l, t), d = A(l, r.negate());
8465
8480
  p(u.greaterThan(M(0)).and(d.greaterThan(M(0))), () => {
8466
8481
  let e = c.div(F(k, M(1e-10))).mul(a).div(d);
8467
8482
  s.position.assign(n), s.normal.assign(r), s.emission.assign(D), s.direction.assign(l), s.distance.assign(o), s.pdf.assign(F(e, Mi)), s.area.assign(k), s.cosThetaLight.assign(d), s.valid.assign(!0);
8468
8483
  });
8469
8484
  });
8470
8485
  }), s;
8471
- }), Ul = f(([e, t, n, r, i, a, o, s]) => {
8486
+ }), Vl = f(([e, t, n, r, i, a, o, s]) => {
8472
8487
  let c = M(0).toVar(), l = N(e).toVar(), u = i.element(o.add(l.shiftRight(N(2)))), f = l.bitAnd(N(3)), h = R(f.equal(N(0)), u.x, R(f.equal(N(1)), u.y, R(f.equal(N(2)), u.z, u.w))).toVar();
8473
8488
  return p(h.greaterThanEqual(M(0)), () => {
8474
8489
  let e = N(h).toVar(), o = M(1).toVar(), u = N(0).toVar(), f = N(0).toVar(), g = T(!1).toVar();
8475
- m(Rl, () => {
8476
- let t = u.mul(N(Il));
8490
+ m(Il, () => {
8491
+ let t = u.mul(N(Pl));
8477
8492
  p(i.element(t.add(N(1))).w.greaterThan(.5), () => {
8478
8493
  g.assign(T(!0)), d();
8479
8494
  });
8480
- let n = i.element(t.add(N(2))), a = N(n.x), s = N(n.y), c = a.mul(N(Il)), l = i.element(c), m = i.element(c.add(N(1))), h = i.element(c.add(N(3))), _ = s.mul(N(Il)), v = i.element(_), y = i.element(_.add(N(1))), b = i.element(_.add(N(3))), x = Vl(l.xyz, l.w, m.xyz, h.xyz, h.w, r), S = Vl(v.xyz, v.w, y.xyz, b.xyz, b.w, r), C = x.add(S), w = e.shiftRight(f).bitAnd(N(1)).equal(N(1));
8495
+ let n = i.element(t.add(N(2))), a = N(n.x), s = N(n.y), c = a.mul(N(Pl)), l = i.element(c), m = i.element(c.add(N(1))), h = i.element(c.add(N(3))), _ = s.mul(N(Pl)), v = i.element(_), y = i.element(_.add(N(1))), b = i.element(_.add(N(3))), x = zl(l.xyz, l.w, m.xyz, h.xyz, h.w, r), S = zl(v.xyz, v.w, y.xyz, b.xyz, b.w, r), C = x.add(S), w = e.shiftRight(f).bitAnd(N(1)).equal(N(1));
8481
8496
  p(C.lessThanEqual(M(0)), () => {
8482
8497
  p(w, () => {
8483
8498
  o.assign(M(0)), u.assign(s);
@@ -8493,28 +8508,28 @@ var Dl = 8, Ol = 2, kl = Cn({
8493
8508
  });
8494
8509
  }), f.addAssign(N(1));
8495
8510
  }), p(g.and(o.greaterThan(M(0))), () => {
8496
- let e = u.mul(N(Il)), f = i.element(e), h = i.element(e.add(N(2))), g = N(h.x), _ = N(h.y), v = F(f.w, M(1e-10)), y = M(0).toVar();
8511
+ let e = u.mul(N(Pl)), f = i.element(e), h = i.element(e.add(N(2))), g = N(h.x), _ = N(h.y), v = F(f.w, M(1e-10)), y = M(0).toVar();
8497
8512
  m({
8498
8513
  start: N(0),
8499
8514
  end: _
8500
8515
  }, ({ i: e }) => {
8501
- let t = g.add(e), n = i.element(a.add(t.mul(N(Ll))));
8516
+ let t = g.add(e), n = i.element(a.add(t.mul(N(Fl))));
8502
8517
  p(N(n.r).equal(l), () => {
8503
8518
  y.assign(F(n.g, M(0))), d();
8504
8519
  });
8505
8520
  }), o.mulAssign(y.div(v));
8506
- let b = kl.wrap(Al(l, s));
8507
- p(xl(b.v0, b.v1, b.v2, r), () => {
8508
- let e = bl(b.v0, b.v1, b.v2, r);
8521
+ let b = Dl.wrap(Ol(l, s));
8522
+ p(yl(b.v0, b.v1, b.v2, r), () => {
8523
+ let e = vl(b.v0, b.v1, b.v2, r);
8509
8524
  c.assign(o.div(F(e, M(1e-10))));
8510
8525
  }).Else(() => {
8511
- let e = L(O(b.v1.sub(b.v0), b.v2.sub(b.v0))), r = F(A(n.negate(), e), M(.001)), i = yl(b.v0, b.v1, b.v2), a = t.mul(t), s = o.div(F(i, M(1e-10)));
8526
+ let e = L(O(b.v1.sub(b.v0), b.v2.sub(b.v0))), r = F(A(n.negate(), e), M(.001)), i = _l(b.v0, b.v1, b.v2), a = t.mul(t), s = o.div(F(i, M(1e-10)));
8512
8527
  c.assign(s.mul(a).div(r));
8513
8528
  });
8514
8529
  });
8515
8530
  }), F(c, Mi);
8516
- }), Wl = 0x8ac7230489e80000, Gl = 1e-4, Kl = 1e-4, ql = .001, Jl = 4294967294;
8517
- function Yl(e) {
8531
+ }), Hl = 0x8ac7230489e80000, Ul = 1e-4, Wl = 1e-4, Gl = .001;
8532
+ function Kl(e) {
8518
8533
  let { bvhBuffer: t, triangleBuffer: n, materialBuffer: r, envCDFTexture: i, lightBuffer: a, rayBufferRW: o, rngBufferRW: s, hitBufferRO: c, gBufferRW: l, counters: u, activeIndicesRO: d, albedoMaps: g, normalMaps: _, bumpMaps: v, metalnessMaps: y, roughnessMaps: b, emissiveMaps: x, displacementMaps: C, envTexture: w, environmentIntensity: D, envMatrix: O, enableEnvironmentLight: k, useEnvMapIS: ee, groundProjectionEnabled: te, groundProjectionRadius: ne, groundProjectionHeight: P, groundProjectionLevel: ae, enableGroundCatcher: oe, groundCatcherHeight: ce, envTotalSum: le, envCompensationDelta: I, envResolution: ue, directionalLightsBuffer: de, numDirectionalLights: fe, areaLightsBuffer: pe, numAreaLights: me, pointLightsBuffer: he, numPointLights: ge, spotLightsBuffer: ve, numSpotLights: ye, maxBounceCount: be, maxSubsurfaceSteps: xe, currentBounce: Se, transparentBackground: Ce, backgroundIntensity: we, backgroundColor: Te, backgroundBlurriness: Ee, backgroundBlurSamples: De, showBackground: Oe, globalIlluminationIntensity: ke, cameraProjectionMatrix: z, cameraViewMatrix: Ae, fireflyThreshold: je, frame: V, resolution: Me, emissiveTriangleCount: Ne, emissiveVec4Offset: Pe, emissiveTotalPower: Fe, emissiveBoost: Ie, totalTriangleCount: H, enableEmissiveTriangleSampling: K, lightBVHNodeCount: Le, reverseMapVec4Offset: Re, maxRayCount: ze, auxGBufferEnabled: Be } = e, Ve = Be.greaterThan(B(0)), He = a !== void 0, Ue = (e, t, n, r) => {
8519
8534
  let i = L(e).toVar(), a = F(n, N(1)).toVar(), o = W(0).toVar();
8520
8535
  return m({
@@ -8524,7 +8539,7 @@ function Yl(e) {
8524
8539
  condition: "<"
8525
8540
  }, () => {
8526
8541
  let e = Ao(i, t, U(Y(r).toVar(), Y(r).toVar())).toVar();
8527
- o.addAssign(Lc({
8542
+ o.addAssign(Fc({
8528
8543
  tex: w,
8529
8544
  samp: _e(w),
8530
8545
  direction: e,
@@ -8535,30 +8550,30 @@ function Yl(e) {
8535
8550
  }), o.div(M(a));
8536
8551
  };
8537
8552
  return f(() => {
8538
- let e = re, m = u ? S(u.element(B(cc.ENTERING_COUNT))) : ze;
8553
+ let e = re, m = u ? S(u.element(B(oc.ENTERING_COUNT))) : ze;
8539
8554
  p(e.greaterThanEqual(m), () => {
8540
8555
  h();
8541
8556
  });
8542
8557
  let H = d.element(e), Be = Ns(o, H).toVar();
8543
- p(Be.bitAnd(B(lc.ACTIVE)).equal(B(0)), () => {
8558
+ p(Be.bitAnd(B(sc.ACTIVE)).equal(B(0)), () => {
8544
8559
  h();
8545
8560
  });
8546
- let We = Be.bitAnd(B(lc.REDIRECTED)).equal(B(0)).toVar(), Ge = js(o, H).toVar(), Ke = Ms(o, H).toVar(), qe = Ps(o, H).toVar(), Je = Is(o, H).toVar(), Ye = H, Xe = s.element(H).toVar(), Ze = qs(c, H).toVar(), Qe = Xs(c, H).toVar(), $e = Ys(c, H).toVar(), et = Zs(c, H).toVar(), tt = Js(c, H).toVar(), nt = ic(o, H).toVar(), rt = N(Se).toVar(), it = ac(o, H).toVar();
8561
+ let We = Be.bitAnd(B(sc.REDIRECTED)).equal(B(0)).toVar(), Ge = js(o, H).toVar(), Ke = Ms(o, H).toVar(), qe = Ps(o, H).toVar(), Je = Is(o, H).toVar(), Ye = H, Xe = s.element(H).toVar(), Ze = Ks(c, H).toVar(), Qe = Ys(c, H).toVar(), $e = Js(c, H).toVar(), et = Xs(c, H).toVar(), tt = qs(c, H).toVar(), nt = nc(o, H).toVar(), rt = N(Se).toVar(), it = rc(o, H).toVar();
8547
8562
  p(oe.and(rt.equal(0)), () => {
8548
8563
  let e = Ke.y.toVar();
8549
8564
  p(e.abs().greaterThan(M(ki)), () => {
8550
8565
  let a = ce.sub(Ge.y).div(e).toVar();
8551
- p(a.greaterThan(M(Gl)).and(a.lessThan(Ze)), () => {
8552
- let e = Ge.add(Ke.mul(a)).toVar(), c = W(0, 1, 0), u = Ke.negate().toVar(), d = di.wrap(Qi()).toVar(), f = xa(c, U(Y(Xe).toVar(), Y(Xe).toVar())).toVar(), m = f.y.mul(Di).toVar(), g = W(Di), _ = pi.wrap(Xc(e, c, d, u, f, m, g, rt, Xe, de, fe, pe, me, he, ge, ve, ye, t, n, r, w, D, O, i, le, I, ue, k, T(!0))).toVar(), v = F(A(_.shadowed, Ni), M(0)), y = F(A(_.unoccluded, Ni), M(0)).toVar(), b = E(v.div(F(y, M(Kl))), 0, 1).toVar();
8553
- p(y.lessThan(M(ql)), () => {
8566
+ p(a.greaterThan(M(Ul)).and(a.lessThan(Ze)), () => {
8567
+ let e = Ge.add(Ke.mul(a)).toVar(), c = W(0, 1, 0), u = Ke.negate().toVar(), d = di.wrap(Qi()).toVar(), f = xa(c, U(Y(Xe).toVar(), Y(Xe).toVar())).toVar(), m = f.y.mul(Di).toVar(), g = W(Di), _ = pi.wrap(Jc(e, c, d, u, f, m, g, rt, Xe, de, fe, pe, me, he, ge, ve, ye, t, n, r, w, D, O, i, le, I, ue, k, T(!0))).toVar(), v = F(A(_.shadowed, Ni), M(0)), y = F(A(_.unoccluded, Ni), M(0)).toVar(), b = E(v.div(F(y, M(Wl))), 0, 1).toVar();
8568
+ p(y.lessThan(M(Gl)), () => {
8554
8569
  b.assign(1);
8555
8570
  });
8556
- let x = zc(Ge, Ke, te, ne, P, ae).toVar(), S = W(0).toVar();
8571
+ let x = Lc(Ge, Ke, te, ne, P, ae).toVar(), S = W(0).toVar();
8557
8572
  p(Oe, () => {
8558
8573
  p(Ee.greaterThan(0), () => {
8559
8574
  S.assign(Ue(x, Ee.mul(1.3), De, Xe));
8560
8575
  }).Else(() => {
8561
- S.assign(Lc({
8576
+ S.assign(Fc({
8562
8577
  tex: w,
8563
8578
  samp: _e(w),
8564
8579
  direction: x,
@@ -8570,26 +8585,26 @@ function Yl(e) {
8570
8585
  });
8571
8586
  let C = R(Oe, S.mul(we), Te), j = R(Ce, W(0), C.mul(b)), ee = R(Ce, M(1).sub(b), M(1));
8572
8587
  p(Ve, () => {
8573
- Rs(l, Ye, c, al({
8588
+ Rs(l, Ye, c, rl({
8574
8589
  worldPos: e,
8575
8590
  cameraProjectionMatrix: z,
8576
8591
  cameraViewMatrix: Ae
8577
- }), W(1)), Bs(l, Ye, B(Jl), B(Jl), .5, .5, B(1));
8578
- }), Ks(o, H, G(j, ee)), Ws(o, H, Ke, Be.bitAnd(B(~lc.ACTIVE))), s.element(H).assign(Xe), h();
8592
+ }), W(1));
8593
+ }), Gs(o, H, G(j, ee)), Us(o, H, Ke, Be.bitAnd(B(~sc.ACTIVE))), s.element(H).assign(Xe), h();
8579
8594
  });
8580
8595
  });
8581
- }), p(Ze.greaterThan(Wl), () => {
8596
+ }), p(Ze.greaterThan(Hl), () => {
8582
8597
  let e = We.and(Oe), t = We.not().and(k);
8583
8598
  p(e.or(t), () => {
8584
8599
  let e = Ke.toVar();
8585
8600
  p(We, () => {
8586
- e.assign(zc(Ge, Ke, te, ne, P, ae));
8601
+ e.assign(Lc(Ge, Ke, te, ne, P, ae));
8587
8602
  });
8588
8603
  let t = W(0).toVar();
8589
8604
  p(We.and(Ee.greaterThan(0)), () => {
8590
8605
  t.assign(Ue(e, Ee.mul(1.3), De, Xe));
8591
8606
  }).Else(() => {
8592
- t.assign(Lc({
8607
+ t.assign(Fc({
8593
8608
  tex: w,
8594
8609
  samp: _e(w),
8595
8610
  direction: e,
@@ -8602,7 +8617,7 @@ function Yl(e) {
8602
8617
  p(We.not().and(ee), () => {
8603
8618
  let e = Fs(o, H);
8604
8619
  p(e.greaterThan(0), () => {
8605
- let t = Fc(w, Ke, O, le, I, ue).w;
8620
+ let t = Nc(w, Ke, O, le, I, ue).w;
8606
8621
  p(t.greaterThan(0), () => {
8607
8622
  n.assign(Hi({
8608
8623
  pdf1: e,
@@ -8612,16 +8627,16 @@ function Yl(e) {
8612
8627
  });
8613
8628
  });
8614
8629
  let r = R(We.not(), ke, M(1)), i = R(We, we, n.mul(r)), a = R(We, M(0), M(rt));
8615
- Je.assign(G(Je.xyz.add(il(qe.mul(t).mul(i), a, je, N(V))), Je.w));
8630
+ Je.assign(G(Je.xyz.add(nl(qe.mul(t).mul(i), a, je, N(V))), Je.w));
8616
8631
  }), p(We.and(Oe.not()).and(Ce.not()), () => {
8617
8632
  Je.assign(G(Je.xyz.add(qe.mul(Te)), Je.w));
8618
- }), p(Ce.and(Be.bitAnd(B(lc.HAS_HIT_OPAQUE)).equal(B(0))), () => {
8633
+ }), p(Ce.and(Be.bitAnd(B(sc.HAS_HIT_OPAQUE)).equal(B(0))), () => {
8619
8634
  Je.w.assign(0);
8620
- }), Ks(o, H, Je), Ws(o, H, Ke, Be.bitAnd(B(~lc.ACTIVE))), h();
8635
+ }), Gs(o, H, Je), Us(o, H, Ke, Be.bitAnd(B(~sc.ACTIVE))), h();
8621
8636
  });
8622
- let at = Ge.add(Ke.mul(Ze)).toVar(), ot = L(Qe).toVar(), st = ec(o, H), q = N(st.stackDepth).toVar(), ct = st.ior1.toVar(), lt = st.ior2.toVar(), ut = st.ior3.toVar(), dt = N(st.transTraversals).toVar(), J = M(st.wavelength).toVar();
8637
+ let at = Ge.add(Ke.mul(Ze)).toVar(), ot = L(Qe).toVar(), st = Qs(o, H), q = N(st.stackDepth).toVar(), ct = st.ior1.toVar(), lt = st.ior2.toVar(), ut = st.ior3.toVar(), dt = N(st.transTraversals).toVar(), J = M(st.wavelength).toVar();
8623
8638
  p(q.greaterThan(0), () => {
8624
- let e = nc(o, H).toVar(), t = oc(o, H), n = t.sigmaS.toVar(), r = t.g.toVar();
8639
+ let e = ec(o, H).toVar(), t = ic(o, H), n = t.sigmaS.toVar(), r = t.g.toVar();
8625
8640
  p(F(F(n.x, n.y), n.z).lessThanEqual(0), () => {
8626
8641
  qe.mulAssign(j(e.mul(Ze).negate()));
8627
8642
  }).Else(() => {
@@ -8631,8 +8646,8 @@ function Yl(e) {
8631
8646
  it.addAssign(1);
8632
8647
  let a = E(F(F(qe.x, qe.y), qe.z), .02, 1).toVar();
8633
8648
  p(it.greaterThanEqual(xe).or(Y(Xe).greaterThan(a)).toVar(), () => {
8634
- Ks(o, H, Je), Ws(o, H, Ke, Be.bitAnd(B(~lc.ACTIVE))), s.element(H).assign(Xe), h();
8635
- }), qe.divAssign(a), Be.assign(Be.bitOr(B(lc.REDIRECTED))), Us(o, H, t, nt, it), Ws(o, H, n, Be), Gs(o, H, qe, Fs(o, H)), Ks(o, H, Je), s.element(H).assign(Xe), h();
8649
+ Gs(o, H, Je), Us(o, H, Ke, Be.bitAnd(B(~sc.ACTIVE))), s.element(H).assign(Xe), h();
8650
+ }), qe.divAssign(a), Be.assign(Be.bitOr(B(sc.REDIRECTED))), Hs(o, H, t, nt, it), Us(o, H, n, Be), Ws(o, H, qe, Fs(o, H)), Gs(o, H, Je), s.element(H).assign(Xe), h();
8636
8651
  });
8637
8652
  });
8638
8653
  });
@@ -8652,7 +8667,7 @@ function Yl(e) {
8652
8667
  triangleIndex: N(tt),
8653
8668
  boxTests: N(0),
8654
8669
  triTests: N(0)
8655
- }), r = ml.wrap(hl(e, t, n, C, ft, rt)).toVar();
8670
+ }), r = fl.wrap(pl(e, t, n, C, ft, rt)).toVar();
8656
8671
  pt.assign(r.uv), mt.assign(r.normal), at.assign(r.hitPoint);
8657
8672
  });
8658
8673
  let ht = bi.wrap(Za(g, _, v, y, b, x, ft, pt, ot)).toVar();
@@ -8663,12 +8678,12 @@ function Yl(e) {
8663
8678
  }).Else(() => {
8664
8679
  ot.assign(ht.normal);
8665
8680
  }), p(rt.equal(0).and(Ve), () => {
8666
- let e = al({
8681
+ let e = rl({
8667
8682
  worldPos: at,
8668
8683
  cameraProjectionMatrix: z,
8669
8684
  cameraViewMatrix: Ae
8670
8685
  });
8671
- Rs(l, Ye, W(0, 0, 1), e, W(0)), Bs(l, Ye, tt, Qs(c, H), $e.x, $e.y, B(1));
8686
+ Rs(l, Ye, W(0, 0, 1), e, W(0));
8672
8687
  });
8673
8688
  let _t = M(1).toVar(), vt = M(1).toVar();
8674
8689
  p(q.equal(1), () => {
@@ -8692,7 +8707,7 @@ function Yl(e) {
8692
8707
  lt.assign(ft.ior);
8693
8708
  }), p(q.equal(3), () => {
8694
8709
  ut.assign(ft.ior);
8695
- }), rc(o, H, R(ft.attenuationDistance.greaterThan(0), se(F(ft.attenuationColor, W(.001))).negate().div(ft.attenuationDistance), W(0))), sc(o, H, W(0), M(0));
8710
+ }), tc(o, H, R(ft.attenuationDistance.greaterThan(0), se(F(ft.attenuationColor, W(.001))).negate().div(ft.attenuationDistance), W(0))), ac(o, H, W(0), M(0));
8696
8711
  });
8697
8712
  }).Else(() => {
8698
8713
  p(q.greaterThan(0), () => {
@@ -8710,7 +8725,7 @@ function Yl(e) {
8710
8725
  ut.assign(ft.ior);
8711
8726
  });
8712
8727
  let e = wa.wrap(Oa(ft.subsurfaceColor, ft.subsurfaceRadius, ft.subsurfaceRadiusScale)).toVar();
8713
- rc(o, H, e.sigmaT.sub(e.sigmaS)), sc(o, H, e.sigmaS, E(ft.subsurfaceAnisotropy, -.99, .99));
8728
+ tc(o, H, e.sigmaT.sub(e.sigmaS)), ac(o, H, e.sigmaS, E(ft.subsurfaceAnisotropy, -.99, .99));
8714
8729
  });
8715
8730
  }).Else(() => {
8716
8731
  p(q.greaterThan(0), () => {
@@ -8722,9 +8737,9 @@ function Yl(e) {
8722
8737
  }), qe.mulAssign(bt.throughput);
8723
8738
  let e = R(bt.entering, ot, ot.negate()), t = R(bt.didReflect, e, Ke), n = at.add(t.mul(.001));
8724
8739
  p(bt.isAlphaSkip.not(), () => {
8725
- Be.assign(Be.bitOr(B(lc.REDIRECTED)));
8726
- }), Us(o, H, n, nt, it), Ws(o, H, bt.direction, Be), Gs(o, H, qe, Fs(o, H)), Ks(o, H, Je), tc(o, H, B(q), B(dt), ct, lt, ut, B(J.add(.5))), s.element(H).assign(Xe), h();
8727
- }), Be.assign(Be.bitOr(B(lc.HAS_HIT_OPAQUE | lc.REDIRECTED)));
8740
+ Be.assign(Be.bitOr(B(sc.REDIRECTED)));
8741
+ }), Hs(o, H, n, nt, it), Us(o, H, bt.direction, Be), Ws(o, H, qe, Fs(o, H)), Gs(o, H, Je), $s(o, H, B(q), B(dt), ct, lt, ut, B(J.add(.5))), s.element(H).assign(Xe), h();
8742
+ }), Be.assign(Be.bitOr(B(sc.HAS_HIT_OPAQUE | sc.REDIRECTED)));
8728
8743
  let xt = ht.emissive.toVar();
8729
8744
  p(ie(xt).greaterThan(0), () => {
8730
8745
  let e = R(We.not(), ke, M(1)), t = M(1).toVar();
@@ -8733,25 +8748,25 @@ function Yl(e) {
8733
8748
  p(e.greaterThan(0), () => {
8734
8749
  let i = M(0).toVar();
8735
8750
  p(Le.greaterThan(N(0)), () => {
8736
- i.assign(Ul(N(tt), Ze, Ke, Ge, a, Pe, Re, n));
8751
+ i.assign(Vl(N(tt), Ze, Ke, Ge, a, Pe, Re, n));
8737
8752
  }).Else(() => {
8738
- i.assign(jl(N(tt), Ze, Ke, Ge, n, r, Fe));
8753
+ i.assign(kl(N(tt), Ze, Ke, Ge, n, r, Fe));
8739
8754
  }), t.assign(Vi({
8740
8755
  pdf1: e,
8741
8756
  pdf2: i
8742
8757
  }));
8743
8758
  });
8744
- }), Je.assign(G(Je.xyz.add(il(xt.mul(qe).mul(e).mul(t), M(rt), je, N(V))), Je.w));
8759
+ }), Je.assign(G(Je.xyz.add(nl(xt.mul(qe).mul(e).mul(t), M(rt), je, N(V))), Je.w));
8745
8760
  });
8746
8761
  let St = Ke.negate().toVar();
8747
8762
  p(A(ot, St).lessThan(0), () => {
8748
8763
  ot.assign(ot.negate());
8749
- }), p(Be.bitAnd(B(lc.AUX_LOCKED)).equal(B(0)).and(Ve), () => {
8750
- let e = Vs(zs(l, Ye)).w;
8764
+ }), p(Be.bitAnd(B(sc.AUX_LOCKED)).equal(B(0)).and(Ve), () => {
8765
+ let e = Bs(zs(l, Ye)).w;
8751
8766
  Rs(l, Ye, ot, e, gt.xyz);
8752
8767
  let t = ft.metalness.greaterThan(.7).and(ft.roughness.lessThan(.3)), n = ft.transmission.greaterThan(.5);
8753
8768
  p(t.or(n).not(), () => {
8754
- Be.assign(Be.bitOr(B(lc.AUX_LOCKED)));
8769
+ Be.assign(Be.bitOr(B(sc.AUX_LOCKED)));
8755
8770
  });
8756
8771
  });
8757
8772
  let Ct = xi.wrap(Ji(ft.metalness, ft.roughness, ft.transmission, ft.clearcoat, ft.emissive, ft.subsurface)).toVar(), wt = N(Me.x).toVar(), Tt = Un(U(M(N(Ye).mod(wt)).add(.5), M(N(Ye).div(wt)).add(.5)), N(0), rt, Xe, N(-1), Me, V).toVar(), Et = gi({
@@ -8789,67 +8804,67 @@ function Yl(e) {
8789
8804
  triangleIndex: N(0),
8790
8805
  boxTests: N(0),
8791
8806
  triTests: N(0)
8792
- }), n = sl.wrap(cl(e, t, ft, Tt, Xe));
8807
+ }), n = al.wrap(ol(e, t, ft, Tt, Xe));
8793
8808
  Ot.assign(n.L), kt.assign(n.brdf), At.assign(n.pdf);
8794
8809
  }).Else(() => {
8795
- let e = hi.wrap(rl(St, ot, ft, Tt, Xe, Ct, !1, Et, !1, Dt));
8810
+ let e = hi.wrap(tl(St, ot, ft, Tt, Xe, Ct, !1, Et, !1, Dt));
8796
8811
  Ot.assign(e.direction), kt.assign(e.value), At.assign(e.pdf);
8797
8812
  });
8798
- let jt = pi.wrap(Xc(at, ot, ft, St, Ot, At, kt, rt, Xe, de, fe, pe, me, he, ge, ve, ye, t, n, r, w, D, O, i, le, I, ue, k, T(!1))).shadowed.toVar(), Mt = R(rt.greaterThan(0), ke, M(1));
8799
- Je.assign(G(Je.xyz.add(il(qe.mul(jt).mul(Mt), M(rt), je, N(V))), Je.w)), He && p(K.equal(N(1)).and(Ne.greaterThan(N(0))), () => {
8800
- let e = f(([e, i, a]) => ro(e, i, a, kc, t, n, r));
8813
+ let jt = pi.wrap(Jc(at, ot, ft, St, Ot, At, kt, rt, Xe, de, fe, pe, me, he, ge, ve, ye, t, n, r, w, D, O, i, le, I, ue, k, T(!1))).shadowed.toVar(), Mt = R(rt.greaterThan(0), ke, M(1));
8814
+ Je.assign(G(Je.xyz.add(nl(qe.mul(jt).mul(Mt), M(rt), je, N(V))), Je.w)), He && p(K.equal(N(1)).and(Ne.greaterThan(N(0))), () => {
8815
+ let e = f(([e, i, a]) => ro(e, i, a, Dc, t, n, r));
8801
8816
  p(Le.greaterThan(N(0)), () => {
8802
- let t = gl.wrap(Hl(at, ot, Xe, a, a, Pe, n));
8817
+ let t = ml.wrap(Bl(at, ot, Xe, a, a, Pe, n));
8803
8818
  p(rt.greaterThan(N(1)).and(ft.roughness.greaterThan(.9)).and(ft.metalness.lessThan(.1)).not().and(t.valid).and(t.pdf.greaterThan(0)), () => {
8804
8819
  let n = F(M(0), A(ot, t.direction));
8805
8820
  p(n.greaterThan(0), () => {
8806
8821
  let r = io(at, ot, ft), i = at.add(r), a = t.distance.sub(.001), o = e(i, t.direction, a);
8807
8822
  p(o.greaterThan(0), () => {
8808
- let e = Vc(St, t.direction, ot, ft), r = Yc(St, t.direction, ot, ft), i = R(r.greaterThan(0), Vi({
8823
+ let e = zc(St, t.direction, ot, ft), r = qc(St, t.direction, ot, ft), i = R(r.greaterThan(0), Vi({
8809
8824
  pdf1: t.pdf,
8810
8825
  pdf2: r
8811
8826
  }), M(1)), a = t.emission.mul(e).mul(n).div(t.pdf).mul(o).mul(Ie).mul(i);
8812
- Je.assign(G(Je.xyz.add(il(a.mul(qe).mul(Mt), M(rt), je, N(V))), Je.w));
8827
+ Je.assign(G(Je.xyz.add(nl(a.mul(qe).mul(Mt), M(rt), je, N(V))), Je.w));
8813
8828
  });
8814
8829
  });
8815
8830
  });
8816
8831
  }).Else(() => {
8817
- let t = Fl(at, ot, St, ft, rt, Xe, Ie, a, Pe, Ne, Fe, n, e, io);
8818
- Je.assign(G(Je.xyz.add(il(t.mul(qe).mul(Mt), M(rt), je, N(V))), Je.w));
8832
+ let t = Nl(at, ot, St, ft, rt, Xe, Ie, a, Pe, Ne, Fe, n, e, io);
8833
+ Je.assign(G(Je.xyz.add(nl(t.mul(qe).mul(Mt), M(rt), je, N(V))), Je.w));
8819
8834
  });
8820
8835
  });
8821
- let Nt = _i.wrap(va(ft, rt, Ct)).toVar(), Pt = ho.wrap(nl(St, ot, ft, Ot, At, kt, Xe, Nt)).toVar(), Ft = Pt.direction.toVar(), It = F(Pt.combinedPdf, .001).toVar();
8836
+ let Nt = _i.wrap(va(ft, rt, Ct)).toVar(), Pt = ho.wrap(el(St, ot, ft, Ot, At, kt, Xe, Nt)).toVar(), Ft = Pt.direction.toVar(), It = F(Pt.combinedPdf, .001).toVar();
8822
8837
  qe.mulAssign(Pt.throughput);
8823
- let Lt = ol(rt, qe, Ct, Ft, Xe, k, ee).toVar();
8838
+ let Lt = il(rt, qe, Ct, Ft, Xe, k, ee).toVar();
8824
8839
  p(Lt.lessThanEqual(0), () => {
8825
- Ks(o, H, Je), Ws(o, H, Ke, Be.bitAnd(B(~lc.ACTIVE))), s.element(H).assign(Xe), h();
8840
+ Gs(o, H, Je), Us(o, H, Ke, Be.bitAnd(B(~sc.ACTIVE))), s.element(H).assign(Xe), h();
8826
8841
  }), qe.divAssign(Lt), p(nt.greaterThanEqual(be), () => {
8827
- Ks(o, H, Je), Ws(o, H, Ke, Be.bitAnd(B(~lc.ACTIVE))), s.element(H).assign(Xe), h();
8828
- }), Us(o, H, at.add(ot.mul(.001)), nt.add(1), it), Ws(o, H, Ft, Be), Gs(o, H, qe, It), Ks(o, H, Je), tc(o, H, B(q), B(dt), ct, lt, ut, B(J.add(.5))), s.element(H).assign(Xe);
8842
+ Gs(o, H, Je), Us(o, H, Ke, Be.bitAnd(B(~sc.ACTIVE))), s.element(H).assign(Xe), h();
8843
+ }), Hs(o, H, at.add(ot.mul(.001)), nt.add(1), it), Us(o, H, Ft, Be), Ws(o, H, qe, It), Gs(o, H, Je), $s(o, H, B(q), B(dt), ct, lt, ut, B(J.add(.5))), s.element(H).assign(Xe);
8829
8844
  });
8830
8845
  }
8831
8846
  //#endregion
8832
8847
  //#region src/TSL/CompactKernel.js
8833
- function Xl(e) {
8848
+ function ql(e) {
8834
8849
  let { rayBufferRO: t, activeIndicesReadRO: n, activeIndicesWriteRW: r, counters: i, currentActiveCount: a } = e;
8835
8850
  return f(() => {
8836
- let e = re, o = i ? S(i.element(B(cc.ENTERING_COUNT))) : a;
8851
+ let e = re, o = i ? S(i.element(B(oc.ENTERING_COUNT))) : a;
8837
8852
  p(e.greaterThanEqual(o), () => {
8838
8853
  h();
8839
8854
  });
8840
8855
  let s = n.element(e);
8841
- p(Ns(t, s).bitAnd(B(lc.ACTIVE)).notEqual(B(0)), () => {
8842
- let e = x(i.element(B(cc.ACTIVE_RAY_COUNT)), B(1));
8856
+ p(Ns(t, s).bitAnd(B(sc.ACTIVE)).notEqual(B(0)), () => {
8857
+ let e = x(i.element(B(oc.ACTIVE_RAY_COUNT)), B(1));
8843
8858
  r.element(e).assign(s);
8844
8859
  });
8845
8860
  });
8846
8861
  }
8847
- function Zl(e) {
8862
+ function Jl(e) {
8848
8863
  let { rayBufferRO: t, activeIndicesReadRO: n, activeIndicesWriteRW: r, counters: i, currentActiveCount: a } = e;
8849
8864
  return f(() => {
8850
- let e = re, o = i ? S(i.element(B(cc.ENTERING_COUNT))) : a, s = e.lessThan(o), c = n.element(e), l = Ns(t, c), u = s.and(l.bitAnd(B(lc.ACTIVE)).notEqual(B(0))), d = R(u, B(1), B(0)), f = De(d).toVar(), m = Te(d).toVar(), h = De(B(1)).toVar(), g = B(0).toVar();
8865
+ let e = re, o = i ? S(i.element(B(oc.ENTERING_COUNT))) : a, s = e.lessThan(o), c = n.element(e), l = Ns(t, c), u = s.and(l.bitAnd(B(sc.ACTIVE)).notEqual(B(0))), d = R(u, B(1), B(0)), f = De(d).toVar(), m = Te(d).toVar(), h = De(B(1)).toVar(), g = B(0).toVar();
8851
8866
  p(h.equal(B(0)), () => {
8852
- g.assign(x(i.element(B(cc.ACTIVE_RAY_COUNT)), m));
8867
+ g.assign(x(i.element(B(oc.ACTIVE_RAY_COUNT)), m));
8853
8868
  });
8854
8869
  let _ = Ee(g, B(0)).toVar();
8855
8870
  p(u, () => {
@@ -8857,8 +8872,8 @@ function Zl(e) {
8857
8872
  });
8858
8873
  });
8859
8874
  }
8860
- var Ql = /* @__PURE__ */ K("\n fn nanInfToRed( c: vec3f ) -> vec3f {\n let isNan = c.x != c.x || c.y != c.y || c.z != c.z;\n let isInf = abs( c.x ) > 1e30f || abs( c.y ) > 1e30f || abs( c.z ) > 1e30f;\n if ( isNan || isInf ) { return vec3f( 1.0f, 0.0f, 0.0f ); }\n return vec3f( 0.0f );\n }\n");
8861
- function $l(e) {
8875
+ var Yl = /* @__PURE__ */ K("\n fn nanInfToRed( c: vec3f ) -> vec3f {\n let isNan = c.x != c.x || c.y != c.y || c.z != c.z;\n let isInf = abs( c.x ) > 1e30f || abs( c.y ) > 1e30f || abs( c.z ) > 1e30f;\n if ( isNan || isInf ) { return vec3f( 1.0f, 0.0f, 0.0f ); }\n return vec3f( 0.0f );\n }\n");
8876
+ function Xl(e) {
8862
8877
  let { rayBufferRO: t, gBufferRO: n, writeColorTex: r, writeNDTex: i, writeAlbedoTex: a, resolution: o, frame: s, enableAccumulation: c, hasPreviousAccumulated: l, accumulationAlpha: u, cameraIsMoving: d, transparentBackground: m, prevAccumTexture: h, prevNormalDepthTexture: g, prevAlbedoTexture: _, renderWidth: v, renderHeight: y, visMode: b, auxGBufferEnabled: x } = e, S = x.greaterThan(B(0));
8863
8878
  return f(() => {
8864
8879
  let e = N(ze.x).mul(16).add(N(oe.x)), f = N(ze.y).mul(16).add(N(oe.y));
@@ -8866,7 +8881,7 @@ function $l(e) {
8866
8881
  let v = B(f.mul(N(o.x)).add(e)), y = Is(t, v), x = y.xyz.toVar(), C = R(m, y.w, M(1)).toVar(), w = G(0).toVar(), T = G(0).xyz.toVar();
8867
8882
  p(S, () => {
8868
8883
  let e = zs(n, v);
8869
- w.assign(Vs(e)), T.assign(G(Hs(e), 0).xyz);
8884
+ w.assign(Bs(e)), T.assign(G(Vs(e), 0).xyz);
8870
8885
  });
8871
8886
  let E = U(M(e).add(.5), M(f).add(.5)).div(o);
8872
8887
  p(c.and(d.not()).and(s.greaterThan(B(0))).and(l).and(b.notEqual(N(11))), () => {
@@ -8877,7 +8892,7 @@ function $l(e) {
8877
8892
  C.assign(I(e.w, y.w, u));
8878
8893
  });
8879
8894
  }), p(b.equal(N(11)), () => {
8880
- x.assign(Ql(x));
8895
+ x.assign(Yl(x));
8881
8896
  });
8882
8897
  let D = Ie(B(e), B(f));
8883
8898
  Ae(r, D, G(x, C)).toWriteOnly(), p(S, () => {
@@ -8888,11 +8903,11 @@ function $l(e) {
8888
8903
  }
8889
8904
  //#endregion
8890
8905
  //#region src/TSL/Debugger.js
8891
- var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n return vec3f( 1.0f - depth );\n }\n"), tu = /* @__PURE__ */ K("\n fn visualizeNormal( normal: vec3f ) -> vec3f {\n return normal * 0.5f + 0.5f;\n }\n"), nu = /* @__PURE__ */ K("\n fn computeNDCDepthLocal( worldPos: vec3f, cameraProjectionMatrix: mat4x4f, cameraViewMatrix: mat4x4f ) -> f32 {\n let clipPos = cameraProjectionMatrix * cameraViewMatrix * vec4f( worldPos, 1.0f );\n let ndcDepth = clipPos.z / clipPos.w * 0.5f + 0.5f;\n return clamp( ndcDepth, 0.0f, 1.0f );\n }\n"), ru = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, m, h, g, _, v, y, b, x, S]) => {
8906
+ var Zl = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n return vec3f( 1.0f - depth );\n }\n"), Ql = /* @__PURE__ */ K("\n fn visualizeNormal( normal: vec3f ) -> vec3f {\n return normal * 0.5f + 0.5f;\n }\n"), $l = /* @__PURE__ */ K("\n fn computeNDCDepthLocal( worldPos: vec3f, cameraProjectionMatrix: mat4x4f, cameraViewMatrix: mat4x4f ) -> f32 {\n let clipPos = cameraProjectionMatrix * cameraViewMatrix * vec4f( worldPos, 1.0f );\n let ndcDepth = clipPos.z / clipPos.w * 0.5f + 0.5f;\n return clamp( ndcDepth, 0.0f, 1.0f );\n }\n"), eu = f(([e, t, n, r, i, a, o, s, c, l, u, d, f, m, h, g, _, v, y, b, x, S]) => {
8892
8907
  let C = G(1, 0, 1, 1).toVar(), w = ui({
8893
8908
  origin: e,
8894
8909
  direction: t
8895
- }), T = mi.wrap(Oc(w, n, r).toVar());
8910
+ }), T = mi.wrap(Ec(w, n, r).toVar());
8896
8911
  return p(l.equal(N(7)), () => {
8897
8912
  let e = M(T.triTests).div(u);
8898
8913
  C.assign(R(e.lessThan(1), G(W(e), 1), G(1, 0, 0, 1)));
@@ -8901,7 +8916,7 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
8901
8916
  C.assign(R(e.lessThan(1), G(W(e), 1), G(1, 0, 0, 1)));
8902
8917
  }), p(l.equal(N(10)), () => {
8903
8918
  p(c, () => {
8904
- let e = Lc({
8919
+ let e = Fc({
8905
8920
  tex: a,
8906
8921
  samp: _e(a),
8907
8922
  direction: t,
@@ -8949,18 +8964,18 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
8949
8964
  C.assign(G(.5, .5, 1, 1));
8950
8965
  }).Else(() => {
8951
8966
  let e = di.wrap(Zi(T.materialIndex, i)).toVar(), t = L(bi.wrap(Za(m, h, g, _, v, y, e, T.uv, T.normal)).toVar().normal);
8952
- C.assign(G(tu({ normal: t }), 1));
8967
+ C.assign(G(Ql({ normal: t }), 1));
8953
8968
  });
8954
8969
  }), p(l.equal(N(2)), () => {
8955
8970
  p(T.didHit.not(), () => {
8956
8971
  C.assign(G(W(1), 1));
8957
8972
  }).Else(() => {
8958
- let e = nu({
8973
+ let e = $l({
8959
8974
  worldPos: T.hitPoint,
8960
8975
  cameraProjectionMatrix: b,
8961
8976
  cameraViewMatrix: x
8962
8977
  });
8963
- C.assign(G(eu({ depth: e }), 1));
8978
+ C.assign(G(Zl({ depth: e }), 1));
8964
8979
  });
8965
8980
  }), p(l.equal(N(3)), () => {
8966
8981
  p(T.didHit.not(), () => {
@@ -8979,10 +8994,10 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
8979
8994
  }).toVar(), x = ui({
8980
8995
  origin: T.hitPoint.add(u.mul(.001)),
8981
8996
  direction: b
8982
- }), w = mi.wrap(Oc(x, n, r).toVar()), E = W(0).toVar();
8997
+ }), w = mi.wrap(Ec(x, n, r).toVar()), E = W(0).toVar();
8983
8998
  p(w.didHit.not(), () => {
8984
8999
  p(c, () => {
8985
- E.assign(Lc({
9000
+ E.assign(Fc({
8986
9001
  tex: a,
8987
9002
  samp: _e(a),
8988
9003
  direction: b,
@@ -8994,7 +9009,7 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
8994
9009
  }).Else(() => {
8995
9010
  let e = di.wrap(Zi(w.materialIndex, i)).toVar(), t = bi.wrap(Za(m, h, g, _, v, y, e, w.uv, w.normal)).toVar();
8996
9011
  E.assign(t.emissive), p(c, () => {
8997
- let e = L(t.normal).toVar(), n = Lc({
9012
+ let e = L(t.normal).toVar(), n = Fc({
8998
9013
  tex: a,
8999
9014
  samp: _e(a),
9000
9015
  direction: e,
@@ -9010,7 +9025,7 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
9010
9025
  });
9011
9026
  }), p(l.equal(N(6)), () => {
9012
9027
  p(T.didHit, () => {
9013
- let e = T.normal.toVar(), n = L(t.sub(e.mul(A(t, e).mul(2)))).toVar(), r = Lc({
9028
+ let e = T.normal.toVar(), n = L(t.sub(e.mul(A(t, e).mul(2)))).toVar(), r = Fc({
9014
9029
  tex: a,
9015
9030
  samp: _e(a),
9016
9031
  direction: n,
@@ -9020,7 +9035,7 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
9020
9035
  }).xyz, i = r.div(r.add(1));
9021
9036
  C.assign(G(i, 1));
9022
9037
  }).Else(() => {
9023
- let e = Lc({
9038
+ let e = Fc({
9024
9039
  tex: a,
9025
9040
  samp: _e(a),
9026
9041
  direction: t,
@@ -9032,19 +9047,19 @@ var eu = /* @__PURE__ */ K("\n fn visualizeDepth( depth: f32 ) -> vec3f {\n ret
9032
9047
  });
9033
9048
  }), C;
9034
9049
  });
9035
- function iu(e) {
9050
+ function tu(e) {
9036
9051
  let { writeColorTex: t, writeNDTex: n, writeAlbedoTex: r, resolution: i, renderWidth: a, renderHeight: o, cameraWorldMatrix: s, cameraProjectionMatrixInverse: c, cameraProjectionMatrix: l, cameraViewMatrix: u, enableDOF: d, focalLength: m, aperture: h, focusDistance: g, sceneScale: _, apertureScale: v, anamorphicRatio: y, bvhBuffer: b, triangleBuffer: x, materialBuffer: S, envTexture: C, environmentMatrix: w, environmentIntensity: T, enableEnvironmentLight: E, visMode: D, debugVisScale: O, albedoMaps: k, normalMaps: A, bumpMaps: j, metalnessMaps: ee, roughnessMaps: te, emissiveMaps: ne, frame: re } = e;
9037
9052
  return f(() => {
9038
9053
  let e = N(ze.x).mul(16).add(N(oe.x)), f = N(ze.y).mul(16).add(N(oe.y));
9039
9054
  p(e.lessThan(a).and(f.lessThan(o)), () => {
9040
9055
  let a = U(M(e).add(.5), M(f).add(.5)), o = Pn({ state: B(f.mul(N(i.x)).add(e)).add(B(1)) }).toVar(), P = a.div(i).mul(2).sub(1).toVar();
9041
9056
  P.y.assign(P.y.negate());
9042
- let ie = ui.wrap(Ac(P, o, s, c, d, m, h, g, _, v, y)), ae = G(1, 0, 1, 1).toVar();
9057
+ let ie = ui.wrap(Oc(P, o, s, c, d, m, h, g, _, v, y)), ae = G(1, 0, 1, 1).toVar();
9043
9058
  p(D.equal(N(9)), () => {
9044
9059
  let e = Wn(a, N(0), N(1), o, i, re);
9045
9060
  ae.assign(G(e, 1, 1));
9046
9061
  }).Else(() => {
9047
- ae.assign(ru(ie.origin, ie.direction, b, x, S, C, w, T, E, D, O, a, i, k, A, j, ee, te, ne, l, u, re));
9062
+ ae.assign(eu(ie.origin, ie.direction, b, x, S, C, w, T, E, D, O, a, i, k, A, j, ee, te, ne, l, u, re));
9048
9063
  });
9049
9064
  let oe = Ie(B(e), B(f));
9050
9065
  Ae(t, oe, ae).toWriteOnly(), Ae(n, oe, G(.5, .5, 1, 1)).toWriteOnly(), Ae(r, oe, G(ae.xyz, 1)).toWriteOnly();
@@ -9053,9 +9068,9 @@ function iu(e) {
9053
9068
  }
9054
9069
  //#endregion
9055
9070
  //#region src/Stages/PathTracer.js
9056
- var au = class extends Ts {
9071
+ var nu = class extends Ts {
9057
9072
  constructor(e, t, n, r = {}) {
9058
- super(e, t, n, r), this.name = "PathTracer", this._packedBuffers = null, this._queueManager = null, this._kernelManager = null, this._gBufferAttr = null, this._wavefrontReady = !1, this._auxGBufferEnabled = !1, this._auxGBufferUniform = V(0, "uint"), this._useDynamicDispatch = !0, this._useSubgroupCompact = !1, this._lastBounceCounts = null, this._lastBounceCountsBudget = -1, this._readbackPending = !1, this._readbackEveryNFrames = 4, this._readbackFrameCounter = 0, this._readbackGeneration = 0, this._bounceEarlyExitThreshold = 100, this._wfRenderWidth = V(1920, "int"), this._wfRenderHeight = V(1080, "int"), this._wfMaxRayCount = V(0, "uint"), this._wfCurrentBounce = V(0, "int"), this.vramTracker = new gc(), this._registerVRAMProviders(), console.log("PathTracer: initialized (wavefront)");
9073
+ super(e, t, n, r), this.name = "PathTracer", this._packedBuffers = null, this._queueManager = null, this._kernelManager = null, this._gBufferAttr = null, this._wavefrontReady = !1, this._auxGBufferEnabled = !1, this._auxGBufferUniform = V(0, "uint"), this._useDynamicDispatch = !0, this._useSubgroupCompact = !1, this._lastBounceCounts = null, this._lastBounceCountsBudget = -1, this._readbackPending = !1, this._readbackEveryNFrames = 4, this._readbackFrameCounter = 0, this._readbackGeneration = 0, this._bounceEarlyExitThreshold = 100, this._wfRenderWidth = V(1920, "int"), this._wfRenderHeight = V(1080, "int"), this._wfMaxRayCount = V(0, "uint"), this._wfCurrentBounce = V(0, "int"), this.vramTracker = new mc(this.renderer), this._registerVRAMProviders(), console.log("PathTracer: initialized (wavefront)");
9059
9074
  }
9060
9075
  _registerVRAMProviders() {
9061
9076
  let e = this.vramTracker;
@@ -9152,7 +9167,7 @@ var au = class extends Ts {
9152
9167
  }
9153
9168
  if (a.dispatch("extend"), a.dispatch("shade"), a.dispatch("resetActiveCounter"), a.dispatch("compact"), t && a.dispatch("compactCopyback"), a.dispatch("snapshotBounceCount"), e < u && e < s && l[e] !== void 0 && l[e] <= this._bounceEarlyExitThreshold) break;
9154
9169
  }
9155
- a.dispatch("finalWrite"), this._maybeReadbackCounters(), this.storageTextures.copyToReadTargets(this.renderer);
9170
+ a.dispatch("finalWrite"), this._maybeReadbackCounters(), this.storageTextures.copyToReadTargets(this.renderer, this._auxGBufferEnabled);
9156
9171
  let d = this.storageTextures.getReadTextures();
9157
9172
  e && this._publishTexturesToContext(e, d), this._emitStateEvents(), this.cameraOptimizer?.isInInteractionMode() || this.frameCount++, r !== null && (this.maxBounces.value = r), this.performanceMonitor?.end();
9158
9173
  }
@@ -9208,14 +9223,14 @@ var au = class extends Ts {
9208
9223
  if (!e) return;
9209
9224
  let t = this.storageTextures.renderWidth, n = this.storageTextures.renderHeight, r = t * n;
9210
9225
  this._bounceEarlyExitThreshold !== -1 && (this._bounceEarlyExitThreshold = Math.max(100, Math.floor(r / 1e3))), this._packedBuffers ? this._packedBuffers.resize(r) : this._packedBuffers = new As(r);
9211
- let i = As.requiredCapacity(r) * 2;
9226
+ let i = As.requiredCapacity(r) * 1;
9212
9227
  this._gBufferAttr = new o(new Uint32Array(i * 4), 4);
9213
9228
  let a = Ce(this._gBufferAttr, "uvec4"), s = Ce(this._gBufferAttr, "uvec4").toReadOnly();
9214
- this._queueManager ? this._queueManager.resize(this._packedBuffers.capacity) : this._queueManager = new uc(this._packedBuffers.capacity), this._kernelManager ||= new vc(this.renderer);
9229
+ this._queueManager ? this._queueManager.resize(this._packedBuffers.capacity) : this._queueManager = new cc(this._packedBuffers.capacity), this._kernelManager ||= new gc(this.renderer);
9215
9230
  let c = this._packedBuffers, l = this._queueManager;
9216
9231
  this._wfRenderWidth.value = t, this._wfRenderHeight.value = n, this._wfMaxRayCount.value = r;
9217
9232
  let u = this.shaderBuilder.prevColorTexNode, d = this.shaderBuilder.prevNormalDepthTexNode, m = this.shaderBuilder.prevAlbedoTexNode, g = this.storageTextures.getWriteTextures(), _ = l.getCounters(), v = f(() => {
9218
- C(_.element(B(cc.ACTIVE_RAY_COUNT)), B(0));
9233
+ C(_.element(B(oc.ACTIVE_RAY_COUNT)), B(0));
9219
9234
  });
9220
9235
  this._kernelManager.register("resetCounters", v().compute([
9221
9236
  1,
@@ -9227,7 +9242,7 @@ var au = class extends Ts {
9227
9242
  1
9228
9243
  ]));
9229
9244
  let y = f(() => {
9230
- C(_.element(B(cc.ACTIVE_RAY_COUNT)), B(0));
9245
+ C(_.element(B(oc.ACTIVE_RAY_COUNT)), B(0));
9231
9246
  });
9232
9247
  this._kernelManager.register("resetActiveCounter", y().compute([
9233
9248
  1,
@@ -9239,8 +9254,8 @@ var au = class extends Ts {
9239
9254
  1
9240
9255
  ]));
9241
9256
  let b = l.getBounceCounts(), x = this._wfCurrentBounce, w = f(() => {
9242
- let e = S(_.element(B(cc.ACTIVE_RAY_COUNT))), t = B(x).clamp(B(0), B(l.MAX_BOUNCE_SNAPSHOTS - 1));
9243
- b.element(t).assign(e), C(_.element(B(cc.ENTERING_COUNT)), e);
9257
+ let e = S(_.element(B(oc.ACTIVE_RAY_COUNT))), t = B(x).clamp(B(0), B(l.MAX_BOUNCE_SNAPSHOTS - 1));
9258
+ b.element(t).assign(e), C(_.element(B(oc.ENTERING_COUNT)), e);
9244
9259
  });
9245
9260
  this._kernelManager.register("snapshotBounceCount", w().compute([
9246
9261
  1,
@@ -9254,7 +9269,7 @@ var au = class extends Ts {
9254
9269
  let T = l.activeIndices.a, E = f(() => {
9255
9270
  let e = re;
9256
9271
  T.element(e).assign(e), p(e.equal(B(0)), () => {
9257
- C(_.element(B(cc.ACTIVE_RAY_COUNT)), this._wfMaxRayCount), C(_.element(B(cc.ENTERING_COUNT)), this._wfMaxRayCount);
9272
+ C(_.element(B(oc.ACTIVE_RAY_COUNT)), this._wfMaxRayCount), C(_.element(B(oc.ENTERING_COUNT)), this._wfMaxRayCount);
9258
9273
  });
9259
9274
  });
9260
9275
  this._kernelManager.register("initActiveIndices", E().compute([
@@ -9266,7 +9281,7 @@ var au = class extends Ts {
9266
9281
  1,
9267
9282
  1
9268
9283
  ]));
9269
- let D = jc({
9284
+ let D = kc({
9270
9285
  rayBufferRW: c.rayBuffer.rw,
9271
9286
  rngBufferRW: c.rngBuffer.rw,
9272
9287
  gBufferRW: a,
@@ -9308,7 +9323,7 @@ var au = class extends Ts {
9308
9323
  emissiveMaps: se,
9309
9324
  displacementMaps: ce
9310
9325
  };
9311
- let le = Mc({
9326
+ let le = Ac({
9312
9327
  bvhBuffer: O,
9313
9328
  triangleBuffer: k,
9314
9329
  materialBuffer: A,
@@ -9327,7 +9342,7 @@ var au = class extends Ts {
9327
9342
  1,
9328
9343
  1
9329
9344
  ]));
9330
- let I = Yl({
9345
+ let I = Kl({
9331
9346
  gBufferRW: a,
9332
9347
  envCompensationDelta: this.envCompensationDelta,
9333
9348
  bvhBuffer: O,
@@ -9405,7 +9420,7 @@ var au = class extends Ts {
9405
9420
  ]));
9406
9421
  let ue = this._useSubgroupCompact && (this.renderer.hasFeature ? this.renderer.hasFeature("subgroups") : !1);
9407
9422
  this._compactIsSubgroup = ue;
9408
- let L = (ue ? Zl : Xl)({
9423
+ let L = (ue ? Jl : ql)({
9409
9424
  rayBufferRO: c.rayBuffer.ro,
9410
9425
  activeIndicesReadRO: l.getActiveReadRO(),
9411
9426
  activeIndicesWriteRW: l.getActiveWrite(),
@@ -9422,7 +9437,7 @@ var au = class extends Ts {
9422
9437
  1
9423
9438
  ]));
9424
9439
  let de = f(() => {
9425
- C(_.element(B(cc.ENTERING_COUNT)), this._wfMaxRayCount);
9440
+ C(_.element(B(oc.ENTERING_COUNT)), this._wfMaxRayCount);
9426
9441
  });
9427
9442
  this._kernelManager.register("enterFull", de().compute([
9428
9443
  1,
@@ -9435,7 +9450,7 @@ var au = class extends Ts {
9435
9450
  ]));
9436
9451
  let fe = l.activeIndicesRO.b, pe = l.activeIndices.a, me = f(() => {
9437
9452
  let e = re;
9438
- p(e.greaterThanEqual(S(_.element(B(cc.ACTIVE_RAY_COUNT)))), () => {
9453
+ p(e.greaterThanEqual(S(_.element(B(oc.ACTIVE_RAY_COUNT)))), () => {
9439
9454
  h();
9440
9455
  }), pe.element(e).assign(fe.element(e));
9441
9456
  });
@@ -9448,7 +9463,7 @@ var au = class extends Ts {
9448
9463
  1,
9449
9464
  1
9450
9465
  ]));
9451
- let he = $l({
9466
+ let he = Xl({
9452
9467
  rayBufferRO: c.rayBuffer.ro,
9453
9468
  gBufferRO: s,
9454
9469
  writeColorTex: g.color,
@@ -9478,7 +9493,7 @@ var au = class extends Ts {
9478
9493
  16,
9479
9494
  1
9480
9495
  ]));
9481
- let ge = iu({
9496
+ let ge = tu({
9482
9497
  writeColorTex: g.color,
9483
9498
  writeNDTex: g.normalDepth,
9484
9499
  writeAlbedoTex: g.albedo,
@@ -9542,7 +9557,7 @@ var au = class extends Ts {
9542
9557
  dispose() {
9543
9558
  super.dispose(), this._packedBuffers?.dispose(), this._queueManager?.dispose(), this._kernelManager?.dispose(), this._gBufferAttr?.dispose?.(), this._packedBuffers = null, this._queueManager = null, this._kernelManager = null, this._gBufferAttr = null, this._wavefrontReady = !1;
9544
9559
  }
9545
- }, ou = class extends qn {
9560
+ }, ru = class extends qn {
9546
9561
  constructor(e, t = {}) {
9547
9562
  super("NormalDepth", {
9548
9563
  ...t,
@@ -9599,7 +9614,7 @@ var au = class extends Ts {
9599
9614
  let m = W(M(d).add(.5).div(s).mul(2).sub(1), M(f).add(.5).div(c).mul(2).sub(1).negate(), 1), h = o.mul(G(m, 1)), g = L(ce(a[0].xyz, a[1].xyz, a[2].xyz).mul(h.xyz.div(h.w))), _ = ui({
9600
9615
  origin: W(a[3]),
9601
9616
  direction: g
9602
- }), v = mi.wrap(Oc(_, t, e)), y = v.normal.mul(.5).add(.5), b = v.dst, x = v.didHit.select(G(y, b), G(0, 0, 0, M(1e6)));
9617
+ }), v = mi.wrap(Ec(_, t, e)), y = v.normal.mul(.5).add(.5), b = v.dst, x = v.didHit.select(G(y, b), G(0, 0, 0, M(1e6)));
9603
9618
  Ae(l, Ie(B(d), B(f)), x).toWriteOnly();
9604
9619
  let S = v.normal.toVar();
9605
9620
  p(v.didHit, () => {
@@ -9637,6 +9652,9 @@ var au = class extends Ts {
9637
9652
  let r = this._currentIdx === 0 ? this._rtA : this._rtB, i = this._currentIdx === 0 ? this._rtB : this._rtA;
9638
9653
  this.renderer.compute(this._computeNode), this._srcRegion.max.set(r.width, r.height), this.renderer.copyTextureToTexture(this._outputStorageTex, r.texture, this._srcRegion), this.renderer.copyTextureToTexture(this._shadingStorageTex, this._shadingRT.texture, this._srcRegion), this._hasHistory ||= (this.renderer.copyTextureToTexture(this._outputStorageTex, i.texture, this._srcRegion), !0), e.setTexture("pathtracer:normalDepth", r.texture), e.setTexture("pathtracer:prevNormalDepth", i.texture), e.setTexture("pathtracer:shadingNormal", this._shadingRT.texture), this._dirty = !1;
9639
9654
  }
9655
+ releaseGPUMemory() {
9656
+ this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose(), this.reset();
9657
+ }
9640
9658
  reset() {
9641
9659
  this._dirty = !0, this._hasHistory = !1;
9642
9660
  }
@@ -9650,7 +9668,7 @@ var au = class extends Ts {
9650
9668
  dispose() {
9651
9669
  this._computeNode?.dispose(), this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose(), this._shadingRT?.dispose(), this._rtA?.dispose(), this._rtB?.dispose();
9652
9670
  }
9653
- }, su = class extends qn {
9671
+ }, iu = class extends qn {
9654
9672
  constructor(e, t, n = {}) {
9655
9673
  super("MotionVector", {
9656
9674
  ...n,
@@ -9736,6 +9754,9 @@ var au = class extends Ts {
9736
9754
  isFirstFrame: this.isFirstFrame
9737
9755
  }), this.isFirstFrame = !1;
9738
9756
  }
9757
+ releaseGPUMemory() {
9758
+ this._screenSpaceStorageTex?.dispose(), this._worldSpaceStorageTex?.dispose(), this.reset();
9759
+ }
9739
9760
  reset() {
9740
9761
  this.matricesInitialized || (this.isFirstFrame = !0), this.frameCount = 0;
9741
9762
  }
@@ -9759,7 +9780,7 @@ var au = class extends Ts {
9759
9780
  dispose() {
9760
9781
  this._screenSpaceComputeNode?.dispose(), this._worldSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this._worldSpaceStorageTex?.dispose(), this.screenSpaceTarget?.dispose(), this.worldSpaceTarget?.dispose(), this._normalDepthTexNode?.dispose();
9761
9782
  }
9762
- }, cu = (e) => R(e.equal(e), e, M(0)).clamp(0, 1e7), lu = (e) => W(cu(e.x), cu(e.y), cu(e.z)), uu = class extends qn {
9783
+ }, au = (e) => R(e.equal(e), e, M(0)).clamp(0, 1e7), ou = (e) => W(au(e.x), au(e.y), au(e.z)), su = class extends qn {
9763
9784
  constructor(e, t = {}) {
9764
9785
  super("ASVGF", {
9765
9786
  ...t,
@@ -9800,7 +9821,7 @@ var au = class extends Ts {
9800
9821
  let e = this._colorTexNode, t = this._albedoTexNode, n = this._motionTexNode, r = this._readTemporalTexNode, i = this.gradientNoiseFloor, a = this.gradientSigmaScale, o = this._gradientStorageTex, s = this.resW, c = this.resH, l = Le("float", 144), u = Le("float", 144);
9801
9822
  this._gradientNode = f(() => {
9802
9823
  let d = oe.x, f = oe.y, m = f.mul(8).add(d), h = N(ze.x).mul(8).sub(2).toVar(), g = N(ze.y).mul(8).sub(2).toVar(), v = (i) => {
9803
- let a = i.mod(B(12)), o = i.div(B(12)), d = h.add(N(a)).clamp(N(0), N(s).sub(1)), f = g.add(N(o)).clamp(N(0), N(c).sub(1)), p = z(e, P(d, f)).xyz, m = z(t, P(d, f)).xyz, _ = Bi(lu(p.div(F(m, W(lr))))).toVar();
9824
+ let a = i.mod(B(12)), o = i.div(B(12)), d = h.add(N(a)).clamp(N(0), N(s).sub(1)), f = g.add(N(o)).clamp(N(0), N(c).sub(1)), p = z(e, P(d, f)).xyz, m = z(t, P(d, f)).xyz, _ = Bi(ou(p.div(F(m, W(lr))))).toVar();
9804
9825
  l.element(i).assign(_);
9805
9826
  let v = z(n, P(d, f)), y = M(d).sub(v.x.mul(s)), b = M(f).sub(v.y.mul(c)), x = N(y.add(.5)).clamp(N(0), N(s).sub(1)), S = N(b.add(.5)).clamp(N(0), N(c).sub(1)), C = v.w.greaterThan(.5), w = z(r, P(x, S)).xyz, T = C.select(Bi(w), _);
9806
9827
  u.element(i).assign(T);
@@ -9847,7 +9868,7 @@ var au = class extends Ts {
9847
9868
  return f(() => {
9848
9869
  let f = N(ze.x).mul(8).add(N(oe.x)), y = N(ze.y).mul(8).add(N(oe.y));
9849
9870
  p(f.lessThan(N(g)).and(y.lessThan(N(v))), () => {
9850
- let b = P(f, y), x = z(t, b).xyz, S = z(n, b).xyz, C = F(S, W(lr)), w = lu(x.div(C)), T = G(w, 1).toVar(), E = G(x, 1).toVar();
9871
+ let b = P(f, y), x = z(t, b).xyz, S = z(n, b).xyz, C = F(S, W(lr)), w = ou(x.div(C)), T = G(w, 1).toVar(), E = G(x, 1).toVar();
9851
9872
  p(m.greaterThan(.5).and(h.lessThan(.5)), () => {
9852
9873
  let e = z(r, b), t = e.w.greaterThan(.5), n = M(f).sub(e.x.mul(g)), c = M(y).sub(e.y.mul(v)), m = n.greaterThanEqual(0).and(n.lessThan(M(g))).and(c.greaterThanEqual(0)).and(c.lessThan(M(v)));
9853
9874
  p(t.and(m), () => {
@@ -9856,7 +9877,7 @@ var au = class extends Ts {
9856
9877
  return i.mul(l).mul(u);
9857
9878
  }, oe = ae(D, k, te), se = ae(O, k, ne), ce = ae(D, ee, re), ue = ae(O, ee, ie), L = oe.add(se).add(ce).add(ue);
9858
9879
  p(L.greaterThan(M(.01)), () => {
9859
- let e = z(o, P(D, k)), t = z(o, P(O, k)), n = z(o, P(D, ee)), r = z(o, P(O, ee)), i = M(1).div(L), a = e.xyz.mul(oe).add(t.xyz.mul(se)).add(n.xyz.mul(ce)).add(r.xyz.mul(ue)).mul(i), c = e.w.mul(oe).add(t.w.mul(se)).add(n.w.mul(ce)).add(r.w.mul(ue)).mul(i), f = z(s, b).x.mul(d).clamp(0, 1), p = lu(I(a, w, I(F(M(1).div(c.add(1)), u), M(1), f))), m = le(c.add(1), l);
9880
+ let e = z(o, P(D, k)), t = z(o, P(O, k)), n = z(o, P(D, ee)), r = z(o, P(O, ee)), i = M(1).div(L), a = e.xyz.mul(oe).add(t.xyz.mul(se)).add(n.xyz.mul(ce)).add(r.xyz.mul(ue)).mul(i), c = e.w.mul(oe).add(t.w.mul(se)).add(n.w.mul(ce)).add(r.w.mul(ue)).mul(i), f = z(s, b).x.mul(d).clamp(0, 1), p = ou(I(a, w, I(F(M(1).div(c.add(1)), u), M(1), f))), m = le(c.add(1), l);
9860
9881
  T.assign(G(p, m)), E.assign(G(p.mul(C), 1));
9861
9882
  });
9862
9883
  });
@@ -9962,10 +9983,13 @@ var au = class extends Ts {
9962
9983
  ];
9963
9984
  }
9964
9985
  reset() {}
9986
+ releaseGPUMemory() {
9987
+ this._temporalTexA?.dispose(), this._temporalTexB?.dispose(), this._outputModulatedTex?.dispose(), this._gradientStorageTex?.dispose(), this._heatmapStorageTex?.dispose(), this.context?.removeTexture("asvgf:demodulated"), this.context?.removeTexture("asvgf:output"), this.context?.removeTexture("asvgf:gradient"), this._demodulatedRT?.texture?.dispose(), this._outputRT?.texture?.dispose(), this._gradientRT?.texture?.dispose(), this.heatmapTarget?.texture?.dispose(), this.resetTemporalData();
9988
+ }
9965
9989
  dispose() {
9966
9990
  this._gradientNode?.dispose(), this._temporalNodeA?.dispose(), this._temporalNodeB?.dispose(), this._temporalTexA?.dispose(), this._temporalTexB?.dispose(), this._outputModulatedTex?.dispose(), this._gradientStorageTex?.dispose(), this._demodulatedRT?.dispose(), this._outputRT?.dispose(), this._gradientRT?.dispose(), this._heatmapComputeNode?.dispose(), this._heatmapStorageTex?.dispose(), this.heatmapTarget?.dispose(), this._colorTexNode?.dispose(), this._albedoTexNode?.dispose(), this._motionTexNode?.dispose(), this._normalDepthTexNode?.dispose(), this._prevNormalDepthTexNode?.dispose(), this._readTemporalTexNode?.dispose(), this._gradientReadTexNode?.dispose(), this._heatmapRawColorTexNode?.dispose(), this._heatmapColorTexNode?.dispose(), this._heatmapTemporalTexNode?.dispose(), this._heatmapNDTexNode?.dispose(), this._heatmapMotionTexNode?.dispose(), this._heatmapGradientTexNode?.dispose();
9967
9991
  }
9968
- }, du = (e) => R(e.equal(e), e, M(0)).clamp(0, 1e7), fu = /* @__PURE__ */ K("\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"), pu = class extends qn {
9992
+ }, cu = (e) => R(e.equal(e), e, M(0)).clamp(0, 1e7), lu = /* @__PURE__ */ K("\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"), uu = class extends qn {
9969
9993
  constructor(e, t = {}) {
9970
9994
  super("VarianceEstimation", {
9971
9995
  ...t,
@@ -9991,9 +10015,9 @@ var au = class extends Ts {
9991
10015
  let n = this._colorTexNode, r = this.temporalAlpha, i = this.varianceBoost, a = this.resW, o = this.resH, s = Le("float", 100);
9992
10016
  return f(() => {
9993
10017
  let c = oe.x, l = oe.y, u = l.mul(8).add(c), d = N(ze.x).mul(8).sub(1), f = N(ze.y).mul(8).sub(1), m = u.mod(10), h = u.div(10), g = z(n, P(d.add(N(m)).clamp(N(0), N(a).sub(1)), f.add(N(h)).clamp(N(0), N(o).sub(1)))).xyz;
9994
- s.element(u).assign(du(Bi(g))), p(u.lessThan(B(36)), () => {
10018
+ s.element(u).assign(cu(Bi(g))), p(u.lessThan(B(36)), () => {
9995
10019
  let e = u.add(B(64)), t = e.mod(10), r = e.div(10), i = z(n, P(d.add(N(t)).clamp(N(0), N(a).sub(1)), f.add(N(r)).clamp(N(0), N(o).sub(1)))).xyz;
9996
- s.element(e).assign(du(Bi(i)));
10020
+ s.element(e).assign(cu(Bi(i)));
9997
10021
  }), Re();
9998
10022
  let _ = N(ze.x).mul(8).add(N(c)), v = N(ze.y).mul(8).add(N(l));
9999
10023
  p(_.lessThan(N(a)).and(v.lessThan(N(o))), () => {
@@ -10004,7 +10028,7 @@ var au = class extends Ts {
10004
10028
  }
10005
10029
  n.divAssign(9), a.divAssign(9);
10006
10030
  let o = F(a.sub(n.mul(n)), M(0)), u = s.element(l.add(1).mul(10).add(c.add(1))), d = z(t, P(_, v));
10007
- Ae(e, Ie(B(_), B(v)), fu(u, d.x, d.y, r, o, i)).toWriteOnly();
10031
+ Ae(e, Ie(B(_), B(v)), lu(u, d.x, d.y, r, o, i)).toWriteOnly();
10008
10032
  });
10009
10033
  })().compute([
10010
10034
  this._dispatchX,
@@ -10030,6 +10054,9 @@ var au = class extends Ts {
10030
10054
  let i = this.currentMoments === 0 ? this._storageTexA : this._storageTexB;
10031
10055
  this.currentMoments = 1 - this.currentMoments, this._srcRegion.max.set(this._outputTarget.width, this._outputTarget.height), this.renderer.copyTextureToTexture(i, this._outputTarget.texture, this._srcRegion), e.setTexture("variance:output", this._outputTarget.texture);
10032
10056
  }
10057
+ releaseGPUMemory() {
10058
+ this._storageTexA?.dispose(), this._storageTexB?.dispose(), this.context?.removeTexture("variance:output"), this._outputTarget?.texture?.dispose(), this.reset();
10059
+ }
10033
10060
  reset() {
10034
10061
  this.currentMoments = 0, this._needsWarmReset = !0, this.context && this.context.removeTexture("variance:output");
10035
10062
  }
@@ -10047,7 +10074,7 @@ var au = class extends Ts {
10047
10074
  dispose() {
10048
10075
  this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose(), this._outputTarget?.dispose(), this._colorTexNode?.dispose(), this._readTexNodeA?.dispose(), this._readTexNodeB?.dispose();
10049
10076
  }
10050
- }, mu = /* @__PURE__ */ K("\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 let normW = pow( clamp( dot( centerNormal, sNormal ), 0.0, 1.0 ), phiNorm );\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"), hu = class extends qn {
10077
+ }, du = /* @__PURE__ */ K("\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 let normW = pow( clamp( dot( centerNormal, sNormal ), 0.0, 1.0 ), phiNorm );\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"), fu = class extends qn {
10051
10078
  constructor(e, t = {}) {
10052
10079
  super("BilateralFiltering", {
10053
10080
  ...t,
@@ -10099,7 +10126,7 @@ var au = class extends Ts {
10099
10126
  p(f.lessThan(N(h)).and(v.lessThan(N(g))), () => {
10100
10127
  let p = P(f, v), y = z(t, p).xyz, b = z(n, p), x = z(r, p).xyz.mul(2).sub(1), S = b.w, C = Bi(y), w = F(z(i, p).xyz, W(lr)), T = F(Bi(w), M(lr)).toVar(), E = z(a, p), D = I(E.z, F(E.z, E.w), u), O = l.mul(xe(F(D, M(0)))).div(T).add(M(1e-4)), k = W(0).toVar(), A = M(0).toVar();
10101
10128
  for (let e = 0; e < 5; e++) for (let i = 0; i < 5; i++) {
10102
- let a = i - 2, l = e - 2, u = _[e * 5 + i], p = f.add(d.mul(a)).clamp(N(0), N(h).sub(1)), m = v.add(d.mul(l)).clamp(N(0), N(g).sub(1)), b = z(t, P(p, m)).xyz, w = z(n, P(p, m)), T = z(r, P(p, m)).xyz.mul(2).sub(1), E = w.w, D = mu(C, Bi(b), x, T, S, E, y, b, M(u), O, s, c, o);
10129
+ let a = i - 2, l = e - 2, u = _[e * 5 + i], p = f.add(d.mul(a)).clamp(N(0), N(h).sub(1)), m = v.add(d.mul(l)).clamp(N(0), N(g).sub(1)), b = z(t, P(p, m)).xyz, w = z(n, P(p, m)), T = z(r, P(p, m)).xyz.mul(2).sub(1), E = w.w, D = du(C, Bi(b), x, T, S, E, y, b, M(u), O, s, c, o);
10103
10130
  k.addAssign(b.mul(D)), A.addAssign(D);
10104
10131
  }
10105
10132
  let j = k.div(F(A, M(1e-4))), ee = m.equal(N(1)).select(j.mul(w), j);
@@ -10143,11 +10170,14 @@ var au = class extends Ts {
10143
10170
  1
10144
10171
  ];
10145
10172
  }
10173
+ releaseGPUMemory() {
10174
+ this._storageTexA?.dispose(), this._storageTexB?.dispose(), this.context?.removeTexture("bilateralFiltering:output"), this._outputTarget?.texture?.dispose();
10175
+ }
10146
10176
  reset() {}
10147
10177
  dispose() {
10148
10178
  this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose(), this._outputTarget?.dispose(), this._readTexNode?.dispose(), this._normalDepthTexNode?.dispose(), this._shadingNormalTexNode?.dispose(), this._albedoTexNode?.dispose(), this._varianceTexNode?.dispose();
10149
10179
  }
10150
- }, gu = class extends qn {
10180
+ }, pu = class extends qn {
10151
10181
  constructor(e, t = {}) {
10152
10182
  super("EdgeAwareFiltering", {
10153
10183
  ...t,
@@ -10217,6 +10247,9 @@ var au = class extends Ts {
10217
10247
  updateUniforms(e) {
10218
10248
  e && (e.filterStrength !== void 0 && (this.filterStrength.value = e.filterStrength), e.strengthDecaySpeed !== void 0 && (this.strengthDecaySpeed.value = e.strengthDecaySpeed), e.edgeThreshold !== void 0 && (this.edgeThreshold.value = e.edgeThreshold), e.phiNormal !== void 0 && (this.phiNormal.value = e.phiNormal), e.phiDepth !== void 0 && (this.phiDepth.value = e.phiDepth));
10219
10249
  }
10250
+ releaseGPUMemory() {
10251
+ this._outputStorageTex?.dispose(), this.context?.removeTexture("edgeFiltering:output"), this.outputTarget?.texture?.dispose(), this.reset();
10252
+ }
10220
10253
  reset() {
10221
10254
  this._iterations = 0, this.iterationCount.value = 0;
10222
10255
  }
@@ -10230,7 +10263,7 @@ var au = class extends Ts {
10230
10263
  dispose() {
10231
10264
  this._computeNode?.dispose(), this._outputStorageTex?.dispose(), this.outputTarget?.dispose(), this._inputTexNode?.dispose(), this._ndTexNode?.dispose();
10232
10265
  }
10233
- }, _u = 256, vu = -8, yu = 6 - vu, bu = yu / _u, xu = 1e4, Su = /* @__PURE__ */ K("\n fn adaptExposure(\n geoMean: f32,\n prevExposure: f32,\n keyValue: f32,\n minExp: f32,\n maxExp: f32,\n speedBright: f32,\n speedDark: f32,\n dt: f32,\n isFirstFrame: f32\n ) -> vec4f {\n\n let targetExp = clamp( keyValue / max( geoMean, 0.001 ), minExp, maxExp );\n var newExposure = targetExp;\n\n // Temporal smoothing (skip on first frame)\n if ( isFirstFrame < 0.5 ) {\n\n // Asymmetric speed: brighter scenes adapt faster\n let speed = select( speedDark, speedBright, targetExp < prevExposure );\n let alpha = 1.0 - exp( -dt * speed );\n newExposure = mix( prevExposure, targetExp, alpha );\n\n }\n\n return vec4f( newExposure, geoMean, targetExp, 1.0 );\n\n }\n"), Cu = class extends qn {
10266
+ }, mu = 256, hu = -8, gu = 6 - hu, _u = gu / mu, vu = 1e4, yu = /* @__PURE__ */ K("\n fn adaptExposure(\n geoMean: f32,\n prevExposure: f32,\n keyValue: f32,\n minExp: f32,\n maxExp: f32,\n speedBright: f32,\n speedDark: f32,\n dt: f32,\n isFirstFrame: f32\n ) -> vec4f {\n\n let targetExp = clamp( keyValue / max( geoMean, 0.001 ), minExp, maxExp );\n var newExposure = targetExp;\n\n // Temporal smoothing (skip on first frame)\n if ( isFirstFrame < 0.5 ) {\n\n // Asymmetric speed: brighter scenes adapt faster\n let speed = select( speedDark, speedBright, targetExp < prevExposure );\n let alpha = 1.0 - exp( -dt * speed );\n newExposure = mix( prevExposure, targetExp, alpha );\n\n }\n\n return vec4f( newExposure, geoMean, targetExp, 1.0 );\n\n }\n"), bu = class extends qn {
10234
10267
  constructor(e, t = {}) {
10235
10268
  super("AutoExposure", {
10236
10269
  ...t,
@@ -10246,7 +10279,7 @@ var au = class extends Ts {
10246
10279
  depthBuffer: !1,
10247
10280
  stencilBuffer: !1
10248
10281
  };
10249
- this._downsampleTarget = new i(this.REDUCTION_SIZE, this.REDUCTION_SIZE, e), this._downsampleStorageTex = new s(this.REDUCTION_SIZE, this.REDUCTION_SIZE), this._downsampleStorageTex.type = q, this._downsampleStorageTex.format = Ft, this._downsampleStorageTex.minFilter = wt, this._downsampleStorageTex.magFilter = wt, this._reductionStorageTex = new s(1, 1), this._reductionStorageTex.type = q, this._reductionStorageTex.format = Ft, this._reductionStorageTex.minFilter = wt, this._reductionStorageTex.magFilter = wt, this._reductionReadTarget = new i(1, 1, e), this._adaptationResult = w(1, "vec4"), this._readbackBuffer = new n(16), this._readbackBuffer.name = "AutoExposureAdaptation", this._histogramBuffer = w(_u, "uint").toAtomic();
10282
+ this._downsampleTarget = new i(this.REDUCTION_SIZE, this.REDUCTION_SIZE, e), this._downsampleStorageTex = new s(this.REDUCTION_SIZE, this.REDUCTION_SIZE), this._downsampleStorageTex.type = q, this._downsampleStorageTex.format = Ft, this._downsampleStorageTex.minFilter = wt, this._downsampleStorageTex.magFilter = wt, this._reductionStorageTex = new s(1, 1), this._reductionStorageTex.type = q, this._reductionStorageTex.format = Ft, this._reductionStorageTex.minFilter = wt, this._reductionStorageTex.magFilter = wt, this._reductionReadTarget = new i(1, 1, e), this._adaptationResult = w(1, "vec4"), this._readbackBuffer = new n(16), this._readbackBuffer.name = "AutoExposureAdaptation", this._histogramBuffer = w(mu, "uint").toAtomic();
10250
10283
  }
10251
10284
  _buildCompute() {
10252
10285
  this._buildDownsampleCompute(), this._buildHistogramCompute(), this._buildHistogramAnalyzeCompute(), this._buildAdaptationCompute();
@@ -10280,7 +10313,7 @@ var au = class extends Ts {
10280
10313
  for (let i = 0; i < 16; i++) {
10281
10314
  let a = r.mul(16).add(i), o = a.mod(64), s = a.div(64), c = z(e, P(N(o), N(s))), l = c.x, u = c.y;
10282
10315
  p(u.greaterThan(0), () => {
10283
- let e = B(l.div(u).sub(M(vu)).div(M(yu)).mul(M(_u)).floor().clamp(0, M(_u - 1))), r = M(o).add(.5).div(M(64)), i = M(s).add(.5).div(M(64)), a = r.sub(.5), c = i.sub(.5), d = B(a.mul(a).add(c.mul(c)).mul(n).negate().exp().mul(M(xu)));
10316
+ let e = B(l.div(u).sub(M(hu)).div(M(gu)).mul(M(mu)).floor().clamp(0, M(mu - 1))), r = M(o).add(.5).div(M(64)), i = M(s).add(.5).div(M(64)), a = r.sub(.5), c = i.sub(.5), d = B(a.mul(a).add(c.mul(c)).mul(n).negate().exp().mul(M(vu)));
10284
10317
  x(t.element(e), d);
10285
10318
  });
10286
10319
  }
@@ -10298,14 +10331,14 @@ var au = class extends Ts {
10298
10331
  let e = this._histogramBuffer, t = this._reductionStorageTex, n = this.lowPercentileU, r = this.highPercentileU;
10299
10332
  this._histogramAnalyzeNode = f(() => {
10300
10333
  let i = M(0).toVar();
10301
- m(_u, ({ i: t }) => {
10334
+ m(mu, ({ i: t }) => {
10302
10335
  i.addAssign(M(S(e.element(t))));
10303
10336
  });
10304
10337
  let a = i.mul(n), o = i.mul(r), s = M(0).toVar(), c = M(0).toVar(), l = M(0).toVar(), u = M(0).toVar();
10305
- m(_u, ({ i: t }) => {
10338
+ m(mu, ({ i: t }) => {
10306
10339
  let n = M(S(e.element(t)));
10307
10340
  u.assign(s), s.addAssign(n), p(u.lessThan(o).and(s.greaterThan(a)), () => {
10308
- let e = M(vu).add(M(t).add(.5).mul(M(bu)));
10341
+ let e = M(hu).add(M(t).add(.5).mul(M(_u)));
10309
10342
  c.addAssign(e.mul(n)), l.addAssign(n);
10310
10343
  });
10311
10344
  });
@@ -10320,7 +10353,7 @@ var au = class extends Ts {
10320
10353
  _buildAdaptationCompute() {
10321
10354
  let e = this._reductionReadTexNode, t = this._adaptationResult, n = this.keyValueU, r = this.minExposureU, i = this.maxExposureU, a = this.adaptSpeedBrightU, o = this.adaptSpeedDarkU, s = this.deltaTimeU, c = this.isFirstFrameU, l = this.previousExposureU;
10322
10355
  this._adaptationComputeNode = f(() => {
10323
- let u = z(e, P(N(0), N(0))).x, d = Su(u, l, n, r, i, a, o, s, c);
10356
+ let u = z(e, P(N(0), N(0))).x, d = yu(u, l, n, r, i, a, o, s, c);
10324
10357
  t.element(B(0)).assign(d);
10325
10358
  })().compute(1, [
10326
10359
  1,
@@ -10387,7 +10420,7 @@ var au = class extends Ts {
10387
10420
  };
10388
10421
  //#endregion
10389
10422
  //#region src/TSL/SSRC.js
10390
- function wu({ colorTexNode: e, ndTexNode: t, motionTexNode: n, readCacheTexNode: r, readPrevNDTexNode: i, writeCacheTex: a, writePrevNDTex: o, resW: s, resH: c, temporalAlpha: l, phiNormal: u, phiDepth: d, maxHistory: m, framesSinceReset: h }) {
10423
+ function xu({ colorTexNode: e, ndTexNode: t, motionTexNode: n, readCacheTexNode: r, readPrevNDTexNode: i, writeCacheTex: a, writePrevNDTex: o, resW: s, resH: c, temporalAlpha: l, phiNormal: u, phiDepth: d, maxHistory: m, framesSinceReset: h }) {
10391
10424
  return f(() => {
10392
10425
  let f = N(ze.x).mul(8).add(N(oe.x)), g = N(ze.y).mul(8).add(N(oe.y));
10393
10426
  p(f.lessThan(N(s)).and(g.lessThan(N(c))), () => {
@@ -10409,7 +10442,7 @@ function wu({ colorTexNode: e, ndTexNode: t, motionTexNode: n, readCacheTexNode:
10409
10442
  });
10410
10443
  });
10411
10444
  }
10412
- function Tu({ colorTexNode: e, ndTexNode: t, readCacheTexNode: n, outputTex: r, resW: i, resH: a, spatialRadius: o, spatialWeight: s, phiNormal: c, phiDepth: l }) {
10445
+ function Su({ colorTexNode: e, ndTexNode: t, readCacheTexNode: n, outputTex: r, resW: i, resH: a, spatialRadius: o, spatialWeight: s, phiNormal: c, phiDepth: l }) {
10413
10446
  let u = [
10414
10447
  [1, 0],
10415
10448
  [-1, 0],
@@ -10435,7 +10468,7 @@ function Tu({ colorTexNode: e, ndTexNode: t, readCacheTexNode: n, outputTex: r,
10435
10468
  }
10436
10469
  //#endregion
10437
10470
  //#region src/Stages/SSRC.js
10438
- var Eu = class extends qn {
10471
+ var Cu = class extends qn {
10439
10472
  constructor(e, t = {}) {
10440
10473
  super("SSRC", {
10441
10474
  ...t,
@@ -10478,6 +10511,9 @@ var Eu = class extends qn {
10478
10511
  ];
10479
10512
  this._readCacheTexNode.value = i, this._readPrevNDTexNode.value = o, this.renderer.compute(this._currentPingPong === 0 ? this._pass1NodeA : this._pass1NodeB), this._readPass1CacheTexNode.value = a, this.renderer.compute(this._pass2Node), this._framesSinceReset.value = Math.min(this._framesSinceReset.value + 1, 9999), this._srcRegion.max.set(this.outputTarget.width, this.outputTarget.height), this.renderer.copyTextureToTexture(this._outputTex, this.outputTarget.texture, this._srcRegion), e.setTexture("ssrc:output", this.outputTarget.texture), this._currentPingPong = 1 - this._currentPingPong;
10480
10513
  }
10514
+ releaseGPUMemory() {
10515
+ this._cacheTexA?.dispose(), this._cacheTexB?.dispose(), this._prevNDTexA?.dispose(), this._prevNDTexB?.dispose(), this._outputTex?.dispose(), this.context?.removeTexture("ssrc:output"), this.outputTarget?.texture?.dispose(), this.reset();
10516
+ }
10481
10517
  reset() {
10482
10518
  this._resetCache();
10483
10519
  }
@@ -10517,12 +10553,12 @@ var Eu = class extends qn {
10517
10553
  phiNormal: this.phiNormal,
10518
10554
  phiDepth: this.phiDepth,
10519
10555
  maxHistory: this.maxHistory
10520
- }, t = wu({
10556
+ }, t = xu({
10521
10557
  ...e,
10522
10558
  writeCacheTex: this._cacheTexA,
10523
10559
  writePrevNDTex: this._prevNDTexA,
10524
10560
  framesSinceReset: this._framesSinceReset
10525
- }), n = wu({
10561
+ }), n = xu({
10526
10562
  ...e,
10527
10563
  writeCacheTex: this._cacheTexB,
10528
10564
  writePrevNDTex: this._prevNDTexB,
@@ -10536,7 +10572,7 @@ var Eu = class extends qn {
10536
10572
  8,
10537
10573
  1
10538
10574
  ];
10539
- this._pass1NodeA = t().compute(r, i), this._pass1NodeB = n().compute(r, i), this._pass2Node = Tu({
10575
+ this._pass1NodeA = t().compute(r, i), this._pass1NodeB = n().compute(r, i), this._pass2Node = Su({
10540
10576
  colorTexNode: this._colorTexNode,
10541
10577
  ndTexNode: this._ndTexNode,
10542
10578
  readCacheTexNode: this._readPass1CacheTexNode,
@@ -10549,7 +10585,7 @@ var Eu = class extends qn {
10549
10585
  phiDepth: this.phiDepth
10550
10586
  })().compute(r, i);
10551
10587
  }
10552
- }, Du = class extends qn {
10588
+ }, wu = class extends qn {
10553
10589
  constructor(n, r = {}) {
10554
10590
  super("Compositor", {
10555
10591
  ...r,
@@ -10575,7 +10611,7 @@ var Eu = class extends qn {
10575
10611
  dispose() {
10576
10612
  this._sourceTexNode?.dispose(), this.compositorMaterial?.dispose(), this.compositorQuad = null;
10577
10613
  }
10578
- }, Ou = class {
10614
+ }, Tu = class {
10579
10615
  constructor() {
10580
10616
  this.textures = /* @__PURE__ */ new Map(), this.renderTargets = /* @__PURE__ */ new Map(), this.uniforms = /* @__PURE__ */ new Map(), this.state = {
10581
10617
  frame: 0,
@@ -10697,7 +10733,7 @@ var Eu = class extends qn {
10697
10733
  dispose() {
10698
10734
  this.textures.clear(), this.renderTargets.clear(), this.uniforms.clear(), this._stateChangeCallbacks.clear(), this.state = {};
10699
10735
  }
10700
- }, ku = class extends ot {
10736
+ }, Eu = class extends ot {
10701
10737
  constructor() {
10702
10738
  super(), this._onceCallbacks = /* @__PURE__ */ new Map();
10703
10739
  }
@@ -10735,9 +10771,9 @@ var Eu = class extends qn {
10735
10771
  eventNames() {
10736
10772
  return this._listeners ? Object.keys(this._listeners) : [];
10737
10773
  }
10738
- }, Au = class {
10774
+ }, Du = class {
10739
10775
  constructor(e, t, n) {
10740
- this.renderer = e, this.width = t, this.height = n, this.stages = [], this.context = new Ou(), this.eventBus = new ku(), this.context.setState("width", t), this.context.setState("height", n), this.stats = {
10776
+ this.renderer = e, this.width = t, this.height = n, this.stages = [], this.context = new Tu(), this.eventBus = new Eu(), this.context.setState("width", t), this.context.setState("height", n), this.stats = {
10741
10777
  enabled: !1,
10742
10778
  logSkipped: !1,
10743
10779
  timings: /* @__PURE__ */ new Map(),
@@ -10869,7 +10905,7 @@ var Eu = class extends qn {
10869
10905
  let e = this.getInfo();
10870
10906
  console.group("[Pipeline] Info"), console.log("Stages:", e.stages), console.log("Context Textures:", e.textures), console.log("Context Render Targets:", e.renderTargets), console.log("Context Uniforms:", e.uniforms), console.log("Event Types:", e.events), console.log("State:", e.contextState), console.groupEnd();
10871
10907
  }
10872
- }, ju = class {
10908
+ }, Ou = class {
10873
10909
  constructor() {
10874
10910
  this.timeElapsed = 0, this.lastResetTime = performance.now(), this.renderCompleteDispatched = !1;
10875
10911
  }
@@ -10891,7 +10927,7 @@ var Eu = class extends qn {
10891
10927
  resumeFromPause() {
10892
10928
  this.renderCompleteDispatched = !1, this.lastResetTime = performance.now() - this.timeElapsed * 1e3;
10893
10929
  }
10894
- }, Mu = class extends ot {
10930
+ }, ku = class extends ot {
10895
10931
  constructor({ scene: e, camera: t, canvas: n, assetLoader: r, pathTracer: i, floorPlane: a }) {
10896
10932
  super(), this.scene = e, this.camera = t, this.canvas = n, this.assetLoader = r, this.pathTracer = i, this.floorPlane = a, this.raycaster = new Rt(), this.focusMode = !1, this.focusPointIndicator = null, this.afPointPlacementMode = !1, this.handleAFPointClick = this.handleAFPointClick.bind(this), this.selectedObject = null, this.selectMode = !1, this.clickTimeout = null, this.mouseDownPosition = null, this.dragThreshold = 5, this.handleFocusClick = this.handleFocusClick.bind(this), this.handleSelectClick = this.handleSelectClick.bind(this), this.handleSelectDoubleClick = this.handleSelectDoubleClick.bind(this), this.handleMouseDown = this.handleMouseDown.bind(this), this.handleMouseUp = this.handleMouseUp.bind(this), this.handleContextMenu = this.handleContextMenu.bind(this), this.handleContextPointerDown = this.handleContextPointerDown.bind(this), this.handleContextPointerUp = this.handleContextPointerUp.bind(this), this.contextPointerDownPosition = null, this.canvas.addEventListener("pointerdown", this.handleContextPointerDown), this.canvas.addEventListener("pointerup", this.handleContextPointerUp), this.canvas.addEventListener("contextmenu", this.handleContextMenu), this._overlayManager = null, this._transformManager = null, this._appDispatch = null, this._orbitControls = null;
10897
10933
  }
@@ -11112,18 +11148,18 @@ var Eu = class extends qn {
11112
11148
  dispose() {
11113
11149
  this.canvas.removeEventListener("click", this.handleAFPointClick), this.canvas.removeEventListener("click", this.handleFocusClick), this.canvas.removeEventListener("mousedown", this.handleMouseDown), this.canvas.removeEventListener("mouseup", this.handleMouseUp), this.canvas.removeEventListener("click", this.handleSelectClick), this.canvas.removeEventListener("dblclick", this.handleSelectDoubleClick), this.canvas.removeEventListener("contextmenu", this.handleContextMenu), this.canvas.removeEventListener("pointerdown", this.handleContextPointerDown), this.canvas.removeEventListener("pointerup", this.handleContextPointerUp), this.clickTimeout &&= (clearTimeout(this.clickTimeout), null), this.mouseDownPosition = null, this.contextPointerDownPosition = null, this.focusPointIndicator &&= (this.scene.remove(this.focusPointIndicator), null), this.canvas.style.cursor = "auto", this.scene = null, this.camera = null, this.canvas = null, this.assetLoader = null, this.pathTracer = null, this.floorPlane = null, this.raycaster = null;
11114
11150
  }
11115
- }, Nu = {
11151
+ }, Au = {
11116
11152
  STRING: "string",
11117
11153
  NUMBER: "number",
11118
11154
  WORD: "word",
11119
11155
  LBRACKET: "[",
11120
11156
  RBRACKET: "]"
11121
- }, Pu = (e) => e === " " || e === " " || e === "\n" || e === "\r" || e === "\f", Fu = (e) => e >= "0" && e <= "9", Iu = (e, t, n) => !!(Fu(e) || e === "." && Fu(t) || (e === "-" || e === "+") && (Fu(t) || t === "." && Fu(n)));
11122
- function Lu(e) {
11157
+ }, ju = (e) => e === " " || e === " " || e === "\n" || e === "\r" || e === "\f", Mu = (e) => e >= "0" && e <= "9", Nu = (e, t, n) => !!(Mu(e) || e === "." && Mu(t) || (e === "-" || e === "+") && (Mu(t) || t === "." && Mu(n)));
11158
+ function Pu(e) {
11123
11159
  let t = [], n = e.length, r = 0;
11124
11160
  for (; r < n;) {
11125
11161
  let i = e[r];
11126
- if (Pu(i)) {
11162
+ if (ju(i)) {
11127
11163
  r++;
11128
11164
  continue;
11129
11165
  }
@@ -11132,11 +11168,11 @@ function Lu(e) {
11132
11168
  continue;
11133
11169
  }
11134
11170
  if (i === "[") {
11135
- t.push({ type: Nu.LBRACKET }), r++;
11171
+ t.push({ type: Au.LBRACKET }), r++;
11136
11172
  continue;
11137
11173
  }
11138
11174
  if (i === "]") {
11139
- t.push({ type: Nu.RBRACKET }), r++;
11175
+ t.push({ type: Au.RBRACKET }), r++;
11140
11176
  continue;
11141
11177
  }
11142
11178
  if (i === "\"") {
@@ -11145,12 +11181,12 @@ function Lu(e) {
11145
11181
  for (; r < n && e[r] !== "\"";) r++;
11146
11182
  if (r >= n) throw Error("PBRT tokenizer: unterminated string literal");
11147
11183
  t.push({
11148
- type: Nu.STRING,
11184
+ type: Au.STRING,
11149
11185
  value: e.slice(i, r)
11150
11186
  }), r++;
11151
11187
  continue;
11152
11188
  }
11153
- if (Iu(i, e[r + 1], e[r + 2])) {
11189
+ if (Nu(i, e[r + 1], e[r + 2])) {
11154
11190
  let i = r;
11155
11191
  for (r++; r < n;) {
11156
11192
  let t = e[r];
@@ -11160,16 +11196,16 @@ function Lu(e) {
11160
11196
  let a = e.slice(i, r), o = Number(a);
11161
11197
  if (Number.isNaN(o)) throw Error(`PBRT tokenizer: invalid number "${a}"`);
11162
11198
  t.push({
11163
- type: Nu.NUMBER,
11199
+ type: Au.NUMBER,
11164
11200
  value: o
11165
11201
  });
11166
11202
  continue;
11167
11203
  }
11168
11204
  {
11169
11205
  let i = r;
11170
- for (; r < n && !Pu(e[r]) && e[r] !== "\"" && e[r] !== "[" && e[r] !== "]" && e[r] !== "#";) r++;
11206
+ for (; r < n && !ju(e[r]) && e[r] !== "\"" && e[r] !== "[" && e[r] !== "]" && e[r] !== "#";) r++;
11171
11207
  t.push({
11172
- type: Nu.WORD,
11208
+ type: Au.WORD,
11173
11209
  value: e.slice(i, r)
11174
11210
  });
11175
11211
  }
@@ -11178,7 +11214,7 @@ function Lu(e) {
11178
11214
  }
11179
11215
  //#endregion
11180
11216
  //#region src/Processor/PBRT/PBRTMath.js
11181
- function Ru() {
11217
+ function Fu() {
11182
11218
  return [
11183
11219
  1,
11184
11220
  0,
@@ -11198,7 +11234,7 @@ function Ru() {
11198
11234
  1
11199
11235
  ];
11200
11236
  }
11201
- function zu(e, t) {
11237
+ function Iu(e, t) {
11202
11238
  let n = e[0], r = e[1], i = e[2], a = e[3], o = e[4], s = e[5], c = e[6], l = e[7], u = e[8], d = e[9], f = e[10], p = e[11], m = e[12], h = e[13], g = e[14], _ = e[15], v = t[0], y = t[1], b = t[2], x = t[3], S = t[4], C = t[5], w = t[6], T = t[7], E = t[8], D = t[9], O = t[10], k = t[11], A = t[12], j = t[13], M = t[14], ee = t[15];
11203
11239
  return [
11204
11240
  n * v + o * y + u * b + m * x,
@@ -11219,7 +11255,7 @@ function zu(e, t) {
11219
11255
  a * A + l * j + p * M + _ * ee
11220
11256
  ];
11221
11257
  }
11222
- function Bu(e, t, n) {
11258
+ function Lu(e, t, n) {
11223
11259
  return [
11224
11260
  1,
11225
11261
  0,
@@ -11239,7 +11275,7 @@ function Bu(e, t, n) {
11239
11275
  1
11240
11276
  ];
11241
11277
  }
11242
- function Vu(e, t, n) {
11278
+ function Ru(e, t, n) {
11243
11279
  return [
11244
11280
  e,
11245
11281
  0,
@@ -11259,7 +11295,7 @@ function Vu(e, t, n) {
11259
11295
  1
11260
11296
  ];
11261
11297
  }
11262
- function Hu(e, t, n, r) {
11298
+ function zu(e, t, n, r) {
11263
11299
  let i = Math.hypot(t, n, r) || 1;
11264
11300
  t /= i, n /= i, r /= i;
11265
11301
  let a = e * Math.PI / 180, o = Math.cos(a), s = Math.sin(a), c = 1 - o, l = c * t * t + o, u = c * t * n - s * r, d = c * t * r + s * n, f = c * t * n + s * r, p = c * n * n + o, m = c * n * r - s * t;
@@ -11282,21 +11318,21 @@ function Hu(e, t, n, r) {
11282
11318
  1
11283
11319
  ];
11284
11320
  }
11285
- function Uu(e, t) {
11321
+ function Bu(e, t) {
11286
11322
  return [
11287
11323
  e[0] - t[0],
11288
11324
  e[1] - t[1],
11289
11325
  e[2] - t[2]
11290
11326
  ];
11291
11327
  }
11292
- function Wu(e, t) {
11328
+ function Vu(e, t) {
11293
11329
  return [
11294
11330
  e[1] * t[2] - e[2] * t[1],
11295
11331
  e[2] * t[0] - e[0] * t[2],
11296
11332
  e[0] * t[1] - e[1] * t[0]
11297
11333
  ];
11298
11334
  }
11299
- function Gu(e) {
11335
+ function Hu(e) {
11300
11336
  let t = Math.hypot(e[0], e[1], e[2]) || 1;
11301
11337
  return [
11302
11338
  e[0] / t,
@@ -11304,8 +11340,8 @@ function Gu(e) {
11304
11340
  e[2] / t
11305
11341
  ];
11306
11342
  }
11307
- function Ku(e, t, n) {
11308
- let r = Gu(Uu(t, e)), i = Gu(Wu(Gu(n), r)), a = Wu(r, i);
11343
+ function Uu(e, t, n) {
11344
+ let r = Hu(Bu(t, e)), i = Hu(Vu(Hu(n), r)), a = Vu(r, i);
11309
11345
  return [
11310
11346
  i[0],
11311
11347
  i[1],
@@ -11325,9 +11361,9 @@ function Ku(e, t, n) {
11325
11361
  1
11326
11362
  ];
11327
11363
  }
11328
- function qu(e) {
11364
+ function Wu(e) {
11329
11365
  let t = e[0], n = e[1], r = e[2], i = e[3], a = e[4], o = e[5], s = e[6], c = e[7], l = e[8], u = e[9], d = e[10], f = e[11], p = e[12], m = e[13], h = e[14], g = e[15], _ = u * h * c - m * d * c + m * s * f - o * h * f - u * s * g + o * d * g, v = p * d * c - l * h * c - p * s * f + a * h * f + l * s * g - a * d * g, y = l * m * c - p * u * c + p * o * f - a * m * f - l * o * g + a * u * g, b = p * u * s - l * m * s - p * o * d + a * m * d + l * o * h - a * u * h, x = t * _ + n * v + r * y + i * b;
11330
- if (x === 0) return Ru();
11366
+ if (x === 0) return Fu();
11331
11367
  let S = 1 / x;
11332
11368
  return [
11333
11369
  _ * S,
@@ -11350,7 +11386,7 @@ function qu(e) {
11350
11386
  }
11351
11387
  //#endregion
11352
11388
  //#region src/Processor/PBRT/PBRTParser.js
11353
- var Ju = class {
11389
+ var Gu = class {
11354
11390
  constructor(e = {}) {
11355
11391
  this.resolveInclude = e.resolveInclude || (() => {
11356
11392
  throw Error("PBRTParser: Include used but no resolveInclude provided");
@@ -11364,14 +11400,14 @@ var Ju = class {
11364
11400
  instances: [],
11365
11401
  objects: /* @__PURE__ */ new Map(),
11366
11402
  warnings: []
11367
- }, this.ctm = Ru(), this.state = {
11403
+ }, this.ctm = Fu(), this.state = {
11368
11404
  material: null,
11369
11405
  areaLight: null,
11370
11406
  reverseOrientation: !1
11371
11407
  }, this.attributeStack = [], this.transformStack = [], this.coordSystems = /* @__PURE__ */ new Map(), this.currentObject = null, this.objectBeginCTM = null, this.dirStack = [""], this.tokens = [], this.pos = 0, this._warnedUnknown = /* @__PURE__ */ new Set();
11372
11408
  }
11373
11409
  parse(e, t = "") {
11374
- return this.dirStack = [t], this._run(Lu(e)), this.ir;
11410
+ return this.dirStack = [t], this._run(Pu(e)), this.ir;
11375
11411
  }
11376
11412
  _peek() {
11377
11413
  return this.tokens[this.pos];
@@ -11381,12 +11417,12 @@ var Ju = class {
11381
11417
  }
11382
11418
  _expectNumber(e) {
11383
11419
  let t = this._next();
11384
- if (!t || t.type !== Nu.NUMBER) throw Error(`PBRT parser: expected number for ${e}, got ${t ? t.value : "EOF"}`);
11420
+ if (!t || t.type !== Au.NUMBER) throw Error(`PBRT parser: expected number for ${e}, got ${t ? t.value : "EOF"}`);
11385
11421
  return t.value;
11386
11422
  }
11387
11423
  _expectString(e) {
11388
11424
  let t = this._next();
11389
- if (!t || t.type !== Nu.STRING) throw Error(`PBRT parser: expected string for ${e}, got ${t ? t.value : "EOF"}`);
11425
+ if (!t || t.type !== Au.STRING) throw Error(`PBRT parser: expected string for ${e}, got ${t ? t.value : "EOF"}`);
11390
11426
  return t.value;
11391
11427
  }
11392
11428
  _readNumbers(e) {
@@ -11395,17 +11431,17 @@ var Ju = class {
11395
11431
  return t;
11396
11432
  }
11397
11433
  _readBracketedOrBareNumbers(e) {
11398
- if (this._peek() && this._peek().type === Nu.LBRACKET) {
11434
+ if (this._peek() && this._peek().type === Au.LBRACKET) {
11399
11435
  this._next();
11400
11436
  let e = [];
11401
- for (; this._peek() && this._peek().type !== Nu.RBRACKET;) e.push(this._expectNumber("transform element"));
11437
+ for (; this._peek() && this._peek().type !== Au.RBRACKET;) e.push(this._expectNumber("transform element"));
11402
11438
  return this._next(), e;
11403
11439
  }
11404
11440
  return this._readNumbers(e);
11405
11441
  }
11406
11442
  _parseParams() {
11407
11443
  let e = {};
11408
- for (; this._peek() && this._peek().type === Nu.STRING;) {
11444
+ for (; this._peek() && this._peek().type === Au.STRING;) {
11409
11445
  let t = this._next().value.trim().split(/\s+/), n = t[0], r = t[1] === void 0 ? t[0] : t[1];
11410
11446
  e[r] = {
11411
11447
  type: n,
@@ -11416,23 +11452,23 @@ var Ju = class {
11416
11452
  }
11417
11453
  _parseParamValue() {
11418
11454
  let e = [];
11419
- if (this._peek() && this._peek().type === Nu.LBRACKET) {
11420
- for (this._next(); this._peek() && this._peek().type !== Nu.RBRACKET;) e.push(this._coerceValueToken(this._next()));
11455
+ if (this._peek() && this._peek().type === Au.LBRACKET) {
11456
+ for (this._next(); this._peek() && this._peek().type !== Au.RBRACKET;) e.push(this._coerceValueToken(this._next()));
11421
11457
  this._next();
11422
11458
  } else e.push(this._coerceValueToken(this._next()));
11423
11459
  return e;
11424
11460
  }
11425
11461
  _coerceValueToken(e) {
11426
11462
  if (!e) throw Error("PBRT parser: unexpected EOF in parameter value");
11427
- if (e.type === Nu.NUMBER || e.type === Nu.STRING) return e.value;
11428
- if (e.type === Nu.WORD) return e.value === "true" ? !0 : e.value === "false" ? !1 : e.value;
11463
+ if (e.type === Au.NUMBER || e.type === Au.STRING) return e.value;
11464
+ if (e.type === Au.WORD) return e.value === "true" ? !0 : e.value === "false" ? !1 : e.value;
11429
11465
  throw Error(`PBRT parser: unexpected token in parameter value: ${e.type}`);
11430
11466
  }
11431
11467
  _run(e) {
11432
11468
  let t = this.tokens, n = this.pos;
11433
11469
  for (this.tokens = e, this.pos = 0; this.pos < this.tokens.length;) {
11434
11470
  let e = this._next();
11435
- if (e.type !== Nu.WORD) throw Error(`PBRT parser: expected directive, got ${e.type} ${e.value ?? ""}`);
11471
+ if (e.type !== Au.WORD) throw Error(`PBRT parser: expected directive, got ${e.type} ${e.value ?? ""}`);
11436
11472
  this._directive(e.value);
11437
11473
  }
11438
11474
  this.tokens = t, this.pos = n;
@@ -11440,25 +11476,25 @@ var Ju = class {
11440
11476
  _directive(e) {
11441
11477
  switch (e) {
11442
11478
  case "Identity":
11443
- this.ctm = Ru();
11479
+ this.ctm = Fu();
11444
11480
  break;
11445
11481
  case "Translate": {
11446
11482
  let [e, t, n] = this._readNumbers(3);
11447
- this.ctm = zu(this.ctm, Bu(e, t, n));
11483
+ this.ctm = Iu(this.ctm, Lu(e, t, n));
11448
11484
  break;
11449
11485
  }
11450
11486
  case "Scale": {
11451
11487
  let [e, t, n] = this._readNumbers(3);
11452
- this.ctm = zu(this.ctm, Vu(e, t, n));
11488
+ this.ctm = Iu(this.ctm, Ru(e, t, n));
11453
11489
  break;
11454
11490
  }
11455
11491
  case "Rotate": {
11456
11492
  let [e, t, n, r] = this._readNumbers(4);
11457
- this.ctm = zu(this.ctm, Hu(e, t, n, r));
11493
+ this.ctm = Iu(this.ctm, zu(e, t, n, r));
11458
11494
  break;
11459
11495
  }
11460
11496
  case "LookAt": {
11461
- let e = this._readNumbers(9), t = Ku([
11497
+ let e = this._readNumbers(9), t = Uu([
11462
11498
  e[0],
11463
11499
  e[1],
11464
11500
  e[2]
@@ -11471,7 +11507,7 @@ var Ju = class {
11471
11507
  e[7],
11472
11508
  e[8]
11473
11509
  ]);
11474
- this.ctm = zu(this.ctm, qu(t));
11510
+ this.ctm = Iu(this.ctm, Wu(t));
11475
11511
  break;
11476
11512
  }
11477
11513
  case "Transform":
@@ -11479,7 +11515,7 @@ var Ju = class {
11479
11515
  break;
11480
11516
  case "ConcatTransform": {
11481
11517
  let e = this._readBracketedOrBareNumbers(16);
11482
- this.ctm = zu(this.ctm, e);
11518
+ this.ctm = Iu(this.ctm, e);
11483
11519
  break;
11484
11520
  }
11485
11521
  case "CoordinateSystem":
@@ -11495,7 +11531,7 @@ var Ju = class {
11495
11531
  this.ir.camera = {
11496
11532
  type: e,
11497
11533
  params: t,
11498
- cameraToWorld: qu(this.ctm)
11534
+ cameraToWorld: Wu(this.ctm)
11499
11535
  };
11500
11536
  break;
11501
11537
  }
@@ -11519,7 +11555,7 @@ var Ju = class {
11519
11555
  this._skipTypeAndParams();
11520
11556
  break;
11521
11557
  case "WorldBegin":
11522
- this.ctm = Ru(), this.state = {
11558
+ this.ctm = Fu(), this.state = {
11523
11559
  material: null,
11524
11560
  areaLight: null,
11525
11561
  reverseOrientation: !1
@@ -11564,7 +11600,7 @@ var Ju = class {
11564
11600
  this._readNumbers(2);
11565
11601
  break;
11566
11602
  case "MediumInterface":
11567
- this._peek() && this._peek().type === Nu.STRING && this._next(), this._peek() && this._peek().type === Nu.STRING && this._next();
11603
+ this._peek() && this._peek().type === Au.STRING && this._next(), this._peek() && this._peek().type === Au.STRING && this._next();
11568
11604
  break;
11569
11605
  case "MakeNamedMedium":
11570
11606
  this._skipNamedAndParams();
@@ -11672,7 +11708,7 @@ var Ju = class {
11672
11708
  }
11673
11709
  }
11674
11710
  _emitShape(e) {
11675
- this.currentObject === null ? this.ir.shapes.push(e) : (e.relativeCTM = zu(qu(this.objectBeginCTM), e.ctm), this.ir.objects.get(this.currentObject).push(e));
11711
+ this.currentObject === null ? this.ir.shapes.push(e) : (e.relativeCTM = Iu(Wu(this.objectBeginCTM), e.ctm), this.ir.objects.get(this.currentObject).push(e));
11676
11712
  }
11677
11713
  _include(e) {
11678
11714
  let t = this.resolveInclude(e, this.dirStack[this.dirStack.length - 1]);
@@ -11681,13 +11717,13 @@ var Ju = class {
11681
11717
  return;
11682
11718
  }
11683
11719
  let n = e.includes("/") ? e.slice(0, e.lastIndexOf("/")) : "";
11684
- this.dirStack.push(n), this._run(Lu(t)), this.dirStack.pop();
11720
+ this.dirStack.push(n), this._run(Pu(t)), this.dirStack.pop();
11685
11721
  }
11686
11722
  _skipTypeAndParams() {
11687
- this._peek() && this._peek().type === Nu.STRING && this._next(), this._parseParams();
11723
+ this._peek() && this._peek().type === Au.STRING && this._next(), this._parseParams();
11688
11724
  }
11689
11725
  _skipNamedAndParams() {
11690
- this._peek() && this._peek().type === Nu.STRING && this._next(), this._parseParams();
11726
+ this._peek() && this._peek().type === Au.STRING && this._next(), this._parseParams();
11691
11727
  }
11692
11728
  _num(e, t) {
11693
11729
  return e && e.value.length ? e.value[0] : t;
@@ -11701,7 +11737,7 @@ var Ju = class {
11701
11737
  _warnUnknown(e) {
11702
11738
  this._warnedUnknown.has(e) || (this._warnedUnknown.add(e), this._warn(`Unsupported directive ignored: ${e}`));
11703
11739
  }
11704
- }, Yu = {
11740
+ }, Ku = {
11705
11741
  au: [
11706
11742
  1,
11707
11743
  .78,
@@ -11757,12 +11793,12 @@ var Ju = class {
11757
11793
  .9,
11758
11794
  .9
11759
11795
  ]
11760
- }, Xu = [
11796
+ }, qu = [
11761
11797
  .92,
11762
11798
  .92,
11763
11799
  .92
11764
11800
  ];
11765
- function Zu(e) {
11801
+ function Ju(e) {
11766
11802
  let t = Math.max(1e3, Math.min(4e4, e)) / 100, n, r, i;
11767
11803
  t <= 66 ? (n = 255, r = 99.47 * Math.log(t) - 161.12) : (n = 329.7 * (t - 60) ** -.1332, r = 288.12 * (t - 60) ** -.0755), i = t >= 66 ? 255 : t <= 19 ? 0 : 138.52 * Math.log(t - 10) - 305.04;
11768
11804
  let a = (e) => Math.max(0, Math.min(255, e)) / 255;
@@ -11772,15 +11808,15 @@ function Zu(e) {
11772
11808
  a(i) ** 2.2
11773
11809
  ];
11774
11810
  }
11775
- function Qu(e, t, n) {
11811
+ function Yu(e, t, n) {
11776
11812
  let r = e[t];
11777
11813
  return r && typeof r.value[0] == "number" ? r.value[0] : n;
11778
11814
  }
11779
- function $u(e, t, n) {
11815
+ function Xu(e, t, n) {
11780
11816
  let r = e[t];
11781
11817
  return r && typeof r.value[0] == "string" ? r.value[0] : n;
11782
11818
  }
11783
- async function ed(e, t, n, r = null) {
11819
+ async function Zu(e, t, n, r = null) {
11784
11820
  let i = e[t];
11785
11821
  if (!i) return {
11786
11822
  rgb: r,
@@ -11819,14 +11855,14 @@ async function ed(e, t, n, r = null) {
11819
11855
  };
11820
11856
  }
11821
11857
  if (i.type === "blackbody") return {
11822
- rgb: Zu(i.value[0]),
11858
+ rgb: Ju(i.value[0]),
11823
11859
  texture: null
11824
11860
  };
11825
11861
  if (i.type === "spectrum") {
11826
11862
  if (typeof i.value[0] == "string") {
11827
- let e = td(i.value[0]);
11828
- return e && Yu[e] ? {
11829
- rgb: Yu[e].slice(),
11863
+ let e = Qu(i.value[0]);
11864
+ return e && Ku[e] ? {
11865
+ rgb: Ku[e].slice(),
11830
11866
  texture: null
11831
11867
  } : (n.warn(`named spectrum "${i.value[0]}" approximated to gray`), {
11832
11868
  rgb: [
@@ -11854,18 +11890,18 @@ async function ed(e, t, n, r = null) {
11854
11890
  texture: null
11855
11891
  };
11856
11892
  }
11857
- function td(e) {
11893
+ function Qu(e) {
11858
11894
  let t = e.toLowerCase().match(/metal-([a-z]+)/);
11859
11895
  if (t) return t[1];
11860
- for (let t of Object.keys(Yu)) if (e.toLowerCase().includes(t)) return t;
11896
+ for (let t of Object.keys(Ku)) if (e.toLowerCase().includes(t)) return t;
11861
11897
  return null;
11862
11898
  }
11863
- function nd(e, t) {
11899
+ function $u(e, t) {
11864
11900
  if (e.roughness && typeof e.roughness.value[0] == "number") return e.roughness.value[0];
11865
- let n = Qu(e, "uroughness", null), r = Qu(e, "vroughness", null);
11901
+ let n = Yu(e, "uroughness", null), r = Yu(e, "vroughness", null);
11866
11902
  return n !== null && r !== null ? (n + r) / 2 : n === null ? t : n;
11867
11903
  }
11868
- async function rd(e, t) {
11904
+ async function ed(e, t) {
11869
11905
  let n = e?.type || "diffuse", r = e?.params || {}, i = new St({
11870
11906
  side: it,
11871
11907
  roughness: 1,
@@ -11877,7 +11913,7 @@ async function rd(e, t) {
11877
11913
  };
11878
11914
  switch (n) {
11879
11915
  case "diffuse":
11880
- o(await ed(r, "reflectance", t, [
11916
+ o(await Zu(r, "reflectance", t, [
11881
11917
  .5,
11882
11918
  .5,
11883
11919
  .5
@@ -11885,14 +11921,14 @@ async function rd(e, t) {
11885
11921
  break;
11886
11922
  case "conductor":
11887
11923
  case "metal": {
11888
- let e = await ed(r, "reflectance", t, null), n = r.eta, s = r.k, c = n && n.type === "spectrum" && typeof n.value[0] == "string";
11924
+ let e = await Zu(r, "reflectance", t, null), n = r.eta, s = r.k, c = n && n.type === "spectrum" && typeof n.value[0] == "string";
11889
11925
  if (e.rgb || e.texture) o(e);
11890
11926
  else if (n && s && !c) {
11891
- let e = (await ed(r, "eta", t, [
11927
+ let e = (await Zu(r, "eta", t, [
11892
11928
  .2,
11893
11929
  .92,
11894
11930
  1.1
11895
- ])).rgb, n = (await ed(r, "k", t, [
11931
+ ])).rgb, n = (await Zu(r, "k", t, [
11896
11932
  3.9,
11897
11933
  2.45,
11898
11934
  2.14
@@ -11902,28 +11938,28 @@ async function rd(e, t) {
11902
11938
  i(e[1], n[1]),
11903
11939
  i(e[2], n[2])
11904
11940
  ]);
11905
- } else a(n ? (await ed(r, "eta", t, Xu)).rgb || Xu : Yu.cu);
11906
- i.metalness = 1, i.roughness = nd(r, .1);
11941
+ } else a(n ? (await Zu(r, "eta", t, qu)).rgb || qu : Ku.cu);
11942
+ i.metalness = 1, i.roughness = $u(r, .1);
11907
11943
  break;
11908
11944
  }
11909
11945
  case "dielectric":
11910
11946
  case "thindielectric":
11911
- i.transmission = 1, i.metalness = 0, i.color.setRGB(1, 1, 1), i.ior = Qu(r, "eta", 1.5), i.roughness = nd(r, 0), i.thickness = n === "thindielectric" ? 0 : Qu(r, "thickness", 0);
11947
+ i.transmission = 1, i.metalness = 0, i.color.setRGB(1, 1, 1), i.ior = Yu(r, "eta", 1.5), i.roughness = $u(r, 0), i.thickness = n === "thindielectric" ? 0 : Yu(r, "thickness", 0);
11912
11948
  break;
11913
11949
  case "coateddiffuse":
11914
- o(await ed(r, "reflectance", t, [
11950
+ o(await Zu(r, "reflectance", t, [
11915
11951
  .5,
11916
11952
  .5,
11917
11953
  .5
11918
- ])), i.roughness = .6, i.metalness = 0, i.clearcoat = 1, i.clearcoatRoughness = nd(r, 0);
11954
+ ])), i.roughness = .6, i.metalness = 0, i.clearcoat = 1, i.clearcoatRoughness = $u(r, 0);
11919
11955
  break;
11920
11956
  case "diffusetransmission": {
11921
- let e = await ed(r, "transmittance", t, [
11957
+ let e = await Zu(r, "transmittance", t, [
11922
11958
  .25,
11923
11959
  .25,
11924
11960
  .25
11925
11961
  ]);
11926
- o(await ed(r, "reflectance", t, [
11962
+ o(await Zu(r, "reflectance", t, [
11927
11963
  .25,
11928
11964
  .25,
11929
11965
  .25
@@ -11936,9 +11972,9 @@ async function rd(e, t) {
11936
11972
  i.transmission = 1, i.ior = 1, i.roughness = 0, i.color.setRGB(1, 1, 1);
11937
11973
  break;
11938
11974
  case "mix": {
11939
- let e = r.materials?.value || [], n = Math.max(0, Math.min(1, Qu(r, "amount", .5))), a = e[0] ? t.namedMaterials?.get(e[0]) : null, o = e[1] ? t.namedMaterials?.get(e[1]) : null;
11975
+ let e = r.materials?.value || [], n = Math.max(0, Math.min(1, Yu(r, "amount", .5))), a = e[0] ? t.namedMaterials?.get(e[0]) : null, o = e[1] ? t.namedMaterials?.get(e[1]) : null;
11940
11976
  if (a && o) {
11941
- let [e, r] = await Promise.all([rd(a, t), rd(o, t)]), s = (e, t) => e * (1 - n) + t * n;
11977
+ let [e, r] = await Promise.all([ed(a, t), ed(o, t)]), s = (e, t) => e * (1 - n) + t * n;
11942
11978
  i.color.lerpColors(e.color, r.color, n), i.roughness = s(e.roughness, r.roughness), i.metalness = s(e.metalness, r.metalness), i.ior = s(e.ior ?? 1.5, r.ior ?? 1.5), i.transmission = s(e.transmission ?? 0, r.transmission ?? 0), i.thickness = s(e.thickness ?? 0, r.thickness ?? 0), i.clearcoat = s(e.clearcoat ?? 0, r.clearcoat ?? 0), i.clearcoatRoughness = s(e.clearcoatRoughness ?? 0, r.clearcoatRoughness ?? 0), i.emissive.lerpColors(e.emissive, r.emissive, n), i.emissiveIntensity = s(e.emissiveIntensity ?? 0, r.emissiveIntensity ?? 0), i.map = (n < .5 ? e.map : r.map) || null;
11943
11979
  break;
11944
11980
  }
@@ -11948,7 +11984,7 @@ async function rd(e, t) {
11948
11984
  case "subsurface":
11949
11985
  case "hair":
11950
11986
  case "measured":
11951
- t.warn(`material "${n}" not supported — using diffuse approximation`), a((await ed(r, "reflectance", t, [
11987
+ t.warn(`material "${n}" not supported — using diffuse approximation`), a((await Zu(r, "reflectance", t, [
11952
11988
  .5,
11953
11989
  .5,
11954
11990
  .5
@@ -11962,7 +11998,7 @@ async function rd(e, t) {
11962
11998
  }
11963
11999
  //#endregion
11964
12000
  //#region src/Processor/PBRT/PBRTSceneBuilder.js
11965
- var id = [
12001
+ var td = [
11966
12002
  1,
11967
12003
  0,
11968
12004
  0,
@@ -11979,7 +12015,7 @@ var id = [
11979
12015
  0,
11980
12016
  0,
11981
12017
  1
11982
- ], ad = class {
12018
+ ], nd = class {
11983
12019
  constructor(e = {}) {
11984
12020
  this.resolvePLY = e.resolvePLY || (async () => null), this.resolveImage = e.resolveImage || (async () => null), this.resolveEnvironment = e.resolveEnvironment || e.resolveImage || (async () => null), this.convertHandedness = e.convertHandedness === !0, this.warnings = [], this.report = [], this._materialCache = /* @__PURE__ */ new Map(), this._textureCache = /* @__PURE__ */ new Map();
11985
12021
  }
@@ -12015,7 +12051,7 @@ var id = [
12015
12051
  continue;
12016
12052
  }
12017
12053
  for (let e of i) {
12018
- let i = zu(r.ctm, e.relativeCTM || e.ctm), a = await this._buildShapeMesh(e, i, `instance_${n++}`);
12054
+ let i = Iu(r.ctm, e.relativeCTM || e.ctm), a = await this._buildShapeMesh(e, i, `instance_${n++}`);
12019
12055
  a && t.add(a);
12020
12056
  }
12021
12057
  }
@@ -12027,7 +12063,7 @@ var id = [
12027
12063
  i.map && !a && (this.warn(`${n} (${e.type}, "${e.material?.type || "diffuse"}") has a texture map but no UVs — dropping map, using base color`), o = i.clone(), o.map = null);
12028
12064
  let s = new bt(r, o);
12029
12065
  s.name = n;
12030
- let c = this.convertHandedness ? zu(id, t) : t;
12066
+ let c = this.convertHandedness ? Iu(td, t) : t;
12031
12067
  new yt().fromArray(c).decompose(s.position, s.quaternion, s.scale), s.updateMatrix(), r.computeBoundingBox();
12032
12068
  let l = r.boundingBox ? r.boundingBox.clone().applyMatrix4(s.matrix).getSize(new nn()) : new nn();
12033
12069
  return this.report.push({
@@ -12082,7 +12118,7 @@ var id = [
12082
12118
  return i.setAttribute("position", new st(Float32Array.from(t), 3)), i.setIndex(r), i.computeVertexNormals(), i;
12083
12119
  }
12084
12120
  async _plyMesh(e) {
12085
- let t = $u(e, "filename", null);
12121
+ let t = Xu(e, "filename", null);
12086
12122
  if (!t) return this.warn("plymesh missing filename"), null;
12087
12123
  try {
12088
12124
  let e = await this.resolvePLY(t);
@@ -12092,10 +12128,10 @@ var id = [
12092
12128
  }
12093
12129
  }
12094
12130
  _sphere(e) {
12095
- return new Kt(Qu(e, "radius", 1), 48, 32);
12131
+ return new Kt(Yu(e, "radius", 1), 48, 32);
12096
12132
  }
12097
12133
  _disk(e) {
12098
- let t = Qu(e, "radius", 1), n = Qu(e, "innerradius", 0), r = Qu(e, "height", 0), i = [], a = [];
12134
+ let t = Yu(e, "radius", 1), n = Yu(e, "innerradius", 0), r = Yu(e, "height", 0), i = [], a = [];
12099
12135
  for (let e = 0; e < 48; e++) {
12100
12136
  let o = e / 48 * Math.PI * 2, s = (e + 1) / 48 * Math.PI * 2, c = i.length / 3;
12101
12137
  i.push(Math.cos(o) * n, Math.sin(o) * n, r), i.push(Math.cos(o) * t, Math.sin(o) * t, r), i.push(Math.cos(s) * t, Math.sin(s) * t, r), i.push(Math.cos(s) * n, Math.sin(s) * n, r), a.push(c, c + 1, c + 2, c, c + 2, c + 3);
@@ -12110,15 +12146,15 @@ var id = [
12110
12146
  resolveNamedTexture: (e) => this._resolveNamedTexture(e),
12111
12147
  namedMaterials: this.ir.namedMaterials,
12112
12148
  warn: (e) => this.warn(e)
12113
- }, r = await rd(e.material, n);
12149
+ }, r = await ed(e.material, n);
12114
12150
  return e.areaLight && await this._applyAreaLight(r, e.areaLight, n), t.set(e.areaLight, r), r;
12115
12151
  }
12116
12152
  async _applyAreaLight(e, t, n) {
12117
- let r = await ed(t.params, "L", n, [
12153
+ let r = await Zu(t.params, "L", n, [
12118
12154
  1,
12119
12155
  1,
12120
12156
  1
12121
- ]), i = Qu(t.params, "scale", 1), a = r.rgb || [
12157
+ ]), i = Yu(t.params, "scale", 1), a = r.rgb || [
12122
12158
  1,
12123
12159
  1,
12124
12160
  1
@@ -12130,7 +12166,7 @@ var id = [
12130
12166
  let t = this.ir.namedTextures.get(e), n = null;
12131
12167
  if (!t) this.warn(`named texture "${e}" not defined`);
12132
12168
  else if (t.class === "imagemap") {
12133
- let r = $u(t.params, "filename", null);
12169
+ let r = Xu(t.params, "filename", null);
12134
12170
  if (r) try {
12135
12171
  let t = await this.resolveImage(r);
12136
12172
  t ? n = { texture: t } : this.warn(`image not found for texture "${e}": ${r}`);
@@ -12218,7 +12254,7 @@ var id = [
12218
12254
  return c.name = "PBRT Camera", c.up.copy(a.normalize()), c.position.copy(r), c.lookAt(o), c.updateMatrixWorld(!0), c;
12219
12255
  }
12220
12256
  _verticalFov(e, t) {
12221
- let n = Qu(e, "fov", 90);
12257
+ let n = Yu(e, "fov", 90);
12222
12258
  if (t >= 1) return n;
12223
12259
  let r = n * Math.PI / 180;
12224
12260
  return 2 * Math.atan(Math.tan(r / 2) / t) * 180 / Math.PI;
@@ -12226,7 +12262,7 @@ var id = [
12226
12262
  async _buildEnvironment(e) {
12227
12263
  let t = e.find((e) => e.type === "infinite");
12228
12264
  if (!t) return null;
12229
- let n = Qu(t.params, "scale", 1), r = $u(t.params, "filename", null);
12265
+ let n = Yu(t.params, "scale", 1), r = Xu(t.params, "filename", null);
12230
12266
  if (r) try {
12231
12267
  let e = await this.resolveEnvironment(r);
12232
12268
  if (e) return e.mapping = at, { texture: e };
@@ -12234,7 +12270,7 @@ var id = [
12234
12270
  } catch (e) {
12235
12271
  this.warn(`failed to load infinite-light image ${r}: ${e.message}`);
12236
12272
  }
12237
- let i = ((await ed(t.params, "L", {
12273
+ let i = ((await Zu(t.params, "L", {
12238
12274
  resolveNamedTexture: async () => null,
12239
12275
  warn: (e) => this.warn(e)
12240
12276
  }, [
@@ -12253,20 +12289,20 @@ var id = [
12253
12289
  _reportUnsupportedLights(e) {
12254
12290
  for (let t of e) t.type !== "infinite" && this.warn(`light "${t.type}" not supported (only infinite lights and emissive area lights are mapped)`);
12255
12291
  }
12256
- }, od = new TextDecoder();
12257
- function sd(e) {
12292
+ }, rd = new TextDecoder();
12293
+ function id(e) {
12258
12294
  let t = e.replace(/\\/g, "/").split("/"), n = [];
12259
12295
  for (let e of t) e === "" || e === "." || (e === ".." ? n.pop() : n.push(e));
12260
12296
  return n.join("/");
12261
12297
  }
12262
- function cd(e, t) {
12263
- return !e || t.startsWith("/") ? sd(t) : sd(`${e}/${t}`);
12298
+ function ad(e, t) {
12299
+ return !e || t.startsWith("/") ? id(t) : id(`${e}/${t}`);
12264
12300
  }
12265
- var ld = class {
12301
+ var od = class {
12266
12302
  constructor(e) {
12267
12303
  this.byPath = /* @__PURE__ */ new Map(), this.byBase = /* @__PURE__ */ new Map();
12268
12304
  for (let t in e) {
12269
- let n = sd(t).toLowerCase(), r = {
12305
+ let n = id(t).toLowerCase(), r = {
12270
12306
  norm: n,
12271
12307
  bytes: e[t]
12272
12308
  };
@@ -12276,13 +12312,13 @@ var ld = class {
12276
12312
  }
12277
12313
  }
12278
12314
  find(e) {
12279
- let t = sd(e).toLowerCase();
12315
+ let t = id(e).toLowerCase();
12280
12316
  if (this.byPath.has(t)) return this.byPath.get(t).bytes;
12281
12317
  let n = this.byBase.get(t.split("/").pop());
12282
12318
  return n ? (n.find((e) => e.norm.endsWith("/" + t)) || n[0]).bytes : null;
12283
12319
  }
12284
12320
  };
12285
- function ud(e) {
12321
+ function sd(e) {
12286
12322
  let t = Object.keys(e).filter((e) => e.toLowerCase().endsWith(".pbrt"));
12287
12323
  if (t.length === 0) return null;
12288
12324
  let n = t.filter((e) => /(^|\/)(scene|main)\.pbrt$/i.test(e)), r = n.length ? n : t;
@@ -12291,17 +12327,17 @@ function ud(e) {
12291
12327
  return n === r ? e.length - t.length : n - r;
12292
12328
  }), r[0];
12293
12329
  }
12294
- async function dd(e) {
12295
- let { vfs: t, plyParser: n, imageFromBytes: r, envFromBytes: i, convertHandedness: a } = e, o = new ld(t), s = e.entryPath || ud(t);
12330
+ async function cd(e) {
12331
+ let { vfs: t, plyParser: n, imageFromBytes: r, envFromBytes: i, convertHandedness: a } = e, o = new od(t), s = e.entryPath || sd(t);
12296
12332
  if (!s) throw Error("PBRT loader: no .pbrt file found in archive");
12297
12333
  let c = o.find(s);
12298
12334
  if (!c) throw Error(`PBRT loader: entry "${s}" not readable`);
12299
- let l = s.includes("/") ? s.slice(0, s.lastIndexOf("/")) : "", u = new Ju({ resolveInclude: (e, t) => {
12300
- let n = o.find(cd(t, e)) || o.find(e);
12301
- return n ? od.decode(n) : null;
12302
- } }).parse(od.decode(c), l), d = (e) => e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
12335
+ let l = s.includes("/") ? s.slice(0, s.lastIndexOf("/")) : "", u = new Gu({ resolveInclude: (e, t) => {
12336
+ let n = o.find(ad(t, e)) || o.find(e);
12337
+ return n ? rd.decode(n) : null;
12338
+ } }).parse(rd.decode(c), l), d = (e) => e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
12303
12339
  return {
12304
- ...await new ad({
12340
+ ...await new nd({
12305
12341
  convertHandedness: a,
12306
12342
  resolvePLY: async (e) => {
12307
12343
  let t = o.find(e);
@@ -12321,7 +12357,7 @@ async function dd(e) {
12321
12357
  }
12322
12358
  //#endregion
12323
12359
  //#region src/Processor/AssetLoader.js
12324
- var fd = {
12360
+ var ld = {
12325
12361
  glb: {
12326
12362
  type: "model",
12327
12363
  name: "GLB (GLTF Binary)"
@@ -12386,7 +12422,7 @@ var fd = {
12386
12422
  type: "archive",
12387
12423
  name: "ZIP Archive"
12388
12424
  }
12389
- }, pd = class extends ot {
12425
+ }, ud = class extends ot {
12390
12426
  constructor(e, t, n) {
12391
12427
  super(), this.scene = e, this.camera = t, this.controls = n, this.targetModel = null, this._externalModel = null, this.floorPlane = null, this.sceneScale = 1, this.loaderCache = {}, this.uploadedFileInfo = null, this.animations = [], this.renderer = null;
12392
12428
  }
@@ -12397,7 +12433,7 @@ var fd = {
12397
12433
  this.renderer = e;
12398
12434
  }
12399
12435
  getFileFormat(e) {
12400
- return fd[e.split(".").pop().toLowerCase()] || null;
12436
+ return ld[e.split(".").pop().toLowerCase()] || null;
12401
12437
  }
12402
12438
  readFileAsArrayBuffer(e) {
12403
12439
  return new Promise((t, n) => {
@@ -12531,7 +12567,7 @@ var fd = {
12531
12567
  async loadArchiveFromFile(e, t) {
12532
12568
  try {
12533
12569
  let n = await this.readFileAsArrayBuffer(e), r = mn(new Uint8Array(n));
12534
- return ud(r) ? await this.loadPBRTFromZip(r, t) : await this.processObjMtlPairsInZip(r, t) || await this.findAndLoadModelFromZip(r, t);
12570
+ return sd(r) ? await this.loadPBRTFromZip(r, t) : await this.processObjMtlPairsInZip(r, t) || await this.findAndLoadModelFromZip(r, t);
12535
12571
  } catch (e) {
12536
12572
  throw console.error("Error loading ZIP archive:", e), e;
12537
12573
  }
@@ -12545,7 +12581,7 @@ var fd = {
12545
12581
  let { PLYLoader: e } = await import("three/examples/jsm/loaders/PLYLoader.js");
12546
12582
  this.loaderCache.ply = new e();
12547
12583
  }
12548
- let { group: n, environment: r, report: i, warnings: a, entryPath: o } = await dd({
12584
+ let { group: n, environment: r, report: i, warnings: a, entryPath: o } = await cd({
12549
12585
  vfs: e,
12550
12586
  plyParser: (e) => this.loaderCache.ply.parse(e),
12551
12587
  imageFromBytes: (e, t) => this._pbrtTextureFromBytes(e, t),
@@ -12644,7 +12680,7 @@ var fd = {
12644
12680
  }
12645
12681
  for (let t in e) {
12646
12682
  let n = t.split(".").pop().toLowerCase();
12647
- if (fd[n] && fd[n].type === "model") return console.log(`Loading model file from ZIP: ${t}`), await this.loadModelFromZipEntry(e[t], t, n, e);
12683
+ if (ld[n] && ld[n].type === "model") return console.log(`Loading model file from ZIP: ${t}`), await this.loadModelFromZipEntry(e[t], t, n, e);
12648
12684
  }
12649
12685
  throw Error("No supported model files found in the ZIP archive");
12650
12686
  }
@@ -13170,10 +13206,10 @@ var fd = {
13170
13206
  getSupportedFormats(e = null) {
13171
13207
  if (e) {
13172
13208
  let t = {};
13173
- for (let [n, r] of Object.entries(fd)) r.type === e && (t[n] = r);
13209
+ for (let [n, r] of Object.entries(ld)) r.type === e && (t[n] = r);
13174
13210
  return t;
13175
13211
  }
13176
- return fd;
13212
+ return ld;
13177
13213
  }
13178
13214
  dispose() {
13179
13215
  for (let e in this.loaderCache) {
@@ -13185,7 +13221,7 @@ var fd = {
13185
13221
  removeAllEventListeners() {
13186
13222
  this._listeners = void 0;
13187
13223
  }
13188
- }, md = {
13224
+ }, dd = {
13189
13225
  maxBounces: {
13190
13226
  uniform: "maxBounces",
13191
13227
  reset: !0
@@ -13324,10 +13360,10 @@ var fd = {
13324
13360
  },
13325
13361
  renderMode: { handler: "handleRenderMode" },
13326
13362
  environmentRotation: { handler: "handleEnvironmentRotation" }
13327
- }, hd = {
13363
+ }, fd = {
13328
13364
  bounces: "maxBounces",
13329
13365
  debugMode: "visMode"
13330
- }, gd = class extends ot {
13366
+ }, pd = class extends ot {
13331
13367
  constructor(e = X) {
13332
13368
  super(), this._values = /* @__PURE__ */ new Map(), this._pathTracer = null, this._resetCallback = null, this._handlers = {}, this._delegates = {}, this._initDefaults(e);
13333
13369
  }
@@ -13373,7 +13409,7 @@ var fd = {
13373
13409
  let i = this._values.get(e);
13374
13410
  if (i === t) return;
13375
13411
  this._values.set(e, t);
13376
- let a = md[e];
13412
+ let a = dd[e];
13377
13413
  a && (this._applyRoute(a, t, i), (n === void 0 ? a.reset ?? !0 : n) && this._resetCallback?.(), r || this.dispatchEvent({
13378
13414
  type: Yn.SETTING_CHANGED,
13379
13415
  key: e,
@@ -13387,7 +13423,7 @@ var fd = {
13387
13423
  let e = this._values.get(r);
13388
13424
  if (e === i) continue;
13389
13425
  this._values.set(r, i);
13390
- let a = md[r];
13426
+ let a = dd[r];
13391
13427
  a && (this._applyRoute(a, i, e), (a.reset ?? !0) && (n = !0), t || this.dispatchEvent({
13392
13428
  type: Yn.SETTING_CHANGED,
13393
13429
  key: r,
@@ -13405,7 +13441,7 @@ var fd = {
13405
13441
  }
13406
13442
  applyAll() {
13407
13443
  for (let [e, t] of this._values) {
13408
- let n = md[e];
13444
+ let n = dd[e];
13409
13445
  n && this._applyRoute(n, t, void 0);
13410
13446
  }
13411
13447
  }
@@ -13413,10 +13449,10 @@ var fd = {
13413
13449
  e.uniform ? (this._pathTracer?.setUniform(e.uniform, t), e.after && this._pathTracer?.[e.after]?.()) : e.handler ? this._handlers[e.handler]?.(t, n) : e.delegate && this._delegates[e.delegate]?.updateParam?.(e.param, t);
13414
13450
  }
13415
13451
  _initDefaults(e) {
13416
- for (let t of Object.keys(md)) t in e && this._values.set(t, e[t]);
13417
- for (let [t, n] of Object.entries(hd)) t in e && this._values.set(n, e[t]);
13452
+ for (let t of Object.keys(dd)) t in e && this._values.set(t, e[t]);
13453
+ for (let [t, n] of Object.entries(fd)) t in e && this._values.set(n, e[t]);
13418
13454
  }
13419
- }, _d = class extends ot {
13455
+ }, md = class extends ot {
13420
13456
  constructor(e) {
13421
13457
  super();
13422
13458
  let t = e.clientWidth, n = e.clientHeight;
@@ -13537,7 +13573,7 @@ var fd = {
13537
13573
  dispose() {
13538
13574
  this.controls?.dispose();
13539
13575
  }
13540
- }, vd = class extends ot {
13576
+ }, hd = class extends ot {
13541
13577
  constructor(e, t, n, r = {}) {
13542
13578
  super(), this.scene = e, this.sceneHelpers = t, this.pathTracer = n, this._onReset = r.onReset || null;
13543
13579
  }
@@ -13690,14 +13726,14 @@ var fd = {
13690
13726
  ], n.distance = e.distance ?? 0, n.penumbra = e.penumbra ?? 0, n.decay = e.decay ?? 2) : e.type === "PointLight" && (n.distance = e.distance ?? 0, n.decay = e.decay ?? 2);
13691
13727
  return (e.type === "SpotLight" || e.type === "DirectionalLight") && e.userData?.gobo && (n.gobo = e.userData.gobo.name, n.goboIntensity = e.userData.gobo.intensity, n.goboInverted = !!e.userData.gobo.inverted, e.type === "DirectionalLight" && (n.goboScale = e.userData.gobo.scale ?? 5)), e.type === "SpotLight" && e.userData?.ies && (n.ies = e.userData.ies.name, n.iesIntensity = e.userData.ies.intensity ?? 1, n.fixtureLumens = e.userData.ies.fixtureLumens ?? null), n;
13692
13728
  }
13693
- }, yd = class {
13729
+ }, gd = class {
13694
13730
  constructor(e, t = {}) {
13695
13731
  this.pathTracer = e, this._onReset = t.onReset || null, this.texture = null, this.entries = [], this._size = 256;
13696
13732
  }
13697
13733
  async loadLibrary(e, { size: t = 256 } = {}) {
13698
13734
  if (!Array.isArray(e) || e.length === 0) return [];
13699
13735
  this._size = t;
13700
- let n = await Promise.all(e.map((e) => bd(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
13736
+ let n = await Promise.all(e.map((e) => _d(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
13701
13737
  s.width = r, s.height = i;
13702
13738
  let c = s.getContext("2d", { willReadFrequently: !0 });
13703
13739
  for (let e = 0; e < a; e++) {
@@ -13726,7 +13762,7 @@ var fd = {
13726
13762
  o.userData.gobo = {
13727
13763
  name: e.name,
13728
13764
  index: e.index,
13729
- intensity: xd(r),
13765
+ intensity: vd(r),
13730
13766
  inverted: !!i,
13731
13767
  scale: Math.max(1e-4, a)
13732
13768
  };
@@ -13768,28 +13804,28 @@ var fd = {
13768
13804
  return t && t.isSpotLight ? t : null;
13769
13805
  }
13770
13806
  };
13771
- function bd(e) {
13807
+ function _d(e) {
13772
13808
  return new Promise((t, n) => {
13773
13809
  let r = new Image();
13774
13810
  r.crossOrigin = "anonymous", r.onload = () => t(r), r.onerror = () => n(/* @__PURE__ */ Error(`Failed to load gobo image: ${e}`)), r.src = e;
13775
13811
  });
13776
13812
  }
13777
- function xd(e) {
13813
+ function vd(e) {
13778
13814
  return Math.max(0, Math.min(1, e));
13779
13815
  }
13780
13816
  //#endregion
13781
13817
  //#region src/Processor/IESParser.js
13782
- function Sd(e, t = "ies") {
13818
+ function yd(e, t = "ies") {
13783
13819
  let n = e.search(/TILT\s*=/i);
13784
13820
  if (n < 0) throw Error(`IES (${t}): missing TILT line`);
13785
13821
  let r = e.indexOf("\n", n);
13786
13822
  if (r < 0) throw Error(`IES (${t}): truncated TILT line`);
13787
13823
  let i = e.slice(n, r).match(/TILT\s*=\s*(\w+)/i), a = i ? i[1].toUpperCase() : "NONE", o = e.slice(r);
13788
13824
  if (a === "INCLUDE") {
13789
- let e = Ed(o), t = 2 + 2 * Number(e[1]);
13790
- o = Dd(o, t);
13825
+ let e = Cd(o), t = 2 + 2 * Number(e[1]);
13826
+ o = wd(o, t);
13791
13827
  }
13792
- let s = Ed(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
13828
+ let s = Cd(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
13793
13829
  l(), l(), l(), l();
13794
13830
  let g = l();
13795
13831
  if (l(), l(), !Number.isFinite(p) || p <= 0) throw Error(`IES (${t}): invalid vertical angle count ${p}`);
@@ -13815,18 +13851,18 @@ function Sd(e, t = "ies") {
13815
13851
  name: t
13816
13852
  };
13817
13853
  }
13818
- function Cd(e, t, n) {
13854
+ function bd(e, t, n) {
13819
13855
  let r = new Uint8Array(t * n), { verticalAngles: i, horizontalAngles: a, candela: o, maxCandela: s } = e;
13820
13856
  if (s <= 0) return r;
13821
13857
  let c = i[i.length - 1], l = a[a.length - 1], u = a[0], d = a.length === 1 || l === u;
13822
13858
  for (let e = 0; e < n; e++) {
13823
- let f = (e + .5) / n * c, p = Od(i, f), m = Math.min(p + 1, i.length - 1), h = i[m] - i[p], g = h > 0 ? (f - i[p]) / h : 0;
13859
+ let f = (e + .5) / n * c, p = Td(i, f), m = Math.min(p + 1, i.length - 1), h = i[m] - i[p], g = h > 0 ? (f - i[p]) / h : 0;
13824
13860
  for (let n = 0; n < t; n++) {
13825
13861
  let i;
13826
- if (d) i = kd(o[p][0], o[m][0], g);
13862
+ if (d) i = Ed(o[p][0], o[m][0], g);
13827
13863
  else {
13828
- let e = u + (n + .5) / t * (l - u), r = Od(a, e), s = Math.min(r + 1, a.length - 1), c = a[s] - a[r], d = c > 0 ? (e - a[r]) / c : 0, f = o[p][r], h = o[p][s], _ = o[m][r], v = o[m][s];
13829
- i = kd(kd(f, h, d), kd(_, v, d), g);
13864
+ let e = u + (n + .5) / t * (l - u), r = Td(a, e), s = Math.min(r + 1, a.length - 1), c = a[s] - a[r], d = c > 0 ? (e - a[r]) / c : 0, f = o[p][r], h = o[p][s], _ = o[m][r], v = o[m][s];
13865
+ i = Ed(Ed(f, h, d), Ed(_, v, d), g);
13830
13866
  }
13831
13867
  let c = Math.min(1, Math.max(0, i / s));
13832
13868
  r[e * t + n] = Math.round(c * 255);
@@ -13834,7 +13870,7 @@ function Cd(e, t, n) {
13834
13870
  }
13835
13871
  return r;
13836
13872
  }
13837
- function wd(e, t = .1) {
13873
+ function xd(e, t = .1) {
13838
13874
  let { verticalAngles: n, horizontalAngles: r, candela: i, maxCandela: a } = e, o = Math.PI / 4;
13839
13875
  if (a <= 0 || !n?.length) return o;
13840
13876
  let s = a * t, c = r.length, l = n[n.length - 1], u = !1;
@@ -13849,7 +13885,7 @@ function wd(e, t = .1) {
13849
13885
  let d = l * Math.PI / 180;
13850
13886
  return Math.min(Math.max(d, 5 * Math.PI / 180), 89 * Math.PI / 180);
13851
13887
  }
13852
- function Td(e, t, n = .7) {
13888
+ function Sd(e, t, n = .7) {
13853
13889
  let { verticalAngles: r, horizontalAngles: i, candela: a, maxCandela: o } = e;
13854
13890
  if (o <= 0 || !r?.length || t <= 0) return 0;
13855
13891
  let s = o * n, c = i.length, l = 0;
@@ -13862,15 +13898,15 @@ function Td(e, t, n = .7) {
13862
13898
  let u = t * 180 / Math.PI, d = u > 0 ? 1 - l / u : 0;
13863
13899
  return Math.min(Math.max(d, 0), 1);
13864
13900
  }
13865
- function Ed(e) {
13901
+ function Cd(e) {
13866
13902
  return e.split(/\s+/).filter((e) => e.length > 0);
13867
13903
  }
13868
- function Dd(e, t) {
13904
+ function wd(e, t) {
13869
13905
  let n = /\S+/g, r = 0;
13870
13906
  for (; n.exec(e) !== null;) if (r++, r === t) return e.slice(n.lastIndex);
13871
13907
  return "";
13872
13908
  }
13873
- function Od(e, t) {
13909
+ function Td(e, t) {
13874
13910
  if (t <= e[0]) return 0;
13875
13911
  if (t >= e[e.length - 1]) return e.length - 1;
13876
13912
  let n = 0, r = e.length - 1;
@@ -13880,12 +13916,12 @@ function Od(e, t) {
13880
13916
  }
13881
13917
  return n;
13882
13918
  }
13883
- function kd(e, t, n) {
13919
+ function Ed(e, t, n) {
13884
13920
  return e + (t - e) * n;
13885
13921
  }
13886
13922
  //#endregion
13887
13923
  //#region src/managers/IESManager.js
13888
- var Ad = class {
13924
+ var Dd = class {
13889
13925
  constructor(e, t = {}) {
13890
13926
  this.pathTracer = e, this._onReset = t.onReset || null, this.texture = null, this.entries = [], this._gridWidth = 128, this._gridHeight = 128;
13891
13927
  }
@@ -13896,11 +13932,11 @@ var Ad = class {
13896
13932
  try {
13897
13933
  let r = await fetch(e.url);
13898
13934
  if (!r.ok) throw Error(`HTTP ${r.status}`);
13899
- let i = Sd(await r.text(), e.name);
13935
+ let i = yd(await r.text(), e.name);
13900
13936
  return {
13901
13937
  it: e,
13902
13938
  profile: i,
13903
- grid: Cd(i, t, n)
13939
+ grid: bd(i, t, n)
13904
13940
  };
13905
13941
  } catch (t) {
13906
13942
  return console.warn(`IESManager: failed to load "${e.name}": ${t.message}`), null;
@@ -13914,14 +13950,14 @@ var Ad = class {
13914
13950
  let r = t[e];
13915
13951
  o[n + e * 4 + 0] = r, o[n + e * 4 + 1] = r, o[n + e * 4 + 2] = r, o[n + e * 4 + 3] = 255;
13916
13952
  }
13917
- let i = r[e].profile, c = wd(i);
13953
+ let i = r[e].profile, c = xd(i);
13918
13954
  s.push({
13919
13955
  name: r[e].it.name,
13920
13956
  index: e,
13921
13957
  maxCandela: i.maxCandela,
13922
13958
  photometricType: i.photometricType,
13923
13959
  suggestedAngle: c,
13924
- suggestedPenumbra: Td(i, c),
13960
+ suggestedPenumbra: Sd(i, c),
13925
13961
  lumens: i.lumens
13926
13962
  });
13927
13963
  }
@@ -13954,7 +13990,7 @@ var Ad = class {
13954
13990
  l = Number.isFinite(e.lumens) ? e.lumens : null, i.userData.ies = {
13955
13991
  name: e.name,
13956
13992
  index: e.index,
13957
- intensity: jd(n),
13993
+ intensity: Od(n),
13958
13994
  fixtureLumens: l
13959
13995
  }, r && (Number.isFinite(e.suggestedAngle) && (i.angle = e.suggestedAngle, o = e.suggestedAngle), Number.isFinite(e.suggestedPenumbra) && (i.penumbra = e.suggestedPenumbra, s = e.suggestedPenumbra), i.decay = 2, c = 2);
13960
13996
  }
@@ -13977,44 +14013,44 @@ var Ad = class {
13977
14013
  return t && t.isSpotLight ? t : null;
13978
14014
  }
13979
14015
  };
13980
- function jd(e) {
14016
+ function Od(e) {
13981
14017
  return Math.max(0, Math.min(1, e));
13982
14018
  }
13983
14019
  //#endregion
13984
14020
  //#region src/Processor/ToneMapCPU.js
13985
- var Md = (e) => Math.min(Math.max(e, 0), 1);
13986
- function Nd(e, t, n, r, i) {
13987
- i[0] = Md(e), i[1] = Md(t), i[2] = Md(n);
14021
+ var kd = (e) => Math.min(Math.max(e, 0), 1);
14022
+ function Ad(e, t, n, r, i) {
14023
+ i[0] = kd(e), i[1] = kd(t), i[2] = kd(n);
13988
14024
  }
13989
- function Pd(e, t, n, r, i) {
13990
- i[0] = Md(e * r), i[1] = Md(t * r), i[2] = Md(n * r);
14025
+ function jd(e, t, n, r, i) {
14026
+ i[0] = kd(e * r), i[1] = kd(t * r), i[2] = kd(n * r);
13991
14027
  }
13992
- function Fd(e, t, n, r, i) {
13993
- e *= r, t *= r, n *= r, i[0] = Md(e / (e + 1)), i[1] = Md(t / (t + 1)), i[2] = Md(n / (n + 1));
14028
+ function Md(e, t, n, r, i) {
14029
+ e *= r, t *= r, n *= r, i[0] = kd(e / (e + 1)), i[1] = kd(t / (t + 1)), i[2] = kd(n / (n + 1));
13994
14030
  }
13995
- function Id(e, t, n, r, i) {
14031
+ function Nd(e, t, n, r, i) {
13996
14032
  e = Math.max(e * r - .004, 0), t = Math.max(t * r - .004, 0), n = Math.max(n * r - .004, 0);
13997
14033
  let a = (e) => (e * (6.2 * e + .5) / (e * (6.2 * e + 1.7) + .06)) ** 2.2;
13998
14034
  i[0] = a(e), i[1] = a(t), i[2] = a(n);
13999
14035
  }
14000
- function Ld(e, t, n, r, i) {
14036
+ function Pd(e, t, n, r, i) {
14001
14037
  e = e * r / .6, t = t * r / .6, n = n * r / .6;
14002
14038
  let a = .59719 * e + .35458 * t + .04823 * n, o = .076 * e + .90834 * t + .01566 * n, s = .0284 * e + .13383 * t + .83777 * n, c = (e) => (e * (e + .0245786) - 90537e-9) / (e * (.983729 * e + .432951) + .238081);
14003
- a = c(a), o = c(o), s = c(s), i[0] = Md(1.60475 * a - .53108 * o - .07367 * s), i[1] = Md(-.10208 * a + 1.10813 * o - .00605 * s), i[2] = Md(-.00327 * a - .07276 * o + 1.07602 * s);
14039
+ a = c(a), o = c(o), s = c(s), i[0] = kd(1.60475 * a - .53108 * o - .07367 * s), i[1] = kd(-.10208 * a + 1.10813 * o - .00605 * s), i[2] = kd(-.00327 * a - .07276 * o + 1.07602 * s);
14004
14040
  }
14005
- function Rd(e, t, n, r, i) {
14041
+ function Fd(e, t, n, r, i) {
14006
14042
  e *= r, t *= r, n *= r;
14007
14043
  let a = .6274 * e + .3293 * t + .0433 * n, o = .0691 * e + .9195 * t + .0113 * n, s = .0164 * e + .088 * t + .8956 * n, c = .856627153315983 * a + .0951212405381588 * o + .0482516061458583 * s, l = .137318972929847 * a + .761241990602591 * o + .101439036467562 * s, u = .11189821299995 * a + .0767994186031903 * o + .811302368396859 * s, d = -12.47393, f = 4.026069 - d;
14008
- c = Md((Math.log2(Math.max(c, 1e-10)) - d) / f), l = Md((Math.log2(Math.max(l, 1e-10)) - d) / f), u = Md((Math.log2(Math.max(u, 1e-10)) - d) / f);
14044
+ c = kd((Math.log2(Math.max(c, 1e-10)) - d) / f), l = kd((Math.log2(Math.max(l, 1e-10)) - d) / f), u = kd((Math.log2(Math.max(u, 1e-10)) - d) / f);
14009
14045
  let p = (e) => {
14010
14046
  let t = e * e, n = t * t;
14011
14047
  return 15.5 * n * t - 40.14 * n * e + 31.96 * n - 6.868 * t * e + .4298 * t + .1191 * e - .00232;
14012
14048
  };
14013
14049
  c = p(c), l = p(l), u = p(u);
14014
14050
  let m = 1.1271005818144368 * c - .11060664309660323 * l - .016493938717834573 * u, h = -.1413297634984383 * c + 1.157823702216272 * l - .016493938717834257 * u, g = -.14132976349843826 * c - .11060664309660294 * l + 1.2519364065950405 * u;
14015
- m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] = Md(1.6605 * m - .5876 * h - .0728 * g), i[1] = Md(-.1246 * m + 1.1329 * h - .0083 * g), i[2] = Md(-.0182 * m - .1006 * h + 1.1187 * g);
14051
+ m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] = kd(1.6605 * m - .5876 * h - .0728 * g), i[1] = kd(-.1246 * m + 1.1329 * h - .0083 * g), i[2] = kd(-.0182 * m - .1006 * h + 1.1187 * g);
14016
14052
  }
14017
- function zd(e, t, n, r, i) {
14053
+ function Id(e, t, n, r, i) {
14018
14054
  let a = .76;
14019
14055
  e *= r, t *= r, n *= r;
14020
14056
  let o = Math.min(e, Math.min(t, n)), s = o < .08 ? o - 6.25 * o * o : .04;
@@ -14029,43 +14065,43 @@ function zd(e, t, n, r, i) {
14029
14065
  let f = 1 - 1 / (.15 * (c - u) + 1);
14030
14066
  i[0] = e + (u - e) * f, i[1] = t + (u - t) * f, i[2] = n + (u - n) * f;
14031
14067
  }
14032
- var Bd = new Map([
14033
- [Dt, Nd],
14034
- [pt, Pd],
14035
- [Vt, Fd],
14036
- [Ye, Id],
14037
- [Be, Ld],
14038
- [He, Rd],
14039
- [Tt, zd]
14040
- ]), Vd = 1 / 2.2;
14041
- function Hd(e) {
14068
+ var Ld = new Map([
14069
+ [Dt, Ad],
14070
+ [pt, jd],
14071
+ [Vt, Md],
14072
+ [Ye, Nd],
14073
+ [Be, Pd],
14074
+ [He, Fd],
14075
+ [Tt, Id]
14076
+ ]), Rd = 1 / 2.2;
14077
+ function zd(e) {
14042
14078
  return e <= .0031308 ? 12.92 * e : 1.055 * e ** (1 / 2.4) - .055;
14043
14079
  }
14044
- var Ud = .2126, Wd = .7152, Gd = .0722;
14045
- function Kd(e, t) {
14080
+ var Bd = .2126, Vd = .7152, Hd = .0722;
14081
+ function Ud(e, t) {
14046
14082
  if (t === 1) return;
14047
- let n = e[0] * Ud + e[1] * Wd + e[2] * Gd;
14083
+ let n = e[0] * Bd + e[1] * Vd + e[2] * Hd;
14048
14084
  e[0] = n + (e[0] - n) * t, e[1] = n + (e[1] - n) * t, e[2] = n + (e[2] - n) * t;
14049
14085
  }
14050
14086
  //#endregion
14051
14087
  //#region src/Passes/OIDNDenoiser.js
14052
- var qd = null, Jd = null;
14053
- async function Yd() {
14054
- if (!qd) {
14088
+ var Wd = null, Gd = null;
14089
+ async function Kd() {
14090
+ if (!Wd) {
14055
14091
  let [e, t] = await Promise.all([import("oidn-web"), import("@tensorflow/tfjs-core")]);
14056
- qd = e.initUNetFromURL, Jd = t.engine;
14092
+ Wd = e.initUNetFromURL, Gd = t.engine;
14057
14093
  }
14058
- return qd;
14094
+ return Wd;
14059
14095
  }
14060
- function Xd() {
14061
- if (Jd) try {
14062
- let e = Jd();
14096
+ function qd() {
14097
+ if (Gd) try {
14098
+ let e = Gd();
14063
14099
  e?.registryFactory && "webgpu-oidn" in e.registryFactory && e.removeBackend("webgpu-oidn");
14064
14100
  } catch (e) {
14065
14101
  console.warn("OIDNDenoiser: failed to clear cached TFJS backend", e);
14066
14102
  }
14067
14103
  }
14068
- var Zd = new Float32Array(3), Qd = {
14104
+ var Jd = new Float32Array(3), Yd = {
14069
14105
  QUALITY_MODELS: {
14070
14106
  fast: "rt_hdr_alb_nrm_small",
14071
14107
  balance: "rt_hdr_alb_nrm",
@@ -14077,7 +14113,7 @@ var Zd = new Float32Array(3), Qd = {
14077
14113
  debugGbufferMaps: !0,
14078
14114
  tileSize: 256
14079
14115
  }
14080
- }, $d = class extends ot {
14116
+ }, Xd = class extends ot {
14081
14117
  constructor(e, t, n, r, i = {}) {
14082
14118
  if (super(), !e || !t || !n || !r) throw Error("OIDNDenoiser requires output canvas, renderer, scene, and camera");
14083
14119
  this.renderer = t, this.scene = n, this.camera = r, this.input = t.domElement, this.output = e, this.extractGBufferData = i.extractGBufferData || null, this.getMRTRenderTarget = i.getMRTRenderTarget || null, this.backendParamsGetter = i.backendParams || null, this.getGPUTextures = i.getGPUTextures || null, this.getExposure = i.getExposure || (() => 1), this.getToneMapping = i.getToneMapping || (() => Be), this.getSaturation = i.getSaturation || (() => 1), this.getTransparentBackground = i.getTransparentBackground || (() => !1), this.isGPUMode = !!this.backendParamsGetter, this.gpuDevice = null, this._gpuInputBuffers = {
@@ -14088,13 +14124,13 @@ var Zd = new Float32Array(3), Qd = {
14088
14124
  width: 0,
14089
14125
  height: 0
14090
14126
  }, this._gpuInputPadBuffer = null, this._gpuInputPaddedRowBytes = 0, this._alphaReadbackBuffer = null, this._alphaReadbackMapped = !1, this._cachedAlpha = null, this._cachedAlphaWidth = 0, this.config = {
14091
- ...Qd.DEFAULT_OPTIONS,
14127
+ ...Yd.DEFAULT_OPTIONS,
14092
14128
  ...i
14093
14129
  }, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.debugGbufferMaps = this.config.debugGbufferMaps, this.tileSize = this.config.tileSize, this.state = {
14094
14130
  isDenoising: !1,
14095
14131
  isLoading: !1,
14096
14132
  abortController: null
14097
- }, this._pendingStagingBuffers = /* @__PURE__ */ new Set(), this.currentTZAUrl = null, this.unet = null, this._initialize().catch((e) => {
14133
+ }, this._pendingStagingBuffers = /* @__PURE__ */ new Set(), this._pendingTileBlits = [], this.currentTZAUrl = null, this.unet = null, this._initialize().catch((e) => {
14098
14134
  console.error("Failed to initialize OIDNDenoiser:", e), this.dispatchEvent({
14099
14135
  type: "error",
14100
14136
  error: e
@@ -14141,7 +14177,7 @@ var Zd = new Float32Array(3), Qd = {
14141
14177
  let e = this.backendParamsGetter();
14142
14178
  this.gpuDevice = e?.device ?? null, t = e?.device ? e : void 0;
14143
14179
  }
14144
- this.unet = await (await Yd())(e, t, {
14180
+ this.unet = await (await Kd())(e, t, {
14145
14181
  aux: !0,
14146
14182
  hdr: !0,
14147
14183
  maxTileSize: this.tileSize
@@ -14156,14 +14192,14 @@ var Zd = new Float32Array(3), Qd = {
14156
14192
  }
14157
14193
  }
14158
14194
  _generateTzaUrl() {
14159
- let { oidnWeightsBaseUrl: e } = Cs(), { QUALITY_MODELS: t } = Qd;
14195
+ let { oidnWeightsBaseUrl: e } = Cs(), { QUALITY_MODELS: t } = Yd;
14160
14196
  return `${e}${t[this.quality] || t.balance}.tza`;
14161
14197
  }
14162
14198
  async updateConfiguration(e) {
14163
14199
  Object.keys(e).some((t) => this.config[t] !== e[t]) && (Object.assign(this.config, e), this.quality = this.config.oidnQuality, this.debugGbufferMaps = this.config.debugGbufferMaps, this.tileSize = this.config.tileSize, await this._setupUNetDenoiser());
14164
14200
  }
14165
14201
  async updateQuality(e) {
14166
- if (!Object.prototype.hasOwnProperty.call(Qd.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Qd.QUALITY_MODELS).join(", ")}`);
14202
+ if (!Object.prototype.hasOwnProperty.call(Yd.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Yd.QUALITY_MODELS).join(", ")}`);
14167
14203
  await this.updateConfiguration({ oidnQuality: e });
14168
14204
  }
14169
14205
  async start() {
@@ -14316,7 +14352,9 @@ var Zd = new Float32Array(3), Qd = {
14316
14352
  n(new DOMException("Aborted", "AbortError"));
14317
14353
  return;
14318
14354
  }
14319
- let r = null, i = () => {
14355
+ let r = null;
14356
+ this._pendingTileBlits = [];
14357
+ let i = () => {
14320
14358
  r &&= (r(), null), n(new DOMException("Aborted", "AbortError"));
14321
14359
  };
14322
14360
  this.state.abortController.signal.addEventListener("abort", i, { once: !0 }), r = this.unet.tileExecute({
@@ -14324,7 +14362,7 @@ var Zd = new Float32Array(3), Qd = {
14324
14362
  done: async (e) => {
14325
14363
  this.state.abortController.signal.removeEventListener("abort", i), r = null;
14326
14364
  try {
14327
- await this._displayGPUOutput(e), t();
14365
+ this._pendingTileBlits.length > 0 ? await Promise.allSettled(this._pendingTileBlits) : await this._displayGPUOutput(e), t();
14328
14366
  } catch (e) {
14329
14367
  n(e);
14330
14368
  }
@@ -14343,11 +14381,12 @@ var Zd = new Float32Array(3), Qd = {
14343
14381
  let r = ((n.y + t) * i + n.x) * 16, a = t * c;
14344
14382
  d.copyBufferToBuffer(e.data, r, u, a, c);
14345
14383
  }
14346
- r.queue.submit([d.finish()]), u.mapAsync(GPUMapMode.READ).then(() => {
14347
- let e = new Float32Array(u.getMappedRange()), t = new ImageData(o, s), r = this.getExposure(), c = this.getSaturation(), l = Bd.get(this.getToneMapping()) || Bd.get(Be), d = this._cachedAlpha, f = this._cachedAlphaWidth;
14384
+ r.queue.submit([d.finish()]);
14385
+ let f = u.mapAsync(GPUMapMode.READ).then(() => {
14386
+ let e = new Float32Array(u.getMappedRange()), t = new ImageData(o, s), r = this.getExposure(), c = this.getSaturation(), l = Ld.get(this.getToneMapping()) || Ld.get(Be), d = this._cachedAlpha, f = this._cachedAlphaWidth;
14348
14387
  for (let i = 0, a = e.length; i < a; i += 4) {
14349
14388
  let a = e[i] * r, s = e[i + 1] * r, u = e[i + 2] * r;
14350
- if (c !== 1 && (Zd[0] = a, Zd[1] = s, Zd[2] = u, Kd(Zd, c), a = Zd[0], s = Zd[1], u = Zd[2]), l(a, s, u, 1, Zd), t.data[i] = Hd(Zd[0]) * 255 + .5 | 0, t.data[i + 1] = Hd(Zd[1]) * 255 + .5 | 0, t.data[i + 2] = Hd(Zd[2]) * 255 + .5 | 0, d) {
14389
+ if (c !== 1 && (Jd[0] = a, Jd[1] = s, Jd[2] = u, Ud(Jd, c), a = Jd[0], s = Jd[1], u = Jd[2]), l(a, s, u, 1, Jd), t.data[i] = zd(Jd[0]) * 255 + .5 | 0, t.data[i + 1] = zd(Jd[1]) * 255 + .5 | 0, t.data[i + 2] = zd(Jd[2]) * 255 + .5 | 0, d) {
14351
14390
  let e = (i >> 2) % o, r = (i >> 2) / o | 0;
14352
14391
  t.data[i + 3] = d[(n.y + r) * f + n.x + e];
14353
14392
  } else t.data[i + 3] = 255;
@@ -14366,6 +14405,7 @@ var Zd = new Float32Array(3), Qd = {
14366
14405
  }).catch(() => {
14367
14406
  u.destroy(), this._pendingStagingBuffers.delete(u);
14368
14407
  });
14408
+ this._pendingTileBlits.push(f);
14369
14409
  }
14370
14410
  });
14371
14411
  });
@@ -14384,10 +14424,10 @@ var Zd = new Float32Array(3), Qd = {
14384
14424
  try {
14385
14425
  let o = r.createCommandEncoder({ label: "oidn-readback" });
14386
14426
  o.copyBufferToBuffer(e, 0, a, 0, i), r.queue.submit([o.finish()]), await a.mapAsync(GPUMapMode.READ);
14387
- let s = new Float32Array(a.getMappedRange()), c = new ImageData(t, n), l = this.getExposure(), u = this.getSaturation(), d = Bd.get(this.getToneMapping()) || Bd.get(Be), f = this._cachedAlpha;
14427
+ let s = new Float32Array(a.getMappedRange()), c = new ImageData(t, n), l = this.getExposure(), u = this.getSaturation(), d = Ld.get(this.getToneMapping()) || Ld.get(Be), f = this._cachedAlpha;
14388
14428
  for (let e = 0, t = s.length; e < t; e += 4) {
14389
14429
  let t = s[e] * l, n = s[e + 1] * l, r = s[e + 2] * l;
14390
- u !== 1 && (Zd[0] = t, Zd[1] = n, Zd[2] = r, Kd(Zd, u), t = Zd[0], n = Zd[1], r = Zd[2]), d(t, n, r, 1, Zd), c.data[e] = Hd(Zd[0]) * 255 + .5 | 0, c.data[e + 1] = Hd(Zd[1]) * 255 + .5 | 0, c.data[e + 2] = Hd(Zd[2]) * 255 + .5 | 0, c.data[e + 3] = f ? f[e >> 2] : 255;
14430
+ u !== 1 && (Jd[0] = t, Jd[1] = n, Jd[2] = r, Ud(Jd, u), t = Jd[0], n = Jd[1], r = Jd[2]), d(t, n, r, 1, Jd), c.data[e] = zd(Jd[0]) * 255 + .5 | 0, c.data[e + 1] = zd(Jd[1]) * 255 + .5 | 0, c.data[e + 2] = zd(Jd[2]) * 255 + .5 | 0, c.data[e + 3] = f ? f[e >> 2] : 255;
14391
14431
  }
14392
14432
  a.unmap(), this.ctx.putImageData(c, 0, 0);
14393
14433
  } finally {
@@ -14408,9 +14448,9 @@ var Zd = new Float32Array(3), Qd = {
14408
14448
  this._pendingStagingBuffers.clear();
14409
14449
  }
14410
14450
  dispose() {
14411
- this.abort(), this._destroyPendingStagingBuffers(), this.unet?.dispose(), Xd(), this._destroyGPUInputBuffers(), this.output?.parentNode && this.output.remove(), this.unet = null, this.ctx = null, this.state.abortController = null, this.removeAllListeners?.(), console.log("OIDNDenoiser disposed");
14451
+ this.abort(), this._destroyPendingStagingBuffers(), this.unet?.dispose(), qd(), this._destroyGPUInputBuffers(), this.output?.parentNode && this.output.remove(), this.unet = null, this.ctx = null, this.state.abortController = null, this.removeAllListeners?.(), console.log("OIDNDenoiser disposed");
14412
14452
  }
14413
- }, ef = "" + new URL("assets/AIUpscalerWorker-AXN-lKWN.js", import.meta.url).href, tf = {
14453
+ }, Zd = "" + new URL("assets/AIUpscalerWorker-AXN-lKWN.js", import.meta.url).href, Qd = {
14414
14454
  fast: {
14415
14455
  2: "2x-spanx2-ch48.onnx",
14416
14456
  4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
@@ -14424,17 +14464,17 @@ var Zd = new Float32Array(3), Qd = {
14424
14464
  4: "4xNomos2_hq_mosr_fp32.onnx"
14425
14465
  }
14426
14466
  };
14427
- function nf() {
14467
+ function $d() {
14428
14468
  let { upscalerModelBaseUrl: e } = Cs(), t = {};
14429
- for (let n in tf) {
14469
+ for (let n in Qd) {
14430
14470
  t[n] = {};
14431
- for (let r in tf[n]) t[n][r] = e + tf[n][r];
14471
+ for (let r in Qd[n]) t[n][r] = e + Qd[n][r];
14432
14472
  }
14433
14473
  return t;
14434
14474
  }
14435
- var rf = {
14475
+ var ef = {
14436
14476
  get QUALITY_PRESETS() {
14437
- return nf();
14477
+ return $d();
14438
14478
  },
14439
14479
  TILE_SIZE: 512,
14440
14480
  TILE_OVERLAP: 16,
@@ -14445,17 +14485,17 @@ var rf = {
14445
14485
  }],
14446
14486
  graphOptimizationLevel: "all"
14447
14487
  }
14448
- }, af = class extends ot {
14488
+ }, tf = class extends ot {
14449
14489
  constructor(e, t, n = {}) {
14450
14490
  if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
14451
- 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 || (() => Be), this.getSaturation = n.getSaturation || (() => 1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.tileSize = n.tileSize || rf.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
14491
+ 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 || (() => Be), this.getSaturation = n.getSaturation || (() => 1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.tileSize = n.tileSize || ef.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
14452
14492
  isUpscaling: !1,
14453
14493
  isLoading: !1,
14454
14494
  abortController: null
14455
14495
  }, this._worker = null, this._currentModelUrl = null, this._tileId = 0, this._pendingWorkerHandlers = /* @__PURE__ */ new Set(), this._upscaledAlpha = null, this._upscaledAlphaWidth = 0, this._backupCanvas = null, this._baseWidth = e.width, this._baseHeight = e.height, this._hdrStagingBuffer = null, this._hdrStagingWidth = 0, this._hdrStagingHeight = 0;
14456
14496
  }
14457
14497
  async _ensureSession() {
14458
- let e = rf.QUALITY_PRESETS[this.quality];
14498
+ let e = ef.QUALITY_PRESETS[this.quality];
14459
14499
  if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
14460
14500
  let t = e[this.scaleFactor];
14461
14501
  if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
@@ -14466,10 +14506,10 @@ var rf = {
14466
14506
  });
14467
14507
  try {
14468
14508
  if (!this._worker) try {
14469
- this._worker = new Worker(ef, { type: "module" });
14509
+ this._worker = new Worker(Zd, { type: "module" });
14470
14510
  } catch (e) {
14471
14511
  if (e.name !== "SecurityError") throw e;
14472
- this._worker = await Nr(ef);
14512
+ this._worker = await Nr(Zd);
14473
14513
  }
14474
14514
  await new Promise((e, n) => {
14475
14515
  let r = (t) => {
@@ -14478,7 +14518,7 @@ var rf = {
14478
14518
  this._worker.addEventListener("message", r), this._worker.postMessage({
14479
14519
  type: "load",
14480
14520
  url: t,
14481
- sessionOptions: rf.SESSION_OPTIONS,
14521
+ sessionOptions: ef.SESSION_OPTIONS,
14482
14522
  ortRuntimeUrl: i,
14483
14523
  ortWasmPaths: a,
14484
14524
  cacheNamespace: o
@@ -14548,8 +14588,8 @@ var rf = {
14548
14588
  willReadFrequently: !0,
14549
14589
  alpha: !0
14550
14590
  });
14551
- this._cacheUpscaledAlpha(t, n * i, r * i), t.isHDR && (this._hdrToneMapFn = Bd.get(this.getToneMapping()) || Bd.get(Be), this._hdrExposure = this.getExposure(), this._hdrSaturation = this.getSaturation(), this._tmOut = new Float32Array(3));
14552
- let o = rf.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
14591
+ this._cacheUpscaledAlpha(t, n * i, r * i), t.isHDR && (this._hdrToneMapFn = Ld.get(this.getToneMapping()) || Ld.get(Be), this._hdrExposure = this.getExposure(), this._hdrSaturation = this.getSaturation(), this._tmOut = new Float32Array(3));
14592
+ let o = ef.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
14553
14593
  for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
14554
14594
  if (e.aborted) throw new DOMException("Aborted", "AbortError");
14555
14595
  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);
@@ -14622,7 +14662,7 @@ var rf = {
14622
14662
  let u = ((n + e) * o + (t + i)) * 4, d = e * r + i;
14623
14663
  if (s) {
14624
14664
  let e = this._hdrToneMapFn, t = this._hdrExposure, n = this._hdrSaturation, r = a[u] * t, i = a[u + 1] * t, o = a[u + 2] * t;
14625
- n !== 1 && (this._tmOut[0] = r, this._tmOut[1] = i, this._tmOut[2] = o, Kd(this._tmOut, n), r = this._tmOut[0], i = this._tmOut[1], o = this._tmOut[2]), e(r, i, o, 1, this._tmOut), l[d] = this._tmOut[0] ** +Vd, l[c + d] = this._tmOut[1] ** +Vd, l[2 * c + d] = this._tmOut[2] ** +Vd;
14665
+ n !== 1 && (this._tmOut[0] = r, this._tmOut[1] = i, this._tmOut[2] = o, Ud(this._tmOut, n), r = this._tmOut[0], i = this._tmOut[1], o = this._tmOut[2]), e(r, i, o, 1, this._tmOut), l[d] = this._tmOut[0] ** +Rd, l[c + d] = this._tmOut[1] ** +Rd, l[2 * c + d] = this._tmOut[2] ** +Rd;
14626
14666
  } else l[d] = a[u] / 255, l[c + d] = a[u + 1] / 255, l[2 * c + d] = a[u + 2] / 255;
14627
14667
  }
14628
14668
  return l;
@@ -14680,10 +14720,10 @@ var rf = {
14680
14720
  this._backupCanvas = document.createElement("canvas"), this._backupCanvas.width = e.width, this._backupCanvas.height = e.height;
14681
14721
  let t = this._backupCanvas.getContext("2d");
14682
14722
  if (e.isHDR) {
14683
- let { data: n, width: r, height: i } = e, a = t.createImageData(r, i), o = a.data, s = Bd.get(this.getToneMapping()) || Bd.get(Be), c = this.getExposure(), l = this.getSaturation(), u = new Float32Array(3);
14723
+ let { data: n, width: r, height: i } = e, a = t.createImageData(r, i), o = a.data, s = Ld.get(this.getToneMapping()) || Ld.get(Be), c = this.getExposure(), l = this.getSaturation(), u = new Float32Array(3);
14684
14724
  for (let e = 0, t = r * i; e < t; e++) {
14685
14725
  let t = e * 4, r = n[t] * c, i = n[t + 1] * c, a = n[t + 2] * c;
14686
- l !== 1 && (u[0] = r, u[1] = i, u[2] = a, Kd(u, l), r = u[0], i = u[1], a = u[2]), s(r, i, a, 1, u), o[t] = u[0] ** +Vd * 255 + .5 | 0, o[t + 1] = u[1] ** +Vd * 255 + .5 | 0, o[t + 2] = u[2] ** +Vd * 255 + .5 | 0, o[t + 3] = 255;
14726
+ l !== 1 && (u[0] = r, u[1] = i, u[2] = a, Ud(u, l), r = u[0], i = u[1], a = u[2]), s(r, i, a, 1, u), o[t] = u[0] ** +Rd * 255 + .5 | 0, o[t + 1] = u[1] ** +Rd * 255 + .5 | 0, o[t + 2] = u[2] ** +Rd * 255 + .5 | 0, o[t + 3] = 255;
14687
14727
  }
14688
14728
  t.putImageData(a, 0, 0);
14689
14729
  } else t.putImageData(e, 0, 0);
@@ -14695,7 +14735,7 @@ var rf = {
14695
14735
  this.hdr = !!e;
14696
14736
  }
14697
14737
  setQuality(e) {
14698
- if (!rf.QUALITY_PRESETS[e]) {
14738
+ if (!ef.QUALITY_PRESETS[e]) {
14699
14739
  console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
14700
14740
  return;
14701
14741
  }
@@ -14718,7 +14758,7 @@ var rf = {
14718
14758
  async dispose() {
14719
14759
  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._hdrStagingBuffer?.destroy(), this._hdrStagingBuffer = null, this._hdrStagingWidth = 0, this._hdrStagingHeight = 0, console.log("AIUpscaler disposed");
14720
14760
  }
14721
- }, of = class extends ot {
14761
+ }, nf = class extends ot {
14722
14762
  constructor({ renderer: e, mainCanvas: t, scene: n, camera: r, stages: i, pipeline: a, getExposure: o, getSaturation: s, getTransparentBg: c }) {
14723
14763
  super(), this.renderer = e, this.mainCanvas = t, this.denoiserCanvas = this._createDenoiserCanvas(t), this.scene = n, this.camera = r, this.pipeline = a, this._stages = i, this._getExposure = o, this._getSaturation = s, this._getTransparentBg = c, this.denoiser = null, this.upscaler = null, this._lastRenderWidth = 0, this._lastRenderHeight = 0, this._pendingStartUpscaler = null, this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null;
14724
14764
  }
@@ -14739,7 +14779,7 @@ var rf = {
14739
14779
  setupDenoiser() {
14740
14780
  if (!this.denoiserCanvas) return;
14741
14781
  let e = this._stages.pathTracer;
14742
- this.denoiser = new $d(this.denoiserCanvas, this.renderer, this.scene, this.camera, {
14782
+ this.denoiser = new Xd(this.denoiserCanvas, this.renderer, this.scene, this.camera, {
14743
14783
  ...X,
14744
14784
  backendParams: () => ({
14745
14785
  device: this.renderer.backend.device,
@@ -14764,7 +14804,7 @@ var rf = {
14764
14804
  setupUpscaler() {
14765
14805
  if (!this.denoiserCanvas) return;
14766
14806
  let e = this._stages.pathTracer;
14767
- this.upscaler = new af(this.denoiserCanvas, this.renderer, {
14807
+ this.upscaler = new tf(this.denoiserCanvas, this.renderer, {
14768
14808
  scaleFactor: X.upscalerScale || 2,
14769
14809
  quality: X.upscalerQuality || "fast",
14770
14810
  getSourceCanvas: () => this.denoiser?.enabled ? null : this.renderer.domElement,
@@ -14814,6 +14854,15 @@ var rf = {
14814
14854
  _syncGBufferStages() {
14815
14855
  let e = this._stages, t = e.normalDepth, n = e.motionVector, r = !!(e.asvgf?.enabled || e.ssrc?.enabled), i = r || !!(e.edgeFilter?.enabled || e.bilateralFilter?.enabled);
14816
14856
  t && (i && !t.enabled && t.reset(), t.enabled = i), n && (r && !n.enabled && (n.matricesInitialized = !1, n.isFirstFrame = !0, n.frameCount = 0), n.enabled = r), e.pathTracer?.setAuxGBufferEnabled?.(i || !!this.denoiser?.enabled);
14857
+ for (let r of [
14858
+ e.asvgf,
14859
+ e.variance,
14860
+ e.bilateralFilter,
14861
+ e.ssrc,
14862
+ e.edgeFilter,
14863
+ t,
14864
+ n
14865
+ ]) r && !r.enabled && r.releaseGPUMemory?.();
14817
14866
  }
14818
14867
  _cleanupCompletionListener() {
14819
14868
  this._pendingStartUpscaler && this.denoiser && this.denoiser.removeEventListener("end", this._pendingStartUpscaler), this._pendingStartUpscaler = null;
@@ -14908,7 +14957,7 @@ var rf = {
14908
14957
  let t = dr[e];
14909
14958
  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));
14910
14959
  }
14911
- }, sf = class {
14960
+ }, rf = class {
14912
14961
  constructor() {
14913
14962
  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;
14914
14963
  }
@@ -14932,7 +14981,7 @@ var rf = {
14932
14981
  dispose() {
14933
14982
  this.visible = !1;
14934
14983
  }
14935
- }, cf = class {
14984
+ }, af = class {
14936
14985
  constructor(n, r, i) {
14937
14986
  this.layer = "scene", this.visible = !0, this._outlineNode = gn(r, i, {
14938
14987
  selectedObjects: [],
@@ -14966,7 +15015,7 @@ var rf = {
14966
15015
  dispose() {
14967
15016
  this.visible = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
14968
15017
  }
14969
- }, lf = class {
15018
+ }, of = class {
14970
15019
  constructor(e, t) {
14971
15020
  this.renderer = e, this.camera = t, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = document.createElement("canvas"), this._hudCanvas.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;", this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null;
14972
15021
  }
@@ -14981,11 +15030,11 @@ var rf = {
14981
15030
  }
14982
15031
  setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
14983
15032
  this.setHelperScene(e);
14984
- let s = new sf();
15033
+ let s = new rf();
14985
15034
  this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener("resolution_changed", (e) => {
14986
15035
  s.setRenderSize(e.width, e.height);
14987
15036
  }), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
14988
- let c = new cf(this.renderer, t, this.camera);
15037
+ let c = new af(this.renderer, t, this.camera);
14989
15038
  this.register("outline", c);
14990
15039
  }
14991
15040
  _wireDenoiserTileEvents(e, t) {
@@ -15052,7 +15101,7 @@ var rf = {
15052
15101
  for (let e of this._helpers.values()) e.dispose?.();
15053
15102
  this._helpers.clear(), this._hudCanvas.parentElement && this._hudCanvas.parentElement.removeChild(this._hudCanvas);
15054
15103
  }
15055
- }, uf = class extends ot {
15104
+ }, sf = class extends ot {
15056
15105
  constructor() {
15057
15106
  super(), this.mixer = null, this.timer = new Zt(), this.actions = [], this.isPlaying = !1, this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._posBuffer = null, this._tempVec = new nn(), this._skinnedCache = null, this._clipsCache = null, this._savedTimeScale = 1, this.onFinished = null, this.wakeCallback = null;
15058
15107
  }
@@ -15152,7 +15201,7 @@ var rf = {
15152
15201
  dispose() {
15153
15202
  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._posBuffer = null, this._skinnedCache = null, this._clipsCache = null;
15154
15203
  }
15155
- }, df = class {
15204
+ }, cf = class {
15156
15205
  constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
15157
15206
  this._app = r, this._orbitControls = n, this._camera = e, this._controls = new _n(e, t), this._gizmoScene = new Wt(), this._gizmoScene.add(this._controls.getHelper()), this._attached = null, this._isDragging = !1, this._meshes = null, this._meshTriRanges = null, this._posBuffer = null, this._normalBuffer = null, this._skinnedCache = null, this._normalCache = null, this._tempVec = new nn(), this._normalMatrix = new vt(), this._refitInFlight = !1, this._baselineComputed = !1, 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);
15158
15207
  }
@@ -15263,15 +15312,15 @@ var rf = {
15263
15312
  dispose() {
15264
15313
  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._meshTriRanges = null, this._posBuffer = null, this._normalBuffer = null, this._skinnedCache = null, this._normalCache = null, this._baselineComputed = !1, this._app = null, this._orbitControls = null, this._camera = null, this._controls = null, this._gizmoScene = null;
15265
15314
  }
15266
- }, ff = /* @__PURE__ */ new WeakMap(), pf = class extends ot {
15315
+ }, lf = /* @__PURE__ */ new WeakMap(), uf = class extends ot {
15267
15316
  constructor(e, t = {}) {
15268
15317
  super();
15269
15318
  try {
15270
- ff.get(e)?.dispose();
15319
+ lf.get(e)?.dispose();
15271
15320
  } catch (e) {
15272
15321
  console.warn("PathTracerApp: prior canvas owner dispose failed", e);
15273
15322
  }
15274
- ff.set(e, this), this.canvas = e, this._autoResize = t.autoResize !== !1, this._container = t.container || null, this.settings = new gd(X), this.renderer = null, this.scene = null, this.meshScene = null, this._sceneHelpers = null, this.assetLoader = null, this._sdf = null, this._animRefitInFlight = !1, this.pipeline = null, this.stages = {}, this.cameraManager = null, this.lightManager = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new uf(), this.environmentManager = null, this.isInitialized = !1, this.pauseRendering = !1, this.pathTracerEnabled = !0, this.animationManagerId = null, this.needsReset = !1, this._loadingInProgress = !1, this._needsDisplayRefresh = !1, this._paused = !1, this.completion = new ju(), this._resizeDebounceTimer = null, this._trackedListeners = [], this._disposed = !1;
15323
+ lf.set(e, this), this.canvas = e, this._autoResize = t.autoResize !== !1, this._container = t.container || null, this.settings = new pd(X), this.renderer = null, this.scene = null, this.meshScene = null, this._sceneHelpers = null, this.assetLoader = null, this._sdf = null, this._animRefitInFlight = !1, this.pipeline = null, this.stages = {}, this.cameraManager = null, this.lightManager = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new sf(), this.environmentManager = null, this.isInitialized = !1, this.pauseRendering = !1, this.pathTracerEnabled = !0, this.animationManagerId = null, this.needsReset = !1, this._loadingInProgress = !1, this._needsDisplayRefresh = !1, this._paused = !1, this.completion = new Ou(), this._resizeDebounceTimer = null, this._trackedListeners = [], this._disposed = !1;
15275
15324
  }
15276
15325
  _addTrackedListener(e, t, n) {
15277
15326
  e && (e.addEventListener(t, n), this._trackedListeners.push({
@@ -15598,32 +15647,32 @@ var rf = {
15598
15647
  }), await this.renderer.init(), r.setLTC(rn.init()), this.renderer.outputColorSpace = a, this.renderer.toneMapping = Be, this.renderer.toneMappingExposure = 1, this.renderer.setPixelRatio(1);
15599
15648
  }
15600
15649
  _initCameraManager() {
15601
- this.cameraManager = new _d(this.canvas);
15650
+ this.cameraManager = new md(this.canvas);
15602
15651
  }
15603
15652
  _initScenes() {
15604
15653
  this.scene = new Wt(), this.meshScene = new Wt(), this._sceneHelpers = new wn();
15605
15654
  }
15606
15655
  _initAssetPipeline() {
15607
- this._sdf = new ys(), this.assetLoader = new pd(this.meshScene, this.cameraManager.camera, this.cameraManager.controls), this.assetLoader.setRenderer(this.renderer), this.assetLoader.createFloorPlane(), this._addTrackedListener(this.cameraManager.controls, "change", () => {
15656
+ this._sdf = new ys(), this.assetLoader = new ud(this.meshScene, this.cameraManager.camera, this.cameraManager.controls), this.assetLoader.setRenderer(this.renderer), this.assetLoader.createFloorPlane(), this._addTrackedListener(this.cameraManager.controls, "change", () => {
15608
15657
  this.needsReset = !0, this.wake();
15609
15658
  });
15610
15659
  }
15611
15660
  _initPipeline() {
15612
15661
  this._createStages();
15613
15662
  let { clientWidth: e, clientHeight: t } = this.canvas;
15614
- this.pipeline = new Au(this.renderer, e || 1, t || 1), this.pipeline.addStage(this.stages.pathTracer), this.pipeline.addStage(this.stages.normalDepth), this.pipeline.addStage(this.stages.motionVector), this.pipeline.addStage(this.stages.ssrc), this.pipeline.addStage(this.stages.asvgf), this.pipeline.addStage(this.stages.variance), this.pipeline.addStage(this.stages.bilateralFilter), this.pipeline.addStage(this.stages.edgeFilter), this.pipeline.addStage(this.stages.autoExposure), this.pipeline.addStage(this.stages.compositor);
15663
+ this.pipeline = new Du(this.renderer, e || 1, t || 1), this.pipeline.addStage(this.stages.pathTracer), this.pipeline.addStage(this.stages.normalDepth), this.pipeline.addStage(this.stages.motionVector), this.pipeline.addStage(this.stages.ssrc), this.pipeline.addStage(this.stages.asvgf), this.pipeline.addStage(this.stages.variance), this.pipeline.addStage(this.stages.bilateralFilter), this.pipeline.addStage(this.stages.edgeFilter), this.pipeline.addStage(this.stages.autoExposure), this.pipeline.addStage(this.stages.compositor);
15615
15664
  let n = this.canvas.clientWidth || 1, r = this.canvas.clientHeight || 1;
15616
15665
  this.pipeline.setSize(n, r);
15617
15666
  }
15618
15667
  _initManagers() {
15619
- this.interactionManager = new Mu({
15668
+ this.interactionManager = new ku({
15620
15669
  scene: this.meshScene,
15621
15670
  camera: this.cameraManager.camera,
15622
15671
  canvas: this.canvas,
15623
15672
  assetLoader: this.assetLoader,
15624
15673
  pathTracer: null,
15625
15674
  floorPlane: this.assetLoader.floorPlane
15626
- }), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.lightManager = new vd(this.scene, this._sceneHelpers, this.stages.pathTracer, { onReset: () => this.reset() }), this.goboManager = new yd(this.stages.pathTracer, { onReset: () => this.reset() }), this.iesManager = new Ad(this.stages.pathTracer, { onReset: () => this.reset() }), this._setupDenoisingManager(), this._setupOverlayManager(), this.transformManager = new df({
15675
+ }), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.lightManager = new hd(this.scene, this._sceneHelpers, this.stages.pathTracer, { onReset: () => this.reset() }), this.goboManager = new gd(this.stages.pathTracer, { onReset: () => this.reset() }), this.iesManager = new Dd(this.stages.pathTracer, { onReset: () => this.reset() }), this._setupDenoisingManager(), this._setupOverlayManager(), this.transformManager = new cf({
15627
15676
  camera: this.cameraManager.camera,
15628
15677
  canvas: this.canvas,
15629
15678
  orbitControls: this.cameraManager.controls,
@@ -15693,10 +15742,10 @@ var rf = {
15693
15742
  this.transformManager?.setMeshData(this._sdf.meshes);
15694
15743
  }
15695
15744
  _createStages() {
15696
- this.stages.pathTracer = new au(this.renderer, this.scene, this.cameraManager.camera), this.stages.normalDepth = new ou(this.renderer, { pathTracer: this.stages.pathTracer }), this.stages.motionVector = new su(this.renderer, this.cameraManager.camera, { pathTracer: this.stages.pathTracer }), this.stages.ssrc = new Eu(this.renderer, { enabled: !1 }), this.stages.asvgf = new uu(this.renderer, { enabled: !1 }), this.stages.variance = new pu(this.renderer, { enabled: !1 }), this.stages.bilateralFilter = new hu(this.renderer, { enabled: !1 }), this.stages.edgeFilter = new gu(this.renderer, { enabled: !1 }), this.stages.autoExposure = new Cu(this.renderer, { enabled: X.autoExposure ?? !1 }), this.stages.compositor = new Du(this.renderer, { saturation: this.settings.get("saturation") ?? X.saturation });
15745
+ this.stages.pathTracer = new nu(this.renderer, this.scene, this.cameraManager.camera), this.stages.normalDepth = new ru(this.renderer, { pathTracer: this.stages.pathTracer }), this.stages.motionVector = new iu(this.renderer, this.cameraManager.camera, { pathTracer: this.stages.pathTracer }), this.stages.ssrc = new Cu(this.renderer, { enabled: !1 }), this.stages.asvgf = new su(this.renderer, { enabled: !1 }), this.stages.variance = new uu(this.renderer, { enabled: !1 }), this.stages.bilateralFilter = new fu(this.renderer, { enabled: !1 }), this.stages.edgeFilter = new pu(this.renderer, { enabled: !1 }), this.stages.autoExposure = new bu(this.renderer, { enabled: X.autoExposure ?? !1 }), this.stages.compositor = new wu(this.renderer, { saturation: this.settings.get("saturation") ?? X.saturation });
15697
15746
  }
15698
15747
  _setupDenoisingManager() {
15699
- this.denoisingManager = new of({
15748
+ this.denoisingManager = new nf({
15700
15749
  renderer: this.renderer,
15701
15750
  mainCanvas: this.canvas,
15702
15751
  scene: this.scene,
@@ -15740,7 +15789,7 @@ var rf = {
15740
15789
  this.scene.updateMatrixWorld(), this.overlayManager?.render(), this.transformManager?.render(this.renderer);
15741
15790
  }
15742
15791
  _setupOverlayManager() {
15743
- this.overlayManager = new lf(this.renderer, this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
15792
+ this.overlayManager = new of(this.renderer, this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
15744
15793
  helperScene: this._sceneHelpers,
15745
15794
  meshScene: this.meshScene,
15746
15795
  pipeline: this.pipeline,
@@ -15756,7 +15805,7 @@ var rf = {
15756
15805
  _forwardEvents(e, t) {
15757
15806
  if (e) for (let n of t) this._addTrackedListener(e, n, (e) => this.dispatchEvent(e));
15758
15807
  }
15759
- }, mf = class {
15808
+ }, df = class {
15760
15809
  constructor(e) {
15761
15810
  this._app = e, this._cancelled = !1, this._rendering = !1;
15762
15811
  }
@@ -15854,6 +15903,6 @@ var rf = {
15854
15903
  }
15855
15904
  };
15856
15905
  //#endregion
15857
- export { gr as AF_DEFAULTS, dr as ASVGF_QUALITY_PRESETS, hr as AUTO_FOCUS_MODES, uf as AnimationManager, _r as BVH_LEAF_MARKERS, mr as CAMERA_PRESETS, fr as CAMERA_RANGES, _d as CameraManager, yr as DEFAULT_TEXTURE_MATRIX, of as DenoisingManager, X as ENGINE_DEFAULTS, Yn as EngineEvents, yd as GoboManager, Ad as IESManager, xr as INTERACTIVE_RENDER_CONFIG, Mu as InteractionManager, vd as LightManager, Sr as MEMORY_CONSTANTS, lf as OverlayManager, br as PRODUCTION_RENDER_CONFIG, pf as PathTracerApp, Ou as PipelineContext, Au as RenderPipeline, gd as RenderSettings, qn as RenderStage, pr as SKY_PRESETS, Kn as StageExecutionMode, vr as TEXTURE_CONSTANTS, Z as TRIANGLE_DATA_LAYOUT, df as TransformManager, gc as VRAMTracker, mf as VideoRenderManager, mc as bufferBytes, Ss as configureAssets, Cs as getAssetConfig, hc as textureBytes };
15906
+ export { gr as AF_DEFAULTS, dr as ASVGF_QUALITY_PRESETS, hr as AUTO_FOCUS_MODES, sf as AnimationManager, _r as BVH_LEAF_MARKERS, mr as CAMERA_PRESETS, fr as CAMERA_RANGES, md as CameraManager, yr as DEFAULT_TEXTURE_MATRIX, nf as DenoisingManager, X as ENGINE_DEFAULTS, Yn as EngineEvents, gd as GoboManager, Dd as IESManager, xr as INTERACTIVE_RENDER_CONFIG, ku as InteractionManager, hd as LightManager, Sr as MEMORY_CONSTANTS, of as OverlayManager, br as PRODUCTION_RENDER_CONFIG, uf as PathTracerApp, Tu as PipelineContext, Du as RenderPipeline, pd as RenderSettings, qn as RenderStage, pr as SKY_PRESETS, Kn as StageExecutionMode, vr as TEXTURE_CONSTANTS, Z as TRIANGLE_DATA_LAYOUT, cf as TransformManager, mc as VRAMTracker, df as VideoRenderManager, fc as bufferBytes, Ss as configureAssets, Cs as getAssetConfig, pc as textureBytes };
15858
15907
 
15859
15908
  //# sourceMappingURL=rayzee.es.js.map