rayzee 9.1.2 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -16
- package/dist/{NeuralRetouch-BRquqfmZ.js → NeuralRetouch-CYgkQY8Z.js} +1 -1
- package/dist/{NeuralSuperRes-CbNvQjCw.js → NeuralSuperRes-PkgDLQcD.js} +72 -40
- package/dist/{ToneMapGPU-DpUZDMbQ.js → ToneMapGPU-B6XIe3DU.js} +102 -92
- package/dist/rayzee.es.js +6209 -5571
- package/dist/rayzee.umd.js +137 -126
- package/package.json +3 -2
- package/src/AssetConfig.js +10 -5
- package/src/EngineEvents.js +41 -1
- package/src/EngineIssues.js +3 -0
- package/src/Headless.js +23 -7
- package/src/HeadlessCanvas.js +104 -0
- package/src/Passes/OIDNDenoiser.js +29 -4
- package/src/Passes/OIDNTemporalHistory.js +7 -0
- package/src/PathTracerApp.js +511 -136
- package/src/Platform.js +76 -0
- package/src/Processor/AssetLoader.js +66 -4
- package/src/Processor/BVHBuilder.js +2 -1
- package/src/Processor/EquirectHDRInfo.js +2 -1
- package/src/Processor/HostMemory.js +14 -0
- package/src/Processor/PBRT/PBRTSceneBuilder.js +26 -0
- package/src/Processor/ParallelBVHBuilder.js +7 -6
- package/src/Processor/PlatformImageLoader.js +118 -0
- package/src/Processor/ResampleRGBA8.js +102 -0
- package/src/Processor/SceneProcessor.js +7 -6
- package/src/Processor/TextureCreator.js +162 -13
- package/src/Processor/TextureReadback.js +26 -10
- package/src/Processor/ToneMapGPU.js +45 -15
- package/src/Processor/Workers/PackWorker.js +28 -0
- package/src/Stages/Compositor.js +25 -6
- package/src/Stages/PathTracer.js +142 -25
- package/src/Stages/PathTracerStage.js +6 -96
- package/src/Storage/DownloadCache.js +30 -7
- package/src/TSL/DebugKernel.js +1 -1
- package/src/TSL/GenerateKernel.js +2 -5
- package/src/TSL/Random.js +3 -120
- package/src/TSL/ShadeKernel.js +3 -3
- package/src/index.js +2 -1
- package/src/managers/CameraManager.js +2 -2
- package/src/managers/DenoisingManager.js +76 -7
- package/src/managers/GoboManager.js +8 -1
- package/src/managers/IESManager.js +13 -2
- package/src/managers/InteractionManager.js +1 -1
- package/src/managers/LightManager.js +31 -0
- package/src/managers/OverlayManager.js +11 -1
- package/src/managers/VideoRenderManager.js +8 -0
- package/src/node/NodeWorker.js +144 -0
- package/src/node/index.js +9 -0
- package/src/node/nodePlatform.js +86 -0
|
@@ -97,8 +97,6 @@ function E() {
|
|
|
97
97
|
//#endregion
|
|
98
98
|
//#region src/AssetConfig.js
|
|
99
99
|
var D = {
|
|
100
|
-
stbnScalarAtlas: "https://assets.rayzee.atulmourya.com/noise/stbn_scalar_atlas.png",
|
|
101
|
-
stbnVec2Atlas: "https://assets.rayzee.atulmourya.com/noise/stbn_vec2_atlas.png",
|
|
102
100
|
ortRuntimeUrl: "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs",
|
|
103
101
|
ortWasmPaths: "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/",
|
|
104
102
|
dracoDecoderPath: "https://www.gstatic.com/draco/v1/decoders/",
|
|
@@ -112,48 +110,54 @@ var D = {
|
|
|
112
110
|
neuralAssetBaseUrl: null,
|
|
113
111
|
cacheNamespace: "rayzee",
|
|
114
112
|
storage: "auto"
|
|
115
|
-
};
|
|
116
|
-
function
|
|
117
|
-
|
|
113
|
+
}, O = /* @__PURE__ */ new Set();
|
|
114
|
+
function k(e) {
|
|
115
|
+
if (e) {
|
|
116
|
+
Object.assign(D, e);
|
|
117
|
+
for (let t of Object.keys(e)) O.add(t);
|
|
118
|
+
}
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
+
function A(e) {
|
|
121
|
+
return O.has(e);
|
|
122
|
+
}
|
|
123
|
+
function j() {
|
|
120
124
|
return { ...D };
|
|
121
125
|
}
|
|
122
126
|
//#endregion
|
|
123
127
|
//#region src/Color/BuiltinViews.js
|
|
124
|
-
var
|
|
125
|
-
function j(e, t, n, r, i) {
|
|
126
|
-
i[0] = A(e), i[1] = A(t), i[2] = A(n);
|
|
127
|
-
}
|
|
128
|
+
var M = (e) => Math.min(Math.max(e, 0), 1);
|
|
128
129
|
function ee(e, t, n, r, i) {
|
|
129
|
-
i[0] =
|
|
130
|
+
i[0] = M(e), i[1] = M(t), i[2] = M(n);
|
|
130
131
|
}
|
|
131
132
|
function te(e, t, n, r, i) {
|
|
132
|
-
|
|
133
|
+
i[0] = M(e * r), i[1] = M(t * r), i[2] = M(n * r);
|
|
133
134
|
}
|
|
134
135
|
function ne(e, t, n, r, i) {
|
|
136
|
+
e *= r, t *= r, n *= r, i[0] = M(e / (e + 1)), i[1] = M(t / (t + 1)), i[2] = M(n / (n + 1));
|
|
137
|
+
}
|
|
138
|
+
function re(e, t, n, r, i) {
|
|
135
139
|
e = Math.max(e * r - .004, 0), t = Math.max(t * r - .004, 0), n = Math.max(n * r - .004, 0);
|
|
136
140
|
let a = (e) => (e * (6.2 * e + .5) / (e * (6.2 * e + 1.7) + .06)) ** 2.2;
|
|
137
141
|
i[0] = a(e), i[1] = a(t), i[2] = a(n);
|
|
138
142
|
}
|
|
139
|
-
function
|
|
143
|
+
function N(e, t, n, r, i) {
|
|
140
144
|
e = e * r / .6, t = t * r / .6, n = n * r / .6;
|
|
141
145
|
let a = .59719 * e + .35458 * t + .04823 * n, o = .076 * e + .90834 * t + .01566 * n, s = .0284 * e + .13383 * t + .83777 * n, c = (e) => (e * (e + .0245786) - 90537e-9) / (e * (.983729 * e + .432951) + .238081);
|
|
142
|
-
a = c(a), o = c(o), s = c(s), i[0] =
|
|
146
|
+
a = c(a), o = c(o), s = c(s), i[0] = M(1.60475 * a - .53108 * o - .07367 * s), i[1] = M(-.10208 * a + 1.10813 * o - .00605 * s), i[2] = M(-.00327 * a - .07276 * o + 1.07602 * s);
|
|
143
147
|
}
|
|
144
|
-
function
|
|
148
|
+
function P(e, t, n, r, i) {
|
|
145
149
|
e *= r, t *= r, n *= r;
|
|
146
150
|
let a = .6274 * e + .3293 * t + .0433 * n, o = .0691 * e + .9195 * t + .0113 * n, s = .0164 * e + .088 * t + .8956 * n, c = .856627153315983 * a + .0951212405381588 * o + .0482516061458583 * s, l = .137318972929847 * a + .761241990602591 * o + .101439036467562 * s, u = .11189821299995 * a + .0767994186031903 * o + .811302368396859 * s, d = -12.47393, f = 4.026069 - d;
|
|
147
|
-
c =
|
|
151
|
+
c = M((Math.log2(Math.max(c, 1e-10)) - d) / f), l = M((Math.log2(Math.max(l, 1e-10)) - d) / f), u = M((Math.log2(Math.max(u, 1e-10)) - d) / f);
|
|
148
152
|
let p = (e) => {
|
|
149
153
|
let t = e * e, n = t * t;
|
|
150
154
|
return 15.5 * n * t - 40.14 * n * e + 31.96 * n - 6.868 * t * e + .4298 * t + .1191 * e - .00232;
|
|
151
155
|
};
|
|
152
156
|
c = p(c), l = p(l), u = p(u);
|
|
153
157
|
let m = 1.1271005818144368 * c - .11060664309660323 * l - .016493938717834573 * u, h = -.1413297634984383 * c + 1.157823702216272 * l - .016493938717834257 * u, g = -.14132976349843826 * c - .11060664309660294 * l + 1.2519364065950405 * u;
|
|
154
|
-
m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] =
|
|
158
|
+
m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] = M(1.6605 * m - .5876 * h - .0728 * g), i[1] = M(-.1246 * m + 1.1329 * h - .0083 * g), i[2] = M(-.0182 * m - .1006 * h + 1.1187 * g);
|
|
155
159
|
}
|
|
156
|
-
function
|
|
160
|
+
function F(e, t, n, r, i) {
|
|
157
161
|
let a = .76;
|
|
158
162
|
e *= r, t *= r, n *= r;
|
|
159
163
|
let o = Math.min(e, Math.min(t, n)), s = o < .08 ? o - 6.25 * o * o : .04;
|
|
@@ -168,12 +172,12 @@ function N(e, t, n, r, i) {
|
|
|
168
172
|
let f = 1 - 1 / (.15 * (c - u) + 1);
|
|
169
173
|
i[0] = e + (u - e) * f, i[1] = t + (u - t) * f, i[2] = n + (u - n) * f;
|
|
170
174
|
}
|
|
171
|
-
var
|
|
175
|
+
var I = [
|
|
172
176
|
{
|
|
173
177
|
id: a,
|
|
174
178
|
name: "None",
|
|
175
179
|
wgslConst: "TM_NONE",
|
|
176
|
-
cpu:
|
|
180
|
+
cpu: ee,
|
|
177
181
|
wgsl: null,
|
|
178
182
|
call: null,
|
|
179
183
|
appliesExposure: !1
|
|
@@ -182,7 +186,7 @@ var P = [
|
|
|
182
186
|
id: r,
|
|
183
187
|
name: "Linear",
|
|
184
188
|
wgslConst: "TM_LINEAR",
|
|
185
|
-
cpu:
|
|
189
|
+
cpu: te,
|
|
186
190
|
wgsl: null,
|
|
187
191
|
call: null
|
|
188
192
|
},
|
|
@@ -190,7 +194,7 @@ var P = [
|
|
|
190
194
|
id: o,
|
|
191
195
|
name: "Reinhard",
|
|
192
196
|
wgslConst: "TM_REINHARD",
|
|
193
|
-
cpu:
|
|
197
|
+
cpu: ne,
|
|
194
198
|
wgsl: "\nfn tm_reinhard( c: vec3<f32> ) -> vec3<f32> {\n return clamp( c / ( c + vec3<f32>( 1.0 ) ), vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n}\n",
|
|
195
199
|
call: "tm_reinhard( c )"
|
|
196
200
|
},
|
|
@@ -198,7 +202,7 @@ var P = [
|
|
|
198
202
|
id: n,
|
|
199
203
|
name: "Cineon",
|
|
200
204
|
wgslConst: "TM_CINEON",
|
|
201
|
-
cpu:
|
|
205
|
+
cpu: re,
|
|
202
206
|
wgsl: "\nfn tm_cineon( c0: vec3<f32> ) -> vec3<f32> {\n let c = max( c0 - vec3<f32>( 0.004 ), vec3<f32>( 0.0 ) );\n let v = ( c * ( 6.2 * c + vec3<f32>( 0.5 ) ) ) / ( c * ( 6.2 * c + vec3<f32>( 1.7 ) ) + vec3<f32>( 0.06 ) );\n return pow( max( v, vec3<f32>( 0.0 ) ), vec3<f32>( 2.2 ) );\n}\n",
|
|
203
207
|
call: "tm_cineon( c )"
|
|
204
208
|
},
|
|
@@ -206,7 +210,7 @@ var P = [
|
|
|
206
210
|
id: e,
|
|
207
211
|
name: "ACES Filmic",
|
|
208
212
|
wgslConst: "TM_ACES",
|
|
209
|
-
cpu:
|
|
213
|
+
cpu: N,
|
|
210
214
|
wgsl: "\nfn tm_aces( c0: vec3<f32> ) -> vec3<f32> {\n let c = c0 / 0.6;\n let m_in = mat3x3<f32>(\n vec3<f32>( 0.59719, 0.07600, 0.02840 ),\n vec3<f32>( 0.35458, 0.90834, 0.13383 ),\n vec3<f32>( 0.04823, 0.01566, 0.83777 ) );\n let v = m_in * c;\n let a = v * ( v + vec3<f32>( 0.0245786 ) ) - vec3<f32>( 0.000090537 );\n let b = v * ( 0.983729 * v + vec3<f32>( 0.4329510 ) ) + vec3<f32>( 0.238081 );\n let m_out = mat3x3<f32>(\n vec3<f32>( 1.60475, -0.10208, -0.00327 ),\n vec3<f32>( -0.53108, 1.10813, -0.07276 ),\n vec3<f32>( -0.07367, -0.00605, 1.07602 ) );\n return clamp( m_out * ( a / b ), vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n}\n",
|
|
211
215
|
call: "tm_aces( c )"
|
|
212
216
|
},
|
|
@@ -214,7 +218,7 @@ var P = [
|
|
|
214
218
|
id: t,
|
|
215
219
|
name: "AgX",
|
|
216
220
|
wgslConst: "TM_AGX",
|
|
217
|
-
cpu:
|
|
221
|
+
cpu: P,
|
|
218
222
|
wgsl: "\nfn tm_agx( c0: vec3<f32> ) -> vec3<f32> {\n let m_in = mat3x3<f32>(\n vec3<f32>( 0.6274, 0.0691, 0.0164 ),\n vec3<f32>( 0.3293, 0.9195, 0.0880 ),\n vec3<f32>( 0.0433, 0.0113, 0.8956 ) );\n let m_agx = mat3x3<f32>(\n vec3<f32>( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n vec3<f32>( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n vec3<f32>( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) );\n\n var v = m_agx * ( m_in * c0 );\n\n let minEv = -12.47393;\n let maxEv = 4.026069;\n v = clamp( ( log2( max( v, vec3<f32>( 1e-10 ) ) ) - vec3<f32>( minEv ) ) / ( maxEv - minEv ),\n vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n\n let x2 = v * v;\n let x4 = x2 * x2;\n v = 15.5 * x4 * x2 - 40.14 * x4 * v + 31.96 * x4 - 6.868 * x2 * v + 0.4298 * x2 + 0.1191 * v\n - vec3<f32>( 0.00232 );\n\n let m_out = mat3x3<f32>(\n vec3<f32>( 1.1271005818144368, -0.1413297634984383, -0.14132976349843826 ),\n vec3<f32>( -0.11060664309660323, 1.157823702216272, -0.11060664309660294 ),\n vec3<f32>( -0.016493938717834573, -0.016493938717834257, 1.2519364065950405 ) );\n let o = pow( max( m_out * v, vec3<f32>( 0.0 ) ), vec3<f32>( 2.2 ) );\n\n let m_srgb = mat3x3<f32>(\n vec3<f32>( 1.6605, -0.1246, -0.0182 ),\n vec3<f32>( -0.5876, 1.1329, -0.1006 ),\n vec3<f32>( -0.0728, -0.0083, 1.1187 ) );\n return clamp( m_srgb * o, vec3<f32>( 0.0 ), vec3<f32>( 1.0 ) );\n}\n",
|
|
219
223
|
call: "tm_agx( c )"
|
|
220
224
|
},
|
|
@@ -222,7 +226,7 @@ var P = [
|
|
|
222
226
|
id: i,
|
|
223
227
|
name: "Neutral",
|
|
224
228
|
wgslConst: "TM_NEUTRAL",
|
|
225
|
-
cpu:
|
|
229
|
+
cpu: F,
|
|
226
230
|
wgsl: "\nfn tm_neutral( c0: vec3<f32> ) -> vec3<f32> {\n let startCompression = 0.8 - 0.04;\n let desaturation = 0.15;\n\n let x = min( c0.r, min( c0.g, c0.b ) );\n var offset = 0.04;\n if ( x < 0.08 ) { offset = x - 6.25 * x * x; }\n var c = c0 - vec3<f32>( offset );\n\n let peak = max( c.r, max( c.g, c.b ) );\n if ( peak < startCompression ) { return c; }\n\n let d = 1.0 - startCompression;\n let newPeak = 1.0 - d * d / ( peak + d - startCompression );\n c = c * ( newPeak / peak );\n let gFactor = 1.0 - 1.0 / ( desaturation * ( peak - newPeak ) + 1.0 );\n return mix( c, vec3<f32>( newPeak ), gFactor );\n}\n",
|
|
227
231
|
call: "tm_neutral( c )"
|
|
228
232
|
}
|
|
@@ -231,23 +235,23 @@ var P = [
|
|
|
231
235
|
outputEncoded: !1,
|
|
232
236
|
appliesExposure: !0,
|
|
233
237
|
...e
|
|
234
|
-
})),
|
|
235
|
-
function V() {
|
|
236
|
-
z++;
|
|
237
|
-
for (let e of B) e();
|
|
238
|
-
}
|
|
239
|
-
var H = R;
|
|
238
|
+
})), L = 200, R = 12, z = [...I], B = new Map(z.map((e) => [e.id, e])), V = 1, H = /* @__PURE__ */ new Set();
|
|
240
239
|
function U() {
|
|
241
|
-
|
|
240
|
+
V++;
|
|
241
|
+
for (let e of H) e();
|
|
242
|
+
}
|
|
243
|
+
var W = B;
|
|
244
|
+
function G() {
|
|
245
|
+
return V;
|
|
242
246
|
}
|
|
243
|
-
function
|
|
244
|
-
return
|
|
247
|
+
function K(e) {
|
|
248
|
+
return H.add(e), () => H.delete(e);
|
|
245
249
|
}
|
|
246
|
-
function
|
|
247
|
-
return
|
|
250
|
+
function q(e) {
|
|
251
|
+
return B.get(e) ?? null;
|
|
248
252
|
}
|
|
249
|
-
function
|
|
250
|
-
return
|
|
253
|
+
function J() {
|
|
254
|
+
return z.map((e) => ({
|
|
251
255
|
id: e.id,
|
|
252
256
|
name: e.name,
|
|
253
257
|
source: e.source,
|
|
@@ -256,52 +260,52 @@ function K() {
|
|
|
256
260
|
look: e.ocio?.look ?? null
|
|
257
261
|
}));
|
|
258
262
|
}
|
|
259
|
-
function
|
|
260
|
-
return
|
|
263
|
+
function Y() {
|
|
264
|
+
return z.filter((e) => e.table).length;
|
|
261
265
|
}
|
|
262
|
-
function
|
|
266
|
+
function ie() {
|
|
263
267
|
let e = 200;
|
|
264
|
-
for (;
|
|
268
|
+
for (; B.has(e);) e++;
|
|
265
269
|
return e;
|
|
266
270
|
}
|
|
267
|
-
function
|
|
271
|
+
function ae(e) {
|
|
268
272
|
if (typeof e?.id != "number") throw Error("view transform needs a numeric id");
|
|
269
273
|
if (typeof e.cpu != "function") throw Error(`view transform ${e.id} needs a cpu function`);
|
|
270
274
|
if (!e.name) throw Error(`view transform ${e.id} needs a name`);
|
|
271
275
|
if (!/^TM_[A-Z0-9_]+$/.test(e.wgslConst ?? "")) throw Error(`view transform ${e.id} needs a wgslConst like TM_SOMETHING`);
|
|
272
|
-
let t =
|
|
273
|
-
if (!t && e.table &&
|
|
276
|
+
let t = B.get(e.id);
|
|
277
|
+
if (!t && e.table && Y() >= 12) throw Error(`cannot register "${e.name}": 12 table-backed view transforms already registered, and WebGPU only guarantees 16 sampled textures per stage. Remove one first.`);
|
|
274
278
|
let n = {
|
|
275
279
|
source: "custom",
|
|
276
280
|
outputEncoded: !1,
|
|
277
281
|
appliesExposure: !0,
|
|
278
282
|
...e
|
|
279
283
|
};
|
|
280
|
-
return t ?
|
|
284
|
+
return t ? z[z.indexOf(t)] = n : z.push(n), B.set(n.id, n), U(), n;
|
|
281
285
|
}
|
|
282
|
-
function
|
|
283
|
-
let t =
|
|
284
|
-
return t ? (
|
|
286
|
+
function oe(e) {
|
|
287
|
+
let t = B.get(e);
|
|
288
|
+
return t ? (z.splice(z.indexOf(t), 1), B.delete(e), U(), !0) : !1;
|
|
285
289
|
}
|
|
286
|
-
function
|
|
287
|
-
let t =
|
|
290
|
+
function se(e = null) {
|
|
291
|
+
let t = z.filter((t) => t.source === "ocio" && !e?.has(t.id)).map((e) => e.id);
|
|
288
292
|
if (t.length === 0) return 0;
|
|
289
293
|
for (let e of t) {
|
|
290
|
-
let t =
|
|
291
|
-
|
|
294
|
+
let t = B.get(e);
|
|
295
|
+
z.splice(z.indexOf(t), 1), B.delete(e);
|
|
292
296
|
}
|
|
293
|
-
return
|
|
297
|
+
return U(), t.length;
|
|
294
298
|
}
|
|
295
|
-
function
|
|
299
|
+
function ce(e) {
|
|
296
300
|
let t = e?.library;
|
|
297
301
|
if (!t?.addToneMapping) return 0;
|
|
298
302
|
let n = 0;
|
|
299
|
-
for (let e of
|
|
303
|
+
for (let e of z) e.tsl && (t.toneMappingNodes?.delete(e.id), t.addToneMapping(e.tsl, e.id), n++);
|
|
300
304
|
return n;
|
|
301
305
|
}
|
|
302
306
|
function X({ group: e = 0, firstBinding: t = 3 } = {}) {
|
|
303
307
|
let n = [], r = t, i = [], a = [];
|
|
304
|
-
for (let t of
|
|
308
|
+
for (let t of z) {
|
|
305
309
|
if (t.table) {
|
|
306
310
|
let a = `${t.wgslConst.toLowerCase()}_tex`;
|
|
307
311
|
i.push(`@group(${e}) @binding(${r}) var ${a}: texture_3d<f32>;`), n.push({
|
|
@@ -312,7 +316,7 @@ function X({ group: e = 0, firstBinding: t = 3 } = {}) {
|
|
|
312
316
|
}
|
|
313
317
|
t.wgsl && a.push(t.wgsl);
|
|
314
318
|
}
|
|
315
|
-
let o =
|
|
319
|
+
let o = z.map((e) => `const ${e.wgslConst}: u32 = ${e.id}u;`).join("\n"), s = z.filter((e) => e.call).map((e) => `\tif ( mode == ${e.wgslConst} ) { return ${e.call}; }`).join("\n"), c = z.filter((e) => e.outputEncoded).map((e) => e.wgslConst), l = c.length ? c.map((e) => `mode == ${e}`).join(" || ") : "false", u = z.filter((e) => !e.appliesExposure).map((e) => e.wgslConst), d = u.length ? u.map((e) => `mode == ${e}`).join(" || ") : "false";
|
|
316
320
|
return {
|
|
317
321
|
wgsl: `
|
|
318
322
|
${o}
|
|
@@ -366,25 +370,28 @@ fn rayzee_to_u8( srgb: vec3<f32> ) -> vec3<u32> {
|
|
|
366
370
|
bindings: n
|
|
367
371
|
};
|
|
368
372
|
}
|
|
369
|
-
function
|
|
370
|
-
|
|
371
|
-
for (let e of
|
|
372
|
-
|
|
373
|
+
function Z() {
|
|
374
|
+
z.length = 0, z.push(...I), B.clear();
|
|
375
|
+
for (let e of z) B.set(e.id, e);
|
|
376
|
+
U();
|
|
373
377
|
}
|
|
374
|
-
var
|
|
378
|
+
var le = a, ue = 0, de = 3;
|
|
375
379
|
function Q() {
|
|
376
380
|
let { wgsl: e, bindings: t } = X({
|
|
377
|
-
group:
|
|
378
|
-
firstBinding:
|
|
381
|
+
group: ue,
|
|
382
|
+
firstBinding: de
|
|
379
383
|
});
|
|
380
384
|
return {
|
|
381
385
|
wgsl: e,
|
|
382
386
|
bindings: t,
|
|
383
|
-
version:
|
|
387
|
+
version: G()
|
|
384
388
|
};
|
|
385
389
|
}
|
|
386
390
|
Q().wgsl;
|
|
387
|
-
var
|
|
391
|
+
var fe = {
|
|
392
|
+
packed: "\n@group(0) @binding(0) var<storage, read> src: array<u32>;\n\nfn rayzee_source( x: u32, y: u32 ) -> vec4<f32> {\n let a = ( y * params.width + x ) * 2u;\n return vec4<f32>( unpack2x16float( src[ a ] ), unpack2x16float( src[ a + 1u ] ) );\n}",
|
|
393
|
+
texture: "\n@group(0) @binding(0) var src: texture_2d<f32>;\n\nfn rayzee_source( x: u32, y: u32 ) -> vec4<f32> {\n return textureLoad( src, vec2<u32>( x, y ), 0 );\n}"
|
|
394
|
+
}, pe = (e, t) => `
|
|
388
395
|
struct Params {
|
|
389
396
|
width: u32,
|
|
390
397
|
height: u32,
|
|
@@ -392,11 +399,12 @@ struct Params {
|
|
|
392
399
|
flipY: u32,
|
|
393
400
|
exposure: f32,
|
|
394
401
|
saturation: f32,
|
|
402
|
+
alpha: u32,
|
|
395
403
|
};
|
|
396
404
|
|
|
397
|
-
@group(0) @binding(0) var<storage, read> src: array<u32>;
|
|
398
405
|
@group(0) @binding(1) var<storage, read_write> dst: array<u32>;
|
|
399
406
|
@group(0) @binding(2) var<uniform> params: Params;
|
|
407
|
+
${fe[t]}
|
|
400
408
|
|
|
401
409
|
${e}
|
|
402
410
|
|
|
@@ -407,17 +415,16 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
407
415
|
var srcY = gid.y;
|
|
408
416
|
if ( params.flipY == 1u ) { srcY = params.height - 1u - gid.y; }
|
|
409
417
|
|
|
410
|
-
let
|
|
411
|
-
let
|
|
412
|
-
let ba = unpack2x16float( src[ a + 1u ] );
|
|
413
|
-
|
|
414
|
-
let mapped = rayzee_tone_map( vec3<f32>( rg.x, rg.y, ba.x ), params.mode, params.exposure, params.saturation );
|
|
418
|
+
let linear = rayzee_source( gid.x, srcY );
|
|
419
|
+
let mapped = rayzee_tone_map( linear.rgb, params.mode, params.exposure, params.saturation );
|
|
415
420
|
let b8 = rayzee_to_u8( rayzee_encode( mapped, params.mode ) );
|
|
416
|
-
|
|
421
|
+
var a8 = 255u;
|
|
422
|
+
if ( params.alpha == 1u ) { a8 = rayzee_to_u8( vec3<f32>( linear.a ) ).x; }
|
|
423
|
+
dst[ gid.y * params.width + gid.x ] = b8.x | ( b8.y << 8u ) | ( b8.z << 16u ) | ( a8 << 24u );
|
|
417
424
|
}
|
|
418
|
-
`, $ = 32,
|
|
419
|
-
constructor(e, t = "rayzee:tonemap") {
|
|
420
|
-
this.device = e, this.label = t, this.width = 0, this.height = 0, this._pipeline = null, this._storage = null, this._map = null, this._params = null, this._paramData = new ArrayBuffer($), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._shaderVersion = -1, this._bindings = [], this._tables = /* @__PURE__ */ new Map(), this.disposed = !1;
|
|
425
|
+
`, $ = 32, me = class {
|
|
426
|
+
constructor(e, t = "rayzee:tonemap", { input: n = "packed" } = {}) {
|
|
427
|
+
this.device = e, this.label = t, this.input = n, this.width = 0, this.height = 0, this._pipeline = null, this._storage = null, this._map = null, this._params = null, this._paramData = new ArrayBuffer($), this._paramU32 = new Uint32Array(this._paramData), this._paramF32 = new Float32Array(this._paramData), this._shaderVersion = -1, this._bindings = [], this._tables = /* @__PURE__ */ new Map(), this.disposed = !1;
|
|
421
428
|
}
|
|
422
429
|
_ensurePipeline() {
|
|
423
430
|
let { wgsl: e, bindings: t, version: n } = Q();
|
|
@@ -427,7 +434,7 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
427
434
|
compute: {
|
|
428
435
|
module: this.device.createShaderModule({
|
|
429
436
|
label: this.label,
|
|
430
|
-
code:
|
|
437
|
+
code: pe(e, this.input)
|
|
431
438
|
}),
|
|
432
439
|
entryPoint: "main"
|
|
433
440
|
}
|
|
@@ -485,24 +492,24 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
485
492
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
486
493
|
}), this.width = e, this.height = t;
|
|
487
494
|
}
|
|
488
|
-
async toRGBA8(e, { exposure: t = 1, toneMapping: n = 0, saturation: r = 1, flipY: i = !1 } = {}) {
|
|
495
|
+
async toRGBA8(e, { exposure: t = 1, toneMapping: n = 0, saturation: r = 1, flipY: i = !1, preserveAlpha: a = !1 } = {}) {
|
|
489
496
|
if (this.disposed) throw Error("PackedToneMapper: disposed");
|
|
490
497
|
if (!this._storage) throw Error("PackedToneMapper: call ensureSize() first");
|
|
491
498
|
this._ensurePipeline(), this._ensureTables();
|
|
492
|
-
let { width:
|
|
493
|
-
this._paramU32[0] =
|
|
494
|
-
let
|
|
499
|
+
let { width: o, height: s } = this;
|
|
500
|
+
this._paramU32[0] = o, this._paramU32[1] = s, this._paramU32[2] = n >>> 0, this._paramU32[3] = +!!i, this._paramF32[4] = t, this._paramF32[5] = r, this._paramU32[6] = +!!a, this.device.queue.writeBuffer(this._params, 0, this._paramData);
|
|
501
|
+
let c = [...this._tables.entries()].map(([e, t]) => ({
|
|
495
502
|
binding: e,
|
|
496
503
|
resource: t.view
|
|
497
|
-
})),
|
|
504
|
+
})), l = this.device.createBindGroup({
|
|
498
505
|
layout: this._pipeline.getBindGroupLayout(0),
|
|
499
506
|
entries: [
|
|
500
|
-
...
|
|
507
|
+
...c,
|
|
501
508
|
{
|
|
502
509
|
binding: 0,
|
|
503
|
-
resource: {
|
|
510
|
+
resource: this.input === "texture" ? e.createView() : {
|
|
504
511
|
buffer: e,
|
|
505
|
-
size:
|
|
512
|
+
size: o * s * 8
|
|
506
513
|
}
|
|
507
514
|
},
|
|
508
515
|
{
|
|
@@ -514,10 +521,13 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
514
521
|
resource: { buffer: this._params }
|
|
515
522
|
}
|
|
516
523
|
]
|
|
517
|
-
}),
|
|
518
|
-
|
|
519
|
-
let
|
|
520
|
-
return this._map.unmap(),
|
|
524
|
+
}), u = this.device.createCommandEncoder({ label: this.label }), d = u.beginComputePass();
|
|
525
|
+
d.setPipeline(this._pipeline), d.setBindGroup(0, l), d.dispatchWorkgroups(Math.ceil(o / 8), Math.ceil(s / 8)), d.end(), u.copyBufferToBuffer(this._storage, 0, this._map, 0, o * s * 4), this.device.queue.submit([u.finish()]), await this._map.mapAsync(GPUMapMode.READ);
|
|
526
|
+
let f = new Uint8ClampedArray(this._map.getMappedRange().slice(0));
|
|
527
|
+
return this._map.unmap(), f;
|
|
528
|
+
}
|
|
529
|
+
release() {
|
|
530
|
+
this._releaseBuffers(), this.width = this.height = 0;
|
|
521
531
|
}
|
|
522
532
|
_releaseBuffers() {
|
|
523
533
|
this._storage?.destroy(), this._map?.destroy(), this._params?.destroy(), this._storage = null, this._map = null, this._params = null;
|
|
@@ -531,4 +541,4 @@ fn main( @builtin(global_invocation_id) gid: vec3<u32> ) {
|
|
|
531
541
|
}
|
|
532
542
|
};
|
|
533
543
|
//#endregion
|
|
534
|
-
export {
|
|
544
|
+
export { C, E, S, T, Z as _, W as a, A as b, Y as c, J as d, ie as f, oe as g, se as h, L as i, G as l, ce as m, le as n, ae as o, K as p, R as r, X as s, me as t, q as u, k as v, x as w, s as x, j as y };
|