rayzee 11.2.1 → 11.4.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 +91 -34
- package/dist/ArchiveImporter-Cgyx5AF7.js +7860 -0
- package/dist/BidirectionalIntegrator-BKF-cwH2.js +954 -0
- package/dist/{BufferLayout-D_IBo2ci.js → BufferLayout-xPRH9jYD.js} +41 -5
- package/dist/{NeuralRetouch-Cr-otSW8.js → NeuralRetouch-C3Q2XqbF.js} +4 -3
- package/dist/{NeuralSuperRes-B7E3_M0t.js → NeuralSuperRes-DV5TtURP.js} +11 -5
- package/dist/{PathTracer-D6nbknj5.js → PathTracer-D3MvEaZK.js} +4384 -4618
- package/dist/{PhysicalSky-Dq5VSiCQ.js → PhysicalSky-CY4jiz6a.js} +2 -2
- package/dist/{RayzeeRenderer-DbjqO6v-.js → RayzeeRenderer-D23m6NqG.js} +486 -391
- package/dist/SolarLimb-bZE6y63S.js +762 -0
- package/dist/{ToneMapGPU-BOjpul7A.js → ToneMapGPU-CTDBvmmS.js} +31 -22
- package/dist/addons/archives.es.js +1 -1
- package/dist/addons/bidirectional.es.js +1 -1
- package/dist/addons/physical-sky.es.js +1 -1
- package/dist/rayzee-core.es.js +7 -7
- package/dist/rayzee.es.js +1327 -838
- package/dist/rayzee.umd.js +146 -134
- package/dist/sceneCachePolicy-AKOEu2lf.js +1602 -0
- package/package.json +1 -1
- package/src/EngineDefaults.js +2 -2
- package/src/Passes/AIUpscaler.js +2 -0
- package/src/PathTracerApp.js +126 -19
- package/src/Pipeline/CompletionTracker.js +7 -3
- package/src/Processor/ArchiveImporter.js +173 -94
- package/src/Processor/ArchiveReader.js +20 -23
- package/src/Processor/AssetLoader.js +48 -1
- package/src/Processor/BVHRefitter.js +109 -13
- package/src/Processor/BufferLayout.js +115 -0
- package/src/Processor/ChunkedRecords.js +3 -2
- package/src/Processor/EmissiveTriangleBuilder.js +6 -6
- package/src/Processor/GeometryExtractor.js +189 -79
- package/src/Processor/HostMemory.js +39 -9
- package/src/Processor/InstanceTable.js +714 -42
- package/src/Processor/PBRT/PBRTCurves.js +224 -6
- package/src/Processor/PBRT/PBRTMaterials.js +3 -0
- package/src/Processor/PBRT/PBRTSceneBuilder.js +82 -25
- package/src/Processor/PackedRayBuffer.js +5 -2
- package/src/Processor/SceneProcessor.js +747 -141
- package/src/Processor/TLASBuilder.js +32 -17
- package/src/Processor/ToneMapCPU.js +16 -4
- package/src/Processor/ToneMapGPU.js +30 -14
- package/src/Processor/USD/USDLayer.js +1149 -0
- package/src/Processor/USD/USDScene.js +1655 -0
- package/src/Processor/USD/USDStage.js +682 -0
- package/src/Processor/USD/USDText.js +674 -0
- package/src/Processor/USD/index.js +138 -0
- package/src/Processor/Workers/BVHRefitWorker.js +3 -3
- package/src/RayzeeRenderer.js +221 -33
- package/src/RenderSettings.js +4 -2
- package/src/Stages/AutoExposure.js +484 -494
- package/src/Stages/Compositor.js +27 -6
- package/src/Stages/LocalExposure.js +546 -0
- package/src/Stages/NormalDepth.js +7 -12
- package/src/Stages/PathTracer.js +18 -21
- package/src/Stages/PathTracerStage.js +282 -103
- package/src/Storage/GeometrySpill.js +46 -14
- package/src/Storage/SceneGraphCodec.js +17 -3
- package/src/Storage/SpillStore.js +9 -0
- package/src/TSL/BVHTraversal.js +183 -7
- package/src/TSL/Common.js +57 -13
- package/src/TSL/ShadeKernel.js +3 -2
- package/src/TSL/TextureSampling.js +11 -8
- package/src/TSL/patches.js +84 -0
- package/src/index.js +1 -0
- package/src/integrators/BidirectionalIntegrator.js +20 -2
- package/src/managers/DenoisingManager.js +15 -19
- package/src/managers/InteractionManager.js +19 -6
- package/src/managers/MaterialDataManager.js +22 -5
- package/src/managers/UniformManager.js +3 -0
- package/src/managers/VideoRenderManager.js +30 -4
- package/src/neural/NeuralRetouch.js +1 -0
- package/src/neural/NeuralSuperRes.js +6 -1
- package/dist/ArchiveImporter-D_x863yu.js +0 -5198
- package/dist/BidirectionalIntegrator-DmkxxEOR.js +0 -946
- package/dist/SolarLimb-CPaeZVwz.js +0 -721
- package/dist/sceneCachePolicy-C4-4qwt6.js +0 -485
package/dist/rayzee.es.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import { t as e } from "./BidirectionalIntegrator-
|
|
2
|
-
import { $t as t, Ft as n,
|
|
3
|
-
import { _ as u, a as d, c as f, d as p, f as m, g as h, h as g, i as _, l as v, m as y, n as b, o as x, p as S, r as ee, s as C, t as
|
|
4
|
-
import { $ as
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import { i as
|
|
8
|
-
import {
|
|
9
|
-
import { i as
|
|
10
|
-
import { i as
|
|
1
|
+
import { t as e } from "./BidirectionalIntegrator-BKF-cwH2.js";
|
|
2
|
+
import { $t as t, Ft as n, Pt as r, Yt as i, en as a, jt as o, nn as s, rt as c, wt as l } from "./SolarLimb-bZE6y63S.js";
|
|
3
|
+
import { _ as u, a as d, c as f, d as p, f as m, g as h, h as g, i as _, l as v, m as y, n as b, o as x, p as S, r as ee, s as C, t as w, u as T } from "./RayzeeRenderer-D23m6NqG.js";
|
|
4
|
+
import { $ as E, B as te, Et as D, H as ne, K as re, L as ie, N as ae, Ot as O, P as k, Q as oe, R as se, Tt as A, X as ce, Z as le, _t as ue, dt as de, et as fe, ft as pe, gt as me, ht as he, kt as ge, lt as _e, nt as ve, pt as ye, tt as be, ut as xe, wt as Se, z as Ce } from "./PathTracer-D3MvEaZK.js";
|
|
5
|
+
import { n as we, t as j } from "./EngineEvents-Ci8dVWCP.js";
|
|
6
|
+
import { D as Te, G as Ee, J as De, K as Oe, O as ke, W as Ae, Y as je, a as Me, c as Ne, et as Pe, i as Fe, m as Ie, ot as Le, p as Re, q as ze, r as Be, tt as Ve, x as He, y as Ue } from "./sceneCachePolicy-AKOEu2lf.js";
|
|
7
|
+
import { i as We, n as Ge, r as Ke, t as qe } from "./Logger-dDDGj9Av.js";
|
|
8
|
+
import { f as Je, r as Ye } from "./BufferLayout-xPRH9jYD.js";
|
|
9
|
+
import { i as Xe, n as Ze, r as Qe, t as $e } from "./EngineIssues-CIZnXHsF.js";
|
|
10
|
+
import { i as et, r as tt } from "./shared-BGBcSxBQ.js";
|
|
11
|
+
import { r as nt } from "./WorkingMatrix-C6y233hT.js";
|
|
11
12
|
import { i as rt, r as it, t as at } from "./ActiveColor-YvuQq44O.js";
|
|
12
13
|
import { n as ot, t as st } from "./AssetConfig-DSEntE65.js";
|
|
13
14
|
import { a as ct, d as lt, g as ut, i as dt, l as ft, o as pt, p as mt, r as ht, s as gt, t as _t, u as vt } from "./ViewTransforms-CYN7bq2w.js";
|
|
14
15
|
import { a as yt, i as bt, n as xt, r as St } from "./identity-C1cLD1C0.js";
|
|
15
16
|
import { a as Ct, n as wt, r as Tt, t as Et } from "./SceneMetadata-D2Sh-0e-.js";
|
|
16
|
-
import { t as Dt } from "./ToneMapGPU-
|
|
17
|
+
import { t as Dt } from "./ToneMapGPU-CTDBvmmS.js";
|
|
17
18
|
import { t as Ot } from "./FileFormats-sPGJeCRc.js";
|
|
18
19
|
import { A as kt, C as At, D as jt, E as Mt, O as Nt, S as Pt, T as Ft, _ as It, a as Lt, b as Rt, c as zt, d as Bt, f as Vt, g as Ht, h as Ut, i as Wt, k as Gt, l as Kt, m as qt, n as Jt, o as Yt, p as Xt, r as Zt, s as Qt, t as $t, u as en, v as tn, w as nn, x as rn, y as an } from "./ColorManagement-oeEk7oSu.js";
|
|
19
20
|
import { c as on, l as sn, n as cn, o as ln, t as un } from "./openStorage-Fe9BoS1_.js";
|
|
20
21
|
import { n as dn, t as fn } from "./ZipReader-gDSWr0I5.js";
|
|
21
|
-
import { i as pn, n as mn, r as hn } from "./NeuralSuperRes-
|
|
22
|
-
import { i as gn, n as _n, r as vn } from "./NeuralRetouch-
|
|
23
|
-
import { ExternalTexture as yn, MeshBasicNodeMaterial as bn, QuadMesh as xn, ReadbackBuffer as Sn, RenderTarget as Cn, StorageTexture as
|
|
24
|
-
import { Fn as
|
|
25
|
-
import { ACESFilmicToneMapping as
|
|
26
|
-
import { OrbitControls as
|
|
27
|
-
import { outline as
|
|
28
|
-
import { TransformControls as
|
|
22
|
+
import { i as pn, n as mn, r as hn } from "./NeuralSuperRes-DV5TtURP.js";
|
|
23
|
+
import { i as gn, n as _n, r as vn } from "./NeuralRetouch-C3Q2XqbF.js";
|
|
24
|
+
import { ExternalTexture as yn, MeshBasicNodeMaterial as bn, QuadMesh as xn, ReadbackBuffer as Sn, RenderTarget as Cn, StorageTexture as wn, TextureNode as M, WebGPURenderer as Tn } from "three/webgpu";
|
|
25
|
+
import { Fn as En, If as N, Loop as Dn, Return as On, abs as kn, atan as An, atomicAdd as jn, atomicLoad as Mn, atomicStore as Nn, attributeArray as Pn, dot as Fn, exp as In, exp2 as Ln, float as P, floatBitsToUint as Rn, floor as zn, fract as Bn, int as F, ivec2 as I, localId as L, log2 as Vn, max as R, min as Hn, mix as z, normalize as Un, pow as Wn, round as Gn, saturate as B, select as V, smoothstep as Kn, sqrt as qn, storage as Jn, textureLoad as H, textureStore as U, toneMappingExposure as Yn, uint as W, uniform as G, uvec2 as Xn, uvec4 as Zn, vec2 as K, vec3 as q, vec4 as J, wgslFn as Qn, workgroupArray as $n, workgroupBarrier as er, workgroupId as Y } from "three/tsl";
|
|
26
|
+
import { ACESFilmicToneMapping as tr, AddEquation as nr, AnimationMixer as rr, Box2 as ir, Box3 as ar, ClampToEdgeWrapping as or, Color as sr, Controls as cr, CustomBlending as lr, DataArrayTexture as ur, DataTexture as dr, EventDispatcher as fr, FloatType as pr, HalfFloatType as mr, InterpolateSmooth as hr, LinearFilter as X, LoopOnce as gr, LoopRepeat as _r, MathUtils as vr, Matrix3 as yr, Matrix4 as br, Mesh as xr, MeshBasicMaterial as Sr, NearestFilter as Z, NoColorSpace as Cr, NumberKeyframeTrack as wr, OneFactor as Tr, OrthographicCamera as Er, PerspectiveCamera as Dr, PropertyBinding as Or, Quaternion as kr, RGBAFormat as Q, Raycaster as Ar, RedIntegerFormat as jr, SRGBColorSpace as Mr, Scene as Nr, SphereGeometry as Pr, Timer as Fr, UnsignedByteType as Ir, UnsignedIntType as Lr, Vector2 as Rr, Vector3 as $, Vector4 as zr, VectorKeyframeTrack as Br } from "three";
|
|
27
|
+
import { OrbitControls as Vr } from "three/addons/controls/OrbitControls.js";
|
|
28
|
+
import { outline as Hr } from "three/addons/tsl/display/OutlineNode.js";
|
|
29
|
+
import { TransformControls as Ur } from "three/addons/controls/TransformControls.js";
|
|
29
30
|
//#region src/Stages/DenoiserSettings.js
|
|
30
|
-
var
|
|
31
|
+
var Wr = 65504, Gr = 6e4, Kr = .01, qr = {
|
|
31
32
|
low: {
|
|
32
33
|
temporalAlpha: .1,
|
|
33
34
|
gradientStrength: .8,
|
|
@@ -67,7 +68,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
67
68
|
maxAccumFrames: 128,
|
|
68
69
|
varianceBoost: 1.5
|
|
69
70
|
}
|
|
70
|
-
},
|
|
71
|
+
}, Jr = 3, Yr = .1, Xr = {
|
|
71
72
|
maxAccumulatedFrameNum: 30,
|
|
72
73
|
maxFastAccumulatedFrameNum: 6,
|
|
73
74
|
maxStabilizedFrameNum: 63,
|
|
@@ -91,7 +92,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
91
92
|
convergenceP: .8,
|
|
92
93
|
lobeVolumePercent: .1,
|
|
93
94
|
handoverFrames: 0
|
|
94
|
-
},
|
|
95
|
+
}, Zr = [
|
|
95
96
|
"maxAccumulatedFrameNum",
|
|
96
97
|
"maxFastAccumulatedFrameNum",
|
|
97
98
|
"maxStabilizedFrameNum",
|
|
@@ -99,7 +100,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
99
100
|
"prepassBlurRadius",
|
|
100
101
|
"maxBlurRadius",
|
|
101
102
|
"enableAntiFirefly"
|
|
102
|
-
],
|
|
103
|
+
], Qr = {
|
|
103
104
|
low: {
|
|
104
105
|
maxAccumulatedFrameNum: 16,
|
|
105
106
|
maxFastAccumulatedFrameNum: 4,
|
|
@@ -117,7 +118,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
117
118
|
prepassBlurRadius: 40,
|
|
118
119
|
maxBlurRadius: 40
|
|
119
120
|
}
|
|
120
|
-
},
|
|
121
|
+
}, $r = qr.medium, ei = {
|
|
121
122
|
denoiserStrategy: "none",
|
|
122
123
|
filterStrength: 1,
|
|
123
124
|
edgeAtrousIterations: 5,
|
|
@@ -135,38 +136,38 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
135
136
|
upscalerHdr: !0,
|
|
136
137
|
enableASVGF: !1,
|
|
137
138
|
asvgfQualityPreset: "medium",
|
|
138
|
-
asvgfTemporalAlpha:
|
|
139
|
-
asvgfAtrousIterations:
|
|
140
|
-
asvgfPhiColor:
|
|
141
|
-
asvgfPhiNormal:
|
|
142
|
-
asvgfPhiDepth:
|
|
143
|
-
asvgfPhiLuminance:
|
|
144
|
-
asvgfVarianceBoost:
|
|
145
|
-
asvgfMaxAccumFrames:
|
|
146
|
-
asvgfGradientStrength:
|
|
147
|
-
asvgfGradientSigmaScale:
|
|
148
|
-
asvgfGradientNoiseFloor:
|
|
139
|
+
asvgfTemporalAlpha: $r.temporalAlpha,
|
|
140
|
+
asvgfAtrousIterations: $r.atrousIterations,
|
|
141
|
+
asvgfPhiColor: $r.phiColor,
|
|
142
|
+
asvgfPhiNormal: $r.phiNormal,
|
|
143
|
+
asvgfPhiDepth: $r.phiDepth,
|
|
144
|
+
asvgfPhiLuminance: $r.phiLuminance,
|
|
145
|
+
asvgfVarianceBoost: $r.varianceBoost,
|
|
146
|
+
asvgfMaxAccumFrames: $r.maxAccumFrames,
|
|
147
|
+
asvgfGradientStrength: $r.gradientStrength,
|
|
148
|
+
asvgfGradientSigmaScale: $r.gradientSigmaScale,
|
|
149
|
+
asvgfGradientNoiseFloor: $r.gradientNoiseFloor,
|
|
149
150
|
asvgfDebugMode: 0,
|
|
150
151
|
showAsvgfHeatmap: !1,
|
|
151
152
|
nrdQualityPreset: "medium",
|
|
152
153
|
nrdDebugMode: 0
|
|
153
|
-
},
|
|
154
|
+
}, ti = class extends O {
|
|
154
155
|
constructor(e, t = {}) {
|
|
155
156
|
super("NormalDepth", {
|
|
156
157
|
...t,
|
|
157
|
-
executionMode:
|
|
158
|
-
}), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = G(new
|
|
158
|
+
executionMode: ge.ALWAYS
|
|
159
|
+
}), this.renderer = e, this.pathTracer = t.pathTracer, this._dirty = !0, this.cameraWorldMatrix = G(new br(), "mat4"), this.cameraProjectionMatrixInverse = G(new br(), "mat4"), this.cameraRay = oe(), this.resolutionWidth = G(t.width || 1), this.resolutionHeight = G(t.height || 1);
|
|
159
160
|
let n = t.width || 1, r = t.height || 1;
|
|
160
|
-
this._outputStorageTex = new
|
|
161
|
-
type:
|
|
161
|
+
this._outputStorageTex = new wn(A, A), this._outputStorageTex.type = mr, this._outputStorageTex.format = Q, this._outputStorageTex.minFilter = Z, this._outputStorageTex.magFilter = Z, this._shadingStorageTex = new wn(A, A), this._shadingStorageTex.type = mr, this._shadingStorageTex.format = Q, this._shadingStorageTex.minFilter = Z, this._shadingStorageTex.magFilter = Z, this._shadingRT = new Cn(n, r, {
|
|
162
|
+
type: mr,
|
|
162
163
|
format: Q,
|
|
163
164
|
minFilter: Z,
|
|
164
165
|
magFilter: Z,
|
|
165
166
|
depthBuffer: !1,
|
|
166
167
|
stencilBuffer: !1
|
|
167
|
-
}), this._leafStorageTex = null, this._leafRT = null, this._srcRegion = new
|
|
168
|
+
}), this._leafStorageTex = null, this._leafRT = null, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0));
|
|
168
169
|
let i = {
|
|
169
|
-
type:
|
|
170
|
+
type: mr,
|
|
170
171
|
format: Q,
|
|
171
172
|
minFilter: Z,
|
|
172
173
|
magFilter: Z,
|
|
@@ -186,40 +187,41 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
186
187
|
let e = this.pathTracer;
|
|
187
188
|
if (!e) return !1;
|
|
188
189
|
let t = e.materialData?.materialStorageAttr, n = e.triangleGeoAttr && e.triangleGeoAttr !== this._lastTriAttr, r = e.bvhStorageAttr && e.bvhStorageAttr !== this._lastBvhAttr, i = t && t !== this._lastMatAttr;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
190
|
+
if ((n || r || i) && (this._computeNode?.dispose?.(), this._computeNode = null, this._computeBuilt = !1, this._triStorageNode = null, this._bvhStorageNode = null, this._matStorageNode = null, this._dirty = !0, this._hasHistory = !1), !this._triStorageNode || !this._bvhStorageNode) {
|
|
191
|
+
let t = e.sceneStorageNodes?.();
|
|
192
|
+
t && (this._triStorageNode = t.triangles, this._bvhStorageNode = t.bvh);
|
|
193
|
+
}
|
|
194
|
+
return t && !this._matStorageNode && (this._matStorageNode = Jn(t, "vec4", t.count).toReadOnly()), this._linearBuckets && te(this._linearBuckets, e.materialData?.linearBuckets), this._lastTriAttr = e.triangleGeoAttr || this._lastTriAttr, this._lastBvhAttr = e.bvhStorageAttr || this._lastBvhAttr, this._lastMatAttr = t || this._lastMatAttr, !!(this._triStorageNode && this._bvhStorageNode && this._matStorageNode);
|
|
193
195
|
}
|
|
194
196
|
_buildCompute() {
|
|
195
|
-
let e = this._triStorageNode, n = this._bvhStorageNode,
|
|
196
|
-
this._linearBuckets =
|
|
197
|
+
let e = this._triStorageNode, n = this._bvhStorageNode, r = this._matStorageNode;
|
|
198
|
+
this._linearBuckets = ae(this.pathTracer?.materialData?.linearBuckets);
|
|
197
199
|
let o = {
|
|
198
|
-
srgbBuckets:
|
|
200
|
+
srgbBuckets: ae(null),
|
|
199
201
|
linearBuckets: this._linearBuckets,
|
|
200
202
|
shadowAlbedoMaps: null,
|
|
201
203
|
goboMaps: null,
|
|
202
204
|
iesProfiles: null,
|
|
203
205
|
alphaShadows: null
|
|
204
|
-
},
|
|
205
|
-
this._computeNode =
|
|
206
|
+
}, c = this.cameraWorldMatrix, u = this.cameraProjectionMatrixInverse, d = this.resolutionWidth, f = this.resolutionHeight, p = this._outputStorageTex, m = this._shadingStorageTex, h = this._leafStorageTex;
|
|
207
|
+
this._computeNode = he(En(([o, c]) => {
|
|
206
208
|
let u = F(Y.x).mul(8).add(F(L.x)), g = F(Y.y).mul(8).add(F(L.y));
|
|
207
209
|
N(u.lessThan(F(d)).and(g.lessThan(F(f))), () => {
|
|
208
|
-
let _ =
|
|
209
|
-
U(p,
|
|
210
|
+
let _ = t(ce(K(P(u).add(.5).div(d), P(g).add(.5).div(f)), o, c, this.cameraRay)), v = i.wrap(re(_, n, e)), y = v.normal.mul(.5).add(.5), b = Hn(v.dst, P(65504)), x = v.didHit.select(J(y, b), J(0, 0, 0, P(Wr)));
|
|
211
|
+
U(p, Xn(W(u), W(g)), x).toWriteOnly(), h && U(h, Xn(W(u), W(g)), Zn(W(v.instanceLeaf.add(1)), 0, 0, 0)).toWriteOnly();
|
|
210
212
|
let S = v.normal.toVar(), ee = P(1).toVar();
|
|
211
213
|
N(v.didHit, () => {
|
|
212
|
-
let
|
|
213
|
-
N(
|
|
214
|
-
o.assign(
|
|
214
|
+
let t = a.wrap(l(v.materialIndex, r)).toVar(), i = s.wrap(k(v.uv, t)).toVar(), o = J(0).toVar();
|
|
215
|
+
N(t.normalMapIndex.greaterThanEqual(F(0)), () => {
|
|
216
|
+
o.assign(ne(e, v.triangleIndex, v.normal, t.normalTransform, n, v.instanceLeaf));
|
|
215
217
|
});
|
|
216
|
-
let
|
|
217
|
-
S.assign(
|
|
218
|
+
let c = Ce(v.normal, t, i, o).toVar();
|
|
219
|
+
S.assign(ie(c, t, i)), ee.assign(se(t, i).y.clamp(.05, 1));
|
|
218
220
|
});
|
|
219
221
|
let C = v.didHit.select(J(S.mul(.5).add(.5), ee), J(0, 0, 0, 1));
|
|
220
|
-
U(m,
|
|
222
|
+
U(m, Xn(W(u), W(g)), C).toWriteOnly();
|
|
221
223
|
});
|
|
222
|
-
})(
|
|
224
|
+
})(c, u), o).compute([
|
|
223
225
|
this._dispatchX,
|
|
224
226
|
this._dispatchY,
|
|
225
227
|
1
|
|
@@ -263,15 +265,15 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
263
265
|
reallocateReservedStorage() {
|
|
264
266
|
this._computeNode?.dispose(), this._computeNode = null, this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose();
|
|
265
267
|
let e = () => {
|
|
266
|
-
let e = new
|
|
267
|
-
return e.type =
|
|
268
|
+
let e = new wn(A, A);
|
|
269
|
+
return e.type = mr, e.format = Q, e.minFilter = Z, e.magFilter = Z, e;
|
|
268
270
|
};
|
|
269
271
|
this._outputStorageTex = e(), this._shadingStorageTex = e(), this._leafStorageTex &&= (this._leafStorageTex.dispose(), this._makeLeafStorage()), this._computeBuilt = !1;
|
|
270
272
|
}
|
|
271
273
|
setInstanceLeafOutput(e) {
|
|
272
274
|
e = !!e, e !== !!this._leafStorageTex && (this._computeNode?.dispose(), this._computeNode = null, this._computeBuilt = !1, this._dirty = !0, e ? (this._leafStorageTex = this._makeLeafStorage(), this._leafRT = new Cn(this._rtA.width, this._rtA.height, {
|
|
273
|
-
type:
|
|
274
|
-
format:
|
|
275
|
+
type: Lr,
|
|
276
|
+
format: jr,
|
|
275
277
|
minFilter: Z,
|
|
276
278
|
magFilter: Z,
|
|
277
279
|
depthBuffer: !1,
|
|
@@ -282,22 +284,22 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
282
284
|
this._leafRT ? e.setTexture("pathtracer:instanceLeaf", this._leafRT.texture) : e.getTexture("pathtracer:instanceLeaf") && e.removeTexture("pathtracer:instanceLeaf");
|
|
283
285
|
}
|
|
284
286
|
_makeLeafStorage() {
|
|
285
|
-
let e = new
|
|
286
|
-
return e.type =
|
|
287
|
+
let e = new wn(A, A);
|
|
288
|
+
return e.type = Lr, e.format = jr, e.minFilter = Z, e.magFilter = Z, e;
|
|
287
289
|
}
|
|
288
290
|
dispose() {
|
|
289
291
|
this._computeNode?.dispose(), this._outputStorageTex?.dispose(), this._shadingStorageTex?.dispose(), this._shadingRT?.dispose(), this._leafStorageTex?.dispose(), this._leafRT?.dispose(), this._rtA?.dispose(), this._rtB?.dispose();
|
|
290
292
|
}
|
|
291
|
-
},
|
|
293
|
+
}, ni = class extends O {
|
|
292
294
|
constructor(e, t, n = {}) {
|
|
293
295
|
super("MotionVector", {
|
|
294
296
|
...n,
|
|
295
|
-
executionMode:
|
|
297
|
+
executionMode: ge.ALWAYS
|
|
296
298
|
}), this.renderer = e, this.camera = t, this.pathTracer = n.pathTracer || null;
|
|
297
299
|
let r = n.width || 1, i = n.height || 1;
|
|
298
|
-
this.prevViewProjectionMatrix = new
|
|
300
|
+
this.prevViewProjectionMatrix = new br(), this.currentViewProjectionMatrix = new br(), this.matricesInitialized = !1, this.isFirstFrame = !0, this.frameCount = 0, this.cameraWorldMatrix = G(new br(), "mat4"), this.cameraProjectionMatrixInverse = G(new br(), "mat4"), this.cameraRay = oe(), this.prevVP = G(new br(), "mat4"), this.isFirstFrameU = G(1), this.deltaTime = G(1 / 60), this.velocityScale = G(1), this.resolutionWidth = G(r), this.resolutionHeight = G(i), this._normalDepthTexNode = new M(), this._screenSpaceStorageTex = new wn(A, A), this._screenSpaceStorageTex.type = mr, this._screenSpaceStorageTex.format = Q, this._screenSpaceStorageTex.minFilter = Z, this._screenSpaceStorageTex.magFilter = Z, this._worldSpaceStorageTex = new wn(A, A), this._worldSpaceStorageTex.type = mr, this._worldSpaceStorageTex.format = Q, this._worldSpaceStorageTex.minFilter = Z, this._worldSpaceStorageTex.magFilter = Z, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0));
|
|
299
301
|
let a = {
|
|
300
|
-
type:
|
|
302
|
+
type: mr,
|
|
301
303
|
format: Q,
|
|
302
304
|
minFilter: Z,
|
|
303
305
|
magFilter: Z,
|
|
@@ -308,14 +310,14 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
308
310
|
}
|
|
309
311
|
_buildScreenSpaceCompute() {
|
|
310
312
|
let e = this._normalDepthTexNode, t = this.cameraWorldMatrix, n = this.cameraProjectionMatrixInverse, r = this.prevVP, i = this.resolutionWidth, a = this.resolutionHeight, o = this._screenSpaceStorageTex;
|
|
311
|
-
this._screenSpaceComputeNode =
|
|
313
|
+
this._screenSpaceComputeNode = En(([t, n]) => {
|
|
312
314
|
let s = F(Y.x).mul(16).add(F(L.x)), c = F(Y.y).mul(16).add(F(L.y));
|
|
313
315
|
N(s.lessThan(F(i)).and(c.lessThan(F(a))), () => {
|
|
314
316
|
let l = H(e, I(s, c)).w, u = K(P(s).add(.5).div(i), P(c).add(.5).div(a)), d = J(0, 0, l, 1).toVar();
|
|
315
317
|
N(l.lessThan(P(6e4)), () => {
|
|
316
|
-
let e =
|
|
318
|
+
let e = le(u, l, t, n, this.cameraRay), i = r.mul(J(e, 1)), a = i.xy.div(i.w), o = K(a.x.mul(.5).add(.5), a.y.mul(-.5).add(.5)), s = u.sub(o), c = o.x.greaterThanEqual(0).and(o.x.lessThanEqual(1)).and(o.y.greaterThanEqual(0)).and(o.y.lessThanEqual(1));
|
|
317
319
|
d.assign(c.select(J(s, l, 1), J(P(1e3), P(1e3), l, 0)));
|
|
318
|
-
}), U(o,
|
|
320
|
+
}), U(o, Xn(W(s), W(c)), d).toWriteOnly();
|
|
319
321
|
});
|
|
320
322
|
})(t, n).compute([
|
|
321
323
|
this._dispatchX,
|
|
@@ -329,14 +331,14 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
329
331
|
}
|
|
330
332
|
_buildWorldSpaceCompute() {
|
|
331
333
|
let e = this._normalDepthTexNode, t = this.cameraWorldMatrix, n = this.cameraProjectionMatrixInverse, r = this.prevVP, i = this.isFirstFrameU, a = this.deltaTime, o = this.velocityScale, s = this.resolutionWidth, c = this.resolutionHeight, l = this._worldSpaceStorageTex;
|
|
332
|
-
this._worldSpaceComputeNode =
|
|
334
|
+
this._worldSpaceComputeNode = En(([t, n]) => {
|
|
333
335
|
let u = F(Y.x).mul(16).add(F(L.x)), d = F(Y.y).mul(16).add(F(L.y));
|
|
334
336
|
N(u.lessThan(F(s)).and(d.lessThan(F(c))), () => {
|
|
335
337
|
let f = H(e, I(u, d)).w, p = J(0, 0, 0, 0).toVar();
|
|
336
338
|
N(i.lessThan(.5).and(f.lessThan(P(6e4))), () => {
|
|
337
|
-
let e = K(P(u).add(.5).div(s), P(d).add(.5).div(c)), i =
|
|
339
|
+
let e = K(P(u).add(.5).div(s), P(d).add(.5).div(c)), i = le(e, f, t, n, this.cameraRay), l = r.mul(J(i, 1)), m = l.xy.div(l.w), h = K(m.x.mul(.5).add(.5), m.y.mul(-.5).add(.5)), g = h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)), _ = e.sub(h), v = q(_.x.div(a).mul(o), _.y.div(a).mul(o), 0);
|
|
338
340
|
p.assign(g.select(J(v, 1), J(0, 0, 0, .5)));
|
|
339
|
-
}), U(l,
|
|
341
|
+
}), U(l, Xn(W(u), W(d)), p).toWriteOnly();
|
|
340
342
|
});
|
|
341
343
|
})(t, n).compute([
|
|
342
344
|
this._dispatchX,
|
|
@@ -400,44 +402,44 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
400
402
|
reallocateReservedStorage() {
|
|
401
403
|
this._screenSpaceComputeNode?.dispose(), this._worldSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this._worldSpaceStorageTex?.dispose();
|
|
402
404
|
let e = () => {
|
|
403
|
-
let e = new
|
|
404
|
-
return e.type =
|
|
405
|
+
let e = new wn(A, A);
|
|
406
|
+
return e.type = mr, e.format = Q, e.minFilter = Z, e.magFilter = Z, e;
|
|
405
407
|
};
|
|
406
408
|
this._screenSpaceStorageTex = e(), this._worldSpaceStorageTex = e(), this._buildScreenSpaceCompute(), this._buildWorldSpaceCompute();
|
|
407
409
|
}
|
|
408
410
|
dispose() {
|
|
409
411
|
this._screenSpaceComputeNode?.dispose(), this._worldSpaceComputeNode?.dispose(), this._screenSpaceStorageTex?.dispose(), this._worldSpaceStorageTex?.dispose(), this.screenSpaceTarget?.dispose(), this.worldSpaceTarget?.dispose(), this._normalDepthTexNode?.dispose();
|
|
410
412
|
}
|
|
411
|
-
},
|
|
413
|
+
}, ri = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), ii = (e) => q(ri(e.x), ri(e.y), ri(e.z)), ai = class extends O {
|
|
412
414
|
constructor(e, t = {}) {
|
|
413
415
|
super("ASVGF", {
|
|
414
416
|
...t,
|
|
415
|
-
executionMode:
|
|
416
|
-
}), this.renderer = e, this.temporalAlpha = G(t.temporalAlpha ??
|
|
417
|
+
executionMode: ge.PER_CYCLE
|
|
418
|
+
}), this.renderer = e, this.temporalAlpha = G(t.temporalAlpha ?? qr.medium.temporalAlpha), this.gradientStrength = G(t.gradientStrength ?? qr.medium.gradientStrength), this.gradientSigmaScale = G(t.gradientSigmaScale ?? qr.medium.gradientSigmaScale), this.gradientNoiseFloor = G(t.gradientNoiseFloor ?? qr.medium.gradientNoiseFloor), this.maxAccumFrames = G(t.maxAccumFrames ?? qr.medium.maxAccumFrames), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this.temporalEnabledU = G(1), this.forceResetU = G(0), this._colorTexNode = new M(), this._albedoTexNode = new M(), this._motionTexNode = new M(), this._normalDepthTexNode = new M(), this._prevNormalDepthTexNode = new M(), this._readTemporalTexNode = new M(), this._gradientReadTexNode = new M();
|
|
417
419
|
let n = t.width || 1, r = t.height || 1;
|
|
418
|
-
this._temporalTexA = new
|
|
419
|
-
type:
|
|
420
|
+
this._temporalTexA = new wn(A, A), this._temporalTexA.type = pr, this._temporalTexA.format = Q, this._temporalTexA.minFilter = X, this._temporalTexA.magFilter = X, this._temporalTexB = new wn(A, A), this._temporalTexB.type = pr, this._temporalTexB.format = Q, this._temporalTexB.minFilter = X, this._temporalTexB.magFilter = X, this._outputModulatedTex = new wn(A, A), this._outputModulatedTex.type = pr, this._outputModulatedTex.format = Q, this._outputModulatedTex.minFilter = X, this._outputModulatedTex.magFilter = X, this._gradientStorageTex = new wn(A, A), this._gradientStorageTex.type = mr, this._gradientStorageTex.format = Q, this._gradientStorageTex.minFilter = X, this._gradientStorageTex.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._demodulatedRT = new Cn(n, r, {
|
|
421
|
+
type: pr,
|
|
420
422
|
format: Q,
|
|
421
423
|
minFilter: X,
|
|
422
424
|
magFilter: X,
|
|
423
425
|
depthBuffer: !1,
|
|
424
426
|
stencilBuffer: !1
|
|
425
427
|
}), this._outputRT = new Cn(n, r, {
|
|
426
|
-
type:
|
|
428
|
+
type: pr,
|
|
427
429
|
format: Q,
|
|
428
430
|
minFilter: X,
|
|
429
431
|
magFilter: X,
|
|
430
432
|
depthBuffer: !1,
|
|
431
433
|
stencilBuffer: !1
|
|
432
434
|
}), this._gradientRT = new Cn(n, r, {
|
|
433
|
-
type:
|
|
435
|
+
type: mr,
|
|
434
436
|
format: Q,
|
|
435
437
|
minFilter: X,
|
|
436
438
|
magFilter: X,
|
|
437
439
|
depthBuffer: !1,
|
|
438
440
|
stencilBuffer: !1
|
|
439
|
-
}), this.currentMoments = 0, this._compiled = !1, this._needsWarmReset = !1, this._dispatchX = Math.ceil(n / 8), this._dispatchY = Math.ceil(r / 8), this._buildGradientCompute(), this._buildTemporalCompute(), this.showHeatmap = !1, this.debugMode = G(0, "int"), this._heatmapStorageTex = new
|
|
440
|
-
type:
|
|
441
|
+
}), this.currentMoments = 0, this._compiled = !1, this._needsWarmReset = !1, this._dispatchX = Math.ceil(n / 8), this._dispatchY = Math.ceil(r / 8), this._buildGradientCompute(), this._buildTemporalCompute(), this.showHeatmap = !1, this.debugMode = G(0, "int"), this._heatmapStorageTex = new wn(A, A), this._heatmapStorageTex.type = pr, this._heatmapStorageTex.format = Q, this._heatmapStorageTex.minFilter = Z, this._heatmapStorageTex.magFilter = Z, this.heatmapTarget = new Cn(n, r, {
|
|
442
|
+
type: pr,
|
|
441
443
|
format: Q,
|
|
442
444
|
minFilter: Z,
|
|
443
445
|
magFilter: Z,
|
|
@@ -446,13 +448,13 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
446
448
|
}), this._heatmapRawColorTexNode = new M(), this._heatmapColorTexNode = new M(), this._heatmapTemporalTexNode = new M(), this._heatmapNDTexNode = new M(), this._heatmapMotionTexNode = new M(), this._heatmapGradientTexNode = new M(), this._buildHeatmapCompute();
|
|
447
449
|
}
|
|
448
450
|
_buildGradientCompute() {
|
|
449
|
-
let e = this._colorTexNode, t = this._albedoTexNode, n = this._motionTexNode, r = this._readTemporalTexNode, i = this.gradientNoiseFloor, a = this.gradientSigmaScale, s = this._gradientStorageTex, c = this.resW, l = this.resH, u =
|
|
450
|
-
this._gradientNode =
|
|
451
|
+
let e = this._colorTexNode, t = this._albedoTexNode, n = this._motionTexNode, r = this._readTemporalTexNode, i = this.gradientNoiseFloor, a = this.gradientSigmaScale, s = this._gradientStorageTex, c = this.resW, l = this.resH, u = $n("float", 144), d = $n("float", 144);
|
|
452
|
+
this._gradientNode = En(() => {
|
|
451
453
|
let f = L.x, p = L.y, m = p.mul(8).add(f), h = F(Y.x).mul(8).sub(2).toVar(), g = F(Y.y).mul(8).sub(2).toVar(), _ = (i) => {
|
|
452
|
-
let a = i.mod(W(12)), s = i.div(W(12)), f = h.add(F(a)).clamp(F(0), F(c).sub(1)), p = g.add(F(s)).clamp(F(0), F(l).sub(1)), m = H(e, I(f, p)).xyz, _ = H(t, I(f, p)).xyz, v = o(
|
|
454
|
+
let a = i.mod(W(12)), s = i.div(W(12)), f = h.add(F(a)).clamp(F(0), F(c).sub(1)), p = g.add(F(s)).clamp(F(0), F(l).sub(1)), m = H(e, I(f, p)).xyz, _ = H(t, I(f, p)).xyz, v = o(ii(m.div(R(_, q(Kr))))).toVar();
|
|
453
455
|
u.element(i).assign(v);
|
|
454
|
-
let y = H(n, I(f, p)), b = P(f).sub(y.x.mul(c)), x = P(p).sub(y.y.mul(l)), S = F(b.add(.5)).clamp(F(0), F(c).sub(1)), ee = F(x.add(.5)).clamp(F(0), F(l).sub(1)), C = y.w.greaterThan(.5),
|
|
455
|
-
d.element(i).assign(
|
|
456
|
+
let y = H(n, I(f, p)), b = P(f).sub(y.x.mul(c)), x = P(p).sub(y.y.mul(l)), S = F(b.add(.5)).clamp(F(0), F(c).sub(1)), ee = F(x.add(.5)).clamp(F(0), F(l).sub(1)), C = y.w.greaterThan(.5), w = H(r, I(S, ee)).xyz, T = C.select(o(w), v);
|
|
457
|
+
d.element(i).assign(T);
|
|
456
458
|
};
|
|
457
459
|
_(m);
|
|
458
460
|
let v = m.add(W(64));
|
|
@@ -462,7 +464,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
462
464
|
let y = m.add(W(128));
|
|
463
465
|
N(y.lessThan(W(144)), () => {
|
|
464
466
|
_(y);
|
|
465
|
-
}),
|
|
467
|
+
}), er();
|
|
466
468
|
let b = F(Y.x).mul(8).add(F(f)), x = F(Y.y).mul(8).add(F(p));
|
|
467
469
|
N(b.lessThan(F(c)).and(x.lessThan(F(l))), () => {
|
|
468
470
|
let e = P(0).toVar(), t = P(0).toVar();
|
|
@@ -470,13 +472,13 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
470
472
|
let i = p.add(W(2 + n)).mul(W(12)).add(f.add(W(2 + r))), a = u.element(i);
|
|
471
473
|
e.addAssign(a), t.addAssign(a.mul(a));
|
|
472
474
|
}
|
|
473
|
-
let o = e.div(25), m =
|
|
475
|
+
let o = e.div(25), m = qn(R(t.div(25).sub(o.mul(o)), P(0))).mul(a).toVar(), h = P(0).toVar();
|
|
474
476
|
for (let e = -2; e <= 2; e++) for (let t = -2; t <= 2; t++) {
|
|
475
|
-
let n = p.add(W(2 + e)).mul(W(12)).add(f.add(W(2 + t))), r = u.element(n), a = d.element(n), o = R(R(
|
|
477
|
+
let n = p.add(W(2 + e)).mul(W(12)).add(f.add(W(2 + t))), r = u.element(n), a = d.element(n), o = R(R(kn(r.sub(a)).sub(m), P(0)).div(R(R(r, a), P(.001))).sub(i), P(0)).div(R(P(1).sub(i), P(1e-4)));
|
|
476
478
|
h.addAssign(o.mul(o));
|
|
477
479
|
}
|
|
478
480
|
let g = h.div(25).clamp(0, 1).toVar(), _ = H(n, I(b, x)), v = F(P(b).sub(_.x.mul(c)).add(.5)).clamp(F(0), F(c).sub(1)), y = F(P(x).sub(_.y.mul(l)).add(.5)).clamp(F(0), F(l).sub(1)), S = _.w.greaterThan(.5).select(H(r, I(v, y)).w, P(0)).div(4).clamp(0, 1), ee = g.mul(S);
|
|
479
|
-
U(s,
|
|
481
|
+
U(s, Xn(W(b), W(x)), J(ee, g, m, 1)).toWriteOnly();
|
|
480
482
|
});
|
|
481
483
|
})().compute([
|
|
482
484
|
this._dispatchX,
|
|
@@ -493,23 +495,23 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
493
495
|
}
|
|
494
496
|
_buildTemporalForDirection(e) {
|
|
495
497
|
let t = this._colorTexNode, n = this._albedoTexNode, r = this._motionTexNode, i = this._normalDepthTexNode, a = this._prevNormalDepthTexNode, o = this._readTemporalTexNode, s = this._gradientReadTexNode, c = this._outputModulatedTex, l = this.maxAccumFrames, u = this.temporalAlpha, d = this.gradientStrength, f = this.temporalEnabledU, p = this.forceResetU, m = this.resW, h = this.resH;
|
|
496
|
-
return
|
|
498
|
+
return En(() => {
|
|
497
499
|
let g = F(Y.x).mul(8).add(F(L.x)), _ = F(Y.y).mul(8).add(F(L.y));
|
|
498
500
|
N(g.lessThan(F(m)).and(_.lessThan(F(h))), () => {
|
|
499
|
-
let v = I(g, _), y = H(t, v), b = y.xyz, x = y.w, S = H(n, v).xyz, ee = R(S, q(
|
|
501
|
+
let v = I(g, _), y = H(t, v), b = y.xyz, x = y.w, S = H(n, v).xyz, ee = R(S, q(Kr)), C = ii(b.div(ee)), w = J(C, 1).toVar(), T = J(b, x).toVar();
|
|
500
502
|
N(f.greaterThan(.5).and(p.lessThan(.5)), () => {
|
|
501
503
|
let e = H(r, v), t = e.w.greaterThan(.5), n = P(g).sub(e.x.mul(m)), c = P(_).sub(e.y.mul(h)), f = n.greaterThanEqual(0).and(n.lessThan(P(m))).and(c.greaterThanEqual(0)).and(c.lessThan(P(h)));
|
|
502
504
|
N(t.and(f), () => {
|
|
503
|
-
let e = H(i, v), t = e.xyz.mul(2).sub(1), r = e.w, f = F(n), p = F(c), g = f.add(F(1)), _ = p.add(F(1)), y = n.sub(P(f)), b = c.sub(P(p)), S = f.clamp(F(0), F(m).sub(1)),
|
|
504
|
-
let o = H(a, I(e, n)), s = o.xyz.mul(2).sub(1), c = o.w, l =
|
|
505
|
+
let e = H(i, v), t = e.xyz.mul(2).sub(1), r = e.w, f = F(n), p = F(c), g = f.add(F(1)), _ = p.add(F(1)), y = n.sub(P(f)), b = c.sub(P(p)), S = f.clamp(F(0), F(m).sub(1)), E = g.clamp(F(0), F(m).sub(1)), te = p.clamp(F(0), F(h).sub(1)), D = _.clamp(F(0), F(h).sub(1)), ne = P(1).sub(y).mul(P(1).sub(b)), re = y.mul(P(1).sub(b)), ie = P(1).sub(y).mul(b), ae = y.mul(b), O = (e, n, i) => {
|
|
506
|
+
let o = H(a, I(e, n)), s = o.xyz.mul(2).sub(1), c = o.w, l = Wn(Fn(t, s).clamp(0, 1), P(16)), u = In(kn(r.sub(c)).div(R(r, P(.001))).div(P(.05)).negate());
|
|
505
507
|
return i.mul(l).mul(u);
|
|
506
|
-
},
|
|
507
|
-
N(
|
|
508
|
-
let e = H(o, I(S,
|
|
509
|
-
|
|
508
|
+
}, k = O(S, te, ne), oe = O(E, te, re), se = O(S, D, ie), A = O(E, D, ae), ce = k.add(oe).add(se).add(A);
|
|
509
|
+
N(ce.greaterThan(P(.01)), () => {
|
|
510
|
+
let e = H(o, I(S, te)), t = H(o, I(E, te)), n = H(o, I(S, D)), r = H(o, I(E, D)), i = P(1).div(ce), a = e.xyz.mul(k).add(t.xyz.mul(oe)).add(n.xyz.mul(se)).add(r.xyz.mul(A)).mul(i), c = e.w.mul(k).add(t.w.mul(oe)).add(n.w.mul(se)).add(r.w.mul(A)).mul(i), f = H(s, v).x.mul(d).clamp(0, 1), p = ii(z(a, C, z(R(P(1).div(c.add(1)), u), P(1), f))), m = Hn(c.add(1), l);
|
|
511
|
+
w.assign(J(p, m)), T.assign(J(p.mul(ee), x));
|
|
510
512
|
});
|
|
511
513
|
});
|
|
512
|
-
}), U(e,
|
|
514
|
+
}), U(e, Xn(W(g), W(_)), w).toWriteOnly(), U(c, Xn(W(g), W(_)), T).toWriteOnly();
|
|
513
515
|
});
|
|
514
516
|
})().compute([
|
|
515
517
|
this._dispatchX,
|
|
@@ -523,7 +525,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
523
525
|
}
|
|
524
526
|
_buildHeatmapCompute() {
|
|
525
527
|
let e = this._heatmapRawColorTexNode, t = this._heatmapColorTexNode, n = this._heatmapTemporalTexNode, r = this._heatmapNDTexNode, i = this._heatmapMotionTexNode, a = this._heatmapGradientTexNode, s = this._heatmapStorageTex, c = this.debugMode, l = this.resW, u = this.resH;
|
|
526
|
-
this._heatmapComputeNode =
|
|
528
|
+
this._heatmapComputeNode = En(() => {
|
|
527
529
|
let d = F(Y.x).mul(8).add(F(L.x)), f = F(Y.y).mul(8).add(F(L.y));
|
|
528
530
|
N(d.lessThan(F(l)).and(f.lessThan(F(u))), () => {
|
|
529
531
|
let p = I(d, f), m = J(0, 0, 0, 1).toVar();
|
|
@@ -543,7 +545,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
543
545
|
let e = H(n, p).w.div(32).clamp(0, 1);
|
|
544
546
|
m.assign(J(P(1).sub(e), e, P(.2), 1));
|
|
545
547
|
}).ElseIf(c.equal(F(3)), () => {
|
|
546
|
-
let e = H(i, p), t =
|
|
548
|
+
let e = H(i, p), t = kn(e.x).mul(100).clamp(0, 1), n = kn(e.y).mul(100).clamp(0, 1), r = t.add(n).clamp(0, 1);
|
|
547
549
|
m.assign(J(t, n, r.mul(.3), 1));
|
|
548
550
|
}).ElseIf(c.equal(F(4)), () => {
|
|
549
551
|
let e = H(r, p);
|
|
@@ -551,7 +553,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
551
553
|
}).Else(() => {
|
|
552
554
|
let e = H(a, p).x.mul(5).clamp(0, 1);
|
|
553
555
|
m.assign(J(e, e.mul(.5), P(1).sub(e), 1));
|
|
554
|
-
}), U(s,
|
|
556
|
+
}), U(s, Xn(W(d), W(f)), m).toWriteOnly();
|
|
555
557
|
});
|
|
556
558
|
})().compute([
|
|
557
559
|
this._dispatchX,
|
|
@@ -592,10 +594,10 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
592
594
|
reallocateReservedStorage() {
|
|
593
595
|
this._gradientNode?.dispose(), this._temporalNodeA?.dispose(), this._temporalNodeB?.dispose(), this._heatmapComputeNode?.dispose(), this._temporalTexA?.dispose(), this._temporalTexB?.dispose(), this._outputModulatedTex?.dispose(), this._gradientStorageTex?.dispose(), this._heatmapStorageTex?.dispose();
|
|
594
596
|
let e = (e, t) => {
|
|
595
|
-
let n = new
|
|
597
|
+
let n = new wn(A, A);
|
|
596
598
|
return n.type = e, n.format = Q, n.minFilter = t, n.magFilter = t, n;
|
|
597
599
|
};
|
|
598
|
-
this._temporalTexA = e(
|
|
600
|
+
this._temporalTexA = e(pr, X), this._temporalTexB = e(pr, X), this._outputModulatedTex = e(pr, X), this._gradientStorageTex = e(mr, X), this._heatmapStorageTex = e(pr, Z), this._buildGradientCompute(), this._buildTemporalCompute(), this._buildHeatmapCompute(), this._compiled = !1, this.currentMoments = 0, this._needsWarmReset = !0;
|
|
599
601
|
}
|
|
600
602
|
setSize(e, t) {
|
|
601
603
|
this._demodulatedRT.setSize(e, t), this._demodulatedRT.texture.needsUpdate = !0, this._outputRT.setSize(e, t), this._outputRT.texture.needsUpdate = !0, this._gradientRT.setSize(e, t), this._gradientRT.texture.needsUpdate = !0, this.heatmapTarget.setSize(e, t), this.heatmapTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e / 8), this._dispatchY = Math.ceil(t / 8), this._gradientNode.dispatchSize = [
|
|
@@ -623,7 +625,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
623
625
|
dispose() {
|
|
624
626
|
this._gradientNode?.dispose(), this._temporalNodeA?.dispose(), this._temporalNodeB?.dispose(), this._temporalTexA?.dispose(), this._temporalTexB?.dispose(), this._outputModulatedTex?.dispose(), this._gradientStorageTex?.dispose(), this._demodulatedRT?.dispose(), this._outputRT?.dispose(), this._gradientRT?.dispose(), this._heatmapComputeNode?.dispose(), this._heatmapStorageTex?.dispose(), this.heatmapTarget?.dispose(), this._colorTexNode?.dispose(), this._albedoTexNode?.dispose(), this._motionTexNode?.dispose(), this._normalDepthTexNode?.dispose(), this._prevNormalDepthTexNode?.dispose(), this._readTemporalTexNode?.dispose(), this._gradientReadTexNode?.dispose(), this._heatmapRawColorTexNode?.dispose(), this._heatmapColorTexNode?.dispose(), this._heatmapTemporalTexNode?.dispose(), this._heatmapNDTexNode?.dispose(), this._heatmapMotionTexNode?.dispose(), this._heatmapGradientTexNode?.dispose();
|
|
625
627
|
}
|
|
626
|
-
},
|
|
628
|
+
}, oi = 1e-6, si = 1.5 / 255, ci = .01, li = 3, ui = 2, di = 2, fi = 3, pi = 2, mi = 38, hi = .1, gi = 4, _i = Math.cos(89 * Math.PI / 180), vi = .5, yi = 16, bi = {
|
|
627
629
|
pre: {
|
|
628
630
|
radiusScale: 1,
|
|
629
631
|
fractionScale: 2
|
|
@@ -636,7 +638,7 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
636
638
|
radiusScale: 2,
|
|
637
639
|
fractionScale: .5
|
|
638
640
|
}
|
|
639
|
-
},
|
|
641
|
+
}, xi = .25 * Math.SQRT2, Si = [
|
|
640
642
|
[
|
|
641
643
|
-1,
|
|
642
644
|
0,
|
|
@@ -658,62 +660,62 @@ var zr = 65504, Br = 6e4, Vr = .01, Hr = {
|
|
|
658
660
|
1
|
|
659
661
|
],
|
|
660
662
|
[
|
|
661
|
-
-
|
|
662
|
-
|
|
663
|
+
-xi,
|
|
664
|
+
xi,
|
|
663
665
|
.5
|
|
664
666
|
],
|
|
665
667
|
[
|
|
666
|
-
|
|
667
|
-
|
|
668
|
+
xi,
|
|
669
|
+
xi,
|
|
668
670
|
.5
|
|
669
671
|
],
|
|
670
672
|
[
|
|
671
|
-
|
|
672
|
-
-
|
|
673
|
+
xi,
|
|
674
|
+
-xi,
|
|
673
675
|
.5
|
|
674
676
|
],
|
|
675
677
|
[
|
|
676
|
-
-
|
|
677
|
-
-
|
|
678
|
+
-xi,
|
|
679
|
+
-xi,
|
|
678
680
|
.5
|
|
679
681
|
]
|
|
680
|
-
],
|
|
681
|
-
let r = e.mul(t).add(n).abs().mul(-
|
|
682
|
+
], Ci = (e, t, n) => Kn(0, 1, P(1).sub(e.mul(t).add(n).abs())), wi = (e, t, n) => {
|
|
683
|
+
let r = e.mul(t).add(n).abs().mul(-li);
|
|
682
684
|
return P(1).div(r.mul(r).sub(r).add(1));
|
|
683
|
-
},
|
|
684
|
-
let i = R(
|
|
685
|
+
}, Ti = (e) => z(P(1.570796), P(1.395402), B(e)).mul(qn(B(P(1).sub(e)))), Ei = (e, t) => P(1).sub(Ln(e.mul(e).mul(-200))).mul(Wn(B(e), t)), Di = (e, t) => B(e).mul(qn(t.div(P(1).sub(t).add(oi)))), Oi = (e, t, n, r) => {
|
|
686
|
+
let i = R(An(Di(n, r.mul(z(B(t), P(1), e)))), P(si));
|
|
685
687
|
return P(1).div(i);
|
|
686
|
-
},
|
|
687
|
-
let n = P(1).div(z(P(
|
|
688
|
+
}, ki = (e, t) => {
|
|
689
|
+
let n = P(1).div(z(P(ci), P(1), B(e.mul(t))));
|
|
688
690
|
return K(n, e.mul(n).negate());
|
|
689
|
-
},
|
|
691
|
+
}, Ai = (e, t, n) => {
|
|
690
692
|
let r = P(1).div(z(P(n), P(1), z(e.mul(e), e, B(t))));
|
|
691
693
|
return K(r, e.mul(r).negate());
|
|
692
|
-
},
|
|
694
|
+
}, ji = (e, t) => {
|
|
693
695
|
let n = P(1).div(t);
|
|
694
696
|
return K(n, e.mul(n).negate());
|
|
695
|
-
},
|
|
697
|
+
}, Mi = (e, t, n, r) => {
|
|
696
698
|
let i = P(1).div(e.mul(t));
|
|
697
|
-
return K(i,
|
|
698
|
-
},
|
|
699
|
+
return K(i, Fn(r, n).mul(i).negate());
|
|
700
|
+
}, Ni = (e) => K(1).sub(K(1).sub(Bn(e.mul(.5)).mul(2)).abs()).min(.99999), Pi = (e) => q(Fn(e, q(.25, .5, .25)), Fn(e, q(.5, 0, -.5)), Fn(e, q(-.25, .5, -.25))), Fi = (e) => {
|
|
699
701
|
let t = e.x.sub(e.z);
|
|
700
702
|
return R(q(t.add(e.y), e.x.add(e.z), t.sub(e.y)), q(0));
|
|
701
|
-
},
|
|
702
|
-
function
|
|
703
|
+
}, Ii = (e, t) => t.add(oi).div(e.add(oi)), Li = (e, t) => J(e.xyz.mul(Ii(e.x, t)), e.w), Ri = (e) => J(Pi(Fi(e.xyz)), B(e.w)), zi = (e, t) => qn(t.sub(e.mul(e)).abs()), Bi = (e, t) => K(e.x.mul(t.x).add(e.y.mul(t.y)), e.z.mul(t.x).add(e.w.mul(t.y))), Vi = (e, t) => V(e.equal(0), J(0), t);
|
|
704
|
+
function Hi(e) {
|
|
703
705
|
let t = Math.imul(e | 0, 2654435761) >>> 0;
|
|
704
706
|
return t ^= t >>> 15, t = Math.imul(t, 2246822507) >>> 0, t ^= t >>> 13, t = Math.imul(t, 3266489909) >>> 0, t ^= t >>> 16, t / 4294967296;
|
|
705
707
|
}
|
|
706
|
-
var
|
|
708
|
+
var Ui = class extends O {
|
|
707
709
|
constructor(e, t = {}) {
|
|
708
710
|
super("NRD", {
|
|
709
711
|
...t,
|
|
710
|
-
executionMode:
|
|
712
|
+
executionMode: ge.PER_CYCLE
|
|
711
713
|
}), this.renderer = e, this.pathTracer = t.pathTracer || null, this.settings = {
|
|
712
|
-
...
|
|
714
|
+
...Xr,
|
|
713
715
|
...t.settings || {}
|
|
714
716
|
}, this._releaseHitDistance = this.pathTracer?.requestOutput?.("hitDistance", { encode: (e, t) => e.div(R(t.mul(.1).add(3), P(1e-4))).clamp(0, 1) }) ?? null;
|
|
715
717
|
let n = t.width || 1, r = t.height || 1;
|
|
716
|
-
this.resW = G(n), this.resH = G(r), this.minRectDimMulUnproject = G(1), this.inputFrames = G(0), this.resetU = G(0), this.debugMode = G(0, "int"), this.rotPre = G(new
|
|
718
|
+
this.resW = G(n), this.resH = G(r), this.minRectDimMulUnproject = G(1), this.inputFrames = G(0), this.resetU = G(0), this.debugMode = G(0, "int"), this.rotPre = G(new zr(1, 0, 0, 1), "vec4"), this.rotBlur = G(new zr(1, 0, 0, 1), "vec4"), this.rotPost = G(new zr(1, 0, 0, 1), "vec4"), this.camWorld = G(new br(), "mat4"), this.camProjInv = G(new br(), "mat4"), this.camView = G(new br(), "mat4"), this.prevCamView = G(new br(), "mat4"), this.camPos = G(new $(), "vec3"), this.prevCamPos = G(new $(), "vec3"), this.viewVector = G(new $(), "vec3"), this.prevViewVector = G(new $(), "vec3"), this.cameraRay = oe(), this.u = {};
|
|
717
719
|
for (let e of [
|
|
718
720
|
"maxAccum",
|
|
719
721
|
"maxFast",
|
|
@@ -734,24 +736,24 @@ var Ri = class extends oe {
|
|
|
734
736
|
"lobeVolumePercent",
|
|
735
737
|
"handoverFrames"
|
|
736
738
|
]) this.u[e] = G(0);
|
|
737
|
-
this.u.antilag = G(new
|
|
739
|
+
this.u.antilag = G(new Rr(), "vec2"), this.u.convergence = G(new $(), "vec3"), this._syncUniforms(), this._colorTexNode = new M(), this._albedoTexNode = new M(), this._ndTexNode = new M(), this._snTexNode = new M(), this._motionTexNode = new M(), this._placeholders = /* @__PURE__ */ new Map();
|
|
738
740
|
let i = () => {
|
|
739
|
-
let e = new
|
|
741
|
+
let e = new dr(new Float32Array(4), 1, 1, Q, pr);
|
|
740
742
|
e.needsUpdate = !0;
|
|
741
743
|
let t = new M(e);
|
|
742
744
|
return this._placeholders.set(t, e), t;
|
|
743
745
|
};
|
|
744
|
-
this._nTmpA = i(), this._nTmpB = i(), this._nHist = i(), this._nFast = i(), this._nInternal = i(), this._nGeom = i(), this._nData = i(), this._nStabRead = i(), this._allocStorage(), this._srcRegion = new
|
|
745
|
-
type:
|
|
746
|
+
this._nTmpA = i(), this._nTmpB = i(), this._nHist = i(), this._nFast = i(), this._nInternal = i(), this._nGeom = i(), this._nData = i(), this._nStabRead = i(), this._allocStorage(), this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this.outputTarget = new Cn(n, r, {
|
|
747
|
+
type: mr,
|
|
746
748
|
format: Q,
|
|
747
749
|
minFilter: X,
|
|
748
750
|
magFilter: X,
|
|
749
751
|
depthBuffer: !1,
|
|
750
752
|
stencilBuffer: !1
|
|
751
|
-
}), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n /
|
|
753
|
+
}), this._compiled = !1, this._needsReset = !0, this._stabPing = 0, this._camInitialized = !1, this._dispatchX = Math.ceil(n / yi), this._dispatchY = Math.ceil(r / yi), this._buildKernels();
|
|
752
754
|
}
|
|
753
755
|
_allocStorage() {
|
|
754
|
-
let e = () =>
|
|
756
|
+
let e = () => D(mr);
|
|
755
757
|
this._tmpA = e(), this._tmpB = e(), this._hist = e(), this._fastHist = e(), this._internal = e(), this._geomPrev = e(), this._stabA = e(), this._stabB = e(), this._dataT = e();
|
|
756
758
|
}
|
|
757
759
|
_disposeStorage() {
|
|
@@ -772,7 +774,7 @@ var Ri = class extends oe {
|
|
|
772
774
|
}
|
|
773
775
|
updateParameters(e) {
|
|
774
776
|
if (e) {
|
|
775
|
-
for (let t of Object.keys(e)) t === "debugMode" ? this.debugMode.value = e.debugMode | 0 : t in
|
|
777
|
+
for (let t of Object.keys(e)) t === "debugMode" ? this.debugMode.value = e.debugMode | 0 : t in Xr && (this.settings[t] = e[t]);
|
|
776
778
|
this._syncUniforms();
|
|
777
779
|
}
|
|
778
780
|
}
|
|
@@ -783,13 +785,13 @@ var Ri = class extends oe {
|
|
|
783
785
|
t.fastClampSigmaScale.value = 3 + (e.fastHistoryClampingSigmaScale - 3) * a, t.fireflyMinRelativeScale.value = e.fireflySuppressorMinRelativeScale, t.antiFirefly.value = +!!e.enableAntiFirefly, t.antilag.value.set(e.antilagLuminanceSigmaScale, e.antilagLuminanceSensitivity), t.disocclusionThreshold.value = e.disocclusionThreshold, t.convergence.value.set(e.convergenceS, e.convergenceB, e.convergenceP), t.lobeVolumePercent.value = e.lobeVolumePercent, t.handoverFrames.value = e.handoverFrames > 0 ? e.handoverFrames : 2 * n;
|
|
784
786
|
}
|
|
785
787
|
_worldPosAt(e, t, n, r) {
|
|
786
|
-
return
|
|
788
|
+
return le(e, t, n, r, this.cameraRay);
|
|
787
789
|
}
|
|
788
790
|
_viewVector(e, t, n) {
|
|
789
|
-
return V(
|
|
791
|
+
return V(E(this.cameraRay.cameraProjection), n, Un(t.sub(e)));
|
|
790
792
|
}
|
|
791
793
|
_frustumSize(e) {
|
|
792
|
-
return this.minRectDimMulUnproject.mul(V(
|
|
794
|
+
return this.minRectDimMulUnproject.mul(V(E(this.cameraRay.cameraProjection), P(1), e));
|
|
793
795
|
}
|
|
794
796
|
_pixelUv(e, t) {
|
|
795
797
|
return K(P(e).add(.5).div(this.resW), P(t).add(.5).div(this.resH));
|
|
@@ -808,7 +810,7 @@ var Ri = class extends oe {
|
|
|
808
810
|
return B(e.div(R(this.u.handoverFrames, 1)));
|
|
809
811
|
}
|
|
810
812
|
_bilinear(e) {
|
|
811
|
-
let t = e.mul(K(this.resW, this.resH)).sub(.5), n =
|
|
813
|
+
let t = e.mul(K(this.resW, this.resH)).sub(.5), n = zn(t), r = B(t.sub(n)), i = F(n.x), a = F(n.y), o = (e, t) => V(e.greaterThanEqual(F(0)).and(t.greaterThanEqual(F(0))).and(e.lessThan(F(this.resW))).and(t.lessThan(F(this.resH))), P(1), P(0));
|
|
812
814
|
return {
|
|
813
815
|
f: r,
|
|
814
816
|
taps: [
|
|
@@ -839,7 +841,7 @@ var Ri = class extends oe {
|
|
|
839
841
|
_sampleHistory(e, t, n, r, i) {
|
|
840
842
|
let a = J(0).toVar();
|
|
841
843
|
return N(i, () => {
|
|
842
|
-
let n = B(t).mul(K(this.resW, this.resH)), r =
|
|
844
|
+
let n = B(t).mul(K(this.resW, this.resH)), r = zn(n.sub(.5)).add(.5), i = B(n.sub(r)), o = vi, 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 = [
|
|
843
845
|
s.x,
|
|
844
846
|
c.x,
|
|
845
847
|
l.x,
|
|
@@ -877,176 +879,176 @@ var Ri = class extends oe {
|
|
|
877
879
|
this._dispatchY,
|
|
878
880
|
1
|
|
879
881
|
], [
|
|
880
|
-
|
|
881
|
-
|
|
882
|
+
yi,
|
|
883
|
+
yi,
|
|
882
884
|
1
|
|
883
885
|
]);
|
|
884
886
|
}
|
|
885
887
|
_buildSpatial(e) {
|
|
886
|
-
let t = e === "pre", { radiusScale:
|
|
887
|
-
let t = H(
|
|
888
|
-
return J(
|
|
889
|
-
} : (e) => H(p, e), C =
|
|
890
|
-
let s = F(Y.x).mul(
|
|
888
|
+
let t = e === "pre", { radiusScale: i, fractionScale: a } = bi[e], o = this.u, s = this._colorTexNode, l = this._albedoTexNode, u = this._ndTexNode, d = this._snTexNode, f = this._nData, p = e === "blur" ? this._nTmpA : this._nTmpB, m = e === "blur" ? this._tmpB : t ? this._tmpA : this._hist, h = this._geomPrev, g = t ? this.rotPre : e === "blur" ? this.rotBlur : this.rotPost, _ = t ? o.prepassBlurRadius : o.maxBlurRadius, v = this.camView, y = this.camPos, b = this.resW, x = this.resH, S = this.inputFrames, ee = t ? (e) => {
|
|
889
|
+
let t = H(s, e), i = H(l, e);
|
|
890
|
+
return J(Pi(n(t.xyz.div(R(i.xyz, q(Kr))))), r(i.w, c).min(1));
|
|
891
|
+
} : (e) => H(p, e), C = En(([n, r]) => {
|
|
892
|
+
let s = F(Y.x).mul(yi).add(F(L.x)), c = F(Y.y).mul(yi).add(F(L.y));
|
|
891
893
|
N(s.lessThan(F(b)).and(c.lessThan(F(x))), () => {
|
|
892
|
-
let l = I(s, c), p =
|
|
893
|
-
N(
|
|
894
|
-
let e = this._pixelUv(s, c), p = this._worldPosAt(e, C, n,
|
|
895
|
-
|
|
896
|
-
let s =
|
|
897
|
-
t || (
|
|
898
|
-
let
|
|
894
|
+
let l = I(s, c), p = Xn(W(s), W(c)), C = H(u, l).w.toVar(), w = C.greaterThanEqual(Gr), T = H(d, l).toVar(), E = Un(T.xyz.mul(2).sub(1)).toVar(), te = T.w.clamp(.05, 1).toVar(), D = P(Gr).toVar(), ne = ee(l).toVar();
|
|
895
|
+
N(w.not(), () => {
|
|
896
|
+
let e = this._pixelUv(s, c), p = this._worldPosAt(e, C, n, r).toVar();
|
|
897
|
+
D.assign(v.mul(J(p, 1)).z.abs()), N(_.greaterThan(0), () => {
|
|
898
|
+
let s = Fn(E, this._viewVector(p, y, this.viewVector)).abs().toVar(), c = this._frustumSize(D).toVar(), m = S.add(1), h = t ? R(S, P(10)) : H(f, l).y.add(S), C = (t ? P(1).div(h.add(1)) : this._advancedNonLinear(h)).toVar(), w = Ei(te, .5).toVar(), T = D.mul(Yr).add(3), re = ne.w.toVar(), ie = B(re.mul(T).div(c)), ae = P(1).sub(this._handover(m)), O = (t ? ie.div(m) : ie.mul(C)).mul(ae), k = o.minBlurRadius.mul(B(P(2).sub(h.div(R(o.maxAccum, 1))))), oe = R(B(qn(B(O)).mul(i)).mul(_).mul(w), k.mul(w)).toVar(), se = Mi(o.planeDistSensitivity, c, p, E).toVar(), A = Oi(C, o.lobeAngleFraction, te, o.lobeVolumePercent).div(a).toVar(), ce = ki(te, o.roughnessFraction.mul(a)).toVar(), le = ji(re, C).toVar(), ue = o.minHitDistanceWeight.mul(a).mul(w);
|
|
899
|
+
t || (ue = ue.mul(C)), ue = ue.toVar();
|
|
900
|
+
let de = K(1);
|
|
899
901
|
if (!t) {
|
|
900
|
-
let e = v.mul(J(
|
|
901
|
-
|
|
902
|
+
let e = v.mul(J(E, 0)).xy;
|
|
903
|
+
de = z(K(1).sub(e.abs()), K(1), s), de = de.div(R(de.x, de.y));
|
|
902
904
|
}
|
|
903
|
-
let
|
|
904
|
-
for (let t = 0; t <
|
|
905
|
-
let
|
|
906
|
-
s.mulAssign(
|
|
907
|
-
let h =
|
|
908
|
-
s.mulAssign(
|
|
905
|
+
let fe = de.mul(K(P(1).div(b), P(1).div(x))).mul(oe).toVar(), pe = P(1).toVar();
|
|
906
|
+
for (let t = 0; t < Si.length; t++) {
|
|
907
|
+
let i = Si[t], a = e.add(Bi(g, K(i[0], i[1])).mul(fe)), o = Ni(a), s = V(o.x.notEqual(a.x).or(o.y.notEqual(a.y)), P(1), P(Math.exp(-.66 * i[2] * i[2]))).toVar(), c = this._uvToCoord(o), l = H(u, c).w, f = this._worldPosAt(o, l, n, r), p = H(d, c), m = Ti(Fn(E, Un(p.xyz.mul(2).sub(1))));
|
|
908
|
+
s.mulAssign(Ci(m, A, P(0))), s.mulAssign(Ci(p.w, ce.x, ce.y)), s.mulAssign(Ci(Fn(E, f), se.x, se.y)), s.assign(V(l.greaterThanEqual(Gr), P(0), s));
|
|
909
|
+
let h = Vi(s, ee(c));
|
|
910
|
+
s.mulAssign(ue.add(wi(h.w, le.x, le.y))), pe.addAssign(s), ne.addAssign(h.mul(s));
|
|
909
911
|
}
|
|
910
|
-
|
|
912
|
+
ne.divAssign(R(pe, 1e-6)), t || ne.assign(J(ne.xyz, re));
|
|
911
913
|
});
|
|
912
|
-
}), U(m, p,
|
|
914
|
+
}), U(m, p, ne).toWriteOnly(), e === "post" && U(h, p, J(E, D)).toWriteOnly();
|
|
913
915
|
});
|
|
914
916
|
});
|
|
915
917
|
return this._dispatchOf(C);
|
|
916
918
|
}
|
|
917
919
|
_buildTemporalAccumulation() {
|
|
918
|
-
let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._motionTexNode, i = this._nTmpA, a = this._nHist, o = this._nFast, s = this._nInternal, c = this._nGeom, l = this._tmpB, u = this._dataT, d = this.camView, f = this.prevCamView, p = this.camPos, m = this.prevCamPos, h = this.resW, g = this.resH, _ = this.inputFrames, v = this.resetU, y =
|
|
919
|
-
let x = F(Y.x).mul(
|
|
920
|
+
let e = this.u, t = this._ndTexNode, n = this._snTexNode, r = this._motionTexNode, i = this._nTmpA, a = this._nHist, o = this._nFast, s = this._nInternal, c = this._nGeom, l = this._tmpB, u = this._dataT, d = this.camView, f = this.prevCamView, p = this.camPos, m = this.prevCamPos, h = this.resW, g = this.resH, _ = this.inputFrames, v = this.resetU, y = En(([y, b]) => {
|
|
921
|
+
let x = F(Y.x).mul(yi).add(F(L.x)), S = F(Y.y).mul(yi).add(F(L.y));
|
|
920
922
|
N(x.lessThan(F(h)).and(S.lessThan(F(g))), () => {
|
|
921
|
-
let h = I(x, S), g =
|
|
922
|
-
N(ee.greaterThanEqual(
|
|
923
|
-
U(l, g, C).toWriteOnly(), U(u, g, J(0)).toWriteOnly(),
|
|
923
|
+
let h = I(x, S), g = Xn(W(x), W(S)), ee = H(t, h).w, C = H(i, h).toVar();
|
|
924
|
+
N(ee.greaterThanEqual(Gr), () => {
|
|
925
|
+
U(l, g, C).toWriteOnly(), U(u, g, J(0)).toWriteOnly(), On();
|
|
924
926
|
});
|
|
925
|
-
let
|
|
926
|
-
|
|
927
|
+
let w = e.maxAccum.mul(P(1).sub(v)).toVar(), T = e.maxFast.mul(P(1).sub(v)).toVar(), E = H(n, h), te = Un(E.xyz.mul(2).sub(1)).toVar(), D = E.w.clamp(.05, 1).toVar(), ne = this._pixelUv(x, S), re = this._worldPosAt(ne, ee, y, b).toVar(), ie = d.mul(J(re, 1)).z.abs().toVar(), ae = Fn(te, this._viewVector(re, p, this.viewVector)).abs().toVar(), O = this._frustumSize(ie).toVar(), k = q(0).toVar();
|
|
928
|
+
k.addAssign(te.mul(.25));
|
|
927
929
|
for (let e = -1; e <= 0; e++) for (let r = -1; r <= 0; r++) {
|
|
928
930
|
if (r === 0 && e === 0) continue;
|
|
929
|
-
let i = this._clampCoord(x.add(r), S.add(e)), a =
|
|
930
|
-
|
|
931
|
+
let i = this._clampCoord(x.add(r), S.add(e)), a = Un(H(n, i).xyz.mul(2).sub(1)), o = H(t, i).w.lessThan(Gr);
|
|
932
|
+
k.addAssign(V(o, a, te).mul(.25));
|
|
931
933
|
}
|
|
932
|
-
let
|
|
934
|
+
let oe = H(r, h), se = ne.sub(oe.xy).toVar(), A = f.mul(J(re, 1)).z.abs().toVar(), ce = this._bilinear(se), le = O.mul(B(e.disocclusionThreshold.div(R(ae, .05)))).sub(oi).toVar(), ue = P(1).sub(v), de = [], fe = [];
|
|
933
935
|
for (let e = 0; e < 4; e++) {
|
|
934
|
-
let t = H(c,
|
|
935
|
-
|
|
936
|
+
let t = H(c, ce.taps[e]), n = V(Fn(t.xyz, k).greaterThan(_i), P(1), P(0)), r = V(t.w.sub(A).abs().lessThanEqual(le), P(1), P(0)), i = V(t.w.lessThan(Gr), P(1), P(0));
|
|
937
|
+
de.push(n.mul(r).mul(i).mul(ce.inScreen[e]).mul(ue).toVar()), fe.push(H(s, ce.taps[e]).x);
|
|
936
938
|
}
|
|
937
|
-
let
|
|
938
|
-
|
|
939
|
-
let
|
|
940
|
-
|
|
941
|
-
let
|
|
942
|
-
|
|
943
|
-
let
|
|
944
|
-
|
|
945
|
-
let
|
|
946
|
-
|
|
947
|
-
let
|
|
948
|
-
|
|
939
|
+
let pe = ce.customWeights(de).map((e) => e.toVar()), me = de[0].add(de[1]).add(de[2]).add(de[3]).greaterThan(3.5).toVar(), he = de[0].add(de[1].mul(2)).add(de[2].mul(4)).add(de[3].mul(8)), ge = this._applyCustomWeights(fe, pe, P(0)).toVar(), _e = Fn(te, this._viewVector(re, m, this.prevViewVector)).abs().add(.001).div(ae.add(.001)).toVar();
|
|
940
|
+
_e.assign(z(P(.1), P(1), B(_e.mul(_e))));
|
|
941
|
+
let ve = qn(B(ce.filter(de))).mul(_e).toVar();
|
|
942
|
+
ge.assign(ge.mul(z(ve, P(1), P(1).div(ge.add(1))))), ge.assign(Hn(ge, w));
|
|
943
|
+
let ye = Ri(this._sampleHistory((e) => H(a, e), se, ce, pe, me)).toVar(), be = R(this._applyCustomWeights(ce.taps.map((e) => H(o, e).x), pe, P(0)), 0).toVar(), xe = _.add(1), Se = this._handover(xe).toVar(), Ce = ge.mul(P(1).sub(Se)), we = xe.div(xe.add(Ce)).toVar(), j = P(1).div(P(1).add(Ei(D, .25).mul(.5).mul(w))), Te = J(z(ye.xyz, C.xyz, we), z(ye.w, C.w, R(we, j))).toVar(), Ee = e.fireflyMinRelativeScale.add(P(mi).div(ge.add(1))).toVar(), De = ge.mul(e.maxBlurRadius).mul(hi).toVar();
|
|
944
|
+
De.assign(De.div(De.add(1)).mul(P(1).sub(Se)));
|
|
945
|
+
let Oe = z(Te.x, Hn(Te.x, ye.x.mul(Ee)), De);
|
|
946
|
+
Te.assign(Li(Te, Oe));
|
|
947
|
+
let ke = P(1.2).add(P(1).div(ge.add(1)));
|
|
948
|
+
Te.assign(J(Te.xyz, z(Te.w, Hn(Te.w, ye.w.mul(ke)), De))), U(l, g, Te).toWriteOnly();
|
|
949
|
+
let Ae = Hn(ge, T).mul(P(1).sub(Se)), je = xe.div(xe.add(Ae)), Me = z(be, C.x, je).toVar(), Ne = Hn(Me, ye.x.mul(Ee).mul(gi));
|
|
950
|
+
Me.assign(z(Me, Ne, De)), U(u, g, J(Me, ge, he, V(me, P(1), P(0)))).toWriteOnly();
|
|
949
951
|
});
|
|
950
952
|
});
|
|
951
953
|
return this._dispatchOf(y);
|
|
952
954
|
}
|
|
953
955
|
_buildHistoryFix() {
|
|
954
|
-
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 =
|
|
955
|
-
let p = F(Y.x).mul(
|
|
956
|
+
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 = En(([d, f]) => {
|
|
957
|
+
let p = F(Y.x).mul(yi).add(F(L.x)), m = F(Y.y).mul(yi).add(F(L.y));
|
|
956
958
|
N(p.lessThan(F(c)).and(m.lessThan(F(l))), () => {
|
|
957
|
-
let h = I(p, m), g =
|
|
958
|
-
N(_.greaterThanEqual(
|
|
959
|
+
let h = I(p, m), g = Xn(W(p), W(m)), _ = H(t, h).w;
|
|
960
|
+
N(_.greaterThanEqual(Gr), () => {
|
|
959
961
|
let e = H(r, h);
|
|
960
|
-
U(a, g, e).toWriteOnly(), U(o, g, J(e.x, 0, 0, 0)).toWriteOnly(),
|
|
962
|
+
U(a, g, e).toWriteOnly(), U(o, g, J(e.x, 0, 0, 0)).toWriteOnly(), On();
|
|
961
963
|
});
|
|
962
|
-
let v = H(i, h).toVar(), y = v.y.toVar(), b = y.add(u), x = this._handover(u.add(1)).toVar(), S = H(n, h), ee =
|
|
963
|
-
N(
|
|
964
|
-
let a =
|
|
965
|
-
|
|
966
|
-
for (let e = -
|
|
967
|
-
if (m === 0 && e === 0 || Math.abs(m) + Math.abs(e) ===
|
|
968
|
-
let h =
|
|
969
|
-
b.mulAssign(
|
|
970
|
-
let x =
|
|
971
|
-
b.mulAssign(
|
|
964
|
+
let v = H(i, h).toVar(), y = v.y.toVar(), b = y.add(u), x = this._handover(u.add(1)).toVar(), S = H(n, h), ee = Un(S.xyz.mul(2).sub(1)).toVar(), C = S.w.clamp(.05, 1).toVar(), w = this._pixelUv(p, m), T = this._worldPosAt(w, _, d, f).toVar(), E = s.mul(J(T, 1)).z.abs(), te = this._frustumSize(E).toVar(), D = H(r, h).toVar(), ne = P(1).div(b.add(1)).toVar(), re = E.mul(Yr).add(3), ie = B(D.w.mul(re).div(te)), ae = D.w.toVar(), O = Gn(V(b.lessThan(e.historyFixFrameNum), P(1), P(0)).mul(.5).mul(2 / ui).mul(e.historyFixStride).mul(z(P(.25).add(qn(ie).mul(.75)), P(1), ne))).toVar();
|
|
965
|
+
N(O.notEqual(0), () => {
|
|
966
|
+
let a = Oi(ne, e.lobeAngleFraction, C, e.lobeVolumePercent).toVar(), o = Mi(e.planeDistSensitivity, te, T, ee).toVar(), s = ji(ae, ne).toVar(), u = Ai(C.mul(C), qn(e.roughnessFraction), ci).toVar(), p = P(1).add(y).toVar();
|
|
967
|
+
D.mulAssign(p);
|
|
968
|
+
for (let e = -ui; e <= ui; e++) for (let m = -ui; m <= ui; m++) {
|
|
969
|
+
if (m === 0 && e === 0 || Math.abs(m) + Math.abs(e) === ui * 2) continue;
|
|
970
|
+
let h = Ni(w.add(K(m, e).mul(O).mul(K(P(1).div(c), P(1).div(l))))), g = this._uvToCoord(h), _ = H(t, g).w, v = this._worldPosAt(h, _, d, f), y = H(n, g), b = wi(Ti(Fn(Un(y.xyz.mul(2).sub(1)), ee)), a, P(0)).toVar();
|
|
971
|
+
b.mulAssign(wi(y.w.mul(y.w), u.x, u.y)), b.mulAssign(P(1).add(H(i, g).y)), b.mulAssign(Ci(Fn(ee, v), o.x, o.y)), b.assign(V(_.greaterThanEqual(Gr), P(0), b));
|
|
972
|
+
let x = Vi(b, H(r, g));
|
|
973
|
+
b.mulAssign(wi(x.w, s.x, s.y)), p.addAssign(b), D.addAssign(x.mul(b));
|
|
972
974
|
}
|
|
973
|
-
|
|
975
|
+
D.divAssign(R(p, 1e-6));
|
|
974
976
|
});
|
|
975
|
-
let
|
|
976
|
-
U(o, g, J(
|
|
977
|
-
let
|
|
978
|
-
let a = this._clampCoord(p.add(e), m.add(n)), o = H(t, a).w, s = V(o.greaterThanEqual(
|
|
979
|
-
Math.abs(e) <=
|
|
980
|
-
},
|
|
981
|
-
for (let e = -
|
|
982
|
-
N(
|
|
983
|
-
for (let e = -
|
|
984
|
-
}), N(
|
|
985
|
-
let e = 1 / ((
|
|
986
|
-
|
|
977
|
+
let k = D.x.toVar(), oe = B(y.div(R(e.historyFixFrameNum, oi))), se = z(k, v.x, oe).toVar();
|
|
978
|
+
U(o, g, J(se, 0, 0, 0)).toWriteOnly();
|
|
979
|
+
let A = se.toVar(), ce = se.mul(se).toVar(), le = P(0).toVar(), ue = P(0).toVar(), de = (e, n, r) => {
|
|
980
|
+
let a = this._clampCoord(p.add(e), m.add(n)), o = H(t, a).w, s = V(o.greaterThanEqual(Gr), se, H(i, a).x);
|
|
981
|
+
Math.abs(e) <= di && Math.abs(n) <= di && (A.addAssign(s), ce.addAssign(s.mul(s))), r && (le.addAssign(s), ue.addAssign(s.mul(s)));
|
|
982
|
+
}, fe = e.antiFirefly.greaterThan(.5);
|
|
983
|
+
for (let e = -di; e <= di; e++) for (let t = -di; t <= di; t++) t === 0 && e === 0 || de(t, e, Math.abs(t) > 1 || Math.abs(e) > 1);
|
|
984
|
+
N(fe, () => {
|
|
985
|
+
for (let e = -fi; e <= fi; e++) for (let t = -fi; t <= fi; t++) Math.abs(t) <= di && Math.abs(e) <= di || de(t, e, !0);
|
|
986
|
+
}), N(fe, () => {
|
|
987
|
+
let e = 1 / ((fi * 2 + 1) ** 2 - 9), t = le.mul(e), n = zi(t, ue.mul(e)).mul(pi);
|
|
988
|
+
k.assign(z(k.clamp(t.sub(n), t.add(n)), k, x));
|
|
987
989
|
});
|
|
988
990
|
{
|
|
989
|
-
let t = 1 / (
|
|
990
|
-
|
|
991
|
+
let t = 1 / (di * 2 + 1) ** 2, n = A.mul(t), r = zi(n, ce.mul(t)).mul(e.fastClampSigmaScale), i = k.clamp(n.sub(r), n.add(r)), a = V(e.maxFast.lessThan(e.maxAccum), P(1), P(0)), o = z(P(1).div(P(1).add(a.mul(y).mul(2))), P(1), x);
|
|
992
|
+
k.assign(z(i, k, o));
|
|
991
993
|
}
|
|
992
|
-
U(a, g,
|
|
994
|
+
U(a, g, Li(D, k)).toWriteOnly();
|
|
993
995
|
});
|
|
994
996
|
});
|
|
995
997
|
return this._dispatchOf(d);
|
|
996
998
|
}
|
|
997
999
|
_buildTemporalStabilization(e) {
|
|
998
1000
|
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;
|
|
999
|
-
return
|
|
1000
|
-
let _ = F(Y.x).mul(
|
|
1001
|
+
return En(() => {
|
|
1002
|
+
let _ = F(Y.x).mul(yi).add(F(L.x)), v = F(Y.y).mul(yi).add(F(L.y));
|
|
1001
1003
|
N(_.lessThan(F(f)).and(v.lessThan(F(p))), () => {
|
|
1002
|
-
let f = I(_, v), p =
|
|
1003
|
-
N(y.greaterThanEqual(
|
|
1004
|
-
U(d, p, b).toWriteOnly(), U(e, p, J(H(s, f).x, 0, 0, 0)).toWriteOnly(), U(u, p, J(0, 1, 0, 0)).toWriteOnly(),
|
|
1004
|
+
let f = I(_, v), p = Xn(W(_), W(v)), y = H(i, f).w, b = H(n, f).toVar();
|
|
1005
|
+
N(y.greaterThanEqual(Gr), () => {
|
|
1006
|
+
U(d, p, b).toWriteOnly(), U(e, p, J(H(s, f).x, 0, 0, 0)).toWriteOnly(), U(u, p, J(0, 1, 0, 0)).toWriteOnly(), On();
|
|
1005
1007
|
});
|
|
1006
|
-
let x = H(a, f).w.clamp(.05, 1), S = this._pixelUv(_, v), ee = H(o, f), C = S.sub(ee.xy).toVar(),
|
|
1008
|
+
let x = H(a, f).w.clamp(.05, 1), S = this._pixelUv(_, v), ee = H(o, f), C = S.sub(ee.xy).toVar(), w = H(c, f).toVar(), T = w.y.toVar(), E = W(w.z.add(.5)).toVar(), te = w.w.greaterThan(.5), D = this._bilinear(C), ne = [
|
|
1007
1009
|
1,
|
|
1008
1010
|
2,
|
|
1009
1011
|
4,
|
|
1010
1012
|
8
|
|
1011
|
-
].map((e) => V(
|
|
1013
|
+
].map((e) => V(E.bitAnd(W(e)).notEqual(W(0)), P(1), P(0))), re = D.customWeights(ne).map((e) => e.toVar()), ie = qn(B(D.filter(ne))).toVar(), ae = H(s, f).toVar(), O = ae.x.toVar(), k = O.toVar(), oe = O.mul(O).toVar();
|
|
1012
1014
|
for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
|
|
1013
1015
|
if (t === 0 && e === 0) continue;
|
|
1014
|
-
let n = this._clampCoord(_.add(t), v.add(e)), r = H(i, n).w, a = V(r.greaterThanEqual(
|
|
1015
|
-
|
|
1016
|
+
let n = this._clampCoord(_.add(t), v.add(e)), r = H(i, n).w, a = V(r.greaterThanEqual(Gr), O, H(s, n).x);
|
|
1017
|
+
k.addAssign(a), oe.addAssign(a.mul(a));
|
|
1016
1018
|
}
|
|
1017
|
-
|
|
1018
|
-
let
|
|
1019
|
-
N(
|
|
1020
|
-
|
|
1019
|
+
k.divAssign(9), oe.divAssign(9);
|
|
1020
|
+
let se = zi(k, oe).toVar();
|
|
1021
|
+
N(T.lessThan(t.historyFixFrameNum), () => {
|
|
1022
|
+
O.assign(Hn(O, k.mul(P(1.2).add(P(1).div(T.add(1))))));
|
|
1021
1023
|
});
|
|
1022
|
-
let
|
|
1023
|
-
|
|
1024
|
-
let
|
|
1025
|
-
|
|
1026
|
-
let
|
|
1027
|
-
U(u, p, J(
|
|
1028
|
-
let
|
|
1024
|
+
let A = R(this._sampleHistory((e) => H(l, e), C, D, re, te).x, 0).toVar(), ce = se.mul(t.antilag.x), le = t.antilag.y.mul(4), ue = A.clamp(k.sub(ce), k.add(ce)), de = A.sub(ue).abs().div(R(A, ue).add(oi)), fe = P(1).div(P(1).add(de.mul(T.mul(ie)).div(le))).toVar(), pe = Hn(T, t.historyFixFrameNum);
|
|
1025
|
+
T.assign(z(pe, T, fe));
|
|
1026
|
+
let me = m.add(1), he = this._handover(me), ge = ie.mul(P(1).sub(this._advancedNonLinear(T.mul(P(1).sub(he)).div(me)))).mul(fe).toVar(), _e = P(1).add(ge.mul(6)), ve = t.stabilizationStrength.mul(P(1).sub(h)), ye = z(O, A.clamp(k.sub(se.mul(_e)), k.add(se.mul(_e))), Hn(ge, ve)).toVar();
|
|
1027
|
+
ae.assign(Li(ae, ye)), U(e, p, J(ye, 0, 0, 0)).toWriteOnly();
|
|
1028
|
+
let be = t.maxAccum.mul(P(1).sub(h));
|
|
1029
|
+
U(u, p, J(Hn(T.add(1), be), x, 0, 0)).toWriteOnly();
|
|
1030
|
+
let xe = H(r, f), Se = J(Fi(ae.xyz).mul(R(xe.xyz, q(Kr))), b.w).toVar();
|
|
1029
1031
|
N(g.equal(F(1)), () => {
|
|
1030
|
-
let e = B(
|
|
1031
|
-
|
|
1032
|
+
let e = B(T.div(R(t.maxAccum, 1)));
|
|
1033
|
+
Se.assign(J(P(1).sub(e), e, .2, 1));
|
|
1032
1034
|
}).ElseIf(g.equal(F(2)), () => {
|
|
1033
|
-
|
|
1035
|
+
Se.assign(J(q(ae.w), 1));
|
|
1034
1036
|
}).ElseIf(g.equal(F(3)), () => {
|
|
1035
|
-
|
|
1037
|
+
Se.assign(J(q(x), 1));
|
|
1036
1038
|
}).ElseIf(g.equal(F(4)), () => {
|
|
1037
|
-
let e =
|
|
1038
|
-
|
|
1039
|
+
let e = w.x.div(w.x.add(1));
|
|
1040
|
+
Se.assign(J(q(e), 1));
|
|
1039
1041
|
}).ElseIf(g.equal(F(5)), () => {
|
|
1040
|
-
|
|
1041
|
-
}), U(d, p,
|
|
1042
|
+
Se.assign(J(q(w.z.div(15)), 1));
|
|
1043
|
+
}), U(d, p, Se).toWriteOnly();
|
|
1042
1044
|
});
|
|
1043
1045
|
})().compute([
|
|
1044
1046
|
this._dispatchX,
|
|
1045
1047
|
this._dispatchY,
|
|
1046
1048
|
1
|
|
1047
1049
|
], [
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
+
yi,
|
|
1051
|
+
yi,
|
|
1050
1052
|
1
|
|
1051
1053
|
]);
|
|
1052
1054
|
}
|
|
@@ -1066,7 +1068,7 @@ var Ri = class extends oe {
|
|
|
1066
1068
|
}
|
|
1067
1069
|
_updateRotators(e) {
|
|
1068
1070
|
let t = (t, n) => {
|
|
1069
|
-
let r =
|
|
1071
|
+
let r = Hi(e * 3 + n) * Math.PI * 2;
|
|
1070
1072
|
t.value.set(Math.cos(r), Math.sin(r), -Math.sin(r), Math.cos(r));
|
|
1071
1073
|
};
|
|
1072
1074
|
t(this.rotPre, 0), t(this.rotBlur, 1), t(this.rotPost, 2);
|
|
@@ -1093,7 +1095,7 @@ var Ri = class extends oe {
|
|
|
1093
1095
|
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;
|
|
1094
1096
|
}
|
|
1095
1097
|
setSize(e, t) {
|
|
1096
|
-
this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e /
|
|
1098
|
+
this.outputTarget.setSize(e, t), this.outputTarget.texture.needsUpdate = !0, this.resW.value = e, this.resH.value = t, this._dispatchX = Math.ceil(e / yi), this._dispatchY = Math.ceil(t / yi);
|
|
1097
1099
|
let n = [
|
|
1098
1100
|
this._dispatchX,
|
|
1099
1101
|
this._dispatchY,
|
|
@@ -1122,15 +1124,15 @@ var Ri = class extends oe {
|
|
|
1122
1124
|
for (let [e, t] of this._placeholders) e.dispose(), t.dispose();
|
|
1123
1125
|
this._placeholders.clear();
|
|
1124
1126
|
}
|
|
1125
|
-
},
|
|
1127
|
+
}, Wi = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), Gi = /* @__PURE__ */ Qn("\n fn temporalAccumulate(\n lum: f32,\n prevMean: f32,\n prevMeanSq: f32,\n alpha: f32,\n spatialVariance: f32,\n varianceBoost: f32\n ) -> vec4f {\n\n let newMean = prevMean + ( lum - prevMean ) * alpha;\n let newMeanSq = prevMeanSq + ( lum * lum - prevMeanSq ) * alpha;\n let temporalVariance = max( newMeanSq - newMean * newMean, 0.0 );\n\n return vec4f(\n newMean,\n newMeanSq,\n temporalVariance * varianceBoost,\n spatialVariance * varianceBoost\n );\n\n }\n"), Ki = class extends O {
|
|
1126
1128
|
constructor(e, t = {}) {
|
|
1127
1129
|
super("VarianceEstimation", {
|
|
1128
1130
|
...t,
|
|
1129
|
-
executionMode:
|
|
1131
|
+
executionMode: ge.ALWAYS
|
|
1130
1132
|
}), this.renderer = e, this.inputTextureName = t.inputTextureName || "pathtracer:color", this.varianceBoost = G(t.varianceBoost ?? 1), this.temporalAlpha = G(t.temporalAlpha ?? .1), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this._colorTexNode = new M();
|
|
1131
1133
|
let n = t.width || 1, r = t.height || 1;
|
|
1132
|
-
this._storageTexA = new
|
|
1133
|
-
type:
|
|
1134
|
+
this._storageTexA = new wn(A, A), this._storageTexA.type = pr, this._storageTexA.format = Q, this._storageTexA.minFilter = X, this._storageTexA.magFilter = X, this._storageTexB = new wn(A, A), this._storageTexB.type = pr, this._storageTexB.format = Q, this._storageTexB.minFilter = X, this._storageTexB.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._outputTarget = new Cn(n, r, {
|
|
1135
|
+
type: pr,
|
|
1134
1136
|
format: Q,
|
|
1135
1137
|
minFilter: X,
|
|
1136
1138
|
magFilter: X,
|
|
@@ -1145,13 +1147,13 @@ var Ri = class extends oe {
|
|
|
1145
1147
|
this._readTexNodeA = new M(), this._readTexNodeB = new M(), this._computeNodeA = this._buildComputeForDirection(this._storageTexA, this._readTexNodeB), this._computeNodeB = this._buildComputeForDirection(this._storageTexB, this._readTexNodeA);
|
|
1146
1148
|
}
|
|
1147
1149
|
_buildComputeForDirection(e, t) {
|
|
1148
|
-
let n = this._colorTexNode, r = this.temporalAlpha, i = this.varianceBoost, a = this.resW, s = this.resH, c =
|
|
1149
|
-
return
|
|
1150
|
+
let n = this._colorTexNode, r = this.temporalAlpha, i = this.varianceBoost, a = this.resW, s = this.resH, c = $n("float", 100);
|
|
1151
|
+
return En(() => {
|
|
1150
1152
|
let l = L.x, u = L.y, d = u.mul(8).add(l), f = F(Y.x).mul(8).sub(1), p = F(Y.y).mul(8).sub(1), m = d.mod(10), h = d.div(10), g = H(n, I(f.add(F(m)).clamp(F(0), F(a).sub(1)), p.add(F(h)).clamp(F(0), F(s).sub(1)))).xyz;
|
|
1151
|
-
c.element(d).assign(
|
|
1153
|
+
c.element(d).assign(Wi(o(g))), N(d.lessThan(W(36)), () => {
|
|
1152
1154
|
let e = d.add(W(64)), t = e.mod(10), r = e.div(10), i = H(n, I(f.add(F(t)).clamp(F(0), F(a).sub(1)), p.add(F(r)).clamp(F(0), F(s).sub(1)))).xyz;
|
|
1153
|
-
c.element(e).assign(
|
|
1154
|
-
}),
|
|
1155
|
+
c.element(e).assign(Wi(o(i)));
|
|
1156
|
+
}), er();
|
|
1155
1157
|
let _ = F(Y.x).mul(8).add(F(l)), v = F(Y.y).mul(8).add(F(u));
|
|
1156
1158
|
N(_.lessThan(F(a)).and(v.lessThan(F(s))), () => {
|
|
1157
1159
|
let n = P(0).toVar(), a = P(0).toVar();
|
|
@@ -1161,7 +1163,7 @@ var Ri = class extends oe {
|
|
|
1161
1163
|
}
|
|
1162
1164
|
n.divAssign(9), a.divAssign(9);
|
|
1163
1165
|
let o = R(a.sub(n.mul(n)), P(0)), s = c.element(u.add(1).mul(10).add(l.add(1))), d = H(t, I(_, v));
|
|
1164
|
-
U(e,
|
|
1166
|
+
U(e, Xn(W(_), W(v)), Gi(s, d.x, d.y, r, o, i)).toWriteOnly();
|
|
1165
1167
|
});
|
|
1166
1168
|
})().compute([
|
|
1167
1169
|
this._dispatchX,
|
|
@@ -1207,23 +1209,23 @@ var Ri = class extends oe {
|
|
|
1207
1209
|
reallocateReservedStorage() {
|
|
1208
1210
|
this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose();
|
|
1209
1211
|
let e = () => {
|
|
1210
|
-
let e = new
|
|
1211
|
-
return e.type =
|
|
1212
|
+
let e = new wn(A, A);
|
|
1213
|
+
return e.type = pr, e.format = Q, e.minFilter = X, e.magFilter = X, e;
|
|
1212
1214
|
};
|
|
1213
1215
|
this._storageTexA = e(), this._storageTexB = e(), this._buildCompute(), this._compiled = !1;
|
|
1214
1216
|
}
|
|
1215
1217
|
dispose() {
|
|
1216
1218
|
this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose(), this._outputTarget?.dispose(), this._colorTexNode?.dispose(), this._readTexNodeA?.dispose(), this._readTexNodeB?.dispose();
|
|
1217
1219
|
}
|
|
1218
|
-
},
|
|
1220
|
+
}, qi = /* @__PURE__ */ Qn("\n fn bilateralWeight(\n centerLum: f32, sLum: f32,\n centerNormal: vec3f, sNormal: vec3f,\n centerDepth: f32, sDepth: f32,\n centerColor: vec3f, sColor: vec3f,\n kernelW: f32,\n sigmaL: f32, phiNorm: f32, phiDep: f32, phiCol: f32\n ) -> f32 {\n\n let lumW = exp( -abs( centerLum - sLum ) / sigmaL );\n // clamp dot to [0,1]: miss-ray normals decode to (-1,-1,-1) with\n // dot=3 → pow saturates to +inf → inf*0 = NaN. See project_tsl_pitfalls.\n // max(phiNorm, 1e-6): pow(0.0, 0.0) is undefined in WGSL and returned NaN on ~12%\n // of pixels when phiNormal was set to 0.\n let normW = pow( clamp( dot( centerNormal, sNormal ), 0.0, 1.0 ), max( phiNorm, 1e-6 ) );\n let depW = exp( -abs( centerDepth - sDepth ) / max( centerDepth * phiDep, 0.001 ) );\n let maxDiff = max( max( abs( centerColor.x - sColor.x ),\n abs( centerColor.y - sColor.y ) ),\n abs( centerColor.z - sColor.z ) );\n let avgLum = max( ( centerLum + sLum ) * 0.5, 0.0001 );\n let colW = exp( -( maxDiff / avgLum ) / max( phiCol, 0.0001 ) );\n return kernelW * lumW * normW * depW * colW;\n\n }\n"), Ji = class extends O {
|
|
1219
1221
|
constructor(e, t = {}) {
|
|
1220
1222
|
super("BilateralFiltering", {
|
|
1221
1223
|
...t,
|
|
1222
|
-
executionMode:
|
|
1224
|
+
executionMode: ge.ALWAYS
|
|
1223
1225
|
}), this.renderer = e, this.inputTextureName = t.inputTextureName || "asvgf:demodulated", this.normalDepthTextureName = t.normalDepthTextureName || "pathtracer:normalDepth", this.shadingNormalTextureName = t.shadingNormalTextureName || "pathtracer:shadingNormal", this.albedoTextureName = t.albedoTextureName || "pathtracer:albedo", this.varianceTextureName = t.varianceTextureName || "variance:output", this.iterations = t.iterations ?? 4, this.phiColor = G(t.phiColor ?? .5), this.phiNormal = G(t.phiNormal ?? 128), this.phiDepth = G(t.phiDepth ?? .05), this.phiLuminance = G(t.phiLuminance ?? 4), this.spatialVarianceWeight = G(t.spatialVarianceWeight ?? 1), this.stepSizeU = G(1, "int"), this.isLastIterationU = G(0, "int"), this.isFirstIterationU = G(1, "int"), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this._readTexNode = new M(), this._normalDepthTexNode = new M(), this._shadingNormalTexNode = new M(), this._albedoTexNode = new M(), this._varianceTexNode = new M(), this._srcAlphaTexNode = new M();
|
|
1224
1226
|
let n = t.width || 1, r = t.height || 1;
|
|
1225
|
-
this._storageTexA = new
|
|
1226
|
-
type:
|
|
1227
|
+
this._storageTexA = new wn(A, A), this._storageTexA.type = mr, this._storageTexA.format = Q, this._storageTexA.minFilter = X, this._storageTexA.magFilter = X, this._storageTexB = new wn(A, A), this._storageTexB.type = mr, this._storageTexB.format = Q, this._storageTexB.minFilter = X, this._storageTexB.magFilter = X, this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this._outputTarget = new Cn(n, r, {
|
|
1228
|
+
type: mr,
|
|
1227
1229
|
format: Q,
|
|
1228
1230
|
minFilter: X,
|
|
1229
1231
|
magFilter: X,
|
|
@@ -1262,19 +1264,19 @@ var Ri = class extends oe {
|
|
|
1262
1264
|
4 / 256,
|
|
1263
1265
|
1 / 256
|
|
1264
1266
|
];
|
|
1265
|
-
return
|
|
1267
|
+
return En(() => {
|
|
1266
1268
|
let y = F(Y.x).mul(8).add(F(L.x)), b = F(Y.y).mul(8).add(F(L.y));
|
|
1267
1269
|
N(y.lessThan(F(g)).and(b.lessThan(F(_))), () => {
|
|
1268
|
-
let x = I(y, b), S = H(t, x), ee = S.xyz, C = H(n, x),
|
|
1270
|
+
let x = I(y, b), S = H(t, x), ee = S.xyz, C = H(n, x), w = H(r, x).xyz.mul(2).sub(1), T = C.w, E = o(ee), te = R(H(i, x).xyz, q(Kr)), D = R(o(te), P(Kr)).toVar(), ne = h.equal(F(1)), re = (e) => {
|
|
1269
1271
|
let t = H(a, e);
|
|
1270
1272
|
return z(t.z, R(t.z, t.w), f);
|
|
1271
|
-
},
|
|
1273
|
+
}, ie = ne.select(re(x), S.w.mul(S.w)).toVar(), ae = d.mul(qn(R(ie, P(0)))).div(D).add(P(1e-4)), O = q(0).toVar(), k = P(0).toVar(), oe = P(0).toVar();
|
|
1272
1274
|
for (let e = 0; e < 5; e++) for (let i = 0; i < 5; i++) {
|
|
1273
|
-
let a = i - 2, s = e - 2, d = v[e * 5 + i], f = y.add(p.mul(a)).clamp(F(0), F(g).sub(1)), m = b.add(p.mul(s)).clamp(F(0), F(_).sub(1)), h = H(t, I(f, m)), x = h.xyz, S = H(n, I(f, m)), C = H(r, I(f, m)).xyz.mul(2).sub(1),
|
|
1274
|
-
|
|
1275
|
+
let a = i - 2, s = e - 2, d = v[e * 5 + i], f = y.add(p.mul(a)).clamp(F(0), F(g).sub(1)), m = b.add(p.mul(s)).clamp(F(0), F(_).sub(1)), h = H(t, I(f, m)), x = h.xyz, S = H(n, I(f, m)), C = H(r, I(f, m)).xyz.mul(2).sub(1), te = S.w, D = qi(E, o(x), w, C, T, te, ee, x, P(d), ae, l, u, c), ie = ne.select(re(I(f, m)), h.w.mul(h.w));
|
|
1276
|
+
O.addAssign(x.mul(D)), k.addAssign(D), oe.addAssign(D.mul(D).mul(R(ie, P(0))));
|
|
1275
1277
|
}
|
|
1276
|
-
let
|
|
1277
|
-
U(e,
|
|
1278
|
+
let se = O.div(R(k, P(1e-4))), A = oe.div(R(k.mul(k), P(1e-8))), ce = m.equal(F(1)), le = ce.select(se.mul(te), se), ue = ce.select(H(s, x).w, qn(R(A, P(0))));
|
|
1279
|
+
U(e, Xn(W(y), W(b)), J(le, ue)).toWriteOnly();
|
|
1278
1280
|
});
|
|
1279
1281
|
})().compute([
|
|
1280
1282
|
this._dispatchX,
|
|
@@ -1321,15 +1323,15 @@ var Ri = class extends oe {
|
|
|
1321
1323
|
reallocateReservedStorage() {
|
|
1322
1324
|
this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose();
|
|
1323
1325
|
let e = () => {
|
|
1324
|
-
let e = new
|
|
1325
|
-
return e.type =
|
|
1326
|
+
let e = new wn(A, A);
|
|
1327
|
+
return e.type = mr, e.format = Q, e.minFilter = X, e.magFilter = X, e;
|
|
1326
1328
|
};
|
|
1327
1329
|
this._storageTexA = e(), this._storageTexB = e(), this._buildCompute(), this._compiled = !1;
|
|
1328
1330
|
}
|
|
1329
1331
|
dispose() {
|
|
1330
1332
|
this._computeNodeA?.dispose(), this._computeNodeB?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose(), this._outputTarget?.dispose(), this._readTexNode?.dispose(), this._normalDepthTexNode?.dispose(), this._shadingNormalTexNode?.dispose(), this._albedoTexNode?.dispose(), this._varianceTexNode?.dispose(), this._srcAlphaTexNode?.dispose();
|
|
1331
1333
|
}
|
|
1332
|
-
},
|
|
1334
|
+
}, Yi = 6e4, Xi = (e) => V(e.equal(e), e, P(0)).clamp(0, 1e7), Zi = (e) => q(Xi(e.x), Xi(e.y), Xi(e.z)), Qi = 4, $i = [
|
|
1333
1335
|
1 / 256,
|
|
1334
1336
|
4 / 256,
|
|
1335
1337
|
6 / 256,
|
|
@@ -1355,15 +1357,15 @@ var Ri = class extends oe {
|
|
|
1355
1357
|
6 / 256,
|
|
1356
1358
|
4 / 256,
|
|
1357
1359
|
1 / 256
|
|
1358
|
-
],
|
|
1360
|
+
], ea = class extends O {
|
|
1359
1361
|
constructor(e, t = {}) {
|
|
1360
1362
|
super("EdgeAwareFiltering", {
|
|
1361
1363
|
...t,
|
|
1362
|
-
executionMode:
|
|
1364
|
+
executionMode: ge.PER_CYCLE
|
|
1363
1365
|
}), this.renderer = e, this.filterStrength = G(t.filterStrength ?? 1), this.phiLuminance = G(t.phiLuminance ?? 1), this.phiNormal = G(t.phiNormal ?? 64), this.phiDepth = G(t.phiDepth ?? .1), this.iterations = t.atrousIterations ?? t.edgeAtrousIterations ?? 5, this.stepSizeU = G(1, "int"), this.isLastIterationU = G(0, "int"), this.isFirstIterationU = G(1, "int"), this.varianceHistoryU = G(0, "int"), this.resW = G(t.width || 1), this.resH = G(t.height || 1), this._colorTexNode = new M(), this._ndTexNode = new M(), this._snTexNode = new M(), this._albedoTexNode = new M(), this._varTexNode = new M(), this._readTexNode = new M();
|
|
1364
1366
|
let n = t.width || 1, r = t.height || 1;
|
|
1365
|
-
this._demodTex = this._makeStorageTex(), this._storageTexA = this._makeStorageTex(), this._storageTexB = this._makeStorageTex(), this._srcRegion = new
|
|
1366
|
-
type:
|
|
1367
|
+
this._demodTex = this._makeStorageTex(), this._storageTexA = this._makeStorageTex(), this._storageTexB = this._makeStorageTex(), this._srcRegion = new ir(new Rr(0, 0), new Rr(0, 0)), this.outputTarget = new Cn(n, r, {
|
|
1368
|
+
type: pr,
|
|
1367
1369
|
format: Q,
|
|
1368
1370
|
minFilter: X,
|
|
1369
1371
|
magFilter: X,
|
|
@@ -1372,19 +1374,19 @@ var Ri = class extends oe {
|
|
|
1372
1374
|
}), this._compiled = !1, this._dispatchX = Math.ceil(n / 16), this._dispatchY = Math.ceil(r / 16), this._buildCompute();
|
|
1373
1375
|
}
|
|
1374
1376
|
_makeStorageTex() {
|
|
1375
|
-
let e = new
|
|
1376
|
-
return e.type =
|
|
1377
|
+
let e = new wn(A, A);
|
|
1378
|
+
return e.type = pr, e.format = Q, e.minFilter = X, e.magFilter = X, e;
|
|
1377
1379
|
}
|
|
1378
1380
|
_buildCompute() {
|
|
1379
1381
|
this._computeDemod = this._buildDemod(), this._computeAtrousA = this._buildAtrous(this._storageTexA), this._computeAtrousB = this._buildAtrous(this._storageTexB);
|
|
1380
1382
|
}
|
|
1381
1383
|
_buildDemod() {
|
|
1382
1384
|
let e = this._colorTexNode, t = this._ndTexNode, n = this._albedoTexNode, r = this._demodTex, i = this.resW, a = this.resH;
|
|
1383
|
-
return
|
|
1385
|
+
return En(() => {
|
|
1384
1386
|
let o = F(Y.x).mul(16).add(F(L.x)), s = F(Y.y).mul(16).add(F(L.y));
|
|
1385
1387
|
N(o.lessThan(F(i)).and(s.lessThan(F(a))), () => {
|
|
1386
|
-
let i = I(o, s), a = H(e, i).xyz, c = H(t, i).w.lessThan(P(
|
|
1387
|
-
U(r,
|
|
1388
|
+
let i = I(o, s), a = H(e, i).xyz, c = H(t, i).w.lessThan(P(Yi)), l = H(n, i).xyz, u = V(c, R(l, q(Kr)), q(1)), d = Zi(a.div(u));
|
|
1389
|
+
U(r, Xn(W(o), W(s)), J(d, 1)).toWriteOnly();
|
|
1388
1390
|
});
|
|
1389
1391
|
})().compute([
|
|
1390
1392
|
this._dispatchX,
|
|
@@ -1398,19 +1400,19 @@ var Ri = class extends oe {
|
|
|
1398
1400
|
}
|
|
1399
1401
|
_buildAtrous(e) {
|
|
1400
1402
|
let t = this._readTexNode, n = this._colorTexNode, r = this._ndTexNode, i = this._snTexNode, a = this._albedoTexNode, s = this._varTexNode, c = this.filterStrength, l = this.phiLuminance, u = this.phiNormal, d = this.phiDepth, f = this.stepSizeU, p = this.isLastIterationU, m = this.isFirstIterationU, h = this.varianceHistoryU, g = this.resW, _ = this.resH;
|
|
1401
|
-
return
|
|
1403
|
+
return En(() => {
|
|
1402
1404
|
let v = F(Y.x).mul(16).add(F(L.x)), y = F(Y.y).mul(16).add(F(L.y));
|
|
1403
1405
|
N(v.lessThan(F(g)).and(y.lessThan(F(_))), () => {
|
|
1404
|
-
let b = I(v, y), x = H(t, b), S = x.xyz, ee = o(S), C = H(r, b).w,
|
|
1406
|
+
let b = I(v, y), x = H(t, b), S = x.xyz, ee = o(S), C = H(r, b).w, w = H(i, b).xyz.mul(2).sub(1), T = C.lessThan(P(Yi)), E = V(T, P(1), P(0)), te = H(a, b).xyz, D = V(T, R(te, q(Kr)), q(1)), ne = R(o(D), P(Kr)), re = m.equal(F(1)), ie = h.lessThan(F(Qi)), ae = (e) => {
|
|
1405
1407
|
let t = H(s, e);
|
|
1406
|
-
return V(
|
|
1407
|
-
},
|
|
1408
|
+
return V(ie, R(t.z, t.w), t.z);
|
|
1409
|
+
}, O = re.select(ae(b), x.w.mul(x.w)).toVar(), k = l.mul(qn(R(O, P(0)))).div(ne).add(P(1e-4)), oe = q(0).toVar(), se = P(0).toVar(), A = P(0).toVar();
|
|
1408
1410
|
for (let e = 0; e < 5; e++) for (let n = 0; n < 5; n++) {
|
|
1409
|
-
let a = n - 2, s = e - 2, c =
|
|
1410
|
-
|
|
1411
|
+
let a = n - 2, s = e - 2, c = $i[e * 5 + n], l = I(v.add(f.mul(a)).clamp(F(0), F(g).sub(1)), y.add(f.mul(s)).clamp(F(0), F(_).sub(1))), p = H(t, l), m = p.xyz, h = o(m), b = H(r, l).w, x = H(i, l).xyz.mul(2).sub(1), S = V(b.lessThan(P(Yi)), P(1), P(0)), T = ee.sub(h).abs().div(k).negate().exp(), te = Wn(Fn(w, x).clamp(0, 1), u), D = C.sub(b).abs().div(R(C.mul(d), P(.001))).negate().exp(), ne = E.mul(S), ie = E.oneMinus().mul(S.oneMinus()), O = ne.add(ie), ce = z(P(1), te.mul(D), ne), le = P(c).mul(T).mul(ce).mul(O), ue = re.select(ae(l), p.w.mul(p.w));
|
|
1412
|
+
oe.addAssign(m.mul(le)), se.addAssign(le), A.addAssign(le.mul(le).mul(R(ue, P(0))));
|
|
1411
1413
|
}
|
|
1412
|
-
let
|
|
1413
|
-
U(e,
|
|
1414
|
+
let ce = oe.div(R(se, P(1e-4))), le = A.div(R(se.mul(se), P(1e-8))), ue = p.equal(F(1)), de = H(n, b).xyz, fe = z(de, ce.mul(D), c), pe = ue.select(fe, ce), me = ue.select(H(n, b).w, qn(R(le, P(0))));
|
|
1415
|
+
U(e, Xn(W(v), W(y)), J(pe, me)).toWriteOnly();
|
|
1414
1416
|
});
|
|
1415
1417
|
})().compute([
|
|
1416
1418
|
this._dispatchX,
|
|
@@ -1468,183 +1470,597 @@ var Ri = class extends oe {
|
|
|
1468
1470
|
dispose() {
|
|
1469
1471
|
this._computeDemod?.dispose(), this._computeAtrousA?.dispose(), this._computeAtrousB?.dispose(), this._demodTex?.dispose(), this._storageTexA?.dispose(), this._storageTexB?.dispose(), this.outputTarget?.dispose(), this._colorTexNode?.dispose(), this._ndTexNode?.dispose(), this._snTexNode?.dispose(), this._albedoTexNode?.dispose(), this._varTexNode?.dispose(), this._readTexNode?.dispose();
|
|
1470
1472
|
}
|
|
1471
|
-
},
|
|
1473
|
+
}, ta = {
|
|
1472
1474
|
autoExposure: !1,
|
|
1475
|
+
autoExposureMetering: "center",
|
|
1476
|
+
autoExposureStrength: .3,
|
|
1473
1477
|
autoExposureKeyValue: .18,
|
|
1474
|
-
autoExposureMinExposure:
|
|
1475
|
-
autoExposureMaxExposure:
|
|
1478
|
+
autoExposureMinExposure: 2 ** -8,
|
|
1479
|
+
autoExposureMaxExposure: 2 ** 8,
|
|
1476
1480
|
autoExposureAdaptSpeedBright: 3,
|
|
1477
|
-
autoExposureAdaptSpeedDark:
|
|
1478
|
-
},
|
|
1481
|
+
autoExposureAdaptSpeedDark: 1
|
|
1482
|
+
}, na = [
|
|
1483
|
+
"average",
|
|
1484
|
+
"center",
|
|
1485
|
+
"spot"
|
|
1486
|
+
], ra = 64, ia = 8, aa = 8, oa = 256, sa = -16, ca = (12 - sa) / oa, la = 2 ** -24, ua = 65536, da = 256, fa = 128, pa = 1.5, ma = .01, ha = .06, ga = .25, _a = 4, va = .3, ya = 1.5, ba = 3, xa = [
|
|
1487
|
+
.2126,
|
|
1488
|
+
.7152,
|
|
1489
|
+
.0722
|
|
1490
|
+
];
|
|
1491
|
+
function Sa(e, t, n, r, i) {
|
|
1492
|
+
let a = t - e;
|
|
1493
|
+
if (a === 0 || !(n > 0)) return e;
|
|
1494
|
+
let o = Math.max(a < 0 ? r : i, .001);
|
|
1495
|
+
if (n === Infinity) return t;
|
|
1496
|
+
let s = Math.min(o * n, Math.abs(a) * (1 - Math.exp(-o * n / pa)));
|
|
1497
|
+
return e + Math.sign(a) * s;
|
|
1498
|
+
}
|
|
1499
|
+
function Ca(e, t, n) {
|
|
1500
|
+
let r = Math.abs(e);
|
|
1501
|
+
return e * (r <= ya ? n : r >= ba ? 1 : n + (1 - n) * (r - ya) / (ba - ya)) + n * (t - e);
|
|
1502
|
+
}
|
|
1503
|
+
function wa(e, t) {
|
|
1504
|
+
if (!e) return t.fromArray(xa);
|
|
1505
|
+
let n = new yr().set(...e).invert().elements;
|
|
1506
|
+
return t.set(xa[0] * n[0] + xa[1] * n[1] + xa[2] * n[2], xa[0] * n[3] + xa[1] * n[4] + xa[2] * n[5], xa[0] * n[6] + xa[1] * n[7] + xa[2] * n[8]);
|
|
1507
|
+
}
|
|
1508
|
+
var Ta = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ea = class extends O {
|
|
1479
1509
|
constructor(e, t = {}) {
|
|
1480
1510
|
super("AutoExposure", {
|
|
1481
1511
|
...t,
|
|
1482
|
-
executionMode:
|
|
1483
|
-
}), this.renderer = e, this.
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1512
|
+
executionMode: ge.ALWAYS
|
|
1513
|
+
}), this.renderer = e, this.metering = t.metering ?? ta.autoExposureMetering, this.meteringPoint = new Rr(.5, .5), this.keyValue = t.keyValue ?? ta.autoExposureKeyValue, this.minExposure = t.minExposure ?? ta.autoExposureMinExposure, this.maxExposure = t.maxExposure ?? ta.autoExposureMaxExposure, this.adaptSpeedBright = t.adaptSpeedBright ?? ta.autoExposureAdaptSpeedBright, this.adaptSpeedDark = t.adaptSpeedDark ?? ta.autoExposureAdaptSpeedDark, this.centerWeight = t.centerWeight ?? 8, this.strength = t.strength ?? ta.autoExposureStrength, this.instant = !1, this.holdSamples = 0, this.onChange = null, this._lowU = G(t.lowPercentile ?? .1), this._highU = G(t.highPercentile ?? .9), this._falloffU = G(new Rr()), this._pointU = G(new Rr(.5, .5)), this._lumWeightsU = G(new $().fromArray(xa)), this._widthU = G(1, "int"), this._heightU = G(1, "int"), this._strideU = G(1, "int"), this._gridXU = G(ra, "int"), this._gridYU = G(ra, "int"), this._inputNode = new M(), this._workingMatrix = void 0, this._histogram = Pn(oa, "uint").toAtomic(), this._result = Pn(1, "vec4"), this._readback = new Sn(16), this._readback.name = "AutoExposure", this._kernels = [this._buildTileKernel(), this._buildResolveKernel()], this._compensation = 1, this._exposureEV = 0, this._targetEV = null, this._viewEV = null, this._roomEV = null, this._clock = 0, this._movingUntil = -1, this._viewMoves = 0, this._landed = null, this._meteredLog2 = null, this._snap = !0, this._lastUpdate = null, this._accumulating = !1, this._emittedEV = null, this._pending = null, this._generation = 0, this._restarts = 0, this._meteredAt = {
|
|
1514
|
+
restarts: -1,
|
|
1515
|
+
samples: -1
|
|
1516
|
+
}, this._stale = !1, this._disposed = !1;
|
|
1517
|
+
}
|
|
1518
|
+
_buildTileKernel() {
|
|
1519
|
+
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;
|
|
1520
|
+
return En(() => {
|
|
1521
|
+
let u = L.y.mul(W(aa)).add(L.x), d = F(Y.x), f = F(Y.y), p = d.mul(n).div(a).toVar(), m = d.add(F(1)).mul(n).div(a).toVar(), h = f.mul(r).div(o).toVar(), g = f.add(F(1)).mul(r).div(o).toVar(), _ = i.mul(F(aa)), v = P(0).toVar(), y = P(0).toVar();
|
|
1522
|
+
Dn({
|
|
1523
|
+
start: h.add(F(L.y)),
|
|
1524
|
+
end: g,
|
|
1525
|
+
type: "int",
|
|
1526
|
+
condition: "<",
|
|
1527
|
+
update: _,
|
|
1528
|
+
name: "py"
|
|
1529
|
+
}, ({ py: t }) => {
|
|
1530
|
+
Dn({
|
|
1531
|
+
start: p.add(F(L.x)),
|
|
1532
|
+
end: m,
|
|
1533
|
+
type: "int",
|
|
1534
|
+
condition: "<",
|
|
1535
|
+
update: _,
|
|
1536
|
+
name: "px"
|
|
1537
|
+
}, ({ px: n }) => {
|
|
1538
|
+
let r = H(e, I(n, t)), i = Fn(r.xyz, s).toVar(), a = Rn(i).bitAnd(W(2139095040)).notEqual(W(2139095040)), o = r.w.clamp(0, 1);
|
|
1539
|
+
v.addAssign(V(a, i.clamp(0, 1e6), P(0)).mul(o)), y.addAssign(o);
|
|
1507
1540
|
});
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1541
|
+
});
|
|
1542
|
+
let b = $n("float", aa * aa), x = $n("float", aa * aa);
|
|
1543
|
+
b.element(u).assign(v), x.element(u).assign(y), er();
|
|
1544
|
+
for (let e = aa * aa >> 1; e > 0; e >>= 1) N(u.lessThan(W(e)), () => {
|
|
1545
|
+
b.element(u).addAssign(b.element(u.add(W(e)))), x.element(u).addAssign(x.element(u.add(W(e))));
|
|
1546
|
+
}), er();
|
|
1547
|
+
N(u.equal(W(0)), () => {
|
|
1548
|
+
let e = b.element(W(0)).toVar(), i = x.element(W(0)).toVar(), a = (e) => e.div(_).mul(F(aa)).add(Hn(e.mod(_), F(aa))), o = P(a(m.sub(p)).mul(a(g.sub(h))));
|
|
1549
|
+
N(i.greaterThan(0).and(e.greaterThan(i.mul(la))), () => {
|
|
1550
|
+
let a = W(Vn(e.div(i)).sub(sa).div(ca).floor().clamp(0, oa - 1)), s = K(P(p.add(m)).div(P(n)), P(h.add(g)).div(P(r))).mul(.5).sub(l), u = W(In(Fn(s.mul(s), c).negate()).mul(i.div(R(o, 1))).mul(ua).add(.5));
|
|
1551
|
+
N(u.greaterThan(W(0)), () => {
|
|
1552
|
+
jn(t.element(a), u);
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
});
|
|
1510
1556
|
})().compute([
|
|
1511
|
-
|
|
1512
|
-
|
|
1557
|
+
ra,
|
|
1558
|
+
ra,
|
|
1513
1559
|
1
|
|
1514
1560
|
], [
|
|
1515
|
-
|
|
1516
|
-
|
|
1561
|
+
aa,
|
|
1562
|
+
aa,
|
|
1517
1563
|
1
|
|
1518
1564
|
]);
|
|
1519
1565
|
}
|
|
1520
|
-
|
|
1521
|
-
let e = this.
|
|
1522
|
-
|
|
1523
|
-
let
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1566
|
+
_buildResolveKernel() {
|
|
1567
|
+
let e = this._histogram, t = this._result, n = this._lowU, r = this._highU;
|
|
1568
|
+
return En(() => {
|
|
1569
|
+
let i = L.x, a = P(Mn(e.element(i))).toVar();
|
|
1570
|
+
Nn(e.element(i), W(0));
|
|
1571
|
+
let o = $n("float", oa), s = $n("float", oa);
|
|
1572
|
+
o.element(i).assign(a), er();
|
|
1573
|
+
for (let e = 1; e < oa; e <<= 1) {
|
|
1574
|
+
let t = o.element(i).toVar();
|
|
1575
|
+
N(i.greaterThanEqual(W(e)), () => {
|
|
1576
|
+
t.addAssign(o.element(i.sub(W(e))));
|
|
1577
|
+
}), er(), o.element(i).assign(t), er();
|
|
1531
1578
|
}
|
|
1579
|
+
let c = o.element(W(oa - 1)).toVar(), l = o.element(i).toVar();
|
|
1580
|
+
er();
|
|
1581
|
+
let u = R(Hn(l, c.mul(r)).sub(R(l.sub(a), c.mul(n))), 0);
|
|
1582
|
+
o.element(i).assign(u), s.element(i).assign(u.mul(P(i).add(.5).mul(ca).add(sa))), er();
|
|
1583
|
+
for (let e = oa >> 1; e > 0; e >>= 1) N(i.lessThan(W(e)), () => {
|
|
1584
|
+
o.element(i).addAssign(o.element(i.add(W(e)))), s.element(i).addAssign(s.element(i.add(W(e))));
|
|
1585
|
+
}), er();
|
|
1586
|
+
N(i.equal(W(0)), () => {
|
|
1587
|
+
let e = o.element(W(0));
|
|
1588
|
+
t.element(W(0)).assign(J(s.element(W(0)).div(R(e, 1e-6)), c.div(ua), e.div(ua), 1));
|
|
1589
|
+
});
|
|
1532
1590
|
})().compute([
|
|
1533
1591
|
1,
|
|
1534
1592
|
1,
|
|
1535
1593
|
1
|
|
1536
1594
|
], [
|
|
1537
|
-
|
|
1595
|
+
oa,
|
|
1538
1596
|
1,
|
|
1539
1597
|
1
|
|
1540
1598
|
]);
|
|
1541
1599
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1600
|
+
setupEventListeners() {
|
|
1601
|
+
this.on("pipeline:reset", () => this._restarts++), this.on("pipeline:lightingChanged", () => this.resetHistory());
|
|
1602
|
+
}
|
|
1603
|
+
render(e) {
|
|
1604
|
+
if (!this.enabled) return;
|
|
1605
|
+
let t = e.getState("pathtracer:samples") ?? 0;
|
|
1606
|
+
if (this._accumulating = t >= 2, !this._pending) {
|
|
1607
|
+
let n = this._meteredAt, r = this._stale || this._targetEV === null || n.restarts !== this._restarts || t - n.samples >= Ta(t), i = t < this.holdSamples && this._targetEV !== null && !this._stale;
|
|
1608
|
+
r && !i && this._meter(e, t);
|
|
1609
|
+
}
|
|
1610
|
+
e.setState("autoexposure:value", this.renderer.toneMappingExposure), e.setState("autoexposure:avgLuminance", this.luminance);
|
|
1611
|
+
}
|
|
1612
|
+
async meter(e = this.context) {
|
|
1613
|
+
for (; this._pending;) await this._pending;
|
|
1614
|
+
let t = this._meter(e, e?.getState("pathtracer:samples") ?? 0);
|
|
1615
|
+
return t ? await t : null;
|
|
1616
|
+
}
|
|
1617
|
+
_meter(e, t) {
|
|
1618
|
+
let n = e?.getTexture("pathtracer:color"), r = n?.image?.width | 0, i = n?.image?.height | 0;
|
|
1619
|
+
if (!n || r < 1 || i < 1 || this._disposed) return null;
|
|
1620
|
+
this._meteredAt.restarts = this._restarts, this._meteredAt.samples = t, this._stale = !1;
|
|
1621
|
+
let a = nt();
|
|
1622
|
+
a !== this._workingMatrix && (this._workingMatrix = a, wa(a, this._lumWeightsU.value));
|
|
1623
|
+
let o = Math.min(ra, Math.max(1, Math.floor(r / ia))), s = Math.min(ra, Math.max(1, Math.floor(i / ia))), c = r / o * (i / s);
|
|
1624
|
+
this._gridXU.value = o, this._gridYU.value = s, this._kernels[0].dispatchSize = [
|
|
1625
|
+
o,
|
|
1626
|
+
s,
|
|
1627
|
+
1
|
|
1628
|
+
], this._strideU.value = Math.max(1, Math.round(Math.sqrt(c / da))), this._widthU.value = r, this._heightU.value = i, this._updateMeteringPattern(r / i), this._inputNode.value = n, this.renderer.compute(this._kernels);
|
|
1629
|
+
let l = this._generation, u = {
|
|
1630
|
+
restarts: this._restarts,
|
|
1631
|
+
moves: this._viewMoves
|
|
1632
|
+
}, d = this.renderer.getArrayBufferAsync(this._result.value, this._readback).then((e) => {
|
|
1633
|
+
let t = e?.buffer ? new Float32Array(e.buffer.slice(0, 16)) : null;
|
|
1634
|
+
return this._readback.release(), t && l === this._generation && !this._disposed ? this._applyMetering(t, u) : null;
|
|
1635
|
+
}, () => (!this._disposed && this._readback._mapped && this._readback.release(), null)).finally(() => {
|
|
1636
|
+
this._pending === d && (this._pending = null);
|
|
1637
|
+
});
|
|
1638
|
+
return this._pending = d, d;
|
|
1639
|
+
}
|
|
1640
|
+
_updateMeteringPattern(e) {
|
|
1641
|
+
let t = this._falloffU.value, n = this._pointU.value;
|
|
1642
|
+
if (this.metering === "average") t.set(0, 0);
|
|
1643
|
+
else if (this.metering === "spot") {
|
|
1644
|
+
t.set(fa * e * e, fa), n.copy(this.meteringPoint);
|
|
1645
|
+
return;
|
|
1646
|
+
} else t.set(this.centerWeight, this.centerWeight);
|
|
1647
|
+
n.set(.5, .5);
|
|
1648
|
+
}
|
|
1649
|
+
_applyMetering(e, t = this._landed) {
|
|
1650
|
+
let [n, r, i] = e;
|
|
1651
|
+
if (!this.enabled || !(r > 0 && i > 0) || !Number.isFinite(n)) return null;
|
|
1652
|
+
let a = this._viewEV;
|
|
1653
|
+
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 + va, this._landed = t;
|
|
1654
|
+
let o = this._aim(), s = this._targetEV === null || Math.abs(o - this._targetEV) > ma;
|
|
1655
|
+
return this._targetEV = o, (s || this.settling) && this.onChange?.(), n;
|
|
1656
|
+
}
|
|
1657
|
+
update(e = performance.now()) {
|
|
1658
|
+
let t = this._lastUpdate === null ? 0 : Math.min((e - this._lastUpdate) / 1e3, ga), n = this.advance(t, this._accumulating);
|
|
1659
|
+
return this._lastUpdate = this.settling || this._clock <= this._movingUntil ? e : null, n;
|
|
1660
|
+
}
|
|
1661
|
+
advance(e, t = !1) {
|
|
1662
|
+
if (!this.enabled || this._targetEV === null) return !1;
|
|
1663
|
+
e > 0 && e !== Infinity && (this._clock += e, this._clock <= this._movingUntil && (this._roomEV += (this._viewEV - this._roomEV) * (1 - Math.exp(-Math.min(e, ga) / _a)), this._targetEV = this._aim()));
|
|
1664
|
+
let n = this._exposureEV;
|
|
1665
|
+
return this._snap || this.instant ? (this._exposureEV = this._targetEV, this._snap = !1) : (this._exposureEV = t ? n + (this._targetEV - n) * (1 - Math.exp(-e / ha)) : Sa(n, this._targetEV, e, this.adaptSpeedBright, this.adaptSpeedDark), Math.abs(this._targetEV - this._exposureEV) <= ma && (this._exposureEV = this._targetEV)), this._exposureEV === n ? !1 : (this._apply(), !0);
|
|
1666
|
+
}
|
|
1667
|
+
_inRange(e) {
|
|
1668
|
+
return Math.min(Math.max(e, Math.log2(this.minExposure)), Math.log2(this.maxExposure));
|
|
1669
|
+
}
|
|
1670
|
+
_aim() {
|
|
1671
|
+
return this._inRange(Ca(this._roomEV, this._viewEV, this.strength));
|
|
1672
|
+
}
|
|
1673
|
+
noteViewChanged() {
|
|
1674
|
+
this._viewMoves++;
|
|
1675
|
+
}
|
|
1676
|
+
get settling() {
|
|
1677
|
+
return this.enabled && this._targetEV !== null && (this._snap || Math.abs(this._targetEV - this._exposureEV) > 0);
|
|
1678
|
+
}
|
|
1679
|
+
get wantsMetering() {
|
|
1680
|
+
return this.enabled && !this._pending && (this._stale || this._targetEV === null);
|
|
1681
|
+
}
|
|
1682
|
+
_apply() {
|
|
1683
|
+
this.renderer.toneMappingExposure = this.enabled ? 2 ** this._exposureEV * this._compensation : this._compensation, !(!this.enabled || this._emittedEV !== null && Math.abs(this._exposureEV - this._emittedEV) < .005) && (this._emittedEV = this._exposureEV, this.emit("autoexposure:updated", {
|
|
1684
|
+
exposure: this.renderer.toneMappingExposure,
|
|
1685
|
+
autoExposure: this.getExposure(),
|
|
1686
|
+
targetExposure: this._targetEV === null ? null : 2 ** this._targetEV,
|
|
1687
|
+
luminance: this.luminance
|
|
1688
|
+
}));
|
|
1689
|
+
}
|
|
1690
|
+
setEnabled(e, t = this._compensation) {
|
|
1691
|
+
if (this._compensation = t, e === this.enabled) {
|
|
1692
|
+
this._apply();
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
this.enabled = e, this._emittedEV = null, e && (this.resetHistory(), this._exposureEV = 0), this._apply(), this.onChange?.();
|
|
1696
|
+
}
|
|
1697
|
+
setCompensation(e) {
|
|
1698
|
+
this._compensation = e, this._apply();
|
|
1699
|
+
}
|
|
1700
|
+
resetHistory() {
|
|
1701
|
+
this._generation++, this._targetEV = null, this._viewEV = null, this._roomEV = null, this._landed = null, this._meteredLog2 = null, this._snap = !0;
|
|
1702
|
+
}
|
|
1703
|
+
getExposure() {
|
|
1704
|
+
return 2 ** this._exposureEV;
|
|
1705
|
+
}
|
|
1706
|
+
get luminance() {
|
|
1707
|
+
return this._meteredLog2 === null ? null : 2 ** this._meteredLog2;
|
|
1708
|
+
}
|
|
1709
|
+
getLuminance() {
|
|
1710
|
+
return this.luminance;
|
|
1711
|
+
}
|
|
1712
|
+
updateParameters(e) {
|
|
1713
|
+
let t = e.metering;
|
|
1714
|
+
t !== void 0 && na.includes(t) && (this.metering = t), e.meteringPoint && this.meteringPoint.set(e.meteringPoint.x, e.meteringPoint.y);
|
|
1715
|
+
for (let t of [
|
|
1716
|
+
"keyValue",
|
|
1717
|
+
"minExposure",
|
|
1718
|
+
"maxExposure",
|
|
1719
|
+
"adaptSpeedBright",
|
|
1720
|
+
"adaptSpeedDark",
|
|
1721
|
+
"centerWeight",
|
|
1722
|
+
"strength"
|
|
1723
|
+
]) e[t] !== void 0 && (this[t] = e[t]);
|
|
1724
|
+
e.lowPercentile !== void 0 && (this._lowU.value = e.lowPercentile), e.highPercentile !== void 0 && (this._highU.value = e.highPercentile), this._stale = !0, this._meteredLog2 !== null && this._applyMetering([
|
|
1725
|
+
this._meteredLog2,
|
|
1726
|
+
1,
|
|
1727
|
+
1
|
|
1728
|
+
]), this.onChange?.();
|
|
1729
|
+
}
|
|
1730
|
+
reset() {}
|
|
1731
|
+
setSize() {}
|
|
1732
|
+
dispose() {
|
|
1733
|
+
this._disposed = !0, this.onChange = null;
|
|
1734
|
+
for (let e of this._kernels) e.dispose();
|
|
1735
|
+
this._readback.dispose(), this._inputNode.dispose();
|
|
1736
|
+
}
|
|
1737
|
+
}, Da = {
|
|
1738
|
+
localExposure: !1,
|
|
1739
|
+
localExposureHighlightContrast: .6,
|
|
1740
|
+
localExposureShadowContrast: 1,
|
|
1741
|
+
localExposureDetailStrength: 1
|
|
1742
|
+
}, Oa = 128, ka = (Oa / 2) ** 2, Aa = 32, ja = -16, Ma = 16, Na = -40, Pa = 40, Fa = 256, Ia = 32, La = .6, Ra = 50, za = Math.log2(.18), Ba = 2 ** -24, Va = Math.ceil(Se / Oa), Ha = Math.ceil(Se / Ia), Ua = [
|
|
1743
|
+
.2126,
|
|
1744
|
+
.7152,
|
|
1745
|
+
.0722
|
|
1746
|
+
], Wa = (e) => e < 16 ? 1 : e < 64 ? 4 : 16, Ga = (e, t, n) => Math.min(Math.max(e, t), n);
|
|
1747
|
+
function Ka(e, t, n, r, i, a, o) {
|
|
1748
|
+
let s = Math.min(Math.log2(Math.max(a, Ba)), Pa), c = e[6], l = e[7], u = Ga(r * e[2] - .5, 0, c - 1), d = Ga(i * e[3] - .5, 0, l - 1), f = Math.floor(u), p = Math.floor(d), m = Math.min(f + 1, c - 1), h = Math.min(p + 1, l - 1), g = u - f, _ = d - p, v = (e) => n[e * c + f] + (n[e * c + m] - n[e * c + f]) * g, y = v(p) + (v(h) - v(p)) * _, b = e[4], x = e[5], S = Ga(r * e[0] - .5, 0, b - 1), ee = Ga(i * e[1] - .5, 0, x - 1), C = Ga((s + e[8] - ja) / (Ma - ja), 0, 1) * (Aa - 1), w = Math.floor(S), T = Math.floor(ee), E = Math.floor(C), te = S - w, D = ee - T, ne = C - E, re = 0, ie = 0;
|
|
1749
|
+
for (let e = 0; e < 8; e++) {
|
|
1750
|
+
let n = e & 1, r = e >> 1 & 1, i = e >> 2, a = (n ? te : 1 - te) * (r ? D : 1 - D) * (i ? ne : 1 - ne), o = ((Math.min(T + r, x - 1) * b + Math.min(w + n, b - 1)) * Aa + Math.min(E + i, Aa - 1)) * 2;
|
|
1751
|
+
re += t[o] * a, ie += t[o + 1] * a;
|
|
1752
|
+
}
|
|
1753
|
+
let ae = ie * ka < .001 ? y : re / ie, O = ae + (y - ae) * e[12] + o, k = s + o, oe = O > e[13] ? e[9] : e[10];
|
|
1754
|
+
return 2 ** (e[13] + (O - e[13]) * oe + (k - O) * e[11] - k);
|
|
1755
|
+
}
|
|
1756
|
+
var qa = `
|
|
1757
|
+
@group(1) @binding(0) var<storage, read> leGrid: array<vec2<f32>>;
|
|
1758
|
+
@group(1) @binding(1) var<storage, read> leBlur: array<f32>;
|
|
1759
|
+
@group(1) @binding(2) var<uniform> le: array<vec4<f32>, 4>;
|
|
1760
|
+
|
|
1761
|
+
fn rayzee_gain( uv: vec2<f32>, linear: vec3<f32>, exposure: f32 ) -> f32 {
|
|
1762
|
+
let logL = min( log2( max( dot( linear, vec3<f32>( ${Ua.join(", ")} ) ), ${Ba} ) ), ${Pa}.0 );
|
|
1763
|
+
let logExposure = log2( exposure );
|
|
1764
|
+
|
|
1765
|
+
let bs = vec2<i32>( le[ 1 ].zw );
|
|
1766
|
+
let bp = clamp( uv * le[ 0 ].zw - 0.5, vec2<f32>( 0.0 ), vec2<f32>( bs - 1 ) );
|
|
1767
|
+
let b0 = vec2<i32>( floor( bp ) );
|
|
1768
|
+
let b1 = min( b0 + 1, bs - 1 );
|
|
1769
|
+
let bf = bp - floor( bp );
|
|
1770
|
+
let top = mix( leBlur[ b0.y * bs.x + b0.x ], leBlur[ b0.y * bs.x + b1.x ], bf.x );
|
|
1771
|
+
let bottom = mix( leBlur[ b1.y * bs.x + b0.x ], leBlur[ b1.y * bs.x + b1.x ], bf.x );
|
|
1772
|
+
let blurred = mix( top, bottom, bf.y );
|
|
1773
|
+
|
|
1774
|
+
let cs = vec2<i32>( le[ 1 ].xy );
|
|
1775
|
+
let gp = clamp( uv * le[ 0 ].xy - 0.5, vec2<f32>( 0.0 ), vec2<f32>( cs - 1 ) );
|
|
1776
|
+
let gz = clamp( ( logL + le[ 2 ].x - (${ja}.0) ) / ${Ma - ja}.0, 0.0, 1.0 ) * ${Aa - 1}.0;
|
|
1777
|
+
let g0 = vec3<i32>( vec2<i32>( floor( gp ) ), i32( floor( gz ) ) );
|
|
1778
|
+
let gf = vec3<f32>( gp - floor( gp ), gz - floor( gz ) );
|
|
1779
|
+
var acc = vec2<f32>( 0.0 );
|
|
1780
|
+
for ( var k = 0; k < 8; k++ ) {
|
|
1781
|
+
let d = vec3<i32>( k & 1, ( k >> 1u ) & 1, k >> 2u );
|
|
1782
|
+
let wv = select( 1.0 - gf, gf, d == vec3<i32>( 1 ) );
|
|
1783
|
+
let c = min( g0 + d, vec3<i32>( cs - 1, ${Aa - 1} ) );
|
|
1784
|
+
acc += leGrid[ ( c.y * cs.x + c.x ) * ${Aa} + c.z ] * ( wv.x * wv.y * wv.z );
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
let bilateral = select( acc.x / acc.y, blurred, acc.y * ${ka}.0 < 1e-3 );
|
|
1788
|
+
let base = mix( bilateral, blurred, le[ 3 ].x ) + logExposure;
|
|
1789
|
+
let y = logL + logExposure;
|
|
1790
|
+
let contrast = select( le[ 2 ].z, le[ 2 ].y, base > le[ 3 ].y );
|
|
1791
|
+
return exp2( le[ 3 ].y + ( base - le[ 3 ].y ) * contrast + ( y - base ) * le[ 2 ].w - y );
|
|
1792
|
+
}
|
|
1793
|
+
`, Ja = class extends O {
|
|
1794
|
+
constructor(e, t = {}) {
|
|
1795
|
+
super("LocalExposure", {
|
|
1796
|
+
...t,
|
|
1797
|
+
executionMode: ge.ALWAYS
|
|
1798
|
+
}), this.renderer = e, this.highlightContrast = t.highlightContrast ?? Da.localExposureHighlightContrast, this.shadowContrast = t.shadowContrast ?? Da.localExposureShadowContrast, this.detailStrength = t.detailStrength ?? Da.localExposureDetailStrength, this.onChange = null, this._grid = Pn(Va * Va * Aa, "vec2"), this._blur = Pn(Ha * Ha, "float"), this._blurTmp = Pn(Ha * Ha, "float"), this._inputNode = new M(), this._widthU = G(1, "int"), this._heightU = G(1, "int"), this._cellsXU = G(1, "int"), this._blurWU = G(1, "int"), this._blurHU = G(1, "int"), this._radiusU = G(1), this._logExposureU = G(0), this._p = [
|
|
1799
|
+
new zr(),
|
|
1800
|
+
new zr(),
|
|
1801
|
+
new zr(),
|
|
1802
|
+
new zr()
|
|
1803
|
+
].map((e) => G(e)), this._params = new Float32Array(16), this._kernels = [
|
|
1804
|
+
this._buildGridKernel(),
|
|
1805
|
+
this._buildBlurSourceKernel(),
|
|
1806
|
+
this._buildBlurKernel(this._blur, this._blurTmp, !0),
|
|
1807
|
+
this._buildBlurKernel(this._blurTmp, this._blur, !1)
|
|
1808
|
+
], this._built = !1, this._restarts = 0, this._builtAt = {
|
|
1809
|
+
restarts: -1,
|
|
1810
|
+
samples: -1
|
|
1811
|
+
}, this._stale = !1, this._paramsBuffer = null, this._disposed = !1;
|
|
1812
|
+
}
|
|
1813
|
+
_buildGridKernel() {
|
|
1814
|
+
let e = this._inputNode, t = this._grid, n = this._widthU, r = this._heightU, i = this._cellsXU, a = this._logExposureU, o = J(...Ua, 0).xyz;
|
|
1815
|
+
return En(() => {
|
|
1816
|
+
let s = L.y.mul(W(16)).add(L.x), c = $n("uint", Aa).toAtomic(), l = $n("uint", Aa).toAtomic();
|
|
1817
|
+
N(s.lessThan(W(Aa)), () => {
|
|
1818
|
+
Nn(c.element(s), W(0)), Nn(l.element(s), W(0));
|
|
1819
|
+
}), er();
|
|
1820
|
+
let u = F(Y.x).mul(F(Oa)).add(F(L.x).mul(F(8))), d = F(Y.y).mul(F(Oa)).add(F(L.y).mul(F(8)));
|
|
1821
|
+
Dn({
|
|
1822
|
+
start: F(0),
|
|
1823
|
+
end: F(8),
|
|
1824
|
+
type: "int",
|
|
1825
|
+
condition: "<",
|
|
1826
|
+
update: 2,
|
|
1827
|
+
name: "ty"
|
|
1828
|
+
}, ({ ty: t }) => {
|
|
1829
|
+
Dn({
|
|
1830
|
+
start: F(0),
|
|
1831
|
+
end: F(8),
|
|
1832
|
+
type: "int",
|
|
1833
|
+
condition: "<",
|
|
1834
|
+
update: 2,
|
|
1835
|
+
name: "tx"
|
|
1836
|
+
}, ({ tx: i }) => {
|
|
1837
|
+
let s = u.add(i), f = d.add(t);
|
|
1838
|
+
N(s.lessThan(n).and(f.lessThan(r)), () => {
|
|
1839
|
+
let t = Hn(s.add(F(1)), n.sub(F(1))), i = Hn(f.add(F(1)), r.sub(F(1))), u = Fn(H(e, I(s, f)).xyz, o).add(Fn(H(e, I(t, f)).xyz, o)).add(Fn(H(e, I(s, i)).xyz, o)).add(Fn(H(e, I(t, i)).xyz, o)).mul(.25).toVar();
|
|
1840
|
+
N(Rn(u).bitAnd(W(2139095040)).notEqual(W(2139095040)), () => {
|
|
1841
|
+
let e = Vn(R(u, Ba)).clamp(Na, Pa).toVar(), t = e.add(a).sub(ja).div(Ma - ja).clamp(0, 1).mul(Aa - 1).toVar(), n = W(zn(t)).min(W(Aa - 1)), r = n.add(W(1)).min(W(Aa - 1)), i = t.sub(zn(t)), o = P(1).sub(i), s = e.sub(Na).mul(Fa);
|
|
1842
|
+
jn(c.element(n), W(s.mul(o).add(.5))), jn(l.element(n), W(o.mul(Fa).add(.5))), jn(c.element(r), W(s.mul(i).add(.5))), jn(l.element(r), W(i.mul(Fa).add(.5)));
|
|
1843
|
+
});
|
|
1844
|
+
});
|
|
1845
|
+
});
|
|
1846
|
+
}), er(), N(s.lessThan(W(Aa)), () => {
|
|
1847
|
+
let e = P(Mn(l.element(s))).div(Fa), n = P(Mn(c.element(s))).div(Fa).add(e.mul(Na)), r = W(Y.y).mul(W(i)).add(W(Y.x));
|
|
1848
|
+
t.element(r.mul(W(Aa)).add(s)).assign(K(n, e).div(ka));
|
|
1548
1849
|
});
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1850
|
+
})().compute([
|
|
1851
|
+
1,
|
|
1852
|
+
1,
|
|
1853
|
+
1
|
|
1854
|
+
], [
|
|
1855
|
+
16,
|
|
1856
|
+
16,
|
|
1857
|
+
1
|
|
1858
|
+
]);
|
|
1859
|
+
}
|
|
1860
|
+
_buildBlurSourceKernel() {
|
|
1861
|
+
let e = this._inputNode, t = this._blur, n = this._widthU, r = this._heightU, i = this._blurWU, a = J(...Ua, 0).xyz;
|
|
1862
|
+
return En(() => {
|
|
1863
|
+
let o = L.y.mul(W(8)).add(L.x), s = F(Y.x).mul(F(Ia)), c = F(Y.y).mul(F(Ia)), l = P(0).toVar(), u = P(0).toVar();
|
|
1864
|
+
Dn({
|
|
1865
|
+
start: F(L.y),
|
|
1866
|
+
end: F(Ia),
|
|
1867
|
+
type: "int",
|
|
1868
|
+
condition: "<",
|
|
1869
|
+
update: 8,
|
|
1870
|
+
name: "by"
|
|
1871
|
+
}, ({ by: t }) => {
|
|
1872
|
+
Dn({
|
|
1873
|
+
start: F(L.x),
|
|
1874
|
+
end: F(Ia),
|
|
1875
|
+
type: "int",
|
|
1876
|
+
condition: "<",
|
|
1877
|
+
update: 8,
|
|
1878
|
+
name: "bx"
|
|
1879
|
+
}, ({ bx: i }) => {
|
|
1880
|
+
let o = s.add(i), d = c.add(t);
|
|
1881
|
+
N(o.lessThan(n).and(d.lessThan(r)), () => {
|
|
1882
|
+
let t = Fn(H(e, I(o, d)).xyz, a).toVar(), n = Rn(t).bitAnd(W(2139095040)).notEqual(W(2139095040));
|
|
1883
|
+
l.addAssign(V(n, t.max(0), P(0))), u.addAssign(V(n, P(1), P(0)));
|
|
1884
|
+
});
|
|
1555
1885
|
});
|
|
1556
1886
|
});
|
|
1557
|
-
let d =
|
|
1558
|
-
|
|
1559
|
-
|
|
1887
|
+
let d = $n("float", 64), f = $n("float", 64);
|
|
1888
|
+
d.element(o).assign(l), f.element(o).assign(u), er();
|
|
1889
|
+
for (let e = 32; e > 0; e >>= 1) N(o.lessThan(W(e)), () => {
|
|
1890
|
+
d.element(o).addAssign(d.element(o.add(W(e)))), f.element(o).addAssign(f.element(o.add(W(e))));
|
|
1891
|
+
}), er();
|
|
1892
|
+
N(o.equal(W(0)), () => {
|
|
1893
|
+
let e = d.element(W(0)).div(R(f.element(W(0)), 1));
|
|
1894
|
+
t.element(W(F(Y.y).mul(i).add(F(Y.x)))).assign(Vn(R(e, Ba)).clamp(Na, Pa));
|
|
1895
|
+
});
|
|
1896
|
+
})().compute([
|
|
1560
1897
|
1,
|
|
1561
1898
|
1,
|
|
1562
1899
|
1
|
|
1900
|
+
], [
|
|
1901
|
+
8,
|
|
1902
|
+
8,
|
|
1903
|
+
1
|
|
1563
1904
|
]);
|
|
1564
1905
|
}
|
|
1565
|
-
|
|
1566
|
-
let
|
|
1567
|
-
|
|
1568
|
-
let
|
|
1569
|
-
|
|
1570
|
-
|
|
1906
|
+
_buildBlurKernel(e, t, n) {
|
|
1907
|
+
let r = this._blurWU, i = this._blurHU, a = this._radiusU;
|
|
1908
|
+
return En(() => {
|
|
1909
|
+
let o = F(Y.x).mul(F(8)).add(F(L.x)), s = F(Y.y).mul(F(8)).add(F(L.y));
|
|
1910
|
+
N(o.lessThan(r).and(s.lessThan(i)), () => {
|
|
1911
|
+
let c = n ? r : i, l = n ? o : s, u = F(a.ceil()), d = P(0).toVar(), f = P(0).toVar();
|
|
1912
|
+
Dn({
|
|
1913
|
+
start: u.negate(),
|
|
1914
|
+
end: u.add(F(1)),
|
|
1915
|
+
type: "int",
|
|
1916
|
+
condition: "<",
|
|
1917
|
+
name: "o"
|
|
1918
|
+
}, ({ o: t }) => {
|
|
1919
|
+
let i = P(t).div(a), u = In(i.mul(i).mul(-16.7)), p = c.mul(F(2)), m = l.add(t).mod(p).add(p).mod(p).toVar();
|
|
1920
|
+
N(m.greaterThanEqual(c), () => {
|
|
1921
|
+
m.assign(p.sub(m).sub(F(1)));
|
|
1922
|
+
});
|
|
1923
|
+
let h = n ? s.mul(r).add(m) : m.mul(r).add(o);
|
|
1924
|
+
d.addAssign(e.element(W(h)).mul(u)), f.addAssign(u);
|
|
1925
|
+
}), t.element(W(s.mul(r).add(o))).assign(d.div(f));
|
|
1926
|
+
});
|
|
1927
|
+
})().compute([
|
|
1571
1928
|
1,
|
|
1572
1929
|
1,
|
|
1573
1930
|
1
|
|
1931
|
+
], [
|
|
1932
|
+
8,
|
|
1933
|
+
8,
|
|
1934
|
+
1
|
|
1574
1935
|
]);
|
|
1575
1936
|
}
|
|
1576
1937
|
setupEventListeners() {
|
|
1577
|
-
this.on("pipeline:reset", () => this.
|
|
1938
|
+
this.on("pipeline:reset", () => this._restarts++);
|
|
1578
1939
|
}
|
|
1579
1940
|
render(e) {
|
|
1580
1941
|
if (!this.enabled) return;
|
|
1581
|
-
let t = e.
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
getLuminance() {
|
|
1622
|
-
return this.currentLuminance;
|
|
1942
|
+
let t = e.getState("pathtracer:samples") ?? 0, n = this._builtAt;
|
|
1943
|
+
(this._stale || !this._built || n.restarts !== this._restarts || t - n.samples >= Wa(t)) && this.build(e);
|
|
1944
|
+
}
|
|
1945
|
+
build(e = this.context) {
|
|
1946
|
+
let t = e?.getTexture("pathtracer:color"), n = t?.image?.width | 0, r = t?.image?.height | 0;
|
|
1947
|
+
if (!t || n < 1 || r < 1 || this._disposed) return !1;
|
|
1948
|
+
this._builtAt.restarts = this._restarts, this._builtAt.samples = e.getState("pathtracer:samples") ?? 0, this._stale = !1;
|
|
1949
|
+
let i = Math.min(Va, Math.ceil(n / Oa)), a = Math.min(Va, Math.ceil(r / Oa)), o = Math.min(Ha, Math.ceil(n / Ia)), s = Math.min(Ha, Math.ceil(r / Ia)), c = Math.log2(Math.max(this.renderer.toneMappingExposure, 1e-6));
|
|
1950
|
+
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, Ra / 100 * o), this._logExposureU.value = c, this._kernels[0].dispatchSize = [
|
|
1951
|
+
i,
|
|
1952
|
+
a,
|
|
1953
|
+
1
|
|
1954
|
+
], this._kernels[1].dispatchSize = [
|
|
1955
|
+
o,
|
|
1956
|
+
s,
|
|
1957
|
+
1
|
|
1958
|
+
], this._kernels[2].dispatchSize = this._kernels[3].dispatchSize = [
|
|
1959
|
+
Math.ceil(o / 8),
|
|
1960
|
+
Math.ceil(s / 8),
|
|
1961
|
+
1
|
|
1962
|
+
], this.renderer.compute(this._kernels), this._params.set([
|
|
1963
|
+
n / Oa,
|
|
1964
|
+
r / Oa,
|
|
1965
|
+
n / Ia,
|
|
1966
|
+
r / Ia,
|
|
1967
|
+
i,
|
|
1968
|
+
a,
|
|
1969
|
+
o,
|
|
1970
|
+
s,
|
|
1971
|
+
c
|
|
1972
|
+
], 0), this._built = !0, this._writeParams(), !0;
|
|
1973
|
+
}
|
|
1974
|
+
_writeParams() {
|
|
1975
|
+
let e = this._params;
|
|
1976
|
+
e[9] = this.highlightContrast, e[10] = this.shadowContrast, e[11] = this.detailStrength, e[12] = La, e[13] = za;
|
|
1977
|
+
for (let t = 0; t < 4; t++) this._p[t].value.fromArray(e, t * 4);
|
|
1978
|
+
this.onChange?.();
|
|
1979
|
+
}
|
|
1980
|
+
get wantsBuild() {
|
|
1981
|
+
return this.enabled && (this._stale || !this._built);
|
|
1623
1982
|
}
|
|
1624
1983
|
updateParameters(e) {
|
|
1625
|
-
|
|
1984
|
+
for (let t of [
|
|
1985
|
+
"highlightContrast",
|
|
1986
|
+
"shadowContrast",
|
|
1987
|
+
"detailStrength"
|
|
1988
|
+
]) e[t] !== void 0 && (this[t] = e[t]);
|
|
1989
|
+
this._writeParams();
|
|
1990
|
+
}
|
|
1991
|
+
setEnabled(e) {
|
|
1992
|
+
this.enabled !== e && (this.enabled = e, this._stale = !0, this.onChange?.());
|
|
1993
|
+
}
|
|
1994
|
+
gainNode(e, t) {
|
|
1995
|
+
let n = Jn(this._grid.value, "vec2", Va * Va * Aa).toReadOnly(), r = Jn(this._blur.value, "float", Ha * Ha).toReadOnly(), [i, a, o, s] = this._p;
|
|
1996
|
+
return En(([e, t]) => {
|
|
1997
|
+
let c = Vn(R(Fn(e, J(...Ua, 0).xyz), Ba)).min(Pa).toVar(), l = Vn(Yn).toVar(), u = I(a.zw), d = t.mul(i.zw).sub(.5).clamp(K(0), K(u.sub(F(1)))).toVar(), f = I(zn(d)).toVar(), p = f.add(F(1)).min(u.sub(F(1))).toVar(), m = d.sub(zn(d)).toVar(), h = (e, t) => r.element(W(t.mul(u.x).add(e))), g = z(z(h(f.x, f.y), h(p.x, f.y), m.x), z(h(f.x, p.y), h(p.x, p.y), m.x), m.y).toVar(), _ = I(a.xy), v = t.mul(i.xy).sub(.5).clamp(K(0), K(_.sub(F(1)))).toVar(), y = c.add(o.x).sub(ja).div(Ma - ja).clamp(0, 1).mul(Aa - 1).toVar(), b = F(zn(v.x)), x = F(zn(v.y)), S = F(zn(y)), ee = v.x.sub(zn(v.x)), C = v.y.sub(zn(v.y)), w = y.sub(zn(y)), T = K(0).toVar();
|
|
1998
|
+
for (let e = 0; e < 8; e++) {
|
|
1999
|
+
let t = e & 1, r = e >> 1 & 1, i = e >> 2, a = (t ? ee : ee.oneMinus()).mul(r ? C : C.oneMinus()).mul(i ? w : w.oneMinus()), o = b.add(F(t)).min(_.x.sub(F(1))), s = x.add(F(r)).min(_.y.sub(F(1))), c = S.add(F(i)).min(F(Aa - 1));
|
|
2000
|
+
T.addAssign(n.element(W(s.mul(_.x).add(o).mul(F(Aa)).add(c))).mul(a));
|
|
2001
|
+
}
|
|
2002
|
+
let E = z(V(T.y.mul(ka).lessThan(.001), g, T.x.div(T.y)), g, s.x).add(l).toVar(), te = c.add(l), D = V(E.greaterThan(s.y), o.y, o.z);
|
|
2003
|
+
return Ln(s.y.add(E.sub(s.y).mul(D)).add(te.sub(E).mul(o.w)).sub(te));
|
|
2004
|
+
})(e, t);
|
|
2005
|
+
}
|
|
2006
|
+
toneGain() {
|
|
2007
|
+
if (!this.enabled || !this._built) return null;
|
|
2008
|
+
let e = this.renderer.backend, t = e.get(this._grid.value)?.buffer, n = e.get(this._blur.value)?.buffer;
|
|
2009
|
+
if (!t || !n) return null;
|
|
2010
|
+
this._paramsBuffer ??= e.device.createBuffer({
|
|
2011
|
+
label: "local-exposure-params",
|
|
2012
|
+
size: 64,
|
|
2013
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
2014
|
+
}), e.device.queue.writeBuffer(this._paramsBuffer, 0, this._params);
|
|
2015
|
+
let r = this._params.slice();
|
|
2016
|
+
return {
|
|
2017
|
+
key: "local-exposure",
|
|
2018
|
+
wgsl: qa,
|
|
2019
|
+
entries: [
|
|
2020
|
+
{
|
|
2021
|
+
binding: 0,
|
|
2022
|
+
resource: { buffer: t }
|
|
2023
|
+
},
|
|
2024
|
+
{
|
|
2025
|
+
binding: 1,
|
|
2026
|
+
resource: { buffer: n }
|
|
2027
|
+
},
|
|
2028
|
+
{
|
|
2029
|
+
binding: 2,
|
|
2030
|
+
resource: { buffer: this._paramsBuffer }
|
|
2031
|
+
}
|
|
2032
|
+
],
|
|
2033
|
+
cpu: async () => {
|
|
2034
|
+
let [e, t] = await Promise.all([this.renderer.getArrayBufferAsync(this._grid.value), this.renderer.getArrayBufferAsync(this._blur.value)]), n = new Float32Array(e), i = new Float32Array(t);
|
|
2035
|
+
return (e, t, a, o) => Ka(r, n, i, e, t, a, o);
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
1626
2038
|
}
|
|
2039
|
+
reset() {}
|
|
2040
|
+
setSize() {}
|
|
1627
2041
|
dispose() {
|
|
1628
|
-
this.
|
|
2042
|
+
this._disposed = !0, this.onChange = null;
|
|
2043
|
+
for (let e of this._kernels) e.dispose();
|
|
2044
|
+
this._inputNode.dispose(), this._paramsBuffer?.destroy(), this._paramsBuffer = null;
|
|
1629
2045
|
}
|
|
1630
|
-
},
|
|
1631
|
-
function
|
|
1632
|
-
return
|
|
2046
|
+
}, Ya = new $(), Xa = new $();
|
|
2047
|
+
function Za(e, t) {
|
|
2048
|
+
return Xa.subVectors(e, t.position).dot(t.getWorldDirection(Ya));
|
|
1633
2049
|
}
|
|
1634
|
-
function
|
|
1635
|
-
return n ? e.distance :
|
|
2050
|
+
function Qa(e, t, n = !1) {
|
|
2051
|
+
return n ? e.distance : Za(e.point, t);
|
|
1636
2052
|
}
|
|
1637
|
-
var
|
|
1638
|
-
constructor({ scene: e, camera: t, canvas: n, assetLoader: r, pathTracer: i, floorPlane: a }) {
|
|
1639
|
-
super(), this.scene = e, this.camera = t, this.canvas = n, this.assetLoader = r, this.pathTracer = i, this.floorPlane = a, this.raycaster = new
|
|
2053
|
+
var $a = class extends fr {
|
|
2054
|
+
constructor({ scene: e, camera: t, canvas: n, assetLoader: r, pathTracer: i, floorPlane: a, isGeometryOnDisk: o = null }) {
|
|
2055
|
+
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;
|
|
1640
2056
|
}
|
|
1641
2057
|
setDependencies({ overlayManager: e, transformManager: t, appDispatch: n, orbitControls: r, helperScene: i }) {
|
|
1642
2058
|
this._overlayManager = e || null, this._transformManager = t || null, this._appDispatch = n || null, this._orbitControls = r || null, this._helperScene = i || null;
|
|
1643
2059
|
}
|
|
1644
2060
|
select(e) {
|
|
1645
2061
|
let t = this._overlayManager?.getHelper("outline");
|
|
1646
|
-
t && t.setSelectedObjects(e ? [e] : []), this.selectedObject = e || null, e ? this._transformManager?.attach(e) : this._transformManager?.detach(), this._appDispatch?.({
|
|
1647
|
-
type:
|
|
2062
|
+
t && t.setSelectedObjects(e && !this.isGeometryOnDisk?.() ? [e] : []), this.selectedObject = e || null, e ? this._transformManager?.attach(e) : this._transformManager?.detach(), this._appDispatch?.({
|
|
2063
|
+
type: j.OBJECT_SELECTED,
|
|
1648
2064
|
object: e || null
|
|
1649
2065
|
});
|
|
1650
2066
|
}
|
|
@@ -1666,9 +2082,9 @@ var ca = class extends cr {
|
|
|
1666
2082
|
handleFocusClick(e) {
|
|
1667
2083
|
let t = this.getMouseCoordinates(e);
|
|
1668
2084
|
this.raycaster.setFromCamera(t, this.camera);
|
|
1669
|
-
let n = this.
|
|
2085
|
+
let n = this._intersectScene();
|
|
1670
2086
|
if (n.length > 0) {
|
|
1671
|
-
let e = n[0], t = this.pathTracer?.cameraProjection?.value === Ae.equirectangular, r =
|
|
2087
|
+
let e = n[0], t = this.pathTracer?.cameraProjection?.value === Ae.equirectangular, r = Qa(e, this.camera, t);
|
|
1672
2088
|
this.showFocusPoint(e.point), this.toggleFocusMode(), this.dispatchEvent({
|
|
1673
2089
|
type: "focusChanged",
|
|
1674
2090
|
distance: r / this.assetLoader.getSceneScale(),
|
|
@@ -1677,7 +2093,7 @@ var ca = class extends cr {
|
|
|
1677
2093
|
}
|
|
1678
2094
|
}
|
|
1679
2095
|
showFocusPoint(e) {
|
|
1680
|
-
this.focusPointIndicator && this.scene.remove(this.focusPointIndicator), this.focusPointIndicator = new
|
|
2096
|
+
this.focusPointIndicator && this.scene.remove(this.focusPointIndicator), this.focusPointIndicator = new xr(new Pr(this.assetLoader.getSceneScale() * .02, 16, 16), new Sr({
|
|
1681
2097
|
color: 65280,
|
|
1682
2098
|
transparent: !0,
|
|
1683
2099
|
opacity: .8,
|
|
@@ -1739,7 +2155,7 @@ var ca = class extends cr {
|
|
|
1739
2155
|
this.clickTimeout = null;
|
|
1740
2156
|
let t = this.getMouseCoordinates(e);
|
|
1741
2157
|
this.raycaster.setFromCamera(t, this.camera);
|
|
1742
|
-
let n = this.
|
|
2158
|
+
let n = this._intersectScene(), r = this.filterValidIntersects(n), i = this._pickLightHelper(), a = null;
|
|
1743
2159
|
if (r.length > 0 && i ? a = r[0].distance <= i.distance ? r[0].object : i.light : r.length > 0 ? a = r[0].object : i && (a = i.light), a) {
|
|
1744
2160
|
let e = this.selectedObject;
|
|
1745
2161
|
e && e.uuid === a.uuid ? this.dispatchEvent({
|
|
@@ -1762,7 +2178,7 @@ var ca = class extends cr {
|
|
|
1762
2178
|
this.mouseDownPosition = null, this.clickTimeout &&= (clearTimeout(this.clickTimeout), null);
|
|
1763
2179
|
let t = this.getMouseCoordinates(e);
|
|
1764
2180
|
this.raycaster.setFromCamera(t, this.camera);
|
|
1765
|
-
let n = this.
|
|
2181
|
+
let n = this._intersectScene(), r = this.filterValidIntersects(n);
|
|
1766
2182
|
if (r.length > 0) {
|
|
1767
2183
|
let e = r[0].object;
|
|
1768
2184
|
this.dispatchEvent({
|
|
@@ -1807,11 +2223,14 @@ var ca = class extends cr {
|
|
|
1807
2223
|
y: -((e.clientY - t.top) / t.height) * 2 + 1
|
|
1808
2224
|
};
|
|
1809
2225
|
}
|
|
2226
|
+
_intersectScene() {
|
|
2227
|
+
return this.isGeometryOnDisk?.() ? [] : this.raycaster.intersectObjects(this.scene.children, !0);
|
|
2228
|
+
}
|
|
1810
2229
|
pickSurface(e, t) {
|
|
1811
2230
|
return this.raycaster.setFromCamera({
|
|
1812
2231
|
x: e,
|
|
1813
2232
|
y: t
|
|
1814
|
-
}, this.camera), this.filterValidIntersects(this.
|
|
2233
|
+
}, this.camera), this.filterValidIntersects(this._intersectScene())[0] ?? null;
|
|
1815
2234
|
}
|
|
1816
2235
|
filterValidIntersects(e) {
|
|
1817
2236
|
return e.filter((e) => {
|
|
@@ -1840,35 +2259,35 @@ var ca = class extends cr {
|
|
|
1840
2259
|
wireAppEvents(e) {
|
|
1841
2260
|
this.addEventListener("objectSelected", (t) => {
|
|
1842
2261
|
this.select(t.object), e.refreshFrame(), e.dispatchEvent({
|
|
1843
|
-
type:
|
|
2262
|
+
type: j.OBJECT_SELECTED,
|
|
1844
2263
|
object: t.object,
|
|
1845
2264
|
uuid: t.uuid
|
|
1846
2265
|
});
|
|
1847
2266
|
}), this.addEventListener("objectDeselected", (t) => {
|
|
1848
2267
|
this.select(null), e.refreshFrame(), e.dispatchEvent({
|
|
1849
|
-
type:
|
|
2268
|
+
type: j.OBJECT_DESELECTED,
|
|
1850
2269
|
object: t.object,
|
|
1851
2270
|
uuid: t.uuid
|
|
1852
2271
|
});
|
|
1853
2272
|
}), this.addEventListener("selectModeChanged", (t) => {
|
|
1854
2273
|
e.dispatchEvent({
|
|
1855
|
-
type:
|
|
2274
|
+
type: j.SELECT_MODE_CHANGED,
|
|
1856
2275
|
enabled: t.enabled
|
|
1857
2276
|
});
|
|
1858
2277
|
}), this.addEventListener("objectDoubleClicked", (t) => {
|
|
1859
2278
|
this.select(t.object), e.refreshFrame(), e.dispatchEvent({
|
|
1860
|
-
type:
|
|
2279
|
+
type: j.OBJECT_DOUBLE_CLICKED,
|
|
1861
2280
|
object: t.object,
|
|
1862
2281
|
uuid: t.uuid
|
|
1863
2282
|
});
|
|
1864
2283
|
}), this.addEventListener("focusChanged", (t) => {
|
|
1865
2284
|
e.settings.set("focusDistance", t.worldDistance), e.dispatchEvent({
|
|
1866
|
-
type:
|
|
2285
|
+
type: j.FOCUS_CHANGED,
|
|
1867
2286
|
distance: t.distance
|
|
1868
2287
|
});
|
|
1869
2288
|
}), this.addEventListener("afPointPlaced", (t) => {
|
|
1870
2289
|
e.dispatchEvent({
|
|
1871
|
-
type:
|
|
2290
|
+
type: j.AF_POINT_PLACED,
|
|
1872
2291
|
point: t.point
|
|
1873
2292
|
});
|
|
1874
2293
|
});
|
|
@@ -1876,7 +2295,7 @@ var ca = class extends cr {
|
|
|
1876
2295
|
dispose() {
|
|
1877
2296
|
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;
|
|
1878
2297
|
}
|
|
1879
|
-
},
|
|
2298
|
+
}, eo = 8, to = 4, no = .25, ro = vr.degToRad(89), io = .25, ao = {
|
|
1880
2299
|
KeyD: [
|
|
1881
2300
|
1,
|
|
1882
2301
|
0,
|
|
@@ -1927,15 +2346,15 @@ var ca = class extends cr {
|
|
|
1927
2346
|
0,
|
|
1928
2347
|
-1
|
|
1929
2348
|
]
|
|
1930
|
-
},
|
|
2349
|
+
}, oo = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=textbox], [role=combobox], [role=listbox], [role=menu], [role=menuitem]", so = (e) => e.shiftKey ? to : e.altKey ? no : 1, co = { type: "change" }, lo = { type: "start" }, uo = new $(), fo = new $(), po = new $(), mo = new $(), ho = new kr(), go = class extends cr {
|
|
1931
2350
|
constructor(e, t, n) {
|
|
1932
|
-
super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 /
|
|
2351
|
+
super(e, t), this.orbit = n, this.enabled = !1, this.speed = 1 / eo, 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);
|
|
1933
2352
|
}
|
|
1934
2353
|
get active() {
|
|
1935
2354
|
return this.enabled && this.orbit.enabled;
|
|
1936
2355
|
}
|
|
1937
2356
|
fitSpeed(e) {
|
|
1938
|
-
this.speed = (e > 0 ? e : 1) /
|
|
2357
|
+
this.speed = (e > 0 ? e : 1) / eo;
|
|
1939
2358
|
}
|
|
1940
2359
|
connect(e) {
|
|
1941
2360
|
super.connect(e);
|
|
@@ -1955,34 +2374,34 @@ var ca = class extends cr {
|
|
|
1955
2374
|
if (!this._held.size || !this.active) return !1;
|
|
1956
2375
|
let t = 0, n = 0, r = 0;
|
|
1957
2376
|
for (let e of this._held) {
|
|
1958
|
-
let [i, a, o] =
|
|
2377
|
+
let [i, a, o] = ao[e];
|
|
1959
2378
|
t += i, n += a, r += o;
|
|
1960
2379
|
}
|
|
1961
2380
|
if (!t && !n && !r) return !1;
|
|
1962
2381
|
let i = this.object;
|
|
1963
|
-
return
|
|
2382
|
+
return fo.set(1, 0, 0).applyQuaternion(i.quaternion), uo.crossVectors(i.up, fo).normalize(), fo.crossVectors(uo, i.up), po.set(0, 0, 0).addScaledVector(fo, t).addScaledVector(uo, n).addScaledVector(i.up, r).normalize().multiplyScalar(this.speed * this._factor * e), i.position.add(po), this.orbit.target.add(po), i.updateMatrixWorld(), this.dispatchEvent(co), !0;
|
|
1964
2383
|
}
|
|
1965
2384
|
_elapsed() {
|
|
1966
|
-
let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3,
|
|
2385
|
+
let e = performance.now(), t = Math.min((e - this._lastTime) / 1e3, io);
|
|
1967
2386
|
return this._lastTime = e, t;
|
|
1968
2387
|
}
|
|
1969
2388
|
_look(e, t) {
|
|
1970
|
-
let n = this.object, r = this.orbit.target, i = n.position.distanceTo(r) || 1, a =
|
|
1971
|
-
n.quaternion.premultiply(
|
|
1972
|
-
let o = Math.asin(
|
|
1973
|
-
n.quaternion.multiply(
|
|
2389
|
+
let n = this.object, r = this.orbit.target, i = n.position.distanceTo(r) || 1, a = vr.degToRad(n.fov) / (this.domElement.clientHeight || 1);
|
|
2390
|
+
n.quaternion.premultiply(ho.setFromAxisAngle(n.up, e * a)), n.getWorldDirection(uo);
|
|
2391
|
+
let o = Math.asin(vr.clamp(uo.dot(n.up), -1, 1)), s = vr.clamp(o + t * a, -ro, ro);
|
|
2392
|
+
n.quaternion.multiply(ho.setFromAxisAngle(mo.set(1, 0, 0), s - o)), n.updateMatrixWorld(), r.copy(n.position).addScaledVector(n.getWorldDirection(uo), i), this.dispatchEvent(co);
|
|
1974
2393
|
}
|
|
1975
2394
|
_onKeyDown(e) {
|
|
1976
|
-
if (!(!this.active || e.defaultPrevented || e.target?.closest?.(
|
|
2395
|
+
if (!(!this.active || e.defaultPrevented || e.target?.closest?.(oo))) {
|
|
1977
2396
|
if (e.metaKey || e.ctrlKey) {
|
|
1978
2397
|
this.release();
|
|
1979
2398
|
return;
|
|
1980
2399
|
}
|
|
1981
|
-
this._factor =
|
|
2400
|
+
this._factor = so(e), ao[e.code] && (e.preventDefault(), !this._held.has(e.code) && (this._held.add(e.code), this._held.size === 1 && (this._lastTime = performance.now(), this.dispatchEvent(lo))));
|
|
1982
2401
|
}
|
|
1983
2402
|
}
|
|
1984
2403
|
_onKeyUp(e) {
|
|
1985
|
-
this._factor =
|
|
2404
|
+
this._factor = so(e), this._held.delete(e.code);
|
|
1986
2405
|
}
|
|
1987
2406
|
release() {
|
|
1988
2407
|
this._held.clear(), this._factor = 1;
|
|
@@ -2003,24 +2422,24 @@ var ca = class extends cr {
|
|
|
2003
2422
|
_onPointerUp(e) {
|
|
2004
2423
|
this._drag?.id === e.pointerId && (this._drag = null, this.domElement.releasePointerCapture?.(e.pointerId));
|
|
2005
2424
|
}
|
|
2006
|
-
},
|
|
2425
|
+
}, _o = {
|
|
2007
2426
|
autoFocusMode: "auto",
|
|
2008
2427
|
afScreenPoint: {
|
|
2009
2428
|
x: .5,
|
|
2010
2429
|
y: .5
|
|
2011
2430
|
},
|
|
2012
2431
|
afSmoothingFactor: .15
|
|
2013
|
-
},
|
|
2432
|
+
}, vo = .05, yo = 10, bo = .5, xo = Object.freeze(new $(1, 1, 1)), So = (e) => e?.isOrthographicCamera ? (e.top - e.bottom) / e.zoom : null, Co = class extends fr {
|
|
2014
2433
|
constructor(e) {
|
|
2015
2434
|
super();
|
|
2016
2435
|
let t = e.clientWidth, n = e.clientHeight;
|
|
2017
|
-
this.camera = new _(60, t / n || 1, .01, 1e3), this.camera.position.set(0, 0, 5), this.controls = new
|
|
2436
|
+
this.camera = new _(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 go(this.camera, e, this.controls), this.interactionManager = null, this.cameras = [this.camera], this.currentCameraIndex = 0, this._userCameraCounter = 0, this.autoFocusMode = _o.autoFocusMode, this.afScreenPoint = { ..._o.afScreenPoint }, this.afSmoothingFactor = _o.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;
|
|
2018
2437
|
}
|
|
2019
2438
|
setCameras(e) {
|
|
2020
2439
|
this.cameras = e, this._userCameraCounter = 0, this.resetAutoFocus();
|
|
2021
2440
|
}
|
|
2022
2441
|
addCameraFromView(e) {
|
|
2023
|
-
let t = this.camera, n = t.orthographic ? new
|
|
2442
|
+
let t = this.camera, n = t.orthographic ? new Er(t.left, t.right, t.top, t.bottom, t.near, t.far) : new Dr(t.fov, t.aspect, t.near, t.far);
|
|
2024
2443
|
return n.zoom = t.zoom, n.position.copy(t.position), n.quaternion.copy(t.quaternion), n.scale.copy(t.scale), n.updateMatrixWorld(!0), n.userData.__rayzeeUserCamera = !0, n.userData.__rayzeeEffects = this._captureEffects(), this.controls && (n.userData.__rayzeeOrbitTarget = this.controls.target.clone()), this._userCameraCounter += 1, n.name = e || `View Camera ${this._userCameraCounter}`, this.cameras.push(n), this.cameras.length - 1;
|
|
2025
2444
|
}
|
|
2026
2445
|
removeCamera(e) {
|
|
@@ -2074,12 +2493,12 @@ var ca = class extends cr {
|
|
|
2074
2493
|
target: this.controls ? this.controls.target.clone() : null
|
|
2075
2494
|
}), this.currentCameraIndex = e, e === 0 && this._defaultCameraState) {
|
|
2076
2495
|
let e = this._defaultCameraState;
|
|
2077
|
-
this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ??
|
|
2496
|
+
this.camera.position.copy(e.position), this.camera.quaternion.copy(e.quaternion), this.camera.scale.copy(e.scale ?? xo), this.camera.fov = e.fov, this.camera.near = e.near, this.camera.far = e.far, this.camera.updateProjectionMatrix(), this.camera.updateMatrixWorld(!0), this.controls && e.target && (this.controls.target.copy(e.target), this.controls.update());
|
|
2078
2497
|
} else this._placeAt(this.cameras[e], t);
|
|
2079
2498
|
this.resetAutoFocus();
|
|
2080
2499
|
let a = this.cameras[e], o = a?.userData?.__rayzeeEffects;
|
|
2081
|
-
this._showOrthographic(o ? o.orthoHeight :
|
|
2082
|
-
type:
|
|
2500
|
+
this._showOrthographic(o ? o.orthoHeight : So(a)), this._applyEffects(o), n?.(), r?.(), this.dispatchEvent({
|
|
2501
|
+
type: j.CAMERA_SWITCHED,
|
|
2083
2502
|
cameraIndex: e,
|
|
2084
2503
|
effects: this._captureEffects(),
|
|
2085
2504
|
fov: this.camera.fov,
|
|
@@ -2093,7 +2512,7 @@ var ca = class extends cr {
|
|
|
2093
2512
|
return;
|
|
2094
2513
|
}
|
|
2095
2514
|
this._placeAt(e, this._getSettings?.("focusDistance"));
|
|
2096
|
-
let t =
|
|
2515
|
+
let t = So(e);
|
|
2097
2516
|
this.camera.orthographic && this._setView(!0, t ? t / 2 : this.camera.orthoHalfHeight), this._onReset?.();
|
|
2098
2517
|
}
|
|
2099
2518
|
_placeAt(e, t) {
|
|
@@ -2116,14 +2535,14 @@ var ca = class extends cr {
|
|
|
2116
2535
|
if (t.orthographic !== n) {
|
|
2117
2536
|
if (n) this._setView(!0, this._fittedHalfHeight());
|
|
2118
2537
|
else {
|
|
2119
|
-
let e = this.controls.target, n = this.orthoHeight / 2 / Math.tan(
|
|
2538
|
+
let e = this.controls.target, n = this.orthoHeight / 2 / Math.tan(vr.degToRad(t.fov) / 2);
|
|
2120
2539
|
t.position.sub(e).setLength(n).add(e), this._setView(!1);
|
|
2121
2540
|
}
|
|
2122
2541
|
this.controls.update();
|
|
2123
2542
|
}
|
|
2124
2543
|
}
|
|
2125
2544
|
get orthoHeight() {
|
|
2126
|
-
return
|
|
2545
|
+
return So(this.camera);
|
|
2127
2546
|
}
|
|
2128
2547
|
setOrthoHeight(e) {
|
|
2129
2548
|
e > 0 && (this._setView(this.camera.orthographic, e / 2), this._onReset?.());
|
|
@@ -2136,13 +2555,13 @@ var ca = class extends cr {
|
|
|
2136
2555
|
n.orthographic = e, n.orthoHalfHeight = t, n.zoom = 1, n.updateProjectionMatrix(), this._reportOrthoHeight();
|
|
2137
2556
|
}
|
|
2138
2557
|
_fittedHalfHeight() {
|
|
2139
|
-
return this.camera.position.distanceTo(this.controls.target) * Math.tan(
|
|
2558
|
+
return this.camera.position.distanceTo(this.controls.target) * Math.tan(vr.degToRad(this.camera.fov) / 2);
|
|
2140
2559
|
}
|
|
2141
2560
|
_reportOrthoHeight() {
|
|
2142
2561
|
if (!this.camera.orthographic) return;
|
|
2143
2562
|
let e = this.orthoHeight;
|
|
2144
2563
|
e !== this._reportedOrthoHeight && (this._reportedOrthoHeight = e, this.dispatchEvent({
|
|
2145
|
-
type:
|
|
2564
|
+
type: j.ORTHO_HEIGHT_UPDATED,
|
|
2146
2565
|
height: e
|
|
2147
2566
|
}));
|
|
2148
2567
|
}
|
|
@@ -2157,7 +2576,7 @@ var ca = class extends cr {
|
|
|
2157
2576
|
this.walkControls.release();
|
|
2158
2577
|
let r = this.interactionManager?.pickSurface(0, 0);
|
|
2159
2578
|
if (!r) return;
|
|
2160
|
-
let i =
|
|
2579
|
+
let i = vr.clamp(r.distance, n.minDistance, n.maxDistance);
|
|
2161
2580
|
n.target.copy(this.camera.position).addScaledVector(this.camera.getWorldDirection(new $()), i), n.update();
|
|
2162
2581
|
}
|
|
2163
2582
|
get navigationMode() {
|
|
@@ -2213,7 +2632,7 @@ var ca = class extends cr {
|
|
|
2213
2632
|
let n = {
|
|
2214
2633
|
index: t,
|
|
2215
2634
|
name: e.name ?? "",
|
|
2216
|
-
effects:
|
|
2635
|
+
effects: ue(e.userData?.__rayzeeEffects) ?? null
|
|
2217
2636
|
};
|
|
2218
2637
|
return t === 0 || !e.userData?.__rayzeeUserCamera ? n : {
|
|
2219
2638
|
...n,
|
|
@@ -2245,8 +2664,8 @@ var ca = class extends cr {
|
|
|
2245
2664
|
let n = /* @__PURE__ */ new Map();
|
|
2246
2665
|
for (let r of e.cameras ?? []) {
|
|
2247
2666
|
if (r.user) {
|
|
2248
|
-
let e = r.orthographic ? new
|
|
2249
|
-
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 =
|
|
2667
|
+
let e = r.orthographic ? new Er(...r.frustum, r.near, r.far) : new Dr(r.fov, r.aspect, r.near, r.far);
|
|
2668
|
+
e.name = r.name, e.zoom = r.zoom ?? 1, e.position.fromArray(r.position), e.quaternion.fromArray(r.quaternion), e.scale.fromArray(r.scale), e.updateProjectionMatrix(), e.updateMatrixWorld(!0), e.userData.__rayzeeUserCamera = !0, e.userData.__rayzeeEffects = me(r.effects), r.orbitTarget && (e.userData.__rayzeeOrbitTarget = new $().fromArray(r.orbitTarget)), n.set(r.index, this.cameras.length), this.cameras.push(e);
|
|
2250
2669
|
continue;
|
|
2251
2670
|
}
|
|
2252
2671
|
let e = this.cameras[r.index];
|
|
@@ -2254,13 +2673,13 @@ var ca = class extends cr {
|
|
|
2254
2673
|
t.push(r.name);
|
|
2255
2674
|
continue;
|
|
2256
2675
|
}
|
|
2257
|
-
n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects =
|
|
2676
|
+
n.set(r.index, r.index), r.effects && (e.userData.__rayzeeEffects = me(r.effects));
|
|
2258
2677
|
}
|
|
2259
2678
|
this._userCameraCounter = this.cameras.filter((e) => e.userData?.__rayzeeUserCamera).length, this.currentCameraIndex = n.get(e.current) ?? 0;
|
|
2260
2679
|
let r = e.defaultView;
|
|
2261
2680
|
this._defaultCameraState = r ? {
|
|
2262
2681
|
position: new $().fromArray(r.position),
|
|
2263
|
-
quaternion: new
|
|
2682
|
+
quaternion: new kr().fromArray(r.quaternion),
|
|
2264
2683
|
scale: new $().fromArray(r.scale),
|
|
2265
2684
|
fov: r.fov,
|
|
2266
2685
|
near: r.near,
|
|
@@ -2273,7 +2692,7 @@ var ca = class extends cr {
|
|
|
2273
2692
|
e.position.fromArray(i.position), e.quaternion.fromArray(i.quaternion), e.scale.fromArray(i.scale), e.fov = i.fov, e.near = i.near, e.far = i.far, this._setView(i.orthographic, i.orthoHalfHeight), e.zoom = i.zoom ?? 1, e.updateProjectionMatrix(), e.updateMatrixWorld(!0), this.controls.target.fromArray(i.target), this.controls.update();
|
|
2274
2693
|
}
|
|
2275
2694
|
return e.autoFocus && (this.setAutoFocusMode(e.autoFocus.mode), this.setAFScreenPoint(e.autoFocus.point.x, e.autoFocus.point.y)), this.resetAutoFocus(), this._reportOrthoHeight(), this.dispatchEvent({
|
|
2276
|
-
type:
|
|
2695
|
+
type: j.CAMERA_SWITCHED,
|
|
2277
2696
|
cameraIndex: this.currentCameraIndex,
|
|
2278
2697
|
effects: this._captureEffects(),
|
|
2279
2698
|
fov: this.camera.fov,
|
|
@@ -2317,25 +2736,25 @@ var ca = class extends cr {
|
|
|
2317
2736
|
let c = i;
|
|
2318
2737
|
if (c?.isReady && c.renderMode?.value === 1 && c.frameCount > 0 && !c.isComplete) return;
|
|
2319
2738
|
let l = this._pickFocusPoint(c.resetCount), u;
|
|
2320
|
-
if (l) u =
|
|
2739
|
+
if (l) u = Za(l, this.camera), this._lastValidFocusDistance = u;
|
|
2321
2740
|
else if (this._lastValidFocusDistance !== null) u = this._lastValidFocusDistance;
|
|
2322
2741
|
else {
|
|
2323
|
-
let e = this.controls ?
|
|
2324
|
-
u = e > 0 ? e :
|
|
2742
|
+
let e = this.controls ? Za(this.controls.target, this.camera) : 0;
|
|
2743
|
+
u = e > 0 ? e : yo * (n?.getSceneScale() || 1), this._lastValidFocusDistance = u;
|
|
2325
2744
|
}
|
|
2326
2745
|
let d = this._afPointDirty;
|
|
2327
|
-
this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance >
|
|
2746
|
+
this._afPointDirty = !1, d || this._smoothedFocusDistance === null || this._smoothedFocusDistance === 0 || Math.abs(u - this._smoothedFocusDistance) / this._smoothedFocusDistance > bo ? this._smoothedFocusDistance = u : this._smoothedFocusDistance += this.afSmoothingFactor * (u - this._smoothedFocusDistance);
|
|
2328
2747
|
let f = r, p = this._smoothedFocusDistance;
|
|
2329
2748
|
if (d || f === 0 || Math.abs(p - f) / Math.max(f, .001) > .001) {
|
|
2330
2749
|
a(p);
|
|
2331
2750
|
let e = n?.getSceneScale() || 1;
|
|
2332
2751
|
this.dispatchEvent({
|
|
2333
|
-
type:
|
|
2752
|
+
type: j.AUTO_FOCUS_UPDATED,
|
|
2334
2753
|
distance: p / e,
|
|
2335
2754
|
worldDistance: p
|
|
2336
2755
|
});
|
|
2337
2756
|
let t = Math.abs(p - f) / Math.max(f, .001);
|
|
2338
|
-
d ? s?.() : t >
|
|
2757
|
+
d ? s?.() : t > vo && o?.();
|
|
2339
2758
|
}
|
|
2340
2759
|
}
|
|
2341
2760
|
_pickFocusPoint(e) {
|
|
@@ -2345,8 +2764,8 @@ var ca = class extends cr {
|
|
|
2345
2764
|
resetCount: NaN,
|
|
2346
2765
|
x: NaN,
|
|
2347
2766
|
y: NaN,
|
|
2348
|
-
view: new
|
|
2349
|
-
projection: new
|
|
2767
|
+
view: new br(),
|
|
2768
|
+
projection: new br()
|
|
2350
2769
|
};
|
|
2351
2770
|
if (this._afPointDirty || e !== i.resetCount || n !== i.x || r !== i.y || !i.view.equals(t.matrixWorld) || !i.projection.equals(t.projectionMatrix)) {
|
|
2352
2771
|
let a = this.interactionManager.pickSurface(n * 2 - 1, 1 - r * 2);
|
|
@@ -2369,7 +2788,7 @@ var ca = class extends cr {
|
|
|
2369
2788
|
dispose() {
|
|
2370
2789
|
this.walkControls?.dispose(), this.controls?.removeEventListener("change", this._reportOrthoHeight), this.controls?.dispose();
|
|
2371
2790
|
}
|
|
2372
|
-
},
|
|
2791
|
+
}, wo = .001, To = 2, Eo = (e, t, n, r) => new e(t, n, r, hr).createInterpolant(), Do = class {
|
|
2373
2792
|
constructor(e, t) {
|
|
2374
2793
|
this._cameraManager = e, this._onChange = t, this.keys = [], this._nextId = 1, this._interpolants = null;
|
|
2375
2794
|
}
|
|
@@ -2379,7 +2798,7 @@ var ca = class extends cr {
|
|
|
2379
2798
|
get duration() {
|
|
2380
2799
|
return this.keys.length ? this.keys[this.keys.length - 1].time : 0;
|
|
2381
2800
|
}
|
|
2382
|
-
addKey(e = this.keys.length ? this.duration +
|
|
2801
|
+
addKey(e = this.keys.length ? this.duration + To : 0) {
|
|
2383
2802
|
return this.add(this._cameraManager.captureView(), e);
|
|
2384
2803
|
}
|
|
2385
2804
|
updateKey(e) {
|
|
@@ -2393,13 +2812,13 @@ var ca = class extends cr {
|
|
|
2393
2812
|
let n = {
|
|
2394
2813
|
id: this._nextId++,
|
|
2395
2814
|
time: t,
|
|
2396
|
-
...
|
|
2815
|
+
...Oo(e)
|
|
2397
2816
|
};
|
|
2398
2817
|
return this.keys.push(n), this._changed(), n;
|
|
2399
2818
|
}
|
|
2400
2819
|
update(e, t) {
|
|
2401
2820
|
let n = this.get(e);
|
|
2402
|
-
n && (Object.assign(n,
|
|
2821
|
+
n && (Object.assign(n, Oo(t)), this._changed());
|
|
2403
2822
|
}
|
|
2404
2823
|
setTime(e, t) {
|
|
2405
2824
|
let n = this.get(e);
|
|
@@ -2444,12 +2863,12 @@ var ca = class extends cr {
|
|
|
2444
2863
|
orthoHeight: 0
|
|
2445
2864
|
}) {
|
|
2446
2865
|
if (!this.keys.length) return null;
|
|
2447
|
-
let { position: n, target: r, fov: i, logHeight: a, start: o, end: s } = this._interpolants ??= this._build(), c =
|
|
2866
|
+
let { position: n, target: r, fov: i, logHeight: a, start: o, end: s } = this._interpolants ??= this._build(), c = vr.clamp(e, o, s);
|
|
2448
2867
|
return t.position.fromArray(n.evaluate(c)), t.target.fromArray(r.evaluate(c)), t.fov = i.evaluate(c)[0], t.orthoHeight = Math.exp(a.evaluate(c)[0]), t;
|
|
2449
2868
|
}
|
|
2450
2869
|
_build() {
|
|
2451
2870
|
let e = [];
|
|
2452
|
-
for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] +
|
|
2871
|
+
for (let t of this.keys) e.push(e.length ? Math.max(t.time, e[e.length - 1] + wo) : t.time);
|
|
2453
2872
|
let t = e[0], n = e[e.length - 1], r = this.keys;
|
|
2454
2873
|
if (r.length > 1) {
|
|
2455
2874
|
let i = r.length;
|
|
@@ -2463,17 +2882,17 @@ var ca = class extends cr {
|
|
|
2463
2882
|
return {
|
|
2464
2883
|
start: t,
|
|
2465
2884
|
end: n,
|
|
2466
|
-
position:
|
|
2467
|
-
target:
|
|
2468
|
-
fov:
|
|
2469
|
-
logHeight:
|
|
2885
|
+
position: Eo(Br, ".position", e, i((e) => e.position)),
|
|
2886
|
+
target: Eo(Br, ".target", e, i((e) => e.target)),
|
|
2887
|
+
fov: Eo(wr, ".fov", e, r.map((e) => e.fov)),
|
|
2888
|
+
logHeight: Eo(wr, ".orthoHeight", e, r.map((e) => Math.log(e.orthoHeight)))
|
|
2470
2889
|
};
|
|
2471
2890
|
}
|
|
2472
2891
|
_changed() {
|
|
2473
2892
|
this.keys.sort((e, t) => e.time - t.time), this._interpolants = null, this._onChange?.();
|
|
2474
2893
|
}
|
|
2475
2894
|
};
|
|
2476
|
-
function
|
|
2895
|
+
function Oo({ position: e, target: t, fov: n, orthoHeight: r }) {
|
|
2477
2896
|
return {
|
|
2478
2897
|
position: e.clone(),
|
|
2479
2898
|
target: t.clone(),
|
|
@@ -2483,9 +2902,9 @@ function Ia({ position: e, target: t, fov: n, orthoHeight: r }) {
|
|
|
2483
2902
|
}
|
|
2484
2903
|
//#endregion
|
|
2485
2904
|
//#region src/managers/timeline/TimelineManager.js
|
|
2486
|
-
var
|
|
2905
|
+
var ko = class extends fr {
|
|
2487
2906
|
constructor({ cameraManager: e, onReset: t }) {
|
|
2488
|
-
super(), this._cameraManager = e, this._onReset = t, this.camera = new
|
|
2907
|
+
super(), this._cameraManager = e, this._onReset = t, this.camera = new Do(e, () => this._changed("camera")), this._playback = null, this._timer = new Fr(), typeof document < "u" && this._timer.connect(document);
|
|
2489
2908
|
}
|
|
2490
2909
|
get duration() {
|
|
2491
2910
|
return this.camera.duration;
|
|
@@ -2517,7 +2936,7 @@ var La = class extends cr {
|
|
|
2517
2936
|
let e = this._playback;
|
|
2518
2937
|
if (!e) return;
|
|
2519
2938
|
this._timer.update(), e.elapsed += this._timer.getDelta();
|
|
2520
|
-
let t =
|
|
2939
|
+
let t = vr.clamp(e.elapsed, 0, this.duration);
|
|
2521
2940
|
this.seek(t), t >= this.duration && this.stop();
|
|
2522
2941
|
}
|
|
2523
2942
|
serialize() {
|
|
@@ -2534,18 +2953,18 @@ var La = class extends cr {
|
|
|
2534
2953
|
}
|
|
2535
2954
|
_changed(e) {
|
|
2536
2955
|
this.dispatchEvent({
|
|
2537
|
-
type:
|
|
2956
|
+
type: j.TIMELINE_CHANGED,
|
|
2538
2957
|
track: e
|
|
2539
2958
|
});
|
|
2540
2959
|
}
|
|
2541
|
-
},
|
|
2960
|
+
}, Ao = class {
|
|
2542
2961
|
constructor(e, t = {}) {
|
|
2543
2962
|
this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._size = 256;
|
|
2544
2963
|
}
|
|
2545
2964
|
async loadLibrary(e, { size: t = 256 } = {}) {
|
|
2546
2965
|
if (!Array.isArray(e) || e.length === 0) return [];
|
|
2547
2966
|
this._size = t;
|
|
2548
|
-
let n = await Promise.all(e.map((e) =>
|
|
2967
|
+
let n = await Promise.all(e.map((e) => jo(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
|
|
2549
2968
|
s.width = r, s.height = i;
|
|
2550
2969
|
let c = s.getContext("2d", { willReadFrequently: !0 }), l = performance.now();
|
|
2551
2970
|
for (let e = 0; e < a; e++) {
|
|
@@ -2553,8 +2972,8 @@ var La = class extends cr {
|
|
|
2553
2972
|
let t = c.getImageData(0, 0, r, i);
|
|
2554
2973
|
o.set(t.data, e * r * i * 4), performance.now() - l > 16 && (await new Promise((e) => setTimeout(e, 0)), l = performance.now());
|
|
2555
2974
|
}
|
|
2556
|
-
let u = new
|
|
2557
|
-
u.minFilter = X, u.magFilter = X, u.format = Q, u.type =
|
|
2975
|
+
let u = new ur(o, r, i, a);
|
|
2976
|
+
u.minFilter = X, u.magFilter = X, u.format = Q, u.type = Ir, u.generateMipmaps = !1, u.needsUpdate = !0;
|
|
2558
2977
|
let d = this.texture;
|
|
2559
2978
|
return this.texture = u, this.entries = e.map((e, t) => ({
|
|
2560
2979
|
name: e.name,
|
|
@@ -2570,14 +2989,14 @@ var La = class extends cr {
|
|
|
2570
2989
|
if (o.userData = o.userData || {}, t == null) delete o.userData.gobo;
|
|
2571
2990
|
else {
|
|
2572
2991
|
let e = this.entries.find((e) => e.name === t);
|
|
2573
|
-
if (!e) return this._issues?.record(
|
|
2992
|
+
if (!e) return this._issues?.record(Ze.ASSET_UNREACHABLE, `no gobo named "${t}" is loaded — the light projects without one`, {
|
|
2574
2993
|
name: t,
|
|
2575
2994
|
asset: "gobo"
|
|
2576
2995
|
}), !1;
|
|
2577
2996
|
o.userData.gobo = {
|
|
2578
2997
|
name: e.name,
|
|
2579
2998
|
index: e.index,
|
|
2580
|
-
intensity:
|
|
2999
|
+
intensity: Mo(r),
|
|
2581
3000
|
inverted: !!i,
|
|
2582
3001
|
scale: Math.max(1e-4, a)
|
|
2583
3002
|
};
|
|
@@ -2619,7 +3038,7 @@ var La = class extends cr {
|
|
|
2619
3038
|
return t && t.isSpotLight ? t : null;
|
|
2620
3039
|
}
|
|
2621
3040
|
};
|
|
2622
|
-
async function
|
|
3041
|
+
async function jo(e) {
|
|
2623
3042
|
let t = await v(e);
|
|
2624
3043
|
try {
|
|
2625
3044
|
return await new Promise((n, r) => {
|
|
@@ -2630,22 +3049,22 @@ async function za(e) {
|
|
|
2630
3049
|
t.release();
|
|
2631
3050
|
}
|
|
2632
3051
|
}
|
|
2633
|
-
function
|
|
3052
|
+
function Mo(e) {
|
|
2634
3053
|
return Math.max(0, Math.min(1, e));
|
|
2635
3054
|
}
|
|
2636
3055
|
//#endregion
|
|
2637
3056
|
//#region src/Processor/IESParser.js
|
|
2638
|
-
function
|
|
3057
|
+
function No(e, t = "ies") {
|
|
2639
3058
|
let n = e.search(/TILT\s*=/i);
|
|
2640
3059
|
if (n < 0) throw Error(`IES (${t}): missing TILT line`);
|
|
2641
3060
|
let r = e.indexOf("\n", n);
|
|
2642
3061
|
if (r < 0) throw Error(`IES (${t}): truncated TILT line`);
|
|
2643
3062
|
let i = e.slice(n, r).match(/TILT\s*=\s*(\w+)/i), a = i ? i[1].toUpperCase() : "NONE", o = e.slice(r);
|
|
2644
3063
|
if (a === "INCLUDE") {
|
|
2645
|
-
let e =
|
|
2646
|
-
o =
|
|
3064
|
+
let e = Ro(o), t = 2 + 2 * Number(e[1]);
|
|
3065
|
+
o = zo(o, t);
|
|
2647
3066
|
}
|
|
2648
|
-
let s =
|
|
3067
|
+
let s = Ro(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
|
|
2649
3068
|
l(), l(), l(), l();
|
|
2650
3069
|
let g = l();
|
|
2651
3070
|
if (l(), l(), !Number.isFinite(p) || p <= 0) throw Error(`IES (${t}): invalid vertical angle count ${p}`);
|
|
@@ -2671,34 +3090,34 @@ function Va(e, t = "ies") {
|
|
|
2671
3090
|
name: t
|
|
2672
3091
|
};
|
|
2673
3092
|
}
|
|
2674
|
-
function
|
|
3093
|
+
function Po(e, t, n) {
|
|
2675
3094
|
if (t === 0 && n === 90) {
|
|
2676
3095
|
let t = e % 180;
|
|
2677
3096
|
return t > 90 ? 180 - t : t;
|
|
2678
3097
|
}
|
|
2679
3098
|
return t === 0 && n === 180 ? e > 180 ? 360 - e : e : t === 90 && n === 270 ? e >= 90 && e <= 270 ? e : (540 - e) % 360 : e;
|
|
2680
3099
|
}
|
|
2681
|
-
function
|
|
3100
|
+
function Fo(e, t, n) {
|
|
2682
3101
|
let r = new Uint8Array(t * n), { verticalAngles: i, horizontalAngles: a, candela: o, maxCandela: s, photometricType: c } = e;
|
|
2683
3102
|
if (s <= 0) return r;
|
|
2684
3103
|
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) => {
|
|
2685
|
-
if (m) return
|
|
3104
|
+
if (m) return Vo(o[e][0], o[t][0], n);
|
|
2686
3105
|
if (r < f || r > p) return 0;
|
|
2687
|
-
let i =
|
|
2688
|
-
return
|
|
3106
|
+
let i = Bo(a, r), s = Math.min(i + 1, a.length - 1), c = a[s] - a[i], l = c > 0 ? (r - a[i]) / c : 0;
|
|
3107
|
+
return Vo(Vo(o[e][i], o[e][s], l), Vo(o[t][i], o[t][s], l), n);
|
|
2689
3108
|
};
|
|
2690
3109
|
for (let e = 0; e < n; e++) {
|
|
2691
3110
|
let a = (e + .5) / n, o = l ? a * 180 : u + a * (d - u);
|
|
2692
3111
|
if (o < u || o > d) continue;
|
|
2693
|
-
let c =
|
|
3112
|
+
let c = Bo(i, o), m = Math.min(c + 1, i.length - 1), g = i[m] - i[c], _ = g > 0 ? (o - i[c]) / g : 0;
|
|
2694
3113
|
for (let n = 0; n < t; n++) {
|
|
2695
|
-
let i = (n + .5) / t, a = l ?
|
|
3114
|
+
let i = (n + .5) / t, a = l ? Po(i * 360, f, p) : f + i * (p - f), o = Math.min(1, Math.max(0, h(c, m, _, a) / s));
|
|
2696
3115
|
r[e * t + n] = Math.round(o * 255);
|
|
2697
3116
|
}
|
|
2698
3117
|
}
|
|
2699
3118
|
return r;
|
|
2700
3119
|
}
|
|
2701
|
-
function
|
|
3120
|
+
function Io(e, t = .1) {
|
|
2702
3121
|
let { verticalAngles: n, horizontalAngles: r, candela: i, maxCandela: a } = e, o = Math.PI / 4;
|
|
2703
3122
|
if (a <= 0 || !n?.length) return o;
|
|
2704
3123
|
let s = a * t, c = r.length, l = n[n.length - 1], u = !1;
|
|
@@ -2713,7 +3132,7 @@ function Wa(e, t = .1) {
|
|
|
2713
3132
|
let d = l * Math.PI / 180;
|
|
2714
3133
|
return Math.min(Math.max(d, 5 * Math.PI / 180), 89 * Math.PI / 180);
|
|
2715
3134
|
}
|
|
2716
|
-
function
|
|
3135
|
+
function Lo(e, t, n = .7) {
|
|
2717
3136
|
let { verticalAngles: r, horizontalAngles: i, candela: a, maxCandela: o } = e;
|
|
2718
3137
|
if (o <= 0 || !r?.length || t <= 0) return 0;
|
|
2719
3138
|
let s = o * n, c = i.length, l = 0;
|
|
@@ -2726,15 +3145,15 @@ function Ga(e, t, n = .7) {
|
|
|
2726
3145
|
let u = t * 180 / Math.PI, d = u > 0 ? 1 - l / u : 0;
|
|
2727
3146
|
return Math.min(Math.max(d, 0), 1);
|
|
2728
3147
|
}
|
|
2729
|
-
function
|
|
3148
|
+
function Ro(e) {
|
|
2730
3149
|
return e.split(/\s+/).filter((e) => e.length > 0);
|
|
2731
3150
|
}
|
|
2732
|
-
function
|
|
3151
|
+
function zo(e, t) {
|
|
2733
3152
|
let n = /\S+/g, r = 0;
|
|
2734
3153
|
for (; n.exec(e) !== null;) if (r++, r === t) return e.slice(n.lastIndex);
|
|
2735
3154
|
return "";
|
|
2736
3155
|
}
|
|
2737
|
-
function
|
|
3156
|
+
function Bo(e, t) {
|
|
2738
3157
|
if (t <= e[0]) return 0;
|
|
2739
3158
|
if (t >= e[e.length - 1]) return e.length - 1;
|
|
2740
3159
|
let n = 0, r = e.length - 1;
|
|
@@ -2744,12 +3163,12 @@ function Ja(e, t) {
|
|
|
2744
3163
|
}
|
|
2745
3164
|
return n;
|
|
2746
3165
|
}
|
|
2747
|
-
function
|
|
3166
|
+
function Vo(e, t, n) {
|
|
2748
3167
|
return e + (t - e) * n;
|
|
2749
3168
|
}
|
|
2750
3169
|
//#endregion
|
|
2751
3170
|
//#region src/managers/IESManager.js
|
|
2752
|
-
var
|
|
3171
|
+
var Ho = class {
|
|
2753
3172
|
constructor(e, t = {}) {
|
|
2754
3173
|
this.pathTracer = e, this._onReset = t.onReset || null, this._issues = t.issues ?? null, this.texture = null, this.entries = [], this._gridWidth = 128, this._gridHeight = 128;
|
|
2755
3174
|
}
|
|
@@ -2758,14 +3177,14 @@ var Xa = class {
|
|
|
2758
3177
|
this._gridWidth = t, this._gridHeight = n;
|
|
2759
3178
|
let r = (await Promise.all(e.map(async (e) => {
|
|
2760
3179
|
try {
|
|
2761
|
-
let { file: r, release: i } = await m().fetch(e.url), a =
|
|
3180
|
+
let { file: r, release: i } = await m().fetch(e.url), a = No(await r.text().finally(i), e.name);
|
|
2762
3181
|
return {
|
|
2763
3182
|
it: e,
|
|
2764
3183
|
profile: a,
|
|
2765
|
-
grid:
|
|
3184
|
+
grid: Fo(a, t, n)
|
|
2766
3185
|
};
|
|
2767
3186
|
} catch (t) {
|
|
2768
|
-
return this._issues?.warn(
|
|
3187
|
+
return this._issues?.warn(Ze.ASSET_UNREACHABLE, `IES profile "${e.name}" could not be loaded: ${t.message}`, {
|
|
2769
3188
|
url: e.url,
|
|
2770
3189
|
asset: "ies",
|
|
2771
3190
|
cause: t.message
|
|
@@ -2780,19 +3199,19 @@ var Xa = class {
|
|
|
2780
3199
|
let r = t[e];
|
|
2781
3200
|
o[n + e * 4 + 0] = r, o[n + e * 4 + 1] = r, o[n + e * 4 + 2] = r, o[n + e * 4 + 3] = 255;
|
|
2782
3201
|
}
|
|
2783
|
-
let i = r[e].profile, c =
|
|
3202
|
+
let i = r[e].profile, c = Io(i);
|
|
2784
3203
|
s.push({
|
|
2785
3204
|
name: r[e].it.name,
|
|
2786
3205
|
index: e,
|
|
2787
3206
|
maxCandela: i.maxCandela,
|
|
2788
3207
|
photometricType: i.photometricType,
|
|
2789
3208
|
suggestedAngle: c,
|
|
2790
|
-
suggestedPenumbra:
|
|
3209
|
+
suggestedPenumbra: Lo(i, c),
|
|
2791
3210
|
lumens: i.lumens
|
|
2792
3211
|
});
|
|
2793
3212
|
}
|
|
2794
|
-
let c = new
|
|
2795
|
-
c.format = Q, c.type =
|
|
3213
|
+
let c = new ur(o, t, n, i);
|
|
3214
|
+
c.format = Q, c.type = Ir, c.minFilter = X, c.magFilter = X, c.generateMipmaps = !1, c.needsUpdate = !0;
|
|
2796
3215
|
let l = this.texture;
|
|
2797
3216
|
return this.texture = c, this.entries = s, this.pathTracer.iesProfiles = c, this.pathTracer.shaderBuilder?.updateIESProfiles?.(c), l?.dispose?.(), this.entries.map(({ name: e, index: t }) => ({
|
|
2798
3217
|
name: e,
|
|
@@ -2816,14 +3235,14 @@ var Xa = class {
|
|
|
2816
3235
|
if (t == null) delete i.userData.ies;
|
|
2817
3236
|
else {
|
|
2818
3237
|
let e = this.entries.find((e) => e.name === t);
|
|
2819
|
-
if (!e) return this._issues?.record(
|
|
3238
|
+
if (!e) return this._issues?.record(Ze.ASSET_UNREACHABLE, `no IES profile named "${t}" is loaded — the light keeps its plain distribution`, {
|
|
2820
3239
|
name: t,
|
|
2821
3240
|
asset: "ies"
|
|
2822
3241
|
}), a;
|
|
2823
3242
|
l = Number.isFinite(e.lumens) ? e.lumens : null, i.userData.ies = {
|
|
2824
3243
|
name: e.name,
|
|
2825
3244
|
index: e.index,
|
|
2826
|
-
intensity:
|
|
3245
|
+
intensity: Uo(n),
|
|
2827
3246
|
fixtureLumens: l
|
|
2828
3247
|
}, 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);
|
|
2829
3248
|
}
|
|
@@ -2846,16 +3265,16 @@ var Xa = class {
|
|
|
2846
3265
|
return t && t.isSpotLight ? t : null;
|
|
2847
3266
|
}
|
|
2848
3267
|
};
|
|
2849
|
-
function
|
|
3268
|
+
function Uo(e) {
|
|
2850
3269
|
return Math.max(0, Math.min(1, e));
|
|
2851
3270
|
}
|
|
2852
3271
|
//#endregion
|
|
2853
3272
|
//#region src/Passes/OIDNDenoiser.js
|
|
2854
|
-
var
|
|
2855
|
-
async function
|
|
2856
|
-
return
|
|
3273
|
+
var Wo = Ke("oidn"), Go = 16, Ko = null;
|
|
3274
|
+
async function qo() {
|
|
3275
|
+
return Ko ||= (await import("oidn-web/dist/oidn.js")).initUNetFromBuffer, Ko;
|
|
2857
3276
|
}
|
|
2858
|
-
var
|
|
3277
|
+
var Jo = {
|
|
2859
3278
|
QUALITY_MODELS: {
|
|
2860
3279
|
fast: {
|
|
2861
3280
|
model: "rt_hdr_alb_nrm_small",
|
|
@@ -2879,9 +3298,9 @@ var no = {
|
|
|
2879
3298
|
oidnQuality: "fast",
|
|
2880
3299
|
tileSize: 1024
|
|
2881
3300
|
}
|
|
2882
|
-
},
|
|
2883
|
-
const WG: u32 = ${
|
|
2884
|
-
const GROUPS: u32 = ${
|
|
3301
|
+
}, Yo = .18, Xo = 256, Zo = 256, Qo = `
|
|
3302
|
+
const WG: u32 = ${Xo}u;
|
|
3303
|
+
const GROUPS: u32 = ${Zo}u;
|
|
2885
3304
|
|
|
2886
3305
|
@group(0) @binding(0) var<storage, read> col: array<vec4<f32>>;
|
|
2887
3306
|
@group(0) @binding(1) var<storage, read_write> partials: array<f32>;
|
|
@@ -2900,7 +3319,7 @@ fn treeSum( lid: u32 ) {
|
|
|
2900
3319
|
}
|
|
2901
3320
|
}
|
|
2902
3321
|
|
|
2903
|
-
@compute @workgroup_size(${
|
|
3322
|
+
@compute @workgroup_size(${Xo})
|
|
2904
3323
|
fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
|
|
2905
3324
|
@builtin(local_invocation_id) lid: vec3<u32>,
|
|
2906
3325
|
@builtin(workgroup_id) wid: vec3<u32> ) {
|
|
@@ -2923,7 +3342,7 @@ fn reduce( @builtin(global_invocation_id) gid: vec3<u32>,
|
|
|
2923
3342
|
if ( lid.x == 0u ) { partials[ wid.x ] = sdata[ 0 ]; }
|
|
2924
3343
|
}
|
|
2925
3344
|
|
|
2926
|
-
@compute @workgroup_size(${
|
|
3345
|
+
@compute @workgroup_size(${Xo})
|
|
2927
3346
|
fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
|
|
2928
3347
|
|
|
2929
3348
|
var v = 0.0;
|
|
@@ -2933,12 +3352,12 @@ fn finalize( @builtin(local_invocation_id) lid: vec3<u32> ) {
|
|
|
2933
3352
|
treeSum( lid.x );
|
|
2934
3353
|
|
|
2935
3354
|
if ( lid.x == 0u ) {
|
|
2936
|
-
let scale = ${
|
|
3355
|
+
let scale = ${Yo} / exp2( sdata[ 0 ] / f32( params.x ) );
|
|
2937
3356
|
// Mirrors the CPU guard: a non-finite or non-positive scale means no scaling at all.
|
|
2938
3357
|
scaleOut[ 0 ] = select( 1.0, scale, scale > 0.0 && scale < 3.4e38 );
|
|
2939
3358
|
}
|
|
2940
3359
|
}
|
|
2941
|
-
`,
|
|
3360
|
+
`, $o = "\n@group(0) @binding(0) var<storage, read_write> col: array<vec4<f32>>;\n@group(0) @binding(1) var<storage, read> scaleBuf: array<f32>;\n\n@compute @workgroup_size(64)\nfn main( @builtin(global_invocation_id) gid: vec3<u32>,\n @builtin(num_workgroups) nwg: vec3<u32> ) {\n let i = gid.y * nwg.x * 64u + gid.x;\n if ( i >= arrayLength( &col ) ) { return; }\n let c = col[ i ];\n col[ i ] = vec4<f32>( c.xyz * scaleBuf[ 0 ], c.w );\n}\n", es = 64, ts = 32768, ns = 16, rs = 32, is = `
|
|
2942
3361
|
struct UnpackParams {
|
|
2943
3362
|
srcWidth: u32,
|
|
2944
3363
|
tileX: u32,
|
|
@@ -2956,7 +3375,7 @@ struct UnpackParams {
|
|
|
2956
3375
|
@group(0) @binding(3) var<storage, read> inColor: array<vec4<f32>>;
|
|
2957
3376
|
@group(0) @binding(4) var dst: texture_storage_2d<rgba16float, write>;
|
|
2958
3377
|
|
|
2959
|
-
@compute @workgroup_size(${
|
|
3378
|
+
@compute @workgroup_size(${ns}, ${ns})
|
|
2960
3379
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
2961
3380
|
|
|
2962
3381
|
if ( gid.x >= P.tileW || gid.y >= P.tileH ) { return; }
|
|
@@ -2970,18 +3389,18 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2970
3389
|
// survives the denoise.
|
|
2971
3390
|
textureStore( dst, vec2<u32>( px, py ), vec4<f32>( src[ si ].xyz / scaleBuf[ 0 ], inColor[ si ].w ) );
|
|
2972
3391
|
}
|
|
2973
|
-
`,
|
|
3392
|
+
`, as = 8, os = `
|
|
2974
3393
|
@group(0) @binding(0) var src: texture_2d<f32>;
|
|
2975
3394
|
@group(0) @binding(1) var<storage, read_write> dst: array<vec4<f32>>;
|
|
2976
3395
|
@group(0) @binding(2) var<uniform> size: vec2<u32>;
|
|
2977
3396
|
|
|
2978
|
-
@compute @workgroup_size(${
|
|
3397
|
+
@compute @workgroup_size(${as}, ${as})
|
|
2979
3398
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
2980
3399
|
|
|
2981
3400
|
if ( gid.x >= size.x || gid.y >= size.y ) { return; }
|
|
2982
3401
|
dst[ gid.y * size.x + gid.x ] = textureLoad( src, gid.xy, 0 );
|
|
2983
3402
|
}
|
|
2984
|
-
`,
|
|
3403
|
+
`, ss = class extends fr {
|
|
2985
3404
|
constructor(e, t = {}) {
|
|
2986
3405
|
if (super(), !e) throw Error("OIDNDenoiser requires a renderer");
|
|
2987
3406
|
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 = {
|
|
@@ -2995,14 +3414,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
2995
3414
|
width: 0,
|
|
2996
3415
|
height: 0
|
|
2997
3416
|
}, this.config = {
|
|
2998
|
-
...
|
|
3417
|
+
...Jo.DEFAULT_OPTIONS,
|
|
2999
3418
|
...t
|
|
3000
3419
|
}, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
|
|
3001
3420
|
isDenoising: !1,
|
|
3002
3421
|
isLoading: !1,
|
|
3003
3422
|
abortController: null
|
|
3004
3423
|
}, 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) => {
|
|
3005
|
-
|
|
3424
|
+
Wo.error("init failed:", e), this.dispatchEvent({
|
|
3006
3425
|
type: "error",
|
|
3007
3426
|
error: e
|
|
3008
3427
|
});
|
|
@@ -3016,7 +3435,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3016
3435
|
}
|
|
3017
3436
|
}
|
|
3018
3437
|
expectsCleanAux(e = this.quality) {
|
|
3019
|
-
let { QUALITY_MODELS: t } =
|
|
3438
|
+
let { QUALITY_MODELS: t } = Jo;
|
|
3020
3439
|
return (t[e] || t.balance).cleanAux;
|
|
3021
3440
|
}
|
|
3022
3441
|
getRuntimeInfo() {
|
|
@@ -3031,8 +3450,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3031
3450
|
_resolveTileSize() {
|
|
3032
3451
|
let e = Math.max(this._renderWidth, this._renderHeight);
|
|
3033
3452
|
if (!e) return this.maxTileSize;
|
|
3034
|
-
let t = Math.ceil(e /
|
|
3035
|
-
return t <= this.maxTileSize ? t : Math.max(
|
|
3453
|
+
let t = Math.ceil(e / Go) * Go;
|
|
3454
|
+
return t <= this.maxTileSize ? t : Math.max(Go, Math.floor(this.maxTileSize / Go) * Go);
|
|
3036
3455
|
}
|
|
3037
3456
|
_setupUNetDenoiser() {
|
|
3038
3457
|
return this.state.isLoading ? (this._reloadPending = !0, Promise.resolve()) : (this._loading = this._loadUNet(), this._loading);
|
|
@@ -3046,7 +3465,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3046
3465
|
try {
|
|
3047
3466
|
await this._loadUNetWeights();
|
|
3048
3467
|
} catch (e) {
|
|
3049
|
-
|
|
3468
|
+
Wo.error("UNet weights failed to load:", e), this.dispatchEvent({
|
|
3050
3469
|
type: "error",
|
|
3051
3470
|
error: /* @__PURE__ */ Error(`Denoiser loading failed: ${e.message}`),
|
|
3052
3471
|
url: this._generateTzaUrl()
|
|
@@ -3072,26 +3491,26 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3072
3491
|
let e = this.backendParamsGetter();
|
|
3073
3492
|
this.gpuDevice = e?.device ?? null, n = e?.device ? e : void 0;
|
|
3074
3493
|
}
|
|
3075
|
-
this.unet = await (await
|
|
3494
|
+
this.unet = await (await qo())(await this._fetchWeights(e), n, {
|
|
3076
3495
|
aux: !0,
|
|
3077
3496
|
hdr: !0,
|
|
3078
3497
|
maxTileSize: t,
|
|
3079
3498
|
dynamicTile: !1
|
|
3080
|
-
}), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }),
|
|
3499
|
+
}), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), Wo.debug("UNet weights loaded:", e);
|
|
3081
3500
|
}
|
|
3082
3501
|
_fetchWeights(e) {
|
|
3083
3502
|
let t = this._weights.get(e);
|
|
3084
3503
|
return t || (t = m().fetch(e, { policy: C.IMMUTABLE }).then(({ file: e, release: t }) => e.arrayBuffer().finally(t)), t.catch(() => this._weights.delete(e)), this._weights.set(e, t)), t;
|
|
3085
3504
|
}
|
|
3086
3505
|
_generateTzaUrl() {
|
|
3087
|
-
let { oidnWeightsBaseUrl: e } = ot(), { QUALITY_MODELS: t } =
|
|
3506
|
+
let { oidnWeightsBaseUrl: e } = ot(), { QUALITY_MODELS: t } = Jo;
|
|
3088
3507
|
return `${e}${(t[this.quality] || t.balance).model}.tza`;
|
|
3089
3508
|
}
|
|
3090
3509
|
async updateConfiguration(e) {
|
|
3091
3510
|
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());
|
|
3092
3511
|
}
|
|
3093
3512
|
async updateQuality(e) {
|
|
3094
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
3513
|
+
if (!Object.prototype.hasOwnProperty.call(Jo.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Jo.QUALITY_MODELS).join(", ")}`);
|
|
3095
3514
|
await this.updateConfiguration({ oidnQuality: e });
|
|
3096
3515
|
}
|
|
3097
3516
|
async start({ continuous: e = !1 } = {}) {
|
|
@@ -3102,7 +3521,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3102
3521
|
continuous: e
|
|
3103
3522
|
});
|
|
3104
3523
|
let t = performance.now(), n = await this.execute(e);
|
|
3105
|
-
return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t,
|
|
3524
|
+
return n && (this.renderer?.resetState?.(), this.lastDenoiseMs = performance.now() - t, Wo.debug(`denoise complete in ${We.ms(this.lastDenoiseMs)} · quality ${this.quality}`)), n;
|
|
3106
3525
|
}
|
|
3107
3526
|
async execute(e = !1) {
|
|
3108
3527
|
if (!this.enabled || !this.unet) return !1;
|
|
@@ -3111,7 +3530,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3111
3530
|
try {
|
|
3112
3531
|
return await this._executeUNetGPU(e) !== !1;
|
|
3113
3532
|
} catch (e) {
|
|
3114
|
-
return e.name === "AbortError" ?
|
|
3533
|
+
return e.name === "AbortError" ? Wo.debug("denoise aborted") : Wo.error("denoise error:", e), !1;
|
|
3115
3534
|
} finally {
|
|
3116
3535
|
this._runId === t && (this.state.isDenoising = !1, this.state.abortController = null), this.dispatchEvent({
|
|
3117
3536
|
type: "end",
|
|
@@ -3121,11 +3540,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3121
3540
|
}
|
|
3122
3541
|
async _executeUNetGPU(e = !1) {
|
|
3123
3542
|
let t = this._renderWidth, n = this._renderHeight;
|
|
3124
|
-
if (!this.getGPUTextures) return
|
|
3543
|
+
if (!this.getGPUTextures) return Wo.warn("GPU mode enabled but getGPUTextures not provided"), !1;
|
|
3125
3544
|
let r = this.getGPUTextures({ continuous: e });
|
|
3126
|
-
if (!r?.color) return
|
|
3545
|
+
if (!r?.color) return Wo.warn("GPU textures not ready yet"), !1;
|
|
3127
3546
|
let i = this.gpuDevice;
|
|
3128
|
-
if (!i) return
|
|
3547
|
+
if (!i) return Wo.warn("gpuDevice not available"), !1;
|
|
3129
3548
|
this._ensureGPUInputBuffers(t, n), this._copyInputs(i, r, t, n), this._computeInputScale(i, t * n), this._applyColorScale(i, t * n), !e && !this._hasOutput && this._unpackToTexture(this._gpuInputBuffers.color, t, {
|
|
3130
3549
|
x: 0,
|
|
3131
3550
|
y: 0,
|
|
@@ -3169,7 +3588,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3169
3588
|
resource: { buffer: this._packParams }
|
|
3170
3589
|
}
|
|
3171
3590
|
]
|
|
3172
|
-
})), o.dispatchWorkgroups(Math.ceil(n /
|
|
3591
|
+
})), o.dispatchWorkgroups(Math.ceil(n / as), Math.ceil(r / as))) : i.copyTextureToBuffer({
|
|
3173
3592
|
texture: t,
|
|
3174
3593
|
mipLevel: 0
|
|
3175
3594
|
}, {
|
|
@@ -3233,7 +3652,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3233
3652
|
compute: {
|
|
3234
3653
|
module: e.createShaderModule({
|
|
3235
3654
|
label: "oidn-pack",
|
|
3236
|
-
code:
|
|
3655
|
+
code: os
|
|
3237
3656
|
}),
|
|
3238
3657
|
entryPoint: "main"
|
|
3239
3658
|
}
|
|
@@ -3286,7 +3705,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3286
3705
|
});
|
|
3287
3706
|
let t = e.createShaderModule({
|
|
3288
3707
|
label: "oidn-autoexposure",
|
|
3289
|
-
code:
|
|
3708
|
+
code: Qo
|
|
3290
3709
|
}), n = e.createPipelineLayout({ bindGroupLayouts: [this._lumLayout] });
|
|
3291
3710
|
this._lumReducePipeline = e.createComputePipeline({
|
|
3292
3711
|
label: "oidn-autoexposure-reduce",
|
|
@@ -3310,7 +3729,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3310
3729
|
compute: {
|
|
3311
3730
|
module: e.createShaderModule({
|
|
3312
3731
|
label: "oidn-color-scale",
|
|
3313
|
-
code:
|
|
3732
|
+
code: $o
|
|
3314
3733
|
}),
|
|
3315
3734
|
entryPoint: "main"
|
|
3316
3735
|
}
|
|
@@ -3320,7 +3739,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3320
3739
|
compute: {
|
|
3321
3740
|
module: e.createShaderModule({
|
|
3322
3741
|
label: "oidn-output-unpack",
|
|
3323
|
-
code:
|
|
3742
|
+
code: is
|
|
3324
3743
|
}),
|
|
3325
3744
|
entryPoint: "main"
|
|
3326
3745
|
}
|
|
@@ -3330,7 +3749,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3330
3749
|
size: 4
|
|
3331
3750
|
}), this._lumPartials = e.createBuffer({
|
|
3332
3751
|
label: "oidn-autoexposure-partials",
|
|
3333
|
-
size:
|
|
3752
|
+
size: Zo * 4,
|
|
3334
3753
|
usage: GPUBufferUsage.STORAGE
|
|
3335
3754
|
}), this._lumParams = e.createBuffer({
|
|
3336
3755
|
label: "oidn-autoexposure-params",
|
|
@@ -3382,13 +3801,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3382
3801
|
0
|
|
3383
3802
|
]));
|
|
3384
3803
|
let n = e.createCommandEncoder({ label: "oidn-autoexposure" }), r = n.beginComputePass({ label: "oidn-autoexposure-reduce" });
|
|
3385
|
-
r.setPipeline(this._lumReducePipeline), r.setBindGroup(0, this._lumBindGroup), r.dispatchWorkgroups(
|
|
3804
|
+
r.setPipeline(this._lumReducePipeline), r.setBindGroup(0, this._lumBindGroup), r.dispatchWorkgroups(Zo, 1, 1), r.end();
|
|
3386
3805
|
let i = n.beginComputePass({ label: "oidn-autoexposure-finalize" });
|
|
3387
3806
|
i.setPipeline(this._lumFinalizePipeline), i.setBindGroup(0, this._lumBindGroup), i.dispatchWorkgroups(1, 1, 1), i.end(), e.queue.submit([n.finish()]);
|
|
3388
3807
|
}
|
|
3389
3808
|
_applyColorScale(e, t) {
|
|
3390
3809
|
if (!this._ensureScalePipelines(e)) return;
|
|
3391
|
-
let n = Math.ceil(t /
|
|
3810
|
+
let n = Math.ceil(t / es), r = Math.min(n, ts), i = Math.ceil(n / r), a = e.createCommandEncoder({ label: "oidn-color-scale" }), o = a.beginComputePass({ label: "oidn-color-scale" });
|
|
3392
3811
|
o.setPipeline(this._colorScalePipeline), o.setBindGroup(0, this._colorScaleBindGroup), o.dispatchWorkgroups(r, i, 1), o.end(), e.queue.submit([a.finish()]);
|
|
3393
3812
|
}
|
|
3394
3813
|
get outputTexture() {
|
|
@@ -3415,7 +3834,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3415
3834
|
width: t,
|
|
3416
3835
|
height: n,
|
|
3417
3836
|
depth: 1
|
|
3418
|
-
}, r.type =
|
|
3837
|
+
}, r.type = mr, r.format = Q, r.colorSpace = Cr, r.minFilter = Z, r.magFilter = Z, r.wrapS = or, r.wrapT = or, r.generateMipmaps = !1, r.flipY = !1, this._outTexture = r, this._outTexSize = {
|
|
3419
3838
|
width: t,
|
|
3420
3839
|
height: n
|
|
3421
3840
|
};
|
|
@@ -3433,7 +3852,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3433
3852
|
if (this._ensureOutputTexture(i, this._renderWidth, this._renderHeight), !this._outGPUTexture) return;
|
|
3434
3853
|
let l = i.createBuffer({
|
|
3435
3854
|
label: "oidn-unpack-params",
|
|
3436
|
-
size:
|
|
3855
|
+
size: rs,
|
|
3437
3856
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
3438
3857
|
});
|
|
3439
3858
|
try {
|
|
@@ -3473,7 +3892,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3473
3892
|
}
|
|
3474
3893
|
]
|
|
3475
3894
|
}), u = i.createCommandEncoder({ label: "oidn-output-unpack" }), d = u.beginComputePass({ label: "oidn-output-unpack" });
|
|
3476
|
-
d.setPipeline(this._unpackPipeline), d.setBindGroup(0, n), d.dispatchWorkgroups(Math.ceil(s /
|
|
3895
|
+
d.setPipeline(this._unpackPipeline), d.setBindGroup(0, n), d.dispatchWorkgroups(Math.ceil(s / ns), Math.ceil(c / ns), 1), d.end(), i.queue.submit([u.finish()]), r && (this._hasOutput = !0);
|
|
3477
3896
|
} finally {
|
|
3478
3897
|
l.destroy();
|
|
3479
3898
|
}
|
|
@@ -3522,7 +3941,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3522
3941
|
}
|
|
3523
3942
|
_displayGPUOutput({ data: e, width: t, height: n }) {
|
|
3524
3943
|
if (!this.gpuDevice) {
|
|
3525
|
-
|
|
3944
|
+
Wo.error("gpuDevice not available for the output picture");
|
|
3526
3945
|
return;
|
|
3527
3946
|
}
|
|
3528
3947
|
this._unpackToTexture(e, t, {
|
|
@@ -3533,7 +3952,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3533
3952
|
});
|
|
3534
3953
|
}
|
|
3535
3954
|
abort() {
|
|
3536
|
-
this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1,
|
|
3955
|
+
this._pendingStart = !1, this._pendingStartContinuous = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this.state.isDenoising = !1, Wo.debug("denoise aborted"));
|
|
3537
3956
|
}
|
|
3538
3957
|
get hasOutput() {
|
|
3539
3958
|
return this._hasOutput;
|
|
@@ -3544,13 +3963,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3544
3963
|
setSize(e, t) {
|
|
3545
3964
|
if (e <= 0 || t <= 0) throw Error(`Invalid dimensions: ${e}x${t}`);
|
|
3546
3965
|
this._renderWidth = e, this._renderHeight = t, this._hasOutput = !1, this.lastDenoiseMs = 0, this._setupUNetDenoiser().catch((e) => {
|
|
3547
|
-
|
|
3966
|
+
Wo.error("reinitialize after size change failed:", e);
|
|
3548
3967
|
});
|
|
3549
3968
|
}
|
|
3550
3969
|
dispose() {
|
|
3551
|
-
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?.(),
|
|
3970
|
+
this.abort(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._releaseOutputTexture(), this._colorScalePipeline = null, this._lumReducePipeline = null, this._lumFinalizePipeline = null, this._lumLayout = null, this._unpackPipeline = null, this.unet = null, this._weights.clear(), this.state.abortController = null, this.removeAllListeners?.(), Wo.debug("disposed");
|
|
3552
3971
|
}
|
|
3553
|
-
},
|
|
3972
|
+
}, cs = Object.freeze({
|
|
3554
3973
|
maxLength: 8,
|
|
3555
3974
|
smoothLength: 2,
|
|
3556
3975
|
roughStart: .45,
|
|
@@ -3558,7 +3977,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3558
3977
|
depthTolerance: .05,
|
|
3559
3978
|
normalTolerance: .8,
|
|
3560
3979
|
movedLength: 2
|
|
3561
|
-
}),
|
|
3980
|
+
}), ls = 8, us = 304, ds = 16, fs = 1, ps = 2, ms = 4, hs = 1073741824, gs = "\nstruct Params {\n size: vec2<u32>,\n reset: u32,\n flags: u32,\n maxLength: f32,\n smoothLength: f32,\n depthTolerance: f32,\n normalTolerance: f32,\n roughStart: f32,\n roughEnd: f32,\n samples: f32,\n historyScale: f32,\n camWorld: mat4x4<f32>,\n projInv: mat4x4<f32>,\n prevViewProj: mat4x4<f32>,\n prevCamPos: vec4<f32>,\n moved: vec4<u32>,\n movedLength: f32,\n prevCamDir: vec4<f32>,\n};\n\n@group(0) @binding(0) var<uniform> P: Params;\n\nfn finite3( v: vec3<f32> ) -> bool {\n let e = bitcast<vec3<u32>>( v ) & vec3<u32>( 0x7f800000u );\n return all( e != vec3<u32>( 0x7f800000u ) );\n}\n\n// [0,1]-encoded in and out, renormalised like FinalWrite's clean aux.\nfn mixNormal( h: vec3<f32>, c: vec3<f32>, t: f32 ) -> vec3<f32> {\n let m = mix( h * 2.0 - 1.0, c * 2.0 - 1.0, t );\n let l = length( m );\n return select( c, m / l * 0.5 + 0.5, l > 1e-4 );\n}\n", _s = gs + `
|
|
3562
3981
|
@group(0) @binding(1) var geoCur: texture_2d<f32>;
|
|
3563
3982
|
@group(0) @binding(2) var geoPrev: texture_2d<f32>;
|
|
3564
3983
|
@group(0) @binding(3) var<storage, read_write> picked: array<i32>;
|
|
@@ -3584,7 +4003,7 @@ fn movedIndex( leaf: u32 ) -> i32 {
|
|
|
3584
4003
|
|
|
3585
4004
|
}
|
|
3586
4005
|
|
|
3587
|
-
@compute @workgroup_size(${
|
|
4006
|
+
@compute @workgroup_size(${ls}, ${ls})
|
|
3588
4007
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
3589
4008
|
|
|
3590
4009
|
if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
|
|
@@ -3594,12 +4013,12 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3594
4013
|
var pick = -1;
|
|
3595
4014
|
var movedFlag = 0;
|
|
3596
4015
|
|
|
3597
|
-
if ( P.reset == 0u && g.w < ${
|
|
4016
|
+
if ( P.reset == 0u && g.w < ${Gr.toFixed(1)} ) {
|
|
3598
4017
|
|
|
3599
4018
|
let size = vec2<f32>( P.size );
|
|
3600
4019
|
let uv = ( vec2<f32>( gid.xy ) + 0.5 ) / size;
|
|
3601
4020
|
// Depth is along the ray: from the camera, or from its image plane when orthographic.
|
|
3602
|
-
let ortho = ( P.flags & ${
|
|
4021
|
+
let ortho = ( P.flags & ${ms}u ) != 0u;
|
|
3603
4022
|
let ndc = vec2<f32>( uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0 );
|
|
3604
4023
|
var origin = P.camWorld[ 3 ].xyz;
|
|
3605
4024
|
var dir: vec3<f32>;
|
|
@@ -3623,7 +4042,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3623
4042
|
let toPrev = movedToPrev[ u32( m ) ];
|
|
3624
4043
|
wp = ( toPrev * vec4<f32>( wp, 1.0 ) ).xyz;
|
|
3625
4044
|
n = normalize( ( toPrev * vec4<f32>( n, 0.0 ) ).xyz );
|
|
3626
|
-
movedFlag = ${
|
|
4045
|
+
movedFlag = ${hs};
|
|
3627
4046
|
|
|
3628
4047
|
}
|
|
3629
4048
|
|
|
@@ -3660,7 +4079,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3660
4079
|
if ( pick >= 0 ) { atomicAdd( &copies[ u32( pick ) ], 1u ); }
|
|
3661
4080
|
|
|
3662
4081
|
}
|
|
3663
|
-
`,
|
|
4082
|
+
`, vs = gs + `
|
|
3664
4083
|
@group(0) @binding(1) var curColor: texture_2d<f32>;
|
|
3665
4084
|
@group(0) @binding(2) var curAlbedo: texture_2d<f32>;
|
|
3666
4085
|
@group(0) @binding(3) var curNormal: texture_2d<f32>;
|
|
@@ -3674,7 +4093,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3674
4093
|
@group(0) @binding(11) var outAlbedo: texture_storage_2d<rgba32float, write>;
|
|
3675
4094
|
@group(0) @binding(12) var outNormal: texture_storage_2d<rgba32float, write>;
|
|
3676
4095
|
|
|
3677
|
-
@compute @workgroup_size(${
|
|
4096
|
+
@compute @workgroup_size(${ls}, ${ls})
|
|
3678
4097
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
3679
4098
|
|
|
3680
4099
|
if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
|
|
@@ -3690,8 +4109,8 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3690
4109
|
var ha = ca.xyz;
|
|
3691
4110
|
var hn = cn.xyz;
|
|
3692
4111
|
let raw = picked[ gid.y * P.size.x + gid.x ];
|
|
3693
|
-
let movedPx = raw >= 0 && ( raw & ${
|
|
3694
|
-
let pick = select( raw, raw & ~${
|
|
4112
|
+
let movedPx = raw >= 0 && ( raw & ${hs} ) != 0;
|
|
4113
|
+
let pick = select( raw, raw & ~${hs}, raw >= 0 );
|
|
3695
4114
|
|
|
3696
4115
|
if ( pick >= 0 ) {
|
|
3697
4116
|
|
|
@@ -3705,7 +4124,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3705
4124
|
ha = a.xyz;
|
|
3706
4125
|
hn = textureLoad( histNormal, q, 0 ).xyz;
|
|
3707
4126
|
len = a.w;
|
|
3708
|
-
if ( ( P.flags & ${
|
|
4127
|
+
if ( ( P.flags & ${ps}u ) != 0u ) { len = len / f32( max( copies[ u32( pick ) ], 1u ) ); }
|
|
3709
4128
|
|
|
3710
4129
|
}
|
|
3711
4130
|
|
|
@@ -3719,11 +4138,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3719
4138
|
|
|
3720
4139
|
textureStore( outColor, p, vec4<f32>( mix( hc, cur.xyz, t ), cur.w ) );
|
|
3721
4140
|
textureStore( outAlbedo, p, vec4<f32>( mix( ha, ca.xyz, t ), newLen ) );
|
|
3722
|
-
let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${
|
|
4141
|
+
let n = select( cn.xyz, mixNormal( hn, cn.xyz, t ), ( P.flags & ${fs}u ) != 0u );
|
|
3723
4142
|
textureStore( outNormal, p, vec4<f32>( n, cn.w ) );
|
|
3724
4143
|
|
|
3725
4144
|
}
|
|
3726
|
-
`,
|
|
4145
|
+
`, ys = gs + `
|
|
3727
4146
|
@group(0) @binding(1) var accColor: texture_2d<f32>;
|
|
3728
4147
|
@group(0) @binding(2) var accAlbedo: texture_2d<f32>;
|
|
3729
4148
|
@group(0) @binding(3) var accNormal: texture_2d<f32>;
|
|
@@ -3734,7 +4153,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3734
4153
|
@group(0) @binding(8) var outAlbedo: texture_storage_2d<rgba32float, write>;
|
|
3735
4154
|
@group(0) @binding(9) var outNormal: texture_storage_2d<rgba32float, write>;
|
|
3736
4155
|
|
|
3737
|
-
@compute @workgroup_size(${
|
|
4156
|
+
@compute @workgroup_size(${ls}, ${ls})
|
|
3738
4157
|
fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
3739
4158
|
|
|
3740
4159
|
if ( gid.x >= P.size.x || gid.y >= P.size.y ) { return; }
|
|
@@ -3768,32 +4187,32 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3768
4187
|
let t = P.samples / max( k + P.samples, 1e-6 );
|
|
3769
4188
|
textureStore( outColor, p, vec4<f32>( mix( hc, ac.xyz, t ), ac.w ) );
|
|
3770
4189
|
textureStore( outAlbedo, p, vec4<f32>( mix( ha, aa.xyz, t ), min( k + P.samples, P.maxLength ) ) );
|
|
3771
|
-
let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${
|
|
4190
|
+
let n = select( an.xyz, mixNormal( hn, an.xyz, t ), ( P.flags & ${fs}u ) != 0u );
|
|
3772
4191
|
textureStore( outNormal, p, vec4<f32>( n, an.w ) );
|
|
3773
4192
|
|
|
3774
4193
|
}
|
|
3775
|
-
`,
|
|
4194
|
+
`, bs = (e) => ({
|
|
3776
4195
|
binding: e,
|
|
3777
4196
|
visibility: GPUShaderStage.COMPUTE,
|
|
3778
4197
|
texture: { sampleType: "unfilterable-float" }
|
|
3779
|
-
}),
|
|
4198
|
+
}), xs = (e) => ({
|
|
3780
4199
|
binding: e,
|
|
3781
4200
|
visibility: GPUShaderStage.COMPUTE,
|
|
3782
4201
|
storageTexture: {
|
|
3783
4202
|
access: "write-only",
|
|
3784
4203
|
format: "rgba32float"
|
|
3785
4204
|
}
|
|
3786
|
-
}),
|
|
4205
|
+
}), Ss = (e, t) => ({
|
|
3787
4206
|
binding: e,
|
|
3788
4207
|
visibility: GPUShaderStage.COMPUTE,
|
|
3789
4208
|
buffer: { type: t }
|
|
3790
|
-
}),
|
|
4209
|
+
}), Cs = class {
|
|
3791
4210
|
constructor(e) {
|
|
3792
4211
|
this.device = e, this.settings = {
|
|
3793
|
-
...
|
|
4212
|
+
...cs,
|
|
3794
4213
|
cleanAux: !1,
|
|
3795
4214
|
splitCopies: !0
|
|
3796
|
-
}, 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(
|
|
4215
|
+
}, this.valid = !1, this.width = 0, this.height = 0, this._sets = null, this._current = 0, this._picked = null, this._copies = null, this._paramsBuffer = null, this._pipelines = null, this._movedLeaves = null, this._movedToPrev = null, this._movedCapacity = 0, this._movedCount = 0, this._paramData = new ArrayBuffer(us), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._prevViewProj = new Float32Array(16), this._prevCamPos = new Float32Array(4), this._prevCamDir = new Float32Array(4);
|
|
3797
4216
|
}
|
|
3798
4217
|
get textures() {
|
|
3799
4218
|
return this.valid ? this._sets[this._current] : null;
|
|
@@ -3901,23 +4320,23 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3901
4320
|
}),
|
|
3902
4321
|
layout: i
|
|
3903
4322
|
};
|
|
3904
|
-
}, n =
|
|
4323
|
+
}, n = Ss(0, "uniform");
|
|
3905
4324
|
this._pipelines = {
|
|
3906
|
-
select: t("oidn-history-select",
|
|
4325
|
+
select: t("oidn-history-select", _s, [
|
|
3907
4326
|
n,
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
4327
|
+
bs(1),
|
|
4328
|
+
bs(2),
|
|
4329
|
+
Ss(3, "storage"),
|
|
4330
|
+
Ss(4, "storage"),
|
|
3912
4331
|
{
|
|
3913
4332
|
binding: 5,
|
|
3914
4333
|
visibility: GPUShaderStage.COMPUTE,
|
|
3915
4334
|
texture: { sampleType: "uint" }
|
|
3916
4335
|
},
|
|
3917
|
-
|
|
3918
|
-
|
|
4336
|
+
Ss(6, "read-only-storage"),
|
|
4337
|
+
Ss(7, "read-only-storage")
|
|
3919
4338
|
]),
|
|
3920
|
-
blend: t("oidn-history-blend",
|
|
4339
|
+
blend: t("oidn-history-blend", vs, [
|
|
3921
4340
|
n,
|
|
3922
4341
|
...[
|
|
3923
4342
|
1,
|
|
@@ -3927,14 +4346,14 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3927
4346
|
5,
|
|
3928
4347
|
6,
|
|
3929
4348
|
7
|
|
3930
|
-
].map(
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
4349
|
+
].map(bs),
|
|
4350
|
+
Ss(8, "read-only-storage"),
|
|
4351
|
+
Ss(9, "read-only-storage"),
|
|
4352
|
+
xs(10),
|
|
4353
|
+
xs(11),
|
|
4354
|
+
xs(12)
|
|
3936
4355
|
]),
|
|
3937
|
-
merge: t("oidn-history-merge",
|
|
4356
|
+
merge: t("oidn-history-merge", ys, [
|
|
3938
4357
|
n,
|
|
3939
4358
|
...[
|
|
3940
4359
|
1,
|
|
@@ -3943,16 +4362,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3943
4362
|
4,
|
|
3944
4363
|
5,
|
|
3945
4364
|
6
|
|
3946
|
-
].map(
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
4365
|
+
].map(bs),
|
|
4366
|
+
xs(7),
|
|
4367
|
+
xs(8),
|
|
4368
|
+
xs(9)
|
|
3950
4369
|
])
|
|
3951
4370
|
}, this._paramsBuffer = e.createBuffer({
|
|
3952
4371
|
label: "oidn-history-params",
|
|
3953
|
-
size:
|
|
4372
|
+
size: us,
|
|
3954
4373
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
3955
|
-
}), this._growMoved(
|
|
4374
|
+
}), this._growMoved(ds);
|
|
3956
4375
|
}
|
|
3957
4376
|
_growMoved(e) {
|
|
3958
4377
|
this._movedLeaves?.destroy(), this._movedToPrev?.destroy();
|
|
@@ -3978,11 +4397,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3978
4397
|
a.setPipeline(t), a.setBindGroup(0, this.device.createBindGroup({
|
|
3979
4398
|
layout: n,
|
|
3980
4399
|
entries: i
|
|
3981
|
-
})), a.dispatchWorkgroups(Math.ceil(this.width /
|
|
4400
|
+
})), a.dispatchWorkgroups(Math.ceil(this.width / ls), Math.ceil(this.height / ls)), a.end();
|
|
3982
4401
|
}
|
|
3983
4402
|
_writeParams(e, t, n, r) {
|
|
3984
4403
|
let i = this.settings, a = this._paramU32, o = this._paramF32;
|
|
3985
|
-
a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ?
|
|
4404
|
+
a[0] = this.width, a[1] = this.height, a[2] = +!!t, a[3] = (i.cleanAux ? fs : 0) | (i.splitCopies ? ps : 0) | (e.orthographic ? ms : 0), o[4] = i.maxLength, o[5] = i.smoothLength, o[6] = i.depthTolerance, o[7] = i.normalTolerance, o[8] = i.roughStart, o[9] = i.roughEnd, o[10] = n, o[11] = r, o.set(e.world, 12), o.set(e.projInv, 28), o.set(this._prevViewProj, 44), o.set(this._prevCamPos, 60), a[64] = this._movedCount, o[68] = i.movedLength, o.set(this._prevCamDir, 72), this.device.queue.writeBuffer(this._paramsBuffer, 0, this._paramData);
|
|
3986
4405
|
}
|
|
3987
4406
|
_rememberCamera(e) {
|
|
3988
4407
|
this._prevViewProj.set(e.viewProj), this._prevCamPos[0] = e.world[12], this._prevCamPos[1] = e.world[13], this._prevCamPos[2] = e.world[14];
|
|
@@ -3992,11 +4411,11 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
3992
4411
|
_releaseTextures() {
|
|
3993
4412
|
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;
|
|
3994
4413
|
}
|
|
3995
|
-
}, No = "const e=Object.freeze({ADAPTER_SOFTWARE:`adapter.software`,ASSET_UNREACHABLE:`asset.unreachable`,ASSET_AMBIGUOUS_ENTRY:`asset.ambiguous_entry`,ASSET_ARCHIVE_TOO_LARGE:`asset.archive_too_large`,ASSET_ENTRY_TOO_LARGE:`asset.entry_too_large`,TEXTURE_BUILD_FAILED:`texture.build_failed`,TEXTURE_PROCESSING_FALLBACK:`texture.processing_fallback`,TEXTURE_LIMIT_EXCEEDED:`texture.limit_exceeded`,ENVIRONMENT_LOAD_FAILED:`environment.load_failed`,SETTING_UNKNOWN_KEY:`setting.unknown_key`,RENDER_SIZE_DECLINED:`render.size_declined`,STAGE_RENDER_FAILED:`stage.render_failed`,RENDER_RESERVE_CAPPED:`render.reserve_capped`,SCENE_MEMORY_BUDGET:`scene.memory_budget`,EMISSIVE_INSTANCES_COLLAPSED:`emissive.instances_collapsed`,REFIT_SHARED_GEOMETRY:`refit.shared_geometry`,VIEW_TRANSFORM_DISPLAY_MISMATCH:`viewTransform.display_mismatch`,VIEW_TRANSFORM_BAKE_FAILED:`viewTransform.bake_failed`,COLOR_CONFIG_LOAD_FAILED:`color.config_load_failed`,STORAGE_UNAVAILABLE:`storage.unavailable`,STORAGE_QUOTA_EXCEEDED:`storage.quota_exceeded`,STORAGE_WRITE_FAILED:`storage.write_failed`,STORAGE_READ_FAILED:`storage.read_failed`,STORAGE_ENTRY_CORRUPT:`storage.entry_corrupt`,STORAGE_CACHE_MISMATCH:`storage.cache_mismatch`,DENOISER_UNAVAILABLE:`denoiser.unavailable`,OUTPUT_SOURCE_FALLBACK:`output.source_fallback`,OUTPUT_TONEMAP_FALLBACK:`output.tonemap_fallback`,LIGHT_PLACEHOLDER_SKIPPED:`light.placeholder_skipped`,CAPABILITY_MISSING:`capability.missing`});Object.freeze({ERROR:`error`,WARNING:`warning`});const t=new Map;function n(e,t){return e.exclusive||t===`exclusive`&&e.shared>0?!1:(t===`exclusive`?e.exclusive=!0:e.shared++,!0)}function r(e,r,a){let o=t.get(e);o||(o={shared:0,exclusive:!1,queue:[]},t.set(e,o));let s=i(()=>{for(r===`exclusive`?o.exclusive=!1:o.shared--;o.queue.length&&n(o,o.queue[0].mode);)o.queue.shift().grant();!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e)});return o.queue.length===0&&n(o,r)?Promise.resolve(s):a?(!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e),Promise.resolve(null)):new Promise(e=>o.queue.push({mode:r,grant:()=>e(s)}))}function i(e){let t=!1;return()=>{t||(t=!0,e())}}const a=()=>typeof navigator<`u`&&navigator.locks?.request?navigator.locks:null;function o(e,{mode:t=`exclusive`,ifAvailable:n=!1}={}){let o=a();return o?new Promise((r,a)=>{o.request(e,{mode:t,ifAvailable:n},e=>{if(!e){r(null);return}return new Promise(e=>r(i(e)))}).catch(a)}):r(e,t,n)}async function s(){let e=a();if(!e)return new Set(t.keys());let{held:n=[]}=await e.query();return new Set(n.map(e=>e.name))}const c=new TextEncoder;function l(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function u(e){let t=typeof e==`string`?c.encode(e):e;return l(new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)))}async function d(e){return(await u(e)).slice(0,32)}var f=class{constructor(){this._handlers=new Map}addEventListener(e,t){this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t)}removeEventListener(e,t){this._handlers.get(e)?.delete(t)}dispatchEvent(e){for(let t of[...this._handlers.get(e.type)??[]])t.call(this,e)}},p=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}},m=class{constructor(e){this._ops=new p(e)}async call(e,t){return this._ops[e](t)}dispose(){this._ops.dispose()}};const h=Object.freeze({CACHE:`cache`,USER:`user`,SCRATCH:`scratch`}),g=Object.freeze({DOWNLOADS:`downloads`,ARCHIVES:`archives`,SCENES:`scenes`,CDF:`cdf`,SPILL:`spill`}),_=`meta.json`,v=100*1024**3,y=64*1024**2,b=8*1024**2,x=new TextEncoder;function S(e,{copy:t,transfer:n}){if(typeof e==`string`&&(e=x.encode(e)),e instanceof ArrayBuffer){if(!t||n)return{args:{buffer:e},list:[e]};let r=e.slice(0);return{args:{buffer:r},list:[r]}}if(!ArrayBuffer.isView(e))throw TypeError(`storage: write expects an ArrayBuffer, a typed array, a Blob or a string`);let{buffer:r,byteOffset:i,byteLength:a}=e,o=typeof SharedArrayBuffer<`u`&&r instanceof SharedArrayBuffer;if(!t)return{args:{buffer:r,byteOffset:i,byteLength:a},list:[]};if(o){let e=new Uint8Array(a);return e.set(new Uint8Array(r,i,a)),{args:{buffer:e.buffer},list:[e.buffer]}}if(n&&i===0&&a===r.byteLength)return{args:{buffer:r},list:[r]};let s=r.slice(i,i+a);return{args:{buffer:s},list:[s]}}async function C(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return JSON.parse(await n.text())}catch{return null}}async function*w(e){for await(let[t,n]of e.entries())n.kind===`directory`&&(yield[t,n])}var T=class{constructor(e,t,n,r,i){this.area=e,this.id=t,this.key=n.key,this.meta=n,this._dir=r,this._release=i}get bytes(){return this.meta.bytes}get extra(){return this.meta.extra??{}}async file(t){try{return await(await this._dir.getFileHandle(t)).getFile()}catch(n){return this.area.manager._issue(e.STORAGE_READ_FAILED,`could not read ${this.area.name}/${this.id}/${t}`,{error:n.message}),null}}async json(e){let t=await this.file(e);return t?JSON.parse(await t.text()):null}release(){this._release?.(),this._release=null}},E=class{constructor(e,t,n,r,i,{sizes:a={},append:o=!1}={}){this.area=e,this.id=t,this.key=n,this._info=r,this._release=i,this._writers=new Map,this._sizes={...a},this._append=o,this._done=!1,this._committedBytes=o?Object.values(a).reduce((e,t)=>e+t,0):0}get _transport(){return this.area.manager._transport}get _path(){return[this.area.name,this.id]}async _writer(e){let t=this._writers.get(e);if(!t){let n=this._append&&e in this._sizes,r=n&&(this._info.growable??[]).includes(e)?this._sizes[e]:void 0;t=this._transport.call(`openWriter`,{path:this._path,name:e,truncate:!n,length:r}),this._writers.set(e,t)}return(await t).id}async write(e,t,{at:n,transfer:r=!1}={}){this._assertOpen();let{args:i,list:a}=(typeof Blob<`u`&&t instanceof Blob?null:S(t,{copy:!0,transfer:r}))??S(await t.arrayBuffer(),{copy:!0,transfer:!0}),o=await this._writer(e);return this._transport.call(`write`,{id:o,at:n,...i},a)}async writeFile(e,t){this._assertOpen(),typeof Blob<`u`&&t instanceof Blob&&(t=await t.arrayBuffer());let{args:n,list:r}=S(t,{copy:!0,transfer:!0}),{size:i}=await this._transport.call(`writeFile`,{path:this._path,name:e,...n},r);return this._sizes[e]=i,i}writeJSON(e,t){return this.writeFile(e,JSON.stringify(t))}async writeStream(e,t,{onProgress:n=null,signal:r=null,batchBytes:i=b}={}){let a=t.getReader(),o=[],s=new Uint8Array(i),c=0,l=0,u=async()=>{if(c===0)return;let t=c===i?s:s.slice(0,c);s=new Uint8Array(i),c=0,o.push(this.write(e,t,{transfer:!0})),o.length>=4&&await o.shift()};try{for(;;){if(r?.aborted)throw r.reason??new DOMException(`aborted`,`AbortError`);let{done:e,value:t}=await a.read();if(e)break;let o=0;for(;o<t.length;){let e=Math.min(t.length-o,i-c);s.set(t.subarray(o,o+e),c),c+=e,o+=e,l+=e,c===i&&await u()}n?.(l)}return await u(),await Promise.all(o),l}catch(e){throw a.cancel().catch(()=>{}),await Promise.allSettled(o),e}}async commit(e={}){this._assertOpen(),this._done=!0;try{for(let[e,t]of this._writers){let{size:n}=await this._transport.call(`closeWriter`,{id:(await t).id});this._sizes[e]=n}this._writers.clear();let t=Date.now(),n={v:1,key:this.key,label:this._info.label??``,kind:this.area.kind,files:{...this._sizes},bytes:Object.values(this._sizes).reduce((e,t)=>e+t,0),createdAt:this._info.createdAt??t,lastUsed:t,pinned:this._info.pinned===!0,extra:{...this._info.extra,...e}},r=this._info.growable??[];r.length&&(n.growable=r);let{args:i,list:a}=S(JSON.stringify(n),{copy:!1});return await this._transport.call(`writeFile`,{path:this._path,name:_,...i},a),this.area.kind===h.CACHE&&this.area.manager._countCacheBytes(n.bytes-this._committedBytes),this.area.manager._changed(this.area.name),n}catch(e){throw await this._discard(),this.area.manager._writeFailed(this.area.name,e),e}finally{this._release?.(),this._release=null}}async abort(){if(!this._done){this._done=!0;try{this._append?await this._closeAll(!0):await this._discard()}finally{this._release?.(),this._release=null}}}async _closeAll(e){for(let t of this._writers.values())try{await this._transport.call(`closeWriter`,{id:(await t).id,abort:e})}catch{}this._writers.clear()}async _discard(){await this._closeAll(!0),await this.area._removeDir(this.id)}_assertOpen(){if(this._done)throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`)}},D=class{constructor(e,t,n){this.manager=e,this.name=t,this.kind=n}_lockName(e){return`${this.manager.namespace}:store:${this.name}:${e}`}async _dir(e=!1){try{return await this.manager._root.getDirectoryHandle(this.name,{create:e})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _entryDir(e,t=!1){let n=await this._dir(t);if(!n)return null;try{return await n.getDirectoryHandle(e,{create:t})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _removeDir(e){let t=await this._dir(!1);if(t)try{await t.removeEntry(e,{recursive:!0})}catch(e){if(e.name!==`NotFoundError`)throw e}}async _validMeta(e,t=null){let n=await C(e,_);if(!n||n.v!==1||typeof n.key!=`string`||t!==null&&n.key!==t)return null;let r=n.growable??[];for(let[t,i]of Object.entries(n.files??{}))try{let n=await(await e.getFileHandle(t)).getFile();if(n.size!==i&&!(r.includes(t)&&n.size>i))return null}catch{return null}return n}async open(t,{wait:n=!1}={}){let r=await d(t),i=await o(this._lockName(r),{mode:`shared`,ifAvailable:!n});if(!i)return null;try{let e=await this._entryDir(r),n=e?await this._validMeta(e,t):null;return n?(Date.now()-n.lastUsed>36e5&&this._touch(r,n),new T(this,r,n,e,i)):(i(),null)}catch(t){return i(),this.manager._issue(e.STORAGE_READ_FAILED,`could not open ${this.name} entry`,{error:t.message}),null}}async has(e){let t=await this.open(e);return t?.release(),!!t}_touch(e,t){let n={...t,lastUsed:Date.now()},{args:r,list:i}=S(JSON.stringify(n),{copy:!1});this.manager._transport.call(`writeFile`,{path:[this.name,e],name:_,...r},i).catch(()=>{}),t.lastUsed=n.lastUsed}async create(t,{label:n=``,pinned:r=!1,expectedBytes:i=0,extra:a={},growable:s=[]}={}){let c=await d(t),l=await o(this._lockName(c),{mode:`exclusive`});try{return i>0&&!await this.manager.ensureSpace(i,this.kind)?(l(),this.manager._issue(e.STORAGE_QUOTA_EXCEEDED,`no room for ${(i/1048576).toFixed(0)} MB in ${this.name}`,{area:this.name,expectedBytes:i}),null):(await this._removeDir(c),await this._entryDir(c,!0),new E(this,c,t,{label:n,pinned:r,extra:a,growable:s},l))}catch(e){return l(),this.manager._writeFailed(this.name,e),null}}async patchMeta(e,t){let n=await d(e),r=await o(this._lockName(n),{mode:`shared`,ifAvailable:!0});if(!r)return!1;try{let r=await this._entryDir(n),i=r?await this._validMeta(r,e):null;if(!i)return!1;let{args:a,list:o}=S(JSON.stringify({...i,...t,v:1,key:e}),{copy:!1});return await this.manager._transport.call(`writeFile`,{path:[this.name,n],name:_,...a},o),!0}finally{r()}}async edit(e){let t=await d(e),n=await o(this._lockName(t),{mode:`exclusive`});try{let r=await this._entryDir(t),i=r?await this._validMeta(r,e):null;if(!i)return n(),null;let a={label:i.label,pinned:i.pinned,extra:i.extra,createdAt:i.createdAt,growable:i.growable};return new E(this,t,e,a,n,{sizes:i.files,append:!0})}catch(e){return n(),this.manager._writeFailed(this.name,e),null}}async remove(e){return this.removeById(await d(e))}async removeById(e){let t=await o(this._lockName(e),{mode:`exclusive`,ifAvailable:!0});if(!t)return!1;try{return await this._removeDir(e),this.manager._changed(this.name),!0}finally{t()}}async list(){let e=await this._dir(!1);if(!e)return[];let t=[];for await(let[n,r]of w(e)){let e=await C(r,_);e?.v===1&&t.push({...e,id:n})}return t}async clear(){let e=0;for(let{id:t}of await this.list())await this.removeById(t)&&e++;return e}async sweep(){let e=await this._dir(!1);if(!e)return 0;let t=await s(),n=0;for await(let[r,i]of w(e))t.has(this._lockName(r))||await this._validMeta(i)||await this.removeById(r)&&n++;return n}},O=class extends f{constructor({root:e,transport:t,namespace:n}){super(),this.namespace=n,this._root=e,this._transport=t,this._areas=new Map,this._budget=null,this._cacheTotal=null;for(let e of Object.values(g))this.defineArea(e,{kind:e===g.SPILL?h.SCRATCH:h.CACHE})}defineArea(e,{kind:t=h.CACHE}={}){let n=this._areas.get(e);if(n){if(n.kind!==t)throw Error(`storage: area \"${e}\" is already defined as ${n.kind}`);return n}let r=new D(this,e,t);return this._areas.set(e,r),r}area(e){let t=this._areas.get(e);if(!t)throw Error(`storage: unknown area \"${e}\"`);return t}get areaNames(){return[...this._areas.keys()]}async estimate(){let e=typeof navigator<`u`?navigator.storage:null;if(!e?.estimate)return{quota:1/0,usage:0};let{quota:t=1/0,usage:n=0}=await e.estimate();return{quota:t,usage:n}}async persisted(){return await globalThis.navigator?.storage?.persisted?.()===!0}async persist(){let e=await globalThis.navigator?.storage?.persist?.()===!0;return this._changed(null),e}async budget(){if(this._budget!==null)return this._budget;let{quota:e}=await this.estimate();return Math.min(e*.3,v)}setBudget(e){this._budget=e===null?null:Math.max(0,e),this._changed(null)}async _cacheBytes(){let e=this._cacheTotal;return(!e||Date.now()-e.at>3e4)&&(e=this._cacheTotal={at:Date.now(),bytes:0,ready:null},e.ready=this._cacheEntries().then(t=>{e.bytes+=t.reduce((e,t)=>e+(t.meta.bytes??0),0)}),e.ready.catch(()=>{this._cacheTotal===e&&(this._cacheTotal=null)})),await e.ready,e.bytes}_countCacheBytes(e){this._cacheTotal&&(this._cacheTotal.bytes+=e)}async _cacheEntries(){let e=[];for(let t of this._areas.values())if(t.kind===h.CACHE)for(let n of await t.list())e.push({area:t,meta:n});return e}async usage(){let{quota:e,usage:t}=await this.estimate(),n={},r=0;for(let e of this._areas.values()){let t=await e.list(),i=t.reduce((e,t)=>e+(t.bytes??0),0);n[e.name]={kind:e.kind,bytes:i,entries:t.length},e.kind===h.CACHE&&(r+=i)}return{quota:e,usage:t,persisted:await this.persisted(),budget:await this.budget(),cacheBytes:r,areas:n}}async collect({freeBytes:e=null}={}){let t=await this._cacheEntries(),n=await this.budget(),r=this._cacheTotal={at:Date.now(),bytes:t.reduce((e,t)=>e+(t.meta.bytes??0),0),ready:null},i=e??Math.max(0,r.bytes-n);if(i<=0)return 0;let a=await s(),o=t.filter(({area:e,meta:t})=>!t.pinned&&!a.has(e._lockName(t.id))).sort((e,t)=>e.meta.lastUsed-t.meta.lastUsed),c=0;for(let{area:e,meta:t}of o){if(c>=i)break;await e.removeById(t.id)&&(c+=t.bytes??0,r.bytes-=t.bytes??0)}return c}async ensureSpace(e,t=h.CACHE){let n=async()=>{let{quota:n,usage:r}=await this.estimate(),i=e+y-(n-r);return t===h.CACHE?{free:i,budget:await this._cacheBytes()+e-await this.budget()}:{free:i,budget:0}},r=await n();return r.free<=0&&r.budget<=0?!0:(await this.collect({freeBytes:Math.max(r.free,r.budget)}),(await n()).free<=0)}async sweep(){let e=0;for(let t of this._areas.values())e+=await t.sweep(),t.kind===h.SCRATCH&&(e+=await t.clear());return e}_changed(e){this.dispatchEvent({type:`change`,area:e})}_issue(e,t,n={}){this.dispatchEvent({type:`issue`,code:e,message:t,detail:n})}_writeFailed(t,n){let r=n?.name===`QuotaExceededError`;this._issue(r?e.STORAGE_QUOTA_EXCEEDED:e.STORAGE_WRITE_FAILED,`${t}: ${n?.message??n}`,{area:t,error:n?.name})}dispose(){this._transport?.dispose(),this._transport=null,this._areas.clear()}};function k({namespace:e,root:t}){let n=new m(t);n.inline=!0;let r=new O({root:t,transport:n,namespace:e});return r.sweep().catch(()=>{}),r}const A=Object.freeze({IMMUTABLE:`immutable`,REVALIDATE:`revalidate`,NETWORK:`network`}),j=(e,t)=>({loaded:e,total:t,lengthComputable:t>0&&e<=t}),M=(e,t)=>e.headers?.get?.(t)??null,N=e=>e.reason??new DOMException(`aborted`,`AbortError`);function P(e){try{let t=new URL(e,globalThis.location?.href??`http://localhost/`).pathname;return decodeURIComponent(t.split(`/`).pop())||`download`}catch{return`download`}}async function F(e,{onProgress:t,signal:n}){let r=Number(M(e,`content-length`))||0,i=M(e,`content-type`)??``;if(!e.body)return new Blob([await e.arrayBuffer()],{type:i});let a=e.body.getReader(),o=[],s=0;for(;;){if(n?.aborted)throw a.cancel().catch(()=>{}),N(n);let{done:e,value:i}=await a.read();if(e)break;o.push(i),s+=i.length,t?.(j(s,r))}return new Blob(o,{type:i})}const I=(e,t,n)=>new File([e],t,{type:n||e.type,lastModified:e.lastModified??Date.now()}),L=()=>{};var R=class{constructor(e){this._storage=e,this._revalidating=new Set}get _area(){return this._storage?.area(g.DOWNLOADS)??null}async fetch(e,{key:t=e,name:n=P(e),policy:r=A.REVALIDATE,maxAgeMs:i=864e5,onProgress:a=null,signal:o=null,fetchOptions:s={}}={}){let c=this._area;if(c&&r!==A.NETWORK){let o=await c.open(t);if(o){let c=await o.file(`data`);if(c)return r===A.REVALIDATE&&Date.now()-(o.extra.checkedAt??0)>=i&&this._revalidate(e,t,n,o.extra,s),a?.(j(c.size,c.size)),{file:I(c,n,o.extra.contentType),release:()=>o.release(),fromCache:!0};o.release()}}return this._download(e,t,n,{onProgress:a,signal:o,fetchOptions:s,cache:!!c})}async has(e){return await this._area?.has(e)===!0}async _download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:o}){if(i?.aborted)throw N(i);let s=await fetch(e,{...a,signal:i});if(!s.ok)throw Error(`HTTP ${s.status} fetching ${e}`);let c=Number(M(s,`content-length`))||0,l={url:e,contentType:M(s,`content-type`)??``,lastModified:M(s,`last-modified`),contentLength:c||null,checkedAt:Date.now()},u=o&&s.body?await this._area.create(t,{label:n,expectedBytes:c}):null;if(!u)return{file:I(await F(s,{onProgress:r,signal:i}),n,l.contentType),release:L,fromCache:!1};try{await u.writeStream(`data`,s.body,{signal:i,onProgress:e=>r?.(j(e,c))}),await u.commit(l)}catch(o){if(await u.abort(),o?.name!==`QuotaExceededError`)throw o;return this._download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:!1})}let d=await this._area.open(t,{wait:!0}),f=d&&await d.file(`data`);if(!f)throw d?.release(),Error(`storage: ${n} vanished right after it was saved`);return{file:I(f,n,l.contentType),release:()=>d.release(),fromCache:!1}}async _revalidate(e,t,n,r,i){if(this._revalidating.has(t))return;this._revalidating.add(t);let a=!1;try{let t=new Headers(i?.headers);t.set(`Range`,`bytes=0-0`);let n=await fetch(e,{...i,headers:t});if(n.body?.cancel().catch(()=>{}),n.ok){let e=M(n,`last-modified`),t=n.status===206?Number(M(n,`content-range`)?.match(/\\/(\\d+)$/)?.[1])||null:Number(M(n,`content-length`))||null;a=!!(e&&r.lastModified&&e!==r.lastModified||t&&r.contentLength&&t!==r.contentLength)}}catch{}try{if(a){let{release:r}=await this._download(e,t,n,{fetchOptions:i,cache:!0});r()}else await this._area.patchMeta(t,{extra:{...r,checkedAt:Date.now()}})}catch{}finally{this._revalidating.delete(t)}}};let z={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`,storage:`auto`},B=null;async function V(){return B||(B=await import(z.ortRuntimeUrl),B.env.wasm.wasmPaths=z.ortWasmPaths,B.env.logLevel=`error`,B)}let H=null,U=null,W=null;function G(){return W??=(async()=>{if(z.storage===!1||!navigator.storage?.getDirectory)return new R(null);try{let e=await(await navigator.storage.getDirectory()).getDirectoryHandle(z.cacheNamespace,{create:!0}),t=k({namespace:z.cacheNamespace,root:e});return await K(t).catch(()=>{}),new R(t)}catch{return new R(null)}})(),W}async function K(e){let t=`${z.cacheNamespace}:ai-upscaler-models`;if(typeof indexedDB>`u`||!indexedDB.databases||!(await indexedDB.databases()).some(e=>e.name===t))return;let n=await new Promise((e,n)=>{let r=indexedDB.open(t);r.onerror=()=>n(r.error),r.onsuccess=()=>{let t=r.result;if(!t.objectStoreNames.contains(`models`)){t.close(),e([]);return}let i=[],a=t.transaction(`models`,`readonly`).objectStore(`models`).openCursor();a.onerror=()=>n(a.error),a.onsuccess=()=>{let n=a.result;if(!n){t.close(),e(i);return}i.push([n.key,n.value]),n.continue()}}}),r=e.area(`downloads`);for(let[e,t]of n){if(typeof e!=`string`||!(t instanceof ArrayBuffer)||await r.has(e))continue;let n=await r.create(e,{label:e.split(`/`).pop(),expectedBytes:t.byteLength});n&&(await n.write(`data`,t,{transfer:!0}),await n.commit({url:e,contentType:`application/octet-stream`,checkedAt:Date.now()}))}await new Promise(e=>{let n=indexedDB.deleteDatabase(t);n.onsuccess=n.onerror=n.onblocked=()=>e()})}async function q(e){let{file:t,release:n,fromCache:r}=await(await G()).fetch(e);try{let e=await t.arrayBuffer();return r&&console.log(`AI Upscaler Worker: model loaded from cache (${(e.byteLength/1024/1024).toFixed(1)}MB)`),e}finally{n()}}async function J(e,t){if(H&&U===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}H&&=(await H.release(),null);let[n,r]=await Promise.all([q(e),V()]);H=await r.InferenceSession.create(n,t),U=e;let i=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);i=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${i}`)}catch{}let a=(n.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${a}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:i})}async function Y(e,t,n,r){let i=await V(),a=H.inputNames[0],o=H.outputNames[0],s=new i.Tensor(`float32`,e,[1,3,n,t]),c=(await H.run({[a]:s}))[o].data;self.postMessage({type:`inferred`,outputData:c,id:r},[c.buffer])}self.onmessage=async e=>{let{type:t}=e.data;try{t===`load`?(e.data.ortRuntimeUrl&&(z.ortRuntimeUrl=e.data.ortRuntimeUrl),e.data.ortWasmPaths&&(z.ortWasmPaths=e.data.ortWasmPaths),e.data.cacheNamespace&&(z.cacheNamespace=e.data.cacheNamespace),e.data.storage!==void 0&&(z.storage=e.data.storage),await J(e.data.url,e.data.sessionOptions)):t===`infer`?await Y(e.data.tileData,e.data.width,e.data.height,e.data.id):t===`dispose`&&H&&(await H.release(),H=null,U=null)}catch(t){self.postMessage({type:`error`,message:t.message,id:e.data?.id})}};", Po = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", No], { type: "text/javascript;charset=utf-8" });
|
|
3996
|
-
function
|
|
4414
|
+
}, ws = "const e=Object.freeze({ADAPTER_SOFTWARE:`adapter.software`,ASSET_UNREACHABLE:`asset.unreachable`,ASSET_AMBIGUOUS_ENTRY:`asset.ambiguous_entry`,ASSET_ARCHIVE_TOO_LARGE:`asset.archive_too_large`,ASSET_ENTRY_TOO_LARGE:`asset.entry_too_large`,TEXTURE_BUILD_FAILED:`texture.build_failed`,TEXTURE_PROCESSING_FALLBACK:`texture.processing_fallback`,TEXTURE_LIMIT_EXCEEDED:`texture.limit_exceeded`,ENVIRONMENT_LOAD_FAILED:`environment.load_failed`,SETTING_UNKNOWN_KEY:`setting.unknown_key`,RENDER_SIZE_DECLINED:`render.size_declined`,STAGE_RENDER_FAILED:`stage.render_failed`,RENDER_RESERVE_CAPPED:`render.reserve_capped`,SCENE_MEMORY_BUDGET:`scene.memory_budget`,EMISSIVE_INSTANCES_COLLAPSED:`emissive.instances_collapsed`,REFIT_SHARED_GEOMETRY:`refit.shared_geometry`,VIEW_TRANSFORM_DISPLAY_MISMATCH:`viewTransform.display_mismatch`,VIEW_TRANSFORM_BAKE_FAILED:`viewTransform.bake_failed`,COLOR_CONFIG_LOAD_FAILED:`color.config_load_failed`,STORAGE_UNAVAILABLE:`storage.unavailable`,STORAGE_QUOTA_EXCEEDED:`storage.quota_exceeded`,STORAGE_WRITE_FAILED:`storage.write_failed`,STORAGE_READ_FAILED:`storage.read_failed`,STORAGE_ENTRY_CORRUPT:`storage.entry_corrupt`,STORAGE_CACHE_MISMATCH:`storage.cache_mismatch`,DENOISER_UNAVAILABLE:`denoiser.unavailable`,OUTPUT_SOURCE_FALLBACK:`output.source_fallback`,OUTPUT_TONEMAP_FALLBACK:`output.tonemap_fallback`,LIGHT_PLACEHOLDER_SKIPPED:`light.placeholder_skipped`,CAPABILITY_MISSING:`capability.missing`});Object.freeze({ERROR:`error`,WARNING:`warning`});const t=new Map;function n(e,t){return e.exclusive||t===`exclusive`&&e.shared>0?!1:(t===`exclusive`?e.exclusive=!0:e.shared++,!0)}function r(e,r,a){let o=t.get(e);o||(o={shared:0,exclusive:!1,queue:[]},t.set(e,o));let s=i(()=>{for(r===`exclusive`?o.exclusive=!1:o.shared--;o.queue.length&&n(o,o.queue[0].mode);)o.queue.shift().grant();!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e)});return o.queue.length===0&&n(o,r)?Promise.resolve(s):a?(!o.exclusive&&o.shared===0&&o.queue.length===0&&t.delete(e),Promise.resolve(null)):new Promise(e=>o.queue.push({mode:r,grant:()=>e(s)}))}function i(e){let t=!1;return()=>{t||(t=!0,e())}}const a=()=>typeof navigator<`u`&&navigator.locks?.request?navigator.locks:null;function o(e,{mode:t=`exclusive`,ifAvailable:n=!1}={}){let o=a();return o?new Promise((r,a)=>{o.request(e,{mode:t,ifAvailable:n},e=>{if(!e){r(null);return}return new Promise(e=>r(i(e)))}).catch(a)}):r(e,t,n)}async function s(){let e=a();if(!e)return new Set(t.keys());let{held:n=[]}=await e.query();return new Set(n.map(e=>e.name))}const c=new TextEncoder;function l(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function u(e){let t=typeof e==`string`?c.encode(e):e;return l(new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)))}async function d(e){return(await u(e)).slice(0,32)}var f=class{constructor(){this._handlers=new Map}addEventListener(e,t){this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t)}removeEventListener(e,t){this._handlers.get(e)?.delete(t)}dispatchEvent(e){for(let t of[...this._handlers.get(e.type)??[]])t.call(this,e)}},p=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}},m=class{constructor(e){this._ops=new p(e)}async call(e,t){return this._ops[e](t)}dispose(){this._ops.dispose()}};const h=Object.freeze({CACHE:`cache`,USER:`user`,SCRATCH:`scratch`}),g=Object.freeze({DOWNLOADS:`downloads`,ARCHIVES:`archives`,SCENES:`scenes`,CDF:`cdf`,SPILL:`spill`}),_=`meta.json`,v=100*1024**3,y=64*1024**2,b=8*1024**2,x=new TextEncoder;function S(e,{copy:t,transfer:n}){if(typeof e==`string`&&(e=x.encode(e)),e instanceof ArrayBuffer){if(!t||n)return{args:{buffer:e},list:[e]};let r=e.slice(0);return{args:{buffer:r},list:[r]}}if(!ArrayBuffer.isView(e))throw TypeError(`storage: write expects an ArrayBuffer, a typed array, a Blob or a string`);let{buffer:r,byteOffset:i,byteLength:a}=e,o=typeof SharedArrayBuffer<`u`&&r instanceof SharedArrayBuffer;if(!t)return{args:{buffer:r,byteOffset:i,byteLength:a},list:[]};if(o){let e=new Uint8Array(a);return e.set(new Uint8Array(r,i,a)),{args:{buffer:e.buffer},list:[e.buffer]}}if(n&&i===0&&a===r.byteLength)return{args:{buffer:r},list:[r]};let s=r.slice(i,i+a);return{args:{buffer:s},list:[s]}}async function C(e,t){try{let n=await(await e.getFileHandle(t)).getFile();return JSON.parse(await n.text())}catch{return null}}async function*w(e){for await(let[t,n]of e.entries())n.kind===`directory`&&(yield[t,n])}var T=class{constructor(e,t,n,r,i){this.area=e,this.id=t,this.key=n.key,this.meta=n,this._dir=r,this._release=i}get bytes(){return this.meta.bytes}get extra(){return this.meta.extra??{}}async file(t){try{return await(await this._dir.getFileHandle(t)).getFile()}catch(n){return this.area.manager._issue(e.STORAGE_READ_FAILED,`could not read ${this.area.name}/${this.id}/${t}`,{error:n.message}),null}}async json(e){let t=await this.file(e);return t?JSON.parse(await t.text()):null}release(){this._release?.(),this._release=null}},E=class{constructor(e,t,n,r,i,{sizes:a={},append:o=!1}={}){this.area=e,this.id=t,this.key=n,this._info=r,this._release=i,this._writers=new Map,this._sizes={...a},this._append=o,this._done=!1,this._committedBytes=o?Object.values(a).reduce((e,t)=>e+t,0):0}get _transport(){return this.area.manager._transport}get _path(){return[this.area.name,this.id]}async _writer(e){let t=this._writers.get(e);if(!t){let n=this._append&&e in this._sizes,r=n&&(this._info.growable??[]).includes(e)?this._sizes[e]:void 0;t=this._transport.call(`openWriter`,{path:this._path,name:e,truncate:!n,length:r}),this._writers.set(e,t)}return(await t).id}async write(e,t,{at:n,transfer:r=!1}={}){this._assertOpen();let{args:i,list:a}=(typeof Blob<`u`&&t instanceof Blob?null:S(t,{copy:!0,transfer:r}))??S(await t.arrayBuffer(),{copy:!0,transfer:!0}),o=await this._writer(e);return this._transport.call(`write`,{id:o,at:n,...i},a)}async writeFile(e,t){this._assertOpen(),typeof Blob<`u`&&t instanceof Blob&&(t=await t.arrayBuffer());let{args:n,list:r}=S(t,{copy:!0,transfer:!0}),{size:i}=await this._transport.call(`writeFile`,{path:this._path,name:e,...n},r);return this._sizes[e]=i,i}writeJSON(e,t){return this.writeFile(e,JSON.stringify(t))}async writeStream(e,t,{onProgress:n=null,signal:r=null,batchBytes:i=b}={}){let a=t.getReader(),o=[],s=new Uint8Array(i),c=0,l=0,u=async()=>{if(c===0)return;let t=c===i?s:s.slice(0,c);s=new Uint8Array(i),c=0,o.push(this.write(e,t,{transfer:!0})),o.length>=4&&await o.shift()};try{for(;;){if(r?.aborted)throw r.reason??new DOMException(`aborted`,`AbortError`);let{done:e,value:t}=await a.read();if(e)break;let o=0;for(;o<t.length;){let e=Math.min(t.length-o,i-c);s.set(t.subarray(o,o+e),c),c+=e,o+=e,l+=e,c===i&&await u()}n?.(l)}return await u(),await Promise.all(o),l}catch(e){throw a.cancel().catch(()=>{}),await Promise.allSettled(o),e}}async commit(e={}){this._assertOpen(),this._done=!0;try{for(let[e,t]of this._writers){let{size:n}=await this._transport.call(`closeWriter`,{id:(await t).id});this._sizes[e]=n}this._writers.clear();let t=Date.now(),n={v:1,key:this.key,label:this._info.label??``,kind:this.area.kind,files:{...this._sizes},bytes:Object.values(this._sizes).reduce((e,t)=>e+t,0),createdAt:this._info.createdAt??t,lastUsed:t,pinned:this._info.pinned===!0,extra:{...this._info.extra,...e}},r=this._info.growable??[];r.length&&(n.growable=r);let{args:i,list:a}=S(JSON.stringify(n),{copy:!1});return await this._transport.call(`writeFile`,{path:this._path,name:_,...i},a),this.area.kind===h.CACHE&&this.area.manager._countCacheBytes(n.bytes-this._committedBytes),this.area.manager._changed(this.area.name),n}catch(e){throw await this._discard(),this.area.manager._writeFailed(this.area.name,e),e}finally{this._release?.(),this._release=null}}async abort(){if(!this._done){this._done=!0;try{this._append?await this._closeAll(!0):await this._discard()}finally{this._release?.(),this._release=null}}}async _closeAll(e){for(let t of this._writers.values())try{await this._transport.call(`closeWriter`,{id:(await t).id,abort:e})}catch{}this._writers.clear()}async _discard(){await this._closeAll(!0),await this.area._removeDir(this.id)}_assertOpen(){if(this._done)throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`)}},D=class{constructor(e,t,n){this.manager=e,this.name=t,this.kind=n}_lockName(e){return`${this.manager.namespace}:store:${this.name}:${e}`}async _dir(e=!1){try{return await this.manager._root.getDirectoryHandle(this.name,{create:e})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _entryDir(e,t=!1){let n=await this._dir(t);if(!n)return null;try{return await n.getDirectoryHandle(e,{create:t})}catch(e){if(e.name===`NotFoundError`)return null;throw e}}async _removeDir(e){let t=await this._dir(!1);if(t)try{await t.removeEntry(e,{recursive:!0})}catch(e){if(e.name!==`NotFoundError`)throw e}}async _validMeta(e,t=null){let n=await C(e,_);if(!n||n.v!==1||typeof n.key!=`string`||t!==null&&n.key!==t)return null;let r=n.growable??[];for(let[t,i]of Object.entries(n.files??{}))try{let n=await(await e.getFileHandle(t)).getFile();if(n.size!==i&&!(r.includes(t)&&n.size>i))return null}catch{return null}return n}async open(t,{wait:n=!1}={}){let r=await d(t),i=await o(this._lockName(r),{mode:`shared`,ifAvailable:!n});if(!i)return null;try{let e=await this._entryDir(r),n=e?await this._validMeta(e,t):null;return n?(Date.now()-n.lastUsed>36e5&&this._touch(r,n),new T(this,r,n,e,i)):(i(),null)}catch(t){return i(),this.manager._issue(e.STORAGE_READ_FAILED,`could not open ${this.name} entry`,{error:t.message}),null}}async has(e){let t=await this.open(e);return t?.release(),!!t}_touch(e,t){let n={...t,lastUsed:Date.now()},{args:r,list:i}=S(JSON.stringify(n),{copy:!1});this.manager._transport.call(`writeFile`,{path:[this.name,e],name:_,...r},i).catch(()=>{}),t.lastUsed=n.lastUsed}async create(t,{label:n=``,pinned:r=!1,expectedBytes:i=0,extra:a={},growable:s=[]}={}){let c=await d(t),l=await o(this._lockName(c),{mode:`exclusive`});try{return i>0&&!await this.manager.ensureSpace(i,this.kind)?(l(),this.manager._issue(e.STORAGE_QUOTA_EXCEEDED,`no room for ${(i/1048576).toFixed(0)} MB in ${this.name}`,{area:this.name,expectedBytes:i}),null):(await this._removeDir(c),await this._entryDir(c,!0),new E(this,c,t,{label:n,pinned:r,extra:a,growable:s},l))}catch(e){return l(),this.manager._writeFailed(this.name,e),null}}async patchMeta(e,t){let n=await d(e),r=await o(this._lockName(n),{mode:`shared`,ifAvailable:!0});if(!r)return!1;try{let r=await this._entryDir(n),i=r?await this._validMeta(r,e):null;if(!i)return!1;let{args:a,list:o}=S(JSON.stringify({...i,...t,v:1,key:e}),{copy:!1});return await this.manager._transport.call(`writeFile`,{path:[this.name,n],name:_,...a},o),!0}finally{r()}}async edit(e){let t=await d(e),n=await o(this._lockName(t),{mode:`exclusive`});try{let r=await this._entryDir(t),i=r?await this._validMeta(r,e):null;if(!i)return n(),null;let a={label:i.label,pinned:i.pinned,extra:i.extra,createdAt:i.createdAt,growable:i.growable};return new E(this,t,e,a,n,{sizes:i.files,append:!0})}catch(e){return n(),this.manager._writeFailed(this.name,e),null}}async remove(e){return this.removeById(await d(e))}async removeById(e){let t=await o(this._lockName(e),{mode:`exclusive`,ifAvailable:!0});if(!t)return!1;try{return await this._removeDir(e),this.manager._changed(this.name),!0}finally{t()}}async list(){let e=await this._dir(!1);if(!e)return[];let t=[];for await(let[n,r]of w(e)){let e=await C(r,_);e?.v===1&&t.push({...e,id:n})}return t}async clear(){let e=0;for(let{id:t}of await this.list())await this.removeById(t)&&e++;return e}async sweep(){let e=await this._dir(!1);if(!e)return 0;let t=await s(),n=0;for await(let[r,i]of w(e))t.has(this._lockName(r))||await this._validMeta(i)||await this.removeById(r)&&n++;return n}},O=class extends f{constructor({root:e,transport:t,namespace:n}){super(),this.namespace=n,this._root=e,this._transport=t,this._areas=new Map,this._budget=null,this._cacheTotal=null;for(let e of Object.values(g))this.defineArea(e,{kind:e===g.SPILL?h.SCRATCH:h.CACHE})}defineArea(e,{kind:t=h.CACHE}={}){let n=this._areas.get(e);if(n){if(n.kind!==t)throw Error(`storage: area \"${e}\" is already defined as ${n.kind}`);return n}let r=new D(this,e,t);return this._areas.set(e,r),r}area(e){let t=this._areas.get(e);if(!t)throw Error(`storage: unknown area \"${e}\"`);return t}get areaNames(){return[...this._areas.keys()]}async estimate(){let e=typeof navigator<`u`?navigator.storage:null;if(!e?.estimate)return{quota:1/0,usage:0};let{quota:t=1/0,usage:n=0}=await e.estimate();return{quota:t,usage:n}}async persisted(){return await globalThis.navigator?.storage?.persisted?.()===!0}async persist(){let e=await globalThis.navigator?.storage?.persist?.()===!0;return this._changed(null),e}async budget(){if(this._budget!==null)return this._budget;let{quota:e}=await this.estimate();return Math.min(e*.3,v)}setBudget(e){this._budget=e===null?null:Math.max(0,e),this._changed(null)}async _cacheBytes(){let e=this._cacheTotal;return(!e||Date.now()-e.at>3e4)&&(e=this._cacheTotal={at:Date.now(),bytes:0,ready:null},e.ready=this._cacheEntries().then(t=>{e.bytes+=t.reduce((e,t)=>e+(t.meta.bytes??0),0)}),e.ready.catch(()=>{this._cacheTotal===e&&(this._cacheTotal=null)})),await e.ready,e.bytes}_countCacheBytes(e){this._cacheTotal&&(this._cacheTotal.bytes+=e)}async _cacheEntries(){let e=[];for(let t of this._areas.values())if(t.kind===h.CACHE)for(let n of await t.list())e.push({area:t,meta:n});return e}async usage(){let{quota:e,usage:t}=await this.estimate(),n={},r=0;for(let e of this._areas.values()){let t=await e.list(),i=t.reduce((e,t)=>e+(t.bytes??0),0);n[e.name]={kind:e.kind,bytes:i,entries:t.length},e.kind===h.CACHE&&(r+=i)}return{quota:e,usage:t,persisted:await this.persisted(),budget:await this.budget(),cacheBytes:r,areas:n}}async collect({freeBytes:e=null}={}){let t=await this._cacheEntries(),n=await this.budget(),r=this._cacheTotal={at:Date.now(),bytes:t.reduce((e,t)=>e+(t.meta.bytes??0),0),ready:null},i=e??Math.max(0,r.bytes-n);if(i<=0)return 0;let a=await s(),o=t.filter(({area:e,meta:t})=>!t.pinned&&!a.has(e._lockName(t.id))).sort((e,t)=>e.meta.lastUsed-t.meta.lastUsed),c=0;for(let{area:e,meta:t}of o){if(c>=i)break;await e.removeById(t.id)&&(c+=t.bytes??0,r.bytes-=t.bytes??0)}return c}async ensureSpace(e,t=h.CACHE){let n=async()=>{let{quota:n,usage:r}=await this.estimate(),i=e+y-(n-r);return t===h.CACHE?{free:i,budget:await this._cacheBytes()+e-await this.budget()}:{free:i,budget:0}},r=await n();return r.free<=0&&r.budget<=0?!0:(await this.collect({freeBytes:Math.max(r.free,r.budget)}),(await n()).free<=0)}async sweep(){let e=0;for(let t of this._areas.values())e+=await t.sweep(),t.kind===h.SCRATCH&&(e+=await t.clear());return e}_changed(e){this.dispatchEvent({type:`change`,area:e})}_issue(e,t,n={}){this.dispatchEvent({type:`issue`,code:e,message:t,detail:n})}_writeFailed(t,n){let r=n?.name===`QuotaExceededError`;this._issue(r?e.STORAGE_QUOTA_EXCEEDED:e.STORAGE_WRITE_FAILED,`${t}: ${n?.message??n}`,{area:t,error:n?.name})}dispose(){this._transport?.dispose(),this._transport=null,this._areas.clear()}};function k({namespace:e,root:t}){let n=new m(t);n.inline=!0;let r=new O({root:t,transport:n,namespace:e});return r.sweep().catch(()=>{}),r}const A=Object.freeze({IMMUTABLE:`immutable`,REVALIDATE:`revalidate`,NETWORK:`network`}),j=(e,t)=>({loaded:e,total:t,lengthComputable:t>0&&e<=t}),M=(e,t)=>e.headers?.get?.(t)??null,N=e=>e.reason??new DOMException(`aborted`,`AbortError`);function P(e){try{let t=new URL(e,globalThis.location?.href??`http://localhost/`).pathname;return decodeURIComponent(t.split(`/`).pop())||`download`}catch{return`download`}}async function F(e,{onProgress:t,signal:n}){let r=Number(M(e,`content-length`))||0,i=M(e,`content-type`)??``;if(!e.body)return new Blob([await e.arrayBuffer()],{type:i});let a=e.body.getReader(),o=[],s=0;for(;;){if(n?.aborted)throw a.cancel().catch(()=>{}),N(n);let{done:e,value:i}=await a.read();if(e)break;o.push(i),s+=i.length,t?.(j(s,r))}return new Blob(o,{type:i})}const I=(e,t,n)=>new File([e],t,{type:n||e.type,lastModified:e.lastModified??Date.now()}),L=()=>{};var R=class{constructor(e){this._storage=e,this._revalidating=new Set}get _area(){return this._storage?.area(g.DOWNLOADS)??null}async fetch(e,{key:t=e,name:n=P(e),policy:r=A.REVALIDATE,maxAgeMs:i=864e5,onProgress:a=null,signal:o=null,fetchOptions:s={}}={}){let c=this._area;if(c&&r!==A.NETWORK){let o=await c.open(t);if(o){let c=await o.file(`data`);if(c)return r===A.REVALIDATE&&Date.now()-(o.extra.checkedAt??0)>=i&&this._revalidate(e,t,n,o.extra,s),a?.(j(c.size,c.size)),{file:I(c,n,o.extra.contentType),release:()=>o.release(),fromCache:!0};o.release()}}return this._download(e,t,n,{onProgress:a,signal:o,fetchOptions:s,cache:!!c})}async has(e){return await this._area?.has(e)===!0}async _download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:o}){if(i?.aborted)throw N(i);let s=await fetch(e,{...a,signal:i});if(!s.ok)throw Error(`HTTP ${s.status} fetching ${e}`);let c=Number(M(s,`content-length`))||0,l={url:e,contentType:M(s,`content-type`)??``,lastModified:M(s,`last-modified`),contentLength:c||null,checkedAt:Date.now()},u=o&&s.body?await this._area.create(t,{label:n,expectedBytes:c}):null;if(!u)return{file:I(await F(s,{onProgress:r,signal:i}),n,l.contentType),release:L,fromCache:!1};try{await u.writeStream(`data`,s.body,{signal:i,onProgress:e=>r?.(j(e,c))}),await u.commit(l)}catch(o){if(await u.abort(),o?.name!==`QuotaExceededError`)throw o;return this._download(e,t,n,{onProgress:r,signal:i,fetchOptions:a,cache:!1})}let d=await this._area.open(t,{wait:!0}),f=d&&await d.file(`data`);if(!f)throw d?.release(),Error(`storage: ${n} vanished right after it was saved`);return{file:I(f,n,l.contentType),release:()=>d.release(),fromCache:!1}}async _revalidate(e,t,n,r,i){if(this._revalidating.has(t))return;this._revalidating.add(t);let a=!1;try{let t=new Headers(i?.headers);t.set(`Range`,`bytes=0-0`);let n=await fetch(e,{...i,headers:t});if(n.body?.cancel().catch(()=>{}),n.ok){let e=M(n,`last-modified`),t=n.status===206?Number(M(n,`content-range`)?.match(/\\/(\\d+)$/)?.[1])||null:Number(M(n,`content-length`))||null;a=!!(e&&r.lastModified&&e!==r.lastModified||t&&r.contentLength&&t!==r.contentLength)}}catch{}try{if(a){let{release:r}=await this._download(e,t,n,{fetchOptions:i,cache:!0});r()}else await this._area.patchMeta(t,{extra:{...r,checkedAt:Date.now()}})}catch{}finally{this._revalidating.delete(t)}}};let z={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`,storage:`auto`},B=null;async function V(){return B||(B=await import(z.ortRuntimeUrl),B.env.wasm.wasmPaths=z.ortWasmPaths,B.env.logLevel=`error`,B)}let H=null,U=null,W=null;function G(){return W??=(async()=>{if(z.storage===!1||!navigator.storage?.getDirectory)return new R(null);try{let e=await(await navigator.storage.getDirectory()).getDirectoryHandle(z.cacheNamespace,{create:!0}),t=k({namespace:z.cacheNamespace,root:e});return await K(t).catch(()=>{}),new R(t)}catch{return new R(null)}})(),W}async function K(e){let t=`${z.cacheNamespace}:ai-upscaler-models`;if(typeof indexedDB>`u`||!indexedDB.databases||!(await indexedDB.databases()).some(e=>e.name===t))return;let n=await new Promise((e,n)=>{let r=indexedDB.open(t);r.onerror=()=>n(r.error),r.onsuccess=()=>{let t=r.result;if(!t.objectStoreNames.contains(`models`)){t.close(),e([]);return}let i=[],a=t.transaction(`models`,`readonly`).objectStore(`models`).openCursor();a.onerror=()=>n(a.error),a.onsuccess=()=>{let n=a.result;if(!n){t.close(),e(i);return}i.push([n.key,n.value]),n.continue()}}}),r=e.area(`downloads`);for(let[e,t]of n){if(typeof e!=`string`||!(t instanceof ArrayBuffer)||await r.has(e))continue;let n=await r.create(e,{label:e.split(`/`).pop(),expectedBytes:t.byteLength});n&&(await n.write(`data`,t,{transfer:!0}),await n.commit({url:e,contentType:`application/octet-stream`,checkedAt:Date.now()}))}await new Promise(e=>{let n=indexedDB.deleteDatabase(t);n.onsuccess=n.onerror=n.onblocked=()=>e()})}async function q(e){let{file:t,release:n,fromCache:r}=await(await G()).fetch(e);try{let e=await t.arrayBuffer();return r&&console.log(`AI Upscaler Worker: model loaded from cache (${(e.byteLength/1024/1024).toFixed(1)}MB)`),e}finally{n()}}async function J(e,t){if(H&&U===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}H&&=(await H.release(),null);let[n,r]=await Promise.all([q(e),V()]);H=await r.InferenceSession.create(n,t),U=e;let i=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);i=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${i}`)}catch{}let a=(n.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${a}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:i})}async function Y(e,t,n,r){let i=await V(),a=H.inputNames[0],o=H.outputNames[0],s=new i.Tensor(`float32`,e,[1,3,n,t]),c=(await H.run({[a]:s}))[o].data;self.postMessage({type:`inferred`,outputData:c,id:r},[c.buffer])}self.onmessage=async e=>{let{type:t}=e.data;try{t===`load`?(e.data.ortRuntimeUrl&&(z.ortRuntimeUrl=e.data.ortRuntimeUrl),e.data.ortWasmPaths&&(z.ortWasmPaths=e.data.ortWasmPaths),e.data.cacheNamespace&&(z.cacheNamespace=e.data.cacheNamespace),e.data.storage!==void 0&&(z.storage=e.data.storage),await J(e.data.url,e.data.sessionOptions)):t===`infer`?await Y(e.data.tileData,e.data.width,e.data.height,e.data.id):t===`dispose`&&H&&(await H.release(),H=null,U=null)}catch(t){self.postMessage({type:`error`,message:t.message,id:e.data?.id})}};", Ts = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", ws], { type: "text/javascript;charset=utf-8" });
|
|
4415
|
+
function Es(e) {
|
|
3997
4416
|
let t;
|
|
3998
4417
|
try {
|
|
3999
|
-
if (t =
|
|
4418
|
+
if (t = Ts && (self.URL || self.webkitURL).createObjectURL(Ts), !t) throw "";
|
|
4000
4419
|
let n = new Worker(t, {
|
|
4001
4420
|
type: "module",
|
|
4002
4421
|
name: e?.name
|
|
@@ -4005,7 +4424,7 @@ function Fo(e) {
|
|
|
4005
4424
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
4006
4425
|
}), n;
|
|
4007
4426
|
} catch {
|
|
4008
|
-
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
4427
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(ws), {
|
|
4009
4428
|
type: "module",
|
|
4010
4429
|
name: e?.name
|
|
4011
4430
|
});
|
|
@@ -4013,7 +4432,7 @@ function Fo(e) {
|
|
|
4013
4432
|
}
|
|
4014
4433
|
//#endregion
|
|
4015
4434
|
//#region src/Passes/AIUpscaler.js
|
|
4016
|
-
var
|
|
4435
|
+
var Ds = {
|
|
4017
4436
|
fast: {
|
|
4018
4437
|
2: "2x-spanx2-ch48.onnx",
|
|
4019
4438
|
4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
|
|
@@ -4027,17 +4446,17 @@ var Io = {
|
|
|
4027
4446
|
4: "4xNomos2_hq_mosr_fp32.onnx"
|
|
4028
4447
|
}
|
|
4029
4448
|
};
|
|
4030
|
-
function
|
|
4449
|
+
function Os() {
|
|
4031
4450
|
let { upscalerModelBaseUrl: e } = ot(), t = {};
|
|
4032
|
-
for (let n in
|
|
4451
|
+
for (let n in Ds) {
|
|
4033
4452
|
t[n] = {};
|
|
4034
|
-
for (let r in
|
|
4453
|
+
for (let r in Ds[n]) t[n][r] = e + Ds[n][r];
|
|
4035
4454
|
}
|
|
4036
4455
|
return t;
|
|
4037
4456
|
}
|
|
4038
|
-
var
|
|
4457
|
+
var ks = {
|
|
4039
4458
|
get QUALITY_PRESETS() {
|
|
4040
|
-
return
|
|
4459
|
+
return Os();
|
|
4041
4460
|
},
|
|
4042
4461
|
TILE_SIZE: 512,
|
|
4043
4462
|
TILE_OVERLAP: 16,
|
|
@@ -4048,17 +4467,17 @@ var Ro = {
|
|
|
4048
4467
|
}],
|
|
4049
4468
|
graphOptimizationLevel: "all"
|
|
4050
4469
|
}
|
|
4051
|
-
},
|
|
4470
|
+
}, As = class extends fr {
|
|
4052
4471
|
constructor(e, t, n = {}) {
|
|
4053
4472
|
if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
|
|
4054
|
-
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 || (() =>
|
|
4473
|
+
this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => tr), this.getSaturation = n.getSaturation || (() => 1), this.getDisplayGain = n.getDisplayGain || (() => null), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize || ks.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
|
|
4055
4474
|
isUpscaling: !1,
|
|
4056
4475
|
isLoading: !1,
|
|
4057
4476
|
abortController: null
|
|
4058
4477
|
}, this._worker = null, this._currentModelUrl = null, this._tileId = 0, this._pendingWorkerHandlers = /* @__PURE__ */ new Set(), this._upscaledAlpha = null, this._upscaledAlphaWidth = 0, this._backupCanvas = null, this._baseWidth = e.width, this._baseHeight = e.height, this._toneMapper = null;
|
|
4059
4478
|
}
|
|
4060
4479
|
async _ensureSession() {
|
|
4061
|
-
let e =
|
|
4480
|
+
let e = ks.QUALITY_PRESETS[this.quality];
|
|
4062
4481
|
if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
|
|
4063
4482
|
let t = e[this.scaleFactor];
|
|
4064
4483
|
if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
|
|
@@ -4068,14 +4487,14 @@ var Ro = {
|
|
|
4068
4487
|
message: `Loading ${this.scaleFactor}x upscale model...`
|
|
4069
4488
|
});
|
|
4070
4489
|
try {
|
|
4071
|
-
this._worker ||= new
|
|
4490
|
+
this._worker ||= new Es(), await new Promise((e, n) => {
|
|
4072
4491
|
let r = (t) => {
|
|
4073
4492
|
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)));
|
|
4074
4493
|
}, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o, storage: s } = ot();
|
|
4075
4494
|
this._worker.addEventListener("message", r), this._worker.postMessage({
|
|
4076
4495
|
type: "load",
|
|
4077
4496
|
url: t,
|
|
4078
|
-
sessionOptions:
|
|
4497
|
+
sessionOptions: ks.SESSION_OPTIONS,
|
|
4079
4498
|
ortRuntimeUrl: i,
|
|
4080
4499
|
ortWasmPaths: a,
|
|
4081
4500
|
cacheNamespace: o,
|
|
@@ -4150,7 +4569,7 @@ var Ro = {
|
|
|
4150
4569
|
alpha: !0
|
|
4151
4570
|
});
|
|
4152
4571
|
this._cacheUpscaledAlpha(t, n * i, r * i);
|
|
4153
|
-
let o =
|
|
4572
|
+
let o = ks.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
|
|
4154
4573
|
for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
|
|
4155
4574
|
if (e.aborted) throw new DOMException("Aborted", "AbortError");
|
|
4156
4575
|
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);
|
|
@@ -4197,8 +4616,9 @@ var Ro = {
|
|
|
4197
4616
|
}), this._toneMapper.ensureSize(n, r);
|
|
4198
4617
|
let i = await this._toneMapper.toPlanar(t, {
|
|
4199
4618
|
exposure: this.getExposure(),
|
|
4200
|
-
toneMapping: this.getToneMapping() ??
|
|
4201
|
-
saturation: this.getSaturation()
|
|
4619
|
+
toneMapping: this.getToneMapping() ?? tr,
|
|
4620
|
+
saturation: this.getSaturation(),
|
|
4621
|
+
gain: this.getDisplayGain()
|
|
4202
4622
|
});
|
|
4203
4623
|
return this._toneMapper.release(), {
|
|
4204
4624
|
planes: i,
|
|
@@ -4292,7 +4712,7 @@ var Ro = {
|
|
|
4292
4712
|
this.hdr = !!e;
|
|
4293
4713
|
}
|
|
4294
4714
|
setQuality(e) {
|
|
4295
|
-
if (!
|
|
4715
|
+
if (!ks.QUALITY_PRESETS[e]) {
|
|
4296
4716
|
console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
|
|
4297
4717
|
return;
|
|
4298
4718
|
}
|
|
@@ -4315,9 +4735,9 @@ var Ro = {
|
|
|
4315
4735
|
async dispose() {
|
|
4316
4736
|
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");
|
|
4317
4737
|
}
|
|
4318
|
-
},
|
|
4319
|
-
constructor({ renderer: e, mainCanvas: t, stages: n, pipeline: r, getExposure: i, getSaturation: a,
|
|
4320
|
-
super(), this.renderer = e, this._issues =
|
|
4738
|
+
}, js = Ke("neural"), Ms = 120, Ns = 2, Ps = 1, Fs = 0, Is = 300, Ls = 5, Rs = 3, zs = 3, Bs = 16, Vs = (e) => Math.max(0, 1 - e / Bs), Hs = class extends fr {
|
|
4739
|
+
constructor({ renderer: e, mainCanvas: t, stages: n, pipeline: r, getExposure: i, getSaturation: a, getDisplayGain: o = null, issues: s = null }) {
|
|
4740
|
+
super(), this.renderer = e, this._issues = s, this.mainCanvas = t, this.upscalerCanvas = this._createUpscalerCanvas(t), this.pipeline = r, this._stages = n, this._getExposure = i, this._getSaturation = a, this._getDisplayGain = o, this.denoiser = null, this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null, this.neuralRendering = !1, this.neuralRenderingSettings = {}, this._retouch = null, this._superResModule = null, this._neuralPostBusy = !1, this._finalQuality = ei.oidnQuality, this.finalDenoise = ei.enableOIDN, this.continuousDenoise = ei.continuousDenoise, this.continuousDenoiseInterval = ei.continuousDenoiseInterval, this._lastCadenceAt = -Infinity, this._lastCadenceSamples = 0, this._failedRefreshes = 0, this._cadenceSuspended = !1, this._movingDenoiseMs = [], this._movingHopeless = !1, this._holdWhileMoving = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this.temporalHistory = ei.oidnTemporalHistory, this._history = null, this._historyDirty = !0, this._knownResetCount = 0, this._seenTracedFrames = 0, this._viewProj = new br(), this._historyCamera = {
|
|
4321
4741
|
world: null,
|
|
4322
4742
|
projInv: null,
|
|
4323
4743
|
viewProj: null,
|
|
@@ -4326,7 +4746,7 @@ var Ro = {
|
|
|
4326
4746
|
count: 0,
|
|
4327
4747
|
leaves: new Uint32Array(),
|
|
4328
4748
|
toPrev: new Float32Array()
|
|
4329
|
-
}, this._matA = new
|
|
4749
|
+
}, this._matA = new br(), this._matB = new br(), this._lastRenderWidth = 0, this._lastRenderHeight = 0, this._pendingStartUpscaler = null, this._pendingCloseDenoise = null, this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._denoiserTileHandler = null, this._denoiserErrorHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null;
|
|
4330
4750
|
}
|
|
4331
4751
|
_createUpscalerCanvas(e) {
|
|
4332
4752
|
let t = e.parentNode;
|
|
@@ -4338,7 +4758,7 @@ var Ro = {
|
|
|
4338
4758
|
return (this.denoiser?.gpuBytes?.() ?? 0) + (this._history?.gpuBytes?.() ?? 0);
|
|
4339
4759
|
}
|
|
4340
4760
|
_recordNoOverlayCanvas(e) {
|
|
4341
|
-
this._issues?.record(
|
|
4761
|
+
this._issues?.record(Ze.DENOISER_UNAVAILABLE, `the ${e} pass needs the render canvas to be in a document, and it is not — skipped`, { pass: e });
|
|
4342
4762
|
}
|
|
4343
4763
|
setRenderSize(e, t) {
|
|
4344
4764
|
this._lastRenderWidth = e, this._lastRenderHeight = t, this._cadenceDowngraded = !1, this._holdWhileMoving = null, this._movingDenoiseMs.length = 0, this._movingHopeless = !1, this._historyDirty = !0, this.denoiser?.abort(), this._unpublishOutput(), this.denoiser?.setSize(e, t), this.upscalerCanvas && (this.upscalerCanvas.width !== e || this.upscalerCanvas.height !== t) && (this.upscalerCanvas.width = e, this.upscalerCanvas.height = t), this.upscaler?.setBaseSize(e, t), this._syncGBufferStages();
|
|
@@ -4348,9 +4768,9 @@ var Ro = {
|
|
|
4348
4768
|
}
|
|
4349
4769
|
setupDenoiser() {
|
|
4350
4770
|
let e = this._stages.pathTracer;
|
|
4351
|
-
this.denoiser = new
|
|
4352
|
-
enableOIDN:
|
|
4353
|
-
oidnQuality:
|
|
4771
|
+
this.denoiser = new ss(this.renderer, {
|
|
4772
|
+
enableOIDN: ei.enableOIDN,
|
|
4773
|
+
oidnQuality: ei.oidnQuality,
|
|
4354
4774
|
backendParams: () => ({
|
|
4355
4775
|
device: this.renderer.backend.device,
|
|
4356
4776
|
adapterInfo: null
|
|
@@ -4367,11 +4787,11 @@ var Ro = {
|
|
|
4367
4787
|
};
|
|
4368
4788
|
}
|
|
4369
4789
|
}), this._syncOIDNInUse(), this._denoiserStartHandler = (e) => this.dispatchEvent({
|
|
4370
|
-
type:
|
|
4790
|
+
type: j.DENOISING_START,
|
|
4371
4791
|
continuous: !!e.continuous
|
|
4372
4792
|
}), this._denoiserEndHandler = (e) => {
|
|
4373
4793
|
this.denoiser?.hasOutput && this._publishOutput(), this.dispatchEvent({
|
|
4374
|
-
type:
|
|
4794
|
+
type: j.DENOISING_END,
|
|
4375
4795
|
continuous: !!e.continuous
|
|
4376
4796
|
});
|
|
4377
4797
|
}, this._denoiserTileHandler = (e) => {
|
|
@@ -4379,7 +4799,7 @@ var Ro = {
|
|
|
4379
4799
|
this._publishOutput();
|
|
4380
4800
|
let t = this.pipeline?.context;
|
|
4381
4801
|
this._stages.compositor && t && this._stages.compositor.render(t);
|
|
4382
|
-
}, this._denoiserErrorHandler = (e) => e.url && this._issues?.record(
|
|
4802
|
+
}, this._denoiserErrorHandler = (e) => e.url && this._issues?.record(Ze.ASSET_UNREACHABLE, `denoiser weights "${e.url}" could not be loaded — the render is not denoised`, {
|
|
4383
4803
|
url: e.url,
|
|
4384
4804
|
asset: "oidn-weights",
|
|
4385
4805
|
cause: String(e.error?.message ?? e.error)
|
|
@@ -4388,9 +4808,9 @@ var Ro = {
|
|
|
4388
4808
|
setupUpscaler() {
|
|
4389
4809
|
if (!this.upscalerCanvas) return;
|
|
4390
4810
|
let e = this._stages.pathTracer;
|
|
4391
|
-
this.upscaler = new
|
|
4392
|
-
scaleFactor:
|
|
4393
|
-
quality:
|
|
4811
|
+
this.upscaler = new As(this.upscalerCanvas, this.renderer, {
|
|
4812
|
+
scaleFactor: ei.upscalerScale || 2,
|
|
4813
|
+
quality: ei.upscalerQuality || "fast",
|
|
4394
4814
|
getSourceCanvas: () => this.renderer.domElement,
|
|
4395
4815
|
refreshInput: () => {
|
|
4396
4816
|
let e = this.pipeline?.context;
|
|
@@ -4403,15 +4823,16 @@ var Ro = {
|
|
|
4403
4823
|
},
|
|
4404
4824
|
getExposure: () => this._getEffectiveExposure(),
|
|
4405
4825
|
getToneMapping: () => this._getToneMapping(),
|
|
4406
|
-
getSaturation: () => this._getSaturation()
|
|
4407
|
-
|
|
4408
|
-
|
|
4826
|
+
getSaturation: () => this._getSaturation(),
|
|
4827
|
+
getDisplayGain: () => this._getDisplayGain?.() ?? null
|
|
4828
|
+
}), this.upscaler.enabled = ei.enableUpscaler || !1, this._upscalerResChangedHandler = (e) => this.dispatchEvent({
|
|
4829
|
+
type: j.RESOLUTION_CHANGED,
|
|
4409
4830
|
width: e.width,
|
|
4410
4831
|
height: e.height
|
|
4411
|
-
}), this._upscalerStartHandler = () => this.dispatchEvent({ type:
|
|
4412
|
-
type:
|
|
4832
|
+
}), this._upscalerStartHandler = () => this.dispatchEvent({ type: j.UPSCALING_START }), this._upscalerProgressHandler = (e) => this.dispatchEvent({
|
|
4833
|
+
type: j.UPSCALING_PROGRESS,
|
|
4413
4834
|
progress: e.progress
|
|
4414
|
-
}), this._upscalerEndHandler = () => this.dispatchEvent({ type:
|
|
4835
|
+
}), this._upscalerEndHandler = () => this.dispatchEvent({ type: j.UPSCALING_END }), this.upscaler.addEventListener("resolution_changed", this._upscalerResChangedHandler), this.upscaler.addEventListener("start", this._upscalerStartHandler), this.upscaler.addEventListener("progress", this._upscalerProgressHandler), this.upscaler.addEventListener("end", this._upscalerEndHandler);
|
|
4415
4836
|
}
|
|
4416
4837
|
get denoiserStrategy() {
|
|
4417
4838
|
return this.continuousDenoise ? "oidn" : this._stages.asvgf?.enabled ? "asvgf" : this._stages.nrd?.enabled ? "nrd" : this._stages.edgeFilter?.enabled ? "edgeaware" : "none";
|
|
@@ -4439,8 +4860,7 @@ var Ro = {
|
|
|
4439
4860
|
this._applyASVGFPreset(e);
|
|
4440
4861
|
}
|
|
4441
4862
|
setAutoExposureEnabled(e, t) {
|
|
4442
|
-
|
|
4443
|
-
n.autoExposure && (n.autoExposure.enabled = e, !e && this.renderer && (this.renderer.toneMappingExposure = t));
|
|
4863
|
+
this._stages.autoExposure?.setEnabled(e, t);
|
|
4444
4864
|
}
|
|
4445
4865
|
get requiresMotionVectors() {
|
|
4446
4866
|
return !!(this._stages.asvgf?.enabled || this._stages.nrd?.enabled);
|
|
@@ -4464,8 +4884,8 @@ var Ro = {
|
|
|
4464
4884
|
get holdsWhileMoving() {
|
|
4465
4885
|
if (!this._stages.pathTracer?.viewIsChanging || !this.continuousDenoise || this._cadenceSuspended || !this.denoiser?.enabled || this._movingHopeless) return !1;
|
|
4466
4886
|
let e = this.movingCostMs, t = this._movingDenoiseMs.length;
|
|
4467
|
-
e >
|
|
4468
|
-
let n = !this._movingHopeless && (t < 2 || e <=
|
|
4887
|
+
e > Is * Rs && (this._movingHopeless = !0, this._syncGBufferStages());
|
|
4888
|
+
let n = !this._movingHopeless && (t < 2 || e <= Is);
|
|
4469
4889
|
return this._holdWhileMoving = (this._holdWhileMoving === null || this._holdWhileMoving) && n, this._holdWhileMoving;
|
|
4470
4890
|
}
|
|
4471
4891
|
skipsTrace() {
|
|
@@ -4482,7 +4902,7 @@ var Ro = {
|
|
|
4482
4902
|
this.pipeline?.context?.removeTexture("oidn:output"), this.denoiser?.invalidateOutput();
|
|
4483
4903
|
}
|
|
4484
4904
|
_checkHeldFrameHealthy() {
|
|
4485
|
-
!this.denoiser?.hasOutput || this._failedRefreshes <
|
|
4905
|
+
!this.denoiser?.hasOutput || this._failedRefreshes < zs || this._unpublishOutput();
|
|
4486
4906
|
}
|
|
4487
4907
|
tickContinuousDenoise(e) {
|
|
4488
4908
|
let t = this.denoiser;
|
|
@@ -4492,12 +4912,12 @@ var Ro = {
|
|
|
4492
4912
|
if (!n) this._holdWhileMoving = null, this._movingDenoiseMs.length = 0;
|
|
4493
4913
|
else if (!this.holdsWhileMoving) return !1;
|
|
4494
4914
|
if (t.state.isDenoising || t.state.isLoading || !n && e <= this._lastCadenceSamples) return !1;
|
|
4495
|
-
let r = performance.now(), i = n ?
|
|
4915
|
+
let r = performance.now(), i = n ? Fs : this._lastCadenceSamples === 0 ? Ps : Ns, a = Math.max(this.continuousDenoiseInterval, t.lastDenoiseMs * i);
|
|
4496
4916
|
if (r - this._lastCadenceAt < a) return !1;
|
|
4497
|
-
this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs >
|
|
4917
|
+
this._lastCadenceAt = r, this._lastCadenceSamples = e, t.lastDenoiseMs > Ms && (this._cadenceDowngraded = !0);
|
|
4498
4918
|
let o = this._cadenceDowngraded ? this.previewQuality() : this._finalQuality;
|
|
4499
4919
|
return t.quality !== o && t.updateQuality(o), t.start({ continuous: !0 }).then((e) => {
|
|
4500
|
-
this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length >
|
|
4920
|
+
this._failedRefreshes = e ? 0 : this._failedRefreshes + 1, !(!e || !n) && (this._movingDenoiseMs.push(t.lastDenoiseMs), this._movingDenoiseMs.length > Ls && this._movingDenoiseMs.shift());
|
|
4501
4921
|
}), !0;
|
|
4502
4922
|
}
|
|
4503
4923
|
previewQuality() {
|
|
@@ -4539,7 +4959,7 @@ var Ro = {
|
|
|
4539
4959
|
r && (this._ensureHistory().merge(r, t.frameCount, this._historyCameraNow(), {
|
|
4540
4960
|
commit: !0,
|
|
4541
4961
|
keepHistory: !this._historyDirty && !n,
|
|
4542
|
-
historyScale:
|
|
4962
|
+
historyScale: Vs(t.frameCount)
|
|
4543
4963
|
}), this._historyDirty = !1);
|
|
4544
4964
|
}
|
|
4545
4965
|
afterReset() {
|
|
@@ -4560,11 +4980,10 @@ var Ro = {
|
|
|
4560
4980
|
let n = this._ensureHistory();
|
|
4561
4981
|
this._historyDirty && n.invalidate(), n.accumulate(t, this._historyCameraNow(), this._takeMovedPlacements()), this._historyDirty = !1;
|
|
4562
4982
|
}
|
|
4563
|
-
notePlacementMoving(e, t
|
|
4983
|
+
notePlacementMoving(e, t) {
|
|
4564
4984
|
e < 0 || !this.historyActive || this._movedPlacements.has(e) || this._movedPlacements.set(e, {
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
prev: t.slice(n, n + 16)
|
|
4985
|
+
matrixOf: t,
|
|
4986
|
+
prev: t().slice()
|
|
4568
4987
|
});
|
|
4569
4988
|
}
|
|
4570
4989
|
_takeMovedPlacements() {
|
|
@@ -4573,8 +4992,8 @@ var Ro = {
|
|
|
4573
4992
|
t.leaves.length < e.size && (t.leaves = new Uint32Array(e.size * 2), t.toPrev = new Float32Array(e.size * 32));
|
|
4574
4993
|
let n = [...e.keys()].sort((e, t) => e - t);
|
|
4575
4994
|
for (let r = 0; r < n.length; r++) {
|
|
4576
|
-
let {
|
|
4577
|
-
this._matB.fromArray(i
|
|
4995
|
+
let { matrixOf: i, prev: a } = e.get(n[r]);
|
|
4996
|
+
this._matB.fromArray(i()).invert(), this._matA.fromArray(a).multiply(this._matB).toArray(t.toPrev, r * 16), t.leaves[r] = n[r];
|
|
4578
4997
|
}
|
|
4579
4998
|
return e.clear(), t;
|
|
4580
4999
|
}
|
|
@@ -4582,9 +5001,9 @@ var Ro = {
|
|
|
4582
5001
|
let e = this._stages.pathTracer, t = this._history;
|
|
4583
5002
|
if (!t?.valid || this._historyDirty || !this.historyActive || e.isComplete || e.resetCount !== this._knownResetCount || t.width !== this._lastRenderWidth || t.height !== this._lastRenderHeight) return null;
|
|
4584
5003
|
if (e.frameCount <= 1) return t.textures;
|
|
4585
|
-
if (e.frameCount >=
|
|
5004
|
+
if (e.frameCount >= Bs) return null;
|
|
4586
5005
|
let n = this._historyInputs();
|
|
4587
|
-
return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale:
|
|
5006
|
+
return n ? t.merge(n, e.frameCount, this._historyCameraNow(), { historyScale: Vs(e.frameCount) }) : null;
|
|
4588
5007
|
}
|
|
4589
5008
|
_historyInputs() {
|
|
4590
5009
|
let e = this._stages.pathTracer, t = this.pipeline?.context, n = this.renderer?.backend;
|
|
@@ -4609,7 +5028,7 @@ var Ro = {
|
|
|
4609
5028
|
return t.world = e.cameraWorldMatrix.value.elements, t.projInv = e.cameraProjectionMatrixInverse.value.elements, t.viewProj = this._viewProj.elements, t.orthographic = e.uniforms?.get("cameraProjection")?.value === Ae.orthographic, t;
|
|
4610
5029
|
}
|
|
4611
5030
|
_ensureHistory() {
|
|
4612
|
-
return this._history ??= new
|
|
5031
|
+
return this._history ??= new Cs(this.renderer.backend.device), this._history.settings.cleanAux = !!this.denoiser?.expectsCleanAux(this._finalQuality), this._history;
|
|
4613
5032
|
}
|
|
4614
5033
|
_releaseHistory() {
|
|
4615
5034
|
this._history?.dispose(), this._history = null, this._historyDirty = !0, this._movedPlacements.clear();
|
|
@@ -4621,7 +5040,7 @@ var Ro = {
|
|
|
4621
5040
|
_restoreRenderDisplay() {
|
|
4622
5041
|
let e = this.upscalerCanvas && this.upscalerCanvas.style.display !== "none";
|
|
4623
5042
|
return this.upscalerCanvas && (this.upscalerCanvas.style.display = "none"), this.mainCanvas && (this.mainCanvas.style.opacity = "1"), e && this._lastRenderWidth && this._lastRenderHeight && this.dispatchEvent({
|
|
4624
|
-
type:
|
|
5043
|
+
type: j.RESOLUTION_CHANGED,
|
|
4625
5044
|
width: this._lastRenderWidth,
|
|
4626
5045
|
height: this._lastRenderHeight
|
|
4627
5046
|
}), !!e;
|
|
@@ -4646,19 +5065,20 @@ var Ro = {
|
|
|
4646
5065
|
return;
|
|
4647
5066
|
}
|
|
4648
5067
|
if (!this.pipeline?.context?.getTexture("oidn:output")) {
|
|
4649
|
-
|
|
5068
|
+
js.warn("neural pass skipped: no denoised picture — it needs OIDN");
|
|
4650
5069
|
return;
|
|
4651
5070
|
}
|
|
4652
|
-
this._neuralPostBusy = !0, this.dispatchEvent({ type:
|
|
5071
|
+
this._neuralPostBusy = !0, this.dispatchEvent({ type: j.UPSCALING_START });
|
|
4653
5072
|
try {
|
|
4654
|
-
let r = await import("./NeuralSuperRes-
|
|
5073
|
+
let r = await import("./NeuralSuperRes-DV5TtURP.js").then((e) => e.t);
|
|
4655
5074
|
this._superResModule = r;
|
|
4656
|
-
let i = n ? await import("./NeuralRetouch-
|
|
4657
|
-
if (n && !s && (
|
|
5075
|
+
let i = n ? await import("./NeuralRetouch-C3Q2XqbF.js").then((e) => e.t) : null, a = this.denoiser?._outTexSize, o = (a?.width ?? 0) * (a?.height ?? 0), s = n && o <= i.RETOUCH_MAX_PIXELS;
|
|
5076
|
+
if (n && !s && (js.warn(`Neural rendering skipped: the render is ${(o / 1e6).toFixed(1)} MP, above the ${(i.RETOUCH_MAX_PIXELS / 1e6).toFixed(1)} MP the pass survives.` + (t ? " The upscale still ran." : "")), this._releaseNeuralRetouch()), !t && !s) return;
|
|
4658
5077
|
let c = {
|
|
4659
5078
|
exposure: this._getEffectiveExposure(),
|
|
4660
5079
|
toneMapping: this._getToneMapping(),
|
|
4661
|
-
saturation: this._getSaturation?.() ?? 1
|
|
5080
|
+
saturation: this._getSaturation?.() ?? 1,
|
|
5081
|
+
gain: this._getDisplayGain?.() ?? null
|
|
4662
5082
|
}, l = await r.readDenoisedHalf(this.denoiser);
|
|
4663
5083
|
t && (this._neuralUpscaler && (this._neuralUpscaler.inputWidth !== l.width || this._neuralUpscaler.inputHeight !== l.height) && this._releaseNeuralUpscaler(), this._neuralUpscaler ||= await r.NeuralSuperRes.create({
|
|
4664
5084
|
width: l.width,
|
|
@@ -4684,14 +5104,14 @@ var Ro = {
|
|
|
4684
5104
|
return;
|
|
4685
5105
|
}
|
|
4686
5106
|
this.mainCanvas && (this.mainCanvas.style.opacity = "0"), this.dispatchEvent({
|
|
4687
|
-
type:
|
|
5107
|
+
type: j.RESOLUTION_CHANGED,
|
|
4688
5108
|
width: u.width,
|
|
4689
5109
|
height: u.height
|
|
4690
5110
|
});
|
|
4691
5111
|
} catch (e) {
|
|
4692
|
-
|
|
5112
|
+
js.warn("neural pass failed", e);
|
|
4693
5113
|
} finally {
|
|
4694
|
-
this._neuralPostBusy = !1, this.dispatchEvent({ type:
|
|
5114
|
+
this._neuralPostBusy = !1, this.dispatchEvent({ type: j.UPSCALING_END });
|
|
4695
5115
|
}
|
|
4696
5116
|
}
|
|
4697
5117
|
}
|
|
@@ -4741,7 +5161,7 @@ var Ro = {
|
|
|
4741
5161
|
this._unpublishOutput(), this._restoreRenderDisplay(), this._historyDirty = !0;
|
|
4742
5162
|
}
|
|
4743
5163
|
dispose() {
|
|
4744
|
-
this._cleanupCompletionListener(), this._releaseNeuralUpscaler(), this._releaseNeuralRetouch(), this._unpublishOutput(), this._releaseHistory(), this.denoiser &&= (this._denoiserStartHandler && this.denoiser.removeEventListener("start", this._denoiserStartHandler), this._denoiserEndHandler && this.denoiser.removeEventListener("end", this._denoiserEndHandler), this._denoiserTileHandler && this.denoiser.removeEventListener("tileProgress", this._denoiserTileHandler), this._denoiserErrorHandler && this.denoiser.removeEventListener("error", this._denoiserErrorHandler), this.denoiser.dispose(), null), this.upscaler && (this._upscalerResChangedHandler && this.upscaler.removeEventListener("resolution_changed", this._upscalerResChangedHandler), this._upscalerStartHandler && this.upscaler.removeEventListener("start", this._upscalerStartHandler), this._upscalerProgressHandler && this.upscaler.removeEventListener("progress", this._upscalerProgressHandler), this._upscalerEndHandler && this.upscaler.removeEventListener("end", this._upscalerEndHandler), this.upscaler.dispose(), this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null), this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._denoiserTileHandler = null, this._denoiserErrorHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this._issues = null, this.upscalerCanvas?.parentNode && (this.upscalerCanvas.parentNode.removeChild(this.upscalerCanvas), this.upscalerCanvas = null);
|
|
5164
|
+
this._cleanupCompletionListener(), this._releaseNeuralUpscaler(), this._releaseNeuralRetouch(), this._unpublishOutput(), this._releaseHistory(), this.denoiser &&= (this._denoiserStartHandler && this.denoiser.removeEventListener("start", this._denoiserStartHandler), this._denoiserEndHandler && this.denoiser.removeEventListener("end", this._denoiserEndHandler), this._denoiserTileHandler && this.denoiser.removeEventListener("tileProgress", this._denoiserTileHandler), this._denoiserErrorHandler && this.denoiser.removeEventListener("error", this._denoiserErrorHandler), this.denoiser.dispose(), null), this.upscaler && (this._upscalerResChangedHandler && this.upscaler.removeEventListener("resolution_changed", this._upscalerResChangedHandler), this._upscalerStartHandler && this.upscaler.removeEventListener("start", this._upscalerStartHandler), this._upscalerProgressHandler && this.upscaler.removeEventListener("progress", this._upscalerProgressHandler), this._upscalerEndHandler && this.upscaler.removeEventListener("end", this._upscalerEndHandler), this.upscaler.dispose(), this.upscaler = null, this.upscalerBackend = "esrgan", this._neuralUpscaler = null), this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._denoiserTileHandler = null, this._denoiserErrorHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null, this._onReset = null, this._onPostProcessRefresh = null, this._onDisplayRefresh = null, this._getExposure = null, this._getSaturation = null, this._getDisplayGain = null, this._issues = null, this.upscalerCanvas?.parentNode && (this.upscalerCanvas.parentNode.removeChild(this.upscalerCanvas), this.upscalerCanvas = null);
|
|
4745
5165
|
}
|
|
4746
5166
|
setOverlayManager(e) {
|
|
4747
5167
|
this._overlayManager = e;
|
|
@@ -4804,7 +5224,7 @@ var Ro = {
|
|
|
4804
5224
|
this.upscaler?.setQuality(e);
|
|
4805
5225
|
}
|
|
4806
5226
|
setAutoExposure(e) {
|
|
4807
|
-
this.setAutoExposureEnabled(e, this._getExposure())
|
|
5227
|
+
this.setAutoExposureEnabled(e, this._getExposure());
|
|
4808
5228
|
}
|
|
4809
5229
|
setStrategy(e, t) {
|
|
4810
5230
|
this.setDenoiserStrategy(e, t), this._onReset?.();
|
|
@@ -4842,20 +5262,20 @@ var Ro = {
|
|
|
4842
5262
|
].forEach((t) => e.removeTexture(t));
|
|
4843
5263
|
}
|
|
4844
5264
|
_applyNRDPreset(e) {
|
|
4845
|
-
let t =
|
|
5265
|
+
let t = Qr[e];
|
|
4846
5266
|
if (!t) return;
|
|
4847
5267
|
let n = {};
|
|
4848
|
-
for (let e of
|
|
5268
|
+
for (let e of Zr) n[e] = Xr[e];
|
|
4849
5269
|
this._stages.nrd?.updateParameters({
|
|
4850
5270
|
...n,
|
|
4851
5271
|
...t
|
|
4852
5272
|
});
|
|
4853
5273
|
}
|
|
4854
5274
|
_applyASVGFPreset(e) {
|
|
4855
|
-
let t =
|
|
5275
|
+
let t = qr[e];
|
|
4856
5276
|
t && (this._stages.asvgf?.updateParameters(t), this._stages.bilateralFilter?.updateParameters(t), this._stages.variance && t.varianceBoost !== void 0 && (this._stages.variance.varianceBoost.value = t.varianceBoost));
|
|
4857
5277
|
}
|
|
4858
|
-
},
|
|
5278
|
+
}, Us = class {
|
|
4859
5279
|
constructor() {
|
|
4860
5280
|
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;
|
|
4861
5281
|
}
|
|
@@ -4879,18 +5299,18 @@ var Ro = {
|
|
|
4879
5299
|
dispose() {
|
|
4880
5300
|
this.visible = !1;
|
|
4881
5301
|
}
|
|
4882
|
-
},
|
|
5302
|
+
}, Ws = class {
|
|
4883
5303
|
constructor(e, t) {
|
|
4884
5304
|
this.layer = "scene", this._enabled = !0, this._scene = e, this._camera = t, this._build([]);
|
|
4885
5305
|
}
|
|
4886
5306
|
_build(e) {
|
|
4887
|
-
this._orthographic = this._camera.isOrthographicCamera === !0, this._outlineNode =
|
|
5307
|
+
this._orthographic = this._camera.isOrthographicCamera === !0, this._outlineNode = Hr(this._scene, this._camera, {
|
|
4888
5308
|
selectedObjects: e,
|
|
4889
5309
|
edgeThickness: G(1),
|
|
4890
5310
|
edgeGlow: G(0)
|
|
4891
5311
|
});
|
|
4892
|
-
let t = G(3), n = G(new
|
|
4893
|
-
this._material = new bn(), this._material.colorNode = J(o, s), this._material.transparent = !0, this._material.blending =
|
|
5312
|
+
let t = G(3), n = G(new sr(16777215)), r = G(new sr(1640965)), { visibleEdge: i, hiddenEdge: a } = this._outlineNode, o = i.mul(n).add(a.mul(r)).mul(t), s = o.r.max(o.g).max(o.b).clamp(0, 1);
|
|
5313
|
+
this._material = new bn(), this._material.colorNode = J(o, s), this._material.transparent = !0, this._material.blending = lr, this._material.blendEquation = nr, this._material.blendSrc = Tr, this._material.blendDst = Tr, this._material.blendEquationAlpha = nr, this._material.blendSrcAlpha = Tr, this._material.blendDstAlpha = Tr, this._material.toneMapped = !1, this._material.depthTest = !1, this._material.depthWrite = !1, this._quad = new xn(this._material);
|
|
4894
5314
|
}
|
|
4895
5315
|
setSelectedObjects(e) {
|
|
4896
5316
|
this._outlineNode.selectedObjects = e;
|
|
@@ -4917,11 +5337,11 @@ var Ro = {
|
|
|
4917
5337
|
this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
|
|
4918
5338
|
}
|
|
4919
5339
|
};
|
|
4920
|
-
function
|
|
5340
|
+
function Gs(e = !1) {
|
|
4921
5341
|
let t = document.createElement("canvas");
|
|
4922
5342
|
return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
|
|
4923
5343
|
}
|
|
4924
|
-
function
|
|
5344
|
+
function Ks(e, t = Infinity) {
|
|
4925
5345
|
let n = e?.getBoundingClientRect();
|
|
4926
5346
|
if (!n || n.width === 0 || n.height === 0) return null;
|
|
4927
5347
|
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);
|
|
@@ -4932,26 +5352,26 @@ function ts(e, t = Infinity) {
|
|
|
4932
5352
|
}
|
|
4933
5353
|
//#endregion
|
|
4934
5354
|
//#region src/managers/helpers/ViewOverlayRenderer.js
|
|
4935
|
-
var
|
|
5355
|
+
var qs = 4096, Js = class {
|
|
4936
5356
|
constructor() {
|
|
4937
|
-
this.canvas =
|
|
5357
|
+
this.canvas = Gs(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
|
|
4938
5358
|
}
|
|
4939
5359
|
async init({ device: e, sizeSource: t }) {
|
|
4940
5360
|
this._sizeSource = t;
|
|
4941
|
-
let n = e.onuncapturederror, r = new
|
|
5361
|
+
let n = e.onuncapturederror, r = new Tn({
|
|
4942
5362
|
canvas: this.canvas,
|
|
4943
5363
|
device: e,
|
|
4944
5364
|
alpha: !0,
|
|
4945
5365
|
antialias: (window.devicePixelRatio || 1) < 2
|
|
4946
5366
|
});
|
|
4947
|
-
return await r.init(), e.onuncapturederror = n, r.outputColorSpace =
|
|
5367
|
+
return await r.init(), e.onuncapturederror = n, r.outputColorSpace = Mr, r.setPixelRatio(1), r.setClearColor(0, 0), r.autoClear = !1, this.renderer = r, this.syncSize(), this;
|
|
4948
5368
|
}
|
|
4949
5369
|
get isVisible() {
|
|
4950
5370
|
return this._visible;
|
|
4951
5371
|
}
|
|
4952
5372
|
syncSize() {
|
|
4953
5373
|
if (!this.renderer) return;
|
|
4954
|
-
let e =
|
|
5374
|
+
let e = Ks(this._sizeSource, qs);
|
|
4955
5375
|
!e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
|
|
4956
5376
|
}
|
|
4957
5377
|
begin() {
|
|
@@ -4963,18 +5383,18 @@ var ns = 4096, rs = class {
|
|
|
4963
5383
|
dispose() {
|
|
4964
5384
|
Pe(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
|
|
4965
5385
|
}
|
|
4966
|
-
},
|
|
5386
|
+
}, Ys = Ke("overlay"), Xs = (e, t) => e.visible && e.layer === t && e.render, Zs = class {
|
|
4967
5387
|
constructor(e) {
|
|
4968
|
-
this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas =
|
|
5388
|
+
this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = Gs(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
|
|
4969
5389
|
}
|
|
4970
5390
|
async initViewRenderer({ device: e, sizeSource: t }) {
|
|
4971
5391
|
if (!(!e || !t)) try {
|
|
4972
|
-
this._viewOverlay = await new
|
|
5392
|
+
this._viewOverlay = await new Js().init({
|
|
4973
5393
|
device: e,
|
|
4974
5394
|
sizeSource: t
|
|
4975
5395
|
});
|
|
4976
5396
|
} catch (e) {
|
|
4977
|
-
|
|
5397
|
+
Ys.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
|
|
4978
5398
|
}
|
|
4979
5399
|
}
|
|
4980
5400
|
gpuResources() {
|
|
@@ -4994,11 +5414,11 @@ var ns = 4096, rs = class {
|
|
|
4994
5414
|
}
|
|
4995
5415
|
setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
|
|
4996
5416
|
this.setHelperScene(e);
|
|
4997
|
-
let s = new
|
|
4998
|
-
this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(
|
|
5417
|
+
let s = new Us();
|
|
5418
|
+
this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener(j.RESOLUTION_CHANGED, (e) => {
|
|
4999
5419
|
s.setRenderSize(e.width, e.height);
|
|
5000
5420
|
}), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
|
|
5001
|
-
let c = new
|
|
5421
|
+
let c = new Ws(t, this.camera);
|
|
5002
5422
|
this.register("outline", c);
|
|
5003
5423
|
}
|
|
5004
5424
|
_wireDenoiserTileEvents(e, t) {
|
|
@@ -5010,7 +5430,7 @@ var ns = 4096, rs = class {
|
|
|
5010
5430
|
}));
|
|
5011
5431
|
}
|
|
5012
5432
|
register(e, t) {
|
|
5013
|
-
this._helpers.has(e) && (
|
|
5433
|
+
this._helpers.has(e) && (Ys.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
|
|
5014
5434
|
}
|
|
5015
5435
|
unregister(e) {
|
|
5016
5436
|
let t = this._helpers.get(e);
|
|
@@ -5048,16 +5468,16 @@ var ns = 4096, rs = class {
|
|
|
5048
5468
|
}
|
|
5049
5469
|
_renderSceneLayer(e) {
|
|
5050
5470
|
this._helperScene?.render(e, this.camera);
|
|
5051
|
-
for (let t of this._helpers.values())
|
|
5471
|
+
for (let t of this._helpers.values()) Xs(t, "scene") && t.render(e, this.camera);
|
|
5052
5472
|
}
|
|
5053
5473
|
_hasVisibleSceneOverlay() {
|
|
5054
5474
|
if (this._helperScene?.isDrawing) return !0;
|
|
5055
|
-
for (let e of this._helpers.values()) if (
|
|
5475
|
+
for (let e of this._helpers.values()) if (Xs(e, "scene")) return !0;
|
|
5056
5476
|
return !1;
|
|
5057
5477
|
}
|
|
5058
5478
|
refreshHUD() {
|
|
5059
5479
|
let e = this._hudCanvas, t = this._hudCtx, n = !1;
|
|
5060
|
-
for (let e of this._helpers.values()) if (
|
|
5480
|
+
for (let e of this._helpers.values()) if (Xs(e, "hud")) {
|
|
5061
5481
|
n = !0;
|
|
5062
5482
|
break;
|
|
5063
5483
|
}
|
|
@@ -5066,10 +5486,10 @@ var ns = 4096, rs = class {
|
|
|
5066
5486
|
return;
|
|
5067
5487
|
}
|
|
5068
5488
|
e.style.display !== "" && (e.style.display = "");
|
|
5069
|
-
let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ?
|
|
5489
|
+
let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Ks(e) : null;
|
|
5070
5490
|
if (a) {
|
|
5071
5491
|
(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);
|
|
5072
|
-
for (let e of this._helpers.values())
|
|
5492
|
+
for (let e of this._helpers.values()) Xs(e, "hud") && e.render(t, r, i);
|
|
5073
5493
|
t.restore(), e.style.display !== "" && (e.style.display = "");
|
|
5074
5494
|
}
|
|
5075
5495
|
}
|
|
@@ -5080,7 +5500,7 @@ var ns = 4096, rs = class {
|
|
|
5080
5500
|
};
|
|
5081
5501
|
//#endregion
|
|
5082
5502
|
//#region src/managers/AnimationManager.js
|
|
5083
|
-
function
|
|
5503
|
+
function Qs(e, t) {
|
|
5084
5504
|
let n = [...e].filter((t) => {
|
|
5085
5505
|
for (let n = t.parent; n; n = n.parent) if (e.has(n)) return !1;
|
|
5086
5506
|
return !0;
|
|
@@ -5089,18 +5509,18 @@ function ss(e, t) {
|
|
|
5089
5509
|
for (let e of n) e.traverse?.(() => i++);
|
|
5090
5510
|
return i + n.length / 2 < r ? n : null;
|
|
5091
5511
|
}
|
|
5092
|
-
var
|
|
5512
|
+
var $s = class extends fr {
|
|
5093
5513
|
constructor() {
|
|
5094
|
-
super(), this.mixer = null, this.timer = new
|
|
5514
|
+
super(), this.mixer = null, this.timer = new Fr(), this.actions = [], this.isPlaying = !1, this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._meshPositions = null, this._tempVec = new $(), this._skinnedCache = null, this._clipsCache = null, this._savedTimeScale = 1, this.onFinished = null, this._rigid = !1, this._plans = null, this._allPlan = null, this._activeClip = 0, this._slotOf = null, this._lastWorld = null, this._lastVisible = null, this._lastMeshWorld = null, this._lastMorphWeights = null, this.wakeCallback = null, this.applyPoseCallback = null;
|
|
5095
5515
|
}
|
|
5096
5516
|
init(e, t, n, r) {
|
|
5097
5517
|
if (this.dispose(), !r || r.length === 0) return;
|
|
5098
|
-
this._scene = e, this._mixerRoot = t, this._meshes = n, this.mixer = new
|
|
5518
|
+
this._scene = e, this._mixerRoot = t, this._meshes = n, this.mixer = new rr(t);
|
|
5099
5519
|
let i = r.map((e) => this.mixer.clipAction(e)), a = (e, t) => e.name === t || e.getObjectByName(t) !== void 0;
|
|
5100
5520
|
!i.some((e) => e.getClip().tracks.some((e) => {
|
|
5101
5521
|
let n = e.name.split(".")[0];
|
|
5102
5522
|
return a(t, n);
|
|
5103
|
-
})) && t !== e && (console.log("[AnimationManager] Tracks did not resolve from model root, retrying with scene root"), this.mixer = new
|
|
5523
|
+
})) && t !== e && (console.log("[AnimationManager] Tracks did not resolve from model root, retrying with scene root"), this.mixer = new rr(e), this._mixerRoot = e, i = r.map((e) => this.mixer.clipAction(e))), this.actions = i, this._rigid = !n.some((e) => e?.isSkinnedMesh) && !r.some((e) => e.tracks.some((e) => e.name.includes("morphTargetInfluences"))), this._planClips(r), this.mixer.addEventListener("finished", () => {
|
|
5104
5524
|
this.isPlaying = !1, this.timer.reset(), this.onFinished && this.onFinished();
|
|
5105
5525
|
}), this._meshTriRanges = [], this._skinnedCache = [];
|
|
5106
5526
|
let o = 0;
|
|
@@ -5124,7 +5544,7 @@ var cs = class extends cr {
|
|
|
5124
5544
|
}), this._plans = e.map((e) => {
|
|
5125
5545
|
let r = /* @__PURE__ */ new Set(), i = !1, a = !1;
|
|
5126
5546
|
for (let o of e.tracks) {
|
|
5127
|
-
let { nodeName: e, propertyName: s } =
|
|
5547
|
+
let { nodeName: e, propertyName: s } = Or.parseTrackName(o.name), c = e === "" || e === "." ? t : n.get(e);
|
|
5128
5548
|
if (!c) {
|
|
5129
5549
|
a = !0;
|
|
5130
5550
|
continue;
|
|
@@ -5143,7 +5563,7 @@ var cs = class extends cr {
|
|
|
5143
5563
|
visibility: i,
|
|
5144
5564
|
cameras: [...s],
|
|
5145
5565
|
nodes: a ? null : r,
|
|
5146
|
-
roots: a ? null :
|
|
5566
|
+
roots: a ? null : Qs(r, t)
|
|
5147
5567
|
};
|
|
5148
5568
|
}), this._allPlan = null, !this._rigid) return;
|
|
5149
5569
|
this._slotOf = new Int32Array(this._meshes.length).fill(-1);
|
|
@@ -5162,7 +5582,7 @@ var cs = class extends cr {
|
|
|
5162
5582
|
visibility: n,
|
|
5163
5583
|
cameras: [...t],
|
|
5164
5584
|
nodes: r,
|
|
5165
|
-
roots: r ?
|
|
5585
|
+
roots: r ? Qs(r, this._mixerRoot) : null
|
|
5166
5586
|
};
|
|
5167
5587
|
}
|
|
5168
5588
|
return this._allPlan;
|
|
@@ -5197,23 +5617,23 @@ var cs = class extends cr {
|
|
|
5197
5617
|
if (!(!this.mixer || this.actions.length === 0)) {
|
|
5198
5618
|
if (this.mixer.stopAllAction(), e === -1) for (let e of this.actions) e.play();
|
|
5199
5619
|
else e >= 0 && e < this.actions.length && this.actions[e].play();
|
|
5200
|
-
this._activeClip = e, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type:
|
|
5620
|
+
this._activeClip = e, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: j.ANIMATION_STARTED });
|
|
5201
5621
|
}
|
|
5202
5622
|
}
|
|
5203
5623
|
pause() {
|
|
5204
|
-
this.mixer && (this.mixer.timeScale = 0, this.timer.reset(), this.isPlaying = !1, this.dispatchEvent({ type:
|
|
5624
|
+
this.mixer && (this.mixer.timeScale = 0, this.timer.reset(), this.isPlaying = !1, this.dispatchEvent({ type: j.ANIMATION_PAUSED }));
|
|
5205
5625
|
}
|
|
5206
5626
|
resume() {
|
|
5207
|
-
this.mixer && (this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type:
|
|
5627
|
+
this.mixer && (this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !0, this.wakeCallback?.(), this.dispatchEvent({ type: j.ANIMATION_STARTED }));
|
|
5208
5628
|
}
|
|
5209
5629
|
stop() {
|
|
5210
|
-
this.mixer && (this.mixer.stopAllAction(), this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !1, this._rigid && (this._mixerRoot.updateMatrixWorld(!0), this._applyRigidPose(-1)), this.dispatchEvent({ type:
|
|
5630
|
+
this.mixer && (this.mixer.stopAllAction(), this.mixer.timeScale = this._savedTimeScale || 1, this.timer.reset(), this.isPlaying = !1, this._rigid && (this._mixerRoot.updateMatrixWorld(!0), this._applyRigidPose(-1)), this.dispatchEvent({ type: j.ANIMATION_STOPPED }));
|
|
5211
5631
|
}
|
|
5212
5632
|
setSpeed(e) {
|
|
5213
5633
|
this._savedTimeScale = e, this.mixer && this.isPlaying && (this.mixer.timeScale = e);
|
|
5214
5634
|
}
|
|
5215
5635
|
setLoop(e) {
|
|
5216
|
-
let t = e ?
|
|
5636
|
+
let t = e ? _r : gr;
|
|
5217
5637
|
for (let n of this.actions) n.setLoop(t), n.clampWhenFinished = !e;
|
|
5218
5638
|
}
|
|
5219
5639
|
seekTo(e, t = 0) {
|
|
@@ -5294,19 +5714,19 @@ var cs = class extends cr {
|
|
|
5294
5714
|
dispose() {
|
|
5295
5715
|
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;
|
|
5296
5716
|
}
|
|
5297
|
-
},
|
|
5717
|
+
}, ec = new $(0, 0, -1), tc = (e) => {
|
|
5298
5718
|
for (; e.parent;) e = e.parent;
|
|
5299
5719
|
return e.isScene ? e : null;
|
|
5300
|
-
},
|
|
5720
|
+
}, nc = class {
|
|
5301
5721
|
constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
|
|
5302
|
-
this._app = r, this._orbitControls = n, this._camera = e, this._controls = new
|
|
5722
|
+
this._app = r, this._orbitControls = n, this._camera = e, this._controls = new Ur(e, t), this._gizmoScene = new Nr(), this._gizmoScene.add(this._controls.getHelper()), this._attached = null, this._isDragging = !1, this._meshes = null, this._refitInFlight = !1, this._baselineComputed = !1, this._moved = /* @__PURE__ */ new Set(), this._tempForward = new $(), this._lightTargetDistance = null, this._lastLightPosition = null, this._onDraggingChanged = this._onDraggingChanged.bind(this), this._onObjectChange = this._onObjectChange.bind(this), this._controls.addEventListener("dragging-changed", this._onDraggingChanged), this._controls.addEventListener("objectChange", this._onObjectChange);
|
|
5303
5723
|
}
|
|
5304
5724
|
setMeshData(e) {
|
|
5305
5725
|
this._meshes = e;
|
|
5306
|
-
for (let e of this._moved)
|
|
5726
|
+
for (let e of this._moved) tc(e) || this._moved.delete(e);
|
|
5307
5727
|
}
|
|
5308
5728
|
get movedObjects() {
|
|
5309
|
-
return [...this._moved].filter((e) =>
|
|
5729
|
+
return [...this._moved].filter((e) => tc(e));
|
|
5310
5730
|
}
|
|
5311
5731
|
noteMoved(e) {
|
|
5312
5732
|
e && !e.isLight && this._moved.add(e);
|
|
@@ -5319,7 +5739,7 @@ var cs = class extends cr {
|
|
|
5319
5739
|
}
|
|
5320
5740
|
setMode(e) {
|
|
5321
5741
|
this._controls.setMode(e), this._app?.dispatchEvent({
|
|
5322
|
-
type:
|
|
5742
|
+
type: j.TRANSFORM_MODE_CHANGED,
|
|
5323
5743
|
mode: e
|
|
5324
5744
|
}), this._app?.refreshFrame();
|
|
5325
5745
|
}
|
|
@@ -5341,7 +5761,7 @@ var cs = class extends cr {
|
|
|
5341
5761
|
e.autoClear = !1, e.clearDepth(), e.setRenderTarget(null), e.render(this._gizmoScene, this._camera), e.autoClear = t;
|
|
5342
5762
|
}
|
|
5343
5763
|
_onDraggingChanged(e) {
|
|
5344
|
-
this._isDragging = e.value, this._orbitControls && (this._orbitControls.enabled = !e.value), e.value ? this._app.dispatchEvent({ type:
|
|
5764
|
+
this._isDragging = e.value, this._orbitControls && (this._orbitControls.enabled = !e.value), e.value ? this._app.dispatchEvent({ type: j.OBJECT_TRANSFORM_START }) : (this._attached?.isLight ? this._finalizeLightTransform() : this._recomputeAndRefit(), this._app.dispatchEvent({ type: j.OBJECT_TRANSFORM_END }));
|
|
5345
5765
|
}
|
|
5346
5766
|
_onObjectChange() {
|
|
5347
5767
|
this._app.needsReset = !0, this._app.wake(), this._attached?.isLight && this._syncLightDuringDrag();
|
|
@@ -5367,7 +5787,7 @@ var cs = class extends cr {
|
|
|
5367
5787
|
}
|
|
5368
5788
|
_syncLightAim(e) {
|
|
5369
5789
|
let t = this._tempForward.copy(e.target.position).sub(e.position), n = t.length();
|
|
5370
|
-
n > 1e-4 ? (e.quaternion.setFromUnitVectors(
|
|
5790
|
+
n > 1e-4 ? (e.quaternion.setFromUnitVectors(ec, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1;
|
|
5371
5791
|
}
|
|
5372
5792
|
_recomputeAndRefit() {
|
|
5373
5793
|
if (!this._meshes || this._refitInFlight || !this._attached) return;
|
|
@@ -5403,7 +5823,7 @@ var cs = class extends cr {
|
|
|
5403
5823
|
dispose() {
|
|
5404
5824
|
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;
|
|
5405
5825
|
}
|
|
5406
|
-
},
|
|
5826
|
+
}, rc = class {
|
|
5407
5827
|
constructor(e) {
|
|
5408
5828
|
this.layer = "scene", this._transformManager = e, this._enabled = !0;
|
|
5409
5829
|
}
|
|
@@ -5422,8 +5842,8 @@ var cs = class extends cr {
|
|
|
5422
5842
|
dispose() {
|
|
5423
5843
|
this._enabled = !1;
|
|
5424
5844
|
}
|
|
5425
|
-
},
|
|
5426
|
-
function
|
|
5845
|
+
}, ic = 1, ac = (e) => typeof e == "string" && /^https?:\/\//.test(e);
|
|
5846
|
+
function oc(e, t) {
|
|
5427
5847
|
let n = [];
|
|
5428
5848
|
for (; e && e !== t;) {
|
|
5429
5849
|
let t = e.parent;
|
|
@@ -5432,12 +5852,12 @@ function hs(e, t) {
|
|
|
5432
5852
|
}
|
|
5433
5853
|
return e === t ? n : null;
|
|
5434
5854
|
}
|
|
5435
|
-
function
|
|
5855
|
+
function sc(e, t) {
|
|
5436
5856
|
let n = e;
|
|
5437
5857
|
for (let e of t) if (n = n?.children[e], !n) return null;
|
|
5438
5858
|
return n;
|
|
5439
5859
|
}
|
|
5440
|
-
function
|
|
5860
|
+
function cc(e) {
|
|
5441
5861
|
return {
|
|
5442
5862
|
key: e.assetLoader?.sceneSourceKey ?? null,
|
|
5443
5863
|
name: e.sceneModel?.name ?? null,
|
|
@@ -5445,7 +5865,7 @@ function _s(e) {
|
|
|
5445
5865
|
materials: e.stages.pathTracer?.materialData.materialCount ?? 0
|
|
5446
5866
|
};
|
|
5447
5867
|
}
|
|
5448
|
-
function
|
|
5868
|
+
function lc(e) {
|
|
5449
5869
|
let t = /* @__PURE__ */ new Map();
|
|
5450
5870
|
for (let n of e.sceneMeshes) {
|
|
5451
5871
|
let e = n.userData?.materialIndex;
|
|
@@ -5453,7 +5873,7 @@ function vs(e) {
|
|
|
5453
5873
|
}
|
|
5454
5874
|
return t;
|
|
5455
5875
|
}
|
|
5456
|
-
function
|
|
5876
|
+
function uc(e) {
|
|
5457
5877
|
if (!e) return null;
|
|
5458
5878
|
let t = e.status(), n = t.activeView, r = t.config?.id ?? n?.configId ?? null;
|
|
5459
5879
|
return {
|
|
@@ -5468,15 +5888,15 @@ function ys(e) {
|
|
|
5468
5888
|
context: t.context ?? null
|
|
5469
5889
|
};
|
|
5470
5890
|
}
|
|
5471
|
-
function
|
|
5472
|
-
let t = e.meshScene, n =
|
|
5891
|
+
function dc(e) {
|
|
5892
|
+
let t = e.meshScene, n = lc(e), r = [];
|
|
5473
5893
|
return t.traverse((e) => {
|
|
5474
|
-
e !== t && e.visible === !1 && r.push(
|
|
5894
|
+
e !== t && e.visible === !1 && r.push(oc(e, t));
|
|
5475
5895
|
}), {
|
|
5476
5896
|
v: 1,
|
|
5477
|
-
engine:
|
|
5897
|
+
engine: Be,
|
|
5478
5898
|
savedAt: Date.now(),
|
|
5479
|
-
scene:
|
|
5899
|
+
scene: cc(e),
|
|
5480
5900
|
appended: t.children.filter((t) => t !== e.sceneModel && t.userData?.__rayzeeSceneObject).map((e) => ({
|
|
5481
5901
|
name: e.userData.__rayzeeName ?? e.name,
|
|
5482
5902
|
url: e.userData.__rayzeeSourceUrl ?? null,
|
|
@@ -5484,7 +5904,7 @@ function bs(e) {
|
|
|
5484
5904
|
})),
|
|
5485
5905
|
settings: e.settings.serialize(),
|
|
5486
5906
|
environment: e.environmentManager?.serialize() ?? null,
|
|
5487
|
-
color:
|
|
5907
|
+
color: uc(e.color),
|
|
5488
5908
|
lights: e.lightManager.serialize(),
|
|
5489
5909
|
cameras: e.cameraManager.serialize(),
|
|
5490
5910
|
timeline: e.timeline?.serialize() ?? null,
|
|
@@ -5494,7 +5914,7 @@ function bs(e) {
|
|
|
5494
5914
|
})),
|
|
5495
5915
|
hidden: r,
|
|
5496
5916
|
moved: (e.transformManager?.movedObjects ?? []).map((e) => ({
|
|
5497
|
-
path:
|
|
5917
|
+
path: oc(e, t),
|
|
5498
5918
|
name: e.name,
|
|
5499
5919
|
position: e.position.toArray(),
|
|
5500
5920
|
quaternion: e.quaternion.toArray(),
|
|
@@ -5502,15 +5922,15 @@ function bs(e) {
|
|
|
5502
5922
|
})).filter((e) => e.path)
|
|
5503
5923
|
};
|
|
5504
5924
|
}
|
|
5505
|
-
function
|
|
5925
|
+
function fc(e, t, n) {
|
|
5506
5926
|
let r = e[t];
|
|
5507
5927
|
r?.copy && (n?.isColor || n?.isVector2 || n?.isVector3) ? r.copy(n) : e[t] = n, e.needsUpdate = !0;
|
|
5508
5928
|
}
|
|
5509
|
-
async function
|
|
5929
|
+
async function pc(e, t, n, r) {
|
|
5510
5930
|
if (!t) return;
|
|
5511
5931
|
let i = e.environmentManager;
|
|
5512
5932
|
if (t.hdri && t.hdri !== i.hdriSource) {
|
|
5513
|
-
let i =
|
|
5933
|
+
let i = ac(t.hdri) ? t.hdri : await n({
|
|
5514
5934
|
kind: "environment",
|
|
5515
5935
|
source: t.hdri
|
|
5516
5936
|
});
|
|
@@ -5522,7 +5942,7 @@ async function Ss(e, t, n, r) {
|
|
|
5522
5942
|
}
|
|
5523
5943
|
await i.restore(t);
|
|
5524
5944
|
}
|
|
5525
|
-
async function
|
|
5945
|
+
async function mc(e, t, n, r) {
|
|
5526
5946
|
let i = e.color;
|
|
5527
5947
|
if (!t || !i) return;
|
|
5528
5948
|
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;
|
|
@@ -5547,7 +5967,7 @@ async function Cs(e, t, n, r) {
|
|
|
5547
5967
|
r("color", e.message, { config: t.config?.id ?? null });
|
|
5548
5968
|
}
|
|
5549
5969
|
}
|
|
5550
|
-
async function
|
|
5970
|
+
async function hc(e, t, { resolve: n = async () => null } = {}) {
|
|
5551
5971
|
if (t?.v !== 1) throw Error(`scene state version ${t?.v} is not 1`);
|
|
5552
5972
|
let r = [], i = (e, t, n = {}) => r.push({
|
|
5553
5973
|
section: e,
|
|
@@ -5568,11 +5988,11 @@ async function ws(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5568
5988
|
i("appended", e.message, { name: n.name });
|
|
5569
5989
|
}
|
|
5570
5990
|
}
|
|
5571
|
-
let a =
|
|
5991
|
+
let a = cc(e), o = t.scene ?? {}, s = o.meshes === a.meshes && o.materials === a.materials;
|
|
5572
5992
|
s || i("scene", "the loaded scene is not the one saved: objects and materials left as loaded", {
|
|
5573
5993
|
saved: o,
|
|
5574
5994
|
now: a
|
|
5575
|
-
}), await
|
|
5995
|
+
}), await pc(e, t.environment, n, i), await mc(e, t.color, n, i);
|
|
5576
5996
|
let c = e.settings.restore(t.settings);
|
|
5577
5997
|
c.length && i("settings", "not settings in this engine", { keys: c });
|
|
5578
5998
|
let l = e.lightManager.restore(t.lights);
|
|
@@ -5581,7 +6001,7 @@ async function ws(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5581
6001
|
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 });
|
|
5582
6002
|
}
|
|
5583
6003
|
if (s) {
|
|
5584
|
-
let n =
|
|
6004
|
+
let n = lc(e);
|
|
5585
6005
|
for (let r of t.materials ?? []) {
|
|
5586
6006
|
let t = n.get(r.index);
|
|
5587
6007
|
if (!t || (t.name ?? "") !== r.name) {
|
|
@@ -5592,17 +6012,17 @@ async function ws(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5592
6012
|
continue;
|
|
5593
6013
|
}
|
|
5594
6014
|
for (let [n, i] of Object.entries(r.props)) {
|
|
5595
|
-
let a =
|
|
5596
|
-
|
|
6015
|
+
let a = me(i);
|
|
6016
|
+
fc(t, n, a), e.setMaterialProperty(r.index, n, a);
|
|
5597
6017
|
}
|
|
5598
6018
|
}
|
|
5599
|
-
let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) =>
|
|
6019
|
+
let r = e.meshScene, a = new Set((t.hidden ?? []).map((e) => sc(r, e)).filter(Boolean));
|
|
5600
6020
|
r.traverse((e) => {
|
|
5601
6021
|
e !== r && !e.isLight && (e.visible = !a.has(e));
|
|
5602
6022
|
}), e.updateAllMeshVisibility();
|
|
5603
6023
|
let o = [];
|
|
5604
6024
|
for (let n of t.moved ?? []) {
|
|
5605
|
-
let t =
|
|
6025
|
+
let t = sc(r, n.path);
|
|
5606
6026
|
if (!t || t.name !== n.name) {
|
|
5607
6027
|
i("moved", "no such object", { name: n.name });
|
|
5608
6028
|
continue;
|
|
@@ -5624,7 +6044,7 @@ async function ws(e, t, { resolve: n = async () => null } = {}) {
|
|
|
5624
6044
|
}
|
|
5625
6045
|
//#endregion
|
|
5626
6046
|
//#region src/PathTracerApp.js
|
|
5627
|
-
var
|
|
6047
|
+
var gc = Ke("engine"), _c = class extends w {
|
|
5628
6048
|
constructor(e, t = {}) {
|
|
5629
6049
|
super(e, t), this.setColorManagement($t), this.setStorageOpener(un), this.settings.define("interactionRenderScale", {
|
|
5630
6050
|
default: .5,
|
|
@@ -5632,16 +6052,16 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5632
6052
|
this.stages?.pathTracer?.interactionMode && this._requestRenderScale(this._interactionRenderScale());
|
|
5633
6053
|
},
|
|
5634
6054
|
reset: !1
|
|
5635
|
-
}), 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
|
|
6055
|
+
}), this._container = t.container || null, this._animRefitInFlight = !1, this._emittersMoved = !1, this._pendingRenderScale = null, this.cameraManager = null, this.timeline = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new $s();
|
|
5636
6056
|
}
|
|
5637
6057
|
_createCamera() {
|
|
5638
|
-
return this.cameraManager = new
|
|
6058
|
+
return this.cameraManager = new Co(this.canvas), this.timeline = new ko({
|
|
5639
6059
|
cameraManager: this.cameraManager,
|
|
5640
6060
|
onReset: () => this.reset()
|
|
5641
6061
|
}), this.cameraManager.camera;
|
|
5642
6062
|
}
|
|
5643
6063
|
_initAssetPipeline() {
|
|
5644
|
-
super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Ot), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-
|
|
6064
|
+
super._initAssetPipeline(), this.assetLoader.controls = this.cameraManager.controls, this.assetLoader.registerFormat(...Ot), this.assetLoader.setArchiveImporterLoader(() => import("./ArchiveImporter-Cgyx5AF7.js").then((e) => e.r).then((e) => new e.ArchiveImporter(this.assetLoader)), Tt);
|
|
5645
6065
|
let e = () => {
|
|
5646
6066
|
this.needsReset = !0, this.stages.pathTracer?.enterInteractionMode(), this.wake();
|
|
5647
6067
|
};
|
|
@@ -5649,10 +6069,10 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5649
6069
|
}
|
|
5650
6070
|
_createExtraStages() {
|
|
5651
6071
|
let { renderer: e, stages: t } = this;
|
|
5652
|
-
return t.normalDepth = new
|
|
6072
|
+
return t.normalDepth = new ti(e, { pathTracer: t.pathTracer }), t.motionVector = new ni(e, this.camera, { pathTracer: t.pathTracer }), t.asvgf = new ai(e, { enabled: !1 }), t.nrd = new Ui(e, {
|
|
5653
6073
|
enabled: !1,
|
|
5654
6074
|
pathTracer: t.pathTracer
|
|
5655
|
-
}), t.variance = new
|
|
6075
|
+
}), t.variance = new Ki(e, { enabled: !1 }), t.bilateralFilter = new Ji(e, { enabled: !1 }), t.edgeFilter = new ea(e, { enabled: !1 }), t.autoExposure = new Ea(e, { enabled: ta.autoExposure }), t.localExposure = new Ja(e, { enabled: Da.localExposure }), [
|
|
5656
6076
|
t.normalDepth,
|
|
5657
6077
|
t.motionVector,
|
|
5658
6078
|
t.nrd,
|
|
@@ -5660,32 +6080,34 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5660
6080
|
t.variance,
|
|
5661
6081
|
t.bilateralFilter,
|
|
5662
6082
|
t.edgeFilter,
|
|
5663
|
-
t.autoExposure
|
|
6083
|
+
t.autoExposure,
|
|
6084
|
+
t.localExposure
|
|
5664
6085
|
];
|
|
5665
6086
|
}
|
|
5666
6087
|
_initPipeline() {
|
|
5667
6088
|
super._initPipeline(), this.pipeline.eventBus.on("pathtracer:interactionStart", () => this._requestRenderScale(this._interactionRenderScale())), this.pipeline.eventBus.on("pathtracer:interactionEnd", () => this._applyRenderScale(1));
|
|
5668
6089
|
}
|
|
5669
6090
|
async _initManagers() {
|
|
5670
|
-
await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-
|
|
6091
|
+
await super._initManagers(), this.environmentManager.setProceduralSkyLoader(() => import("./PhysicalSky-CY4jiz6a.js").then((e) => e.n).then((e) => e.PhysicalSky)), this.stages.pathTracer.registerIntegrator(["bidirectional", "vcm"], (t) => new e(t)), this.stages.pathTracer.requestOutput("gBuffer"), this.interactionManager = new $a({
|
|
5671
6092
|
scene: this.meshScene,
|
|
5672
6093
|
camera: this.camera,
|
|
5673
6094
|
canvas: this.canvas,
|
|
5674
6095
|
assetLoader: this.assetLoader,
|
|
5675
6096
|
pathTracer: null,
|
|
5676
|
-
floorPlane: this.assetLoader.floorPlane
|
|
5677
|
-
|
|
6097
|
+
floorPlane: this.assetLoader.floorPlane,
|
|
6098
|
+
isGeometryOnDisk: () => this.geometryOnDisk
|
|
6099
|
+
}), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.goboManager = new Ao(this.stages.pathTracer, {
|
|
5678
6100
|
onReset: () => this.reset(),
|
|
5679
6101
|
issues: this._issues
|
|
5680
|
-
}), this.iesManager = new
|
|
6102
|
+
}), this.iesManager = new Ho(this.stages.pathTracer, {
|
|
5681
6103
|
onReset: () => this.reset(),
|
|
5682
6104
|
issues: this._issues
|
|
5683
|
-
}), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new
|
|
6105
|
+
}), this._setupDenoisingManager(), this._headless || (await this._setupOverlayManager(), this.transformManager = new nc({
|
|
5684
6106
|
camera: this.camera,
|
|
5685
6107
|
canvas: this.canvas,
|
|
5686
6108
|
orbitControls: this.cameraManager.controls,
|
|
5687
6109
|
app: this
|
|
5688
|
-
}), this.overlayManager.register("transform", new
|
|
6110
|
+
}), this.overlayManager.register("transform", new rc(this.transformManager))), this.interactionManager.setDependencies({
|
|
5689
6111
|
overlayManager: this.overlayManager,
|
|
5690
6112
|
transformManager: this.transformManager,
|
|
5691
6113
|
appDispatch: (e) => this.dispatchEvent(e),
|
|
@@ -5694,20 +6116,20 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5694
6116
|
}), this.denoisingManager.setOverlayManager(this.overlayManager), this.denoisingManager.setResetCallback(() => this.reset()), this.denoisingManager.setPostProcessRefreshCallback(() => this.requestPostProcessRefresh()), this.denoisingManager.setDisplayRefreshCallback(() => this._presentDisplay()), this.denoisingManager.setSettings(this.settings);
|
|
5695
6117
|
}
|
|
5696
6118
|
_wireEvents() {
|
|
5697
|
-
this._addTrackedListener(this.cameraManager,
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
6119
|
+
this._addTrackedListener(this.cameraManager, j.CAMERA_SWITCHED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, j.AUTO_FOCUS_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.cameraManager, j.ORTHO_HEIGHT_UPDATED, (e) => this.dispatchEvent(e)), this._addTrackedListener(this.timeline, j.TIMELINE_CHANGED, (e) => this.dispatchEvent(e)), this._forwardEvents(this.denoisingManager, [
|
|
6120
|
+
j.DENOISING_START,
|
|
6121
|
+
j.DENOISING_END,
|
|
6122
|
+
j.UPSCALING_START,
|
|
6123
|
+
j.UPSCALING_PROGRESS,
|
|
6124
|
+
j.UPSCALING_END,
|
|
6125
|
+
j.RESOLUTION_CHANGED
|
|
5704
6126
|
]), this._setupAutoExposureListener(), this.animationManager.wakeCallback = () => this.wake(), this.animationManager.applyPoseCallback = (e) => this._applyAnimationPose(e), this._forwardEvents(this.animationManager, [
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
]), this._addTrackedListener(this.animationManager,
|
|
6127
|
+
j.ANIMATION_STARTED,
|
|
6128
|
+
j.ANIMATION_PAUSED,
|
|
6129
|
+
j.ANIMATION_STOPPED
|
|
6130
|
+
]), this._addTrackedListener(this.animationManager, j.ANIMATION_PAUSED, () => {
|
|
5709
6131
|
this._animRefitInFlight = !1, this._refreshMovedEmitters();
|
|
5710
|
-
}), this._addTrackedListener(this.animationManager,
|
|
6132
|
+
}), this._addTrackedListener(this.animationManager, j.ANIMATION_STOPPED, () => {
|
|
5711
6133
|
this._animRefitInFlight = !1;
|
|
5712
6134
|
}), this.cameraManager.initCallbacks({
|
|
5713
6135
|
onResize: () => this.onResize(),
|
|
@@ -5742,7 +6164,7 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5742
6164
|
return {
|
|
5743
6165
|
...e,
|
|
5744
6166
|
applyExposure: (t) => {
|
|
5745
|
-
this.stages.autoExposure
|
|
6167
|
+
this.stages.autoExposure ? this.stages.autoExposure.setCompensation(t) : e.applyExposure(t);
|
|
5746
6168
|
},
|
|
5747
6169
|
onCameraProjection: (e) => {
|
|
5748
6170
|
this.cameraManager.applyProjection(e), e === "equirectangular" && this.denoisingManager?.requiresMotionVectors && this.denoisingManager.setDenoiserStrategy("edgeaware");
|
|
@@ -5750,9 +6172,9 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5750
6172
|
};
|
|
5751
6173
|
}
|
|
5752
6174
|
_beginFrame() {
|
|
5753
|
-
if (this.timeline.update(), this.cameraManager.updateControls(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
|
|
6175
|
+
if (this.timeline.update(), this.cameraManager.updateControls(), this._updateExposure(), this._applyPendingRenderScale(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
|
|
5754
6176
|
let e = this.animationManager.update();
|
|
5755
|
-
e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) =>
|
|
6177
|
+
e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => gc.error("animation refit error:", e)).finally(() => {
|
|
5756
6178
|
this._animRefitInFlight = !1;
|
|
5757
6179
|
}));
|
|
5758
6180
|
}
|
|
@@ -5767,11 +6189,45 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5767
6189
|
this.denoisingManager?.afterTrace(), t && !e.isComplete && this.denoisingManager?.tickContinuousDenoise(e.frameCount);
|
|
5768
6190
|
}
|
|
5769
6191
|
_renderCompleted() {
|
|
5770
|
-
this.denoisingManager.onRenderComplete({
|
|
6192
|
+
this.stages.autoExposure?.enabled && this._refreshFinished(), this.denoisingManager.onRenderComplete({
|
|
5771
6193
|
isStillComplete: () => this.completion.renderCompleteDispatched,
|
|
5772
6194
|
context: this.pipeline?.context
|
|
5773
6195
|
});
|
|
5774
6196
|
}
|
|
6197
|
+
_settling() {
|
|
6198
|
+
return !!this.stages.autoExposure?.settling;
|
|
6199
|
+
}
|
|
6200
|
+
_displayGain() {
|
|
6201
|
+
let e = this.stages.localExposure;
|
|
6202
|
+
return e?.wantsBuild && e.build(this.pipeline.context), e?.toneGain() ?? null;
|
|
6203
|
+
}
|
|
6204
|
+
setLocalExposure(e) {
|
|
6205
|
+
let t = this.stages.localExposure;
|
|
6206
|
+
t && (t.setEnabled(e), this.stages.compositor.setDisplayGain(e ? (e, n) => t.gainNode(e, n) : null), this.refreshFrame());
|
|
6207
|
+
}
|
|
6208
|
+
setLocalExposureParams(e) {
|
|
6209
|
+
this.stages.localExposure?.updateParameters(e);
|
|
6210
|
+
}
|
|
6211
|
+
_finishImage() {
|
|
6212
|
+
let e = this.stages.autoExposure;
|
|
6213
|
+
return e?.enabled ? e.meter(this.pipeline.context).then(() => e.advance(Infinity)) : null;
|
|
6214
|
+
}
|
|
6215
|
+
getProvenance() {
|
|
6216
|
+
let e = super.getProvenance(), t = this.stages.autoExposure, n = this.stages.localExposure;
|
|
6217
|
+
return e.exposure = {
|
|
6218
|
+
auto: t?.enabled ? {
|
|
6219
|
+
exposure: t.getExposure(),
|
|
6220
|
+
strength: t.strength,
|
|
6221
|
+
metering: t.metering,
|
|
6222
|
+
keyValue: t.keyValue
|
|
6223
|
+
} : null,
|
|
6224
|
+
local: n?.enabled ? {
|
|
6225
|
+
highlightContrast: n.highlightContrast,
|
|
6226
|
+
shadowContrast: n.shadowContrast,
|
|
6227
|
+
detailStrength: n.detailStrength
|
|
6228
|
+
} : null
|
|
6229
|
+
}, e;
|
|
6230
|
+
}
|
|
5775
6231
|
_renderHelperOverlay() {
|
|
5776
6232
|
super._renderHelperOverlay(), this.overlayManager?.render();
|
|
5777
6233
|
}
|
|
@@ -5830,10 +6286,10 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5830
6286
|
}
|
|
5831
6287
|
_setDeterministicExtras(e, t) {
|
|
5832
6288
|
if (e) {
|
|
5833
|
-
this.cameraManager?.setAutoFocusMode("manual"), this.stages.autoExposure
|
|
6289
|
+
this.cameraManager?.setAutoFocusMode("manual"), this.stages.autoExposure?.setEnabled(!1), this.denoisingManager?.setContinuousDenoise(!1);
|
|
5834
6290
|
return;
|
|
5835
6291
|
}
|
|
5836
|
-
t.autoFocusMode !== void 0 && this.cameraManager?.setAutoFocusMode(t.autoFocusMode),
|
|
6292
|
+
t.autoFocusMode !== void 0 && this.cameraManager?.setAutoFocusMode(t.autoFocusMode), t.autoExposure !== void 0 && this.stages.autoExposure?.setEnabled(t.autoExposure), t.continuousDenoise !== void 0 && this.denoisingManager?.setContinuousDenoise(t.continuousDenoise);
|
|
5837
6293
|
}
|
|
5838
6294
|
_disposeExtensions() {
|
|
5839
6295
|
this.interactionManager?.deselect?.(), this.transformManager?.detach?.(), this.animationManager?.dispose(), this.transformManager?.dispose(), this.overlayManager?.dispose(), this.goboManager?.dispose(), this.iesManager?.dispose(), this.denoisingManager?.dispose(), this.interactionManager?.dispose(), this.timeline?.dispose(), this.cameraManager?.dispose();
|
|
@@ -5850,14 +6306,14 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5850
6306
|
return t && this._dispatchCamerasUpdated(), t;
|
|
5851
6307
|
}
|
|
5852
6308
|
exportSceneState() {
|
|
5853
|
-
return
|
|
6309
|
+
return dc(this);
|
|
5854
6310
|
}
|
|
5855
6311
|
async importSceneState(e, t) {
|
|
5856
|
-
return await
|
|
6312
|
+
return await hc(this, e, t);
|
|
5857
6313
|
}
|
|
5858
6314
|
_dispatchCamerasUpdated() {
|
|
5859
6315
|
this.dispatchEvent({
|
|
5860
|
-
type:
|
|
6316
|
+
type: j.CAMERAS_UPDATED,
|
|
5861
6317
|
cameras: this.cameraManager.cameras,
|
|
5862
6318
|
cameraNames: this.cameraManager.getCameraNames()
|
|
5863
6319
|
});
|
|
@@ -5865,13 +6321,13 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5865
6321
|
_applyAnimationPose({ meshIndices: e, visibilityChanged: t, cameras: n }) {
|
|
5866
6322
|
if (!this._sdf?.instanceTable) return;
|
|
5867
6323
|
let r = !1;
|
|
5868
|
-
e.length > 0 && (this._notePlacementsMoving(e), this._sdf.updateMeshTransforms(e), this.stages.pathTracer?.updateBufferRanges([],
|
|
6324
|
+
e.length > 0 && (this._notePlacementsMoving(e), this._sdf.updateMeshTransforms(e), this.stages.pathTracer?.updateBufferRanges([], this._sdf.takeMoveRanges()), this._sdf.movesEmitters(e) && (this._emittersMoved = !0, this.animationManager.isPlaying || this._refreshMovedEmitters()), r = !0), t && (this.stages.pathTracer?.updateAllMeshVisibility(), this._refreshEmissiveForVisibility(), r = !0), n.length > 0 && this._followAnimatedCamera(n) && (r = !0), r && this.reset(!1, { motion: !0 });
|
|
5869
6325
|
}
|
|
5870
6326
|
_notePlacementsMoving(e) {
|
|
5871
6327
|
let t = this.denoisingManager, n = this._sdf?.instanceTable;
|
|
5872
6328
|
if (!(!t?.historyActive || !n)) for (let r of e) {
|
|
5873
6329
|
let e = n.placementRunOf(r);
|
|
5874
|
-
if (e) for (let r = e.start; r < e.start + e.count; r++) t.notePlacementMoving(n.tlasLeafIndex[r], n.
|
|
6330
|
+
if (e) for (let r = e.start; r < e.start + e.count; r++) t.notePlacementMoving(n.tlasLeafIndex[r], () => n.matrixWorldOf(r));
|
|
5875
6331
|
}
|
|
5876
6332
|
}
|
|
5877
6333
|
_refreshMovedEmitters() {
|
|
@@ -5911,8 +6367,8 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5911
6367
|
this._pendingRenderScale = null, !(this._disposed || e === this._renderScale) && (this._renderScale = e, !(!this._displayWidth || !this._displayHeight) && (this._setDisplaySize(this._displayWidth, this._displayHeight), this.pipeline?.setSize(this._scaled(this._displayWidth), this._scaled(this._displayHeight)), this.pipeline?.eventBus.emit("pipeline:historyReset"), this.needsReset = !0));
|
|
5912
6368
|
}
|
|
5913
6369
|
configureForMode(e, t = {}) {
|
|
5914
|
-
let n = e === "production", r = n ?
|
|
5915
|
-
this.denoisingManager?.setCadenceSuspended(n), this.timeline.stop(), this.cameraManager.controls.enabled = !n, this.settings.setMany(
|
|
6370
|
+
let n = e === "production", r = n ? De : Oe;
|
|
6371
|
+
this.denoisingManager?.setCadenceSuspended(n), this.timeline.stop(), this.cameraManager.controls.enabled = !n, this.stages.autoExposure && (this.stages.autoExposure.holdSamples = n ? 8 : 0), this.settings.setMany(je(r), {
|
|
5916
6372
|
silent: !0,
|
|
5917
6373
|
source: x.MODE_PRESET
|
|
5918
6374
|
}), this.stages.pathTracer?.setUniform("renderMode", parseInt(r.renderMode)), n && this._applyRenderScale(1), this.stages.pathTracer?.updateCompletionThreshold?.();
|
|
@@ -5935,13 +6391,13 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5935
6391
|
let e = this.denoisingManager;
|
|
5936
6392
|
if (await e?.denoiseOnce()) return !0;
|
|
5937
6393
|
let t = e?.denoiser ? e.denoiser.enabled ? "the denoise did not complete" : "OIDN was off while accumulating — call denoisingManager.setOIDNEnabled( true ) first" : "the denoiser was not built";
|
|
5938
|
-
return this._issues.record(
|
|
6394
|
+
return this._issues.record(Ze.DENOISER_UNAVAILABLE, `final denoise produced no picture: ${t}`, { reason: t }), !1;
|
|
5939
6395
|
}
|
|
5940
6396
|
_abortPostProcess({ keepDisplay: e = !1 } = {}) {
|
|
5941
6397
|
if (this.denoisingManager?.abort(this.canvas, { keepDisplay: e }), this.denoisingManager?.restoreBaseResolution()) {
|
|
5942
6398
|
let e = this.denoisingManager._lastRenderWidth, t = this.denoisingManager._lastRenderHeight;
|
|
5943
6399
|
this.dispatchEvent({
|
|
5944
|
-
type:
|
|
6400
|
+
type: j.RESOLUTION_CHANGED,
|
|
5945
6401
|
width: e,
|
|
5946
6402
|
height: t
|
|
5947
6403
|
});
|
|
@@ -5969,13 +6425,13 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5969
6425
|
if (e.length > 0) {
|
|
5970
6426
|
let t = this.sceneModel || this.meshScene;
|
|
5971
6427
|
this.animationManager.init(this.meshScene, t, this._sdf.meshes, e), this.animationManager.onFinished = () => {
|
|
5972
|
-
this._animRefitInFlight = !1, this._refreshMovedEmitters(), this.dispatchEvent({ type:
|
|
6428
|
+
this._animRefitInFlight = !1, this._refreshMovedEmitters(), this.dispatchEvent({ type: j.ANIMATION_FINISHED });
|
|
5973
6429
|
};
|
|
5974
6430
|
}
|
|
5975
6431
|
this.transformManager?.setMeshData(this._sdf.meshes);
|
|
5976
6432
|
}
|
|
5977
6433
|
_setupDenoisingManager() {
|
|
5978
|
-
this.denoisingManager = new
|
|
6434
|
+
this.denoisingManager = new Hs({
|
|
5979
6435
|
renderer: this.renderer,
|
|
5980
6436
|
mainCanvas: this.canvas,
|
|
5981
6437
|
stages: {
|
|
@@ -5993,22 +6449,45 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
5993
6449
|
pipeline: this.pipeline,
|
|
5994
6450
|
getExposure: () => this.settings.get("exposure") ?? 1,
|
|
5995
6451
|
getSaturation: () => this.settings.get("saturation") ?? 1,
|
|
6452
|
+
getDisplayGain: () => this._displayGain(),
|
|
5996
6453
|
issues: this._issues
|
|
5997
6454
|
}), this.denoisingManager.setupDenoiser(), this.denoisingManager.setupUpscaler(), this.denoisingManager._syncGBufferStages();
|
|
5998
6455
|
let e = this.canvas.clientWidth || 1, t = this.canvas.clientHeight || 1;
|
|
5999
6456
|
this.denoisingManager.setRenderSize(e, t);
|
|
6000
6457
|
}
|
|
6001
6458
|
_setupAutoExposureListener() {
|
|
6002
|
-
|
|
6459
|
+
let e = this.stages.autoExposure;
|
|
6460
|
+
e && (e.setCompensation(this.settings.get("exposure") ?? 1), this.stages.localExposure && (this.stages.localExposure.onChange = () => this._refreshFinished()), e.onChange = () => this._refreshFinished(), this._addTrackedListener(this.cameraManager, j.CAMERA_SWITCHED, () => e.resetHistory()), e.on("autoexposure:updated", ({ exposure: e, autoExposure: t, targetExposure: n, luminance: r }) => {
|
|
6003
6461
|
this.dispatchEvent({
|
|
6004
|
-
type:
|
|
6005
|
-
exposure: e
|
|
6006
|
-
|
|
6462
|
+
type: j.AUTO_EXPOSURE_UPDATED,
|
|
6463
|
+
exposure: e,
|
|
6464
|
+
autoExposure: t,
|
|
6465
|
+
targetExposure: n,
|
|
6466
|
+
luminance: r
|
|
6007
6467
|
});
|
|
6008
|
-
});
|
|
6468
|
+
}));
|
|
6469
|
+
}
|
|
6470
|
+
_refreshFinished() {
|
|
6471
|
+
this.completion.renderCompleteDispatched && (this._needsDisplayRefresh = !0, this.wake());
|
|
6472
|
+
}
|
|
6473
|
+
_updateExposure() {
|
|
6474
|
+
let e = this.stages.localExposure;
|
|
6475
|
+
e?.wantsBuild && this.completion.renderCompleteDispatched && e.build(this.pipeline.context);
|
|
6476
|
+
let t = this.stages.autoExposure;
|
|
6477
|
+
if (!t?.enabled) return;
|
|
6478
|
+
this._noteExposureView();
|
|
6479
|
+
let n = this.cameraManager.afScreenPoint;
|
|
6480
|
+
t.metering === "spot" && (t.meteringPoint.x !== n.x || t.meteringPoint.y !== n.y) && t.updateParameters({ meteringPoint: n }), t.wantsMetering && this.completion.renderCompleteDispatched && t.meter(this.pipeline.context), t.update() && (this._needsDisplayRefresh = !0);
|
|
6481
|
+
}
|
|
6482
|
+
_noteExposureView() {
|
|
6483
|
+
let { matrixWorld: e, projectionMatrix: t } = this.camera, n = this._exposureView;
|
|
6484
|
+
n?.view.equals(e) && n.projection.equals(t) || (this._exposureView = {
|
|
6485
|
+
view: e.clone(),
|
|
6486
|
+
projection: t.clone()
|
|
6487
|
+
}, n && this.stages.autoExposure?.noteViewChanged());
|
|
6009
6488
|
}
|
|
6010
6489
|
async _setupOverlayManager() {
|
|
6011
|
-
this.overlayManager = new
|
|
6490
|
+
this.overlayManager = new Zs(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
|
|
6012
6491
|
helperScene: this._sceneHelpers,
|
|
6013
6492
|
meshScene: this.meshScene,
|
|
6014
6493
|
pipeline: this.pipeline,
|
|
@@ -6026,7 +6505,7 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
6026
6505
|
}
|
|
6027
6506
|
_recalibrateControlLimits() {
|
|
6028
6507
|
if (!this.meshScene || !this.cameraManager) return;
|
|
6029
|
-
let e = new
|
|
6508
|
+
let e = new ar(), t = new ar();
|
|
6030
6509
|
for (let n of this.meshScene.children) n.userData?.__rayzeeSceneObject && (t.setFromObject(n), t.isEmpty() || e.union(t));
|
|
6031
6510
|
if (e.isEmpty()) return;
|
|
6032
6511
|
let n = Math.max(e.max.x - e.min.x, e.max.y - e.min.y, e.max.z - e.min.z);
|
|
@@ -6039,15 +6518,15 @@ var Ts = qe("engine"), Es = class extends te {
|
|
|
6039
6518
|
};
|
|
6040
6519
|
//#endregion
|
|
6041
6520
|
//#region src/Headless.js
|
|
6042
|
-
async function
|
|
6043
|
-
let t = await
|
|
6521
|
+
async function vc(e) {
|
|
6522
|
+
let t = await bc(e);
|
|
6044
6523
|
try {
|
|
6045
|
-
return await
|
|
6524
|
+
return await yc(t, e);
|
|
6046
6525
|
} finally {
|
|
6047
6526
|
t.dispose();
|
|
6048
6527
|
}
|
|
6049
6528
|
}
|
|
6050
|
-
async function
|
|
6529
|
+
async function yc(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire: r = !1, denoise: i = !1, onProgress: a = void 0 } = {}) {
|
|
6051
6530
|
let o = e.denoisingManager;
|
|
6052
6531
|
i && o && !o.finalDenoise && (o.applyOIDNEnabled(!0), o._syncGBufferStages());
|
|
6053
6532
|
let s = await e.renderFrames(t, {
|
|
@@ -6066,8 +6545,8 @@ async function Os(e, { samples: t = 64, colorSpace: n = "srgb", allowEarlyRetire
|
|
|
6066
6545
|
provenance: e.getProvenance()
|
|
6067
6546
|
};
|
|
6068
6547
|
}
|
|
6069
|
-
async function
|
|
6070
|
-
let l = new
|
|
6548
|
+
async function bc({ canvas: e, model: t = null, width: n = 1920, height: r = 1080, strict: i = !0, deterministic: a = !0, settings: o = null, storage: s = !1, hostMemoryGB: c = void 0 } = {}) {
|
|
6549
|
+
let l = new _c(e ?? null, {
|
|
6071
6550
|
autoResize: !1,
|
|
6072
6551
|
strict: i,
|
|
6073
6552
|
storage: s,
|
|
@@ -6081,12 +6560,12 @@ async function ks({ canvas: e, model: t = null, width: n = 1920, height: r = 108
|
|
|
6081
6560
|
}
|
|
6082
6561
|
//#endregion
|
|
6083
6562
|
//#region src/managers/VideoRenderManager.js
|
|
6084
|
-
var
|
|
6563
|
+
var xc = class {
|
|
6085
6564
|
constructor(e) {
|
|
6086
6565
|
this._app = e, this._cancelled = !1, this._rendering = !1;
|
|
6087
6566
|
}
|
|
6088
6567
|
async renderAnimation(e = {}) {
|
|
6089
|
-
let { clipIndex: t = 0, fps: n = 30, speed: r = 1, samplesPerFrame: i =
|
|
6568
|
+
let { clipIndex: t = 0, fps: n = 30, speed: r = 1, samplesPerFrame: i = De.maxSamples, enableOIDN: a = !0, timeline: o = null, startFrame: s = 0, onFrame: c, onProgress: l, onComplete: u } = e, d = this._app, f = d.animationManager?.hasAnimations ? d.animationManager.clips[t] : null;
|
|
6090
6569
|
if (!f && !o?.animates) {
|
|
6091
6570
|
console.warn(d.animationManager?.hasAnimations ? `VideoRenderManager: Invalid clip index ${t}` : "VideoRenderManager: No animation clips or keyframes"), u?.(!1);
|
|
6092
6571
|
return;
|
|
@@ -6098,24 +6577,32 @@ var As = class {
|
|
|
6098
6577
|
}
|
|
6099
6578
|
this._cancelled = !1, this._rendering = !0;
|
|
6100
6579
|
let g = this._saveState({ view: !!o });
|
|
6101
|
-
d.stopAnimation(), d.configureForMode("production")
|
|
6580
|
+
d.stopAnimation(), d.configureForMode("production");
|
|
6581
|
+
let _ = d.stages.autoExposure?.enabled ? d.stages.autoExposure : null;
|
|
6582
|
+
_ && (_.instant = !1), d.settings.setMany({
|
|
6583
|
+
maxSamples: i,
|
|
6584
|
+
renderLimitMode: "frames"
|
|
6585
|
+
}, {
|
|
6586
|
+
silent: !0,
|
|
6587
|
+
reset: !1
|
|
6588
|
+
}), d.stages.pathTracer?.updateCompletionThreshold?.(), d.cameraManager.controls && (d.cameraManager.controls.enabled = !1);
|
|
6102
6589
|
try {
|
|
6103
6590
|
for (let e = Math.max(0, s); e < m && !this._cancelled; e++) {
|
|
6104
6591
|
let n = e * h * r, i = f ? d.animationManager.seekTo(n, t) : null;
|
|
6105
|
-
if (o?.seek(e * h) && (d.cameraManager.resetAutoFocus(), d.cameraManager.updateAutoFocus()), i ? await d.refitBVH(i) : d.reset(), d.stopAnimation(), await this._accumulateFrame(d), this._cancelled || (a && d.denoisingManager?.finalDenoise && await this._waitForDenoise(d), this._cancelled)) break;
|
|
6106
|
-
let
|
|
6107
|
-
if (
|
|
6108
|
-
let t = await createImageBitmap(
|
|
6592
|
+
if (o?.seek(e * h) && (d.cameraManager.resetAutoFocus(), d.cameraManager.updateAutoFocus()), i ? await d.refitBVH(i) : d.reset(), d.stopAnimation(), _ && d._noteExposureView(), await this._accumulateFrame(d), this._cancelled || (_ && (await _.meter(d.pipeline.context), _.advance(e === Math.max(0, s) ? Infinity : h), d._presentDisplay()), a && d.denoisingManager?.finalDenoise && await this._waitForDenoise(d), this._cancelled)) break;
|
|
6593
|
+
let u = d.getCanvas();
|
|
6594
|
+
if (u && c) {
|
|
6595
|
+
let t = await createImageBitmap(u);
|
|
6109
6596
|
await c(t, e, m), t.close();
|
|
6110
6597
|
}
|
|
6111
|
-
let
|
|
6598
|
+
let p = {
|
|
6112
6599
|
frame: e + 1,
|
|
6113
6600
|
totalFrames: m,
|
|
6114
6601
|
percent: (e + 1) / m * 100
|
|
6115
6602
|
};
|
|
6116
|
-
l?.(
|
|
6117
|
-
type:
|
|
6118
|
-
...
|
|
6603
|
+
l?.(p), d.dispatchEvent({
|
|
6604
|
+
type: j.VIDEO_RENDER_PROGRESS,
|
|
6605
|
+
...p
|
|
6119
6606
|
});
|
|
6120
6607
|
}
|
|
6121
6608
|
} catch (e) {
|
|
@@ -6124,7 +6611,7 @@ var As = class {
|
|
|
6124
6611
|
this._restoreState(g), this._rendering = !1;
|
|
6125
6612
|
let e = !this._cancelled;
|
|
6126
6613
|
u?.(e), d.dispatchEvent({
|
|
6127
|
-
type:
|
|
6614
|
+
type: j.VIDEO_RENDER_COMPLETE,
|
|
6128
6615
|
success: e
|
|
6129
6616
|
});
|
|
6130
6617
|
}
|
|
@@ -6143,26 +6630,26 @@ var As = class {
|
|
|
6143
6630
|
await n;
|
|
6144
6631
|
continue;
|
|
6145
6632
|
}
|
|
6146
|
-
e.cameraManager.camera.updateMatrixWorld(), e.pipeline.render(), t.frameCount % 4 == 0 && (
|
|
6633
|
+
e.cameraManager.camera.updateMatrixWorld(), e.pipeline.render(), t.frameCount % 4 == 0 && (Le({ samples: Ve(t) }), await new Promise((e) => setTimeout(e, 0)));
|
|
6147
6634
|
}
|
|
6148
6635
|
}
|
|
6149
6636
|
_waitForDenoise(e) {
|
|
6150
6637
|
return new Promise((t) => {
|
|
6151
6638
|
let n, r = () => {
|
|
6152
|
-
e.removeEventListener(
|
|
6639
|
+
e.removeEventListener(j.DENOISING_END, i), clearTimeout(n);
|
|
6153
6640
|
}, i = () => {
|
|
6154
6641
|
r(), t();
|
|
6155
6642
|
};
|
|
6156
6643
|
n = setTimeout(() => {
|
|
6157
6644
|
console.warn("VideoRenderManager: Denoise timed out, skipping"), r(), t();
|
|
6158
|
-
}, 3e4), e.addEventListener(
|
|
6645
|
+
}, 3e4), e.addEventListener(j.DENOISING_END, i), e.denoisingManager.onRenderComplete({
|
|
6159
6646
|
isStillComplete: () => !this._cancelled,
|
|
6160
6647
|
context: e.pipeline?.context
|
|
6161
6648
|
});
|
|
6162
6649
|
});
|
|
6163
6650
|
}
|
|
6164
6651
|
_saveState({ view: e }) {
|
|
6165
|
-
let t = this._app, n = t.settings.getEffective(), r = Object.keys(
|
|
6652
|
+
let t = this._app, n = t.settings.getEffective(), r = [...Object.keys(je(De)), "renderLimitMode"];
|
|
6166
6653
|
return e && r.push("focusDistance"), {
|
|
6167
6654
|
view: e ? t.cameraManager.captureView() : null,
|
|
6168
6655
|
settings: r.map((e) => [e, n[e]]),
|
|
@@ -6170,6 +6657,8 @@ var As = class {
|
|
|
6170
6657
|
controlsEnabled: t.cameraManager.controls?.enabled,
|
|
6171
6658
|
oidnEnabled: t.denoisingManager?.finalDenoise,
|
|
6172
6659
|
oidnQuality: t.denoisingManager?.oidnQuality,
|
|
6660
|
+
instantExposure: t.stages.autoExposure?.instant,
|
|
6661
|
+
holdExposureSamples: t.stages.autoExposure?.holdSamples,
|
|
6173
6662
|
wasPlaying: t.animationManager?.isPlaying,
|
|
6174
6663
|
pauseRendering: t.pauseRendering
|
|
6175
6664
|
};
|
|
@@ -6181,8 +6670,8 @@ var As = class {
|
|
|
6181
6670
|
reset: !1,
|
|
6182
6671
|
source: r.source
|
|
6183
6672
|
});
|
|
6184
|
-
t.stages.pathTracer && e.renderMode !== void 0 && t.stages.pathTracer?.setUniform("renderMode", parseInt(e.renderMode)), t.stages.pathTracer?.updateCompletionThreshold?.(), t.cameraManager.controls && (t.cameraManager.controls.enabled = e.controlsEnabled ?? !0), t.denoisingManager?.denoiser && (t.denoisingManager.applyOIDNEnabled(e.oidnEnabled ?? !1), e.oidnQuality && t.denoisingManager.applyOIDNQuality(e.oidnQuality)), t.pauseRendering = e.pauseRendering ?? !1, e.view && t.cameraManager.applyPose(e.view), t.denoisingManager?.setCadenceSuspended(!1), t.animationManager?.stop(), t.reset(), t.wake();
|
|
6673
|
+
t.stages.pathTracer && e.renderMode !== void 0 && t.stages.pathTracer?.setUniform("renderMode", parseInt(e.renderMode)), t.stages.pathTracer?.updateCompletionThreshold?.(), t.cameraManager.controls && (t.cameraManager.controls.enabled = e.controlsEnabled ?? !0), t.denoisingManager?.denoiser && (t.denoisingManager.applyOIDNEnabled(e.oidnEnabled ?? !1), e.oidnQuality && t.denoisingManager.applyOIDNQuality(e.oidnQuality)), t.pauseRendering = e.pauseRendering ?? !1, t.stages.autoExposure && (t.stages.autoExposure.instant = e.instantExposure ?? !1, t.stages.autoExposure.holdSamples = e.holdExposureSamples ?? 0), e.view && t.cameraManager.applyPose(e.view), t.denoisingManager?.setCadenceSuspended(!1), t.animationManager?.stop(), t.reset(), t.wake();
|
|
6185
6674
|
}
|
|
6186
6675
|
};
|
|
6187
6676
|
//#endregion
|
|
6188
|
-
export { Tt as ARCHIVE_FORMATS,
|
|
6677
|
+
export { Tt as ARCHIVE_FORMATS, qr as ASVGF_QUALITY_PRESETS, ta as AUTO_EXPOSURE_DEFAULTS, _o as AUTO_FOCUS_DEFAULTS, $s as AnimationManager, Ye as BVH_LEAF_MARKERS, Co as CameraManager, Do as CameraTrack, $t as ColorManagement, Vt as DEFAULT_LUT_SIZE, Xt as DEFAULT_MAX_EV, qt as DEFAULT_MIN_EV, _e as DEFAULT_SUN_PATH, _t as DEFAULT_VIEW, at as DEFAULT_WORKING_SPACE, ei as DENOISER_DEFAULTS, C as DOWNLOAD_POLICY, Hs as DenoisingManager, f as DownloadCache, tt as ENGINE_AREAS, Ee as ENGINE_DEFAULTS, j as EngineEvents, $e as EngineIssueError, Ao as GoboManager, Ho as IESManager, Oe as INTERACTIVE_RENDER_CONFIG, Ze as ISSUE_CODES, Qe as ISSUE_SEVERITY, $a as InteractionManager, Xe as IssueLog, we as LEGACY_EVENT_NAMES, Da as LOCAL_EXPOSURE_DEFAULTS, qe as LOG_LEVELS, ee as LightManager, Ge as Logger, ze as MATERIAL_DEFAULTS, Te as MATERIAL_VALUE_SOURCE, Se as MAX_RESERVABLE_RENDER_SIZE, Fe as MAX_SCENE_BYTES, ht as MAX_TABLE_TRANSFORMS, Me as MemoryLedger, Xr as NRD_DEFAULTS, Jr as NRD_HIT_DIST_A, Yr as NRD_HIT_DIST_B, Zr as NRD_PRESET_KEYS, Qr as NRD_QUALITY_PRESETS, dt as OCIO_VIEW_BASE, Zs as OverlayManager, De as PRODUCTION_RENDER_CONFIG, _c as PathTracerApp, u as PipelineContext, _n as RETOUCH_DEFAULTS, vn as RETOUCH_MAX_PIXELS, gn as RETOUCH_RANGES, w as RayzeeRenderer, S as RenderPipeline, d as RenderSettings, O as RenderStage, Ne as SAFE_SCENE_BYTES, ic as SCENE_STATE_VERSION, x as SETTING_SOURCE, xe as SKY_DEFAULTS, mn as SR_MAX_INPUT, hn as SR_SCALE, et as STORAGE_KIND, ge as StageExecutionMode, ln as StorageManager, Je as TRIANGLE_DATA_LAYOUT, ko as TimelineManager, nc as TransformManager, Be as VERSION, ct as VIEW_TRANSFORMS, fe as VRAMTracker, xc as VideoRenderManager, on as acquireLock, Ut as addAllOcioViews, Ht as addOcioView, pt as addViewTransform, rn as applyMatrixRGBA8, tn as bakeLut, be as bufferBytes, It as buildOcioView, gt as buildToneMapWGSL, v as cachedObjectURL, Jt as canvasColorSpaceFor, yc as captureHeadless, y as clearBindingAuditFindings, Lt as clearInputOverrides, st as configureAssets, Ue as configurePlatform, Pt as convertColor, At as convertEncodedRGBA8, nn as convertPixelsF32, Ke as createLogger, de as dayOfYearForMonth, ke as deriveAlphaMode, b as describeAdapter, kt as displayCanvasFit, Re as estimateSceneBytes, Ft as extractMatrix, Et as extractSceneMetadata, T as fetchFile, xt as fileIdentity, Zt as findNativeLinearSpace, We as fmt, St as folderIdentity, me as fromPortable, it as getActiveColorManagement, ot as getAssetConfig, g as getBindingAuditFindings, He as getPlatform, ft as getRegistryVersion, vt as getViewTransform, Mt as hasColorSpace, sn as heldLockNames, bt as identityKey, Wt as isColorManaged, jt as isDataSpace, Yt as isDataTexture, Nt as linearToSrgb, Qt as listFileRules, zt as listInputOverrides, lt as listViewTransforms, Ct as localFolder, an as makeCpuSampler, Rt as measureBakeError, p as nameFromUrl, mt as onRegistryChange, bc as openHeadless, cn as openStorage, fn as openZip, wt as parseSceneMetadata, Ie as probeAddressSpace, dn as readZipDirectory, ut as removeViewTransform, vc as renderHeadless, pn as renderUpscaled, Kt as resolveInputSpace, yt as sameIdentity, rt as setActiveColorManagement, h as setBindingAudit, en as setInputOverride, Gt as srgbToLinear, pe as sunPosition, ve as textureBytes, Bt as textureInputSpace, ye as timeForSunElevation, ue as toPortable };
|