rayzee 11.8.0 → 11.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -6
- package/dist/{ArchiveImporter-_sJm5uaK.js → ArchiveImporter-BJxszU_k.js} +1549 -1232
- package/dist/{BidirectionalIntegrator-Dzt4Z97x.js → BidirectionalIntegrator-DWg66vAd.js} +240 -240
- package/dist/{BufferLayout-xPRH9jYD.js → BufferLayout-Bzgccg1o.js} +1 -0
- package/dist/{ColorManagement-30MfpHwQ.js → ColorManagement-B_HjAiy2.js} +1 -1
- package/dist/{EngineIssues-xljoXM0E.js → EngineIssues-CfJiBaNj.js} +1 -0
- package/dist/{NeuralRetouch-BKQCsmEs.js → NeuralRetouch-BD9E-Yht.js} +1 -1
- package/dist/{NeuralSuperRes-C4ymq68e.js → NeuralSuperRes-C8Mf3tJX.js} +1 -1
- package/dist/{PathTracer-C_to_i40.js → PathTracer-DeE9UJ1n.js} +3433 -3363
- package/dist/{PhysicalSky-bMHbm_7H.js → PhysicalSky-cKy75-oR.js} +45 -45
- package/dist/{RayzeeRenderer-B_aB6VTJ.js → RayzeeRenderer-CzLyBA3G.js} +13 -8
- package/dist/{SceneMetadata-CSmlJW4c.js → SceneMetadata-C17UfOEp.js} +1 -1
- package/dist/{SolarLimb-bZE6y63S.js → SolarLimb-DRYy8tln.js} +184 -172
- package/dist/addons/archives.es.js +1 -1
- package/dist/addons/bidirectional.es.js +1 -1
- package/dist/addons/color.es.js +1 -1
- package/dist/addons/physical-sky.es.js +1 -1
- package/dist/addons/storage.es.js +1 -1
- package/dist/{openStorage-B085D9FR.js → openStorage-CdyVjmps.js} +1 -1
- package/dist/rayzee-core.es.js +7 -7
- package/dist/rayzee.es.js +567 -559
- package/dist/rayzee.umd.js +106 -101
- package/dist/{sceneCachePolicy-D_uBSbQF.js → sceneCachePolicy-ywbGKHD3.js} +9 -6
- package/package.json +1 -1
- package/src/EngineDefaults.js +1 -0
- package/src/EngineIssues.js +1 -0
- package/src/Passes/OIDNTemporalHistory.js +1 -1
- package/src/Processor/ArchiveImporter.js +83 -21
- package/src/Processor/AssetLoader.js +7 -0
- package/src/Processor/BufferLayout.js +3 -3
- package/src/Processor/GeometryExtractor.js +12 -4
- package/src/Processor/MaterialPacking.js +2 -2
- package/src/Processor/PBRT/PBRTMaterials.js +47 -12
- package/src/Processor/PBRT/PBRTParser.js +144 -22
- package/src/Processor/PBRT/PBRTSceneBuilder.js +287 -67
- package/src/Processor/PBRT/PBRTTextureBake.js +191 -9
- package/src/Processor/PBRT/index.js +19 -4
- package/src/Processor/SceneProcessor.js +42 -26
- package/src/RayzeeRenderer.js +4 -2
- package/src/Stages/DenoiserSettings.js +0 -4
- package/src/Stages/NRD.js +53 -24
- package/src/Stages/NormalDepth.js +5 -3
- package/src/Stages/PathTracer.js +2 -0
- package/src/Stages/PathTracerStage.js +5 -1
- package/src/Storage/SceneGraphCodec.js +6 -3
- package/src/TSL/BVHTraversal.js +33 -20
- package/src/TSL/Common.js +25 -8
- package/src/TSL/Displacement.js +66 -113
- package/src/TSL/LightsDirect.js +33 -11
- package/src/TSL/SceneResources.js +8 -0
- package/src/TSL/ShadeKernel.js +2 -2
- package/src/TSL/Struct.js +1 -0
- package/src/managers/MaterialDataManager.js +11 -0
package/dist/rayzee.es.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { t as e } from "./BidirectionalIntegrator-
|
|
2
|
-
import {
|
|
3
|
-
import { _ as l, a as u, c as d, d as f, f as p, g as m, h, i as g, l as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, u as T } from "./RayzeeRenderer-
|
|
4
|
-
import { $ as E, At as D, B as
|
|
1
|
+
import { t as e } from "./BidirectionalIntegrator-DWg66vAd.js";
|
|
2
|
+
import { Ft as t, Pt as n, Xt as r, en as i, rn as a, rt as o, tn as s, wt as c } from "./SolarLimb-DRYy8tln.js";
|
|
3
|
+
import { _ as l, a as u, c as d, d as f, f as p, g as m, h, i as g, l as _, m as v, n as y, o as b, p as x, r as S, s as C, t as w, u as T } from "./RayzeeRenderer-CzLyBA3G.js";
|
|
4
|
+
import { $ as E, At as D, B as O, F as k, H as ee, I as te, J as ne, Mt as A, Nt as j, Ot as re, Q as M, V as ie, W as ae, _t as oe, at as se, bt as ce, dt as le, et as N, gt as ue, ht as de, it as fe, kt as pe, mt as me, nt as he, pt as ge, rt as _e, tt as ve, xt as ye, yt as be, z as xe } from "./PathTracer-DeE9UJ1n.js";
|
|
5
5
|
import { n as Se, t as P } from "./EngineEvents-CLckhYbL.js";
|
|
6
|
-
import { D as Ce, G as we, J as Te, K as Ee, O as De, W as Oe, Y as ke, a as Ae, c as je, et as Me, i as Ne, m as Pe, ot as Fe, p as Ie, q as Le, r as Re, tt as ze, x as Be, y as Ve } from "./sceneCachePolicy-
|
|
6
|
+
import { D as Ce, G as we, J as Te, K as Ee, O as De, W as Oe, Y as ke, a as Ae, c as je, et as Me, i as Ne, m as Pe, ot as Fe, p as Ie, q as Le, r as Re, tt as ze, x as Be, y as Ve } from "./sceneCachePolicy-ywbGKHD3.js";
|
|
7
7
|
import { i as He, n as Ue, r as We, t as Ge } from "./Logger-dDDGj9Av.js";
|
|
8
|
-
import { f as Ke, r as qe } from "./BufferLayout-
|
|
9
|
-
import { i as Je, n as Ye, r as Xe, t as Ze } from "./EngineIssues-
|
|
8
|
+
import { f as Ke, r as qe } from "./BufferLayout-Bzgccg1o.js";
|
|
9
|
+
import { i as Je, n as Ye, r as Xe, t as Ze } from "./EngineIssues-CfJiBaNj.js";
|
|
10
10
|
import { i as Qe, r as $e } from "./shared-BGBcSxBQ.js";
|
|
11
11
|
import { r as et } from "./WorkingMatrix-C6y233hT.js";
|
|
12
12
|
import { i as tt, r as nt, t as rt } from "./ActiveColor-YvuQq44O.js";
|
|
13
13
|
import { n as it, t as at } from "./AssetConfig-DSEntE65.js";
|
|
14
14
|
import { a as ot, d as st, g as ct, i as lt, l as ut, o as dt, p as ft, r as pt, s as mt, t as ht, u as gt } from "./ViewTransforms-CYN7bq2w.js";
|
|
15
15
|
import { a as _t, i as vt, n as yt, r as bt } from "./identity-C1cLD1C0.js";
|
|
16
|
-
import { l as xt, n as St, s as Ct, t as wt } from "./SceneMetadata-
|
|
16
|
+
import { l as xt, n as St, s as Ct, t as wt } from "./SceneMetadata-C17UfOEp.js";
|
|
17
17
|
import { t as Tt } from "./ToneMapGPU-4GPwoG_c.js";
|
|
18
18
|
import { t as Et } from "./FileFormats-sPGJeCRc.js";
|
|
19
|
-
import { A as Dt, C as Ot, D as kt, E as At, O as jt, S as Mt, T as Nt, _ as Pt, a as Ft, b as It, c as Lt, d as Rt, f as zt, g as Bt, h as Vt, i as Ht, k as Ut, l as Wt, m as Gt, n as Kt, o as qt, p as Jt, r as Yt, s as Xt, t as Zt, u as Qt, v as $t, w as en, x as tn, y as nn } from "./ColorManagement-
|
|
20
|
-
import { c as rn, l as an, n as on, o as sn, t as cn } from "./openStorage-
|
|
19
|
+
import { A as Dt, C as Ot, D as kt, E as At, O as jt, S as Mt, T as Nt, _ as Pt, a as Ft, b as It, c as Lt, d as Rt, f as zt, g as Bt, h as Vt, i as Ht, k as Ut, l as Wt, m as Gt, n as Kt, o as qt, p as Jt, r as Yt, s as Xt, t as Zt, u as Qt, v as $t, w as en, x as tn, y as nn } from "./ColorManagement-B_HjAiy2.js";
|
|
20
|
+
import { c as rn, l as an, n as on, o as sn, t as cn } from "./openStorage-CdyVjmps.js";
|
|
21
21
|
import { n as ln, t as un } from "./ZipReader-gDSWr0I5.js";
|
|
22
|
-
import { i as dn, n as fn, r as pn } from "./NeuralSuperRes-
|
|
23
|
-
import { i as mn, n as hn, r as gn } from "./NeuralRetouch-
|
|
22
|
+
import { i as dn, n as fn, r as pn } from "./NeuralSuperRes-C8Mf3tJX.js";
|
|
23
|
+
import { i as mn, n as hn, r as gn } from "./NeuralRetouch-BD9E-Yht.js";
|
|
24
24
|
import { ExternalTexture as _n, MeshBasicNodeMaterial as vn, QuadMesh as yn, ReadbackBuffer as bn, RenderTarget as xn, StorageTexture as Sn, TextureNode as Cn, WebGPURenderer as wn } from "three/webgpu";
|
|
25
25
|
import { Fn as Tn, If as F, Loop as En, Return as Dn, atan as On, atomicAdd as kn, atomicLoad as An, atomicStore as jn, attributeArray as Mn, dot as I, exp as Nn, exp2 as Pn, float as L, floatBitsToUint as Fn, floor as In, fract as Ln, int as R, ivec2 as Rn, localId as z, log2 as zn, max as B, min as Bn, mix as V, normalize as Vn, pow as Hn, round as Un, saturate as H, select as U, smoothstep as Wn, sqrt as Gn, storage as Kn, textureLoad as W, textureStore as G, toneMappingExposure as qn, uint as K, uniform as q, uvec2 as Jn, uvec4 as Yn, vec2 as J, vec3 as Xn, vec4 as Y, workgroupArray as Zn, workgroupBarrier as Qn, workgroupId as X } from "three/tsl";
|
|
26
26
|
import { ACESFilmicToneMapping as $n, AddEquation as er, AnimationMixer as tr, Box2 as nr, Box3 as rr, ClampToEdgeWrapping as ir, Color as ar, Controls as or, CustomBlending as sr, DataArrayTexture as cr, DataTexture as lr, EventDispatcher as ur, FloatType as dr, HalfFloatType as fr, InterpolateSmooth as pr, LinearFilter as mr, LoopOnce as hr, LoopRepeat as gr, MathUtils as _r, Matrix3 as vr, Matrix4 as yr, Mesh as br, MeshBasicMaterial as xr, NearestFilter as Z, NoColorSpace as Sr, NumberKeyframeTrack as Cr, OneFactor as wr, OrthographicCamera as Tr, PerspectiveCamera as Er, PropertyBinding as Dr, Quaternion as Or, RGBAFormat as kr, Raycaster as Ar, RedIntegerFormat as jr, SRGBColorSpace as Mr, Scene as Nr, SphereGeometry as Pr, Timer as Fr, UnsignedByteType as Ir, UnsignedIntType as Lr, Vector2 as Rr, Vector3 as Q, Vector4 as zr, VectorKeyframeTrack as Br } from "three";
|
|
@@ -28,11 +28,11 @@ import { OrbitControls as Vr } from "three/addons/controls/OrbitControls.js";
|
|
|
28
28
|
import { outline as Hr } from "three/addons/tsl/display/OutlineNode.js";
|
|
29
29
|
import { TransformControls as Ur } from "three/addons/controls/TransformControls.js";
|
|
30
30
|
//#region src/Stages/DenoiserSettings.js
|
|
31
|
-
var Wr = 65504, Gr = 6e4, Kr =
|
|
31
|
+
var Wr = 65504, Gr = 6e4, Kr = Object.freeze([
|
|
32
32
|
"none",
|
|
33
33
|
"nrd",
|
|
34
34
|
"oidn"
|
|
35
|
-
]),
|
|
35
|
+
]), qr = 3, Jr = .1, Yr = {
|
|
36
36
|
maxAccumulatedFrameNum: 30,
|
|
37
37
|
maxFastAccumulatedFrameNum: 6,
|
|
38
38
|
maxStabilizedFrameNum: 63,
|
|
@@ -56,7 +56,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
56
56
|
convergenceP: .8,
|
|
57
57
|
lobeVolumePercent: .1,
|
|
58
58
|
handoverFrames: 0
|
|
59
|
-
},
|
|
59
|
+
}, Xr = [
|
|
60
60
|
"maxAccumulatedFrameNum",
|
|
61
61
|
"maxFastAccumulatedFrameNum",
|
|
62
62
|
"maxStabilizedFrameNum",
|
|
@@ -64,7 +64,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
64
64
|
"prepassBlurRadius",
|
|
65
65
|
"maxBlurRadius",
|
|
66
66
|
"enableAntiFirefly"
|
|
67
|
-
],
|
|
67
|
+
], Zr = {
|
|
68
68
|
low: {
|
|
69
69
|
maxAccumulatedFrameNum: 16,
|
|
70
70
|
maxFastAccumulatedFrameNum: 4,
|
|
@@ -82,7 +82,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
82
82
|
prepassBlurRadius: 40,
|
|
83
83
|
maxBlurRadius: 40
|
|
84
84
|
}
|
|
85
|
-
},
|
|
85
|
+
}, Qr = {
|
|
86
86
|
denoiserStrategy: "none",
|
|
87
87
|
enableOIDN: !1,
|
|
88
88
|
oidnQuality: "fast",
|
|
@@ -95,14 +95,14 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
95
95
|
upscalerHdr: !0,
|
|
96
96
|
nrdQualityPreset: "medium",
|
|
97
97
|
nrdDebugMode: 0
|
|
98
|
-
},
|
|
98
|
+
}, $r = class extends A {
|
|
99
99
|
constructor(e, t = {}) {
|
|
100
100
|
super("NormalDepth", {
|
|
101
101
|
...t,
|
|
102
|
-
executionMode:
|
|
102
|
+
executionMode: j.ALWAYS
|
|
103
103
|
}), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = q(new yr(), "mat4"), this.cameraProjectionMatrixInverse = q(new yr(), "mat4"), this.cameraRay = ve(), this.resolutionWidth = q(t.width || 1), this.resolutionHeight = q(t.height || 1);
|
|
104
104
|
let n = t.width || 1, r = t.height || 1;
|
|
105
|
-
this._outputStorageTex = new Sn(
|
|
105
|
+
this._outputStorageTex = new Sn(pe, pe), this._outputStorageTex.type = fr, this._outputStorageTex.format = kr, this._outputStorageTex.minFilter = Z, this._outputStorageTex.magFilter = Z, this._shadingStorageTex = new Sn(pe, pe), this._shadingStorageTex.type = fr, this._shadingStorageTex.format = kr, this._shadingStorageTex.minFilter = Z, this._shadingStorageTex.magFilter = Z, this._shadingRT = new xn(n, r, {
|
|
106
106
|
type: fr,
|
|
107
107
|
format: kr,
|
|
108
108
|
minFilter: Z,
|
|
@@ -135,40 +135,42 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
135
135
|
let t = e.sceneStorageNodes?.();
|
|
136
136
|
t && (this._triStorageNode = t.triangles, this._bvhStorageNode = t.bvh);
|
|
137
137
|
}
|
|
138
|
-
return t && !this._matStorageNode && (this._matStorageNode = Kn(t, "vec4", t.count).toReadOnly()), this._linearBuckets &&
|
|
138
|
+
return t && !this._matStorageNode && (this._matStorageNode = Kn(t, "vec4", t.count).toReadOnly()), this._linearBuckets && ee(this._linearBuckets, e.materialData?.linearBuckets), this._lastTriAttr = e.triangleGeoAttr || this._lastTriAttr, this._lastBvhAttr = e.bvhStorageAttr || this._lastBvhAttr, this._lastMatAttr = t || this._lastMatAttr, !!(this._triStorageNode && this._bvhStorageNode && this._matStorageNode);
|
|
139
139
|
}
|
|
140
140
|
_buildCompute() {
|
|
141
|
-
let e = this._triStorageNode,
|
|
142
|
-
this._linearBuckets =
|
|
143
|
-
let
|
|
144
|
-
srgbBuckets:
|
|
141
|
+
let e = this._triStorageNode, t = this._bvhStorageNode, n = this._matStorageNode;
|
|
142
|
+
this._linearBuckets = k(this.pathTracer?.materialData?.linearBuckets);
|
|
143
|
+
let o = {
|
|
144
|
+
srgbBuckets: k(null),
|
|
145
145
|
linearBuckets: this._linearBuckets,
|
|
146
146
|
shadowAlbedoMaps: null,
|
|
147
147
|
goboMaps: null,
|
|
148
148
|
iesProfiles: null,
|
|
149
149
|
alphaShadows: null
|
|
150
150
|
}, l = this.cameraWorldMatrix, u = this.cameraProjectionMatrixInverse, d = this.resolutionWidth, f = this.resolutionHeight, p = this._outputStorageTex, m = this._shadingStorageTex, h = this._leafStorageTex;
|
|
151
|
-
this._computeNode = be(Tn(([
|
|
151
|
+
this._computeNode = be(Tn(([o, l]) => {
|
|
152
152
|
let u = R(X.x).mul(8).add(R(z.x)), g = R(X.y).mul(8).add(R(z.y));
|
|
153
153
|
F(u.lessThan(R(d)).and(g.lessThan(R(f))), () => {
|
|
154
|
-
let _ = E(J(L(u).add(.5).div(d), L(g).add(.5).div(f)),
|
|
154
|
+
let _ = E(J(L(u).add(.5).div(d), L(g).add(.5).div(f)), o, l, this.cameraRay), v = _.direction.toVar(), y = M(v, this.cameraRay.clipStart, o, this.cameraRay.cameraProjection).toVar(), b = i({
|
|
155
155
|
origin: _.origin.add(v.mul(y)),
|
|
156
156
|
direction: v
|
|
157
|
-
}), x =
|
|
157
|
+
}), x = r.wrap(ne(b, t, e)), S = x.normal.mul(.5).add(.5), C = Bn(x.dst.add(y), L(65504)), w = x.didHit.select(Y(S, C), Y(0, 0, 0, L(Wr)));
|
|
158
158
|
G(p, Jn(K(u), K(g)), w).toWriteOnly(), h && G(h, Jn(K(u), K(g)), Yn(K(x.instanceLeaf.add(1)), 0, 0, 0)).toWriteOnly();
|
|
159
159
|
let T = x.normal.toVar(), D = L(1).toVar();
|
|
160
160
|
F(x.didHit, () => {
|
|
161
|
-
let
|
|
162
|
-
F(
|
|
163
|
-
|
|
161
|
+
let r = s.wrap(c(x.materialIndex, n)).toVar(), i = a.wrap(te(x.uv, r)).toVar(), o = Y(0).toVar();
|
|
162
|
+
F(r.normalMapIndex.greaterThanEqual(R(0)), () => {
|
|
163
|
+
o.assign(ae(e, x.triangleIndex, x.normal, r.normalTransform, t, x.instanceLeaf));
|
|
164
164
|
});
|
|
165
|
-
let l =
|
|
166
|
-
T.assign(xe(l,
|
|
165
|
+
let l = ie(x.normal, r, i, o).toVar();
|
|
166
|
+
T.assign(xe(l, r, i)), D.assign(O(r, i).y.clamp(.05, 1));
|
|
167
|
+
let u = B(r.emissive.x, B(r.emissive.y, r.emissive.z)).mul(r.emissiveIntensity).greaterThan(0);
|
|
168
|
+
D.assign(U(u, D.negate(), D));
|
|
167
169
|
});
|
|
168
|
-
let
|
|
169
|
-
G(m, Jn(K(u), K(g)),
|
|
170
|
+
let k = x.didHit.select(Y(T.mul(.5).add(.5), D), Y(0, 0, 0, 1));
|
|
171
|
+
G(m, Jn(K(u), K(g)), k).toWriteOnly();
|
|
170
172
|
});
|
|
171
|
-
})(l, u),
|
|
173
|
+
})(l, u), o).compute([
|
|
172
174
|
this._dispatchX,
|
|
173
175
|
this._dispatchY,
|
|
174
176
|
1
|
|
@@ -212,7 +214,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
212
214
|
reallocateReservedStorage() {
|
|
213
215
|
this._computeNode?.dispose(), this._computeNode = null, this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose();
|
|
214
216
|
let e = () => {
|
|
215
|
-
let e = new Sn(
|
|
217
|
+
let e = new Sn(pe, pe);
|
|
216
218
|
return e.type = fr, e.format = kr, e.minFilter = Z, e.magFilter = Z, e;
|
|
217
219
|
};
|
|
218
220
|
this._outputStorageTex = e(), this._shadingStorageTex = e(), this._leafStorageTex &&= (this._leafStorageTex.dispose(), this._makeLeafStorage()), this._computeBuilt = !1;
|
|
@@ -231,20 +233,20 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
231
233
|
this._leafRT ? e.setTexture("pathtracer:instanceLeaf", this._leafRT.texture) : e.getTexture("pathtracer:instanceLeaf") && e.removeTexture("pathtracer:instanceLeaf");
|
|
232
234
|
}
|
|
233
235
|
_makeLeafStorage() {
|
|
234
|
-
let e = new Sn(
|
|
236
|
+
let e = new Sn(pe, pe);
|
|
235
237
|
return e.type = Lr, e.format = jr, e.minFilter = Z, e.magFilter = Z, e;
|
|
236
238
|
}
|
|
237
239
|
dispose() {
|
|
238
240
|
this._computeNode?.dispose(), this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose(), this._shadingRT?.dispose(), this._leafStorageTex?.dispose(), this._leafRT?.dispose(), this._rtA?.dispose(), this._rtB?.dispose();
|
|
239
241
|
}
|
|
240
|
-
},
|
|
242
|
+
}, ei = class extends A {
|
|
241
243
|
constructor(e, t, n = {}) {
|
|
242
244
|
super("MotionVector", {
|
|
243
245
|
...n,
|
|
244
|
-
executionMode:
|
|
246
|
+
executionMode: j.ALWAYS
|
|
245
247
|
}), this.renderer = e, this.camera = t, this.pathTracer = n.pathTracer || null;
|
|
246
248
|
let r = n.width || 1, i = n.height || 1;
|
|
247
|
-
this.prevViewProjectionMatrix = new yr(), this.currentViewProjectionMatrix = new yr(), this.matricesInitialized = !1, this.cameraWorldMatrix = q(new yr(), "mat4"), this.cameraProjectionMatrixInverse = q(new yr(), "mat4"), this.cameraRay = ve(), this.prevVP = q(new yr(), "mat4"), this.resolutionWidth = q(r), this.resolutionHeight = q(i), this._normalDepthTexNode = new Cn(), this._screenSpaceStorageTex = new Sn(
|
|
249
|
+
this.prevViewProjectionMatrix = new yr(), this.currentViewProjectionMatrix = new yr(), this.matricesInitialized = !1, this.cameraWorldMatrix = q(new yr(), "mat4"), this.cameraProjectionMatrixInverse = q(new yr(), "mat4"), this.cameraRay = ve(), this.prevVP = q(new yr(), "mat4"), this.resolutionWidth = q(r), this.resolutionHeight = q(i), this._normalDepthTexNode = new Cn(), this._screenSpaceStorageTex = new Sn(pe, pe), this._screenSpaceStorageTex.type = fr, this._screenSpaceStorageTex.format = kr, this._screenSpaceStorageTex.minFilter = Z, this._screenSpaceStorageTex.magFilter = Z, this._srcRegion = new nr(new Rr(0, 0), new Rr(0, 0)), this.screenSpaceTarget = new xn(r, i, {
|
|
248
250
|
type: fr,
|
|
249
251
|
format: kr,
|
|
250
252
|
minFilter: Z,
|
|
@@ -260,7 +262,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
260
262
|
F(s.lessThan(R(i)).and(c.lessThan(R(a))), () => {
|
|
261
263
|
let l = W(e, Rn(s, c)).w, u = J(L(s).add(.5).div(i), L(c).add(.5).div(a)), d = Y(0, 0, l, 1).toVar();
|
|
262
264
|
F(l.lessThan(L(6e4)), () => {
|
|
263
|
-
let e =
|
|
265
|
+
let e = N(u, l, t, n, this.cameraRay), i = r.mul(Y(e, 1)), a = i.xy.div(i.w), o = J(a.x.mul(.5).add(.5), a.y.mul(-.5).add(.5)), s = u.sub(o), c = o.x.greaterThanEqual(0).and(o.x.lessThanEqual(1)).and(o.y.greaterThanEqual(0)).and(o.y.lessThanEqual(1));
|
|
264
266
|
d.assign(c.select(Y(s, l, 1), Y(L(1e3), L(1e3), l, 0)));
|
|
265
267
|
}), G(o, Jn(K(s), K(c)), d).toWriteOnly();
|
|
266
268
|
});
|
|
@@ -304,13 +306,13 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
304
306
|
}
|
|
305
307
|
reallocateReservedStorage() {
|
|
306
308
|
this._screenSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose();
|
|
307
|
-
let e = new Sn(
|
|
309
|
+
let e = new Sn(pe, pe);
|
|
308
310
|
e.type = fr, e.format = kr, e.minFilter = Z, e.magFilter = Z, this._screenSpaceStorageTex = e, this._buildScreenSpaceCompute();
|
|
309
311
|
}
|
|
310
312
|
dispose() {
|
|
311
313
|
this._screenSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this.screenSpaceTarget?.dispose(), this._normalDepthTexNode?.dispose();
|
|
312
314
|
}
|
|
313
|
-
},
|
|
315
|
+
}, ti = 1e-6, ni = 1.5 / 255, ri = .01, ii = 3, ai = 2, oi = 2, si = 3, ci = 2, li = 38, ui = .1, di = 4, fi = Math.cos(89 * Math.PI / 180), pi = .5, mi = .04, hi = .1 * mi, gi = 16, _i = 16, vi = {
|
|
314
316
|
pre: {
|
|
315
317
|
radiusScale: 1,
|
|
316
318
|
fractionScale: 2
|
|
@@ -323,7 +325,7 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
323
325
|
radiusScale: 2,
|
|
324
326
|
fractionScale: .5
|
|
325
327
|
}
|
|
326
|
-
},
|
|
328
|
+
}, yi = .25 * Math.SQRT2, bi = [
|
|
327
329
|
[
|
|
328
330
|
-1,
|
|
329
331
|
0,
|
|
@@ -345,58 +347,58 @@ var Wr = 65504, Gr = 6e4, Kr = .01, qr = Object.freeze([
|
|
|
345
347
|
1
|
|
346
348
|
],
|
|
347
349
|
[
|
|
348
|
-
-
|
|
349
|
-
|
|
350
|
+
-yi,
|
|
351
|
+
yi,
|
|
350
352
|
.5
|
|
351
353
|
],
|
|
352
354
|
[
|
|
353
|
-
|
|
354
|
-
|
|
355
|
+
yi,
|
|
356
|
+
yi,
|
|
355
357
|
.5
|
|
356
358
|
],
|
|
357
359
|
[
|
|
358
|
-
|
|
359
|
-
-
|
|
360
|
+
yi,
|
|
361
|
+
-yi,
|
|
360
362
|
.5
|
|
361
363
|
],
|
|
362
364
|
[
|
|
363
|
-
-
|
|
364
|
-
-
|
|
365
|
+
-yi,
|
|
366
|
+
-yi,
|
|
365
367
|
.5
|
|
366
368
|
]
|
|
367
|
-
],
|
|
368
|
-
let r = e.mul(t).add(n).abs().mul(-
|
|
369
|
+
], xi = (e, t, n) => Wn(0, 1, L(1).sub(e.mul(t).add(n).abs())), Si = (e, t, n) => {
|
|
370
|
+
let r = e.mul(t).add(n).abs().mul(-ii);
|
|
369
371
|
return L(1).div(r.mul(r).sub(r).add(1));
|
|
370
|
-
},
|
|
371
|
-
let i = B(On(
|
|
372
|
+
}, Ci = (e) => V(L(1.570796), L(1.395402), H(e)).mul(Gn(H(L(1).sub(e)))), wi = (e, t) => L(1).sub(Pn(e.mul(e).mul(-200))).mul(Hn(H(e), t)), Ti = (e, t) => H(e).mul(Gn(t.div(L(1).sub(t).add(ti)))), Ei = (e, t, n, r) => {
|
|
373
|
+
let i = B(On(Ti(n, r.mul(V(H(t), L(1), e)))), L(ni));
|
|
372
374
|
return L(1).div(i);
|
|
373
|
-
},
|
|
374
|
-
let n = L(1).div(V(L(
|
|
375
|
+
}, Di = (e, t) => {
|
|
376
|
+
let n = L(1).div(V(L(ri), L(1), H(e.mul(t))));
|
|
375
377
|
return J(n, e.mul(n).negate());
|
|
376
|
-
},
|
|
378
|
+
}, Oi = (e, t, n) => {
|
|
377
379
|
let r = L(1).div(V(L(n), L(1), V(e.mul(e), e, H(t))));
|
|
378
380
|
return J(r, e.mul(r).negate());
|
|
379
|
-
},
|
|
381
|
+
}, ki = (e, t) => {
|
|
380
382
|
let n = L(1).div(t);
|
|
381
383
|
return J(n, e.mul(n).negate());
|
|
382
|
-
},
|
|
384
|
+
}, Ai = (e, t, n, r) => {
|
|
383
385
|
let i = L(1).div(e.mul(t));
|
|
384
386
|
return J(i, I(r, n).mul(i).negate());
|
|
385
|
-
},
|
|
387
|
+
}, ji = (e) => J(1).sub(J(1).sub(Ln(e.mul(.5)).mul(2)).abs()).min(.99999), Mi = (e) => Xn(I(e, Xn(.25, .5, .25)), I(e, Xn(.5, 0, -.5)), I(e, Xn(-.25, .5, -.25))), Ni = (e) => {
|
|
386
388
|
let t = e.x.sub(e.z);
|
|
387
389
|
return B(Xn(t.add(e.y), e.x.add(e.z), t.sub(e.y)), Xn(0));
|
|
388
|
-
},
|
|
389
|
-
function
|
|
390
|
+
}, Pi = (e, t) => t.add(ti).div(e.add(ti)), Fi = (e, t) => Y(e.xyz.mul(Pi(e.x, t)), e.w), Ii = (e) => Y(Mi(Ni(e.xyz)), H(e.w)), Li = (e, t) => Gn(t.sub(e.mul(e)).abs()), Ri = (e, t) => J(e.x.mul(t.x).add(e.y.mul(t.y)), e.z.mul(t.x).add(e.w.mul(t.y))), zi = (e) => e.mul(1 - mi).add(mi), Bi = (e) => B(e.x, B(e.y, e.z)).lessThan(hi), Vi = (e) => e.z.greaterThan(gi - .5), Hi = (e) => e.lessThan(0), Ui = (e) => e.abs().clamp(.05, 1), Wi = (e, t) => U(e.equal(0), Y(0), t);
|
|
391
|
+
function Gi(e) {
|
|
390
392
|
let t = Math.imul(e | 0, 2654435761) >>> 0;
|
|
391
393
|
return t ^= t >>> 15, t = Math.imul(t, 2246822507) >>> 0, t ^= t >>> 13, t = Math.imul(t, 3266489909) >>> 0, t ^= t >>> 16, t / 4294967296;
|
|
392
394
|
}
|
|
393
|
-
var
|
|
395
|
+
var Ki = class extends A {
|
|
394
396
|
constructor(e, t = {}) {
|
|
395
397
|
super("NRD", {
|
|
396
398
|
...t,
|
|
397
|
-
executionMode:
|
|
399
|
+
executionMode: j.PER_CYCLE
|
|
398
400
|
}), this.renderer = e, this.pathTracer = t.pathTracer || null, this.settings = {
|
|
399
|
-
...
|
|
401
|
+
...Yr,
|
|
400
402
|
...t.settings || {}
|
|
401
403
|
}, this._releaseHitDistance = this.pathTracer?.requestOutput?.("hitDistance", { encode: (e, t) => e.div(B(t.mul(.1).add(3), L(1e-4))).clamp(0, 1) }) ?? null;
|
|
402
404
|
let n = t.width || 1, r = t.height || 1;
|
|
@@ -435,7 +437,7 @@ var zi = class extends k {
|
|
|
435
437
|
magFilter: mr,
|
|
436
438
|
depthBuffer: !1,
|
|
437
439
|
stencilBuffer: !1
|
|
438
|
-
}), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n /
|
|
440
|
+
}), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n / _i), this._dispatchY = Math.ceil(r / _i), this._buildKernels();
|
|
439
441
|
}
|
|
440
442
|
_allocStorage() {
|
|
441
443
|
let e = () => D(fr);
|
|
@@ -459,7 +461,7 @@ var zi = class extends k {
|
|
|
459
461
|
}
|
|
460
462
|
updateParameters(e) {
|
|
461
463
|
if (e) {
|
|
462
|
-
for (let t of Object.keys(e)) t === "debugMode" ? this.debugMode.value = e.debugMode | 0 : t in
|
|
464
|
+
for (let t of Object.keys(e)) t === "debugMode" ? this.debugMode.value = e.debugMode | 0 : t in Yr && (this.settings[t] = e[t]);
|
|
463
465
|
this._syncUniforms();
|
|
464
466
|
}
|
|
465
467
|
}
|
|
@@ -470,7 +472,7 @@ var zi = class extends k {
|
|
|
470
472
|
t.fastClampSigmaScale.value = 3 + (e.fastHistoryClampingSigmaScale - 3) * a, t.fireflyMinRelativeScale.value = e.fireflySuppressorMinRelativeScale, t.antiFirefly.value = +!!e.enableAntiFirefly, t.antilag.value.set(e.antilagLuminanceSigmaScale, e.antilagLuminanceSensitivity), t.disocclusionThreshold.value = e.disocclusionThreshold, t.convergence.value.set(e.convergenceS, e.convergenceB, e.convergenceP), t.lobeVolumePercent.value = e.lobeVolumePercent, t.handoverFrames.value = e.handoverFrames > 0 ? e.handoverFrames : 2 * n;
|
|
471
473
|
}
|
|
472
474
|
_worldPosAt(e, t, n, r) {
|
|
473
|
-
return
|
|
475
|
+
return N(e, t, n, r, this.cameraRay);
|
|
474
476
|
}
|
|
475
477
|
_viewVector(e, t, n) {
|
|
476
478
|
return U(he(this.cameraRay.cameraProjection), n, Vn(t.sub(e)));
|
|
@@ -494,6 +496,9 @@ var zi = class extends k {
|
|
|
494
496
|
_handover(e) {
|
|
495
497
|
return H(e.div(B(this.u.handoverFrames, 1)));
|
|
496
498
|
}
|
|
499
|
+
_excluded(e, t, n, r) {
|
|
500
|
+
return e.greaterThanEqual(Gr).or(Hi(t)).or(n.and(r.not()));
|
|
501
|
+
}
|
|
497
502
|
_bilinear(e) {
|
|
498
503
|
let t = e.mul(J(this.resW, this.resH)).sub(.5), n = In(t), r = H(t.sub(n)), i = R(n.x), a = R(n.y), o = (e, t) => U(e.greaterThanEqual(R(0)).and(t.greaterThanEqual(R(0))).and(e.lessThan(R(this.resW))).and(t.lessThan(R(this.resH))), L(1), L(0));
|
|
499
504
|
return {
|
|
@@ -526,7 +531,7 @@ var zi = class extends k {
|
|
|
526
531
|
_sampleHistory(e, t, n, r, i) {
|
|
527
532
|
let a = Y(0).toVar();
|
|
528
533
|
return F(i, () => {
|
|
529
|
-
let n = H(t).mul(J(this.resW, this.resH)), r = In(n.sub(.5)).add(.5), i = H(n.sub(r)), o =
|
|
534
|
+
let n = H(t).mul(J(this.resW, this.resH)), r = In(n.sub(.5)).add(.5), i = H(n.sub(r)), o = pi, s = i.mul(i.mul(i.mul(-o).add(2 * o)).sub(o)), c = i.mul(i.mul(i.mul(2 - o).sub(3 - o))).add(1), l = i.mul(i.mul(i.mul(-(2 - o)).add(3 - 2 * o)).add(o)), u = i.mul(i.mul(i.mul(o).sub(o))), d = [
|
|
530
535
|
s.x,
|
|
531
536
|
c.x,
|
|
532
537
|
l.x,
|
|
@@ -564,119 +569,122 @@ var zi = class extends k {
|
|
|
564
569
|
this._dispatchY,
|
|
565
570
|
1
|
|
566
571
|
], [
|
|
567
|
-
|
|
568
|
-
|
|
572
|
+
_i,
|
|
573
|
+
_i,
|
|
569
574
|
1
|
|
570
575
|
]);
|
|
571
576
|
}
|
|
572
577
|
_buildSpatial(e) {
|
|
573
|
-
let
|
|
574
|
-
let
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
if (!t) {
|
|
587
|
-
let e = v.mul(Y(D, 0)).xy;
|
|
588
|
-
M = V(J(1).sub(e.abs()), J(1), s), M = M.div(B(M.x, M.y));
|
|
578
|
+
let r = e === "pre", { radiusScale: i, fractionScale: a } = vi[e], s = this.u, c = this._colorTexNode, l = this._albedoTexNode, u = this._ndTexNode, d = this._snTexNode, f = this._nData, p = e === "blur" ? this._nTmpA : this._nTmpB, m = e === "blur" ? this._tmpB : r ? this._tmpA : this._hist, h = this._geomPrev, g = r ? this.rotPre : e === "blur" ? this.rotBlur : this.rotPost, _ = r ? s.prepassBlurRadius : s.maxBlurRadius, v = this.camView, y = this.camPos, b = this.resW, x = this.resH, S = this.inputFrames, C = r ? (e, r) => Y(Mi(t(W(c, e).xyz.div(zi(r.xyz)))), n(r.w, o).min(1)) : (e) => W(p, e), w = Tn(([t, n]) => {
|
|
579
|
+
let o = R(X.x).mul(_i).add(R(z.x)), c = R(X.y).mul(_i).add(R(z.y));
|
|
580
|
+
F(o.lessThan(R(b)).and(c.lessThan(R(x))), () => {
|
|
581
|
+
let p = Rn(o, c), w = Jn(K(o), K(c)), T = W(u, p).w.toVar(), E = T.greaterThanEqual(Gr), D = W(d, p).toVar(), O = Vn(D.xyz.mul(2).sub(1)).toVar(), k = Ui(D.w).toVar(), ee = L(Gr).toVar(), te = r ? W(l, p) : null, ne = (r ? Bi(te) : Vi(W(f, p))).toVar(), A = C(p, te).toVar();
|
|
582
|
+
F(E.not(), () => {
|
|
583
|
+
let e = this._pixelUv(o, c), m = this._worldPosAt(e, T, t, n).toVar();
|
|
584
|
+
ee.assign(v.mul(Y(m, 1)).z.abs()), F(_.greaterThan(0).and(Hi(D.w).not()), () => {
|
|
585
|
+
let o = I(O, this._viewVector(m, y, this.viewVector)).abs().toVar(), c = this._frustumSize(ee).toVar(), h = S.add(1), w = r ? B(S, L(10)) : W(f, p).y.add(S), T = (r ? L(1).div(w.add(1)) : this._advancedNonLinear(w)).toVar(), E = wi(k, .5).toVar(), D = ee.mul(Jr).add(3), te = A.w.toVar(), j = H(te.mul(D).div(c)), re = L(1).sub(this._handover(h)), M = (r ? j.div(h) : j.mul(T)).mul(re), ie = s.minBlurRadius.mul(H(L(2).sub(w.div(B(s.maxAccum, 1))))), ae = B(H(Gn(H(M)).mul(i)).mul(_).mul(E), ie.mul(E)).toVar(), oe = Ai(s.planeDistSensitivity, c, m, O).toVar(), se = Ei(T, s.lobeAngleFraction, k, s.lobeVolumePercent).div(a).toVar(), ce = Di(k, s.roughnessFraction.mul(a)).toVar(), le = ki(te, T).toVar(), N = s.minHitDistanceWeight.mul(a).mul(E);
|
|
586
|
+
r || (N = N.mul(T)), N = N.toVar();
|
|
587
|
+
let ue = J(1);
|
|
588
|
+
if (!r) {
|
|
589
|
+
let e = v.mul(Y(O, 0)).xy;
|
|
590
|
+
ue = V(J(1).sub(e.abs()), J(1), o), ue = ue.div(B(ue.x, ue.y));
|
|
589
591
|
}
|
|
590
|
-
let
|
|
591
|
-
for (let
|
|
592
|
-
let
|
|
593
|
-
|
|
594
|
-
let
|
|
595
|
-
|
|
592
|
+
let de = ue.mul(J(L(1).div(b), L(1).div(x))).mul(ae).toVar(), fe = L(1).toVar();
|
|
593
|
+
for (let i = 0; i < bi.length; i++) {
|
|
594
|
+
let a = bi[i], o = e.add(Ri(g, J(a[0], a[1])).mul(de)), s = ji(o), c = U(s.x.notEqual(o.x).or(s.y.notEqual(o.y)), L(1), L(Math.exp(-.66 * a[2] * a[2]))).toVar(), p = this._uvToCoord(s), m = W(u, p).w, h = this._worldPosAt(s, m, t, n), _ = W(d, p), v = Ci(I(O, Vn(_.xyz.mul(2).sub(1))));
|
|
595
|
+
c.mulAssign(xi(v, se, L(0))), c.mulAssign(xi(Ui(_.w), ce.x, ce.y)), c.mulAssign(xi(I(O, h), oe.x, oe.y));
|
|
596
|
+
let y = r ? W(l, p) : null, b = r ? Bi(y) : Vi(W(f, p));
|
|
597
|
+
c.assign(U(this._excluded(m, _.w, b, ne), L(0), c));
|
|
598
|
+
let x = Wi(c, C(p, y));
|
|
599
|
+
c.mulAssign(N.add(Si(x.w, le.x, le.y))), fe.addAssign(c), A.addAssign(x.mul(c));
|
|
596
600
|
}
|
|
597
|
-
|
|
601
|
+
A.divAssign(B(fe, 1e-6)), r || A.assign(Y(A.xyz, te));
|
|
598
602
|
});
|
|
599
|
-
}), G(m,
|
|
603
|
+
}), G(m, w, A).toWriteOnly(), e === "post" && G(h, w, Y(O, ee)).toWriteOnly();
|
|
600
604
|
});
|
|
601
605
|
});
|
|
602
606
|
return this._dispatchOf(w);
|
|
603
607
|
}
|
|
604
608
|
_buildTemporalAccumulation() {
|
|
605
|
-
let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._motionTexNode, i = this._nTmpA, a = this._nHist, o = this._nFast, s = this._nInternal, c = this._nGeom, l = this._tmpB, u = this._dataT, d = this.
|
|
606
|
-
let
|
|
607
|
-
F(
|
|
608
|
-
let
|
|
609
|
-
F(
|
|
610
|
-
G(l,
|
|
609
|
+
let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._motionTexNode, i = this._nTmpA, a = this._nHist, o = this._nFast, s = this._nInternal, c = this._nGeom, l = this._tmpB, u = this._dataT, d = this._albedoTexNode, f = this.camView, p = this.prevCamView, m = this.camPos, h = this.prevCamPos, g = this.resW, _ = this.resH, v = this.inputFrames, y = this.resetU, b = Tn(([b, x]) => {
|
|
610
|
+
let S = R(X.x).mul(_i).add(R(z.x)), C = R(X.y).mul(_i).add(R(z.y));
|
|
611
|
+
F(S.lessThan(R(g)).and(C.lessThan(R(_))), () => {
|
|
612
|
+
let g = Rn(S, C), _ = Jn(K(S), K(C)), w = W(t, g).w, T = W(i, g).toVar();
|
|
613
|
+
F(w.greaterThanEqual(Gr), () => {
|
|
614
|
+
G(l, _, T).toWriteOnly(), G(u, _, Y(0)).toWriteOnly(), Dn();
|
|
611
615
|
});
|
|
612
|
-
let
|
|
613
|
-
|
|
616
|
+
let E = e.maxAccum.mul(L(1).sub(y)).toVar(), D = e.maxFast.mul(L(1).sub(y)).toVar(), O = W(n, g), k = Vn(O.xyz.mul(2).sub(1)).toVar(), ee = Ui(O.w).toVar(), te = this._pixelUv(S, C), ne = this._worldPosAt(te, w, b, x).toVar(), A = f.mul(Y(ne, 1)).z.abs().toVar(), j = I(k, this._viewVector(ne, m, this.viewVector)).abs().toVar(), re = this._frustumSize(A).toVar(), M = Xn(0).toVar();
|
|
617
|
+
M.addAssign(k.mul(.25));
|
|
614
618
|
for (let e = -1; e <= 0; e++) for (let r = -1; r <= 0; r++) {
|
|
615
619
|
if (r === 0 && e === 0) continue;
|
|
616
|
-
let i = this._clampCoord(
|
|
617
|
-
|
|
620
|
+
let i = this._clampCoord(S.add(r), C.add(e)), a = Vn(W(n, i).xyz.mul(2).sub(1)), o = W(t, i).w.lessThan(Gr);
|
|
621
|
+
M.addAssign(U(o, a, k).mul(.25));
|
|
618
622
|
}
|
|
619
|
-
let ie = W(r,
|
|
623
|
+
let ie = W(r, g), ae = te.sub(ie.xy).toVar(), oe = p.mul(Y(ne, 1)).z.abs().toVar(), se = this._bilinear(ae), ce = re.mul(H(e.disocclusionThreshold.div(B(j, .05)))).sub(ti).toVar(), le = L(1).sub(y), N = [], ue = [];
|
|
620
624
|
for (let e = 0; e < 4; e++) {
|
|
621
|
-
let t = W(c, se.taps[e]), n = U(I(t.xyz,
|
|
622
|
-
|
|
625
|
+
let t = W(c, se.taps[e]), n = U(I(t.xyz, M).greaterThan(fi), L(1), L(0)), r = U(t.w.sub(oe).abs().lessThanEqual(ce), L(1), L(0)), i = U(t.w.lessThan(Gr), L(1), L(0));
|
|
626
|
+
N.push(n.mul(r).mul(i).mul(se.inScreen[e]).mul(le).toVar()), ue.push(W(s, se.taps[e]).x);
|
|
623
627
|
}
|
|
624
|
-
let de = se.customWeights(
|
|
625
|
-
|
|
626
|
-
let
|
|
627
|
-
|
|
628
|
-
let
|
|
629
|
-
|
|
630
|
-
let
|
|
631
|
-
|
|
632
|
-
let
|
|
633
|
-
|
|
634
|
-
let
|
|
635
|
-
|
|
628
|
+
let de = se.customWeights(N).map((e) => e.toVar()), fe = N[0].add(N[1]).add(N[2]).add(N[3]).greaterThan(3.5).toVar(), pe = N[0].add(N[1].mul(2)).add(N[2].mul(4)).add(N[3].mul(8)), me = this._applyCustomWeights(ue, de, L(0)).toVar(), he = I(k, this._viewVector(ne, h, this.prevViewVector)).abs().add(.001).div(j.add(.001)).toVar();
|
|
629
|
+
he.assign(V(L(.1), L(1), H(he.mul(he))));
|
|
630
|
+
let ge = Gn(H(se.filter(N))).mul(he).toVar();
|
|
631
|
+
me.assign(me.mul(V(ge, L(1), L(1).div(me.add(1))))), me.assign(Bn(me, E));
|
|
632
|
+
let _e = Ii(this._sampleHistory((e) => W(a, e), ae, se, de, fe)).toVar(), ve = B(this._applyCustomWeights(se.taps.map((e) => W(o, e).x), de, L(0)), 0).toVar(), ye = v.add(1), be = this._handover(ye).toVar(), xe = me.mul(L(1).sub(be)), Se = ye.div(ye.add(xe)).toVar(), P = L(1).div(L(1).add(wi(ee, .25).mul(.5).mul(E))), Ce = Y(V(_e.xyz, T.xyz, Se), V(_e.w, T.w, B(Se, P))).toVar(), we = e.fireflyMinRelativeScale.add(L(li).div(me.add(1))).toVar(), Te = me.mul(e.maxBlurRadius).mul(ui).toVar();
|
|
633
|
+
Te.assign(Te.div(Te.add(1)).mul(L(1).sub(be)));
|
|
634
|
+
let Ee = V(Ce.x, Bn(Ce.x, _e.x.mul(we)), Te);
|
|
635
|
+
Ce.assign(Fi(Ce, Ee));
|
|
636
|
+
let De = L(1.2).add(L(1).div(me.add(1)));
|
|
637
|
+
Ce.assign(Y(Ce.xyz, V(Ce.w, Bn(Ce.w, _e.w.mul(De)), Te))), G(l, _, Ce).toWriteOnly();
|
|
638
|
+
let Oe = Bn(me, D).mul(L(1).sub(be)), ke = ye.div(ye.add(Oe)), Ae = V(ve, T.x, ke).toVar(), je = Bn(Ae, _e.x.mul(we).mul(di));
|
|
639
|
+
Ae.assign(V(Ae, je, Te));
|
|
640
|
+
let Me = U(Bi(W(d, g)), L(gi), L(0));
|
|
641
|
+
G(u, _, Y(Ae, me, pe.add(Me), U(fe, L(1), L(0)))).toWriteOnly();
|
|
636
642
|
});
|
|
637
643
|
});
|
|
638
|
-
return this._dispatchOf(
|
|
644
|
+
return this._dispatchOf(b);
|
|
639
645
|
}
|
|
640
646
|
_buildHistoryFix() {
|
|
641
647
|
let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._nTmpB, i = this._nData, a = this._tmpA, o = this._fastHist, s = this.camView, c = this.resW, l = this.resH, u = this.inputFrames, d = Tn(([d, f]) => {
|
|
642
|
-
let p = R(X.x).mul(
|
|
648
|
+
let p = R(X.x).mul(_i).add(R(z.x)), m = R(X.y).mul(_i).add(R(z.y));
|
|
643
649
|
F(p.lessThan(R(c)).and(m.lessThan(R(l))), () => {
|
|
644
650
|
let h = Rn(p, m), g = Jn(K(p), K(m)), _ = W(t, h).w;
|
|
645
651
|
F(_.greaterThanEqual(Gr), () => {
|
|
646
652
|
let e = W(r, h);
|
|
647
653
|
G(a, g, e).toWriteOnly(), G(o, g, Y(e.x, 0, 0, 0)).toWriteOnly(), Dn();
|
|
648
654
|
});
|
|
649
|
-
let v = W(i, h).toVar(), y = v.y.toVar(), b = y.add(u), x = this._handover(u.add(1)).toVar(), S = W(n, h), C = Vn(S.xyz.mul(2).sub(1)).toVar(), w = S.w
|
|
650
|
-
F(
|
|
651
|
-
let a =
|
|
652
|
-
|
|
653
|
-
for (let e = -
|
|
654
|
-
if (
|
|
655
|
-
let
|
|
656
|
-
|
|
657
|
-
let
|
|
658
|
-
|
|
655
|
+
let v = W(i, h).toVar(), y = v.y.toVar(), b = y.add(u), x = this._handover(u.add(1)).toVar(), S = W(n, h), C = Vn(S.xyz.mul(2).sub(1)).toVar(), w = Ui(S.w).toVar(), T = this._pixelUv(p, m), E = this._worldPosAt(T, _, d, f).toVar(), D = s.mul(Y(E, 1)).z.abs(), O = this._frustumSize(D).toVar(), k = W(r, h).toVar(), ee = L(1).div(b.add(1)).toVar(), te = D.mul(Jr).add(3), ne = H(k.w.mul(te).div(O)), A = k.w.toVar(), j = Un(U(b.lessThan(e.historyFixFrameNum), L(1), L(0)).mul(.5).mul(2 / ai).mul(e.historyFixStride).mul(V(L(.25).add(Gn(ne).mul(.75)), L(1), ee))).toVar(), re = Hi(S.w).toVar();
|
|
656
|
+
F(j.notEqual(0).and(re.not()), () => {
|
|
657
|
+
let a = Ei(ee, e.lobeAngleFraction, w, e.lobeVolumePercent).toVar(), o = Ai(e.planeDistSensitivity, O, E, C).toVar(), s = ki(A, ee).toVar(), u = Oi(w.mul(w), Gn(e.roughnessFraction), ri).toVar(), p = Vi(v).toVar(), m = L(1).add(y).toVar();
|
|
658
|
+
k.mulAssign(m);
|
|
659
|
+
for (let e = -ai; e <= ai; e++) for (let h = -ai; h <= ai; h++) {
|
|
660
|
+
if (h === 0 && e === 0 || Math.abs(h) + Math.abs(e) === ai * 2) continue;
|
|
661
|
+
let g = ji(T.add(J(h, e).mul(j).mul(J(L(1).div(c), L(1).div(l))))), _ = this._uvToCoord(g), v = W(t, _).w, y = this._worldPosAt(g, v, d, f), b = W(n, _), x = Si(Ci(I(Vn(b.xyz.mul(2).sub(1)), C)), a, L(0)).toVar(), S = Ui(b.w);
|
|
662
|
+
x.mulAssign(Si(S.mul(S), u.x, u.y));
|
|
663
|
+
let w = W(i, _);
|
|
664
|
+
x.mulAssign(L(1).add(w.y)), x.mulAssign(xi(I(C, y), o.x, o.y)), x.assign(U(this._excluded(v, b.w, Vi(w), p), L(0), x));
|
|
665
|
+
let E = Wi(x, W(r, _));
|
|
666
|
+
x.mulAssign(Si(E.w, s.x, s.y)), m.addAssign(x), k.addAssign(E.mul(x));
|
|
659
667
|
}
|
|
660
|
-
|
|
668
|
+
k.divAssign(B(m, 1e-6));
|
|
661
669
|
});
|
|
662
|
-
let
|
|
670
|
+
let M = k.x.toVar(), ie = H(y.div(B(e.historyFixFrameNum, ti))), ae = V(M, v.x, ie).toVar();
|
|
663
671
|
G(o, g, Y(ae, 0, 0, 0)).toWriteOnly();
|
|
664
|
-
let oe = ae.toVar(), se = ae.mul(ae).toVar(), ce = L(0).toVar(), le = L(0).toVar(),
|
|
672
|
+
let oe = ae.toVar(), se = ae.mul(ae).toVar(), ce = L(0).toVar(), le = L(0).toVar(), N = (e, n, r) => {
|
|
665
673
|
let a = this._clampCoord(p.add(e), m.add(n)), o = W(t, a).w, s = U(o.greaterThanEqual(Gr), ae, W(i, a).x);
|
|
666
|
-
Math.abs(e) <=
|
|
674
|
+
Math.abs(e) <= oi && Math.abs(n) <= oi && (oe.addAssign(s), se.addAssign(s.mul(s))), r && (ce.addAssign(s), le.addAssign(s.mul(s)));
|
|
667
675
|
}, ue = e.antiFirefly.greaterThan(.5);
|
|
668
|
-
for (let e = -
|
|
676
|
+
for (let e = -oi; e <= oi; e++) for (let t = -oi; t <= oi; t++) t === 0 && e === 0 || N(t, e, Math.abs(t) > 1 || Math.abs(e) > 1);
|
|
669
677
|
F(ue, () => {
|
|
670
|
-
for (let e = -
|
|
678
|
+
for (let e = -si; e <= si; e++) for (let t = -si; t <= si; t++) Math.abs(t) <= oi && Math.abs(e) <= oi || N(t, e, !0);
|
|
671
679
|
}), F(ue, () => {
|
|
672
|
-
let e = 1 / ((
|
|
673
|
-
|
|
680
|
+
let e = 1 / ((si * 2 + 1) ** 2 - 9), t = ce.mul(e), n = Li(t, le.mul(e)).mul(ci);
|
|
681
|
+
M.assign(V(M.clamp(t.sub(n), t.add(n)), M, x));
|
|
674
682
|
});
|
|
675
683
|
{
|
|
676
|
-
let t = 1 / (
|
|
677
|
-
|
|
684
|
+
let t = 1 / (oi * 2 + 1) ** 2, n = oe.mul(t), r = Li(n, se.mul(t)).mul(e.fastClampSigmaScale), i = M.clamp(n.sub(r), n.add(r)), a = U(e.maxFast.lessThan(e.maxAccum), L(1), L(0)), o = V(L(1).div(L(1).add(a.mul(y).mul(2))), L(1), x);
|
|
685
|
+
M.assign(V(i, M, o));
|
|
678
686
|
}
|
|
679
|
-
G(a, g,
|
|
687
|
+
G(a, g, U(re, k, Fi(k, M))).toWriteOnly();
|
|
680
688
|
});
|
|
681
689
|
});
|
|
682
690
|
return this._dispatchOf(d);
|
|
@@ -684,56 +692,56 @@ var zi = class extends k {
|
|
|
684
692
|
_buildTemporalStabilization(e) {
|
|
685
693
|
let t = this.u, n = this._colorTexNode, r = this._albedoTexNode, i = this._ndTexNode, a = this._snTexNode, o = this._motionTexNode, s = this._nHist, c = this._nData, l = this._nStabRead, u = this._internal, d = this._tmpA, f = this.resW, p = this.resH, m = this.inputFrames, h = this.resetU, g = this.debugMode;
|
|
686
694
|
return Tn(() => {
|
|
687
|
-
let _ = R(X.x).mul(
|
|
695
|
+
let _ = R(X.x).mul(_i).add(R(z.x)), v = R(X.y).mul(_i).add(R(z.y));
|
|
688
696
|
F(_.lessThan(R(f)).and(v.lessThan(R(p))), () => {
|
|
689
697
|
let f = Rn(_, v), p = Jn(K(_), K(v)), y = W(i, f).w, b = W(n, f).toVar();
|
|
690
698
|
F(y.greaterThanEqual(Gr), () => {
|
|
691
699
|
G(d, p, b).toWriteOnly(), G(e, p, Y(W(s, f).x, 0, 0, 0)).toWriteOnly(), G(u, p, Y(0, 1, 0, 0)).toWriteOnly(), Dn();
|
|
692
700
|
});
|
|
693
|
-
let x = W(a, f).w
|
|
701
|
+
let x = W(a, f).w, S = Ui(x), C = this._pixelUv(_, v), w = W(o, f), T = C.sub(w.xy).toVar(), E = W(c, f).toVar(), D = E.y.toVar(), O = K(E.z.add(.5)).toVar(), k = E.w.greaterThan(.5), ee = this._bilinear(T), te = [
|
|
694
702
|
1,
|
|
695
703
|
2,
|
|
696
704
|
4,
|
|
697
705
|
8
|
|
698
|
-
].map((e) => U(
|
|
706
|
+
].map((e) => U(O.bitAnd(K(e)).notEqual(K(0)), L(1), L(0))), ne = ee.customWeights(te).map((e) => e.toVar()), A = Gn(H(ee.filter(te))).toVar(), j = W(s, f).toVar(), re = j.x.toVar(), M = re.toVar(), ie = re.mul(re).toVar();
|
|
699
707
|
for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
|
|
700
708
|
if (t === 0 && e === 0) continue;
|
|
701
|
-
let n = this._clampCoord(_.add(t), v.add(e)), r = W(i, n).w, a = U(r.greaterThanEqual(Gr),
|
|
702
|
-
|
|
709
|
+
let n = this._clampCoord(_.add(t), v.add(e)), r = W(i, n).w, a = U(r.greaterThanEqual(Gr), re, W(s, n).x);
|
|
710
|
+
M.addAssign(a), ie.addAssign(a.mul(a));
|
|
703
711
|
}
|
|
704
|
-
|
|
705
|
-
let ae =
|
|
706
|
-
F(
|
|
707
|
-
|
|
712
|
+
M.divAssign(9), ie.divAssign(9);
|
|
713
|
+
let ae = Li(M, ie).toVar();
|
|
714
|
+
F(D.lessThan(t.historyFixFrameNum).and(Hi(x).not()), () => {
|
|
715
|
+
re.assign(Bn(re, M.mul(L(1.2).add(L(1).div(D.add(1))))));
|
|
708
716
|
});
|
|
709
|
-
let oe = B(this._sampleHistory((e) => W(l, e),
|
|
710
|
-
|
|
711
|
-
let fe = m.add(1), pe = this._handover(fe),
|
|
712
|
-
|
|
713
|
-
let
|
|
714
|
-
G(u, p, Y(Bn(
|
|
715
|
-
let
|
|
717
|
+
let oe = B(this._sampleHistory((e) => W(l, e), T, ee, ne, k).x, 0).toVar(), se = ae.mul(t.antilag.x), ce = t.antilag.y.mul(4), le = oe.clamp(M.sub(se), M.add(se)), N = oe.sub(le).abs().div(B(oe, le).add(ti)), ue = L(1).div(L(1).add(N.mul(D.mul(A)).div(ce))).toVar(), de = Bn(D, t.historyFixFrameNum);
|
|
718
|
+
D.assign(V(de, D, ue));
|
|
719
|
+
let fe = m.add(1), pe = this._handover(fe), me = A.mul(L(1).sub(this._advancedNonLinear(D.mul(L(1).sub(pe)).div(fe)))).mul(ue).toVar(), he = L(1).add(me.mul(6)), ge = t.stabilizationStrength.mul(L(1).sub(h)), _e = V(re, oe.clamp(M.sub(ae.mul(he)), M.add(ae.mul(he))), Bn(me, ge)).toVar();
|
|
720
|
+
j.assign(Fi(j, _e)), G(e, p, Y(_e, 0, 0, 0)).toWriteOnly();
|
|
721
|
+
let ve = t.maxAccum.mul(L(1).sub(h));
|
|
722
|
+
G(u, p, Y(Bn(D.add(1), ve), S, 0, 0)).toWriteOnly();
|
|
723
|
+
let ye = W(r, f), be = Y(Ni(j.xyz).mul(zi(ye.xyz)), b.w).toVar();
|
|
716
724
|
F(g.equal(R(1)), () => {
|
|
717
|
-
let e = H(
|
|
718
|
-
|
|
725
|
+
let e = H(D.div(B(t.maxAccum, 1)));
|
|
726
|
+
be.assign(Y(L(1).sub(e), e, .2, 1));
|
|
719
727
|
}).ElseIf(g.equal(R(2)), () => {
|
|
720
|
-
|
|
728
|
+
be.assign(Y(Xn(j.w), 1));
|
|
721
729
|
}).ElseIf(g.equal(R(3)), () => {
|
|
722
|
-
|
|
730
|
+
be.assign(Y(Xn(S), 1));
|
|
723
731
|
}).ElseIf(g.equal(R(4)), () => {
|
|
724
|
-
let e =
|
|
725
|
-
|
|
732
|
+
let e = E.x.div(E.x.add(1));
|
|
733
|
+
be.assign(Y(Xn(e), 1));
|
|
726
734
|
}).ElseIf(g.equal(R(5)), () => {
|
|
727
|
-
|
|
728
|
-
}), G(d, p,
|
|
735
|
+
be.assign(Y(Xn(L(O.bitAnd(K(15))).div(15)), 1));
|
|
736
|
+
}), G(d, p, be).toWriteOnly();
|
|
729
737
|
});
|
|
730
738
|
})().compute([
|
|
731
739
|
this._dispatchX,
|
|
732
740
|
this._dispatchY,
|
|
733
741
|
1
|
|
734
742
|
], [
|
|
735
|
-
|
|
736
|
-
|
|
743
|
+
_i,
|
|
744
|
+
_i,
|
|
737
745
|
1
|
|
738
746
|
]);
|
|
739
747
|
}
|
|
@@ -753,7 +761,7 @@ var zi = class extends k {
|
|
|
753
761
|
}
|
|
754
762
|
_updateRotators(e) {
|
|
755
763
|
let t = (t, n) => {
|
|
756
|
-
let r =
|
|
764
|
+
let r = Gi(e * 3 + n) * Math.PI * 2;
|
|
757
765
|
t.value.set(Math.cos(r), Math.sin(r), -Math.sin(r), Math.cos(r));
|
|
758
766
|
};
|
|
759
767
|
t(this.rotPre, 0), t(this.rotBlur, 1), t(this.rotPost, 2);
|
|
@@ -780,7 +788,7 @@ var zi = class extends k {
|
|
|
780
788
|
this._nTmpA.value = this._tmpA, this._nTmpB.value = this._tmpB, this._nHist.value = this._hist, this._nFast.value = this._fastHist, this._nInternal.value = this._internal, this._nGeom.value = this._geomPrev, this._nData.value = this._dataT, this._nStabRead.value = this._stabPing === 0 ? this._stabB : this._stabA, this.renderer.compute(this._kPre), this.renderer.compute(this._kTa), this.renderer.compute(this._kHf), this.renderer.compute(this._kBlur), this.renderer.compute(this._kPost), this.renderer.compute(this._stabPing === 0 ? this._kTsA : this._kTsB), this._srcRegion.max.set(this.outputTarget.width, this.outputTarget.height), this.renderer.copyTextureToTexture(this._tmpA, this.outputTarget.texture, this._srcRegion), e.setTexture("nrd:output", this.outputTarget.texture), this._stabPing = 1 - this._stabPing, this._needsReset = !1, this._needsReset = !1;
|
|
781
789
|
}
|
|
782
790
|
setSize(e, t) {
|
|
783
|
-
this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e /
|
|
791
|
+
this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e / _i), this._dispatchY = Math.ceil(t / _i);
|
|
784
792
|
let n = [
|
|
785
793
|
this._dispatchX,
|
|
786
794
|
this._dispatchY,
|
|
@@ -809,7 +817,7 @@ var zi = class extends k {
|
|
|
809
817
|
for (let [e, t] of this._placeholders) e.dispose(), t.dispose();
|
|
810
818
|
this._placeholders.clear();
|
|
811
819
|
}
|
|
812
|
-
},
|
|
820
|
+
}, qi = {
|
|
813
821
|
autoExposure: !1,
|
|
814
822
|
autoExposureMetering: "center",
|
|
815
823
|
autoExposureStrength: .3,
|
|
@@ -818,42 +826,42 @@ var zi = class extends k {
|
|
|
818
826
|
autoExposureMaxExposure: 2 ** 8,
|
|
819
827
|
autoExposureAdaptSpeedBright: 3,
|
|
820
828
|
autoExposureAdaptSpeedDark: 1
|
|
821
|
-
},
|
|
829
|
+
}, Ji = [
|
|
822
830
|
"average",
|
|
823
831
|
"center",
|
|
824
832
|
"spot"
|
|
825
|
-
],
|
|
833
|
+
], Yi = 64, Xi = 8, Zi = 8, Qi = 256, $i = -16, ea = (12 - $i) / Qi, ta = 2 ** -24, na = 65536, ra = 256, ia = 128, aa = 1.5, oa = .01, sa = .06, ca = .25, la = 4, ua = .3, da = 1.5, fa = 3, pa = [
|
|
826
834
|
.2126,
|
|
827
835
|
.7152,
|
|
828
836
|
.0722
|
|
829
|
-
],
|
|
837
|
+
], ma = .999, ha = {
|
|
830
838
|
transparent: 0,
|
|
831
839
|
environment: 1,
|
|
832
840
|
color: 2
|
|
833
841
|
};
|
|
834
|
-
function
|
|
842
|
+
function ga(e, t, n, r, i) {
|
|
835
843
|
let a = t - e;
|
|
836
844
|
if (a === 0 || !(n > 0)) return e;
|
|
837
845
|
let o = Math.max(a < 0 ? r : i, .001);
|
|
838
846
|
if (n === Infinity) return t;
|
|
839
|
-
let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n /
|
|
847
|
+
let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n / aa)));
|
|
840
848
|
return e + Math.sign(a) * s;
|
|
841
849
|
}
|
|
842
|
-
function
|
|
850
|
+
function _a(e, t, n) {
|
|
843
851
|
let r = Math.abs(e);
|
|
844
|
-
return e * (r <=
|
|
852
|
+
return e * (r <= da ? n : r >= fa ? 1 : n + (1 - n) * (r - da) / (fa - da)) + n * (t - e);
|
|
845
853
|
}
|
|
846
|
-
function
|
|
847
|
-
if (!e) return t.fromArray(
|
|
854
|
+
function va(e, t) {
|
|
855
|
+
if (!e) return t.fromArray(pa);
|
|
848
856
|
let n = new vr().set(...e).invert().elements;
|
|
849
|
-
return t.set(
|
|
857
|
+
return t.set(pa[0] * n[0] + pa[1] * n[1] + pa[2] * n[2], pa[0] * n[3] + pa[1] * n[4] + pa[2] * n[5], pa[0] * n[6] + pa[1] * n[7] + pa[2] * n[8]);
|
|
850
858
|
}
|
|
851
|
-
var
|
|
859
|
+
var ya = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, ba = class extends A {
|
|
852
860
|
constructor(e, t = {}) {
|
|
853
861
|
super("AutoExposure", {
|
|
854
862
|
...t,
|
|
855
|
-
executionMode:
|
|
856
|
-
}), this.renderer = e, this.metering = t.metering ??
|
|
863
|
+
executionMode: j.ALWAYS
|
|
864
|
+
}), this.renderer = e, this.metering = t.metering ?? qi.autoExposureMetering, this.meteringPoint = new Rr(.5, .5), this.keyValue = t.keyValue ?? qi.autoExposureKeyValue, this.minExposure = t.minExposure ?? qi.autoExposureMinExposure, this.maxExposure = t.maxExposure ?? qi.autoExposureMaxExposure, this.adaptSpeedBright = t.adaptSpeedBright ?? qi.autoExposureAdaptSpeedBright, this.adaptSpeedDark = t.adaptSpeedDark ?? qi.autoExposureAdaptSpeedDark, this.centerWeight = t.centerWeight ?? 8, this.strength = t.strength ?? qi.autoExposureStrength, this.instant = !1, this.holdSamples = 0, this.onChange = null, this._lowU = q(t.lowPercentile ?? .1), this._highU = q(t.highPercentile ?? .9), this._falloffU = q(new Rr()), this._pointU = q(new Rr(.5, .5)), this._lumWeightsU = q(new Q().fromArray(pa)), this._backdropModeU = q(ha.transparent, "int"), this._widthU = q(1, "int"), this._heightU = q(1, "int"), this._strideU = q(1, "int"), this._gridXU = q(Yi, "int"), this._gridYU = q(Yi, "int"), this._inputNode = new Cn(), this._workingMatrix = void 0, this._histogram = Mn(Qi, "uint").toAtomic(), this._result = Mn(1, "vec4"), this._readback = new bn(16), this._readback.name = "AutoExposure", this._kernels = [this._buildTileKernel(), this._buildResolveKernel()], this._compensation = 1, this._exposureEV = 0, this._targetEV = null, this._viewEV = null, this._roomEV = null, this._clock = 0, this._movingUntil = -1, this._viewMoves = 0, this._landed = null, this._meteredLog2 = null, this._snap = !0, this._lastUpdate = null, this._accumulating = !1, this._emittedEV = null, this._pending = null, this._generation = 0, this._restarts = 0, this._meteredAt = {
|
|
857
865
|
restarts: -1,
|
|
858
866
|
samples: -1
|
|
859
867
|
}, this._stale = !1, this._disposed = !1;
|
|
@@ -861,7 +869,7 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
861
869
|
_buildTileKernel() {
|
|
862
870
|
let e = this._inputNode, t = this._histogram, n = this._widthU, r = this._heightU, i = this._strideU, a = this._gridXU, o = this._gridYU, s = this._lumWeightsU, c = this._falloffU, l = this._pointU, u = this._backdropModeU;
|
|
863
871
|
return Tn(() => {
|
|
864
|
-
let d = z.y.mul(K(
|
|
872
|
+
let d = z.y.mul(K(Zi)).add(z.x), f = R(X.x), p = R(X.y), m = f.mul(n).div(a).toVar(), h = f.add(R(1)).mul(n).div(a).toVar(), g = p.mul(r).div(o).toVar(), _ = p.add(R(1)).mul(r).div(o).toVar(), v = i.mul(R(Zi)), y = L(0).toVar(), b = L(0).toVar();
|
|
865
873
|
En({
|
|
866
874
|
start: g.add(R(z.y)),
|
|
867
875
|
end: _,
|
|
@@ -878,31 +886,31 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
878
886
|
update: v,
|
|
879
887
|
name: "px"
|
|
880
888
|
}, ({ px: n }) => {
|
|
881
|
-
let r = W(e, Rn(n, t)), i = I(r.xyz, s).toVar(), a = Fn(i).bitAnd(K(2139095040)).notEqual(K(2139095040)), o = r.w.clamp(0, 1), c = U(u.equal(R(
|
|
889
|
+
let r = W(e, Rn(n, t)), i = I(r.xyz, s).toVar(), a = Fn(i).bitAnd(K(2139095040)).notEqual(K(2139095040)), o = r.w.clamp(0, 1), c = U(u.equal(R(ha.environment)), L(1), U(u.equal(R(ha.color)), U(o.greaterThanEqual(ma), L(1), L(0)), o));
|
|
882
890
|
y.addAssign(U(a, i.clamp(0, 1e6), L(0)).mul(c)), b.addAssign(c);
|
|
883
891
|
});
|
|
884
892
|
});
|
|
885
|
-
let x = Zn("float",
|
|
893
|
+
let x = Zn("float", Zi * Zi), S = Zn("float", Zi * Zi);
|
|
886
894
|
x.element(d).assign(y), S.element(d).assign(b), Qn();
|
|
887
|
-
for (let e =
|
|
895
|
+
for (let e = Zi * Zi >> 1; e > 0; e >>= 1) F(d.lessThan(K(e)), () => {
|
|
888
896
|
x.element(d).addAssign(x.element(d.add(K(e)))), S.element(d).addAssign(S.element(d.add(K(e))));
|
|
889
897
|
}), Qn();
|
|
890
898
|
F(d.equal(K(0)), () => {
|
|
891
|
-
let e = x.element(K(0)).toVar(), i = S.element(K(0)).toVar(), a = (e) => e.div(v).mul(R(
|
|
892
|
-
F(i.greaterThan(0).and(e.greaterThan(i.mul(
|
|
893
|
-
let a = K(zn(e.div(i)).sub(
|
|
899
|
+
let e = x.element(K(0)).toVar(), i = S.element(K(0)).toVar(), a = (e) => e.div(v).mul(R(Zi)).add(Bn(e.mod(v), R(Zi))), o = L(a(h.sub(m)).mul(a(_.sub(g))));
|
|
900
|
+
F(i.greaterThan(0).and(e.greaterThan(i.mul(ta))), () => {
|
|
901
|
+
let a = K(zn(e.div(i)).sub($i).div(ea).floor().clamp(0, Qi - 1)), s = J(L(m.add(h)).div(L(n)), L(g.add(_)).div(L(r))).mul(.5).sub(l), u = K(Nn(I(s.mul(s), c).negate()).mul(i.div(B(o, 1))).mul(na).add(.5));
|
|
894
902
|
F(u.greaterThan(K(0)), () => {
|
|
895
903
|
kn(t.element(a), u);
|
|
896
904
|
});
|
|
897
905
|
});
|
|
898
906
|
});
|
|
899
907
|
})().compute([
|
|
900
|
-
|
|
901
|
-
|
|
908
|
+
Yi,
|
|
909
|
+
Yi,
|
|
902
910
|
1
|
|
903
911
|
], [
|
|
904
|
-
|
|
905
|
-
|
|
912
|
+
Zi,
|
|
913
|
+
Zi,
|
|
906
914
|
1
|
|
907
915
|
]);
|
|
908
916
|
}
|
|
@@ -911,31 +919,31 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
911
919
|
return Tn(() => {
|
|
912
920
|
let i = z.x, a = L(An(e.element(i))).toVar();
|
|
913
921
|
jn(e.element(i), K(0));
|
|
914
|
-
let o = Zn("float",
|
|
922
|
+
let o = Zn("float", Qi), s = Zn("float", Qi);
|
|
915
923
|
o.element(i).assign(a), Qn();
|
|
916
|
-
for (let e = 1; e <
|
|
924
|
+
for (let e = 1; e < Qi; e <<= 1) {
|
|
917
925
|
let t = o.element(i).toVar();
|
|
918
926
|
F(i.greaterThanEqual(K(e)), () => {
|
|
919
927
|
t.addAssign(o.element(i.sub(K(e))));
|
|
920
928
|
}), Qn(), o.element(i).assign(t), Qn();
|
|
921
929
|
}
|
|
922
|
-
let c = o.element(K(
|
|
930
|
+
let c = o.element(K(Qi - 1)).toVar(), l = o.element(i).toVar();
|
|
923
931
|
Qn();
|
|
924
932
|
let u = B(Bn(l, c.mul(r)).sub(B(l.sub(a), c.mul(n))), 0);
|
|
925
|
-
o.element(i).assign(u), s.element(i).assign(u.mul(L(i).add(.5).mul(
|
|
926
|
-
for (let e =
|
|
933
|
+
o.element(i).assign(u), s.element(i).assign(u.mul(L(i).add(.5).mul(ea).add($i))), Qn();
|
|
934
|
+
for (let e = Qi >> 1; e > 0; e >>= 1) F(i.lessThan(K(e)), () => {
|
|
927
935
|
o.element(i).addAssign(o.element(i.add(K(e)))), s.element(i).addAssign(s.element(i.add(K(e))));
|
|
928
936
|
}), Qn();
|
|
929
937
|
F(i.equal(K(0)), () => {
|
|
930
938
|
let e = o.element(K(0));
|
|
931
|
-
t.element(K(0)).assign(Y(s.element(K(0)).div(B(e, 1e-6)), c.div(
|
|
939
|
+
t.element(K(0)).assign(Y(s.element(K(0)).div(B(e, 1e-6)), c.div(na), e.div(na), 1));
|
|
932
940
|
});
|
|
933
941
|
})().compute([
|
|
934
942
|
1,
|
|
935
943
|
1,
|
|
936
944
|
1
|
|
937
945
|
], [
|
|
938
|
-
|
|
946
|
+
Qi,
|
|
939
947
|
1,
|
|
940
948
|
1
|
|
941
949
|
]);
|
|
@@ -947,7 +955,7 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
947
955
|
if (!this.enabled) return;
|
|
948
956
|
let t = e.getState("pathtracer:samples") ?? 0;
|
|
949
957
|
if (this._accumulating = t >= 2, !this._pending) {
|
|
950
|
-
let n = this._meteredAt, r = this._stale || this._targetEV === null || n.restarts !== this._restarts || t - n.samples >=
|
|
958
|
+
let n = this._meteredAt, r = this._stale || this._targetEV === null || n.restarts !== this._restarts || t - n.samples >= ya(t), i = t < this.holdSamples && this._targetEV !== null && !this._stale;
|
|
951
959
|
r && !i && this._meter(e, t);
|
|
952
960
|
}
|
|
953
961
|
e.setState("autoexposure:value", this.renderer.toneMappingExposure), e.setState("autoexposure:avgLuminance", this.luminance);
|
|
@@ -962,13 +970,13 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
962
970
|
if (!n || r < 1 || i < 1 || this._disposed) return null;
|
|
963
971
|
this._meteredAt.restarts = this._restarts, this._meteredAt.samples = t, this._stale = !1;
|
|
964
972
|
let a = et();
|
|
965
|
-
a !== this._workingMatrix && (this._workingMatrix = a,
|
|
966
|
-
let o = Math.min(
|
|
973
|
+
a !== this._workingMatrix && (this._workingMatrix = a, va(a, this._lumWeightsU.value));
|
|
974
|
+
let o = Math.min(Yi, Math.max(1, Math.floor(r / Xi))), s = Math.min(Yi, Math.max(1, Math.floor(i / Xi))), c = r / o * (i / s);
|
|
967
975
|
this._gridXU.value = o, this._gridYU.value = s, this._kernels[0].dispatchSize = [
|
|
968
976
|
o,
|
|
969
977
|
s,
|
|
970
978
|
1
|
|
971
|
-
], this._strideU.value = Math.max(1, Math.round(Math.sqrt(c /
|
|
979
|
+
], this._strideU.value = Math.max(1, Math.round(Math.sqrt(c / ra))), this._widthU.value = r, this._heightU.value = i, this._backdropModeU.value = ha[e.getState("pathtracer:backdrop")] ?? ha.transparent, this._updateMeteringPattern(r / i), this._inputNode.value = n, this.renderer.compute(this._kernels);
|
|
972
980
|
let l = this._generation, u = {
|
|
973
981
|
restarts: this._restarts,
|
|
974
982
|
moves: this._viewMoves
|
|
@@ -984,7 +992,7 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
984
992
|
let t = this._falloffU.value, n = this._pointU.value;
|
|
985
993
|
if (this.metering === "average") t.set(0, 0);
|
|
986
994
|
else if (this.metering === "spot") {
|
|
987
|
-
t.set(
|
|
995
|
+
t.set(ia * e * e, ia), n.copy(this.meteringPoint);
|
|
988
996
|
return;
|
|
989
997
|
} else t.set(this.centerWeight, this.centerWeight);
|
|
990
998
|
n.set(.5, .5);
|
|
@@ -993,25 +1001,25 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
993
1001
|
let [n, r, i] = e;
|
|
994
1002
|
if (!this.enabled || !(r > 0 && i > 0) || !Number.isFinite(n)) return null;
|
|
995
1003
|
let a = this._viewEV;
|
|
996
|
-
this._meteredLog2 = n, this._viewEV = Math.log2(this.keyValue) - n, this._roomEV === null ? this._roomEV = this._viewEV : t?.moves === this._landed?.moves ? this._roomEV += this._viewEV - a : this._movingUntil = this._clock +
|
|
997
|
-
let o = this._aim(), s = this._targetEV === null || Math.abs(o - this._targetEV) >
|
|
1004
|
+
this._meteredLog2 = n, this._viewEV = Math.log2(this.keyValue) - n, this._roomEV === null ? this._roomEV = this._viewEV : t?.moves === this._landed?.moves ? this._roomEV += this._viewEV - a : this._movingUntil = this._clock + ua, this._landed = t;
|
|
1005
|
+
let o = this._aim(), s = this._targetEV === null || Math.abs(o - this._targetEV) > oa;
|
|
998
1006
|
return this._targetEV = o, (s || this.settling) && this.onChange?.(), n;
|
|
999
1007
|
}
|
|
1000
1008
|
update(e = performance.now()) {
|
|
1001
|
-
let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3,
|
|
1009
|
+
let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3, ca), n = this.advance(t, this._accumulating);
|
|
1002
1010
|
return this._lastUpdate = this.settling || this._clock <= this._movingUntil ? e : null, n;
|
|
1003
1011
|
}
|
|
1004
1012
|
advance(e, t = !1) {
|
|
1005
1013
|
if (!this.enabled || this._targetEV === null) return !1;
|
|
1006
|
-
e > 0 && e !== Infinity && (this._clock += e, this._clock <= this._movingUntil && (this._roomEV += (this._viewEV - this._roomEV) * (1 - Math.exp(-Math.min(e,
|
|
1014
|
+
e > 0 && e !== Infinity && (this._clock += e, this._clock <= this._movingUntil && (this._roomEV += (this._viewEV - this._roomEV) * (1 - Math.exp(-Math.min(e, ca) / la)), this._targetEV = this._aim()));
|
|
1007
1015
|
let n = this._exposureEV;
|
|
1008
|
-
return this._snap || this.instant ? (this._exposureEV = this._targetEV, this._snap = !1) : (this._exposureEV = t ? n + (this._targetEV - n) * (1 - Math.exp(-e /
|
|
1016
|
+
return this._snap || this.instant ? (this._exposureEV = this._targetEV, this._snap = !1) : (this._exposureEV = t ? n + (this._targetEV - n) * (1 - Math.exp(-e / sa)) : ga(n, this._targetEV, e, this.adaptSpeedBright, this.adaptSpeedDark), Math.abs(this._targetEV - this._exposureEV) <= oa && (this._exposureEV = this._targetEV)), this._exposureEV === n ? !1 : (this._apply(), !0);
|
|
1009
1017
|
}
|
|
1010
1018
|
_inRange(e) {
|
|
1011
1019
|
return Math.min(Math.max(e, Math.log2(this.minExposure)), Math.log2(this.maxExposure));
|
|
1012
1020
|
}
|
|
1013
1021
|
_aim() {
|
|
1014
|
-
return this._inRange(
|
|
1022
|
+
return this._inRange(_a(this._roomEV, this._viewEV, this.strength));
|
|
1015
1023
|
}
|
|
1016
1024
|
noteViewChanged() {
|
|
1017
1025
|
this._viewMoves++;
|
|
@@ -1054,7 +1062,7 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
1054
1062
|
}
|
|
1055
1063
|
updateParameters(e) {
|
|
1056
1064
|
let t = e.metering;
|
|
1057
|
-
t !== void 0 &&
|
|
1065
|
+
t !== void 0 && Ji.includes(t) && (this.metering = t), e.meteringPoint && this.meteringPoint.set(e.meteringPoint.x, e.meteringPoint.y);
|
|
1058
1066
|
for (let t of [
|
|
1059
1067
|
"keyValue",
|
|
1060
1068
|
"minExposure",
|
|
@@ -1077,32 +1085,32 @@ var fa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, pa = class extends k {
|
|
|
1077
1085
|
for (let e of this._kernels) e.dispose();
|
|
1078
1086
|
this._readback.dispose(), this._inputNode.dispose();
|
|
1079
1087
|
}
|
|
1080
|
-
},
|
|
1088
|
+
}, xa = {
|
|
1081
1089
|
localExposure: !1,
|
|
1082
1090
|
localExposureHighlightContrast: .6,
|
|
1083
1091
|
localExposureShadowContrast: 1,
|
|
1084
1092
|
localExposureDetailStrength: 1
|
|
1085
|
-
},
|
|
1093
|
+
}, Sa = 128, Ca = (Sa / 2) ** 2, $ = 32, wa = -16, Ta = 16, Ea = -40, Da = 40, Oa = 256, ka = 32, Aa = .6, ja = 50, Ma = Math.log2(.18), Na = .999, Pa = 2 ** -24, Fa = Math.ceil(re / Sa), Ia = Math.ceil(re / ka), La = [
|
|
1086
1094
|
.2126,
|
|
1087
1095
|
.7152,
|
|
1088
1096
|
.0722
|
|
1089
|
-
],
|
|
1090
|
-
function
|
|
1091
|
-
let s = Math.min(Math.log2(Math.max(a,
|
|
1097
|
+
], Ra = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, za = (e, t, n) => Math.min(Math.max(e, t), n);
|
|
1098
|
+
function Ba(e, t, n, r, i, a, o) {
|
|
1099
|
+
let s = Math.min(Math.log2(Math.max(a, Pa)), Da), c = e[6], l = e[7], u = za(r * e[2] - .5, 0, c - 1), d = za(i * e[3] - .5, 0, l - 1), f = Math.floor(u), p = Math.floor(d), m = Math.min(f + 1, c - 1), h = Math.min(p + 1, l - 1), g = u - f, _ = d - p, v = (e) => n[e * c + f] + (n[e * c + m] - n[e * c + f]) * g, y = v(p) + (v(h) - v(p)) * _, b = e[4], x = e[5], S = za(r * e[0] - .5, 0, b - 1), C = za(i * e[1] - .5, 0, x - 1), w = za((s + e[8] - wa) / (Ta - wa), 0, 1) * ($ - 1), T = Math.floor(S), E = Math.floor(C), D = Math.floor(w), O = S - T, k = C - E, ee = w - D, te = 0, ne = 0;
|
|
1092
1100
|
for (let e = 0; e < 8; e++) {
|
|
1093
|
-
let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ?
|
|
1094
|
-
|
|
1101
|
+
let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? O : 1 - O) * (r ? k : 1 - k) * (i ? ee : 1 - ee), o = ((Math.min(E + r, x - 1) * b + Math.min(T + n, b - 1)) * $ + Math.min(D + i, $ - 1)) * 2;
|
|
1102
|
+
te += t[o] * a, ne += t[o + 1] * a;
|
|
1095
1103
|
}
|
|
1096
|
-
let
|
|
1097
|
-
return 2 ** (e[13] + (
|
|
1104
|
+
let A = ne * Ca < .001 ? y : te / ne, j = A + (y - A) * e[12] + o, re = s + o, M = j > e[13] ? e[9] : e[10];
|
|
1105
|
+
return 2 ** (e[13] + (j - e[13]) * M + (re - j) * e[11] - re);
|
|
1098
1106
|
}
|
|
1099
|
-
var
|
|
1107
|
+
var Va = `
|
|
1100
1108
|
@group(1) @binding(0) var<storage, read> leGrid: array<vec2<f32>>;
|
|
1101
1109
|
@group(1) @binding(1) var<storage, read> leBlur: array<f32>;
|
|
1102
1110
|
@group(1) @binding(2) var<uniform> le: array<vec4<f32>, 4>;
|
|
1103
1111
|
|
|
1104
1112
|
fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
1105
|
-
let logL = min( log2( max( dot( linear, vec3<f32>( ${
|
|
1113
|
+
let logL = min( log2( max( dot( linear, vec3<f32>( ${La.join(", ")} ) ), ${Pa} ) ), ${Da}.0 );
|
|
1106
1114
|
let logExposure = log2( exposure );
|
|
1107
1115
|
|
|
1108
1116
|
let bs = vec2<i32>( le[ 1 ].zw );
|
|
@@ -1116,7 +1124,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1116
1124
|
|
|
1117
1125
|
let cs = vec2<i32>( le[ 1 ].xy );
|
|
1118
1126
|
let gp = clamp( uv * le[ 0 ].xy - 0.5, vec2<f32>( 0.0 ), vec2<f32>( cs - 1 ) );
|
|
1119
|
-
let gz = clamp( ( logL + le[ 2 ].x - (${
|
|
1127
|
+
let gz = clamp( ( logL + le[ 2 ].x - (${wa}.0) ) / ${Ta - wa}.0, 0.0, 1.0 ) * ${$ - 1}.0;
|
|
1120
1128
|
let g0 = vec3<i32>( vec2<i32>( floor( gp ) ), i32( floor( gz ) ) );
|
|
1121
1129
|
let gf = vec3<f32>( gp - floor( gp ), gz - floor( gz ) );
|
|
1122
1130
|
var acc = vec2<f32>( 0.0 );
|
|
@@ -1127,18 +1135,18 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1127
1135
|
acc += leGrid[ ( c.y * cs.x + c.x ) * ${$} + c.z ] * ( wv.x * wv.y * wv.z );
|
|
1128
1136
|
}
|
|
1129
1137
|
|
|
1130
|
-
let bilateral = select( acc.x / acc.y, blurred, acc.y * ${
|
|
1138
|
+
let bilateral = select( acc.x / acc.y, blurred, acc.y * ${Ca}.0 < 1e-3 );
|
|
1131
1139
|
let base = mix( bilateral, blurred, le[ 3 ].x ) + logExposure;
|
|
1132
1140
|
let y = logL + logExposure;
|
|
1133
1141
|
let contrast = select( le[ 2 ].z, le[ 2 ].y, base > le[ 3 ].y );
|
|
1134
1142
|
return exp2( le[ 3 ].y + ( base - le[ 3 ].y ) * contrast + ( y - base ) * le[ 2 ].w - y );
|
|
1135
1143
|
}
|
|
1136
|
-
`,
|
|
1144
|
+
`, Ha = class extends A {
|
|
1137
1145
|
constructor(e, t = {}) {
|
|
1138
1146
|
super("LocalExposure", {
|
|
1139
1147
|
...t,
|
|
1140
|
-
executionMode:
|
|
1141
|
-
}), this.renderer = e, this.highlightContrast = t.highlightContrast ??
|
|
1148
|
+
executionMode: j.ALWAYS
|
|
1149
|
+
}), this.renderer = e, this.highlightContrast = t.highlightContrast ?? xa.localExposureHighlightContrast, this.shadowContrast = t.shadowContrast ?? xa.localExposureShadowContrast, this.detailStrength = t.detailStrength ?? xa.localExposureDetailStrength, this.onChange = null, this._grid = Mn(Fa * Fa * $, "vec2"), this._blur = Mn(Ia * Ia, "float"), this._blurSource = Mn(Ia * Ia, "vec2"), this._blurTmp = Mn(Ia * Ia, "vec2"), this._inputNode = new Cn(), this._widthU = q(1, "int"), this._heightU = q(1, "int"), this._cellsXU = q(1, "int"), this._blurWU = q(1, "int"), this._blurHU = q(1, "int"), this._radiusU = q(1), this._logExposureU = q(0), this._sceneOnlyU = q(0, "int"), this._p = [
|
|
1142
1150
|
new zr(),
|
|
1143
1151
|
new zr(),
|
|
1144
1152
|
new zr(),
|
|
@@ -1154,13 +1162,13 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1154
1162
|
}, this._stale = !1, this._paramsBuffer = null, this._disposed = !1;
|
|
1155
1163
|
}
|
|
1156
1164
|
_buildGridKernel() {
|
|
1157
|
-
let e = this._inputNode, t = this._grid, n = this._widthU, r = this._heightU, i = this._cellsXU, a = this._logExposureU, o = this._sceneOnlyU.greaterThan(R(0)), s = Y(...
|
|
1165
|
+
let e = this._inputNode, t = this._grid, n = this._widthU, r = this._heightU, i = this._cellsXU, a = this._logExposureU, o = this._sceneOnlyU.greaterThan(R(0)), s = Y(...La, 0).xyz;
|
|
1158
1166
|
return Tn(() => {
|
|
1159
1167
|
let c = z.y.mul(K(16)).add(z.x), l = Zn("uint", $).toAtomic(), u = Zn("uint", $).toAtomic();
|
|
1160
1168
|
F(c.lessThan(K($)), () => {
|
|
1161
1169
|
jn(l.element(c), K(0)), jn(u.element(c), K(0));
|
|
1162
1170
|
}), Qn();
|
|
1163
|
-
let d = R(X.x).mul(R(
|
|
1171
|
+
let d = R(X.x).mul(R(Sa)).add(R(z.x).mul(R(8))), f = R(X.y).mul(R(Sa)).add(R(z.y).mul(R(8)));
|
|
1164
1172
|
En({
|
|
1165
1173
|
start: R(0),
|
|
1166
1174
|
end: R(8),
|
|
@@ -1179,16 +1187,16 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1179
1187
|
}, ({ tx: i }) => {
|
|
1180
1188
|
let c = d.add(i), p = f.add(t);
|
|
1181
1189
|
F(c.lessThan(n).and(p.lessThan(r)), () => {
|
|
1182
|
-
let t = Bn(c.add(R(1)), n.sub(R(1))), i = Bn(p.add(R(1)), r.sub(R(1))), d = W(e, Rn(c, p)).toVar(), f = W(e, Rn(t, p)).toVar(), m = W(e, Rn(c, i)).toVar(), h = W(e, Rn(t, i)).toVar(), g = (e) => U(o.and(e.w.lessThan(
|
|
1190
|
+
let t = Bn(c.add(R(1)), n.sub(R(1))), i = Bn(p.add(R(1)), r.sub(R(1))), d = W(e, Rn(c, p)).toVar(), f = W(e, Rn(t, p)).toVar(), m = W(e, Rn(c, i)).toVar(), h = W(e, Rn(t, i)).toVar(), g = (e) => U(o.and(e.w.lessThan(Na)), L(0), L(1)), _ = g(d), v = g(f), y = g(m), b = g(h), x = _.add(v).add(y).add(b).toVar(), S = I(d.xyz, s).mul(_).add(I(f.xyz, s).mul(v)).add(I(m.xyz, s).mul(y)).add(I(h.xyz, s).mul(b)).div(B(x, 1e-6)).toVar(), C = x.mul(.25).toVar();
|
|
1183
1191
|
F(Fn(S).bitAnd(K(2139095040)).notEqual(K(2139095040)).and(x.greaterThan(0)), () => {
|
|
1184
|
-
let e = zn(B(S,
|
|
1185
|
-
kn(l.element(n), K(s.mul(o).add(.5))), kn(u.element(n), K(o.mul(
|
|
1192
|
+
let e = zn(B(S, Pa)).clamp(Ea, Da).toVar(), t = e.add(a).sub(wa).div(Ta - wa).clamp(0, 1).mul($ - 1).toVar(), n = K(In(t)).min(K($ - 1)), r = n.add(K(1)).min(K($ - 1)), i = t.sub(In(t)).mul(C), o = L(1).sub(t.sub(In(t))).mul(C), s = e.sub(Ea).mul(Oa);
|
|
1193
|
+
kn(l.element(n), K(s.mul(o).add(.5))), kn(u.element(n), K(o.mul(Oa).add(.5))), kn(l.element(r), K(s.mul(i).add(.5))), kn(u.element(r), K(i.mul(Oa).add(.5)));
|
|
1186
1194
|
});
|
|
1187
1195
|
});
|
|
1188
1196
|
});
|
|
1189
1197
|
}), Qn(), F(c.lessThan(K($)), () => {
|
|
1190
|
-
let e = L(An(u.element(c))).div(
|
|
1191
|
-
t.element(r.mul(K($)).add(c)).assign(J(n, e).div(
|
|
1198
|
+
let e = L(An(u.element(c))).div(Oa), n = L(An(l.element(c))).div(Oa).add(e.mul(Ea)), r = K(X.y).mul(K(i)).add(K(X.x));
|
|
1199
|
+
t.element(r.mul(K($)).add(c)).assign(J(n, e).div(Ca));
|
|
1192
1200
|
});
|
|
1193
1201
|
})().compute([
|
|
1194
1202
|
1,
|
|
@@ -1201,12 +1209,12 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1201
1209
|
]);
|
|
1202
1210
|
}
|
|
1203
1211
|
_buildBlurSourceKernel() {
|
|
1204
|
-
let e = this._inputNode, t = this._blurSource, n = this._widthU, r = this._heightU, i = this._blurWU, a = this._sceneOnlyU.greaterThan(R(0)), o = Y(...
|
|
1212
|
+
let e = this._inputNode, t = this._blurSource, n = this._widthU, r = this._heightU, i = this._blurWU, a = this._sceneOnlyU.greaterThan(R(0)), o = Y(...La, 0).xyz;
|
|
1205
1213
|
return Tn(() => {
|
|
1206
|
-
let s = z.y.mul(K(8)).add(z.x), c = R(X.x).mul(R(
|
|
1214
|
+
let s = z.y.mul(K(8)).add(z.x), c = R(X.x).mul(R(ka)), l = R(X.y).mul(R(ka)), u = L(0).toVar(), d = L(0).toVar(), f = L(0).toVar();
|
|
1207
1215
|
En({
|
|
1208
1216
|
start: R(z.y),
|
|
1209
|
-
end: R(
|
|
1217
|
+
end: R(ka),
|
|
1210
1218
|
type: "int",
|
|
1211
1219
|
condition: "<",
|
|
1212
1220
|
update: 8,
|
|
@@ -1214,7 +1222,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1214
1222
|
}, ({ by: t }) => {
|
|
1215
1223
|
En({
|
|
1216
1224
|
start: R(z.x),
|
|
1217
|
-
end: R(
|
|
1225
|
+
end: R(ka),
|
|
1218
1226
|
type: "int",
|
|
1219
1227
|
condition: "<",
|
|
1220
1228
|
update: 8,
|
|
@@ -1222,7 +1230,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1222
1230
|
}, ({ bx: i }) => {
|
|
1223
1231
|
let s = c.add(i), p = l.add(t);
|
|
1224
1232
|
F(s.lessThan(n).and(p.lessThan(r)), () => {
|
|
1225
|
-
let t = W(e, Rn(s, p)).toVar(), n = I(t.xyz, o).toVar(), r = Fn(n).bitAnd(K(2139095040)).notEqual(K(2139095040)), i = U(a.and(t.w.lessThan(
|
|
1233
|
+
let t = W(e, Rn(s, p)).toVar(), n = I(t.xyz, o).toVar(), r = Fn(n).bitAnd(K(2139095040)).notEqual(K(2139095040)), i = U(a.and(t.w.lessThan(Na)), L(0), L(1));
|
|
1226
1234
|
u.addAssign(U(r, n.max(0).mul(i), L(0))), d.addAssign(U(r, i, L(0))), f.addAssign(U(r, L(1), L(0)));
|
|
1227
1235
|
});
|
|
1228
1236
|
});
|
|
@@ -1233,7 +1241,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1233
1241
|
p.element(s).addAssign(p.element(s.add(K(e)))), m.element(s).addAssign(m.element(s.add(K(e)))), h.element(s).addAssign(h.element(s.add(K(e))));
|
|
1234
1242
|
}), Qn();
|
|
1235
1243
|
F(s.equal(K(0)), () => {
|
|
1236
|
-
let e = zn(B(p.element(K(0)).div(B(m.element(K(0)), 1)),
|
|
1244
|
+
let e = zn(B(p.element(K(0)).div(B(m.element(K(0)), 1)), Pa)).clamp(Ea, Da), n = U(a, m.element(K(0)).div(B(h.element(K(0)), 1)), L(1)).toVar();
|
|
1237
1245
|
t.element(K(R(X.y).mul(i).add(R(X.x)))).assign(J(e.mul(n), n));
|
|
1238
1246
|
});
|
|
1239
1247
|
})().compute([
|
|
@@ -1285,14 +1293,14 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1285
1293
|
render(e) {
|
|
1286
1294
|
if (!this.enabled) return;
|
|
1287
1295
|
let t = e.getState("pathtracer:samples") ?? 0, n = this._builtAt;
|
|
1288
|
-
(this._stale || !this._built || n.restarts !== this._restarts || t - n.samples >=
|
|
1296
|
+
(this._stale || !this._built || n.restarts !== this._restarts || t - n.samples >= Ra(t)) && this.build(e);
|
|
1289
1297
|
}
|
|
1290
1298
|
build(e = this.context) {
|
|
1291
1299
|
let t = e?.getTexture("pathtracer:color"), n = t?.image?.width | 0, r = t?.image?.height | 0;
|
|
1292
1300
|
if (!t || n < 1 || r < 1 || this._disposed) return !1;
|
|
1293
1301
|
this._builtAt.restarts = this._restarts, this._builtAt.samples = e.getState("pathtracer:samples") ?? 0, this._stale = !1;
|
|
1294
|
-
let i = Math.min(
|
|
1295
|
-
return this._inputNode.value = t, this._widthU.value = n, this._heightU.value = r, this._cellsXU.value = i, this._blurWU.value = o, this._blurHU.value = s, this._radiusU.value = Math.max(1,
|
|
1302
|
+
let i = Math.min(Fa, Math.ceil(n / Sa)), a = Math.min(Fa, Math.ceil(r / Sa)), o = Math.min(Ia, Math.ceil(n / ka)), s = Math.min(Ia, Math.ceil(r / ka)), c = Math.log2(Math.max(this.renderer.toneMappingExposure, 1e-6));
|
|
1303
|
+
return this._inputNode.value = t, this._widthU.value = n, this._heightU.value = r, this._cellsXU.value = i, this._blurWU.value = o, this._blurHU.value = s, this._radiusU.value = Math.max(1, ja / 100 * o), this._logExposureU.value = c, this._sceneOnlyU.value = +(e.getState("pathtracer:backdrop") === "color"), this._kernels[0].dispatchSize = [
|
|
1296
1304
|
i,
|
|
1297
1305
|
a,
|
|
1298
1306
|
1
|
|
@@ -1305,10 +1313,10 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1305
1313
|
Math.ceil(s / 8),
|
|
1306
1314
|
1
|
|
1307
1315
|
], this.renderer.compute(this._kernels), this._params.set([
|
|
1308
|
-
n / ha,
|
|
1309
|
-
r / ha,
|
|
1310
1316
|
n / Sa,
|
|
1311
1317
|
r / Sa,
|
|
1318
|
+
n / ka,
|
|
1319
|
+
r / ka,
|
|
1312
1320
|
i,
|
|
1313
1321
|
a,
|
|
1314
1322
|
o,
|
|
@@ -1318,7 +1326,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1318
1326
|
}
|
|
1319
1327
|
_writeParams() {
|
|
1320
1328
|
let e = this._params;
|
|
1321
|
-
e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] =
|
|
1329
|
+
e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] = Aa, e[13] = Ma;
|
|
1322
1330
|
for (let t = 0; t < 4; t++) this._p[t].value.fromArray(e, t * 4);
|
|
1323
1331
|
this.onChange?.();
|
|
1324
1332
|
}
|
|
@@ -1337,15 +1345,15 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1337
1345
|
this.enabled !== e && (this.enabled = e, this._stale = !0, this.onChange?.());
|
|
1338
1346
|
}
|
|
1339
1347
|
gainNode(e, t) {
|
|
1340
|
-
let n = Kn(this._grid.value, "vec2",
|
|
1348
|
+
let n = Kn(this._grid.value, "vec2", Fa * Fa * $).toReadOnly(), r = Kn(this._blur.value, "float", Ia * Ia).toReadOnly(), [i, a, o, s] = this._p;
|
|
1341
1349
|
return Tn(([e, t]) => {
|
|
1342
|
-
let c = zn(B(I(e, Y(...
|
|
1350
|
+
let c = zn(B(I(e, Y(...La, 0).xyz), Pa)).min(Da).toVar(), l = zn(qn).toVar(), u = Rn(a.zw), d = t.mul(i.zw).sub(.5).clamp(J(0), J(u.sub(R(1)))).toVar(), f = Rn(In(d)).toVar(), p = f.add(R(1)).min(u.sub(R(1))).toVar(), m = d.sub(In(d)).toVar(), h = (e, t) => r.element(K(t.mul(u.x).add(e))), g = V(V(h(f.x, f.y), h(p.x, f.y), m.x), V(h(f.x, p.y), h(p.x, p.y), m.x), m.y).toVar(), _ = Rn(a.xy), v = t.mul(i.xy).sub(.5).clamp(J(0), J(_.sub(R(1)))).toVar(), y = c.add(o.x).sub(wa).div(Ta - wa).clamp(0, 1).mul($ - 1).toVar(), b = R(In(v.x)), x = R(In(v.y)), S = R(In(y)), C = v.x.sub(In(v.x)), w = v.y.sub(In(v.y)), T = y.sub(In(y)), E = J(0).toVar();
|
|
1343
1351
|
for (let e = 0; e < 8; e++) {
|
|
1344
1352
|
let t = e & 1, r = e >> 1 & 1, i = e >> 2, a = (t ? C : C.oneMinus()).mul(r ? w : w.oneMinus()).mul(i ? T : T.oneMinus()), o = b.add(R(t)).min(_.x.sub(R(1))), s = x.add(R(r)).min(_.y.sub(R(1))), c = S.add(R(i)).min(R($ - 1));
|
|
1345
1353
|
E.addAssign(n.element(K(s.mul(_.x).add(o).mul(R($)).add(c))).mul(a));
|
|
1346
1354
|
}
|
|
1347
|
-
let D = V(U(E.y.mul(
|
|
1348
|
-
return Pn(s.y.add(D.sub(s.y).mul(
|
|
1355
|
+
let D = V(U(E.y.mul(Ca).lessThan(.001), g, E.x.div(E.y)), g, s.x).add(l).toVar(), O = c.add(l), k = U(D.greaterThan(s.y), o.y, o.z);
|
|
1356
|
+
return Pn(s.y.add(D.sub(s.y).mul(k)).add(O.sub(D).mul(o.w)).sub(O));
|
|
1349
1357
|
})(e, t);
|
|
1350
1358
|
}
|
|
1351
1359
|
toneGain() {
|
|
@@ -1360,7 +1368,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1360
1368
|
let r = this._params.slice(), i = () => Promise.all([this.renderer.getArrayBufferAsync(this._grid.value), this.renderer.getArrayBufferAsync(this._blur.value)]);
|
|
1361
1369
|
return {
|
|
1362
1370
|
key: "local-exposure",
|
|
1363
|
-
wgsl:
|
|
1371
|
+
wgsl: Va,
|
|
1364
1372
|
device: e.device,
|
|
1365
1373
|
entries: [
|
|
1366
1374
|
{
|
|
@@ -1378,7 +1386,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1378
1386
|
],
|
|
1379
1387
|
cpu: async () => {
|
|
1380
1388
|
let [e, t] = await i(), n = new Float32Array(e), a = new Float32Array(t);
|
|
1381
|
-
return (e, t, i, o) =>
|
|
1389
|
+
return (e, t, i, o) => Ba(r, n, a, e, t, i, o);
|
|
1382
1390
|
},
|
|
1383
1391
|
copyTo: async (e) => {
|
|
1384
1392
|
let [t, n] = await i(), a = [
|
|
@@ -1395,7 +1403,7 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1395
1403
|
});
|
|
1396
1404
|
return {
|
|
1397
1405
|
key: "local-exposure",
|
|
1398
|
-
wgsl:
|
|
1406
|
+
wgsl: Va,
|
|
1399
1407
|
device: e,
|
|
1400
1408
|
entries: a.map((e, t) => ({
|
|
1401
1409
|
binding: t,
|
|
@@ -1413,14 +1421,14 @@ fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
|
1413
1421
|
for (let e of this._kernels) e.dispose();
|
|
1414
1422
|
this._inputNode.dispose(), this._paramsBuffer?.destroy(), this._paramsBuffer = null;
|
|
1415
1423
|
}
|
|
1416
|
-
},
|
|
1417
|
-
function
|
|
1418
|
-
return
|
|
1424
|
+
}, Ua = new Q(), Wa = new Q();
|
|
1425
|
+
function Ga(e, t) {
|
|
1426
|
+
return Wa.subVectors(e, t.position).dot(t.getWorldDirection(Ua));
|
|
1419
1427
|
}
|
|
1420
|
-
function
|
|
1421
|
-
return n ? e.distance :
|
|
1428
|
+
function Ka(e, t, n = !1) {
|
|
1429
|
+
return n ? e.distance : Ga(e.point, t);
|
|
1422
1430
|
}
|
|
1423
|
-
var
|
|
1431
|
+
var qa = class extends ur {
|
|
1424
1432
|
constructor({ scene: e, camera: t, canvas: n, assetLoader: r, pathTracer: i, floorPlane: a, isGeometryOnDisk: o = null }) {
|
|
1425
1433
|
super(), this.scene = e, this.isGeometryOnDisk = o, this.camera = t, this.canvas = n, this.assetLoader = r, this.pathTracer = i, this.floorPlane = a, this.raycaster = new Ar(), this.focusMode = !1, this.focusPointIndicator = null, this.afPointPlacementMode = !1, this.handleAFPointClick = this.handleAFPointClick.bind(this), this.selectedObject = null, this.selectMode = !1, this.clickTimeout = null, this.mouseDownPosition = null, this.dragThreshold = 5, this.handleFocusClick = this.handleFocusClick.bind(this), this.handleSelectClick = this.handleSelectClick.bind(this), this.handleSelectDoubleClick = this.handleSelectDoubleClick.bind(this), this.handleMouseDown = this.handleMouseDown.bind(this), this.handleMouseUp = this.handleMouseUp.bind(this), this.handleContextMenu = this.handleContextMenu.bind(this), this.handleContextPointerDown = this.handleContextPointerDown.bind(this), this.handleContextPointerUp = this.handleContextPointerUp.bind(this), this.contextPointerDownPosition = null, this.canvas.addEventListener("pointerdown", this.handleContextPointerDown), this.canvas.addEventListener("pointerup", this.handleContextPointerUp), this.canvas.addEventListener("contextmenu", this.handleContextMenu), this._overlayManager = null, this._transformManager = null, this._appDispatch = null, this._orbitControls = null, this._helperScene = null;
|
|
1426
1434
|
}
|
|
@@ -1454,7 +1462,7 @@ var Ba = class extends ur {
|
|
|
1454
1462
|
this.raycaster.setFromCamera(t, this.camera);
|
|
1455
1463
|
let n = this._intersectScene();
|
|
1456
1464
|
if (n.length > 0) {
|
|
1457
|
-
let e = n[0], t = this.pathTracer?.cameraProjection?.value === Oe.equirectangular, r =
|
|
1465
|
+
let e = n[0], t = this.pathTracer?.cameraProjection?.value === Oe.equirectangular, r = Ka(e, this.camera, t);
|
|
1458
1466
|
this.showFocusPoint(e.point), this.toggleFocusMode(), this.dispatchEvent({
|
|
1459
1467
|
type: "focusChanged",
|
|
1460
1468
|
distance: r / this.assetLoader.getSceneScale(),
|
|
@@ -1595,7 +1603,7 @@ var Ba = class extends ur {
|
|
|
1595
1603
|
}
|
|
1596
1604
|
_intersectScene() {
|
|
1597
1605
|
let e = this.camera.userData?.clipStart ?? 0;
|
|
1598
|
-
return this.raycaster.near = e > 0 && !this.camera.isOrthographicCamera ? e / Math.max(this.raycaster.ray.direction.dot(this.camera.getWorldDirection(
|
|
1606
|
+
return this.raycaster.near = e > 0 && !this.camera.isOrthographicCamera ? e / Math.max(this.raycaster.ray.direction.dot(this.camera.getWorldDirection(Ua)), 1e-4) : 0, this.isGeometryOnDisk?.() ? [] : this.raycaster.intersectObjects(this.scene.children, !0);
|
|
1599
1607
|
}
|
|
1600
1608
|
pickSurface(e, t) {
|
|
1601
1609
|
return this.raycaster.setFromCamera({
|
|
@@ -1666,7 +1674,7 @@ var Ba = class extends ur {
|
|
|
1666
1674
|
dispose() {
|
|
1667
1675
|
this.canvas.removeEventListener("click", this.handleAFPointClick), this.canvas.removeEventListener("click", this.handleFocusClick), this.canvas.removeEventListener("mousedown", this.handleMouseDown), this.canvas.removeEventListener("mouseup", this.handleMouseUp), this.canvas.removeEventListener("click", this.handleSelectClick), this.canvas.removeEventListener("dblclick", this.handleSelectDoubleClick), this.canvas.removeEventListener("contextmenu", this.handleContextMenu), this.canvas.removeEventListener("pointerdown", this.handleContextPointerDown), this.canvas.removeEventListener("pointerup", this.handleContextPointerUp), this.clickTimeout &&= (clearTimeout(this.clickTimeout), null), this.mouseDownPosition = null, this.contextPointerDownPosition = null, this.focusPointIndicator &&= (this.scene.remove(this.focusPointIndicator), null), this.canvas.style.cursor = "auto", this.scene = null, this.camera = null, this.canvas = null, this.assetLoader = null, this.pathTracer = null, this.floorPlane = null, this.raycaster = null;
|
|
1668
1676
|
}
|
|
1669
|
-
},
|
|
1677
|
+
}, Ja = 8, Ya = 4, Xa = .25, Za = _r.degToRad(89), Qa = .25, $a = {
|
|
1670
1678
|
KeyD: [
|
|
1671
1679
|
1,
|
|
1672
1680
|
0,
|
|
@@ -1717,15 +1725,15 @@ var Ba = class extends ur {
|
|
|
1717
1725
|
0,
|
|
1718
1726
|
-1
|
|
1719
1727
|
]
|
|
1720
|
-
},
|
|
1728
|
+
}, eo = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=textbox], [role=combobox], [role=listbox], [role=menu], [role=menuitem]", to = (e) => e.shiftKey ? Ya : e.altKey ? Xa : 1, no = { type: "change" }, ro = { type: "start" }, io = new Q(), ao = new Q(), oo = new Q(), so = new Q(), co = new Or(), lo = class extends or {
|
|
1721
1729
|
constructor(e, t, n) {
|
|
1722
|
-
super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 /
|
|
1730
|
+
super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 / Ja, this._held = /* @__PURE__ */ new Set(), this._factor = 1, this._lastTime = 0, this._drag = null, this._onKeyDown = this._onKeyDown.bind(this), this._onKeyUp = this._onKeyUp.bind(this), this.release = this.release.bind(this), this._onPointerDown = this._onPointerDown.bind(this), this._onPointerMove = this._onPointerMove.bind(this), this._onPointerUp = this._onPointerUp.bind(this), t && this.connect(t);
|
|
1723
1731
|
}
|
|
1724
1732
|
get active() {
|
|
1725
1733
|
return this.enabled && this.orbit.enabled;
|
|
1726
1734
|
}
|
|
1727
1735
|
fitSpeed(e) {
|
|
1728
|
-
this.speed = (e > 0 ? e : 1) /
|
|
1736
|
+
this.speed = (e > 0 ? e : 1) / Ja;
|
|
1729
1737
|
}
|
|
1730
1738
|
connect(e) {
|
|
1731
1739
|
super.connect(e);
|
|
@@ -1745,34 +1753,34 @@ var Ba = class extends ur {
|
|
|
1745
1753
|
if (!this._held.size || !this.active) return !1;
|
|
1746
1754
|
let t = 0, n = 0, r = 0;
|
|
1747
1755
|
for (let e of this._held) {
|
|
1748
|
-
let [i, a, o] =
|
|
1756
|
+
let [i, a, o] = $a[e];
|
|
1749
1757
|
t += i, n += a, r += o;
|
|
1750
1758
|
}
|
|
1751
1759
|
if (!t && !n && !r) return !1;
|
|
1752
1760
|
let i = this.object;
|
|
1753
|
-
return
|
|
1761
|
+
return ao.set(1, 0, 0).applyQuaternion(i.quaternion), io.crossVectors(i.up, ao).normalize(), ao.crossVectors(io, i.up), oo.set(0, 0, 0).addScaledVector(ao, t).addScaledVector(io, n).addScaledVector(i.up, r).normalize().multiplyScalar(this.speed * this._factor * e), i.position.add(oo), this.orbit.target.add(oo), i.updateMatrixWorld(), this.dispatchEvent(no), !0;
|
|
1754
1762
|
}
|
|
1755
1763
|
_elapsed() {
|
|
1756
|
-
let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3,
|
|
1764
|
+
let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3, Qa);
|
|
1757
1765
|
return this._lastTime = e, t;
|
|
1758
1766
|
}
|
|
1759
1767
|
_look(e, t) {
|
|
1760
1768
|
let n = this.object, r = this.orbit.target, i = n.position.distanceTo(r) || 1, a = _r.degToRad(n.fov) / (this.domElement.clientHeight || 1);
|
|
1761
|
-
n.quaternion.premultiply(
|
|
1762
|
-
let o = Math.asin(_r.clamp(
|
|
1763
|
-
n.quaternion.multiply(
|
|
1769
|
+
n.quaternion.premultiply(co.setFromAxisAngle(n.up, e * a)), n.getWorldDirection(io);
|
|
1770
|
+
let o = Math.asin(_r.clamp(io.dot(n.up), -1, 1)), s = _r.clamp(o + t * a, -Za, Za);
|
|
1771
|
+
n.quaternion.multiply(co.setFromAxisAngle(so.set(1, 0, 0), s - o)), n.updateMatrixWorld(), r.copy(n.position).addScaledVector(n.getWorldDirection(io), i), this.dispatchEvent(no);
|
|
1764
1772
|
}
|
|
1765
1773
|
_onKeyDown(e) {
|
|
1766
|
-
if (!(!this.active || e.defaultPrevented || e.target?.closest?.(
|
|
1774
|
+
if (!(!this.active || e.defaultPrevented || e.target?.closest?.(eo))) {
|
|
1767
1775
|
if (e.metaKey || e.ctrlKey) {
|
|
1768
1776
|
this.release();
|
|
1769
1777
|
return;
|
|
1770
1778
|
}
|
|
1771
|
-
this._factor =
|
|
1779
|
+
this._factor = to(e), $a[e.code] && (e.preventDefault(), !this._held.has(e.code) && (this._held.add(e.code), this._held.size === 1 && (this._lastTime = performance.now(), this.dispatchEvent(ro))));
|
|
1772
1780
|
}
|
|
1773
1781
|
}
|
|
1774
1782
|
_onKeyUp(e) {
|
|
1775
|
-
this._factor =
|
|
1783
|
+
this._factor = to(e), this._held.delete(e.code);
|
|
1776
1784
|
}
|
|
1777
1785
|
release() {
|
|
1778
1786
|
this._held.clear(), this._factor = 1;
|
|
@@ -1793,18 +1801,18 @@ var Ba = class extends ur {
|
|
|
1793
1801
|
_onPointerUp(e) {
|
|
1794
1802
|
this._drag?.id === e.pointerId && (this._drag = null, this.domElement.releasePointerCapture?.(e.pointerId));
|
|
1795
1803
|
}
|
|
1796
|
-
},
|
|
1804
|
+
}, uo = {
|
|
1797
1805
|
autoFocusMode: "auto",
|
|
1798
1806
|
afScreenPoint: {
|
|
1799
1807
|
x: .5,
|
|
1800
1808
|
y: .5
|
|
1801
1809
|
},
|
|
1802
1810
|
afSmoothingFactor: .15
|
|
1803
|
-
},
|
|
1811
|
+
}, fo = .05, po = 10, mo = .5, ho = Object.freeze(new Q(1, 1, 1)), go = (e) => e?.isOrthographicCamera ? (e.top - e.bottom) / e.zoom : null, _o = class extends ur {
|
|
1804
1812
|
constructor(e) {
|
|
1805
1813
|
super();
|
|
1806
1814
|
let t = e.clientWidth, n = e.clientHeight;
|
|
1807
|
-
this.camera = new g(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new Vr(this.camera, e), this.controls.screenSpacePanning = !0, this.controls.zoomToCursor = !0, this.controls.saveState(), this._reportedOrthoHeight = null, this._reportOrthoHeight = this._reportOrthoHeight.bind(this), this.controls.addEventListener("change", this._reportOrthoHeight), this.walkControls = new
|
|
1815
|
+
this.camera = new g(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new Vr(this.camera, e), this.controls.screenSpacePanning = !0, this.controls.zoomToCursor = !0, this.controls.saveState(), this._reportedOrthoHeight = null, this._reportOrthoHeight = this._reportOrthoHeight.bind(this), this.controls.addEventListener("change", this._reportOrthoHeight), this.walkControls = new lo(this.camera, e, this.controls), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this._userCameraCounter = 0, this.autoFocusMode = uo.autoFocusMode, this.afScreenPoint = { ...uo.afScreenPoint }, this.afSmoothingFactor = uo.afSmoothingFactor, this._lastValidFocusDistance = null, this._smoothedFocusDistance = null, this._afPointDirty = !1, this._afSuspended = !1, this._afPick = null, this._defaultCameraState = null, this._onResize = null, this._onReset = null, this._getSettings = null, this._applySettings = null;
|
|
1808
1816
|
}
|
|
1809
1817
|
setCameras(e) {
|
|
1810
1818
|
this.cameras = e, this._userCameraCounter = 0, this.camera.userData.clipStart = 0, this.resetAutoFocus();
|
|
@@ -1864,11 +1872,11 @@ var Ba = class extends ur {
|
|
|
1864
1872
|
target: this.controls ? this.controls.target.clone() : null
|
|
1865
1873
|
}), this.currentCameraIndex = e, e === 0 && this._defaultCameraState) {
|
|
1866
1874
|
let e = this._defaultCameraState;
|
|
1867
|
-
this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ??
|
|
1875
|
+
this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ?? ho), this.camera.fov = e.fov, this.camera.near = e.near, this.camera.far = e.far, this.camera.userData.clipStart = 0, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls && e.target && (this.controls.target.copy(e.target), this.controls.update());
|
|
1868
1876
|
} else this._placeAt(this.cameras[e], t);
|
|
1869
1877
|
this.resetAutoFocus();
|
|
1870
1878
|
let a = this.cameras[e], o = a?.userData?.__rayzeeEffects;
|
|
1871
|
-
this._showOrthographic(o ? o.orthoHeight :
|
|
1879
|
+
this._showOrthographic(o ? o.orthoHeight : go(a)), this._applyEffects(o), n?.(), r?.(), this.dispatchEvent({
|
|
1872
1880
|
type: P.CAMERA_SWITCHED,
|
|
1873
1881
|
cameraIndex: e,
|
|
1874
1882
|
effects: this._captureEffects(),
|
|
@@ -1883,7 +1891,7 @@ var Ba = class extends ur {
|
|
|
1883
1891
|
return;
|
|
1884
1892
|
}
|
|
1885
1893
|
this._placeAt(e, this._getSettings?.("focusDistance"));
|
|
1886
|
-
let t =
|
|
1894
|
+
let t = go(e);
|
|
1887
1895
|
this.camera.orthographic && this._setView(!0, t ? t / 2 : this.camera.orthoHalfHeight), this._onReset?.();
|
|
1888
1896
|
}
|
|
1889
1897
|
_placeAt(e, t) {
|
|
@@ -1913,7 +1921,7 @@ var Ba = class extends ur {
|
|
|
1913
1921
|
}
|
|
1914
1922
|
}
|
|
1915
1923
|
get orthoHeight() {
|
|
1916
|
-
return
|
|
1924
|
+
return go(this.camera);
|
|
1917
1925
|
}
|
|
1918
1926
|
setOrthoHeight(e) {
|
|
1919
1927
|
e > 0 && (this._setView(this.camera.orthographic, e / 2), this._onReset?.());
|
|
@@ -2038,7 +2046,7 @@ var Ba = class extends ur {
|
|
|
2038
2046
|
for (let r of e.cameras ?? []) {
|
|
2039
2047
|
if (r.user) {
|
|
2040
2048
|
let e = r.orthographic ? new Tr(...r.frustum, r.near, r.far) : new Er(r.fov, r.aspect, r.near, r.far);
|
|
2041
|
-
e.name = r.name, e.zoom = r.zoom ?? 1, e.position.fromArray(r.position), e.quaternion.fromArray(r.quaternion), e.scale.fromArray(r.scale), e.updateProjectionMatrix(), e.updateMatrixWorld(!0), e.userData.__rayzeeUserCamera = !0, e.userData.__rayzeeEffects =
|
|
2049
|
+
e.name = r.name, e.zoom = r.zoom ?? 1, e.position.fromArray(r.position), e.quaternion.fromArray(r.quaternion), e.scale.fromArray(r.scale), e.updateProjectionMatrix(), e.updateMatrixWorld(!0), e.userData.__rayzeeUserCamera = !0, e.userData.__rayzeeEffects = ce(r.effects), r.clipStart > 0 && (e.userData.clipStart = r.clipStart), r.orbitTarget && (e.userData.__rayzeeOrbitTarget = new Q().fromArray(r.orbitTarget)), n.set(r.index, this.cameras.length), this.cameras.push(e);
|
|
2042
2050
|
continue;
|
|
2043
2051
|
}
|
|
2044
2052
|
let e = this.cameras[r.index];
|
|
@@ -2046,7 +2054,7 @@ var Ba = class extends ur {
|
|
|
2046
2054
|
t.push(r.name);
|
|
2047
2055
|
continue;
|
|
2048
2056
|
}
|
|
2049
|
-
n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects =
|
|
2057
|
+
n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = ce(r.effects));
|
|
2050
2058
|
}
|
|
2051
2059
|
this._userCameraCounter = this.cameras.filter((e) => e.userData?.__rayzeeUserCamera).length, this.currentCameraIndex = n.get(e.current) ?? 0;
|
|
2052
2060
|
let r = e.defaultView;
|
|
@@ -2109,14 +2117,14 @@ var Ba = class extends ur {
|
|
|
2109
2117
|
let c = i;
|
|
2110
2118
|
if (c?.isReady && c.renderMode?.value === 1 && c.frameCount > 0 && !c.isComplete) return;
|
|
2111
2119
|
let l = this._pickFocusPoint(c.resetCount), u;
|
|
2112
|
-
if (l) u =
|
|
2120
|
+
if (l) u = Ga(l, this.camera), this._lastValidFocusDistance = u;
|
|
2113
2121
|
else if (this._lastValidFocusDistance !== null) u = this._lastValidFocusDistance;
|
|
2114
2122
|
else {
|
|
2115
|
-
let e = this.controls ?
|
|
2116
|
-
u = e > 0 ? e :
|
|
2123
|
+
let e = this.controls ? Ga(this.controls.target, this.camera) : 0;
|
|
2124
|
+
u = e > 0 ? e : po * (n?.getSceneScale() || 1), this._lastValidFocusDistance = u;
|
|
2117
2125
|
}
|
|
2118
2126
|
let d = this._afPointDirty;
|
|
2119
|
-
this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance >
|
|
2127
|
+
this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance > mo ? this._smoothedFocusDistance = u : this._smoothedFocusDistance += this.afSmoothingFactor * (u - this._smoothedFocusDistance);
|
|
2120
2128
|
let f = r, p = this._smoothedFocusDistance;
|
|
2121
2129
|
if (d || f === 0 || Math.abs(p - f) / Math.max(f, .001) > .001) {
|
|
2122
2130
|
a(p);
|
|
@@ -2127,7 +2135,7 @@ var Ba = class extends ur {
|
|
|
2127
2135
|
worldDistance: p
|
|
2128
2136
|
});
|
|
2129
2137
|
let t = Math.abs(p - f) / Math.max(f, .001);
|
|
2130
|
-
d ? s?.() : t >
|
|
2138
|
+
d ? s?.() : t > fo && o?.();
|
|
2131
2139
|
}
|
|
2132
2140
|
}
|
|
2133
2141
|
_pickFocusPoint(e) {
|
|
@@ -2161,7 +2169,7 @@ var Ba = class extends ur {
|
|
|
2161
2169
|
dispose() {
|
|
2162
2170
|
this.walkControls?.dispose(), this.controls?.removeEventListener("change", this._reportOrthoHeight), this.controls?.dispose();
|
|
2163
2171
|
}
|
|
2164
|
-
},
|
|
2172
|
+
}, vo = .001, yo = 2, bo = (e, t, n, r) => new e(t, n, r, pr).createInterpolant(), xo = class {
|
|
2165
2173
|
constructor(e, t) {
|
|
2166
2174
|
this._cameraManager = e, this._onChange = t, this.keys = [], this._nextId = 1, this._interpolants = null;
|
|
2167
2175
|
}
|
|
@@ -2171,7 +2179,7 @@ var Ba = class extends ur {
|
|
|
2171
2179
|
get duration() {
|
|
2172
2180
|
return this.keys.length ? this.keys[this.keys.length - 1].time : 0;
|
|
2173
2181
|
}
|
|
2174
|
-
addKey(e = this.keys.length ? this.duration +
|
|
2182
|
+
addKey(e = this.keys.length ? this.duration + yo : 0) {
|
|
2175
2183
|
return this.add(this._cameraManager.captureView(), e);
|
|
2176
2184
|
}
|
|
2177
2185
|
updateKey(e) {
|
|
@@ -2185,13 +2193,13 @@ var Ba = class extends ur {
|
|
|
2185
2193
|
let n = {
|
|
2186
2194
|
id: this._nextId++,
|
|
2187
2195
|
time: t,
|
|
2188
|
-
...
|
|
2196
|
+
...So(e)
|
|
2189
2197
|
};
|
|
2190
2198
|
return this.keys.push(n), this._changed(), n;
|
|
2191
2199
|
}
|
|
2192
2200
|
update(e, t) {
|
|
2193
2201
|
let n = this.get(e);
|
|
2194
|
-
n && (Object.assign(n,
|
|
2202
|
+
n && (Object.assign(n, So(t)), this._changed());
|
|
2195
2203
|
}
|
|
2196
2204
|
setTime(e, t) {
|
|
2197
2205
|
let n = this.get(e);
|
|
@@ -2241,7 +2249,7 @@ var Ba = class extends ur {
|
|
|
2241
2249
|
}
|
|
2242
2250
|
_build() {
|
|
2243
2251
|
let e = [];
|
|
2244
|
-
for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] +
|
|
2252
|
+
for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] + vo) : t.time);
|
|
2245
2253
|
let t = e[0], n = e[e.length - 1], r = this.keys;
|
|
2246
2254
|
if (r.length > 1) {
|
|
2247
2255
|
let i = r.length;
|
|
@@ -2255,17 +2263,17 @@ var Ba = class extends ur {
|
|
|
2255
2263
|
return {
|
|
2256
2264
|
start: t,
|
|
2257
2265
|
end: n,
|
|
2258
|
-
position:
|
|
2259
|
-
target:
|
|
2260
|
-
fov:
|
|
2261
|
-
logHeight:
|
|
2266
|
+
position: bo(Br, ".position", e, i((e) => e.position)),
|
|
2267
|
+
target: bo(Br, ".target", e, i((e) => e.target)),
|
|
2268
|
+
fov: bo(Cr, ".fov", e, r.map((e) => e.fov)),
|
|
2269
|
+
logHeight: bo(Cr, ".orthoHeight", e, r.map((e) => Math.log(e.orthoHeight)))
|
|
2262
2270
|
};
|
|
2263
2271
|
}
|
|
2264
2272
|
_changed() {
|
|
2265
2273
|
this.keys.sort((e, t) => e.time - t.time), this._interpolants = null, this._onChange?.();
|
|
2266
2274
|
}
|
|
2267
2275
|
};
|
|
2268
|
-
function
|
|
2276
|
+
function So({ position: e, target: t, fov: n, orthoHeight: r }) {
|
|
2269
2277
|
return {
|
|
2270
2278
|
position: e.clone(),
|
|
2271
2279
|
target: t.clone(),
|
|
@@ -2275,9 +2283,9 @@ function ho({ position: e, target: t, fov: n, orthoHeight: r }) {
|
|
|
2275
2283
|
}
|
|
2276
2284
|
//#endregion
|
|
2277
2285
|
//#region src/managers/timeline/TimelineManager.js
|
|
2278
|
-
var
|
|
2286
|
+
var Co = class extends ur {
|
|
2279
2287
|
constructor({ cameraManager: e, onReset: t }) {
|
|
2280
|
-
super(), this._cameraManager = e, this._onReset = t, this.camera = new
|
|
2288
|
+
super(), this._cameraManager = e, this._onReset = t, this.camera = new xo(e, () => this._changed("camera")), this._playback = null, this._timer = new Fr(), typeof document < "u" && this._timer.connect(document);
|
|
2281
2289
|
}
|
|
2282
2290
|
get duration() {
|
|
2283
2291
|
return this.camera.duration;
|
|
@@ -2330,14 +2338,14 @@ var go = class extends ur {
|
|
|
2330
2338
|
track: e
|
|
2331
2339
|
});
|
|
2332
2340
|
}
|
|
2333
|
-
},
|
|
2341
|
+
}, wo = class {
|
|
2334
2342
|
constructor(e, t = {}) {
|
|
2335
2343
|
this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._size = 256;
|
|
2336
2344
|
}
|
|
2337
2345
|
async loadLibrary(e, { size: t = 256 } = {}) {
|
|
2338
2346
|
if (!Array.isArray(e) || e.length === 0) return [];
|
|
2339
2347
|
this._size = t;
|
|
2340
|
-
let n = await Promise.all(e.map((e) =>
|
|
2348
|
+
let n = await Promise.all(e.map((e) => To(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
|
|
2341
2349
|
s.width = r, s.height = i;
|
|
2342
2350
|
let c = s.getContext("2d", { willReadFrequently: !0 }), l = performance.now();
|
|
2343
2351
|
for (let e = 0; e < a; e++) {
|
|
@@ -2369,7 +2377,7 @@ var go = class extends ur {
|
|
|
2369
2377
|
o.userData.gobo = {
|
|
2370
2378
|
name: e.name,
|
|
2371
2379
|
index: e.index,
|
|
2372
|
-
intensity:
|
|
2380
|
+
intensity: Eo(r),
|
|
2373
2381
|
inverted: !!i,
|
|
2374
2382
|
scale: Math.max(1e-4, a)
|
|
2375
2383
|
};
|
|
@@ -2411,7 +2419,7 @@ var go = class extends ur {
|
|
|
2411
2419
|
return t && t.isSpotLight ? t : null;
|
|
2412
2420
|
}
|
|
2413
2421
|
};
|
|
2414
|
-
async function
|
|
2422
|
+
async function To(e) {
|
|
2415
2423
|
let t = await _(e);
|
|
2416
2424
|
try {
|
|
2417
2425
|
return await new Promise((n, r) => {
|
|
@@ -2422,22 +2430,22 @@ async function vo(e) {
|
|
|
2422
2430
|
t.release();
|
|
2423
2431
|
}
|
|
2424
2432
|
}
|
|
2425
|
-
function
|
|
2433
|
+
function Eo(e) {
|
|
2426
2434
|
return Math.max(0, Math.min(1, e));
|
|
2427
2435
|
}
|
|
2428
2436
|
//#endregion
|
|
2429
2437
|
//#region src/Processor/IESParser.js
|
|
2430
|
-
function
|
|
2438
|
+
function Do(e, t = "ies") {
|
|
2431
2439
|
let n = e.search(/TILT\s*=/i);
|
|
2432
2440
|
if (n < 0) throw Error(`IES (${t}): missing TILT line`);
|
|
2433
2441
|
let r = e.indexOf("\n", n);
|
|
2434
2442
|
if (r < 0) throw Error(`IES (${t}): truncated TILT line`);
|
|
2435
2443
|
let i = e.slice(n, r).match(/TILT\s*=\s*(\w+)/i), a = i ? i[1].toUpperCase() : "NONE", o = e.slice(r);
|
|
2436
2444
|
if (a === "INCLUDE") {
|
|
2437
|
-
let e =
|
|
2438
|
-
o =
|
|
2445
|
+
let e = Mo(o), t = 2 + 2 * Number(e[1]);
|
|
2446
|
+
o = No(o, t);
|
|
2439
2447
|
}
|
|
2440
|
-
let s =
|
|
2448
|
+
let s = Mo(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
|
|
2441
2449
|
l(), l(), l(), l();
|
|
2442
2450
|
let g = l();
|
|
2443
2451
|
if (l(), l(), !Number.isFinite(p) || p <= 0) throw Error(`IES (${t}): invalid vertical angle count ${p}`);
|
|
@@ -2463,34 +2471,34 @@ function bo(e, t = "ies") {
|
|
|
2463
2471
|
name: t
|
|
2464
2472
|
};
|
|
2465
2473
|
}
|
|
2466
|
-
function
|
|
2474
|
+
function Oo(e, t, n) {
|
|
2467
2475
|
if (t === 0 && n === 90) {
|
|
2468
2476
|
let t = e % 180;
|
|
2469
2477
|
return t > 90 ? 180 - t : t;
|
|
2470
2478
|
}
|
|
2471
2479
|
return t === 0 && n === 180 ? e > 180 ? 360 - e : e : t === 90 && n === 270 ? e >= 90 && e <= 270 ? e : (540 - e) % 360 : e;
|
|
2472
2480
|
}
|
|
2473
|
-
function
|
|
2481
|
+
function ko(e, t, n) {
|
|
2474
2482
|
let r = new Uint8Array(t * n), { verticalAngles: i, horizontalAngles: a, candela: o, maxCandela: s, photometricType: c } = e;
|
|
2475
2483
|
if (s <= 0) return r;
|
|
2476
2484
|
let l = c === void 0 || c === 1, u = i[0], d = i[i.length - 1], f = a[0], p = a[a.length - 1], m = a.length === 1 || p === f, h = (e, t, n, r) => {
|
|
2477
|
-
if (m) return
|
|
2485
|
+
if (m) return Fo(o[e][0], o[t][0], n);
|
|
2478
2486
|
if (r < f || r > p) return 0;
|
|
2479
|
-
let i =
|
|
2480
|
-
return
|
|
2487
|
+
let i = Po(a, r), s = Math.min(i + 1, a.length - 1), c = a[s] - a[i], l = c > 0 ? (r - a[i]) / c : 0;
|
|
2488
|
+
return Fo(Fo(o[e][i], o[e][s], l), Fo(o[t][i], o[t][s], l), n);
|
|
2481
2489
|
};
|
|
2482
2490
|
for (let e = 0; e < n; e++) {
|
|
2483
2491
|
let a = (e + .5) / n, o = l ? a * 180 : u + a * (d - u);
|
|
2484
2492
|
if (o < u || o > d) continue;
|
|
2485
|
-
let c =
|
|
2493
|
+
let c = Po(i, o), m = Math.min(c + 1, i.length - 1), g = i[m] - i[c], _ = g > 0 ? (o - i[c]) / g : 0;
|
|
2486
2494
|
for (let n = 0; n < t; n++) {
|
|
2487
|
-
let i = (n + .5) / t, a = l ?
|
|
2495
|
+
let i = (n + .5) / t, a = l ? Oo(i * 360, f, p) : f + i * (p - f), o = Math.min(1, Math.max(0, h(c, m, _, a) / s));
|
|
2488
2496
|
r[e * t + n] = Math.round(o * 255);
|
|
2489
2497
|
}
|
|
2490
2498
|
}
|
|
2491
2499
|
return r;
|
|
2492
2500
|
}
|
|
2493
|
-
function
|
|
2501
|
+
function Ao(e, t = .1) {
|
|
2494
2502
|
let { verticalAngles: n, horizontalAngles: r, candela: i, maxCandela: a } = e, o = Math.PI / 4;
|
|
2495
2503
|
if (a <= 0 || !n?.length) return o;
|
|
2496
2504
|
let s = a * t, c = r.length, l = n[n.length - 1], u = !1;
|
|
@@ -2505,7 +2513,7 @@ function Co(e, t = .1) {
|
|
|
2505
2513
|
let d = l * Math.PI / 180;
|
|
2506
2514
|
return Math.min(Math.max(d, 5 * Math.PI / 180), 89 * Math.PI / 180);
|
|
2507
2515
|
}
|
|
2508
|
-
function
|
|
2516
|
+
function jo(e, t, n = .7) {
|
|
2509
2517
|
let { verticalAngles: r, horizontalAngles: i, candela: a, maxCandela: o } = e;
|
|
2510
2518
|
if (o <= 0 || !r?.length || t <= 0) return 0;
|
|
2511
2519
|
let s = o * n, c = i.length, l = 0;
|
|
@@ -2518,15 +2526,15 @@ function wo(e, t, n = .7) {
|
|
|
2518
2526
|
let u = t * 180 / Math.PI, d = u > 0 ? 1 - l / u : 0;
|
|
2519
2527
|
return Math.min(Math.max(d, 0), 1);
|
|
2520
2528
|
}
|
|
2521
|
-
function
|
|
2529
|
+
function Mo(e) {
|
|
2522
2530
|
return e.split(/\s+/).filter((e) => e.length > 0);
|
|
2523
2531
|
}
|
|
2524
|
-
function
|
|
2532
|
+
function No(e, t) {
|
|
2525
2533
|
let n = /\S+/g, r = 0;
|
|
2526
2534
|
for (; n.exec(e) !== null;) if (r++, r === t) return e.slice(n.lastIndex);
|
|
2527
2535
|
return "";
|
|
2528
2536
|
}
|
|
2529
|
-
function
|
|
2537
|
+
function Po(e, t) {
|
|
2530
2538
|
if (t <= e[0]) return 0;
|
|
2531
2539
|
if (t >= e[e.length - 1]) return e.length - 1;
|
|
2532
2540
|
let n = 0, r = e.length - 1;
|
|
@@ -2536,12 +2544,12 @@ function Do(e, t) {
|
|
|
2536
2544
|
}
|
|
2537
2545
|
return n;
|
|
2538
2546
|
}
|
|
2539
|
-
function
|
|
2547
|
+
function Fo(e, t, n) {
|
|
2540
2548
|
return e + (t - e) * n;
|
|
2541
2549
|
}
|
|
2542
2550
|
//#endregion
|
|
2543
2551
|
//#region src/managers/IESManager.js
|
|
2544
|
-
var
|
|
2552
|
+
var Io = class {
|
|
2545
2553
|
constructor(e, t = {}) {
|
|
2546
2554
|
this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._gridWidth = 128, this._gridHeight = 128;
|
|
2547
2555
|
}
|
|
@@ -2550,11 +2558,11 @@ var ko = class {
|
|
|
2550
2558
|
this._gridWidth = t, this._gridHeight = n;
|
|
2551
2559
|
let r = (await Promise.all(e.map(async (e) => {
|
|
2552
2560
|
try {
|
|
2553
|
-
let { file: r, release: i } = await p().fetch(e.url), a =
|
|
2561
|
+
let { file: r, release: i } = await p().fetch(e.url), a = Do(await r.text().finally(i), e.name);
|
|
2554
2562
|
return {
|
|
2555
2563
|
it: e,
|
|
2556
2564
|
profile: a,
|
|
2557
|
-
grid:
|
|
2565
|
+
grid: ko(a, t, n)
|
|
2558
2566
|
};
|
|
2559
2567
|
} catch (t) {
|
|
2560
2568
|
return this._issues?.warn(Ye.ASSET_UNREACHABLE, `IES profile "${e.name}" could not be loaded: ${t.message}`, {
|
|
@@ -2572,14 +2580,14 @@ var ko = class {
|
|
|
2572
2580
|
let r = t[e];
|
|
2573
2581
|
o[n + e * 4 + 0] = r, o[n + e * 4 + 1] = r, o[n + e * 4 + 2] = r, o[n + e * 4 + 3] = 255;
|
|
2574
2582
|
}
|
|
2575
|
-
let i = r[e].profile, c =
|
|
2583
|
+
let i = r[e].profile, c = Ao(i);
|
|
2576
2584
|
s.push({
|
|
2577
2585
|
name: r[e].it.name,
|
|
2578
2586
|
index: e,
|
|
2579
2587
|
maxCandela: i.maxCandela,
|
|
2580
2588
|
photometricType: i.photometricType,
|
|
2581
2589
|
suggestedAngle: c,
|
|
2582
|
-
suggestedPenumbra:
|
|
2590
|
+
suggestedPenumbra: jo(i, c),
|
|
2583
2591
|
lumens: i.lumens
|
|
2584
2592
|
});
|
|
2585
2593
|
}
|
|
@@ -2615,7 +2623,7 @@ var ko = class {
|
|
|
2615
2623
|
l = Number.isFinite(e.lumens) ? e.lumens : null, i.userData.ies = {
|
|
2616
2624
|
name: e.name,
|
|
2617
2625
|
index: e.index,
|
|
2618
|
-
intensity:
|
|
2626
|
+
intensity: Lo(n),
|
|
2619
2627
|
fixtureLumens: l
|
|
2620
2628
|
}, r && (Number.isFinite(e.suggestedAngle) && (i.angle = e.suggestedAngle, o = e.suggestedAngle), Number.isFinite(e.suggestedPenumbra) && (i.penumbra = e.suggestedPenumbra, s = e.suggestedPenumbra), i.decay = 2, c = 2);
|
|
2621
2629
|
}
|
|
@@ -2638,24 +2646,24 @@ var ko = class {
|
|
|
2638
2646
|
return t && t.isSpotLight ? t : null;
|
|
2639
2647
|
}
|
|
2640
2648
|
};
|
|
2641
|
-
function
|
|
2649
|
+
function Lo(e) {
|
|
2642
2650
|
return Math.max(0, Math.min(1, e));
|
|
2643
2651
|
}
|
|
2644
2652
|
//#endregion
|
|
2645
2653
|
//#region src/Passes/OIDNDenoiser.js
|
|
2646
|
-
var
|
|
2647
|
-
function
|
|
2648
|
-
let n = (e) => Math.ceil((e + 2 *
|
|
2654
|
+
var Ro = We("oidn"), zo = 16, Bo = 16;
|
|
2655
|
+
function Vo(e, t) {
|
|
2656
|
+
let n = (e) => Math.ceil((e + 2 * Bo) / zo) * zo;
|
|
2649
2657
|
return {
|
|
2650
2658
|
width: n(e),
|
|
2651
2659
|
height: n(t)
|
|
2652
2660
|
};
|
|
2653
2661
|
}
|
|
2654
|
-
var
|
|
2655
|
-
async function
|
|
2656
|
-
return
|
|
2662
|
+
var Ho = null;
|
|
2663
|
+
async function Uo() {
|
|
2664
|
+
return Ho ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Ho;
|
|
2657
2665
|
}
|
|
2658
|
-
var
|
|
2666
|
+
var Wo = {
|
|
2659
2667
|
QUALITY_MODELS: {
|
|
2660
2668
|
fast: {
|
|
2661
2669
|
model: "rt_hdr_alb_nrm_small",
|
|
@@ -2679,9 +2687,9 @@ var Lo = {
|
|
|
2679
2687
|
oidnQuality: "fast",
|
|
2680
2688
|
tileSize: 1024
|
|
2681
2689
|
}
|
|
2682
|
-
},
|
|
2683
|
-
const WG: u32 = ${
|
|
2684
|
-
const GROUPS: u32 = ${
|
|
2690
|
+
}, Go = .18, Ko = 256, qo = 256, Jo = `
|
|
2691
|
+
const WG: u32 = ${Ko}u;
|
|
2692
|
+
const GROUPS: u32 = ${qo}u;
|
|
2685
2693
|
|
|
2686
2694
|
@group(0) @binding(0) var<storage, read> col: array<vec4<f32>>;
|
|
2687
2695
|
@group(0) @binding(1) var<storage, read_write> partials: array<f32>;
|
|
@@ -2700,7 +2708,7 @@ fn treeSum( lid: u32 ) {
|
|
|
2700
2708
|
}
|
|
2701
2709
|
}
|
|
2702
2710
|
|
|
2703
|
-
@compute @workgroup_size(${
|
|
2711
|
+
@compute @workgroup_size(${Ko})
|
|
2704
2712
|
fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
|
|
2705
2713
|
@builtin(local_invocation_id) lid: vec3<u32>,
|
|
2706
2714
|
@builtin(workgroup_id) wid: vec3<u32> ) {
|
|
@@ -2724,7 +2732,7 @@ fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
|
|
|
2724
2732
|
if ( lid.x == 0u ) { partials[ wid.x ] = sdata[ 0 ]; }
|
|
2725
2733
|
}
|
|
2726
2734
|
|
|
2727
|
-
@compute @workgroup_size(${
|
|
2735
|
+
@compute @workgroup_size(${Ko})
|
|
2728
2736
|
fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
|
|
2729
2737
|
|
|
2730
2738
|
var v = 0.0;
|
|
@@ -2734,12 +2742,12 @@ fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
|
|
|
2734
2742
|
treeSum( lid.x );
|
|
2735
2743
|
|
|
2736
2744
|
if ( lid.x == 0u ) {
|
|
2737
|
-
let scale = ${
|
|
2745
|
+
let scale = ${Go} / exp2( sdata[ 0 ] / f32( params.x ) );
|
|
2738
2746
|
// Mirrors the CPU guard: a non-finite or non-positive scale means no scaling at all.
|
|
2739
2747
|
scaleOut[ 0 ] = select( 1.0, scale, scale > 0.0 && scale < 3.4e38 );
|
|
2740
2748
|
}
|
|
2741
2749
|
}
|
|
2742
|
-
`,
|
|
2750
|
+
`, Yo = "\n@group(0) @binding(0) var<storage, read_write> col: array<vec4<f32>>;\n@group(0) @binding(1) var<storage, read> scaleBuf: array<f32>;\n\n@compute @workgroup_size(64)\nfn main( @builtin(global_invocation_id) gid: vec3<u32>,\n @builtin(num_workgroups) nwg: vec3<u32> ) {\n let i = gid.y * nwg.x * 64u + gid.x;\n if ( i >= arrayLength( &col ) ) { return; }\n let c = col[ i ];\n col[ i ] = vec4<f32>( c.xyz * scaleBuf[ 0 ], c.w );\n}\n", Xo = 64, Zo = 32768, Qo = 16, $o = 32, es = `
|
|
2743
2751
|
struct UnpackParams {
|
|
2744
2752
|
srcWidth: u32,
|
|
2745
2753
|
tileX: u32,
|
|
@@ -2757,7 +2765,7 @@ struct UnpackParams {
|
|
|
2757
2765
|
@group(0) @binding(3) var<storage, read> inColor: array<vec4<f32>>;
|
|
2758
2766
|
@group(0) @binding(4) var dst: texture_storage_2d<rgba16float, write>;
|
|
2759
2767
|
|
|
2760
|
-
@compute @workgroup_size(${
|
|
2768
|
+
@compute @workgroup_size(${Qo}, ${Qo})
|
|
2761
2769
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
2762
2770
|
|
|
2763
2771
|
if ( gid.x >= P.tileW || gid.y >= P.tileH ) { return; }
|
|
@@ -2771,7 +2779,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2771
2779
|
// survives the denoise.
|
|
2772
2780
|
textureStore( dst, vec2<u32>( px, py ), vec4<f32>( src[ si ].xyz / scaleBuf[ 0 ], inColor[ si ].w ) );
|
|
2773
2781
|
}
|
|
2774
|
-
`,
|
|
2782
|
+
`, ts = 8, ns = `
|
|
2775
2783
|
@group(0) @binding(0) var src: texture_2d<f32>;
|
|
2776
2784
|
@group(0) @binding(1) var<storage, read_write> dst: array<vec4<f32>>;
|
|
2777
2785
|
@group(0) @binding(2) var<uniform> size: vec4<u32>; // buffer w, h; frame w, h
|
|
@@ -2781,15 +2789,15 @@ fn mirror( i: i32, n: i32 ) -> i32 {
|
|
|
2781
2789
|
return clamp( select( m, 2 * n - 2 - m, m >= n ), 0, n - 1 );
|
|
2782
2790
|
}
|
|
2783
2791
|
|
|
2784
|
-
@compute @workgroup_size(${
|
|
2792
|
+
@compute @workgroup_size(${ts}, ${ts})
|
|
2785
2793
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
2786
2794
|
|
|
2787
2795
|
if ( gid.x >= size.x || gid.y >= size.y ) { return; }
|
|
2788
|
-
let p = vec2<i32>( gid.xy ) - ${
|
|
2796
|
+
let p = vec2<i32>( gid.xy ) - ${Bo};
|
|
2789
2797
|
let s = vec2<i32>( mirror( p.x, i32( size.z ) ), mirror( p.y, i32( size.w ) ) );
|
|
2790
2798
|
dst[ gid.y * size.x + gid.x ] = textureLoad( src, s, 0 );
|
|
2791
2799
|
}
|
|
2792
|
-
`,
|
|
2800
|
+
`, rs = class extends ur {
|
|
2793
2801
|
constructor(e, t = {}) {
|
|
2794
2802
|
if (super(), !e) throw Error("OIDNDenoiser requires a renderer");
|
|
2795
2803
|
this.renderer = e, this._renderWidth = e.domElement.width, this._renderHeight = e.domElement.height, this.backendParamsGetter = t.backendParams || null, this.getGPUTextures = t.getGPUTextures || null, this.gpuDevice = null, this._gpuInputBuffers = {
|
|
@@ -2803,14 +2811,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2803
2811
|
width: 0,
|
|
2804
2812
|
height: 0
|
|
2805
2813
|
}, this.config = {
|
|
2806
|
-
...
|
|
2814
|
+
...Wo.DEFAULT_OPTIONS,
|
|
2807
2815
|
...t
|
|
2808
2816
|
}, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
|
|
2809
2817
|
isDenoising: !1,
|
|
2810
2818
|
isLoading: !1,
|
|
2811
2819
|
abortController: null
|
|
2812
2820
|
}, this._tilesWritten = 0, this._runId = 0, this._hasOutput = !1, this.lastDenoiseMs = 0, this.currentTZAUrl = null, this.unet = null, this._weights = /* @__PURE__ */ new Map(), this._pendingStart = !1, this._pendingStartContinuous = !1, this._reloadPending = !1, this._initialize().catch((e) => {
|
|
2813
|
-
|
|
2821
|
+
Ro.error("init failed:", e), this.dispatchEvent({
|
|
2814
2822
|
type: "error",
|
|
2815
2823
|
error: e
|
|
2816
2824
|
});
|
|
@@ -2824,7 +2832,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2824
2832
|
}
|
|
2825
2833
|
}
|
|
2826
2834
|
expectsCleanAux(e = this.quality) {
|
|
2827
|
-
let { QUALITY_MODELS: t } =
|
|
2835
|
+
let { QUALITY_MODELS: t } = Wo;
|
|
2828
2836
|
return (t[e] || t.balance).cleanAux;
|
|
2829
2837
|
}
|
|
2830
2838
|
getRuntimeInfo() {
|
|
@@ -2838,8 +2846,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2838
2846
|
}
|
|
2839
2847
|
_resolveTileSize() {
|
|
2840
2848
|
if (!this._renderWidth || !this._renderHeight) return this.maxTileSize;
|
|
2841
|
-
let e =
|
|
2842
|
-
return e.width * e.height <= t.width * t.height ? Math.max(e.width, e.height) : Math.max(
|
|
2849
|
+
let e = Vo(this._renderWidth, this._renderHeight), t = Vo(this.maxTileSize, this.maxTileSize);
|
|
2850
|
+
return e.width * e.height <= t.width * t.height ? Math.max(e.width, e.height) : Math.max(zo, Math.floor(this.maxTileSize / zo) * zo);
|
|
2843
2851
|
}
|
|
2844
2852
|
_setupUNetDenoiser() {
|
|
2845
2853
|
return this.state.isLoading ? (this._reloadPending = !0, Promise.resolve()) : (this._loading = this._loadUNet(), this._loading);
|
|
@@ -2853,7 +2861,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2853
2861
|
try {
|
|
2854
2862
|
await this._loadUNetWeights();
|
|
2855
2863
|
} catch (e) {
|
|
2856
|
-
|
|
2864
|
+
Ro.error("UNet weights failed to load:", e), this.dispatchEvent({
|
|
2857
2865
|
type: "error",
|
|
2858
2866
|
error: /* @__PURE__ */ Error(`Denoiser loading failed: ${e.message}`),
|
|
2859
2867
|
url: this._generateTzaUrl()
|
|
@@ -2879,26 +2887,26 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2879
2887
|
let e = this.backendParamsGetter();
|
|
2880
2888
|
this.gpuDevice = e?.device ?? null, n = e?.device ? { device: e.device } : void 0;
|
|
2881
2889
|
}
|
|
2882
|
-
this.unet = await (await
|
|
2890
|
+
this.unet = await (await Uo())(await this._fetchWeights(e), n, {
|
|
2883
2891
|
aux: !0,
|
|
2884
2892
|
hdr: !0,
|
|
2885
2893
|
maxTileSize: t,
|
|
2886
2894
|
dynamicTile: !1
|
|
2887
|
-
}), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }),
|
|
2895
|
+
}), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), Ro.debug("UNet weights loaded:", e);
|
|
2888
2896
|
}
|
|
2889
2897
|
_fetchWeights(e) {
|
|
2890
2898
|
let t = this._weights.get(e);
|
|
2891
2899
|
return t || (t = p().fetch(e, { policy: C.IMMUTABLE }).then(({ file: e, release: t }) => e.arrayBuffer().finally(t)), t.catch(() => this._weights.delete(e)), this._weights.set(e, t)), t;
|
|
2892
2900
|
}
|
|
2893
2901
|
_generateTzaUrl() {
|
|
2894
|
-
let { oidnWeightsBaseUrl: e } = it(), { QUALITY_MODELS: t } =
|
|
2902
|
+
let { oidnWeightsBaseUrl: e } = it(), { QUALITY_MODELS: t } = Wo;
|
|
2895
2903
|
return `${e}${(t[this.quality] || t.balance).model}.tza`;
|
|
2896
2904
|
}
|
|
2897
2905
|
async updateConfiguration(e) {
|
|
2898
2906
|
Object.keys(e).some((t) => this.config[t] !== e[t]) && (Object.assign(this.config, e), this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, await this._setupUNetDenoiser());
|
|
2899
2907
|
}
|
|
2900
2908
|
async updateQuality(e) {
|
|
2901
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
2909
|
+
if (!Object.prototype.hasOwnProperty.call(Wo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Wo.QUALITY_MODELS).join(", ")}`);
|
|
2902
2910
|
await this.updateConfiguration({ oidnQuality: e });
|
|
2903
2911
|
}
|
|
2904
2912
|
async start({ continuous: e = !1 } = {}) {
|
|
@@ -2909,7 +2917,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2909
2917
|
continuous: e
|
|
2910
2918
|
});
|
|
2911
2919
|
let t = performance.now(), n = await this.execute(e);
|
|
2912
|
-
return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t,
|
|
2920
|
+
return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t, Ro.debug(`denoise complete in ${He.ms(this.lastDenoiseMs)} · quality ${this.quality}`)), n;
|
|
2913
2921
|
}
|
|
2914
2922
|
async execute(e = !1) {
|
|
2915
2923
|
let t = ++this._runId;
|
|
@@ -2917,7 +2925,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2917
2925
|
try {
|
|
2918
2926
|
return !this.enabled || !this.unet ? !1 : await this._executeUNetGPU(e) !== !1;
|
|
2919
2927
|
} catch (e) {
|
|
2920
|
-
return e.name === "AbortError" ?
|
|
2928
|
+
return e.name === "AbortError" ? Ro.debug("denoise aborted") : Ro.error("denoise error:", e), !1;
|
|
2921
2929
|
} finally {
|
|
2922
2930
|
this._runId === t && (this.state.isDenoising = !1, this.state.abortController = null), this.dispatchEvent({
|
|
2923
2931
|
type: "end",
|
|
@@ -2927,13 +2935,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2927
2935
|
}
|
|
2928
2936
|
async _executeUNetGPU(e = !1) {
|
|
2929
2937
|
let t = this._renderWidth, n = this._renderHeight;
|
|
2930
|
-
if (!this.getGPUTextures) return
|
|
2938
|
+
if (!this.getGPUTextures) return Ro.warn("GPU mode enabled but getGPUTextures not provided"), !1;
|
|
2931
2939
|
let r = this.getGPUTextures({ continuous: e });
|
|
2932
|
-
if (!r?.color) return
|
|
2940
|
+
if (!r?.color) return Ro.warn("GPU textures not ready yet"), !1;
|
|
2933
2941
|
let i = this.gpuDevice;
|
|
2934
|
-
if (!i) return
|
|
2942
|
+
if (!i) return Ro.warn("gpuDevice not available"), !1;
|
|
2935
2943
|
this._ensureGPUInputBuffers(t, n), this._copyInputs(i, r, t, n);
|
|
2936
|
-
let a =
|
|
2944
|
+
let a = Vo(t, n);
|
|
2937
2945
|
this._computeInputScale(i, t, n), this._applyColorScale(i, a.width * a.height), !e && !this._hasOutput && this._unpackToTexture(this._gpuInputBuffers.color, {
|
|
2938
2946
|
x: 0,
|
|
2939
2947
|
y: 0,
|
|
@@ -2952,7 +2960,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2952
2960
|
return this._executeWithAbortGPU(s, e);
|
|
2953
2961
|
}
|
|
2954
2962
|
_copyInputs(e, t, n, r) {
|
|
2955
|
-
let i =
|
|
2963
|
+
let i = Vo(n, r), a = e.createCommandEncoder({ label: "oidn-tex-to-buf" }), o = this._beginPack(e, a, i, n, r);
|
|
2956
2964
|
for (let n of [
|
|
2957
2965
|
"color",
|
|
2958
2966
|
"albedo",
|
|
@@ -2973,14 +2981,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2973
2981
|
resource: { buffer: this._packParams }
|
|
2974
2982
|
}
|
|
2975
2983
|
]
|
|
2976
|
-
})), o.dispatchWorkgroups(Math.ceil(i.width /
|
|
2984
|
+
})), o.dispatchWorkgroups(Math.ceil(i.width / ts), Math.ceil(i.height / ts));
|
|
2977
2985
|
o.end(), e.queue.submit([a.finish()]);
|
|
2978
2986
|
}
|
|
2979
2987
|
_ensureGPUInputBuffers(e, t) {
|
|
2980
2988
|
let { width: n, height: r } = this._gpuInputBufferSize;
|
|
2981
2989
|
if (n === e && r === t && this._gpuInputBuffers.color) return;
|
|
2982
2990
|
this._destroyGPUInputBuffers();
|
|
2983
|
-
let i = this.gpuDevice, a =
|
|
2991
|
+
let i = this.gpuDevice, a = Vo(e, t), o = a.width * a.height * 16, s = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC;
|
|
2984
2992
|
this._gpuInputBuffers.color = i.createBuffer({
|
|
2985
2993
|
label: "oidn-in-color",
|
|
2986
2994
|
size: o,
|
|
@@ -3024,7 +3032,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3024
3032
|
compute: {
|
|
3025
3033
|
module: e.createShaderModule({
|
|
3026
3034
|
label: "oidn-pack",
|
|
3027
|
-
code:
|
|
3035
|
+
code: ns
|
|
3028
3036
|
}),
|
|
3029
3037
|
entryPoint: "main"
|
|
3030
3038
|
}
|
|
@@ -3082,7 +3090,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3082
3090
|
});
|
|
3083
3091
|
let t = e.createShaderModule({
|
|
3084
3092
|
label: "oidn-autoexposure",
|
|
3085
|
-
code:
|
|
3093
|
+
code: Jo
|
|
3086
3094
|
}), n = e.createPipelineLayout({ bindGroupLayouts: [this._lumLayout] });
|
|
3087
3095
|
this._lumReducePipeline = e.createComputePipeline({
|
|
3088
3096
|
label: "oidn-autoexposure-reduce",
|
|
@@ -3106,7 +3114,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3106
3114
|
compute: {
|
|
3107
3115
|
module: e.createShaderModule({
|
|
3108
3116
|
label: "oidn-color-scale",
|
|
3109
|
-
code:
|
|
3117
|
+
code: Yo
|
|
3110
3118
|
}),
|
|
3111
3119
|
entryPoint: "main"
|
|
3112
3120
|
}
|
|
@@ -3116,7 +3124,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3116
3124
|
compute: {
|
|
3117
3125
|
module: e.createShaderModule({
|
|
3118
3126
|
label: "oidn-output-unpack",
|
|
3119
|
-
code:
|
|
3127
|
+
code: es
|
|
3120
3128
|
}),
|
|
3121
3129
|
entryPoint: "main"
|
|
3122
3130
|
}
|
|
@@ -3126,7 +3134,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3126
3134
|
size: 4
|
|
3127
3135
|
}), this._lumPartials = e.createBuffer({
|
|
3128
3136
|
label: "oidn-autoexposure-partials",
|
|
3129
|
-
size:
|
|
3137
|
+
size: qo * 4,
|
|
3130
3138
|
usage: GPUBufferUsage.STORAGE
|
|
3131
3139
|
}), this._lumParams = e.createBuffer({
|
|
3132
3140
|
label: "oidn-autoexposure-params",
|
|
@@ -3171,21 +3179,21 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3171
3179
|
e.queue.writeBuffer(this._inputScaleBuffer, 0, new Float32Array([1]));
|
|
3172
3180
|
return;
|
|
3173
3181
|
}
|
|
3174
|
-
let r =
|
|
3182
|
+
let r = Vo(t, n);
|
|
3175
3183
|
e.queue.writeBuffer(this._lumParams, 0, new Uint32Array([
|
|
3176
3184
|
t * n,
|
|
3177
3185
|
t,
|
|
3178
3186
|
r.width,
|
|
3179
|
-
|
|
3187
|
+
Bo
|
|
3180
3188
|
]));
|
|
3181
3189
|
let i = e.createCommandEncoder({ label: "oidn-autoexposure" }), a = i.beginComputePass({ label: "oidn-autoexposure-reduce" });
|
|
3182
|
-
a.setPipeline(this._lumReducePipeline), a.setBindGroup(0, this._lumBindGroup), a.dispatchWorkgroups(
|
|
3190
|
+
a.setPipeline(this._lumReducePipeline), a.setBindGroup(0, this._lumBindGroup), a.dispatchWorkgroups(qo, 1, 1), a.end();
|
|
3183
3191
|
let o = i.beginComputePass({ label: "oidn-autoexposure-finalize" });
|
|
3184
3192
|
o.setPipeline(this._lumFinalizePipeline), o.setBindGroup(0, this._lumBindGroup), o.dispatchWorkgroups(1, 1, 1), o.end(), e.queue.submit([i.finish()]);
|
|
3185
3193
|
}
|
|
3186
3194
|
_applyColorScale(e, t) {
|
|
3187
3195
|
if (!this._ensureScalePipelines(e)) return;
|
|
3188
|
-
let n = Math.ceil(t /
|
|
3196
|
+
let n = Math.ceil(t / Xo), r = Math.min(n, Zo), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
|
|
3189
3197
|
o.setPipeline(this._colorScalePipeline), o.setBindGroup(0, this._colorScaleBindGroup), o.dispatchWorkgroups(r, i, 1), o.end(), e.queue.submit([a.finish()]);
|
|
3190
3198
|
}
|
|
3191
3199
|
get outputTexture() {
|
|
@@ -3230,18 +3238,18 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3230
3238
|
if (this._ensureOutputTexture(r, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
|
|
3231
3239
|
let c = r.createBuffer({
|
|
3232
3240
|
label: "oidn-unpack-params",
|
|
3233
|
-
size:
|
|
3241
|
+
size: $o,
|
|
3234
3242
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
3235
3243
|
});
|
|
3236
3244
|
try {
|
|
3237
|
-
let t =
|
|
3245
|
+
let t = Vo(this._gpuInputBufferSize.width, this._gpuInputBufferSize.height).width;
|
|
3238
3246
|
r.queue.writeBuffer(c, 0, new Uint32Array([
|
|
3239
3247
|
t,
|
|
3240
3248
|
i,
|
|
3241
3249
|
a,
|
|
3242
3250
|
o,
|
|
3243
3251
|
s,
|
|
3244
|
-
|
|
3252
|
+
Bo,
|
|
3245
3253
|
0,
|
|
3246
3254
|
0
|
|
3247
3255
|
]));
|
|
@@ -3271,7 +3279,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3271
3279
|
}
|
|
3272
3280
|
]
|
|
3273
3281
|
}), u = r.createCommandEncoder({ label: "oidn-output-unpack" }), d = u.beginComputePass({ label: "oidn-output-unpack" });
|
|
3274
|
-
d.setPipeline(this._unpackPipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o /
|
|
3282
|
+
d.setPipeline(this._unpackPipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / Qo), Math.ceil(s / Qo), 1), d.end(), r.queue.submit([u.finish()]), n && (this._hasOutput = !0);
|
|
3275
3283
|
} finally {
|
|
3276
3284
|
c.destroy();
|
|
3277
3285
|
}
|
|
@@ -3303,7 +3311,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3303
3311
|
},
|
|
3304
3312
|
progress: (e, n, r) => {
|
|
3305
3313
|
if (!e?.data || !r) return;
|
|
3306
|
-
let { width: i, height: a } = this._gpuInputBufferSize, o = Math.max(r.x -
|
|
3314
|
+
let { width: i, height: a } = this._gpuInputBufferSize, o = Math.max(r.x - Bo, 0), s = Math.max(r.y - Bo, 0), c = Math.min(r.x + r.width - Bo, i) - o, l = Math.min(r.y + r.height - Bo, a) - s;
|
|
3307
3315
|
if (c <= 0 || l <= 0) return;
|
|
3308
3316
|
let u = {
|
|
3309
3317
|
x: o,
|
|
@@ -3324,7 +3332,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3324
3332
|
}
|
|
3325
3333
|
_displayGPUOutput({ data: e }) {
|
|
3326
3334
|
if (!this.gpuDevice) {
|
|
3327
|
-
|
|
3335
|
+
Ro.error("gpuDevice not available for the output picture");
|
|
3328
3336
|
return;
|
|
3329
3337
|
}
|
|
3330
3338
|
let { width: t, height: n } = this._gpuInputBufferSize;
|
|
@@ -3336,7 +3344,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3336
3344
|
});
|
|
3337
3345
|
}
|
|
3338
3346
|
abort() {
|
|
3339
|
-
this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1,
|
|
3347
|
+
this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1, Ro.debug("denoise aborted"));
|
|
3340
3348
|
}
|
|
3341
3349
|
get hasOutput() {
|
|
3342
3350
|
return this._hasOutput;
|
|
@@ -3347,13 +3355,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3347
3355
|
setSize(e, t) {
|
|
3348
3356
|
if (e <= 0 || t <= 0) throw Error(`Invalid dimensions: ${e}x${t}`);
|
|
3349
3357
|
this._renderWidth = e, this._renderHeight = t, this._hasOutput = !1, this.lastDenoiseMs = 0, this._setupUNetDenoiser().catch((e) => {
|
|
3350
|
-
|
|
3358
|
+
Ro.error("reinitialize after size change failed:", e);
|
|
3351
3359
|
});
|
|
3352
3360
|
}
|
|
3353
3361
|
dispose() {
|
|
3354
|
-
this.abort(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._releaseOutputTexture(), this._colorScalePipeline = null, this._lumReducePipeline = null, this._lumFinalizePipeline = null, this._lumLayout = null, this._unpackPipeline = null, this.unet = null, this._weights.clear(), this.state.abortController = null, this.removeAllListeners?.(),
|
|
3362
|
+
this.abort(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._releaseOutputTexture(), this._colorScalePipeline = null, this._lumReducePipeline = null, this._lumFinalizePipeline = null, this._lumLayout = null, this._unpackPipeline = null, this.unet = null, this._weights.clear(), this.state.abortController = null, this.removeAllListeners?.(), Ro.debug("disposed");
|
|
3355
3363
|
}
|
|
3356
|
-
},
|
|
3364
|
+
}, is = Object.freeze({
|
|
3357
3365
|
maxLength: 8,
|
|
3358
3366
|
smoothLength: 2,
|
|
3359
3367
|
roughStart: .45,
|
|
@@ -3361,7 +3369,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3361
3369
|
depthTolerance: .05,
|
|
3362
3370
|
normalTolerance: .8,
|
|
3363
3371
|
movedLength: 2
|
|
3364
|
-
}),
|
|
3372
|
+
}), as = 8, os = 304, ss = 16, cs = 1, ls = 2, us = 4, ds = 1073741824, fs = "\nstruct Params {\n size: vec2<u32>,\n reset: u32,\n flags: u32,\n maxLength: f32,\n smoothLength: f32,\n depthTolerance: f32,\n normalTolerance: f32,\n roughStart: f32,\n roughEnd: f32,\n samples: f32,\n historyScale: f32,\n camWorld: mat4x4<f32>,\n projInv: mat4x4<f32>,\n prevViewProj: mat4x4<f32>,\n prevCamPos: vec4<f32>,\n moved: vec4<u32>,\n movedLength: f32,\n prevCamDir: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> P: Params;\n\nfn finite3( v: vec3<f32> ) -> bool {\n let e = bitcast<vec3<u32>>( v ) & vec3<u32>( 0x7f800000u );\n return all( e != vec3<u32>( 0x7f800000u ) );\n}\n\n// [0,1]-encoded in and out, renormalised like FinalWrite's clean aux.\nfn mixNormal( h: vec3<f32>, c: vec3<f32>, t: f32 ) -> vec3<f32> {\n let m = mix( h * 2.0 - 1.0, c * 2.0 - 1.0, t );\n let l = length( m );\n return select( c, m / l * 0.5 + 0.5, l > 1e-4 );\n}\n", ps = fs + `
|
|
3365
3373
|
@group(0) @binding(1) var geoCur: texture_2d<f32>;
|
|
3366
3374
|
@group(0) @binding(2) var geoPrev: texture_2d<f32>;
|
|
3367
3375
|
@group(0) @binding(3) var<storage, read_write> picked: array<i32>;
|
|
@@ -3387,7 +3395,7 @@ fn movedIndex( leaf: u32 ) -> i32 {
|
|
|
3387
3395
|
|
|
3388
3396
|
}
|
|
3389
3397
|
|
|
3390
|
-
@compute @workgroup_size(${
|
|
3398
|
+
@compute @workgroup_size(${as}, ${as})
|
|
3391
3399
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
3392
3400
|
|
|
3393
3401
|
if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
|
|
@@ -3402,7 +3410,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3402
3410
|
let size = vec2<f32>( P.size );
|
|
3403
3411
|
let uv = ( vec2<f32>( gid.xy ) + 0.5 ) / size;
|
|
3404
3412
|
// Depth is along the ray: from the camera, or from its image plane when orthographic.
|
|
3405
|
-
let ortho = ( P.flags & ${
|
|
3413
|
+
let ortho = ( P.flags & ${us}u ) != 0u;
|
|
3406
3414
|
let ndc = vec2<f32>( uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0 );
|
|
3407
3415
|
var origin = P.camWorld[ 3 ].xyz;
|
|
3408
3416
|
var dir: vec3<f32>;
|
|
@@ -3426,7 +3434,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3426
3434
|
let toPrev = movedToPrev[ u32( m ) ];
|
|
3427
3435
|
wp = ( toPrev * vec4<f32>( wp, 1.0 ) ).xyz;
|
|
3428
3436
|
n = normalize( ( toPrev * vec4<f32>( n, 0.0 ) ).xyz );
|
|
3429
|
-
movedFlag = ${
|
|
3437
|
+
movedFlag = ${ds};
|
|
3430
3438
|
|
|
3431
3439
|
}
|
|
3432
3440
|
|
|
@@ -3463,7 +3471,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3463
3471
|
if ( pick >= 0 ) { atomicAdd( &copies[ u32( pick ) ], 1u ); }
|
|
3464
3472
|
|
|
3465
3473
|
}
|
|
3466
|
-
`,
|
|
3474
|
+
`, ms = fs + `
|
|
3467
3475
|
@group(0) @binding(1) var curColor: texture_2d<f32>;
|
|
3468
3476
|
@group(0) @binding(2) var curAlbedo: texture_2d<f32>;
|
|
3469
3477
|
@group(0) @binding(3) var curNormal: texture_2d<f32>;
|
|
@@ -3477,7 +3485,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3477
3485
|
@group(0) @binding(11) var outAlbedo: texture_storage_2d<rgba32float, write>;
|
|
3478
3486
|
@group(0) @binding(12) var outNormal: texture_storage_2d<rgba32float, write>;
|
|
3479
3487
|
|
|
3480
|
-
@compute @workgroup_size(${
|
|
3488
|
+
@compute @workgroup_size(${as}, ${as})
|
|
3481
3489
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
3482
3490
|
|
|
3483
3491
|
if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
|
|
@@ -3493,8 +3501,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3493
3501
|
var ha = ca.xyz;
|
|
3494
3502
|
var hn = cn.xyz;
|
|
3495
3503
|
let raw = picked[ gid.y * P.size.x + gid.x ];
|
|
3496
|
-
let movedPx = raw >= 0 && ( raw & ${
|
|
3497
|
-
let pick = select( raw, raw & ~${
|
|
3504
|
+
let movedPx = raw >= 0 && ( raw & ${ds} ) != 0;
|
|
3505
|
+
let pick = select( raw, raw & ~${ds}, raw >= 0 );
|
|
3498
3506
|
|
|
3499
3507
|
if ( pick >= 0 ) {
|
|
3500
3508
|
|
|
@@ -3508,13 +3516,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3508
3516
|
ha = a.xyz;
|
|
3509
3517
|
hn = textureLoad( histNormal, q, 0 ).xyz;
|
|
3510
3518
|
len = a.w;
|
|
3511
|
-
if ( ( P.flags & ${
|
|
3519
|
+
if ( ( P.flags & ${ls}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
|
|
3512
3520
|
|
|
3513
3521
|
}
|
|
3514
3522
|
|
|
3515
3523
|
}
|
|
3516
3524
|
|
|
3517
|
-
let rough = textureLoad( shading, p, 0 ).w;
|
|
3525
|
+
let rough = abs( textureLoad( shading, p, 0 ).w );
|
|
3518
3526
|
var cap = mix( P.smoothLength, P.maxLength, smoothstep( P.roughStart, P.roughEnd, rough ) );
|
|
3519
3527
|
if ( movedPx ) { cap = min( cap, P.movedLength ); }
|
|
3520
3528
|
let newLen = min( len + 1.0, cap );
|
|
@@ -3522,11 +3530,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3522
3530
|
|
|
3523
3531
|
textureStore( outColor, p, vec4<f32>( mix( hc, cur.xyz, t ), cur.w ) );
|
|
3524
3532
|
textureStore( outAlbedo, p, vec4<f32>( mix( ha, ca.xyz, t ), newLen ) );
|
|
3525
|
-
let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${
|
|
3533
|
+
let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${cs}u ) != 0u );
|
|
3526
3534
|
textureStore( outNormal, p, vec4<f32>( n, cn.w ) );
|
|
3527
3535
|
|
|
3528
3536
|
}
|
|
3529
|
-
`,
|
|
3537
|
+
`, hs = fs + `
|
|
3530
3538
|
@group(0) @binding(1) var accColor: texture_2d<f32>;
|
|
3531
3539
|
@group(0) @binding(2) var accAlbedo: texture_2d<f32>;
|
|
3532
3540
|
@group(0) @binding(3) var accNormal: texture_2d<f32>;
|
|
@@ -3537,7 +3545,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3537
3545
|
@group(0) @binding(8) var outAlbedo: texture_storage_2d<rgba32float, write>;
|
|
3538
3546
|
@group(0) @binding(9) var outNormal: texture_storage_2d<rgba32float, write>;
|
|
3539
3547
|
|
|
3540
|
-
@compute @workgroup_size(${
|
|
3548
|
+
@compute @workgroup_size(${as}, ${as})
|
|
3541
3549
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
3542
3550
|
|
|
3543
3551
|
if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
|
|
@@ -3571,32 +3579,32 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3571
3579
|
let t = P.samples / max( k + P.samples, 1e-6 );
|
|
3572
3580
|
textureStore( outColor, p, vec4<f32>( mix( hc, ac.xyz, t ), ac.w ) );
|
|
3573
3581
|
textureStore( outAlbedo, p, vec4<f32>( mix( ha, aa.xyz, t ), min( k + P.samples, P.maxLength ) ) );
|
|
3574
|
-
let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${
|
|
3582
|
+
let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${cs}u ) != 0u );
|
|
3575
3583
|
textureStore( outNormal, p, vec4<f32>( n, an.w ) );
|
|
3576
3584
|
|
|
3577
3585
|
}
|
|
3578
|
-
`,
|
|
3586
|
+
`, gs = (e) => ({
|
|
3579
3587
|
binding: e,
|
|
3580
3588
|
visibility: GPUShaderStage.COMPUTE,
|
|
3581
3589
|
texture: { sampleType: "unfilterable-float" }
|
|
3582
|
-
}),
|
|
3590
|
+
}), _s = (e) => ({
|
|
3583
3591
|
binding: e,
|
|
3584
3592
|
visibility: GPUShaderStage.COMPUTE,
|
|
3585
3593
|
storageTexture: {
|
|
3586
3594
|
access: "write-only",
|
|
3587
3595
|
format: "rgba32float"
|
|
3588
3596
|
}
|
|
3589
|
-
}),
|
|
3597
|
+
}), vs = (e, t) => ({
|
|
3590
3598
|
binding: e,
|
|
3591
3599
|
visibility: GPUShaderStage.COMPUTE,
|
|
3592
3600
|
buffer: { type: t }
|
|
3593
|
-
}),
|
|
3601
|
+
}), ys = class {
|
|
3594
3602
|
constructor(e) {
|
|
3595
3603
|
this.device = e, this.settings = {
|
|
3596
|
-
...
|
|
3604
|
+
...is,
|
|
3597
3605
|
cleanAux: !1,
|
|
3598
3606
|
splitCopies: !0
|
|
3599
|
-
}, this.valid = !1, this.width = 0, this.height = 0, this._sets = null, this._current = 0, this._picked = null, this._copies = null, this._paramsBuffer = null, this._pipelines = null, this._movedLeaves = null, this._movedToPrev = null, this._movedCapacity = 0, this._movedCount = 0, this._paramData = new ArrayBuffer(
|
|
3607
|
+
}, this.valid = !1, this.width = 0, this.height = 0, this._sets = null, this._current = 0, this._picked = null, this._copies = null, this._paramsBuffer = null, this._pipelines = null, this._movedLeaves = null, this._movedToPrev = null, this._movedCapacity = 0, this._movedCount = 0, this._paramData = new ArrayBuffer(os), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._prevViewProj = new Float32Array(16), this._prevCamPos = new Float32Array(4), this._prevCamDir = new Float32Array(4);
|
|
3600
3608
|
}
|
|
3601
3609
|
get textures() {
|
|
3602
3610
|
return this.valid ? this._sets[this._current] : null;
|
|
@@ -3704,23 +3712,23 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3704
3712
|
}),
|
|
3705
3713
|
layout: i
|
|
3706
3714
|
};
|
|
3707
|
-
}, n =
|
|
3715
|
+
}, n = vs(0, "uniform");
|
|
3708
3716
|
this._pipelines = {
|
|
3709
|
-
select: t("oidn-history-select",
|
|
3717
|
+
select: t("oidn-history-select", ps, [
|
|
3710
3718
|
n,
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3719
|
+
gs(1),
|
|
3720
|
+
gs(2),
|
|
3721
|
+
vs(3, "storage"),
|
|
3722
|
+
vs(4, "storage"),
|
|
3715
3723
|
{
|
|
3716
3724
|
binding: 5,
|
|
3717
3725
|
visibility: GPUShaderStage.COMPUTE,
|
|
3718
3726
|
texture: { sampleType: "uint" }
|
|
3719
3727
|
},
|
|
3720
|
-
|
|
3721
|
-
|
|
3728
|
+
vs(6, "read-only-storage"),
|
|
3729
|
+
vs(7, "read-only-storage")
|
|
3722
3730
|
]),
|
|
3723
|
-
blend: t("oidn-history-blend",
|
|
3731
|
+
blend: t("oidn-history-blend", ms, [
|
|
3724
3732
|
n,
|
|
3725
3733
|
...[
|
|
3726
3734
|
1,
|
|
@@ -3730,14 +3738,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3730
3738
|
5,
|
|
3731
3739
|
6,
|
|
3732
3740
|
7
|
|
3733
|
-
].map(
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3741
|
+
].map(gs),
|
|
3742
|
+
vs(8, "read-only-storage"),
|
|
3743
|
+
vs(9, "read-only-storage"),
|
|
3744
|
+
_s(10),
|
|
3745
|
+
_s(11),
|
|
3746
|
+
_s(12)
|
|
3739
3747
|
]),
|
|
3740
|
-
merge: t("oidn-history-merge",
|
|
3748
|
+
merge: t("oidn-history-merge", hs, [
|
|
3741
3749
|
n,
|
|
3742
3750
|
...[
|
|
3743
3751
|
1,
|
|
@@ -3746,16 +3754,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3746
3754
|
4,
|
|
3747
3755
|
5,
|
|
3748
3756
|
6
|
|
3749
|
-
].map(
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3757
|
+
].map(gs),
|
|
3758
|
+
_s(7),
|
|
3759
|
+
_s(8),
|
|
3760
|
+
_s(9)
|
|
3753
3761
|
])
|
|
3754
3762
|
}, this._paramsBuffer = e.createBuffer({
|
|
3755
3763
|
label: "oidn-history-params",
|
|
3756
|
-
size:
|
|
3764
|
+
size: os,
|
|
3757
3765
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
3758
|
-
}), this._growMoved(
|
|
3766
|
+
}), this._growMoved(ss);
|
|
3759
3767
|
}
|
|
3760
3768
|
_growMoved(e) {
|
|
3761
3769
|
this._movedLeaves?.destroy(), this._movedToPrev?.destroy();
|
|
@@ -3781,11 +3789,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3781
3789
|
a.setPipeline(t), a.setBindGroup(0, this.device.createBindGroup({
|
|
3782
3790
|
layout: n,
|
|
3783
3791
|
entries: i
|
|
3784
|
-
})), a.dispatchWorkgroups(Math.ceil(this.width /
|
|
3792
|
+
})), a.dispatchWorkgroups(Math.ceil(this.width / as), Math.ceil(this.height / as)), a.end();
|
|
3785
3793
|
}
|
|
3786
3794
|
_writeParams(e, t, n, r) {
|
|
3787
3795
|
let i = this.settings, a = this._paramU32, o = this._paramF32;
|
|
3788
|
-
a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ?
|
|
3796
|
+
a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? cs : 0) | (i.splitCopies ? ls : 0) | (e.orthographic ? us : 0), o[4] = i.maxLength, o[5] = i.smoothLength, o[6] = i.depthTolerance, o[7] = i.normalTolerance, o[8] = i.roughStart, o[9] = i.roughEnd, o[10] = n, o[11] = r, o.set(e.world, 12), o.set(e.projInv, 28), o.set(this._prevViewProj, 44), o.set(this._prevCamPos, 60), a[64] = this._movedCount, o[68] = i.movedLength, o.set(this._prevCamDir, 72), this.device.queue.writeBuffer(this._paramsBuffer, 0, this._paramData);
|
|
3789
3797
|
}
|
|
3790
3798
|
_rememberCamera(e) {
|
|
3791
3799
|
this._prevViewProj.set(e.viewProj), this._prevCamPos[0] = e.world[12], this._prevCamPos[1] = e.world[13], this._prevCamPos[2] = e.world[14];
|
|
@@ -3795,11 +3803,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3795
3803
|
_releaseTextures() {
|
|
3796
3804
|
this._sets?.forEach((e) => Object.values(e).forEach((e) => e.destroy())), this._picked?.destroy(), this._copies?.destroy(), this._sets = null, this._picked = null, this._copies = null, this.width = 0, this.height = 0, this.valid = !1;
|
|
3797
3805
|
}
|
|
3798
|
-
}, ps = "const e=Object.freeze({ADAPTER_SOFTWARE:`adapter.software`,ADAPTER_UNAVAILABLE:`adapter.unavailable`,DEVICE_UNAVAILABLE:`device.unavailable`,WEBGPU_UNAVAILABLE:`webgpu.unavailable`,ASSET_UNREACHABLE:`asset.unreachable`,ASSET_AMBIGUOUS_ENTRY:`asset.ambiguous_entry`,ASSET_ARCHIVE_TOO_LARGE:`asset.archive_too_large`,ASSET_ENTRY_TOO_LARGE:`asset.entry_too_large`,TEXTURE_BUILD_FAILED:`texture.build_failed`,TEXTURE_PROCESSING_FALLBACK:`texture.processing_fallback`,TEXTURE_LIMIT_EXCEEDED:`texture.limit_exceeded`,ENVIRONMENT_LOAD_FAILED:`environment.load_failed`,SETTING_UNKNOWN_KEY:`setting.unknown_key`,RENDER_SIZE_DECLINED:`render.size_declined`,STAGE_RENDER_FAILED:`stage.render_failed`,RENDER_RESERVE_CAPPED:`render.reserve_capped`,SCENE_MEMORY_BUDGET:`scene.memory_budget`,EMISSIVE_INSTANCES_COLLAPSED:`emissive.instances_collapsed`,REFIT_SHARED_GEOMETRY:`refit.shared_geometry`,VIEW_TRANSFORM_DISPLAY_MISMATCH:`viewTransform.display_mismatch`,VIEW_TRANSFORM_BAKE_FAILED:`viewTransform.bake_failed`,COLOR_CONFIG_LOAD_FAILED:`color.config_load_failed`,STORAGE_UNAVAILABLE:`storage.unavailable`,STORAGE_QUOTA_EXCEEDED:`storage.quota_exceeded`,STORAGE_WRITE_FAILED:`storage.write_failed`,STORAGE_READ_FAILED:`storage.read_failed`,STORAGE_ENTRY_CORRUPT:`storage.entry_corrupt`,STORAGE_CACHE_MISMATCH:`storage.cache_mismatch`,DENOISER_UNAVAILABLE:`denoiser.unavailable`,OUTPUT_SOURCE_FALLBACK:`output.source_fallback`,OUTPUT_TONEMAP_FALLBACK:`output.tonemap_fallback`,LIGHT_PLACEHOLDER_SKIPPED:`light.placeholder_skipped`,CAPABILITY_MISSING:`capability.missing`});Object.freeze({ERROR:`error`,WARNING:`warning`});const t=new Map;function n(e,t){return e.exclusive||t===`exclusive`&&e.shared>0?!1:(t===`exclusive`?e.exclusive=!0:e.shared++,!0)}function r(e,r,a){let o=t.get(e);o||(o={shared:0,exclusive:!1,queue:[]},t.set(e,o));let s=i(()=>{for(r===`exclusive`?o.exclusive=!1:o.shared--;o.queue.length&&n(o,o.queue[0].mode);)o.queue.shift().grant();!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e)});return o.queue.length===0&&n(o,r)?Promise.resolve(s):a?(!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e),Promise.resolve(null)):new Promise(e=>o.queue.push({mode:r,grant:()=>e(s)}))}function i(e){let t=!1;return()=>{t||(t=!0,e())}}const a=()=>typeof navigator<`u`&&navigator.locks?.request?navigator.locks:null;function o(e,{mode:t=`exclusive`,ifAvailable:n=!1}={}){let o=a();return o?new Promise((r,a)=>{o.request(e,{mode:t,ifAvailable:n},e=>{if(!e){r(null);return}return new Promise(e=>r(i(e)))}).catch(a)}):r(e,t,n)}async function s(){let e=a();if(!e)return new Set(t.keys());let{held:n=[]}=await e.query();return new Set(n.map(e=>e.name))}const c=new TextEncoder;function l(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function u(e){let t=typeof e==`string`?c.encode(e):e;return l(new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)))}async function d(e){return(await u(e)).slice(0,32)}var f=class{constructor(){this._handlers=new Map}addEventListener(e,t){this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t)}removeEventListener(e,t){this._handlers.get(e)?.delete(t)}dispatchEvent(e){for(let t of[...this._handlers.get(e.type)??[]])t.call(this,e)}},p=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}},m=class{constructor(e){this._ops=new p(e)}async call(e,t){return this._ops[e](t)}dispose(){this._ops.dispose()}};const h=Object.freeze({CACHE:`cache`,USER:`user`,SCRATCH:`scratch`}),g=Object.freeze({DOWNLOADS:`downloads`,ARCHIVES:`archives`,SCENES:`scenes`,CDF:`cdf`,SPILL:`spill`}),_=`meta.json`,v=100*1024**3,y=64*1024**2,b=8*1024**2,x=new TextEncoder;function S(e,{copy:t,transfer:n}){if(typeof e==`string`&&(e=x.encode(e)),e instanceof ArrayBuffer){if(!t||n)return{args:{buffer:e},list:[e]};let r=e.slice(0);return{args:{buffer:r},list:[r]}}if(!ArrayBuffer.isView(e))throw TypeError(`storage: write expects an ArrayBuffer, a typed array, a Blob or a string`);let{buffer:r,byteOffset:i,byteLength:a}=e,o=typeof SharedArrayBuffer<`u`&&r instanceof SharedArrayBuffer;if(!t)return{args:{buffer:r,byteOffset:i,byteLength:a},list:[]};if(o){let e=new Uint8Array(a);return e.set(new Uint8Array(r,i,a)),{args:{buffer:e.buffer},list:[e.buffer]}}if(n&&i===0&&a===r.byteLength)return{args:{buffer:r},list:[r]};let s=r.slice(i,i+a);return{args:{buffer:s},list:[s]}}async function C(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return JSON.parse(await n.text())}catch{return null}}async function*w(e){for await(let[t,n]of e.entries())n.kind===`directory`&&(yield[t,n])}var T=class{constructor(e,t,n,r,i){this.area=e,this.id=t,this.key=n.key,this.meta=n,this._dir=r,this._release=i}get bytes(){return this.meta.bytes}get extra(){return this.meta.extra??{}}async file(t){try{return await(await this._dir.getFileHandle(t)).getFile()}catch(n){return this.area.manager._issue(e.STORAGE_READ_FAILED,`could not read ${this.area.name}/${this.id}/${t}`,{error:n.message}),null}}async json(e){let t=await this.file(e);return t?JSON.parse(await t.text()):null}release(){this._release?.(),this._release=null}},E=class{constructor(e,t,n,r,i,{sizes:a={},append:o=!1}={}){this.area=e,this.id=t,this.key=n,this._info=r,this._release=i,this._writers=new Map,this._sizes={...a},this._append=o,this._done=!1,this._committedBytes=o?Object.values(a).reduce((e,t)=>e+t,0):0}get _transport(){return this.area.manager._transport}get _path(){return[this.area.name,this.id]}async _writer(e){let t=this._writers.get(e);if(!t){let n=this._append&&e in this._sizes,r=n&&(this._info.growable??[]).includes(e)?this._sizes[e]:void 0;t=this._transport.call(`openWriter`,{path:this._path,name:e,truncate:!n,length:r}),this._writers.set(e,t)}return(await t).id}async write(e,t,{at:n,transfer:r=!1}={}){this._assertOpen();let{args:i,list:a}=(typeof Blob<`u`&&t instanceof Blob?null:S(t,{copy:!0,transfer:r}))??S(await t.arrayBuffer(),{copy:!0,transfer:!0}),o=await this._writer(e);return this._transport.call(`write`,{id:o,at:n,...i},a)}async writeFile(e,t){this._assertOpen(),typeof Blob<`u`&&t instanceof Blob&&(t=await t.arrayBuffer());let{args:n,list:r}=S(t,{copy:!0,transfer:!0}),{size:i}=await this._transport.call(`writeFile`,{path:this._path,name:e,...n},r);return this._sizes[e]=i,i}writeJSON(e,t){return this.writeFile(e,JSON.stringify(t))}async writeStream(e,t,{onProgress:n=null,signal:r=null,batchBytes:i=b}={}){let a=t.getReader(),o=[],s=new Uint8Array(i),c=0,l=0,u=async()=>{if(c===0)return;let t=c===i?s:s.slice(0,c);s=new Uint8Array(i),c=0,o.push(this.write(e,t,{transfer:!0})),o.length>=4&&await o.shift()};try{for(;;){if(r?.aborted)throw r.reason??new DOMException(`aborted`,`AbortError`);let{done:e,value:t}=await a.read();if(e)break;let o=0;for(;o<t.length;){let e=Math.min(t.length-o,i-c);s.set(t.subarray(o,o+e),c),c+=e,o+=e,l+=e,c===i&&await u()}n?.(l)}return await u(),await Promise.all(o),l}catch(e){throw a.cancel().catch(()=>{}),await Promise.allSettled(o),e}}async commit(e={}){this._assertOpen(),this._done=!0;try{for(let[e,t]of this._writers){let{size:n}=await this._transport.call(`closeWriter`,{id:(await t).id});this._sizes[e]=n}this._writers.clear();let t=Date.now(),n={v:1,key:this.key,label:this._info.label??``,kind:this.area.kind,files:{...this._sizes},bytes:Object.values(this._sizes).reduce((e,t)=>e+t,0),createdAt:this._info.createdAt??t,lastUsed:t,pinned:this._info.pinned===!0,extra:{...this._info.extra,...e}},r=this._info.growable??[];r.length&&(n.growable=r);let{args:i,list:a}=S(JSON.stringify(n),{copy:!1});return await this._transport.call(`writeFile`,{path:this._path,name:_,...i},a),this.area.kind===h.CACHE&&this.area.manager._countCacheBytes(n.bytes-this._committedBytes),this.area.manager._changed(this.area.name),n}catch(e){throw await this._discard(),this.area.manager._writeFailed(this.area.name,e),e}finally{this._release?.(),this._release=null}}async abort(){if(!this._done){this._done=!0;try{this._append?await this._closeAll(!0):await this._discard()}finally{this._release?.(),this._release=null}}}async _closeAll(e){for(let t of this._writers.values())try{await this._transport.call(`closeWriter`,{id:(await t).id,abort:e})}catch{}this._writers.clear()}async _discard(){await this._closeAll(!0),await this.area._removeDir(this.id)}_assertOpen(){if(this._done)throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`)}},D=class{constructor(e,t,n){this.manager=e,this.name=t,this.kind=n}_lockName(e){return`${this.manager.namespace}:store:${this.name}:${e}`}async _dir(e=!1){try{return await this.manager._root.getDirectoryHandle(this.name,{create:e})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _entryDir(e,t=!1){let n=await this._dir(t);if(!n)return null;try{return await n.getDirectoryHandle(e,{create:t})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _removeDir(e){let t=await this._dir(!1);if(t)try{await t.removeEntry(e,{recursive:!0})}catch(e){if(e.name!==`NotFoundError`)throw e}}async _validMeta(e,t=null){let n=await C(e,_);if(!n||n.v!==1||typeof n.key!=`string`||t!==null&&n.key!==t)return null;let r=n.growable??[];for(let[t,i]of Object.entries(n.files??{}))try{let n=await(await e.getFileHandle(t)).getFile();if(n.size!==i&&!(r.includes(t)&&n.size>i))return null}catch{return null}return n}async open(t,{wait:n=!1}={}){let r=await d(t),i=await o(this._lockName(r),{mode:`shared`,ifAvailable:!n});if(!i)return null;try{let e=await this._entryDir(r),n=e?await this._validMeta(e,t):null;return n?(Date.now()-n.lastUsed>36e5&&this._touch(r,n),new T(this,r,n,e,i)):(i(),null)}catch(t){return i(),this.manager._issue(e.STORAGE_READ_FAILED,`could not open ${this.name} entry`,{error:t.message}),null}}async has(e){let t=await this.open(e);return t?.release(),!!t}_touch(e,t){let n={...t,lastUsed:Date.now()},{args:r,list:i}=S(JSON.stringify(n),{copy:!1});this.manager._transport.call(`writeFile`,{path:[this.name,e],name:_,...r},i).catch(()=>{}),t.lastUsed=n.lastUsed}async create(t,{label:n=``,pinned:r=!1,expectedBytes:i=0,extra:a={},growable:s=[]}={}){let c=await d(t),l=await o(this._lockName(c),{mode:`exclusive`});try{return i>0&&!await this.manager.ensureSpace(i,this.kind)?(l(),this.manager._issue(e.STORAGE_QUOTA_EXCEEDED,`no room for ${(i/1048576).toFixed(0)} MB in ${this.name}`,{area:this.name,expectedBytes:i}),null):(await this._removeDir(c),await this._entryDir(c,!0),new E(this,c,t,{label:n,pinned:r,extra:a,growable:s},l))}catch(e){return l(),this.manager._writeFailed(this.name,e),null}}async patchMeta(e,t){let n=await d(e),r=await o(this._lockName(n),{mode:`shared`,ifAvailable:!0});if(!r)return!1;try{let r=await this._entryDir(n),i=r?await this._validMeta(r,e):null;if(!i)return!1;let{args:a,list:o}=S(JSON.stringify({...i,...t,v:1,key:e}),{copy:!1});return await this.manager._transport.call(`writeFile`,{path:[this.name,n],name:_,...a},o),!0}finally{r()}}async edit(e){let t=await d(e),n=await o(this._lockName(t),{mode:`exclusive`});try{let r=await this._entryDir(t),i=r?await this._validMeta(r,e):null;if(!i)return n(),null;let a={label:i.label,pinned:i.pinned,extra:i.extra,createdAt:i.createdAt,growable:i.growable};return new E(this,t,e,a,n,{sizes:i.files,append:!0})}catch(e){return n(),this.manager._writeFailed(this.name,e),null}}async remove(e){return this.removeById(await d(e))}async removeById(e){let t=await o(this._lockName(e),{mode:`exclusive`,ifAvailable:!0});if(!t)return!1;try{return await this._removeDir(e),this.manager._changed(this.name),!0}finally{t()}}async list(){let e=await this._dir(!1);if(!e)return[];let t=[];for await(let[n,r]of w(e)){let e=await C(r,_);e?.v===1&&t.push({...e,id:n})}return t}async clear(){let e=0;for(let{id:t}of await this.list())await this.removeById(t)&&e++;return e}async sweep(){let e=await this._dir(!1);if(!e)return 0;let t=await s(),n=0;for await(let[r,i]of w(e))t.has(this._lockName(r))||await this._validMeta(i)||await this.removeById(r)&&n++;return n}},O=class extends f{constructor({root:e,transport:t,namespace:n}){super(),this.namespace=n,this._root=e,this._transport=t,this._areas=new Map,this._budget=null,this._cacheTotal=null;for(let e of Object.values(g))this.defineArea(e,{kind:e===g.SPILL?h.SCRATCH:h.CACHE})}defineArea(e,{kind:t=h.CACHE}={}){let n=this._areas.get(e);if(n){if(n.kind!==t)throw Error(`storage: area \"${e}\" is already defined as ${n.kind}`);return n}let r=new D(this,e,t);return this._areas.set(e,r),r}area(e){let t=this._areas.get(e);if(!t)throw Error(`storage: unknown area \"${e}\"`);return t}get areaNames(){return[...this._areas.keys()]}async estimate(){let e=typeof navigator<`u`?navigator.storage:null;if(!e?.estimate)return{quota:1/0,usage:0};let{quota:t=1/0,usage:n=0}=await e.estimate();return{quota:t,usage:n}}async persisted(){return await globalThis.navigator?.storage?.persisted?.()===!0}async persist(){let e=await globalThis.navigator?.storage?.persist?.()===!0;return this._changed(null),e}async budget(){if(this._budget!==null)return this._budget;let{quota:e}=await this.estimate();return Math.min(e*.3,v)}setBudget(e){this._budget=e===null?null:Math.max(0,e),this._changed(null)}async _cacheBytes(){let e=this._cacheTotal;return(!e||Date.now()-e.at>3e4)&&(e=this._cacheTotal={at:Date.now(),bytes:0,ready:null},e.ready=this._cacheEntries().then(t=>{e.bytes+=t.reduce((e,t)=>e+(t.meta.bytes??0),0)}),e.ready.catch(()=>{this._cacheTotal===e&&(this._cacheTotal=null)})),await e.ready,e.bytes}_countCacheBytes(e){this._cacheTotal&&(this._cacheTotal.bytes+=e)}async _cacheEntries(){let e=[];for(let t of this._areas.values())if(t.kind===h.CACHE)for(let n of await t.list())e.push({area:t,meta:n});return e}async usage(){let{quota:e,usage:t}=await this.estimate(),n={},r=0;for(let e of this._areas.values()){let t=await e.list(),i=t.reduce((e,t)=>e+(t.bytes??0),0);n[e.name]={kind:e.kind,bytes:i,entries:t.length},e.kind===h.CACHE&&(r+=i)}return{quota:e,usage:t,persisted:await this.persisted(),budget:await this.budget(),cacheBytes:r,areas:n}}async collect({freeBytes:e=null}={}){let t=await this._cacheEntries(),n=await this.budget(),r=this._cacheTotal={at:Date.now(),bytes:t.reduce((e,t)=>e+(t.meta.bytes??0),0),ready:null},i=e??Math.max(0,r.bytes-n);if(i<=0)return 0;let a=await s(),o=t.filter(({area:e,meta:t})=>!t.pinned&&!a.has(e._lockName(t.id))).sort((e,t)=>e.meta.lastUsed-t.meta.lastUsed),c=0;for(let{area:e,meta:t}of o){if(c>=i)break;await e.removeById(t.id)&&(c+=t.bytes??0,r.bytes-=t.bytes??0)}return c}async ensureSpace(e,t=h.CACHE){let n=async()=>{let{quota:n,usage:r}=await this.estimate(),i=e+y-(n-r);return t===h.CACHE?{free:i,budget:await this._cacheBytes()+e-await this.budget()}:{free:i,budget:0}},r=await n();return r.free<=0&&r.budget<=0?!0:(await this.collect({freeBytes:Math.max(r.free,r.budget)}),(await n()).free<=0)}async sweep(){let e=0;for(let t of this._areas.values())e+=await t.sweep(),t.kind===h.SCRATCH&&(e+=await t.clear());return e}_changed(e){this.dispatchEvent({type:`change`,area:e})}_issue(e,t,n={}){this.dispatchEvent({type:`issue`,code:e,message:t,detail:n})}_writeFailed(t,n){let r=n?.name===`QuotaExceededError`;this._issue(r?e.STORAGE_QUOTA_EXCEEDED:e.STORAGE_WRITE_FAILED,`${t}: ${n?.message??n}`,{area:t,error:n?.name})}dispose(){this._transport?.dispose(),this._transport=null,this._areas.clear()}};function k({namespace:e,root:t}){let n=new m(t);n.inline=!0;let r=new O({root:t,transport:n,namespace:e});return r.sweep().catch(()=>{}),r}const A=Object.freeze({IMMUTABLE:`immutable`,REVALIDATE:`revalidate`,NETWORK:`network`}),j=(e,t)=>({loaded:e,total:t,lengthComputable:t>0&&e<=t}),M=(e,t)=>e.headers?.get?.(t)??null,N=e=>e.reason??new DOMException(`aborted`,`AbortError`);function P(e){try{let t=new URL(e,globalThis.location?.href??`http://localhost/`).pathname;return decodeURIComponent(t.split(`/`).pop())||`download`}catch{return`download`}}async function F(e,{onProgress:t,signal:n}){let r=Number(M(e,`content-length`))||0,i=M(e,`content-type`)??``;if(!e.body)return new Blob([await e.arrayBuffer()],{type:i});let a=e.body.getReader(),o=[],s=0;for(;;){if(n?.aborted)throw a.cancel().catch(()=>{}),N(n);let{done:e,value:i}=await a.read();if(e)break;o.push(i),s+=i.length,t?.(j(s,r))}return new Blob(o,{type:i})}const I=(e,t,n)=>new File([e],t,{type:n||e.type,lastModified:e.lastModified??Date.now()}),L=()=>{};var R=class{constructor(e){this._storage=e,this._revalidating=new Set}get _area(){return this._storage?.area(g.DOWNLOADS)??null}async fetch(e,{key:t=e,name:n=P(e),policy:r=A.REVALIDATE,maxAgeMs:i=864e5,onProgress:a=null,signal:o=null,fetchOptions:s={}}={}){let c=this._area;if(c&&r!==A.NETWORK){let o=await c.open(t);if(o){let c=await o.file(`data`);if(c)return r===A.REVALIDATE&&Date.now()-(o.extra.checkedAt??0)>=i&&this._revalidate(e,t,n,o.extra,s),a?.(j(c.size,c.size)),{file:I(c,n,o.extra.contentType),release:()=>o.release(),fromCache:!0};o.release()}}return this._download(e,t,n,{onProgress:a,signal:o,fetchOptions:s,cache:!!c})}async has(e){return await this._area?.has(e)===!0}async _download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:o}){if(i?.aborted)throw N(i);let s=await fetch(e,{...a,signal:i});if(!s.ok)throw Error(`HTTP ${s.status} fetching ${e}`);let c=Number(M(s,`content-length`))||0,l={url:e,contentType:M(s,`content-type`)??``,lastModified:M(s,`last-modified`),contentLength:c||null,checkedAt:Date.now()},u=o&&s.body?await this._area.create(t,{label:n,expectedBytes:c}):null;if(!u)return{file:I(await F(s,{onProgress:r,signal:i}),n,l.contentType),release:L,fromCache:!1};try{await u.writeStream(`data`,s.body,{signal:i,onProgress:e=>r?.(j(e,c))}),await u.commit(l)}catch(o){if(await u.abort(),o?.name!==`QuotaExceededError`)throw o;return this._download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:!1})}let d=await this._area.open(t,{wait:!0}),f=d&&await d.file(`data`);if(!f)throw d?.release(),Error(`storage: ${n} vanished right after it was saved`);return{file:I(f,n,l.contentType),release:()=>d.release(),fromCache:!1}}async _revalidate(e,t,n,r,i){if(this._revalidating.has(t))return;this._revalidating.add(t);let a=!1;try{let t=new Headers(i?.headers);t.set(`Range`,`bytes=0-0`);let n=await fetch(e,{...i,headers:t});if(n.body?.cancel().catch(()=>{}),n.ok){let e=M(n,`last-modified`),t=n.status===206?Number(M(n,`content-range`)?.match(/\\/(\\d+)$/)?.[1])||null:Number(M(n,`content-length`))||null;a=!!(e&&r.lastModified&&e!==r.lastModified||t&&r.contentLength&&t!==r.contentLength)}}catch{}try{if(a){let{release:r}=await this._download(e,t,n,{fetchOptions:i,cache:!0});r()}else await this._area.patchMeta(t,{extra:{...r,checkedAt:Date.now()}})}catch{}finally{this._revalidating.delete(t)}}};let z={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`,storage:`auto`},B=null;async function V(){return B||(B=await import(z.ortRuntimeUrl),B.env.wasm.wasmPaths=z.ortWasmPaths,B.env.logLevel=`error`,B)}let H=null,U=null,W=null;function G(){return W??=(async()=>{if(z.storage===!1||!navigator.storage?.getDirectory)return new R(null);try{let e=await(await navigator.storage.getDirectory()).getDirectoryHandle(z.cacheNamespace,{create:!0}),t=k({namespace:z.cacheNamespace,root:e});return await K(t).catch(()=>{}),new R(t)}catch{return new R(null)}})(),W}async function K(e){let t=`${z.cacheNamespace}:ai-upscaler-models`;if(typeof indexedDB>`u`||!indexedDB.databases||!(await indexedDB.databases()).some(e=>e.name===t))return;let n=await new Promise((e,n)=>{let r=indexedDB.open(t);r.onerror=()=>n(r.error),r.onsuccess=()=>{let t=r.result;if(!t.objectStoreNames.contains(`models`)){t.close(),e([]);return}let i=[],a=t.transaction(`models`,`readonly`).objectStore(`models`).openCursor();a.onerror=()=>n(a.error),a.onsuccess=()=>{let n=a.result;if(!n){t.close(),e(i);return}i.push([n.key,n.value]),n.continue()}}}),r=e.area(`downloads`);for(let[e,t]of n){if(typeof e!=`string`||!(t instanceof ArrayBuffer)||await r.has(e))continue;let n=await r.create(e,{label:e.split(`/`).pop(),expectedBytes:t.byteLength});n&&(await n.write(`data`,t,{transfer:!0}),await n.commit({url:e,contentType:`application/octet-stream`,checkedAt:Date.now()}))}await new Promise(e=>{let n=indexedDB.deleteDatabase(t);n.onsuccess=n.onerror=n.onblocked=()=>e()})}async function q(e){let{file:t,release:n,fromCache:r}=await(await G()).fetch(e);try{let e=await t.arrayBuffer();return r&&console.log(`AI Upscaler Worker: model loaded from cache (${(e.byteLength/1024/1024).toFixed(1)}MB)`),e}finally{n()}}async function J(e,t){if(H&&U===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}H&&=(await H.release(),null);let[n,r]=await Promise.all([q(e),V()]);H=await r.InferenceSession.create(n,t),U=e;let i=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);i=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${i}`)}catch{}let a=(n.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${a}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:i})}async function Y(e,t,n,r){let i=await V(),a=H.inputNames[0],o=H.outputNames[0],s=new i.Tensor(`float32`,e,[1,3,n,t]),c=(await H.run({[a]:s}))[o].data;self.postMessage({type:`inferred`,outputData:c,id:r},[c.buffer])}self.onmessage=async e=>{let{type:t}=e.data;try{t===`load`?(e.data.ortRuntimeUrl&&(z.ortRuntimeUrl=e.data.ortRuntimeUrl),e.data.ortWasmPaths&&(z.ortWasmPaths=e.data.ortWasmPaths),e.data.cacheNamespace&&(z.cacheNamespace=e.data.cacheNamespace),e.data.storage!==void 0&&(z.storage=e.data.storage),await J(e.data.url,e.data.sessionOptions)):t===`infer`?await Y(e.data.tileData,e.data.width,e.data.height,e.data.id):t===`dispose`&&H&&(await H.release(),H=null,U=null)}catch(t){self.postMessage({type:`error`,message:t.message,id:e.data?.id})}};", ms = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", ps], { type: "text/javascript;charset=utf-8" });
|
|
3799
|
-
function
|
|
3806
|
+
}, bs = "const e=Object.freeze({ADAPTER_SOFTWARE:`adapter.software`,ADAPTER_UNAVAILABLE:`adapter.unavailable`,DEVICE_UNAVAILABLE:`device.unavailable`,WEBGPU_UNAVAILABLE:`webgpu.unavailable`,ASSET_UNREACHABLE:`asset.unreachable`,ASSET_AMBIGUOUS_ENTRY:`asset.ambiguous_entry`,ASSET_ARCHIVE_TOO_LARGE:`asset.archive_too_large`,ASSET_ENTRY_TOO_LARGE:`asset.entry_too_large`,ASSET_PARAMETERS_IGNORED:`asset.parameters_ignored`,TEXTURE_BUILD_FAILED:`texture.build_failed`,TEXTURE_PROCESSING_FALLBACK:`texture.processing_fallback`,TEXTURE_LIMIT_EXCEEDED:`texture.limit_exceeded`,ENVIRONMENT_LOAD_FAILED:`environment.load_failed`,SETTING_UNKNOWN_KEY:`setting.unknown_key`,RENDER_SIZE_DECLINED:`render.size_declined`,STAGE_RENDER_FAILED:`stage.render_failed`,RENDER_RESERVE_CAPPED:`render.reserve_capped`,SCENE_MEMORY_BUDGET:`scene.memory_budget`,EMISSIVE_INSTANCES_COLLAPSED:`emissive.instances_collapsed`,REFIT_SHARED_GEOMETRY:`refit.shared_geometry`,VIEW_TRANSFORM_DISPLAY_MISMATCH:`viewTransform.display_mismatch`,VIEW_TRANSFORM_BAKE_FAILED:`viewTransform.bake_failed`,COLOR_CONFIG_LOAD_FAILED:`color.config_load_failed`,STORAGE_UNAVAILABLE:`storage.unavailable`,STORAGE_QUOTA_EXCEEDED:`storage.quota_exceeded`,STORAGE_WRITE_FAILED:`storage.write_failed`,STORAGE_READ_FAILED:`storage.read_failed`,STORAGE_ENTRY_CORRUPT:`storage.entry_corrupt`,STORAGE_CACHE_MISMATCH:`storage.cache_mismatch`,DENOISER_UNAVAILABLE:`denoiser.unavailable`,OUTPUT_SOURCE_FALLBACK:`output.source_fallback`,OUTPUT_TONEMAP_FALLBACK:`output.tonemap_fallback`,LIGHT_PLACEHOLDER_SKIPPED:`light.placeholder_skipped`,CAPABILITY_MISSING:`capability.missing`});Object.freeze({ERROR:`error`,WARNING:`warning`});const t=new Map;function n(e,t){return e.exclusive||t===`exclusive`&&e.shared>0?!1:(t===`exclusive`?e.exclusive=!0:e.shared++,!0)}function r(e,r,a){let o=t.get(e);o||(o={shared:0,exclusive:!1,queue:[]},t.set(e,o));let s=i(()=>{for(r===`exclusive`?o.exclusive=!1:o.shared--;o.queue.length&&n(o,o.queue[0].mode);)o.queue.shift().grant();!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e)});return o.queue.length===0&&n(o,r)?Promise.resolve(s):a?(!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e),Promise.resolve(null)):new Promise(e=>o.queue.push({mode:r,grant:()=>e(s)}))}function i(e){let t=!1;return()=>{t||(t=!0,e())}}const a=()=>typeof navigator<`u`&&navigator.locks?.request?navigator.locks:null;function o(e,{mode:t=`exclusive`,ifAvailable:n=!1}={}){let o=a();return o?new Promise((r,a)=>{o.request(e,{mode:t,ifAvailable:n},e=>{if(!e){r(null);return}return new Promise(e=>r(i(e)))}).catch(a)}):r(e,t,n)}async function s(){let e=a();if(!e)return new Set(t.keys());let{held:n=[]}=await e.query();return new Set(n.map(e=>e.name))}const c=new TextEncoder;function l(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function u(e){let t=typeof e==`string`?c.encode(e):e;return l(new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)))}async function d(e){return(await u(e)).slice(0,32)}var f=class{constructor(){this._handlers=new Map}addEventListener(e,t){this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t)}removeEventListener(e,t){this._handlers.get(e)?.delete(t)}dispatchEvent(e){for(let t of[...this._handlers.get(e.type)??[]])t.call(this,e)}},p=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}},m=class{constructor(e){this._ops=new p(e)}async call(e,t){return this._ops[e](t)}dispose(){this._ops.dispose()}};const h=Object.freeze({CACHE:`cache`,USER:`user`,SCRATCH:`scratch`}),g=Object.freeze({DOWNLOADS:`downloads`,ARCHIVES:`archives`,SCENES:`scenes`,CDF:`cdf`,SPILL:`spill`}),_=`meta.json`,v=100*1024**3,y=64*1024**2,b=8*1024**2,x=new TextEncoder;function S(e,{copy:t,transfer:n}){if(typeof e==`string`&&(e=x.encode(e)),e instanceof ArrayBuffer){if(!t||n)return{args:{buffer:e},list:[e]};let r=e.slice(0);return{args:{buffer:r},list:[r]}}if(!ArrayBuffer.isView(e))throw TypeError(`storage: write expects an ArrayBuffer, a typed array, a Blob or a string`);let{buffer:r,byteOffset:i,byteLength:a}=e,o=typeof SharedArrayBuffer<`u`&&r instanceof SharedArrayBuffer;if(!t)return{args:{buffer:r,byteOffset:i,byteLength:a},list:[]};if(o){let e=new Uint8Array(a);return e.set(new Uint8Array(r,i,a)),{args:{buffer:e.buffer},list:[e.buffer]}}if(n&&i===0&&a===r.byteLength)return{args:{buffer:r},list:[r]};let s=r.slice(i,i+a);return{args:{buffer:s},list:[s]}}async function C(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return JSON.parse(await n.text())}catch{return null}}async function*w(e){for await(let[t,n]of e.entries())n.kind===`directory`&&(yield[t,n])}var T=class{constructor(e,t,n,r,i){this.area=e,this.id=t,this.key=n.key,this.meta=n,this._dir=r,this._release=i}get bytes(){return this.meta.bytes}get extra(){return this.meta.extra??{}}async file(t){try{return await(await this._dir.getFileHandle(t)).getFile()}catch(n){return this.area.manager._issue(e.STORAGE_READ_FAILED,`could not read ${this.area.name}/${this.id}/${t}`,{error:n.message}),null}}async json(e){let t=await this.file(e);return t?JSON.parse(await t.text()):null}release(){this._release?.(),this._release=null}},E=class{constructor(e,t,n,r,i,{sizes:a={},append:o=!1}={}){this.area=e,this.id=t,this.key=n,this._info=r,this._release=i,this._writers=new Map,this._sizes={...a},this._append=o,this._done=!1,this._committedBytes=o?Object.values(a).reduce((e,t)=>e+t,0):0}get _transport(){return this.area.manager._transport}get _path(){return[this.area.name,this.id]}async _writer(e){let t=this._writers.get(e);if(!t){let n=this._append&&e in this._sizes,r=n&&(this._info.growable??[]).includes(e)?this._sizes[e]:void 0;t=this._transport.call(`openWriter`,{path:this._path,name:e,truncate:!n,length:r}),this._writers.set(e,t)}return(await t).id}async write(e,t,{at:n,transfer:r=!1}={}){this._assertOpen();let{args:i,list:a}=(typeof Blob<`u`&&t instanceof Blob?null:S(t,{copy:!0,transfer:r}))??S(await t.arrayBuffer(),{copy:!0,transfer:!0}),o=await this._writer(e);return this._transport.call(`write`,{id:o,at:n,...i},a)}async writeFile(e,t){this._assertOpen(),typeof Blob<`u`&&t instanceof Blob&&(t=await t.arrayBuffer());let{args:n,list:r}=S(t,{copy:!0,transfer:!0}),{size:i}=await this._transport.call(`writeFile`,{path:this._path,name:e,...n},r);return this._sizes[e]=i,i}writeJSON(e,t){return this.writeFile(e,JSON.stringify(t))}async writeStream(e,t,{onProgress:n=null,signal:r=null,batchBytes:i=b}={}){let a=t.getReader(),o=[],s=new Uint8Array(i),c=0,l=0,u=async()=>{if(c===0)return;let t=c===i?s:s.slice(0,c);s=new Uint8Array(i),c=0,o.push(this.write(e,t,{transfer:!0})),o.length>=4&&await o.shift()};try{for(;;){if(r?.aborted)throw r.reason??new DOMException(`aborted`,`AbortError`);let{done:e,value:t}=await a.read();if(e)break;let o=0;for(;o<t.length;){let e=Math.min(t.length-o,i-c);s.set(t.subarray(o,o+e),c),c+=e,o+=e,l+=e,c===i&&await u()}n?.(l)}return await u(),await Promise.all(o),l}catch(e){throw a.cancel().catch(()=>{}),await Promise.allSettled(o),e}}async commit(e={}){this._assertOpen(),this._done=!0;try{for(let[e,t]of this._writers){let{size:n}=await this._transport.call(`closeWriter`,{id:(await t).id});this._sizes[e]=n}this._writers.clear();let t=Date.now(),n={v:1,key:this.key,label:this._info.label??``,kind:this.area.kind,files:{...this._sizes},bytes:Object.values(this._sizes).reduce((e,t)=>e+t,0),createdAt:this._info.createdAt??t,lastUsed:t,pinned:this._info.pinned===!0,extra:{...this._info.extra,...e}},r=this._info.growable??[];r.length&&(n.growable=r);let{args:i,list:a}=S(JSON.stringify(n),{copy:!1});return await this._transport.call(`writeFile`,{path:this._path,name:_,...i},a),this.area.kind===h.CACHE&&this.area.manager._countCacheBytes(n.bytes-this._committedBytes),this.area.manager._changed(this.area.name),n}catch(e){throw await this._discard(),this.area.manager._writeFailed(this.area.name,e),e}finally{this._release?.(),this._release=null}}async abort(){if(!this._done){this._done=!0;try{this._append?await this._closeAll(!0):await this._discard()}finally{this._release?.(),this._release=null}}}async _closeAll(e){for(let t of this._writers.values())try{await this._transport.call(`closeWriter`,{id:(await t).id,abort:e})}catch{}this._writers.clear()}async _discard(){await this._closeAll(!0),await this.area._removeDir(this.id)}_assertOpen(){if(this._done)throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`)}},D=class{constructor(e,t,n){this.manager=e,this.name=t,this.kind=n}_lockName(e){return`${this.manager.namespace}:store:${this.name}:${e}`}async _dir(e=!1){try{return await this.manager._root.getDirectoryHandle(this.name,{create:e})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _entryDir(e,t=!1){let n=await this._dir(t);if(!n)return null;try{return await n.getDirectoryHandle(e,{create:t})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _removeDir(e){let t=await this._dir(!1);if(t)try{await t.removeEntry(e,{recursive:!0})}catch(e){if(e.name!==`NotFoundError`)throw e}}async _validMeta(e,t=null){let n=await C(e,_);if(!n||n.v!==1||typeof n.key!=`string`||t!==null&&n.key!==t)return null;let r=n.growable??[];for(let[t,i]of Object.entries(n.files??{}))try{let n=await(await e.getFileHandle(t)).getFile();if(n.size!==i&&!(r.includes(t)&&n.size>i))return null}catch{return null}return n}async open(t,{wait:n=!1}={}){let r=await d(t),i=await o(this._lockName(r),{mode:`shared`,ifAvailable:!n});if(!i)return null;try{let e=await this._entryDir(r),n=e?await this._validMeta(e,t):null;return n?(Date.now()-n.lastUsed>36e5&&this._touch(r,n),new T(this,r,n,e,i)):(i(),null)}catch(t){return i(),this.manager._issue(e.STORAGE_READ_FAILED,`could not open ${this.name} entry`,{error:t.message}),null}}async has(e){let t=await this.open(e);return t?.release(),!!t}_touch(e,t){let n={...t,lastUsed:Date.now()},{args:r,list:i}=S(JSON.stringify(n),{copy:!1});this.manager._transport.call(`writeFile`,{path:[this.name,e],name:_,...r},i).catch(()=>{}),t.lastUsed=n.lastUsed}async create(t,{label:n=``,pinned:r=!1,expectedBytes:i=0,extra:a={},growable:s=[]}={}){let c=await d(t),l=await o(this._lockName(c),{mode:`exclusive`});try{return i>0&&!await this.manager.ensureSpace(i,this.kind)?(l(),this.manager._issue(e.STORAGE_QUOTA_EXCEEDED,`no room for ${(i/1048576).toFixed(0)} MB in ${this.name}`,{area:this.name,expectedBytes:i}),null):(await this._removeDir(c),await this._entryDir(c,!0),new E(this,c,t,{label:n,pinned:r,extra:a,growable:s},l))}catch(e){return l(),this.manager._writeFailed(this.name,e),null}}async patchMeta(e,t){let n=await d(e),r=await o(this._lockName(n),{mode:`shared`,ifAvailable:!0});if(!r)return!1;try{let r=await this._entryDir(n),i=r?await this._validMeta(r,e):null;if(!i)return!1;let{args:a,list:o}=S(JSON.stringify({...i,...t,v:1,key:e}),{copy:!1});return await this.manager._transport.call(`writeFile`,{path:[this.name,n],name:_,...a},o),!0}finally{r()}}async edit(e){let t=await d(e),n=await o(this._lockName(t),{mode:`exclusive`});try{let r=await this._entryDir(t),i=r?await this._validMeta(r,e):null;if(!i)return n(),null;let a={label:i.label,pinned:i.pinned,extra:i.extra,createdAt:i.createdAt,growable:i.growable};return new E(this,t,e,a,n,{sizes:i.files,append:!0})}catch(e){return n(),this.manager._writeFailed(this.name,e),null}}async remove(e){return this.removeById(await d(e))}async removeById(e){let t=await o(this._lockName(e),{mode:`exclusive`,ifAvailable:!0});if(!t)return!1;try{return await this._removeDir(e),this.manager._changed(this.name),!0}finally{t()}}async list(){let e=await this._dir(!1);if(!e)return[];let t=[];for await(let[n,r]of w(e)){let e=await C(r,_);e?.v===1&&t.push({...e,id:n})}return t}async clear(){let e=0;for(let{id:t}of await this.list())await this.removeById(t)&&e++;return e}async sweep(){let e=await this._dir(!1);if(!e)return 0;let t=await s(),n=0;for await(let[r,i]of w(e))t.has(this._lockName(r))||await this._validMeta(i)||await this.removeById(r)&&n++;return n}},O=class extends f{constructor({root:e,transport:t,namespace:n}){super(),this.namespace=n,this._root=e,this._transport=t,this._areas=new Map,this._budget=null,this._cacheTotal=null;for(let e of Object.values(g))this.defineArea(e,{kind:e===g.SPILL?h.SCRATCH:h.CACHE})}defineArea(e,{kind:t=h.CACHE}={}){let n=this._areas.get(e);if(n){if(n.kind!==t)throw Error(`storage: area \"${e}\" is already defined as ${n.kind}`);return n}let r=new D(this,e,t);return this._areas.set(e,r),r}area(e){let t=this._areas.get(e);if(!t)throw Error(`storage: unknown area \"${e}\"`);return t}get areaNames(){return[...this._areas.keys()]}async estimate(){let e=typeof navigator<`u`?navigator.storage:null;if(!e?.estimate)return{quota:1/0,usage:0};let{quota:t=1/0,usage:n=0}=await e.estimate();return{quota:t,usage:n}}async persisted(){return await globalThis.navigator?.storage?.persisted?.()===!0}async persist(){let e=await globalThis.navigator?.storage?.persist?.()===!0;return this._changed(null),e}async budget(){if(this._budget!==null)return this._budget;let{quota:e}=await this.estimate();return Math.min(e*.3,v)}setBudget(e){this._budget=e===null?null:Math.max(0,e),this._changed(null)}async _cacheBytes(){let e=this._cacheTotal;return(!e||Date.now()-e.at>3e4)&&(e=this._cacheTotal={at:Date.now(),bytes:0,ready:null},e.ready=this._cacheEntries().then(t=>{e.bytes+=t.reduce((e,t)=>e+(t.meta.bytes??0),0)}),e.ready.catch(()=>{this._cacheTotal===e&&(this._cacheTotal=null)})),await e.ready,e.bytes}_countCacheBytes(e){this._cacheTotal&&(this._cacheTotal.bytes+=e)}async _cacheEntries(){let e=[];for(let t of this._areas.values())if(t.kind===h.CACHE)for(let n of await t.list())e.push({area:t,meta:n});return e}async usage(){let{quota:e,usage:t}=await this.estimate(),n={},r=0;for(let e of this._areas.values()){let t=await e.list(),i=t.reduce((e,t)=>e+(t.bytes??0),0);n[e.name]={kind:e.kind,bytes:i,entries:t.length},e.kind===h.CACHE&&(r+=i)}return{quota:e,usage:t,persisted:await this.persisted(),budget:await this.budget(),cacheBytes:r,areas:n}}async collect({freeBytes:e=null}={}){let t=await this._cacheEntries(),n=await this.budget(),r=this._cacheTotal={at:Date.now(),bytes:t.reduce((e,t)=>e+(t.meta.bytes??0),0),ready:null},i=e??Math.max(0,r.bytes-n);if(i<=0)return 0;let a=await s(),o=t.filter(({area:e,meta:t})=>!t.pinned&&!a.has(e._lockName(t.id))).sort((e,t)=>e.meta.lastUsed-t.meta.lastUsed),c=0;for(let{area:e,meta:t}of o){if(c>=i)break;await e.removeById(t.id)&&(c+=t.bytes??0,r.bytes-=t.bytes??0)}return c}async ensureSpace(e,t=h.CACHE){let n=async()=>{let{quota:n,usage:r}=await this.estimate(),i=e+y-(n-r);return t===h.CACHE?{free:i,budget:await this._cacheBytes()+e-await this.budget()}:{free:i,budget:0}},r=await n();return r.free<=0&&r.budget<=0?!0:(await this.collect({freeBytes:Math.max(r.free,r.budget)}),(await n()).free<=0)}async sweep(){let e=0;for(let t of this._areas.values())e+=await t.sweep(),t.kind===h.SCRATCH&&(e+=await t.clear());return e}_changed(e){this.dispatchEvent({type:`change`,area:e})}_issue(e,t,n={}){this.dispatchEvent({type:`issue`,code:e,message:t,detail:n})}_writeFailed(t,n){let r=n?.name===`QuotaExceededError`;this._issue(r?e.STORAGE_QUOTA_EXCEEDED:e.STORAGE_WRITE_FAILED,`${t}: ${n?.message??n}`,{area:t,error:n?.name})}dispose(){this._transport?.dispose(),this._transport=null,this._areas.clear()}};function k({namespace:e,root:t}){let n=new m(t);n.inline=!0;let r=new O({root:t,transport:n,namespace:e});return r.sweep().catch(()=>{}),r}const A=Object.freeze({IMMUTABLE:`immutable`,REVALIDATE:`revalidate`,NETWORK:`network`}),j=(e,t)=>({loaded:e,total:t,lengthComputable:t>0&&e<=t}),M=(e,t)=>e.headers?.get?.(t)??null,N=e=>e.reason??new DOMException(`aborted`,`AbortError`);function P(e){try{let t=new URL(e,globalThis.location?.href??`http://localhost/`).pathname;return decodeURIComponent(t.split(`/`).pop())||`download`}catch{return`download`}}async function F(e,{onProgress:t,signal:n}){let r=Number(M(e,`content-length`))||0,i=M(e,`content-type`)??``;if(!e.body)return new Blob([await e.arrayBuffer()],{type:i});let a=e.body.getReader(),o=[],s=0;for(;;){if(n?.aborted)throw a.cancel().catch(()=>{}),N(n);let{done:e,value:i}=await a.read();if(e)break;o.push(i),s+=i.length,t?.(j(s,r))}return new Blob(o,{type:i})}const I=(e,t,n)=>new File([e],t,{type:n||e.type,lastModified:e.lastModified??Date.now()}),L=()=>{};var R=class{constructor(e){this._storage=e,this._revalidating=new Set}get _area(){return this._storage?.area(g.DOWNLOADS)??null}async fetch(e,{key:t=e,name:n=P(e),policy:r=A.REVALIDATE,maxAgeMs:i=864e5,onProgress:a=null,signal:o=null,fetchOptions:s={}}={}){let c=this._area;if(c&&r!==A.NETWORK){let o=await c.open(t);if(o){let c=await o.file(`data`);if(c)return r===A.REVALIDATE&&Date.now()-(o.extra.checkedAt??0)>=i&&this._revalidate(e,t,n,o.extra,s),a?.(j(c.size,c.size)),{file:I(c,n,o.extra.contentType),release:()=>o.release(),fromCache:!0};o.release()}}return this._download(e,t,n,{onProgress:a,signal:o,fetchOptions:s,cache:!!c})}async has(e){return await this._area?.has(e)===!0}async _download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:o}){if(i?.aborted)throw N(i);let s=await fetch(e,{...a,signal:i});if(!s.ok)throw Error(`HTTP ${s.status} fetching ${e}`);let c=Number(M(s,`content-length`))||0,l={url:e,contentType:M(s,`content-type`)??``,lastModified:M(s,`last-modified`),contentLength:c||null,checkedAt:Date.now()},u=o&&s.body?await this._area.create(t,{label:n,expectedBytes:c}):null;if(!u)return{file:I(await F(s,{onProgress:r,signal:i}),n,l.contentType),release:L,fromCache:!1};try{await u.writeStream(`data`,s.body,{signal:i,onProgress:e=>r?.(j(e,c))}),await u.commit(l)}catch(o){if(await u.abort(),o?.name!==`QuotaExceededError`)throw o;return this._download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:!1})}let d=await this._area.open(t,{wait:!0}),f=d&&await d.file(`data`);if(!f)throw d?.release(),Error(`storage: ${n} vanished right after it was saved`);return{file:I(f,n,l.contentType),release:()=>d.release(),fromCache:!1}}async _revalidate(e,t,n,r,i){if(this._revalidating.has(t))return;this._revalidating.add(t);let a=!1;try{let t=new Headers(i?.headers);t.set(`Range`,`bytes=0-0`);let n=await fetch(e,{...i,headers:t});if(n.body?.cancel().catch(()=>{}),n.ok){let e=M(n,`last-modified`),t=n.status===206?Number(M(n,`content-range`)?.match(/\\/(\\d+)$/)?.[1])||null:Number(M(n,`content-length`))||null;a=!!(e&&r.lastModified&&e!==r.lastModified||t&&r.contentLength&&t!==r.contentLength)}}catch{}try{if(a){let{release:r}=await this._download(e,t,n,{fetchOptions:i,cache:!0});r()}else await this._area.patchMeta(t,{extra:{...r,checkedAt:Date.now()}})}catch{}finally{this._revalidating.delete(t)}}};let z={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`,storage:`auto`},B=null;async function V(){return B||(B=await import(z.ortRuntimeUrl),B.env.wasm.wasmPaths=z.ortWasmPaths,B.env.logLevel=`error`,B)}let H=null,U=null,W=null;function G(){return W??=(async()=>{if(z.storage===!1||!navigator.storage?.getDirectory)return new R(null);try{let e=await(await navigator.storage.getDirectory()).getDirectoryHandle(z.cacheNamespace,{create:!0}),t=k({namespace:z.cacheNamespace,root:e});return await K(t).catch(()=>{}),new R(t)}catch{return new R(null)}})(),W}async function K(e){let t=`${z.cacheNamespace}:ai-upscaler-models`;if(typeof indexedDB>`u`||!indexedDB.databases||!(await indexedDB.databases()).some(e=>e.name===t))return;let n=await new Promise((e,n)=>{let r=indexedDB.open(t);r.onerror=()=>n(r.error),r.onsuccess=()=>{let t=r.result;if(!t.objectStoreNames.contains(`models`)){t.close(),e([]);return}let i=[],a=t.transaction(`models`,`readonly`).objectStore(`models`).openCursor();a.onerror=()=>n(a.error),a.onsuccess=()=>{let n=a.result;if(!n){t.close(),e(i);return}i.push([n.key,n.value]),n.continue()}}}),r=e.area(`downloads`);for(let[e,t]of n){if(typeof e!=`string`||!(t instanceof ArrayBuffer)||await r.has(e))continue;let n=await r.create(e,{label:e.split(`/`).pop(),expectedBytes:t.byteLength});n&&(await n.write(`data`,t,{transfer:!0}),await n.commit({url:e,contentType:`application/octet-stream`,checkedAt:Date.now()}))}await new Promise(e=>{let n=indexedDB.deleteDatabase(t);n.onsuccess=n.onerror=n.onblocked=()=>e()})}async function q(e){let{file:t,release:n,fromCache:r}=await(await G()).fetch(e);try{let e=await t.arrayBuffer();return r&&console.log(`AI Upscaler Worker: model loaded from cache (${(e.byteLength/1024/1024).toFixed(1)}MB)`),e}finally{n()}}async function J(e,t){if(H&&U===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}H&&=(await H.release(),null);let[n,r]=await Promise.all([q(e),V()]);H=await r.InferenceSession.create(n,t),U=e;let i=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);i=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${i}`)}catch{}let a=(n.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${a}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:i})}async function Y(e,t,n,r){let i=await V(),a=H.inputNames[0],o=H.outputNames[0],s=new i.Tensor(`float32`,e,[1,3,n,t]),c=(await H.run({[a]:s}))[o].data;self.postMessage({type:`inferred`,outputData:c,id:r},[c.buffer])}self.onmessage=async e=>{let{type:t}=e.data;try{t===`load`?(e.data.ortRuntimeUrl&&(z.ortRuntimeUrl=e.data.ortRuntimeUrl),e.data.ortWasmPaths&&(z.ortWasmPaths=e.data.ortWasmPaths),e.data.cacheNamespace&&(z.cacheNamespace=e.data.cacheNamespace),e.data.storage!==void 0&&(z.storage=e.data.storage),await J(e.data.url,e.data.sessionOptions)):t===`infer`?await Y(e.data.tileData,e.data.width,e.data.height,e.data.id):t===`dispose`&&H&&(await H.release(),H=null,U=null)}catch(t){self.postMessage({type:`error`,message:t.message,id:e.data?.id})}};", xs = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", bs], { type: "text/javascript;charset=utf-8" });
|
|
3807
|
+
function Ss(e) {
|
|
3800
3808
|
let t;
|
|
3801
3809
|
try {
|
|
3802
|
-
if (t =
|
|
3810
|
+
if (t = xs && (self.URL || self.webkitURL).createObjectURL(xs), !t) throw "";
|
|
3803
3811
|
let n = new Worker(t, {
|
|
3804
3812
|
type: "module",
|
|
3805
3813
|
name: e?.name
|
|
@@ -3808,7 +3816,7 @@ function hs(e) {
|
|
|
3808
3816
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
3809
3817
|
}), n;
|
|
3810
3818
|
} catch {
|
|
3811
|
-
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
3819
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(bs), {
|
|
3812
3820
|
type: "module",
|
|
3813
3821
|
name: e?.name
|
|
3814
3822
|
});
|
|
@@ -3816,7 +3824,7 @@ function hs(e) {
|
|
|
3816
3824
|
}
|
|
3817
3825
|
//#endregion
|
|
3818
3826
|
//#region src/Passes/AIUpscaler.js
|
|
3819
|
-
var
|
|
3827
|
+
var Cs = {
|
|
3820
3828
|
fast: {
|
|
3821
3829
|
2: "2x-spanx2-ch48.onnx",
|
|
3822
3830
|
4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
|
|
@@ -3830,17 +3838,17 @@ var gs = {
|
|
|
3830
3838
|
4: "4xNomos2_hq_mosr_fp32.onnx"
|
|
3831
3839
|
}
|
|
3832
3840
|
};
|
|
3833
|
-
function
|
|
3841
|
+
function ws() {
|
|
3834
3842
|
let { upscalerModelBaseUrl: e } = it(), t = {};
|
|
3835
|
-
for (let n in
|
|
3843
|
+
for (let n in Cs) {
|
|
3836
3844
|
t[n] = {};
|
|
3837
|
-
for (let r in
|
|
3845
|
+
for (let r in Cs[n]) t[n][r] = e + Cs[n][r];
|
|
3838
3846
|
}
|
|
3839
3847
|
return t;
|
|
3840
3848
|
}
|
|
3841
|
-
var
|
|
3849
|
+
var Ts = {
|
|
3842
3850
|
get QUALITY_PRESETS() {
|
|
3843
|
-
return
|
|
3851
|
+
return ws();
|
|
3844
3852
|
},
|
|
3845
3853
|
TILE_SIZE: 512,
|
|
3846
3854
|
TILE_OVERLAP: 16,
|
|
@@ -3851,17 +3859,17 @@ var vs = {
|
|
|
3851
3859
|
}],
|
|
3852
3860
|
graphOptimizationLevel: "all"
|
|
3853
3861
|
}
|
|
3854
|
-
},
|
|
3862
|
+
}, Es = class extends ur {
|
|
3855
3863
|
constructor(e, t, n = {}) {
|
|
3856
3864
|
if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
|
|
3857
|
-
this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => $n), this.getSaturation = n.getSaturation || (() => 1), this.getDisplayGain = n.getDisplayGain || (() => null), this.getTransparentBackground = n.getTransparentBackground || (() => !1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize ||
|
|
3865
|
+
this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => $n), this.getSaturation = n.getSaturation || (() => 1), this.getDisplayGain = n.getDisplayGain || (() => null), this.getTransparentBackground = n.getTransparentBackground || (() => !1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize || Ts.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
|
|
3858
3866
|
isUpscaling: !1,
|
|
3859
3867
|
isLoading: !1,
|
|
3860
3868
|
abortController: null
|
|
3861
3869
|
}, this._worker = null, this._currentModelUrl = null, this._tileId = 0, this._pendingWorkerHandlers = /* @__PURE__ */ new Map(), this._upscaledAlpha = null, this._upscaledAlphaWidth = 0, this._backupCanvas = null, this._baseWidth = e.width, this._baseHeight = e.height, this._toneMapper = null;
|
|
3862
3870
|
}
|
|
3863
3871
|
async _ensureSession() {
|
|
3864
|
-
let e =
|
|
3872
|
+
let e = Ts.QUALITY_PRESETS[this.quality];
|
|
3865
3873
|
if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
|
|
3866
3874
|
let t = e[this.scaleFactor];
|
|
3867
3875
|
if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
|
|
@@ -3871,14 +3879,14 @@ var vs = {
|
|
|
3871
3879
|
message: `Loading ${this.scaleFactor}x upscale model...`
|
|
3872
3880
|
});
|
|
3873
3881
|
try {
|
|
3874
|
-
this._worker ||= new
|
|
3882
|
+
this._worker ||= new Ss(), await new Promise((e, n) => {
|
|
3875
3883
|
let r = (t) => {
|
|
3876
3884
|
t.data.type === "loaded" ? (this._worker.removeEventListener("message", r), t.data.tileSize && !this._tileSizeOverride && (this.tileSize = t.data.tileSize), console.log(`AI Upscaler: ${this.scaleFactor}x model loaded, backend: ${t.data.backend}, tileSize: ${this.tileSize}`), e()) : t.data.type === "error" && (this._worker.removeEventListener("message", r), n(Error(t.data.message)));
|
|
3877
3885
|
}, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o, storage: s } = it();
|
|
3878
3886
|
this._worker.addEventListener("message", r), this._worker.postMessage({
|
|
3879
3887
|
type: "load",
|
|
3880
3888
|
url: t,
|
|
3881
|
-
sessionOptions:
|
|
3889
|
+
sessionOptions: Ts.SESSION_OPTIONS,
|
|
3882
3890
|
ortRuntimeUrl: i,
|
|
3883
3891
|
ortWasmPaths: a,
|
|
3884
3892
|
cacheNamespace: o,
|
|
@@ -3953,7 +3961,7 @@ var vs = {
|
|
|
3953
3961
|
alpha: !0
|
|
3954
3962
|
});
|
|
3955
3963
|
this._cacheUpscaledAlpha(t, n * i, r * i);
|
|
3956
|
-
let o =
|
|
3964
|
+
let o = Ts.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
|
|
3957
3965
|
for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
|
|
3958
3966
|
if (e.aborted) throw new DOMException("Aborted", "AbortError");
|
|
3959
3967
|
let l = Math.min(u * c, Math.max(0, n - s)), p = Math.min(o * c, Math.max(0, r - s)), m = Math.min(s, n - l), h = Math.min(s, r - p), g = this._extractTile(t, l, p, m, h), _ = await this._inferTile(g, m, h), v = l * i, y = p * i, b = m * i, x = h * i, S = this._tensorToImageData(_, b, x, v, y);
|
|
@@ -4096,7 +4104,7 @@ var vs = {
|
|
|
4096
4104
|
this.hdr = !!e;
|
|
4097
4105
|
}
|
|
4098
4106
|
setQuality(e) {
|
|
4099
|
-
if (!
|
|
4107
|
+
if (!Ts.QUALITY_PRESETS[e]) {
|
|
4100
4108
|
console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
|
|
4101
4109
|
return;
|
|
4102
4110
|
}
|
|
@@ -4119,9 +4127,9 @@ var vs = {
|
|
|
4119
4127
|
async dispose() {
|
|
4120
4128
|
this.abort(), this._cleanupPendingWorkerHandlers(), this._worker &&= (this._worker.postMessage({ type: "dispose" }), this._worker.terminate(), null), this._currentModelUrl = null, this._backupCanvas = null, this._upscaledAlpha = null, this.state.abortController = null, this._toneMapper?.dispose(), this._toneMapper = null, console.log("AIUpscaler disposed");
|
|
4121
4129
|
}
|
|
4122
|
-
},
|
|
4130
|
+
}, Ds = We("neural"), Os = 120, ks = 2, As = 1, js = 0, Ms = 300, Ns = 5, Ps = 3, Fs = 3, Is = 16, Ls = (e) => Math.max(0, 1 - e / Is), Rs = class extends ur {
|
|
4123
4131
|
constructor({ renderer: e, mainCanvas: t, stages: n, pipeline: r, getExposure: i, getSaturation: a, getDisplayGain: o = null, issues: s = null }) {
|
|
4124
|
-
super(), this.renderer = e, this._issues = s, this.mainCanvas = t, this.upscalerCanvas = this._createUpscalerCanvas(t), this.pipeline = r, this._stages = n, this._getExposure = i, this._getSaturation = a, this._getDisplayGain = o, this.denoiser = null, this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null, this.neuralRendering = !1, this.neuralRenderingSettings = {}, this._retouch = null, this._superResModule = null, this._neuralPostBusy = !1, this._postIsStillComplete = null, this._postRun = null, this._postRedo = null, this._postCancelled = !1, this._finalQuality =
|
|
4132
|
+
super(), this.renderer = e, this._issues = s, this.mainCanvas = t, this.upscalerCanvas = this._createUpscalerCanvas(t), this.pipeline = r, this._stages = n, this._getExposure = i, this._getSaturation = a, this._getDisplayGain = o, this.denoiser = null, this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null, this.neuralRendering = !1, this.neuralRenderingSettings = {}, this._retouch = null, this._superResModule = null, this._neuralPostBusy = !1, this._postIsStillComplete = null, this._postRun = null, this._postRedo = null, this._postCancelled = !1, this._finalQuality = Qr.oidnQuality, this.finalDenoise = Qr.enableOIDN, this.continuousDenoise = Qr.continuousDenoise, this.continuousDenoiseInterval = Qr.continuousDenoiseInterval, this._lastCadenceAt = -Infinity, this._lastCadenceSamples = 0, this._failedRefreshes = 0, this._cadenceSuspended = !1, this._movingDenoiseMs = [], this._movingHopeless = !1, this._holdWhileMoving = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this.temporalHistory = Qr.oidnTemporalHistory, this._history = null, this._historyDirty = !0, this._knownResetCount = 0, this._seenTracedFrames = 0, this._viewProj = new yr(), this._historyCamera = {
|
|
4125
4133
|
world: null,
|
|
4126
4134
|
projInv: null,
|
|
4127
4135
|
viewProj: null,
|
|
@@ -4152,9 +4160,9 @@ var vs = {
|
|
|
4152
4160
|
}
|
|
4153
4161
|
setupDenoiser() {
|
|
4154
4162
|
let e = this._stages.pathTracer;
|
|
4155
|
-
this.denoiser = new
|
|
4156
|
-
enableOIDN:
|
|
4157
|
-
oidnQuality:
|
|
4163
|
+
this.denoiser = new rs(this.renderer, {
|
|
4164
|
+
enableOIDN: Qr.enableOIDN,
|
|
4165
|
+
oidnQuality: Qr.oidnQuality,
|
|
4158
4166
|
backendParams: () => ({
|
|
4159
4167
|
device: this.renderer.backend.device,
|
|
4160
4168
|
adapterInfo: null
|
|
@@ -4205,9 +4213,9 @@ var vs = {
|
|
|
4205
4213
|
setupUpscaler() {
|
|
4206
4214
|
if (!this.upscalerCanvas) return;
|
|
4207
4215
|
let e = this._stages.pathTracer;
|
|
4208
|
-
this.upscaler = new
|
|
4209
|
-
scaleFactor:
|
|
4210
|
-
quality:
|
|
4216
|
+
this.upscaler = new Es(this.upscalerCanvas, this.renderer, {
|
|
4217
|
+
scaleFactor: Qr.upscalerScale || 2,
|
|
4218
|
+
quality: Qr.upscalerQuality || "fast",
|
|
4211
4219
|
getSourceCanvas: () => this.renderer.domElement,
|
|
4212
4220
|
refreshInput: () => {
|
|
4213
4221
|
let e = this.pipeline?.context;
|
|
@@ -4223,7 +4231,7 @@ var vs = {
|
|
|
4223
4231
|
getSaturation: () => this._getSaturation(),
|
|
4224
4232
|
getDisplayGain: () => this._getDisplayGain?.() ?? null,
|
|
4225
4233
|
getTransparentBackground: () => !!this._settings?.get("transparentBackground")
|
|
4226
|
-
}), this.upscaler.enabled =
|
|
4234
|
+
}), this.upscaler.enabled = Qr.enableUpscaler || !1, this._upscalerResChangedHandler = (e) => this.dispatchEvent({
|
|
4227
4235
|
type: P.RESOLUTION_CHANGED,
|
|
4228
4236
|
width: e.width,
|
|
4229
4237
|
height: e.height
|
|
@@ -4237,7 +4245,7 @@ var vs = {
|
|
|
4237
4245
|
}
|
|
4238
4246
|
setDenoiserStrategy(e, t) {
|
|
4239
4247
|
let n = this._stages;
|
|
4240
|
-
|
|
4248
|
+
Kr.includes(e) || (this._issues?.record(Ye.DENOISER_UNAVAILABLE, `'${e}' is not a live denoiser (${Kr.join(", ")}) — none is used`, { strategy: e }), e = "none"), e === "nrd" && this._isPanorama() && (this._issues?.record(Ye.DENOISER_UNAVAILABLE, "NRD cannot run in a panorama — oidn is used", { strategy: e }), e = "oidn"), this._clearDenoiserTextures(), n.nrd && (n.nrd.enabled = e === "nrd"), n.nrd?.enabled && (n.nrd.resetHistory?.(), this._applyNRDPreset(t || "medium")), this.setContinuousDenoise(e === "oidn");
|
|
4241
4249
|
}
|
|
4242
4250
|
setAutoExposureEnabled(e, t) {
|
|
4243
4251
|
this._stages.autoExposure?.setEnabled(e, t);
|
|
@@ -4260,8 +4268,8 @@ var vs = {
|
|
|
4260
4268
|
get holdsWhileMoving() {
|
|
4261
4269
|
if (!this._stages.pathTracer?.viewIsChanging || !this.continuousDenoise || this._cadenceSuspended || !this.denoiser?.enabled || this._movingHopeless) return !1;
|
|
4262
4270
|
let e = this.movingCostMs, t = this._movingDenoiseMs.length;
|
|
4263
|
-
e >
|
|
4264
|
-
let n = !this._movingHopeless && (t < 2 || e <=
|
|
4271
|
+
e > Ms * Ps && (this._movingHopeless = !0, this._syncGBufferStages());
|
|
4272
|
+
let n = !this._movingHopeless && (t < 2 || e <= Ms);
|
|
4265
4273
|
return this._holdWhileMoving = (this._holdWhileMoving === null || this._holdWhileMoving) && n, this._holdWhileMoving;
|
|
4266
4274
|
}
|
|
4267
4275
|
skipsTrace() {
|
|
@@ -4278,7 +4286,7 @@ var vs = {
|
|
|
4278
4286
|
this.pipeline?.context?.removeTexture("oidn:output"), this.denoiser?.invalidateOutput();
|
|
4279
4287
|
}
|
|
4280
4288
|
_checkHeldFrameHealthy() {
|
|
4281
|
-
!this.denoiser?.hasOutput || this._failedRefreshes <
|
|
4289
|
+
!this.denoiser?.hasOutput || this._failedRefreshes < Fs || this._unpublishOutput();
|
|
4282
4290
|
}
|
|
4283
4291
|
tickContinuousDenoise(e) {
|
|
4284
4292
|
let t = this.denoiser;
|
|
@@ -4288,12 +4296,12 @@ var vs = {
|
|
|
4288
4296
|
if (!n) this._holdWhileMoving = null, this._movingDenoiseMs.length = 0;
|
|
4289
4297
|
else if (!this.holdsWhileMoving) return !1;
|
|
4290
4298
|
if (t.state.isDenoising || t.state.isLoading || !n && e <= this._lastCadenceSamples) return !1;
|
|
4291
|
-
let r = performance.now(), i = n ?
|
|
4299
|
+
let r = performance.now(), i = n ? js : this._lastCadenceSamples === 0 ? As : ks, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
|
|
4292
4300
|
if (r - this._lastCadenceAt < a) return !1;
|
|
4293
|
-
this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs >
|
|
4301
|
+
this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > Os && (this._cadenceDowngraded = !0);
|
|
4294
4302
|
let o = this._cadenceDowngraded ? this.previewQuality() : this._finalQuality;
|
|
4295
4303
|
return t.quality !== o && t.updateQuality(o), t.start({ continuous: !0 }).then((e) => {
|
|
4296
|
-
this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length >
|
|
4304
|
+
this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > Ns && this._movingDenoiseMs.shift());
|
|
4297
4305
|
}), !0;
|
|
4298
4306
|
}
|
|
4299
4307
|
previewQuality() {
|
|
@@ -4337,7 +4345,7 @@ var vs = {
|
|
|
4337
4345
|
r && (this._ensureHistory().merge(r, t.frameCount, this._historyCameraNow(), {
|
|
4338
4346
|
commit: !0,
|
|
4339
4347
|
keepHistory: !this._historyDirty && !n,
|
|
4340
|
-
historyScale:
|
|
4348
|
+
historyScale: Ls(t.frameCount)
|
|
4341
4349
|
}), this._historyDirty = !1);
|
|
4342
4350
|
}
|
|
4343
4351
|
afterReset() {
|
|
@@ -4379,9 +4387,9 @@ var vs = {
|
|
|
4379
4387
|
let e = this._stages.pathTracer, t = this._history;
|
|
4380
4388
|
if (!t?.valid || this._historyDirty || !this.historyActive || e.isComplete || e.resetCount !== this._knownResetCount || t.width !== this._lastRenderWidth || t.height !== this._lastRenderHeight) return null;
|
|
4381
4389
|
if (e.frameCount <= 1) return t.textures;
|
|
4382
|
-
if (e.frameCount >=
|
|
4390
|
+
if (e.frameCount >= Is) return null;
|
|
4383
4391
|
let n = this._historyInputs();
|
|
4384
|
-
return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale:
|
|
4392
|
+
return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Ls(e.frameCount) }) : null;
|
|
4385
4393
|
}
|
|
4386
4394
|
_historyInputs() {
|
|
4387
4395
|
let e = this._stages.pathTracer, t = this.pipeline?.context, n = this.renderer?.backend;
|
|
@@ -4406,7 +4414,7 @@ var vs = {
|
|
|
4406
4414
|
return t.world = e.cameraWorldMatrix.value.elements, t.projInv = e.cameraProjectionMatrixInverse.value.elements, t.viewProj = this._viewProj.elements, t.orthographic = e.uniforms?.get("cameraProjection")?.value === Oe.orthographic, t;
|
|
4407
4415
|
}
|
|
4408
4416
|
_ensureHistory() {
|
|
4409
|
-
return this._history ??= new
|
|
4417
|
+
return this._history ??= new ys(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
|
|
4410
4418
|
}
|
|
4411
4419
|
_releaseHistory() {
|
|
4412
4420
|
this._history?.dispose(), this._history = null, this._historyDirty = !0, this._movedPlacements.clear();
|
|
@@ -4444,15 +4452,15 @@ var vs = {
|
|
|
4444
4452
|
return;
|
|
4445
4453
|
}
|
|
4446
4454
|
if (!this.pipeline?.context?.getTexture("oidn:output")) {
|
|
4447
|
-
|
|
4455
|
+
Ds.warn("neural pass skipped: no denoised picture — it needs OIDN");
|
|
4448
4456
|
return;
|
|
4449
4457
|
}
|
|
4450
4458
|
this._neuralPostBusy = !0, this.dispatchEvent({ type: P.UPSCALING_START });
|
|
4451
4459
|
try {
|
|
4452
|
-
let i = await import("./NeuralSuperRes-
|
|
4460
|
+
let i = await import("./NeuralSuperRes-C8Mf3tJX.js").then((e) => e.t);
|
|
4453
4461
|
this._superResModule = i;
|
|
4454
|
-
let a = n ? await import("./NeuralRetouch-
|
|
4455
|
-
if (n && !c && (
|
|
4462
|
+
let a = n ? await import("./NeuralRetouch-BD9E-Yht.js").then((e) => e.t) : null, o = this.denoiser?._outTexSize, s = (o?.width ?? 0) * (o?.height ?? 0), c = n && s <= a.RETOUCH_MAX_PIXELS;
|
|
4463
|
+
if (n && !c && (Ds.warn(`Neural rendering skipped: the render is ${(s / 1e6).toFixed(1)} MP, above the ${(a.RETOUCH_MAX_PIXELS / 1e6).toFixed(1)} MP the pass survives.` + (t ? " The upscale still ran." : "")), this._releaseNeuralRetouch()), !t && !c) {
|
|
4456
4464
|
r && !this._postCancelled && await this.upscaler.start();
|
|
4457
4465
|
return;
|
|
4458
4466
|
}
|
|
@@ -4496,7 +4504,7 @@ var vs = {
|
|
|
4496
4504
|
height: d.height
|
|
4497
4505
|
});
|
|
4498
4506
|
} catch (e) {
|
|
4499
|
-
|
|
4507
|
+
Ds.warn("neural pass failed", e);
|
|
4500
4508
|
} finally {
|
|
4501
4509
|
this._neuralPostBusy = !1, this.dispatchEvent({ type: P.UPSCALING_END });
|
|
4502
4510
|
}
|
|
@@ -4649,16 +4657,16 @@ var vs = {
|
|
|
4649
4657
|
e && (e.removeTexture("nrd:output"), e.removeTexture("oidn:output"));
|
|
4650
4658
|
}
|
|
4651
4659
|
_applyNRDPreset(e) {
|
|
4652
|
-
let t =
|
|
4660
|
+
let t = Zr[e];
|
|
4653
4661
|
if (!t) return;
|
|
4654
4662
|
let n = {};
|
|
4655
|
-
for (let e of
|
|
4663
|
+
for (let e of Xr) n[e] = Yr[e];
|
|
4656
4664
|
this._stages.nrd?.updateParameters({
|
|
4657
4665
|
...n,
|
|
4658
4666
|
...t
|
|
4659
4667
|
});
|
|
4660
4668
|
}
|
|
4661
|
-
},
|
|
4669
|
+
}, zs = class {
|
|
4662
4670
|
constructor() {
|
|
4663
4671
|
this.layer = "hud", this.visible = !1, this._tileBounds = null, this._imageWidth = 1, this._imageHeight = 1, this.enabled = !0, this._borderColor = "rgba(255, 0, 0, 0.6)", this._borderWidthRatio = 1 / 540, this._borderWidthMin = 1.5, this._borderWidthMax = 4;
|
|
4664
4672
|
}
|
|
@@ -4682,7 +4690,7 @@ var vs = {
|
|
|
4682
4690
|
dispose() {
|
|
4683
4691
|
this.visible = !1;
|
|
4684
4692
|
}
|
|
4685
|
-
},
|
|
4693
|
+
}, Bs = class {
|
|
4686
4694
|
constructor(e, t) {
|
|
4687
4695
|
this.layer = "scene", this._enabled = !0, this._scene = e, this._camera = t, this._build([]);
|
|
4688
4696
|
}
|
|
@@ -4720,11 +4728,11 @@ var vs = {
|
|
|
4720
4728
|
this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
|
|
4721
4729
|
}
|
|
4722
4730
|
};
|
|
4723
|
-
function
|
|
4731
|
+
function Vs(e = !1) {
|
|
4724
4732
|
let t = document.createElement("canvas");
|
|
4725
4733
|
return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
|
|
4726
4734
|
}
|
|
4727
|
-
function
|
|
4735
|
+
function Hs(e, t = Infinity) {
|
|
4728
4736
|
let n = e?.getBoundingClientRect();
|
|
4729
4737
|
if (!n || n.width === 0 || n.height === 0) return null;
|
|
4730
4738
|
let r = Math.min(window.devicePixelRatio || 1, 2), i = Math.round(n.width * r), a = Math.round(n.height * r), o = t / Math.max(i, a);
|
|
@@ -4735,9 +4743,9 @@ function Fs(e, t = Infinity) {
|
|
|
4735
4743
|
}
|
|
4736
4744
|
//#endregion
|
|
4737
4745
|
//#region src/managers/helpers/ViewOverlayRenderer.js
|
|
4738
|
-
var
|
|
4746
|
+
var Us = 4096, Ws = class {
|
|
4739
4747
|
constructor() {
|
|
4740
|
-
this.canvas =
|
|
4748
|
+
this.canvas = Vs(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
|
|
4741
4749
|
}
|
|
4742
4750
|
async init({ device: e, sizeSource: t }) {
|
|
4743
4751
|
this._sizeSource = t;
|
|
@@ -4754,7 +4762,7 @@ var Is = 4096, Ls = class {
|
|
|
4754
4762
|
}
|
|
4755
4763
|
syncSize() {
|
|
4756
4764
|
if (!this.renderer) return;
|
|
4757
|
-
let e =
|
|
4765
|
+
let e = Hs(this._sizeSource, Us);
|
|
4758
4766
|
!e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
|
|
4759
4767
|
}
|
|
4760
4768
|
begin() {
|
|
@@ -4766,18 +4774,18 @@ var Is = 4096, Ls = class {
|
|
|
4766
4774
|
dispose() {
|
|
4767
4775
|
Me(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
|
|
4768
4776
|
}
|
|
4769
|
-
},
|
|
4777
|
+
}, Gs = We("overlay"), Ks = (e, t) => e.visible && e.layer === t && e.render, qs = class {
|
|
4770
4778
|
constructor(e) {
|
|
4771
|
-
this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas =
|
|
4779
|
+
this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = Vs(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
|
|
4772
4780
|
}
|
|
4773
4781
|
async initViewRenderer({ device: e, sizeSource: t }) {
|
|
4774
4782
|
if (!(!e || !t)) try {
|
|
4775
|
-
this._viewOverlay = await new
|
|
4783
|
+
this._viewOverlay = await new Ws().init({
|
|
4776
4784
|
device: e,
|
|
4777
4785
|
sizeSource: t
|
|
4778
4786
|
});
|
|
4779
4787
|
} catch (e) {
|
|
4780
|
-
|
|
4788
|
+
Gs.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
|
|
4781
4789
|
}
|
|
4782
4790
|
}
|
|
4783
4791
|
gpuResources() {
|
|
@@ -4797,11 +4805,11 @@ var Is = 4096, Ls = class {
|
|
|
4797
4805
|
}
|
|
4798
4806
|
setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
|
|
4799
4807
|
this.setHelperScene(e);
|
|
4800
|
-
let s = new
|
|
4808
|
+
let s = new zs();
|
|
4801
4809
|
this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(P.RESOLUTION_CHANGED, (e) => {
|
|
4802
4810
|
s.setRenderSize(e.width, e.height);
|
|
4803
4811
|
}), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
|
|
4804
|
-
let c = new
|
|
4812
|
+
let c = new Bs(t, this.camera);
|
|
4805
4813
|
this.register("outline", c);
|
|
4806
4814
|
}
|
|
4807
4815
|
_wireDenoiserTileEvents(e, t) {
|
|
@@ -4813,7 +4821,7 @@ var Is = 4096, Ls = class {
|
|
|
4813
4821
|
}));
|
|
4814
4822
|
}
|
|
4815
4823
|
register(e, t) {
|
|
4816
|
-
this._helpers.has(e) && (
|
|
4824
|
+
this._helpers.has(e) && (Gs.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
|
|
4817
4825
|
}
|
|
4818
4826
|
unregister(e) {
|
|
4819
4827
|
let t = this._helpers.get(e);
|
|
@@ -4851,16 +4859,16 @@ var Is = 4096, Ls = class {
|
|
|
4851
4859
|
}
|
|
4852
4860
|
_renderSceneLayer(e) {
|
|
4853
4861
|
this._helperScene?.render(e, this.camera);
|
|
4854
|
-
for (let t of this._helpers.values())
|
|
4862
|
+
for (let t of this._helpers.values()) Ks(t, "scene") && t.render(e, this.camera);
|
|
4855
4863
|
}
|
|
4856
4864
|
_hasVisibleSceneOverlay() {
|
|
4857
4865
|
if (this._helperScene?.isDrawing) return !0;
|
|
4858
|
-
for (let e of this._helpers.values()) if (
|
|
4866
|
+
for (let e of this._helpers.values()) if (Ks(e, "scene")) return !0;
|
|
4859
4867
|
return !1;
|
|
4860
4868
|
}
|
|
4861
4869
|
refreshHUD() {
|
|
4862
4870
|
let e = this._hudCanvas, t = this._hudCtx, n = !1;
|
|
4863
|
-
for (let e of this._helpers.values()) if (
|
|
4871
|
+
for (let e of this._helpers.values()) if (Ks(e, "hud")) {
|
|
4864
4872
|
n = !0;
|
|
4865
4873
|
break;
|
|
4866
4874
|
}
|
|
@@ -4869,10 +4877,10 @@ var Is = 4096, Ls = class {
|
|
|
4869
4877
|
return;
|
|
4870
4878
|
}
|
|
4871
4879
|
e.style.display !== "" && (e.style.display = "");
|
|
4872
|
-
let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ?
|
|
4880
|
+
let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Hs(e) : null;
|
|
4873
4881
|
if (a) {
|
|
4874
4882
|
(e.width !== a.width || e.height !== a.height) && (e.width = a.width, e.height = a.height), t.clearRect(0, 0, a.width, a.height), t.save(), t.scale(a.width / r, a.height / i);
|
|
4875
|
-
for (let e of this._helpers.values())
|
|
4883
|
+
for (let e of this._helpers.values()) Ks(e, "hud") && e.render(t, r, i);
|
|
4876
4884
|
t.restore(), e.style.display !== "" && (e.style.display = "");
|
|
4877
4885
|
}
|
|
4878
4886
|
}
|
|
@@ -4883,7 +4891,7 @@ var Is = 4096, Ls = class {
|
|
|
4883
4891
|
};
|
|
4884
4892
|
//#endregion
|
|
4885
4893
|
//#region src/managers/AnimationManager.js
|
|
4886
|
-
function
|
|
4894
|
+
function Js(e, t) {
|
|
4887
4895
|
let n = [...e].filter((t) => {
|
|
4888
4896
|
for (let n = t.parent; n; n = n.parent) if (e.has(n)) return !1;
|
|
4889
4897
|
return !0;
|
|
@@ -4892,7 +4900,7 @@ function Vs(e, t) {
|
|
|
4892
4900
|
for (let e of n) e.traverse?.(() => i++);
|
|
4893
4901
|
return i + n.length / 2 < r ? n : null;
|
|
4894
4902
|
}
|
|
4895
|
-
var
|
|
4903
|
+
var Ys = class extends ur {
|
|
4896
4904
|
constructor() {
|
|
4897
4905
|
super(), this.mixer = null, this.timer = new Fr(), this.actions = [], this.isPlaying = !1, this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._meshPositions = null, this._tempVec = new Q(), this._skinnedCache = null, this._clipsCache = null, this._savedTimeScale = 1, this.onFinished = null, this._rigid = !1, this._plans = null, this._allPlan = null, this._activeClip = 0, this._slotOf = null, this._lastWorld = null, this._lastVisible = null, this._lastMeshWorld = null, this._lastMorphWeights = null, this.wakeCallback = null, this.applyPoseCallback = null;
|
|
4898
4906
|
}
|
|
@@ -4946,7 +4954,7 @@ var Hs = class extends ur {
|
|
|
4946
4954
|
visibility: i,
|
|
4947
4955
|
cameras: [...s],
|
|
4948
4956
|
nodes: a ? null : r,
|
|
4949
|
-
roots: a ? null :
|
|
4957
|
+
roots: a ? null : Js(r, t)
|
|
4950
4958
|
};
|
|
4951
4959
|
}), this._allPlan = null, !this._rigid) return;
|
|
4952
4960
|
this._slotOf = new Int32Array(this._meshes.length).fill(-1);
|
|
@@ -4965,7 +4973,7 @@ var Hs = class extends ur {
|
|
|
4965
4973
|
visibility: n,
|
|
4966
4974
|
cameras: [...t],
|
|
4967
4975
|
nodes: r,
|
|
4968
|
-
roots: r ?
|
|
4976
|
+
roots: r ? Js(r, this._mixerRoot) : null
|
|
4969
4977
|
};
|
|
4970
4978
|
}
|
|
4971
4979
|
return this._allPlan;
|
|
@@ -5097,19 +5105,19 @@ var Hs = class extends ur {
|
|
|
5097
5105
|
dispose() {
|
|
5098
5106
|
this.mixer &&= (this.mixer.stopAllAction(), this.mixer.uncacheRoot(this._mixerRoot), null), this.actions = [], this.isPlaying = !1, this.timer.reset(), this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._meshPositions = null, this._skinnedCache = null, this._clipsCache = null, this._rigid = !1, this._plans = null, this._allPlan = null, this._activeClip = 0, this._slotOf = null, this._lastWorld = null, this._lastVisible = null, this._lastMeshWorld = null, this._lastMorphWeights = null;
|
|
5099
5107
|
}
|
|
5100
|
-
},
|
|
5108
|
+
}, Xs = new Q(0, 0, -1), Zs = (e) => {
|
|
5101
5109
|
for (; e.parent;) e = e.parent;
|
|
5102
5110
|
return e.isScene ? e : null;
|
|
5103
|
-
},
|
|
5111
|
+
}, Qs = class {
|
|
5104
5112
|
constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
|
|
5105
5113
|
this._app = r, this._orbitControls = n, this._camera = e, this._controls = new Ur(e, t), this._gizmoScene = new Nr(), this._gizmoScene.add(this._controls.getHelper()), this._attached = null, this._isDragging = !1, this._meshes = null, this._refitInFlight = !1, this._baselineComputed = !1, this._moved = /* @__PURE__ */ new Set(), this._tempForward = new Q(), this._lightTargetDistance = null, this._lastLightPosition = null, this._onDraggingChanged = this._onDraggingChanged.bind(this), this._onObjectChange = this._onObjectChange.bind(this), this._controls.addEventListener("dragging-changed", this._onDraggingChanged), this._controls.addEventListener("objectChange", this._onObjectChange);
|
|
5106
5114
|
}
|
|
5107
5115
|
setMeshData(e) {
|
|
5108
5116
|
this._meshes = e;
|
|
5109
|
-
for (let e of this._moved)
|
|
5117
|
+
for (let e of this._moved) Zs(e) || this._moved.delete(e);
|
|
5110
5118
|
}
|
|
5111
5119
|
get movedObjects() {
|
|
5112
|
-
return [...this._moved].filter((e) =>
|
|
5120
|
+
return [...this._moved].filter((e) => Zs(e));
|
|
5113
5121
|
}
|
|
5114
5122
|
noteMoved(e) {
|
|
5115
5123
|
e && !e.isLight && this._moved.add(e);
|
|
@@ -5170,7 +5178,7 @@ var Hs = class extends ur {
|
|
|
5170
5178
|
}
|
|
5171
5179
|
_syncLightAim(e) {
|
|
5172
5180
|
let t = this._tempForward.copy(e.target.position).sub(e.position), n = t.length();
|
|
5173
|
-
n > 1e-4 ? (e.quaternion.setFromUnitVectors(
|
|
5181
|
+
n > 1e-4 ? (e.quaternion.setFromUnitVectors(Xs, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
|
|
5174
5182
|
}
|
|
5175
5183
|
_recomputeAndRefit() {
|
|
5176
5184
|
if (!this._meshes || this._refitInFlight || !this._attached) return;
|
|
@@ -5206,7 +5214,7 @@ var Hs = class extends ur {
|
|
|
5206
5214
|
dispose() {
|
|
5207
5215
|
this._controls.removeEventListener("dragging-changed", this._onDraggingChanged), this._controls.removeEventListener("objectChange", this._onObjectChange), this.detach(), this._gizmoScene.remove(this._controls.getHelper()), this._controls.dispose(), this._meshes = null, this._moved.clear(), this._baselineComputed = !1, this._tempForward = null, this._lightTargetDistance = null, this._lastLightPosition = null, this._app = null, this._orbitControls = null, this._camera = null, this._controls = null, this._gizmoScene = null;
|
|
5208
5216
|
}
|
|
5209
|
-
},
|
|
5217
|
+
}, $s = class {
|
|
5210
5218
|
constructor(e) {
|
|
5211
5219
|
this.layer = "scene", this._transformManager = e, this._enabled = !0;
|
|
5212
5220
|
}
|
|
@@ -5225,8 +5233,8 @@ var Hs = class extends ur {
|
|
|
5225
5233
|
dispose() {
|
|
5226
5234
|
this._enabled = !1;
|
|
5227
5235
|
}
|
|
5228
|
-
},
|
|
5229
|
-
function
|
|
5236
|
+
}, ec = 1, tc = (e) => typeof e == "string" && /^https?:\/\//.test(e);
|
|
5237
|
+
function nc(e, t) {
|
|
5230
5238
|
let n = [];
|
|
5231
5239
|
for (; e && e !== t;) {
|
|
5232
5240
|
let t = e.parent;
|
|
@@ -5235,12 +5243,12 @@ function Ys(e, t) {
|
|
|
5235
5243
|
}
|
|
5236
5244
|
return e === t ? n : null;
|
|
5237
5245
|
}
|
|
5238
|
-
function
|
|
5246
|
+
function rc(e, t) {
|
|
5239
5247
|
let n = e;
|
|
5240
5248
|
for (let e of t) if (n = n?.children[e], !n) return null;
|
|
5241
5249
|
return n;
|
|
5242
5250
|
}
|
|
5243
|
-
function
|
|
5251
|
+
function ic(e) {
|
|
5244
5252
|
return {
|
|
5245
5253
|
key: e.assetLoader?.sceneSourceKey ?? null,
|
|
5246
5254
|
name: e.sceneModel?.name ?? null,
|
|
@@ -5248,7 +5256,7 @@ function Zs(e) {
|
|
|
5248
5256
|
materials: e.stages.pathTracer?.materialData.materialCount ?? 0
|
|
5249
5257
|
};
|
|
5250
5258
|
}
|
|
5251
|
-
function
|
|
5259
|
+
function ac(e) {
|
|
5252
5260
|
let t = /* @__PURE__ */ new Map();
|
|
5253
5261
|
for (let n of e.sceneMeshes) {
|
|
5254
5262
|
let e = n.userData?.materialIndex;
|
|
@@ -5256,7 +5264,7 @@ function Qs(e) {
|
|
|
5256
5264
|
}
|
|
5257
5265
|
return t;
|
|
5258
5266
|
}
|
|
5259
|
-
function
|
|
5267
|
+
function oc(e) {
|
|
5260
5268
|
if (!e) return null;
|
|
5261
5269
|
let t = e.status(), n = t.activeView, r = t.config?.id ?? n?.configId ?? null;
|
|
5262
5270
|
return {
|
|
@@ -5271,15 +5279,15 @@ function $s(e) {
|
|
|
5271
5279
|
context: t.context ?? null
|
|
5272
5280
|
};
|
|
5273
5281
|
}
|
|
5274
|
-
function
|
|
5275
|
-
let t = e.meshScene, n =
|
|
5282
|
+
function sc(e) {
|
|
5283
|
+
let t = e.meshScene, n = ac(e), r = [];
|
|
5276
5284
|
return t.traverse((e) => {
|
|
5277
|
-
e !== t && e.visible === !1 && r.push(
|
|
5285
|
+
e !== t && e.visible === !1 && r.push(nc(e, t));
|
|
5278
5286
|
}), {
|
|
5279
5287
|
v: 1,
|
|
5280
5288
|
engine: Re,
|
|
5281
5289
|
savedAt: Date.now(),
|
|
5282
|
-
scene:
|
|
5290
|
+
scene: ic(e),
|
|
5283
5291
|
appended: t.children.filter((t) => t !== e.sceneModel && t.userData?.__rayzeeSceneObject).map((e) => ({
|
|
5284
5292
|
name: e.userData.__rayzeeName ?? e.name,
|
|
5285
5293
|
url: e.userData.__rayzeeSourceUrl ?? null,
|
|
@@ -5287,7 +5295,7 @@ function ec(e) {
|
|
|
5287
5295
|
})),
|
|
5288
5296
|
settings: e.settings.serialize(),
|
|
5289
5297
|
environment: e.environmentManager?.serialize() ?? null,
|
|
5290
|
-
color:
|
|
5298
|
+
color: oc(e.color),
|
|
5291
5299
|
lights: e.lightManager.serialize(),
|
|
5292
5300
|
cameras: e.cameraManager.serialize(),
|
|
5293
5301
|
timeline: e.timeline?.serialize() ?? null,
|
|
@@ -5297,7 +5305,7 @@ function ec(e) {
|
|
|
5297
5305
|
})),
|
|
5298
5306
|
hidden: r,
|
|
5299
5307
|
moved: (e.transformManager?.movedObjects ?? []).map((e) => ({
|
|
5300
|
-
path:
|
|
5308
|
+
path: nc(e, t),
|
|
5301
5309
|
name: e.name,
|
|
5302
5310
|
position: e.position.toArray(),
|
|
5303
5311
|
quaternion: e.quaternion.toArray(),
|
|
@@ -5305,15 +5313,15 @@ function ec(e) {
|
|
|
5305
5313
|
})).filter((e) => e.path)
|
|
5306
5314
|
};
|
|
5307
5315
|
}
|
|
5308
|
-
function
|
|
5316
|
+
function cc(e, t, n) {
|
|
5309
5317
|
let r = e[t];
|
|
5310
5318
|
r?.copy && (n?.isColor || n?.isVector2 || n?.isVector3) ? r.copy(n) : e[t] = n, e.needsUpdate = !0;
|
|
5311
5319
|
}
|
|
5312
|
-
async function
|
|
5320
|
+
async function lc(e, t, n, r) {
|
|
5313
5321
|
if (!t) return;
|
|
5314
5322
|
let i = e.environmentManager;
|
|
5315
5323
|
if (t.hdri && t.hdri !== i.hdriSource) {
|
|
5316
|
-
let i =
|
|
5324
|
+
let i = tc(t.hdri) ? t.hdri : await n({
|
|
5317
5325
|
kind: "environment",
|
|
5318
5326
|
source: t.hdri
|
|
5319
5327
|
});
|
|
@@ -5325,7 +5333,7 @@ async function nc(e, t, n, r) {
|
|
|
5325
5333
|
}
|
|
5326
5334
|
await i.restore(t);
|
|
5327
5335
|
}
|
|
5328
|
-
async function
|
|
5336
|
+
async function uc(e, t, n, r) {
|
|
5329
5337
|
let i = e.color;
|
|
5330
5338
|
if (!t || !i) return;
|
|
5331
5339
|
let a = i.status(), o = a.activeView, s = !!t.view && !!o && o.display === t.view.display && o.view === t.view.view && (o.look ?? null) === t.view.look, c = a.config?.id ?? null, l = c ?? o?.configId ?? null;
|
|
@@ -5350,7 +5358,7 @@ async function rc(e, t, n, r) {
|
|
|
5350
5358
|
r("color", e.message, { config: t.config?.id ?? null });
|
|
5351
5359
|
}
|
|
5352
5360
|
}
|
|
5353
|
-
async function
|
|
5361
|
+
async function dc(e, t, { resolve: n = async () => null } = {}) {
|
|
5354
5362
|
if (t?.v !== 1) throw Error(`scene state version ${t?.v} is not 1`);
|
|
5355
5363
|
let r = [], i = (e, t, n = {}) => r.push({
|
|
5356
5364
|
section: e,
|
|
@@ -5371,11 +5379,11 @@ async function ic(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5371
5379
|
i("appended", e.message, { name: n.name });
|
|
5372
5380
|
}
|
|
5373
5381
|
}
|
|
5374
|
-
let a =
|
|
5382
|
+
let a = ic(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
|
|
5375
5383
|
s || i("scene", "the loaded scene is not the one saved: objects and materials left as loaded", {
|
|
5376
5384
|
saved: o,
|
|
5377
5385
|
now: a
|
|
5378
|
-
}), await
|
|
5386
|
+
}), await lc(e, t.environment, n, i), await uc(e, t.color, n, i);
|
|
5379
5387
|
let c = e.settings.restore(t.settings);
|
|
5380
5388
|
c.length && i("settings", "not settings in this engine", { keys: c });
|
|
5381
5389
|
let l = e.lightManager.restore(t.lights);
|
|
@@ -5384,7 +5392,7 @@ async function ic(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5384
5392
|
n && e.goboManager?.entries?.length && e.goboManager.setLightGobo(t.uuid, n.name, n), r && e.iesManager?.entries?.length && e.iesManager.setSpotLightProfile(t.uuid, r.name, r.intensity, { applyAutoCone: !1 });
|
|
5385
5393
|
}
|
|
5386
5394
|
if (s) {
|
|
5387
|
-
let n =
|
|
5395
|
+
let n = ac(e);
|
|
5388
5396
|
for (let r of t.materials ?? []) {
|
|
5389
5397
|
let t = n.get(r.index);
|
|
5390
5398
|
if (!t || (t.name ?? "") !== r.name) {
|
|
@@ -5395,17 +5403,17 @@ async function ic(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5395
5403
|
continue;
|
|
5396
5404
|
}
|
|
5397
5405
|
for (let [n, i] of Object.entries(r.props)) {
|
|
5398
|
-
let a =
|
|
5399
|
-
|
|
5406
|
+
let a = ce(i);
|
|
5407
|
+
cc(t, n, a), e.setMaterialProperty(r.index, n, a);
|
|
5400
5408
|
}
|
|
5401
5409
|
}
|
|
5402
|
-
let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) =>
|
|
5410
|
+
let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => rc(r, e)).filter(Boolean));
|
|
5403
5411
|
r.traverse((e) => {
|
|
5404
5412
|
e !== r && !e.isLight && (e.visible = !a.has(e));
|
|
5405
5413
|
}), e.updateAllMeshVisibility();
|
|
5406
5414
|
let o = [];
|
|
5407
5415
|
for (let n of t.moved ?? []) {
|
|
5408
|
-
let t =
|
|
5416
|
+
let t = rc(r, n.path);
|
|
5409
5417
|
if (!t || t.name !== n.name) {
|
|
5410
5418
|
i("moved", "no such object", { name: n.name });
|
|
5411
5419
|
continue;
|
|
@@ -5427,7 +5435,7 @@ async function ic(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5427
5435
|
}
|
|
5428
5436
|
//#endregion
|
|
5429
5437
|
//#region src/PathTracerApp.js
|
|
5430
|
-
var
|
|
5438
|
+
var fc = We("engine"), pc = class extends w {
|
|
5431
5439
|
constructor(e, t = {}) {
|
|
5432
5440
|
super(e, t), this.setColorManagement(Zt), this.setStorageOpener(cn), this.settings.define("interactionRenderScale", {
|
|
5433
5441
|
default: .5,
|
|
@@ -5435,16 +5443,16 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5435
5443
|
this.stages?.pathTracer?.interactionMode && this._requestRenderScale(this._interactionRenderScale());
|
|
5436
5444
|
},
|
|
5437
5445
|
reset: !1
|
|
5438
|
-
}), this._container = t.container || null, this._animRefitInFlight = !1, this._emittersMoved = !1, this._pendingRenderScale = null, this.cameraManager = null, this.timeline = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new
|
|
5446
|
+
}), this._container = t.container || null, this._animRefitInFlight = !1, this._emittersMoved = !1, this._pendingRenderScale = null, this.cameraManager = null, this.timeline = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new Ys();
|
|
5439
5447
|
}
|
|
5440
5448
|
_createCamera() {
|
|
5441
|
-
return this.cameraManager = new
|
|
5449
|
+
return this.cameraManager = new _o(this.canvas), this.timeline = new Co({
|
|
5442
5450
|
cameraManager: this.cameraManager,
|
|
5443
5451
|
onReset: () => this.reset()
|
|
5444
5452
|
}), this.cameraManager.camera;
|
|
5445
5453
|
}
|
|
5446
5454
|
_initAssetPipeline() {
|
|
5447
|
-
super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Et), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-
|
|
5455
|
+
super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Et), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-BJxszU_k.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Ct);
|
|
5448
5456
|
let e = () => {
|
|
5449
5457
|
this.needsReset = !0, this.stages.pathTracer?.enterInteractionMode(), this.wake();
|
|
5450
5458
|
};
|
|
@@ -5452,10 +5460,10 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5452
5460
|
}
|
|
5453
5461
|
_createExtraStages() {
|
|
5454
5462
|
let { renderer: e, stages: t } = this;
|
|
5455
|
-
return t.normalDepth = new
|
|
5463
|
+
return t.normalDepth = new $r(e, { pathTracer: t.pathTracer }), t.motionVector = new ei(e, this.camera, { pathTracer: t.pathTracer }), t.nrd = new Ki(e, {
|
|
5456
5464
|
enabled: !1,
|
|
5457
5465
|
pathTracer: t.pathTracer
|
|
5458
|
-
}), t.autoExposure = new
|
|
5466
|
+
}), t.autoExposure = new ba(e, { enabled: qi.autoExposure }), t.localExposure = new Ha(e, { enabled: xa.localExposure }), [
|
|
5459
5467
|
t.normalDepth,
|
|
5460
5468
|
t.motionVector,
|
|
5461
5469
|
t.nrd,
|
|
@@ -5467,7 +5475,7 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5467
5475
|
super._initPipeline(), this.pipeline.eventBus.on("pathtracer:interactionStart", () => this._requestRenderScale(this._interactionRenderScale())), this.pipeline.eventBus.on("pathtracer:interactionEnd", () => this._applyRenderScale(1));
|
|
5468
5476
|
}
|
|
5469
5477
|
async _initManagers() {
|
|
5470
|
-
await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-
|
|
5478
|
+
await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-cKy75-oR.js").then((e) => e.n).then((e) => e.PhysicalSky)), this.stages.pathTracer.registerIntegrator(["bidirectional", "vcm"], (t) => new e(t)), this.stages.pathTracer.requestOutput("gBuffer"), this.interactionManager = new qa({
|
|
5471
5479
|
scene: this.meshScene,
|
|
5472
5480
|
camera: this.camera,
|
|
5473
5481
|
canvas: this.canvas,
|
|
@@ -5475,18 +5483,18 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5475
5483
|
pathTracer: null,
|
|
5476
5484
|
floorPlane: this.assetLoader.floorPlane,
|
|
5477
5485
|
isGeometryOnDisk: () => this.geometryOnDisk
|
|
5478
|
-
}), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new
|
|
5486
|
+
}), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new wo(this.stages.pathTracer, {
|
|
5479
5487
|
onReset: () => this.reset(),
|
|
5480
5488
|
issues: this._issues
|
|
5481
|
-
}), this.iesManager = new
|
|
5489
|
+
}), this.iesManager = new Io(this.stages.pathTracer, {
|
|
5482
5490
|
onReset: () => this.reset(),
|
|
5483
5491
|
issues: this._issues
|
|
5484
|
-
}), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new
|
|
5492
|
+
}), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new Qs({
|
|
5485
5493
|
camera: this.camera,
|
|
5486
5494
|
canvas: this.canvas,
|
|
5487
5495
|
orbitControls: this.cameraManager.controls,
|
|
5488
5496
|
app: this
|
|
5489
|
-
}), this.overlayManager.register("transform", new
|
|
5497
|
+
}), this.overlayManager.register("transform", new $s(this.transformManager))), this.interactionManager.setDependencies({
|
|
5490
5498
|
overlayManager: this.overlayManager,
|
|
5491
5499
|
transformManager: this.transformManager,
|
|
5492
5500
|
appDispatch: (e) => this.dispatchEvent(e),
|
|
@@ -5548,7 +5556,7 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5548
5556
|
_beginFrame() {
|
|
5549
5557
|
if (this.timeline.update(), this.cameraManager.updateControls(), this._updateExposure(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
|
|
5550
5558
|
let e = this.animationManager.update();
|
|
5551
|
-
e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) =>
|
|
5559
|
+
e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => fc.error("animation refit error:", e)).finally(() => {
|
|
5552
5560
|
this._animRefitInFlight = !1;
|
|
5553
5561
|
}));
|
|
5554
5562
|
}
|
|
@@ -5579,7 +5587,7 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5579
5587
|
let { toneMappingExposure: n, toneMapping: r } = this.renderer;
|
|
5580
5588
|
return {
|
|
5581
5589
|
...t,
|
|
5582
|
-
backdrop:
|
|
5590
|
+
backdrop: le(this.settings.get("exposure") ?? 1, n, r)
|
|
5583
5591
|
};
|
|
5584
5592
|
}
|
|
5585
5593
|
setLocalExposure(e) {
|
|
@@ -5687,10 +5695,10 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5687
5695
|
return t && this._dispatchCamerasUpdated(), t;
|
|
5688
5696
|
}
|
|
5689
5697
|
exportSceneState() {
|
|
5690
|
-
return
|
|
5698
|
+
return sc(this);
|
|
5691
5699
|
}
|
|
5692
5700
|
async importSceneState(e, t) {
|
|
5693
|
-
return await
|
|
5701
|
+
return await dc(this, e, t);
|
|
5694
5702
|
}
|
|
5695
5703
|
_dispatchCamerasUpdated() {
|
|
5696
5704
|
this.dispatchEvent({
|
|
@@ -5812,7 +5820,7 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5812
5820
|
this.transformManager?.setMeshData(this._sdf.meshes);
|
|
5813
5821
|
}
|
|
5814
5822
|
_setupDenoisingManager() {
|
|
5815
|
-
this.denoisingManager = new
|
|
5823
|
+
this.denoisingManager = new Rs({
|
|
5816
5824
|
renderer: this.renderer,
|
|
5817
5825
|
mainCanvas: this.canvas,
|
|
5818
5826
|
stages: {
|
|
@@ -5864,7 +5872,7 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5864
5872
|
}, n && this.stages.autoExposure?.noteViewChanged());
|
|
5865
5873
|
}
|
|
5866
5874
|
async _setupOverlayManager() {
|
|
5867
|
-
this.overlayManager = new
|
|
5875
|
+
this.overlayManager = new qs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
|
|
5868
5876
|
helperScene: this._sceneHelpers,
|
|
5869
5877
|
meshScene: this.meshScene,
|
|
5870
5878
|
pipeline: this.pipeline,
|
|
@@ -5895,15 +5903,15 @@ var ac = We("engine"), oc = class extends w {
|
|
|
5895
5903
|
};
|
|
5896
5904
|
//#endregion
|
|
5897
5905
|
//#region src/Headless.js
|
|
5898
|
-
async function
|
|
5899
|
-
let t = await
|
|
5906
|
+
async function mc(e) {
|
|
5907
|
+
let t = await gc(e);
|
|
5900
5908
|
try {
|
|
5901
|
-
return await
|
|
5909
|
+
return await hc(t, e);
|
|
5902
5910
|
} finally {
|
|
5903
5911
|
t.dispose();
|
|
5904
5912
|
}
|
|
5905
5913
|
}
|
|
5906
|
-
async function
|
|
5914
|
+
async function hc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
|
|
5907
5915
|
let o = e.denoisingManager;
|
|
5908
5916
|
i && o && !o.finalDenoise && (o.applyOIDNEnabled(!0), o._syncGBufferStages());
|
|
5909
5917
|
let s = await e.renderFrames(t, {
|
|
@@ -5922,8 +5930,8 @@ async function cc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire
|
|
|
5922
5930
|
provenance: e.getProvenance()
|
|
5923
5931
|
};
|
|
5924
5932
|
}
|
|
5925
|
-
async function
|
|
5926
|
-
let l = new
|
|
5933
|
+
async function gc({ canvas: e, model: t = null, width: n = 1920, height: r = 1080, strict: i = !0, deterministic: a = !0, settings: o = null, storage: s = !1, hostMemoryGB: c = void 0 } = {}) {
|
|
5934
|
+
let l = new pc(e ?? null, {
|
|
5927
5935
|
autoResize: !1,
|
|
5928
5936
|
strict: i,
|
|
5929
5937
|
storage: s,
|
|
@@ -5937,7 +5945,7 @@ async function lc({ canvas: e, model: t = null, width: n = 1920, height: r = 108
|
|
|
5937
5945
|
}
|
|
5938
5946
|
//#endregion
|
|
5939
5947
|
//#region src/managers/VideoRenderManager.js
|
|
5940
|
-
var
|
|
5948
|
+
var _c = class {
|
|
5941
5949
|
constructor(e) {
|
|
5942
5950
|
this._app = e, this._cancelled = !1, this._rendering = !1;
|
|
5943
5951
|
}
|
|
@@ -6051,4 +6059,4 @@ var uc = class {
|
|
|
6051
6059
|
}
|
|
6052
6060
|
};
|
|
6053
6061
|
//#endregion
|
|
6054
|
-
export { Ct as ARCHIVE_FORMATS,
|
|
6062
|
+
export { Ct as ARCHIVE_FORMATS, qi as AUTO_EXPOSURE_DEFAULTS, uo as AUTO_FOCUS_DEFAULTS, Ys as AnimationManager, qe as BVH_LEAF_MARKERS, _o as CameraManager, xo as CameraTrack, Zt as ColorManagement, zt as DEFAULT_LUT_SIZE, Jt as DEFAULT_MAX_EV, Gt as DEFAULT_MIN_EV, ge as DEFAULT_SUN_PATH, ht as DEFAULT_VIEW, rt as DEFAULT_WORKING_SPACE, Qr as DENOISER_DEFAULTS, Kr as DENOISER_STRATEGIES, C as DOWNLOAD_POLICY, Rs as DenoisingManager, d as DownloadCache, $e as ENGINE_AREAS, we as ENGINE_DEFAULTS, P as EngineEvents, Ze as EngineIssueError, wo as GoboManager, Io as IESManager, Ee as INTERACTIVE_RENDER_CONFIG, Ye as ISSUE_CODES, Xe as ISSUE_SEVERITY, qa as InteractionManager, Je as IssueLog, Se as LEGACY_EVENT_NAMES, xa as LOCAL_EXPOSURE_DEFAULTS, Ge as LOG_LEVELS, S as LightManager, Ue as Logger, Le as MATERIAL_DEFAULTS, Ce as MATERIAL_VALUE_SOURCE, re as MAX_RESERVABLE_RENDER_SIZE, Ne as MAX_SCENE_BYTES, pt as MAX_TABLE_TRANSFORMS, Ae as MemoryLedger, Yr as NRD_DEFAULTS, qr as NRD_HIT_DIST_A, Jr as NRD_HIT_DIST_B, Xr as NRD_PRESET_KEYS, Zr as NRD_QUALITY_PRESETS, lt as OCIO_VIEW_BASE, qs as OverlayManager, Te as PRODUCTION_RENDER_CONFIG, pc as PathTracerApp, l as PipelineContext, hn as RETOUCH_DEFAULTS, gn as RETOUCH_MAX_PIXELS, mn as RETOUCH_RANGES, w as RayzeeRenderer, x as RenderPipeline, u as RenderSettings, A as RenderStage, je as SAFE_SCENE_BYTES, ec as SCENE_STATE_VERSION, b as SETTING_SOURCE, me as SKY_DEFAULTS, fn as SR_MAX_INPUT, pn as SR_SCALE, Qe as STORAGE_KIND, j as StageExecutionMode, sn as StorageManager, Ke as TRIANGLE_DATA_LAYOUT, Co as TimelineManager, Qs as TransformManager, Re as VERSION, ot as VIEW_TRANSFORMS, _e as VRAMTracker, _c as VideoRenderManager, rn as acquireLock, Vt as addAllOcioViews, Bt as addOcioView, dt as addViewTransform, tn as applyMatrixRGBA8, $t as bakeLut, fe as bufferBytes, Pt as buildOcioView, mt as buildToneMapWGSL, _ as cachedObjectURL, Kt as canvasColorSpaceFor, hc as captureHeadless, v as clearBindingAuditFindings, Ft as clearInputOverrides, at as configureAssets, Ve as configurePlatform, Mt as convertColor, Ot as convertEncodedRGBA8, en as convertPixelsF32, We as createLogger, de as dayOfYearForMonth, De as deriveAlphaMode, y as describeAdapter, Dt as displayCanvasFit, Ie as estimateSceneBytes, Nt as extractMatrix, wt as extractSceneMetadata, T as fetchFile, yt as fileIdentity, Yt as findNativeLinearSpace, He as fmt, bt as folderIdentity, ce as fromPortable, nt as getActiveColorManagement, it as getAssetConfig, h as getBindingAuditFindings, Be as getPlatform, ut as getRegistryVersion, gt as getViewTransform, At as hasColorSpace, an as heldLockNames, vt as identityKey, Ht as isColorManaged, kt as isDataSpace, qt as isDataTexture, jt as linearToSrgb, Xt as listFileRules, Lt as listInputOverrides, st as listViewTransforms, xt as localFolder, nn as makeCpuSampler, It as measureBakeError, f as nameFromUrl, ft as onRegistryChange, gc as openHeadless, on as openStorage, un as openZip, St as parseSceneMetadata, Pe as probeAddressSpace, ln as readZipDirectory, ct as removeViewTransform, mc as renderHeadless, dn as renderUpscaled, Wt as resolveInputSpace, _t as sameIdentity, tt as setActiveColorManagement, m as setBindingAudit, Qt as setInputOverride, Ut as srgbToLinear, ue as sunPosition, se as textureBytes, Rt as textureInputSpace, oe as timeForSunElevation, ye as toPortable };
|