@naanouff/w3dts-path-tracer 0.0.0-stage → 0.1.18
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 +44 -3
- package/dist/PathTracer2Project.d.ts +17 -0
- package/dist/PathTracer2Project.d.ts.map +1 -0
- package/dist/PathTracerFrameUploadController.d.ts +186 -0
- package/dist/PathTracerFrameUploadController.d.ts.map +1 -0
- package/dist/PathTracerProject.d.ts +19 -0
- package/dist/PathTracerProject.d.ts.map +1 -0
- package/dist/SceneToRayData.d.ts +72 -0
- package/dist/SceneToRayData.d.ts.map +1 -0
- package/dist/bloomSubgraph.d.ts +14 -0
- package/dist/bloomSubgraph.d.ts.map +1 -0
- package/dist/buildPathTracerBvh.d.ts +34 -0
- package/dist/buildPathTracerBvh.d.ts.map +1 -0
- package/dist/buildPathTracerTwoLevel.d.ts +66 -0
- package/dist/buildPathTracerTwoLevel.d.ts.map +1 -0
- package/dist/emissiveTriangles.d.ts +28 -0
- package/dist/emissiveTriangles.d.ts.map +1 -0
- package/dist/fsr1EasuConstants.d.ts +7 -0
- package/dist/fsr1EasuConstants.d.ts.map +1 -0
- package/dist/hybridAtrous.d.ts +25 -0
- package/dist/hybridAtrous.d.ts.map +1 -0
- package/dist/hybridOidn.d.ts +15 -0
- package/dist/hybridOidn.d.ts.map +1 -0
- package/dist/hybridTemporal.d.ts +59 -0
- package/dist/hybridTemporal.d.ts.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/khronosPathTraceReference.d.ts +143 -0
- package/dist/khronosPathTraceReference.d.ts.map +1 -0
- package/dist/pathTracerBackplate.d.ts +29 -0
- package/dist/pathTracerBackplate.d.ts.map +1 -0
- package/dist/pathTracerBaselineMetrics.d.ts +98 -0
- package/dist/pathTracerBaselineMetrics.d.ts.map +1 -0
- package/dist/pathTracerBounceBudget.d.ts +32 -0
- package/dist/pathTracerBounceBudget.d.ts.map +1 -0
- package/dist/pathTracerCameraLens.d.ts +12 -0
- package/dist/pathTracerCameraLens.d.ts.map +1 -0
- package/dist/pathTracerConstants.d.ts +165 -0
- package/dist/pathTracerConstants.d.ts.map +1 -0
- package/dist/pathTracerDielectric.d.ts +30 -0
- package/dist/pathTracerDielectric.d.ts.map +1 -0
- package/dist/pathTracerEnvMap.d.ts +83 -0
- package/dist/pathTracerEnvMap.d.ts.map +1 -0
- package/dist/pathTracerGraphDefinition.d.ts +11 -0
- package/dist/pathTracerGraphDefinition.d.ts.map +1 -0
- package/dist/pathTracerInteractionEpoch.d.ts +11 -0
- package/dist/pathTracerInteractionEpoch.d.ts.map +1 -0
- package/dist/pathTracerInterleave.d.ts +74 -0
- package/dist/pathTracerInterleave.d.ts.map +1 -0
- package/dist/pathTracerLightFingerprint.d.ts +26 -0
- package/dist/pathTracerLightFingerprint.d.ts.map +1 -0
- package/dist/pathTracerMaterialTable.d.ts +63 -0
- package/dist/pathTracerMaterialTable.d.ts.map +1 -0
- package/dist/pathTracerMaterialTextureArrays.d.ts +58 -0
- package/dist/pathTracerMaterialTextureArrays.d.ts.map +1 -0
- package/dist/pathTracerOidnDenoiser.d.ts +43 -0
- package/dist/pathTracerOidnDenoiser.d.ts.map +1 -0
- package/dist/pathTracerPost.d.ts +137 -0
- package/dist/pathTracerPost.d.ts.map +1 -0
- package/dist/pathTracerRuntimeConfig.d.ts +6 -0
- package/dist/pathTracerRuntimeConfig.d.ts.map +1 -0
- package/dist/pathTracerSceneCache.d.ts +32 -0
- package/dist/pathTracerSceneCache.d.ts.map +1 -0
- package/dist/pathTracerSceneSettings.d.ts +43 -0
- package/dist/pathTracerSceneSettings.d.ts.map +1 -0
- package/dist/progressiveRenderState.d.ts +34 -0
- package/dist/progressiveRenderState.d.ts.map +1 -0
- package/dist/w3dts-path-tracer.es.js +4555 -0
- package/dist/w3dts-path-tracer.umd.js +46 -0
- package/package.json +55 -3
- package/shaders/clear_composite.compute.wgsl +20 -0
- package/shaders/clear_composite_layers.compute.wgsl +32 -0
- package/shaders/clear_path_trace_tile.compute.wgsl +30 -0
- package/shaders/copy_accum.compute.wgsl +15 -0
- package/shaders/denoise.compute.wgsl +88 -0
- package/shaders/denoise_atrous.compute.wgsl +104 -0
- package/shaders/display_grade.wgsl +74 -0
- package/shaders/fsr1_easu_path.compute.wgsl +240 -0
- package/shaders/fsr1_rcas_path.compute.wgsl +84 -0
- package/shaders/hole_fill.compute.wgsl +57 -0
- package/shaders/hybrid_atrous.compute.wgsl +239 -0
- package/shaders/hybrid_copy_aov.compute.wgsl +24 -0
- package/shaders/hybrid_gbuffer.wgsl +150 -0
- package/shaders/hybrid_history_copy.compute.wgsl +35 -0
- package/shaders/hybrid_primary_aov.compute.wgsl +784 -0
- package/shaders/hybrid_taa.compute.wgsl +131 -0
- package/shaders/hybrid_temporal.compute.wgsl +507 -0
- package/shaders/path_trace.compute.wgsl +923 -0
- package/shaders/path_trace_common.wgsl +1738 -0
- package/shaders/pt_bloom.compute.wgsl +91 -0
- package/shaders/pt_bloom_down.compute.wgsl +88 -0
- package/shaders/pt_bloom_up.compute.wgsl +76 -0
- package/shaders/pt_display.frag.wgsl +29 -0
- package/shaders/tile_composite.compute.wgsl +22 -0
- package/shaders/tile_composite_layers.compute.wgsl +86 -0
|
@@ -0,0 +1,4555 @@
|
|
|
1
|
+
var Bs = Object.defineProperty;
|
|
2
|
+
var Ns = (t, e, a) => e in t ? Bs(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
|
|
3
|
+
var y = (t, e, a) => Ns(t, typeof e != "symbol" ? e + "" : e, a);
|
|
4
|
+
import { pbrNeutralToneMapping as Ls, readMaterialBaseColor as Ye, readMaterialMetallic as je, readMaterialRoughness as qe, DirectionalLightComponent as ye, TransformComponent as bt, isEntityEffectivelyVisible as Re, PointLightComponent as Hs, SpotLightComponent as Ds, AreaLightComponent as Os, TextureLoader as Br, CameraComponent as Gs, getGameViewRenderModeFromGlobal as Us, getGameViewSurfacePixelSize as zs, AbstractProject as Nr, setEntityLocallyVisible as Lr, PrimitiveFactory as Xe, Material as Ka, SceneNode as te, GraphLoader as Hr, clampScalar as G, mixVec3 as Za, distributionGGX as Ra, vGGXCorrelated as Dr, clampVec3 as Ws, fresnelSchlickF90 as ks } from "@naanouff/w3dts-core";
|
|
5
|
+
import { evalKhrPunctualAttenuation as Hc, evalKhrSpotAttenuation as Dc } from "@naanouff/w3dts-core";
|
|
6
|
+
import { LogChannel as $t } from "@naanouff/w3dts-logger";
|
|
7
|
+
var $s = 1e-6, Tt = typeof Float32Array < "u" ? Float32Array : Array;
|
|
8
|
+
Math.hypot || (Math.hypot = function() {
|
|
9
|
+
for (var t = 0, e = arguments.length; e--; )
|
|
10
|
+
t += arguments[e] * arguments[e];
|
|
11
|
+
return Math.sqrt(t);
|
|
12
|
+
});
|
|
13
|
+
function Vs() {
|
|
14
|
+
var t = new Tt(9);
|
|
15
|
+
return Tt != Float32Array && (t[1] = 0, t[2] = 0, t[3] = 0, t[5] = 0, t[6] = 0, t[7] = 0), t[0] = 1, t[4] = 1, t[8] = 1, t;
|
|
16
|
+
}
|
|
17
|
+
function Ke() {
|
|
18
|
+
var t = new Tt(16);
|
|
19
|
+
return Tt != Float32Array && (t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[6] = 0, t[7] = 0, t[8] = 0, t[9] = 0, t[11] = 0, t[12] = 0, t[13] = 0, t[14] = 0), t[0] = 1, t[5] = 1, t[10] = 1, t[15] = 1, t;
|
|
20
|
+
}
|
|
21
|
+
function Ja(t) {
|
|
22
|
+
var e = new Tt(16);
|
|
23
|
+
return e[0] = t[0], e[1] = t[1], e[2] = t[2], e[3] = t[3], e[4] = t[4], e[5] = t[5], e[6] = t[6], e[7] = t[7], e[8] = t[8], e[9] = t[9], e[10] = t[10], e[11] = t[11], e[12] = t[12], e[13] = t[13], e[14] = t[14], e[15] = t[15], e;
|
|
24
|
+
}
|
|
25
|
+
function Ys(t, e) {
|
|
26
|
+
if (t === e) {
|
|
27
|
+
var a = e[1], r = e[2], s = e[3], n = e[6], o = e[7], i = e[11];
|
|
28
|
+
t[1] = e[4], t[2] = e[8], t[3] = e[12], t[4] = a, t[6] = e[9], t[7] = e[13], t[8] = r, t[9] = n, t[11] = e[14], t[12] = s, t[13] = o, t[14] = i;
|
|
29
|
+
} else
|
|
30
|
+
t[0] = e[0], t[1] = e[4], t[2] = e[8], t[3] = e[12], t[4] = e[1], t[5] = e[5], t[6] = e[9], t[7] = e[13], t[8] = e[2], t[9] = e[6], t[10] = e[10], t[11] = e[14], t[12] = e[3], t[13] = e[7], t[14] = e[11], t[15] = e[15];
|
|
31
|
+
return t;
|
|
32
|
+
}
|
|
33
|
+
function Qa(t, e) {
|
|
34
|
+
var a = e[0], r = e[1], s = e[2], n = e[3], o = e[4], i = e[5], c = e[6], l = e[7], u = e[8], h = e[9], f = e[10], m = e[11], g = e[12], p = e[13], T = e[14], b = e[15], A = a * i - r * o, M = a * c - s * o, x = a * l - n * o, P = r * c - s * i, v = r * l - n * i, w = s * l - n * c, d = u * p - h * g, S = u * T - f * g, _ = u * b - m * g, I = h * T - f * p, C = h * b - m * p, F = f * b - m * T, R = A * F - M * C + x * I + P * _ - v * S + w * d;
|
|
35
|
+
return R ? (R = 1 / R, t[0] = (i * F - c * C + l * I) * R, t[1] = (s * C - r * F - n * I) * R, t[2] = (p * w - T * v + b * P) * R, t[3] = (f * v - h * w - m * P) * R, t[4] = (c * _ - o * F - l * S) * R, t[5] = (a * F - s * _ + n * S) * R, t[6] = (T * x - g * w - b * M) * R, t[7] = (u * w - f * x + m * M) * R, t[8] = (o * C - i * _ + l * d) * R, t[9] = (r * _ - a * C - n * d) * R, t[10] = (g * v - p * x + b * A) * R, t[11] = (h * x - u * v - m * A) * R, t[12] = (i * S - o * I - c * d) * R, t[13] = (a * I - r * S + s * d) * R, t[14] = (p * M - g * P - T * A) * R, t[15] = (u * P - h * M + f * A) * R, t) : null;
|
|
36
|
+
}
|
|
37
|
+
function Ft() {
|
|
38
|
+
var t = new Tt(3);
|
|
39
|
+
return Tt != Float32Array && (t[0] = 0, t[1] = 0, t[2] = 0), t;
|
|
40
|
+
}
|
|
41
|
+
function js(t) {
|
|
42
|
+
var e = t[0], a = t[1], r = t[2];
|
|
43
|
+
return Math.hypot(e, a, r);
|
|
44
|
+
}
|
|
45
|
+
function Te(t, e, a) {
|
|
46
|
+
var r = new Tt(3);
|
|
47
|
+
return r[0] = t, r[1] = e, r[2] = a, r;
|
|
48
|
+
}
|
|
49
|
+
function tr(t, e) {
|
|
50
|
+
return t[0] = e[0], t[1] = e[1], t[2] = e[2], t;
|
|
51
|
+
}
|
|
52
|
+
function dt(t, e, a, r) {
|
|
53
|
+
return t[0] = e, t[1] = a, t[2] = r, t;
|
|
54
|
+
}
|
|
55
|
+
function qs(t, e) {
|
|
56
|
+
var a = e[0] - t[0], r = e[1] - t[1], s = e[2] - t[2];
|
|
57
|
+
return Math.hypot(a, r, s);
|
|
58
|
+
}
|
|
59
|
+
function pe(t, e) {
|
|
60
|
+
var a = e[0], r = e[1], s = e[2], n = a * a + r * r + s * s;
|
|
61
|
+
return n > 0 && (n = 1 / Math.sqrt(n)), t[0] = e[0] * n, t[1] = e[1] * n, t[2] = e[2] * n, t;
|
|
62
|
+
}
|
|
63
|
+
function Or(t, e) {
|
|
64
|
+
return t[0] * e[0] + t[1] * e[1] + t[2] * e[2];
|
|
65
|
+
}
|
|
66
|
+
function Ze(t, e, a) {
|
|
67
|
+
var r = e[0], s = e[1], n = e[2], o = a[0], i = a[1], c = a[2];
|
|
68
|
+
return t[0] = s * c - n * i, t[1] = n * o - r * c, t[2] = r * i - s * o, t;
|
|
69
|
+
}
|
|
70
|
+
function Wt(t, e, a) {
|
|
71
|
+
var r = e[0], s = e[1], n = e[2], o = a[3] * r + a[7] * s + a[11] * n + a[15];
|
|
72
|
+
return o = o || 1, t[0] = (a[0] * r + a[4] * s + a[8] * n + a[12]) / o, t[1] = (a[1] * r + a[5] * s + a[9] * n + a[13]) / o, t[2] = (a[2] * r + a[6] * s + a[10] * n + a[14]) / o, t;
|
|
73
|
+
}
|
|
74
|
+
var Xs = js;
|
|
75
|
+
(function() {
|
|
76
|
+
var t = Ft();
|
|
77
|
+
return function(e, a, r, s, n, o) {
|
|
78
|
+
var i, c;
|
|
79
|
+
for (a || (a = 3), r || (r = 0), s ? c = Math.min(s * a + r, e.length) : c = e.length, i = r; i < c; i += a)
|
|
80
|
+
t[0] = e[i], t[1] = e[i + 1], t[2] = e[i + 2], n(t, t, o), e[i] = t[0], e[i + 1] = t[1], e[i + 2] = t[2];
|
|
81
|
+
return e;
|
|
82
|
+
};
|
|
83
|
+
})();
|
|
84
|
+
function Ks() {
|
|
85
|
+
var t = new Tt(4);
|
|
86
|
+
return Tt != Float32Array && (t[0] = 0, t[1] = 0, t[2] = 0, t[3] = 0), t;
|
|
87
|
+
}
|
|
88
|
+
function Zs(t, e) {
|
|
89
|
+
var a = e[0], r = e[1], s = e[2], n = e[3], o = a * a + r * r + s * s + n * n;
|
|
90
|
+
return o > 0 && (o = 1 / Math.sqrt(o)), t[0] = a * o, t[1] = r * o, t[2] = s * o, t[3] = n * o, t;
|
|
91
|
+
}
|
|
92
|
+
(function() {
|
|
93
|
+
var t = Ks();
|
|
94
|
+
return function(e, a, r, s, n, o) {
|
|
95
|
+
var i, c;
|
|
96
|
+
for (a || (a = 4), r || (r = 0), s ? c = Math.min(s * a + r, e.length) : c = e.length, i = r; i < c; i += a)
|
|
97
|
+
t[0] = e[i], t[1] = e[i + 1], t[2] = e[i + 2], t[3] = e[i + 3], n(t, t, o), e[i] = t[0], e[i + 1] = t[1], e[i + 2] = t[2], e[i + 3] = t[3];
|
|
98
|
+
return e;
|
|
99
|
+
};
|
|
100
|
+
})();
|
|
101
|
+
function er() {
|
|
102
|
+
var t = new Tt(4);
|
|
103
|
+
return Tt != Float32Array && (t[0] = 0, t[1] = 0, t[2] = 0), t[3] = 1, t;
|
|
104
|
+
}
|
|
105
|
+
function Ne(t, e, a) {
|
|
106
|
+
a = a * 0.5;
|
|
107
|
+
var r = Math.sin(a);
|
|
108
|
+
return t[0] = r * e[0], t[1] = r * e[1], t[2] = r * e[2], t[3] = Math.cos(a), t;
|
|
109
|
+
}
|
|
110
|
+
function Je(t, e, a, r) {
|
|
111
|
+
var s = e[0], n = e[1], o = e[2], i = e[3], c = a[0], l = a[1], u = a[2], h = a[3], f, m, g, p, T;
|
|
112
|
+
return m = s * c + n * l + o * u + i * h, m < 0 && (m = -m, c = -c, l = -l, u = -u, h = -h), 1 - m > $s ? (f = Math.acos(m), g = Math.sin(f), p = Math.sin((1 - r) * f) / g, T = Math.sin(r * f) / g) : (p = 1 - r, T = r), t[0] = p * s + T * c, t[1] = p * n + T * l, t[2] = p * o + T * u, t[3] = p * i + T * h, t;
|
|
113
|
+
}
|
|
114
|
+
function Js(t, e) {
|
|
115
|
+
var a = e[0] + e[4] + e[8], r;
|
|
116
|
+
if (a > 0)
|
|
117
|
+
r = Math.sqrt(a + 1), t[3] = 0.5 * r, r = 0.5 / r, t[0] = (e[5] - e[7]) * r, t[1] = (e[6] - e[2]) * r, t[2] = (e[1] - e[3]) * r;
|
|
118
|
+
else {
|
|
119
|
+
var s = 0;
|
|
120
|
+
e[4] > e[0] && (s = 1), e[8] > e[s * 3 + s] && (s = 2);
|
|
121
|
+
var n = (s + 1) % 3, o = (s + 2) % 3;
|
|
122
|
+
r = Math.sqrt(e[s * 3 + s] - e[n * 3 + n] - e[o * 3 + o] + 1), t[s] = 0.5 * r, r = 0.5 / r, t[3] = (e[n * 3 + o] - e[o * 3 + n]) * r, t[n] = (e[n * 3 + s] + e[s * 3 + n]) * r, t[o] = (e[o * 3 + s] + e[s * 3 + o]) * r;
|
|
123
|
+
}
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
var Gr = Zs;
|
|
127
|
+
(function() {
|
|
128
|
+
var t = Ft(), e = Te(1, 0, 0), a = Te(0, 1, 0);
|
|
129
|
+
return function(r, s, n) {
|
|
130
|
+
var o = Or(s, n);
|
|
131
|
+
return o < -0.999999 ? (Ze(t, e, s), Xs(t) < 1e-6 && Ze(t, a, s), pe(t, t), Ne(r, t, Math.PI), r) : o > 0.999999 ? (r[0] = 0, r[1] = 0, r[2] = 0, r[3] = 1, r) : (Ze(t, s, n), r[0] = t[0], r[1] = t[1], r[2] = t[2], r[3] = 1 + o, Gr(r, r));
|
|
132
|
+
};
|
|
133
|
+
})();
|
|
134
|
+
(function() {
|
|
135
|
+
var t = er(), e = er();
|
|
136
|
+
return function(a, r, s, n, o, i) {
|
|
137
|
+
return Je(t, r, o, i), Je(e, s, n, i), Je(a, t, e, 2 * i * (1 - i)), a;
|
|
138
|
+
};
|
|
139
|
+
})();
|
|
140
|
+
(function() {
|
|
141
|
+
var t = Vs();
|
|
142
|
+
return function(e, a, r, s) {
|
|
143
|
+
return t[0] = r[0], t[3] = r[1], t[6] = r[2], t[1] = s[0], t[4] = s[1], t[7] = s[2], t[2] = -a[0], t[5] = -a[1], t[8] = -a[2], Gr(e, Js(e, t));
|
|
144
|
+
};
|
|
145
|
+
})();
|
|
146
|
+
const Rt = 57, yt = 256, Qs = 1024, tn = 512 * 1024 * 1024, en = 64, Vt = 524288, Ur = 4096, an = 16 + Ur * 16, zr = Vt * Rt * 4, kt = 65535, rn = yt * 4, sn = Vt * 2, Wr = sn * 32, be = 4096, De = 144, nn = be * De, kr = 24, on = 1, cn = kr * 4, ln = 8, hn = ln * 4, ft = 512, gt = 256, ze = 2, un = 128, fn = 80, $r = un, Vr = $r + ze * ft * gt * 4, Yr = Vr + ze * gt, jr = Yr + ze * gt * ft, dn = jr * 4, Ca = 128, mn = 64, pn = 256;
|
|
147
|
+
function qr(t) {
|
|
148
|
+
const e = Math.floor(Number.isFinite(t) ? t : Ca);
|
|
149
|
+
return Math.max(mn, Math.min(pn, e));
|
|
150
|
+
}
|
|
151
|
+
const Xr = 64, ga = 80, bn = 1, yn = 2, Tn = 4, gn = 8, Mn = 16, Sn = 32, An = 64, vn = 128, xn = 256, _n = 32, En = 64, Ji = {
|
|
152
|
+
floatsPerTriangle: Rt,
|
|
153
|
+
maxTextureSlots: yt,
|
|
154
|
+
maxTriangles: Vt,
|
|
155
|
+
sceneTrianglesBufferBytes: zr,
|
|
156
|
+
materialSlotNone: kt,
|
|
157
|
+
tileInfoBufferBytes: Xr,
|
|
158
|
+
bvhNodesBufferBytes: Wr
|
|
159
|
+
}, se = 20, Le = 4096, Pn = Le * se * 4, Rn = {
|
|
160
|
+
texSlot: 0,
|
|
161
|
+
bsdfKind: 1,
|
|
162
|
+
envSlot: 2,
|
|
163
|
+
/** header.w: 0 opaque, >0 MASK cutoff, <0 BLEND (stochastic coverage). */
|
|
164
|
+
alphaMode: 3,
|
|
165
|
+
specularFactor: 4,
|
|
166
|
+
specularColor: 5,
|
|
167
|
+
transmission: 8,
|
|
168
|
+
opacity: 9,
|
|
169
|
+
ior: 10,
|
|
170
|
+
dispersion: 11,
|
|
171
|
+
attenuationColor: 12,
|
|
172
|
+
attenuationDistance: 15,
|
|
173
|
+
clearcoat: 16,
|
|
174
|
+
clearcoatRoughness: 17,
|
|
175
|
+
catcherReflect: 18,
|
|
176
|
+
shadowCatcherCutoff: 19
|
|
177
|
+
}, $ = Rn, Qi = 2, Kr = 3;
|
|
178
|
+
function Fa(t) {
|
|
179
|
+
var a, r;
|
|
180
|
+
if (!t) return !1;
|
|
181
|
+
if (t.shadingModel === "unlit" || ((r = (a = t.properties) == null ? void 0 : a.get) == null ? void 0 : r.call(a, "bsdfKind")) === Kr) return !0;
|
|
182
|
+
const e = t.shaderGraph;
|
|
183
|
+
return Array.isArray(e == null ? void 0 : e.nodes) && e.nodes.some((s) => (s == null ? void 0 : s.type) === "UnlitMasterNode");
|
|
184
|
+
}
|
|
185
|
+
function Cn(t) {
|
|
186
|
+
var r, s, n, o;
|
|
187
|
+
const e = (s = (r = t.properties) == null ? void 0 : r.get) == null ? void 0 : s.call(r, "alphaMode"), a = t.alphaMode ?? (typeof e == "string" ? e : "OPAQUE");
|
|
188
|
+
if (a === "MASK") {
|
|
189
|
+
const i = (o = (n = t.properties) == null ? void 0 : n.get) == null ? void 0 : o.call(n, "alphaCutoff"), c = t.alphaCutoff ?? i, l = typeof c == "number" && Number.isFinite(c) && c > 0 ? c : 0.5;
|
|
190
|
+
return Math.min(l, 1);
|
|
191
|
+
}
|
|
192
|
+
return a === "BLEND" || a === "MULTIPLY" ? -1 : 0;
|
|
193
|
+
}
|
|
194
|
+
let ar = !1;
|
|
195
|
+
function _t(t, e, a, r, s) {
|
|
196
|
+
var o, i;
|
|
197
|
+
const n = (i = (o = t.properties) == null ? void 0 : o.get) == null ? void 0 : i.call(o, e);
|
|
198
|
+
return typeof n != "number" || !Number.isFinite(n) ? a : Math.max(r, Math.min(s, n));
|
|
199
|
+
}
|
|
200
|
+
function rr(t, e, a) {
|
|
201
|
+
var s, n;
|
|
202
|
+
const r = (n = (s = t.properties) == null ? void 0 : s.get) == null ? void 0 : n.call(s, e);
|
|
203
|
+
return r == null || typeof r[0] != "number" ? [a, a, a] : [Number(r[0]), Number(r[1] ?? a), Number(r[2] ?? a)];
|
|
204
|
+
}
|
|
205
|
+
function Fn(t) {
|
|
206
|
+
var r, s, n, o;
|
|
207
|
+
const e = (s = (r = t.properties) == null ? void 0 : r.get) == null ? void 0 : s.call(r, "opacity");
|
|
208
|
+
if (typeof e == "number" && Number.isFinite(e)) return Math.max(0, Math.min(1, e));
|
|
209
|
+
const a = (o = (n = t.properties) == null ? void 0 : n.get) == null ? void 0 : o.call(n, "baseColor");
|
|
210
|
+
return a != null && typeof a[3] == "number" ? Math.max(0, Math.min(1, a[3])) : 1;
|
|
211
|
+
}
|
|
212
|
+
function Zr(t, e) {
|
|
213
|
+
t.fill(0, e, e + se), t[e + $.texSlot] = kt, t[e + $.specularFactor] = 1, t[e + $.specularColor] = 1, t[e + $.specularColor + 1] = 1, t[e + $.specularColor + 2] = 1, t[e + $.opacity] = 1, t[e + $.ior] = 1.5, t[e + $.attenuationColor] = 1, t[e + $.attenuationColor + 1] = 1, t[e + $.attenuationColor + 2] = 1;
|
|
214
|
+
}
|
|
215
|
+
function wn(t, e, a, r) {
|
|
216
|
+
var i, c;
|
|
217
|
+
Zr(t, e), t[e + $.texSlot] = r, t[e + $.alphaMode] = Cn(a);
|
|
218
|
+
const s = (c = (i = a.properties) == null ? void 0 : i.get) == null ? void 0 : c.call(i, "bsdfKind"), n = typeof s == "number" && Number.isFinite(s) ? Math.max(0, Math.min(255, Math.floor(s))) : null;
|
|
219
|
+
t[e + $.bsdfKind] = n !== null && n !== 0 ? n : Fa(a) ? Kr : 0, t[e + $.envSlot] = Math.floor(_t(a, "envSlot", 0, 0, 255)), t[e + $.specularFactor] = _t(a, "specularFactor", 1, 0, 4), t.set(rr(a, "specularColorFactor", 1), e + $.specularColor), t[e + $.transmission] = _t(a, "transmissionFactor", 0, 0, 1), t[e + $.opacity] = Fn(a), t[e + $.ior] = _t(a, "ior", 1.5, 1, 4), t[e + $.dispersion] = _t(a, "dispersionFactor", 0, 0, 10), t.set(rr(a, "attenuationColor", 1), e + $.attenuationColor);
|
|
220
|
+
const o = _t(a, "attenuationDistance", 0, 0, 1 / 0);
|
|
221
|
+
t[e + $.attenuationDistance] = o >= 1e30 ? 0 : o, t[e + $.clearcoat] = _t(a, "clearcoatFactor", 0, 0, 1), t[e + $.clearcoatRoughness] = _t(a, "clearcoatRoughnessFactor", 0, 0, 1), t[e + $.catcherReflect] = _t(a, "catcherReflect", 0, 0, 1), t[e + $.shadowCatcherCutoff] = _t(a, "shadowCatcherCutoff", 0, 0, 1);
|
|
222
|
+
}
|
|
223
|
+
class In {
|
|
224
|
+
constructor() {
|
|
225
|
+
y(this, "data", new Float32Array(Le * se));
|
|
226
|
+
y(this, "indexById", /* @__PURE__ */ new Map());
|
|
227
|
+
y(this, "nextIndex", 1);
|
|
228
|
+
y(this, "transmissive", !1);
|
|
229
|
+
Zr(this.data, 0);
|
|
230
|
+
}
|
|
231
|
+
/** Drops all records but the default one (pooled reuse across scene builds). */
|
|
232
|
+
reset() {
|
|
233
|
+
this.indexById.clear(), this.nextIndex = 1, this.transmissive = !1;
|
|
234
|
+
}
|
|
235
|
+
/** At least one recorded material has transmission > 0. */
|
|
236
|
+
get hasTransmission() {
|
|
237
|
+
return this.transmissive;
|
|
238
|
+
}
|
|
239
|
+
get count() {
|
|
240
|
+
return this.nextIndex;
|
|
241
|
+
}
|
|
242
|
+
/** Byte length of the used records. */
|
|
243
|
+
get byteLength() {
|
|
244
|
+
return this.nextIndex * se * 4;
|
|
245
|
+
}
|
|
246
|
+
getIndex(e, a) {
|
|
247
|
+
const r = typeof e.id == "number" ? e.id : -1;
|
|
248
|
+
if (r < 0) return 0;
|
|
249
|
+
const s = this.indexById.get(r);
|
|
250
|
+
if (s !== void 0) return s;
|
|
251
|
+
if (this.nextIndex >= Le)
|
|
252
|
+
return ar || (ar = !0, console.warn(
|
|
253
|
+
`[PathTracer] More than ${Le - 1} materials; extra materials use the default material in path trace.`
|
|
254
|
+
)), this.indexById.set(r, 0), 0;
|
|
255
|
+
const n = this.nextIndex++;
|
|
256
|
+
this.indexById.set(r, n);
|
|
257
|
+
const o = n * se;
|
|
258
|
+
return wn(this.data, o, e, a), this.data[o + $.transmission] > 0 && (this.transmissive = !0), n;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const Bn = 31, Nn = 8;
|
|
262
|
+
function ce(t, e) {
|
|
263
|
+
const a = Math.floor(Number.isFinite(t) ? t : 0);
|
|
264
|
+
return Math.max(e, Math.min(Bn, a));
|
|
265
|
+
}
|
|
266
|
+
function Ln(t, e) {
|
|
267
|
+
const a = t == null ? void 0 : t.totalBounces;
|
|
268
|
+
if (typeof a == "number" && Number.isFinite(a) && a > 0) {
|
|
269
|
+
const s = ce(a, 1), n = Math.min(s, ce((t == null ? void 0 : t.diffuseBounces) ?? s, 0)), o = Math.min(s, ce((t == null ? void 0 : t.glossyBounces) ?? s, 0));
|
|
270
|
+
return { diffuse: n, glossy: o, opaque: Math.min(s, n + o), total: s };
|
|
271
|
+
}
|
|
272
|
+
const r = ce(e, 1);
|
|
273
|
+
return {
|
|
274
|
+
diffuse: r,
|
|
275
|
+
glossy: r,
|
|
276
|
+
opaque: r,
|
|
277
|
+
total: ce(r + Nn, 1)
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function Hn(t) {
|
|
281
|
+
return (t.diffuse & 255 | (t.glossy & 255) << 8 | (t.opaque & 255) << 16 | (t.total & 255) << 24) >>> 0;
|
|
282
|
+
}
|
|
283
|
+
let Ma = null, Jr = 0, Qr = null;
|
|
284
|
+
function tc(t) {
|
|
285
|
+
if (!t) {
|
|
286
|
+
Ma = null;
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
Ma = {
|
|
290
|
+
...t,
|
|
291
|
+
...t.bloom ? { bloom: { ...t.bloom } } : {}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function sr() {
|
|
295
|
+
return Ma;
|
|
296
|
+
}
|
|
297
|
+
function ec(t) {
|
|
298
|
+
Qr = t, Jr += 1;
|
|
299
|
+
}
|
|
300
|
+
function Dn() {
|
|
301
|
+
return { serial: Jr, data: Qr };
|
|
302
|
+
}
|
|
303
|
+
const ts = 16, On = 1, es = ts * 4, Qe = 16, Gn = 3, Un = 0.25, as = 8, zn = 0.6, nr = {
|
|
304
|
+
threshold: 4.5,
|
|
305
|
+
glare: 0,
|
|
306
|
+
size: 0,
|
|
307
|
+
numRays: 0,
|
|
308
|
+
rotation: 0
|
|
309
|
+
};
|
|
310
|
+
function Et(t, e) {
|
|
311
|
+
return typeof t == "number" && Number.isFinite(t) ? t : e;
|
|
312
|
+
}
|
|
313
|
+
function rs(t) {
|
|
314
|
+
return 2 ** (Number.isFinite(t) ? t : 0);
|
|
315
|
+
}
|
|
316
|
+
function ac(t) {
|
|
317
|
+
const e = Math.min(1, Math.max(0, t)), a = e <= 31308e-7 ? 12.92 * e : 1.055 * e ** (1 / 2.4) - 0.055;
|
|
318
|
+
return Math.round(Math.min(1, Math.max(0, a)) * 255);
|
|
319
|
+
}
|
|
320
|
+
function rc(t, e) {
|
|
321
|
+
const a = Math.max(0, t), r = Math.max(0, e), s = 0.5 * r;
|
|
322
|
+
if (!(s > 1e-8)) return Math.max(0, a - r);
|
|
323
|
+
const n = Math.max(0, a - r + s) * Math.max(0, a - r + s) / (4 * s);
|
|
324
|
+
return a >= r + s ? a - r : Math.min(n, s);
|
|
325
|
+
}
|
|
326
|
+
const or = [
|
|
327
|
+
0.125,
|
|
328
|
+
0.125,
|
|
329
|
+
0.125,
|
|
330
|
+
0.125,
|
|
331
|
+
0.125,
|
|
332
|
+
0.0625,
|
|
333
|
+
0.0625,
|
|
334
|
+
0.0625,
|
|
335
|
+
0.0625,
|
|
336
|
+
0.03125,
|
|
337
|
+
0.03125,
|
|
338
|
+
0.03125,
|
|
339
|
+
0.03125
|
|
340
|
+
];
|
|
341
|
+
function sc(t) {
|
|
342
|
+
let e = 0, a = 0;
|
|
343
|
+
for (let r = 0; r < or.length; r++) {
|
|
344
|
+
const s = Math.max(0, t[r] ?? 0), n = or[r] / (1 + s);
|
|
345
|
+
e += s * n, a += n;
|
|
346
|
+
}
|
|
347
|
+
return e / Math.max(a, 1e-6);
|
|
348
|
+
}
|
|
349
|
+
function nc(t, e) {
|
|
350
|
+
return Math.max(0, t) / Math.max(1, e);
|
|
351
|
+
}
|
|
352
|
+
function ir(t) {
|
|
353
|
+
return typeof t != "string" || !t.endsWith("-srgb");
|
|
354
|
+
}
|
|
355
|
+
function Wn(t) {
|
|
356
|
+
const o = t * (2.51 * t + 0.03), i = t * (2.43 * t + 0.59) + 0.14;
|
|
357
|
+
return i !== 0 ? o / i : 0;
|
|
358
|
+
}
|
|
359
|
+
function wa(t, e, a) {
|
|
360
|
+
return 0.2126 * t + 0.7152 * e + 0.0722 * a;
|
|
361
|
+
}
|
|
362
|
+
function kn(t) {
|
|
363
|
+
if (t.length === 0) return 0;
|
|
364
|
+
const e = t.slice().sort((a, r) => a - r);
|
|
365
|
+
return e[Math.min(e.length - 1, Math.floor(0.95 * (e.length - 1)))];
|
|
366
|
+
}
|
|
367
|
+
function ta(t, e, a) {
|
|
368
|
+
let r = 0, s = 0, n = 0, o = 0;
|
|
369
|
+
for (let i = 0; i < t.length; i++)
|
|
370
|
+
r = Math.max(r, t[i]), s = Math.max(s, e[i]), t[i] > a && n++, e[i] > a && o++;
|
|
371
|
+
return {
|
|
372
|
+
count: t.length,
|
|
373
|
+
maxLuma: r,
|
|
374
|
+
p95Luma: kn(t),
|
|
375
|
+
maxChannel: s,
|
|
376
|
+
aboveLumaThreshold: n,
|
|
377
|
+
aboveMaxChannel: o
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function oc(t, e, a, r) {
|
|
381
|
+
const s = [], n = [], o = [], i = [], c = [], l = [];
|
|
382
|
+
let u = 0, h = 0, f = 0;
|
|
383
|
+
const m = Math.max(0, Math.min(e * a, Math.floor(t.length / 4)));
|
|
384
|
+
for (let g = 0; g < m; g++) {
|
|
385
|
+
const p = g * 4, T = t[p + 3] ?? 0, b = Math.min(1, Math.max(T, 0));
|
|
386
|
+
let A = t[p] ?? 0, M = t[p + 1] ?? 0, x = t[p + 2] ?? 0;
|
|
387
|
+
b > 1e-6 ? (A /= b, M /= b, x /= b) : (A = 0, M = 0, x = 0);
|
|
388
|
+
const P = wa(A, M, x), v = Math.max(A, M, x), w = Math.min(A, M, x);
|
|
389
|
+
u = Math.max(u, P), P > r && h++, v > r && f++, M >= A && M >= x && M > A * 1.15 && M > x * 1.15 && M > 0.5 ? (s.push(P), n.push(v)) : x >= A && x >= M && x > A * 1.15 && x > M * 1.15 && x > 0.5 ? (o.push(P), i.push(v)) : v > 1.5 && v - w <= 0.15 * v && (c.push(P), l.push(v));
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
width: e,
|
|
393
|
+
height: a,
|
|
394
|
+
threshold: r,
|
|
395
|
+
maxLuma: u,
|
|
396
|
+
aboveLumaThreshold: h,
|
|
397
|
+
aboveMaxChannel: f,
|
|
398
|
+
green: ta(s, n, r),
|
|
399
|
+
blue: ta(o, i, r),
|
|
400
|
+
neutral: ta(c, l, r)
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function $n(t, e) {
|
|
404
|
+
return t > e;
|
|
405
|
+
}
|
|
406
|
+
function Vn(t, e, a) {
|
|
407
|
+
const r = Math.max(1, Math.floor(e));
|
|
408
|
+
return a + t * Math.PI / r;
|
|
409
|
+
}
|
|
410
|
+
const me = {
|
|
411
|
+
exposure: 0,
|
|
412
|
+
contrast: 0,
|
|
413
|
+
saturation: 1,
|
|
414
|
+
colorBalanceMode: 3
|
|
415
|
+
}, Yn = -12, jn = 6;
|
|
416
|
+
function Ia(t) {
|
|
417
|
+
return Number.isFinite(t) ? Math.max(Yn, Math.min(jn, t)) : me.exposure;
|
|
418
|
+
}
|
|
419
|
+
function qn() {
|
|
420
|
+
const t = typeof globalThis < "u" ? globalThis.__W3DTS_PATH_TRACER_CONFIG : void 0, e = t == null ? void 0 : t.exposure, a = t == null ? void 0 : t.contrast, r = t == null ? void 0 : t.saturation, s = t == null ? void 0 : t.colorBalanceMode;
|
|
421
|
+
return {
|
|
422
|
+
exposure: typeof e == "number" && Number.isFinite(e) ? Ia(e) : me.exposure,
|
|
423
|
+
contrast: typeof a == "number" && Number.isFinite(a) ? Math.max(-1, Math.min(1, a)) : me.contrast,
|
|
424
|
+
saturation: typeof r == "number" && Number.isFinite(r) ? Math.max(0, Math.min(2, r)) : me.saturation,
|
|
425
|
+
colorBalanceMode: typeof s == "number" && Number.isFinite(s) ? Math.max(0, Math.min(3, Math.floor(s))) : me.colorBalanceMode
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function Xn(t, e, a = qn()) {
|
|
429
|
+
const r = t ?? void 0;
|
|
430
|
+
return Kn(
|
|
431
|
+
{
|
|
432
|
+
...r,
|
|
433
|
+
exposure: typeof (r == null ? void 0 : r.exposure) == "number" ? r.exposure : a.exposure,
|
|
434
|
+
contrast: typeof (r == null ? void 0 : r.contrast) == "number" ? r.contrast : a.contrast,
|
|
435
|
+
saturation: typeof (r == null ? void 0 : r.saturation) == "number" ? r.saturation : a.saturation,
|
|
436
|
+
colorBalanceMode: typeof (r == null ? void 0 : r.colorBalanceMode) == "number" ? r.colorBalanceMode : a.colorBalanceMode
|
|
437
|
+
},
|
|
438
|
+
e
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
function Kn(t, e) {
|
|
442
|
+
const a = t == null ? void 0 : t.bloom, r = e === "Converged" || e === "Denoised", s = a ? Math.max(0, Math.min(as, Math.floor(a.numRays))) : 0, n = a ? Et(a.glare, 0) : 0, o = a ? Et(a.size, 0) : 0, i = (a == null ? void 0 : a.mode) === "pyramid" ? "pyramid" : "glare", u = !!(a && r && s > 0 && n !== 0 && o > 0 && i === "glare") || !!(a && r && i === "pyramid") ? 1 : 0, h = Math.max(1, Math.min(5, Math.floor(Et(a == null ? void 0 : a.levels, 5))));
|
|
443
|
+
return {
|
|
444
|
+
exposureEv: Et(t == null ? void 0 : t.exposure, 0),
|
|
445
|
+
contrast: Et(t == null ? void 0 : t.contrast, 0),
|
|
446
|
+
saturation: Et(t == null ? void 0 : t.saturation, 1),
|
|
447
|
+
colorBalanceMode: Et(t == null ? void 0 : t.colorBalanceMode, 2),
|
|
448
|
+
bloomMix: u,
|
|
449
|
+
bloom: a ? {
|
|
450
|
+
threshold: Et(a.threshold, nr.threshold),
|
|
451
|
+
glare: n,
|
|
452
|
+
size: o,
|
|
453
|
+
numRays: s,
|
|
454
|
+
rotation: Et(a.rotation, 0),
|
|
455
|
+
mode: i,
|
|
456
|
+
intensity: Math.max(0, Et(a.intensity, 1)),
|
|
457
|
+
levels: h
|
|
458
|
+
} : { ...nr, mode: "glare", intensity: 1, levels: 5 }
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function ic(t, e) {
|
|
462
|
+
const a = rs(e.exposureEv), r = e.colorBalanceMode, s = [t[0] * a, t[1] * a, t[2] * a], n = r >= 2.5 ? [...Ls(s)] : [
|
|
463
|
+
ea(s[0], r),
|
|
464
|
+
ea(s[1], r),
|
|
465
|
+
ea(s[2], r)
|
|
466
|
+
], o = Math.max(0, 1 + e.contrast), i = n.map((l) => (l - 0.5) * o + 0.5), c = wa(i[0], i[1], i[2]);
|
|
467
|
+
return i.map((l) => c + (l - c) * e.saturation);
|
|
468
|
+
}
|
|
469
|
+
function ea(t, e) {
|
|
470
|
+
const a = Math.max(t, 0);
|
|
471
|
+
return e >= 1.5 ? Wn(a * zn) : e >= 0.5 ? a / (1 + a) : Math.min(1, a);
|
|
472
|
+
}
|
|
473
|
+
function Zn(t, e, a = !1) {
|
|
474
|
+
t[0] = rs(e.exposureEv), t[1] = e.contrast, t[2] = e.saturation, t[3] = e.colorBalanceMode, t[4] = e.bloomMix, t[5] = e.bloom.threshold, t[6] = e.bloom.glare, t[7] = e.bloom.size, t[8] = e.bloom.numRays, t[9] = e.bloom.rotation, t[10] = a ? 1 : 0, t[11] = 0, t.length > 14 && (t[12] = e.bloom.mode === "pyramid" ? On : 0, t[13] = Number.isFinite(e.bloom.intensity) ? e.bloom.intensity : 1, t[14] = Number.isFinite(e.bloom.levels) ? e.bloom.levels : 5, t[15] = 0);
|
|
475
|
+
}
|
|
476
|
+
function Jn(t, e, a, r, s, n) {
|
|
477
|
+
if (r < 0 || s < 0 || r >= e || s >= a) return null;
|
|
478
|
+
const o = (s * e + r) * 4, i = t[o + 3] ?? 0, c = Math.min(1, Math.max(i, 0));
|
|
479
|
+
let l = t[o] ?? 0, u = t[o + 1] ?? 0, h = t[o + 2] ?? 0;
|
|
480
|
+
c > 1e-6 ? (l /= c, u /= c, h /= c) : (l = 0, u = 0, h = 0);
|
|
481
|
+
const f = wa(l, u, h);
|
|
482
|
+
if (!$n(f, n)) return null;
|
|
483
|
+
const m = (f - n) / f;
|
|
484
|
+
return [l * m, u * m, h * m];
|
|
485
|
+
}
|
|
486
|
+
function cc(t, e, a, r) {
|
|
487
|
+
const s = new Float32Array(Math.max(0, e * a * 3)), n = Math.max(0, Math.min(as, Math.floor(r.numRays)));
|
|
488
|
+
if (n < 1 || !(r.size > 0) || r.glare === 0 || e < 1 || a < 1) return s;
|
|
489
|
+
const o = r.size * Math.min(e, a);
|
|
490
|
+
for (let i = 0; i < a; i++)
|
|
491
|
+
for (let c = 0; c < e; c++) {
|
|
492
|
+
let l = 0, u = 0, h = 0;
|
|
493
|
+
for (let m = 0; m < n; m++) {
|
|
494
|
+
const g = Vn(m, n, r.rotation), p = Math.cos(g), T = Math.sin(g);
|
|
495
|
+
for (let b = 1; b <= Qe; b++) {
|
|
496
|
+
const A = b / Qe, M = A * o, x = r.glare * Math.exp(-Gn * A) / Qe * Un;
|
|
497
|
+
for (const P of [1, -1]) {
|
|
498
|
+
const v = Math.trunc(P * p * M), w = Math.trunc(P * T * M);
|
|
499
|
+
if (v === 0 && w === 0) continue;
|
|
500
|
+
const d = Jn(t, e, a, c + v, i + w, r.threshold);
|
|
501
|
+
d && (l += d[0] * x, u += d[1] * x, h += d[2] * x);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const f = (i * e + c) * 3;
|
|
506
|
+
s[f] = l, s[f + 1] = u, s[f + 2] = h;
|
|
507
|
+
}
|
|
508
|
+
return s;
|
|
509
|
+
}
|
|
510
|
+
function lc(t, e, a, r = 0.18) {
|
|
511
|
+
const s = Math.min(Math.floor(t.length / 4), Math.max(0, e * a));
|
|
512
|
+
if (s < 1) return 0;
|
|
513
|
+
let n = 0, o = 0;
|
|
514
|
+
for (let l = 0; l < s; l++) {
|
|
515
|
+
const u = l * 4, h = t[u + 3];
|
|
516
|
+
if (!(h > 1e-4) || !Number.isFinite(h)) continue;
|
|
517
|
+
const f = 1 / Math.min(h, 1), m = t[u] * f, g = t[u + 1] * f, p = t[u + 2] * f, T = 0.2126 * m + 0.7152 * g + 0.0722 * p;
|
|
518
|
+
if (!Number.isFinite(T)) continue;
|
|
519
|
+
const b = Math.max(1e-4, Math.min(1e6, T));
|
|
520
|
+
n += Math.log(b), o++;
|
|
521
|
+
}
|
|
522
|
+
if (o === 0) return 0;
|
|
523
|
+
const i = Math.exp(n / o), c = Math.log2(Math.max(1e-4, r) / i);
|
|
524
|
+
return Ia(Math.round(c * 10) / 10);
|
|
525
|
+
}
|
|
526
|
+
function hc(t, e) {
|
|
527
|
+
if (t.length === 0) return null;
|
|
528
|
+
const a = Math.max(
|
|
529
|
+
0.5,
|
|
530
|
+
0.25 * (Number.isFinite(e) && e > 0 ? e : 4)
|
|
531
|
+
), r = 1 / (a * a);
|
|
532
|
+
let s = 0;
|
|
533
|
+
for (const o of t) {
|
|
534
|
+
if (!Number.isFinite(o.intensity) || o.intensity <= 0) continue;
|
|
535
|
+
const i = Number(o.color[0] ?? 1), c = Number(o.color[1] ?? 1), l = Number(o.color[2] ?? 1), u = Math.max(0.05, 0.2126 * i + 0.7152 * c + 0.0722 * l);
|
|
536
|
+
if (o.kind === "directional")
|
|
537
|
+
s += o.intensity * u;
|
|
538
|
+
else if (o.kind === "area") {
|
|
539
|
+
const h = o.area && o.area > 0 ? o.area : 1;
|
|
540
|
+
s += o.intensity * u * h * r;
|
|
541
|
+
} else
|
|
542
|
+
s += o.intensity * u * r;
|
|
543
|
+
}
|
|
544
|
+
if (!(s > 8)) return null;
|
|
545
|
+
const n = -Math.log2(s / 2.5);
|
|
546
|
+
return Ia(Math.round(n * 10) / 10);
|
|
547
|
+
}
|
|
548
|
+
const Qn = [
|
|
549
|
+
"BloomDown0",
|
|
550
|
+
"BloomDown1",
|
|
551
|
+
"BloomDown2",
|
|
552
|
+
"BloomDown3",
|
|
553
|
+
"BloomDown4",
|
|
554
|
+
"BloomUp3",
|
|
555
|
+
"BloomUp2",
|
|
556
|
+
"BloomUp1",
|
|
557
|
+
"BloomUp0",
|
|
558
|
+
"BloomComposite"
|
|
559
|
+
], aa = [0.5, 0.25, 0.125, 0.0625, 0.03125];
|
|
560
|
+
function cr(t, e, a) {
|
|
561
|
+
return {
|
|
562
|
+
name: t,
|
|
563
|
+
type: "texture",
|
|
564
|
+
format: "rgba16float",
|
|
565
|
+
sizeType: "relative",
|
|
566
|
+
width: e,
|
|
567
|
+
height: e,
|
|
568
|
+
relativeSizeRef: a,
|
|
569
|
+
usage: 12
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function le(t, e, a, r) {
|
|
573
|
+
return {
|
|
574
|
+
name: `BloomDown${t}`,
|
|
575
|
+
type: "compute",
|
|
576
|
+
shaderPath: "/shaders/path-tracer/pt_bloom_down.compute.wgsl",
|
|
577
|
+
entryPoint: "main",
|
|
578
|
+
dispatchMode: "auto",
|
|
579
|
+
workgroupSize: [8, 8, 1],
|
|
580
|
+
dispatchTextureHandle: a,
|
|
581
|
+
constants: { PREFILTER: r ? 1 : 0, LEVEL: t },
|
|
582
|
+
bufferBindings: {
|
|
583
|
+
0: { handle: "pathTracerPostParams", type: "read-only-storage" }
|
|
584
|
+
},
|
|
585
|
+
textureBindings: {
|
|
586
|
+
1: { handle: e, access: "read", format: "rgba16float" },
|
|
587
|
+
2: { handle: a, access: "write", format: "rgba16float" }
|
|
588
|
+
},
|
|
589
|
+
inputs: [e],
|
|
590
|
+
outputs: [a]
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function he(t, e, a, r, s, n) {
|
|
594
|
+
return {
|
|
595
|
+
name: t,
|
|
596
|
+
type: "compute",
|
|
597
|
+
shaderPath: "/shaders/path-tracer/pt_bloom_up.compute.wgsl",
|
|
598
|
+
entryPoint: "main",
|
|
599
|
+
dispatchMode: "auto",
|
|
600
|
+
workgroupSize: [8, 8, 1],
|
|
601
|
+
dispatchTextureHandle: r,
|
|
602
|
+
constants: { LEVEL: s, COMPOSITE: n ? 1 : 0 },
|
|
603
|
+
bufferBindings: {
|
|
604
|
+
0: { handle: "pathTracerPostParams", type: "read-only-storage" }
|
|
605
|
+
},
|
|
606
|
+
textureBindings: {
|
|
607
|
+
1: { handle: e, access: "read", format: "rgba16float" },
|
|
608
|
+
2: { handle: a, access: "read", format: "rgba16float" },
|
|
609
|
+
3: { handle: r, access: "write", format: "rgba16float" }
|
|
610
|
+
},
|
|
611
|
+
inputs: [e, a],
|
|
612
|
+
outputs: [r]
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function lr(t) {
|
|
616
|
+
const e = t.relativeSizeRef ?? "graph", a = [
|
|
617
|
+
{
|
|
618
|
+
name: "pathTracerPostParams",
|
|
619
|
+
type: "buffer",
|
|
620
|
+
sizeType: "fixed",
|
|
621
|
+
size: es,
|
|
622
|
+
usage: 136
|
|
623
|
+
}
|
|
624
|
+
];
|
|
625
|
+
for (let s = 0; s < aa.length; s++)
|
|
626
|
+
a.push(cr(`bloomMip${s}`, aa[s], e));
|
|
627
|
+
for (let s = 0; s < 4; s++)
|
|
628
|
+
a.push(cr(`bloomAcc${s}`, aa[s], e));
|
|
629
|
+
const r = [
|
|
630
|
+
le(0, t.input, "bloomMip0", !0),
|
|
631
|
+
le(1, "bloomMip0", "bloomMip1", !1),
|
|
632
|
+
le(2, "bloomMip1", "bloomMip2", !1),
|
|
633
|
+
le(3, "bloomMip2", "bloomMip3", !1),
|
|
634
|
+
le(4, "bloomMip3", "bloomMip4", !1),
|
|
635
|
+
he("BloomUp3", "bloomMip4", "bloomMip3", "bloomAcc3", 3, !1),
|
|
636
|
+
he("BloomUp2", "bloomAcc3", "bloomMip2", "bloomAcc2", 2, !1),
|
|
637
|
+
he("BloomUp1", "bloomAcc2", "bloomMip1", "bloomAcc1", 1, !1),
|
|
638
|
+
he("BloomUp0", "bloomAcc1", "bloomMip0", "bloomAcc0", 0, !1),
|
|
639
|
+
he("BloomComposite", "bloomAcc0", "bloomAcc0", t.output, 0, !0)
|
|
640
|
+
];
|
|
641
|
+
return { resources: a, passes: r };
|
|
642
|
+
}
|
|
643
|
+
function to(t, e, a, r, s, n, o) {
|
|
644
|
+
const i = (l) => 1 / Math.max(l, 1e-20), c = (o == null ? void 0 : o.length) === 16 ? o : new Float32Array(16);
|
|
645
|
+
return c[0] = t * i(s), c[1] = e * i(n), c[2] = 0.5 * t * i(s) - 0.5, c[3] = 0.5 * e * i(n) - 0.5, c[4] = i(a), c[5] = i(r), c[6] = 1 * i(a), c[7] = -1 * i(r), c[8] = -1 * i(a), c[9] = 2 * i(r), c[10] = 1 * i(a), c[11] = 2 * i(r), c[12] = 0 * i(a), c[13] = 4 * i(r), c[14] = 0, c[15] = 0, c;
|
|
646
|
+
}
|
|
647
|
+
const eo = [64, 512];
|
|
648
|
+
class ao {
|
|
649
|
+
constructor(e = {}) {
|
|
650
|
+
y(this, "sppMilestones");
|
|
651
|
+
y(this, "interactiveEwmaAlpha");
|
|
652
|
+
y(this, "sessionStartMs", 0);
|
|
653
|
+
y(this, "started", !1);
|
|
654
|
+
y(this, "lastTickMs", 0);
|
|
655
|
+
y(this, "interactiveUntilMs", 0);
|
|
656
|
+
y(this, "interactiveEwmaMs", 0);
|
|
657
|
+
y(this, "interactiveSampleCount", 0);
|
|
658
|
+
y(this, "timeToFirstSampleMs", null);
|
|
659
|
+
y(this, "timeToFirstFullCoverageMs", null);
|
|
660
|
+
y(this, "timeToConvergedMs", null);
|
|
661
|
+
y(this, "timeToSppMs", /* @__PURE__ */ new Map());
|
|
662
|
+
y(this, "lastSamplesPerSecond", null);
|
|
663
|
+
y(this, "lastAverageSpp", 0);
|
|
664
|
+
y(this, "lastSceneW", 0);
|
|
665
|
+
y(this, "lastSceneH", 0);
|
|
666
|
+
y(this, "lastTotalTiles", 0);
|
|
667
|
+
y(this, "lastMaxSamples", 0);
|
|
668
|
+
y(this, "lastConverged", !1);
|
|
669
|
+
y(this, "lastSamplesDone", 0);
|
|
670
|
+
this.sppMilestones = e.sppMilestones ?? [...eo], this.interactiveEwmaAlpha = e.interactiveEwmaAlpha ?? 0.15;
|
|
671
|
+
for (const a of this.sppMilestones)
|
|
672
|
+
this.timeToSppMs.set(a, null);
|
|
673
|
+
}
|
|
674
|
+
/** Begin (or restart) a measurement session. */
|
|
675
|
+
start(e) {
|
|
676
|
+
this.sessionStartMs = e, this.started = !0, this.lastTickMs = e, this.interactiveUntilMs = 0, this.interactiveEwmaMs = 0, this.interactiveSampleCount = 0, this.timeToFirstSampleMs = null, this.timeToFirstFullCoverageMs = null, this.timeToConvergedMs = null, this.lastSamplesPerSecond = null, this.lastAverageSpp = 0, this.lastConverged = !1, this.lastSamplesDone = 0, this.timeToSppMs.clear();
|
|
677
|
+
for (const a of this.sppMilestones)
|
|
678
|
+
this.timeToSppMs.set(a, null);
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Mark the next ~250 ms of ticks as interactive (camera / scene motion).
|
|
682
|
+
* Used for {@link PathTracerBaselineReport.interactiveMsPerFrame}.
|
|
683
|
+
*/
|
|
684
|
+
markInteractive(e, a = 250) {
|
|
685
|
+
this.interactiveUntilMs = Math.max(this.interactiveUntilMs, e + a);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Ingest one progress snapshot. Resets the session automatically when `samplesDone`
|
|
689
|
+
* drops relative to the previous tick (accumulation reset).
|
|
690
|
+
*/
|
|
691
|
+
tick(e, a) {
|
|
692
|
+
if (!e)
|
|
693
|
+
return this.report();
|
|
694
|
+
this.started || this.start(a), (e.samplesDone < this.lastSamplesDone || this.lastSamplesDone > 0 && e.samplesDone === 0) && this.start(a), this.lastSamplesDone = e.samplesDone;
|
|
695
|
+
const r = Math.max(0, a - this.sessionStartMs), s = Math.max(0, a - this.lastTickMs);
|
|
696
|
+
this.lastTickMs = a, a < this.interactiveUntilMs && s > 0 && s < 2e3 && (this.interactiveSampleCount += 1, this.interactiveEwmaMs = this.interactiveSampleCount === 1 ? s : this.interactiveEwmaMs * (1 - this.interactiveEwmaAlpha) + s * this.interactiveEwmaAlpha), this.lastSceneW = e.sceneWidth, this.lastSceneH = e.sceneHeight, this.lastTotalTiles = e.totalTiles, this.lastMaxSamples = e.maxSamples, this.lastConverged = e.converged, e.samplesPerSecond !== void 0 && e.samplesPerSecond > 0 && (this.lastSamplesPerSecond = e.samplesPerSecond);
|
|
697
|
+
const n = Math.max(1, e.totalTiles), o = e.samplesDone / n;
|
|
698
|
+
this.lastAverageSpp = o, this.timeToFirstSampleMs === null && e.samplesDone > 0 && e.accumFrameIndex >= 1 && (this.timeToFirstSampleMs = r);
|
|
699
|
+
const i = e.converged || e.totalTiles > 0 && e.tileIndex >= e.totalTiles - 1 && e.accumFrameIndex >= 1;
|
|
700
|
+
this.timeToFirstFullCoverageMs === null && i && (this.timeToFirstFullCoverageMs = r), this.timeToConvergedMs === null && e.converged && (this.timeToConvergedMs = r);
|
|
701
|
+
for (const c of this.sppMilestones)
|
|
702
|
+
this.timeToSppMs.get(c) == null && o >= c && this.timeToSppMs.set(c, r);
|
|
703
|
+
return this.report();
|
|
704
|
+
}
|
|
705
|
+
report() {
|
|
706
|
+
const e = {};
|
|
707
|
+
for (const a of this.sppMilestones)
|
|
708
|
+
e[a] = this.timeToSppMs.get(a) ?? null;
|
|
709
|
+
return {
|
|
710
|
+
timeToFirstSampleMs: this.timeToFirstSampleMs,
|
|
711
|
+
timeToFirstFullCoverageMs: this.timeToFirstFullCoverageMs,
|
|
712
|
+
timeToConvergedMs: this.timeToConvergedMs,
|
|
713
|
+
interactiveMsPerFrame: this.interactiveSampleCount > 0 ? this.interactiveEwmaMs : null,
|
|
714
|
+
samplesPerSecond: this.lastSamplesPerSecond,
|
|
715
|
+
averageSpp: this.lastAverageSpp,
|
|
716
|
+
timeToSppMs: e,
|
|
717
|
+
sceneWidth: this.lastSceneW,
|
|
718
|
+
sceneHeight: this.lastSceneH,
|
|
719
|
+
totalTiles: this.lastTotalTiles,
|
|
720
|
+
maxSamples: this.lastMaxSamples,
|
|
721
|
+
converged: this.lastConverged
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
/** JSON-serializable report for clipboard / HUD / baseline files. */
|
|
725
|
+
toJSON() {
|
|
726
|
+
return this.report();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function uc(t) {
|
|
730
|
+
const e = (r, s = 1) => r == null || !Number.isFinite(r) ? "—" : `${r.toFixed(s)} ms`, a = [
|
|
731
|
+
`Path tracer baseline (${t.sceneWidth}×${t.sceneHeight}, ${t.totalTiles} tiles, maxSamples=${t.maxSamples})`,
|
|
732
|
+
` timeToFirstSample: ${e(t.timeToFirstSampleMs)}`,
|
|
733
|
+
` timeToFirstFullCoverage: ${e(t.timeToFirstFullCoverageMs)}`,
|
|
734
|
+
` timeToConverged: ${e(t.timeToConvergedMs)}`,
|
|
735
|
+
` interactiveMs/frame: ${e(t.interactiveMsPerFrame)}`,
|
|
736
|
+
` samplesPerSecond: ${t.samplesPerSecond == null ? "—" : t.samplesPerSecond.toFixed(1)}`,
|
|
737
|
+
` averageSpp: ${t.averageSpp.toFixed(2)}`
|
|
738
|
+
];
|
|
739
|
+
for (const [r, s] of Object.entries(t.timeToSppMs))
|
|
740
|
+
a.push(` timeTo${r}spp: ${e(s ?? null)}`);
|
|
741
|
+
return a.push(` converged: ${t.converged}`), a.join(`
|
|
742
|
+
`);
|
|
743
|
+
}
|
|
744
|
+
const fc = 4294967295, ss = 2147483648, hr = 4, st = 16, ro = 4294967294;
|
|
745
|
+
function so(t) {
|
|
746
|
+
return (ss | t & 2147483647) >>> 0;
|
|
747
|
+
}
|
|
748
|
+
function no(t) {
|
|
749
|
+
return (t & ss) !== 0 && t !== ro;
|
|
750
|
+
}
|
|
751
|
+
const Sa = 32, oo = 1;
|
|
752
|
+
function ra(t, e, a, r, s, n) {
|
|
753
|
+
const o = Math.max(0, r - t), i = Math.max(0, s - e), c = Math.max(0, n - a);
|
|
754
|
+
return 2 * (o * i + i * c + c * o);
|
|
755
|
+
}
|
|
756
|
+
function ur(t, e, a, r) {
|
|
757
|
+
const s = e * Sa, n = new DataView(t);
|
|
758
|
+
a[0] = n.getFloat32(s, !0), a[1] = n.getFloat32(s + 4, !0), a[2] = n.getFloat32(s + 8, !0), r[0] = n.getFloat32(s + 16, !0), r[1] = n.getFloat32(s + 20, !0), r[2] = n.getFloat32(s + 24, !0);
|
|
759
|
+
}
|
|
760
|
+
function ns(t, e) {
|
|
761
|
+
if (e <= 0) return null;
|
|
762
|
+
const a = Rt, r = new Array(e);
|
|
763
|
+
for (let d = 0; d < e; d++) {
|
|
764
|
+
const S = d * a;
|
|
765
|
+
let _ = 1 / 0, I = 1 / 0, C = 1 / 0, F = -1 / 0, R = -1 / 0, B = -1 / 0;
|
|
766
|
+
for (let H = 0; H < 3; H++) {
|
|
767
|
+
const L = S + H * 3, Q = t[L], tt = t[L + 1], W = t[L + 2];
|
|
768
|
+
_ = Math.min(_, Q), I = Math.min(I, tt), C = Math.min(C, W), F = Math.max(F, Q), R = Math.max(R, tt), B = Math.max(B, W);
|
|
769
|
+
}
|
|
770
|
+
r[d] = {
|
|
771
|
+
oldIndex: d,
|
|
772
|
+
minX: _,
|
|
773
|
+
minY: I,
|
|
774
|
+
minZ: C,
|
|
775
|
+
maxX: F,
|
|
776
|
+
maxY: R,
|
|
777
|
+
maxZ: B,
|
|
778
|
+
cx: (_ + F) * 0.5,
|
|
779
|
+
cy: (I + R) * 0.5,
|
|
780
|
+
cz: (C + B) * 0.5
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
const s = Math.max(1, e * 2), n = new ArrayBuffer(s * Sa), o = new DataView(n);
|
|
784
|
+
let i = 0;
|
|
785
|
+
const c = new Uint32Array(e), l = new Float32Array(3), u = new Float32Array(3), h = new Float32Array(3), f = new Float32Array(3);
|
|
786
|
+
function m(d, S, _, I, C, F, R, B) {
|
|
787
|
+
const H = i++, L = H * Sa;
|
|
788
|
+
return o.setFloat32(L, d, !0), o.setFloat32(L + 4, S, !0), o.setFloat32(L + 8, _, !0), o.setUint32(L + 12, R >>> 0, !0), o.setFloat32(L + 16, I, !0), o.setFloat32(L + 20, C, !0), o.setFloat32(L + 24, F, !0), o.setUint32(L + 28, B >>> 0, !0), H;
|
|
789
|
+
}
|
|
790
|
+
function g(d, S) {
|
|
791
|
+
let _ = 1 / 0, I = 1 / 0, C = 1 / 0, F = -1 / 0, R = -1 / 0, B = -1 / 0;
|
|
792
|
+
for (let H = d; H < S; H++) {
|
|
793
|
+
const L = r[H];
|
|
794
|
+
_ = Math.min(_, L.minX), I = Math.min(I, L.minY), C = Math.min(C, L.minZ), F = Math.max(F, L.maxX), R = Math.max(R, L.maxY), B = Math.max(B, L.maxZ);
|
|
795
|
+
}
|
|
796
|
+
return [_, I, C, F, R, B];
|
|
797
|
+
}
|
|
798
|
+
function p(d, S) {
|
|
799
|
+
return S === 0 ? d.cx : S === 1 ? d.cy : d.cz;
|
|
800
|
+
}
|
|
801
|
+
function T(d, S) {
|
|
802
|
+
const [_, I, C, F, R, B] = g(d, S), H = ra(_, I, C, F, R, B);
|
|
803
|
+
if (H <= 1e-20) return null;
|
|
804
|
+
let L = null;
|
|
805
|
+
for (let Q = 0; Q < 3; Q++) {
|
|
806
|
+
let tt = 1 / 0, W = -1 / 0;
|
|
807
|
+
for (let O = d; O < S; O++) {
|
|
808
|
+
const nt = p(r[O], Q);
|
|
809
|
+
tt = Math.min(tt, nt), W = Math.max(W, nt);
|
|
810
|
+
}
|
|
811
|
+
const z = W - tt;
|
|
812
|
+
if (z < 1e-12) continue;
|
|
813
|
+
const V = new Int32Array(st), D = new Float32Array(st), et = new Float32Array(st), Z = new Float32Array(st), k = new Float32Array(st), wt = new Float32Array(st), lt = new Float32Array(st);
|
|
814
|
+
D.fill(1 / 0), et.fill(1 / 0), Z.fill(1 / 0), k.fill(-1 / 0), wt.fill(-1 / 0), lt.fill(-1 / 0);
|
|
815
|
+
for (let O = d; O < S; O++) {
|
|
816
|
+
const nt = r[O];
|
|
817
|
+
let j = Math.floor((p(nt, Q) - tt) / z * st);
|
|
818
|
+
j < 0 && (j = 0), j >= st && (j = st - 1), V[j] += 1, D[j] = Math.min(D[j], nt.minX), et[j] = Math.min(et[j], nt.minY), Z[j] = Math.min(Z[j], nt.minZ), k[j] = Math.max(k[j], nt.maxX), wt[j] = Math.max(wt[j], nt.maxY), lt[j] = Math.max(lt[j], nt.maxZ);
|
|
819
|
+
}
|
|
820
|
+
let Yt = 0, E = 1 / 0, jt = 1 / 0, ne = 1 / 0, Gt = -1 / 0, qt = -1 / 0, ot = -1 / 0;
|
|
821
|
+
const ct = new Int32Array(st), Ut = new Float32Array(st);
|
|
822
|
+
for (let O = 0; O < st; O++)
|
|
823
|
+
V[O] > 0 && (Yt += V[O], E = Math.min(E, D[O]), jt = Math.min(jt, et[O]), ne = Math.min(ne, Z[O]), Gt = Math.max(Gt, k[O]), qt = Math.max(qt, wt[O]), ot = Math.max(ot, lt[O])), ct[O] = Yt, Ut[O] = Yt > 0 ? ra(E, jt, ne, Gt, qt, ot) : 0;
|
|
824
|
+
let Xt = 0, It = 1 / 0, Y = 1 / 0, at = 1 / 0, J = -1 / 0, Bt = -1 / 0, Nt = -1 / 0;
|
|
825
|
+
for (let O = st - 1; O >= 1; O--) {
|
|
826
|
+
V[O] > 0 && (Xt += V[O], It = Math.min(It, D[O]), Y = Math.min(Y, et[O]), at = Math.min(at, Z[O]), J = Math.max(J, k[O]), Bt = Math.max(Bt, wt[O]), Nt = Math.max(Nt, lt[O]));
|
|
827
|
+
const nt = ct[O - 1];
|
|
828
|
+
if (nt === 0 || Xt === 0) continue;
|
|
829
|
+
const j = oo + (nt * Ut[O - 1] + Xt * ra(It, Y, at, J, Bt, Nt)) / H;
|
|
830
|
+
(!L || j < L.cost) && (L = { axis: Q, bin: O, c0: tt, extent: z, cost: j });
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return L;
|
|
834
|
+
}
|
|
835
|
+
function b(d, S) {
|
|
836
|
+
let _ = 1 / 0, I = -1 / 0, C = 1 / 0, F = -1 / 0, R = 1 / 0, B = -1 / 0;
|
|
837
|
+
for (let z = d; z < S; z++) {
|
|
838
|
+
const V = r[z];
|
|
839
|
+
_ = Math.min(_, V.cx), I = Math.max(I, V.cx), C = Math.min(C, V.cy), F = Math.max(F, V.cy), R = Math.min(R, V.cz), B = Math.max(B, V.cz);
|
|
840
|
+
}
|
|
841
|
+
const H = I - _, L = F - C, Q = B - R, tt = L >= H && L >= Q ? 1 : Q >= H && Q >= L ? 2 : 0, W = r.slice(d, S);
|
|
842
|
+
W.sort((z, V) => p(z, tt) - p(V, tt));
|
|
843
|
+
for (let z = 0; z < W.length; z++) r[d + z] = W[z];
|
|
844
|
+
return d + Math.max(1, Math.floor((S - d) / 2));
|
|
845
|
+
}
|
|
846
|
+
function A(d, S, _) {
|
|
847
|
+
let I = d;
|
|
848
|
+
for (let C = d; C < S; C++) {
|
|
849
|
+
let F = Math.floor(
|
|
850
|
+
(p(r[C], _.axis) - _.c0) / _.extent * st
|
|
851
|
+
);
|
|
852
|
+
if (F < 0 && (F = 0), F >= st && (F = st - 1), F < _.bin) {
|
|
853
|
+
const R = r[C];
|
|
854
|
+
r[C] = r[I], r[I] = R, I++;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return I <= d || I >= S ? b(d, S) : I;
|
|
858
|
+
}
|
|
859
|
+
function M(d, S) {
|
|
860
|
+
const _ = S - d, [I, C, F, R, B, H] = g(d, S);
|
|
861
|
+
for (let L = d; L < S; L++) c[L] = r[L].oldIndex;
|
|
862
|
+
return m(I, C, F, R, B, H, so(_), d);
|
|
863
|
+
}
|
|
864
|
+
function x(d, S) {
|
|
865
|
+
const _ = S - d;
|
|
866
|
+
if (_ <= 1) return M(d, S);
|
|
867
|
+
const I = T(d, S);
|
|
868
|
+
if (!I) {
|
|
869
|
+
if (_ <= hr) return M(d, S);
|
|
870
|
+
const B = b(d, S), H = x(d, B), L = x(B, S);
|
|
871
|
+
return P(H, L);
|
|
872
|
+
}
|
|
873
|
+
if (_ <= hr && I.cost >= _) return M(d, S);
|
|
874
|
+
const C = A(d, S, I), F = x(d, C), R = x(C, S);
|
|
875
|
+
return P(F, R);
|
|
876
|
+
}
|
|
877
|
+
function P(d, S) {
|
|
878
|
+
return ur(n, d, l, u), ur(n, S, h, f), m(
|
|
879
|
+
Math.min(l[0], h[0]),
|
|
880
|
+
Math.min(l[1], h[1]),
|
|
881
|
+
Math.min(l[2], h[2]),
|
|
882
|
+
Math.max(u[0], f[0]),
|
|
883
|
+
Math.max(u[1], f[1]),
|
|
884
|
+
Math.max(u[2], f[2]),
|
|
885
|
+
d,
|
|
886
|
+
S
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
const v = x(0, e), w = t.slice(0, e * a);
|
|
890
|
+
for (let d = 0; d < e; d++) {
|
|
891
|
+
const S = c[d] * a;
|
|
892
|
+
t.set(w.subarray(S, S + a), d * a);
|
|
893
|
+
}
|
|
894
|
+
return { nodeCount: i, rootIndex: v, nodes: n, permutation: c };
|
|
895
|
+
}
|
|
896
|
+
const io = 4294967294, ge = 32;
|
|
897
|
+
function Aa(t, e, a, r) {
|
|
898
|
+
const s = e * ge, n = new DataView(t);
|
|
899
|
+
a[0] = n.getFloat32(s, !0), a[1] = n.getFloat32(s + 4, !0), a[2] = n.getFloat32(s + 8, !0), r[0] = n.getFloat32(s + 16, !0), r[1] = n.getFloat32(s + 20, !0), r[2] = n.getFloat32(s + 24, !0);
|
|
900
|
+
}
|
|
901
|
+
function co(t, e, a, r, s) {
|
|
902
|
+
const n = t;
|
|
903
|
+
r[0] = 1 / 0, r[1] = 1 / 0, r[2] = 1 / 0, s[0] = -1 / 0, s[1] = -1 / 0, s[2] = -1 / 0;
|
|
904
|
+
const o = Ft();
|
|
905
|
+
for (let i = 0; i < 8; i++)
|
|
906
|
+
o[0] = i & 1 ? a[0] : e[0], o[1] = i & 2 ? a[1] : e[1], o[2] = i & 4 ? a[2] : e[2], Wt(o, o, n), r[0] = Math.min(r[0], o[0]), r[1] = Math.min(r[1], o[1]), r[2] = Math.min(r[2], o[2]), s[0] = Math.max(s[0], o[0]), s[1] = Math.max(s[1], o[1]), s[2] = Math.max(s[2], o[2]);
|
|
907
|
+
}
|
|
908
|
+
function lo(t, e, a, r) {
|
|
909
|
+
const s = new DataView(a.nodes), n = new DataView(t);
|
|
910
|
+
for (let o = 0; o < a.nodeCount; o++) {
|
|
911
|
+
const i = o * ge, c = (e + o) * ge;
|
|
912
|
+
n.setFloat32(c, s.getFloat32(i, !0), !0), n.setFloat32(c + 4, s.getFloat32(i + 4, !0), !0), n.setFloat32(c + 8, s.getFloat32(i + 8, !0), !0), n.setFloat32(c + 16, s.getFloat32(i + 16, !0), !0), n.setFloat32(c + 20, s.getFloat32(i + 20, !0), !0), n.setFloat32(c + 24, s.getFloat32(i + 24, !0), !0);
|
|
913
|
+
const l = s.getUint32(i + 12, !0), u = s.getUint32(i + 28, !0);
|
|
914
|
+
no(l) ? (n.setUint32(c + 12, l >>> 0, !0), n.setUint32(c + 28, u + r >>> 0, !0)) : (n.setUint32(c + 12, l + e >>> 0, !0), n.setUint32(c + 28, u + e >>> 0, !0));
|
|
915
|
+
}
|
|
916
|
+
return e + a.nodeCount;
|
|
917
|
+
}
|
|
918
|
+
function ho(t, e, a) {
|
|
919
|
+
const r = t.length;
|
|
920
|
+
if (r <= 0) return null;
|
|
921
|
+
const s = new Float32Array(r * 3);
|
|
922
|
+
for (let b = 0; b < r; b++) {
|
|
923
|
+
const A = t[b];
|
|
924
|
+
s[b * 3] = (A.worldMin[0] + A.worldMax[0]) * 0.5, s[b * 3 + 1] = (A.worldMin[1] + A.worldMax[1]) * 0.5, s[b * 3 + 2] = (A.worldMin[2] + A.worldMax[2]) * 0.5;
|
|
925
|
+
}
|
|
926
|
+
const n = new DataView(e);
|
|
927
|
+
let o = 0;
|
|
928
|
+
const i = new Float32Array(3), c = new Float32Array(3), l = new Float32Array(3), u = new Float32Array(3), h = new Float32Array(3), f = new Float32Array(3);
|
|
929
|
+
function m(b, A, M, x) {
|
|
930
|
+
if (o >= a) return 0;
|
|
931
|
+
const P = o++, v = P * ge;
|
|
932
|
+
return n.setFloat32(v, b[0], !0), n.setFloat32(v + 4, b[1], !0), n.setFloat32(v + 8, b[2], !0), n.setUint32(v + 12, M >>> 0, !0), n.setFloat32(v + 16, A[0], !0), n.setFloat32(v + 20, A[1], !0), n.setFloat32(v + 24, A[2], !0), n.setUint32(v + 28, x >>> 0, !0), P;
|
|
933
|
+
}
|
|
934
|
+
function g(b) {
|
|
935
|
+
if (b.length === 1) {
|
|
936
|
+
const F = b[0], R = t[F];
|
|
937
|
+
return m(R.worldMin, R.worldMax, io, F);
|
|
938
|
+
}
|
|
939
|
+
let A = 0, M = 0, x = 0;
|
|
940
|
+
for (const F of b)
|
|
941
|
+
A += s[F * 3], M += s[F * 3 + 1], x += s[F * 3 + 2];
|
|
942
|
+
const P = 1 / b.length;
|
|
943
|
+
A *= P, M *= P, x *= P;
|
|
944
|
+
let v = 0, w = 0, d = 0;
|
|
945
|
+
for (const F of b) {
|
|
946
|
+
const R = s[F * 3] - A, B = s[F * 3 + 1] - M, H = s[F * 3 + 2] - x;
|
|
947
|
+
v += R * R, w += B * B, d += H * H;
|
|
948
|
+
}
|
|
949
|
+
let S = 0;
|
|
950
|
+
w >= v && w >= d ? S = 1 : d >= v && d >= w && (S = 2), b.sort((F, R) => s[F * 3 + S] - s[R * 3 + S]);
|
|
951
|
+
const _ = Math.max(1, Math.floor(b.length / 2)), I = g(b.slice(0, _)), C = g(b.slice(_));
|
|
952
|
+
return Aa(e, I, l, u), Aa(e, C, h, f), i[0] = Math.min(l[0], h[0]), i[1] = Math.min(l[1], h[1]), i[2] = Math.min(l[2], h[2]), c[0] = Math.max(u[0], f[0]), c[1] = Math.max(u[1], f[1]), c[2] = Math.max(u[2], f[2]), m(i, c, I, C);
|
|
953
|
+
}
|
|
954
|
+
const p = Array.from({ length: r }, (b, A) => A), T = g(p);
|
|
955
|
+
return { nodeCount: o, rootIndex: T, nodes: e };
|
|
956
|
+
}
|
|
957
|
+
function uo(t) {
|
|
958
|
+
const e = new ArrayBuffer(t.length * De), a = new DataView(e);
|
|
959
|
+
for (let r = 0; r < t.length; r++) {
|
|
960
|
+
const s = t[r], n = r * De;
|
|
961
|
+
for (let o = 0; o < 16; o++)
|
|
962
|
+
a.setFloat32(n + o * 4, s.worldFromObject[o], !0), a.setFloat32(n + 64 + o * 4, s.objectFromWorld[o], !0);
|
|
963
|
+
a.setUint32(n + 128, s.triBase >>> 0, !0), a.setUint32(n + 132, s.triCount >>> 0, !0), a.setUint32(n + 136, s.blasRoot >>> 0, !0), a.setUint32(n + 140, 0, !0);
|
|
964
|
+
}
|
|
965
|
+
return e;
|
|
966
|
+
}
|
|
967
|
+
function fo(t, e) {
|
|
968
|
+
if (e <= 0) return null;
|
|
969
|
+
const a = ns(t, e);
|
|
970
|
+
if (!a) return null;
|
|
971
|
+
const r = new Float32Array(3), s = new Float32Array(3);
|
|
972
|
+
return Aa(a.nodes, a.rootIndex, r, s), {
|
|
973
|
+
triangleFloats: t.slice(0, e * Rt),
|
|
974
|
+
triCount: e,
|
|
975
|
+
bvh: a,
|
|
976
|
+
bmin: r,
|
|
977
|
+
bmax: s
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
function mo(t) {
|
|
981
|
+
const e = Math.min(t.length, be);
|
|
982
|
+
if (e <= 0) return null;
|
|
983
|
+
const a = t.slice(0, e), r = Math.max(1, e * 2), s = /* @__PURE__ */ new Set();
|
|
984
|
+
let n = 0;
|
|
985
|
+
for (const f of a)
|
|
986
|
+
s.has(f.blasNodes) || (s.add(f.blasNodes), n += f.blasNodeCount);
|
|
987
|
+
const o = r + n, i = new ArrayBuffer(o * ge), c = ho(a, i, r);
|
|
988
|
+
if (!c) return null;
|
|
989
|
+
let l = c.nodeCount;
|
|
990
|
+
const u = /* @__PURE__ */ new Map(), h = [];
|
|
991
|
+
for (const f of a) {
|
|
992
|
+
let m = u.get(f.blasNodes);
|
|
993
|
+
m === void 0 && (m = l, lo(
|
|
994
|
+
i,
|
|
995
|
+
m,
|
|
996
|
+
{
|
|
997
|
+
nodeCount: f.blasNodeCount,
|
|
998
|
+
rootIndex: f.blasRootLocal,
|
|
999
|
+
nodes: f.blasNodes
|
|
1000
|
+
},
|
|
1001
|
+
f.triBase
|
|
1002
|
+
), u.set(f.blasNodes, m), l += f.blasNodeCount), h.push({
|
|
1003
|
+
worldFromObject: f.worldFromObject,
|
|
1004
|
+
objectFromWorld: f.objectFromWorld,
|
|
1005
|
+
triBase: f.triBase,
|
|
1006
|
+
triCount: f.triCount,
|
|
1007
|
+
blasRoot: m + f.blasRootLocal
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
return {
|
|
1011
|
+
bvh: {
|
|
1012
|
+
nodeCount: l,
|
|
1013
|
+
rootIndex: c.rootIndex,
|
|
1014
|
+
nodes: i
|
|
1015
|
+
},
|
|
1016
|
+
instancesBuffer: uo(h),
|
|
1017
|
+
instanceCount: h.length
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
const po = 4294967295, sa = 53, fr = 16, dr = 16;
|
|
1021
|
+
function bo(t, e, a) {
|
|
1022
|
+
return 0.2126 * t + 0.7152 * e + 0.0722 * a;
|
|
1023
|
+
}
|
|
1024
|
+
function dc(t, e) {
|
|
1025
|
+
return !(t > 0) || !(e > 0) ? 0 : Math.PI * t / e;
|
|
1026
|
+
}
|
|
1027
|
+
function na(t, e, a, r) {
|
|
1028
|
+
const s = t[3] * e + t[7] * a + t[11] * r + t[15], n = s !== 0 ? 1 / s : 1;
|
|
1029
|
+
return [
|
|
1030
|
+
(t[0] * e + t[4] * a + t[8] * r + t[12]) * n,
|
|
1031
|
+
(t[1] * e + t[5] * a + t[9] * r + t[13]) * n,
|
|
1032
|
+
(t[2] * e + t[6] * a + t[10] * r + t[14]) * n
|
|
1033
|
+
];
|
|
1034
|
+
}
|
|
1035
|
+
function yo(t, e, a, r, s, n, o, i, c) {
|
|
1036
|
+
const l = r - t, u = s - e, h = n - a, f = o - t, m = i - e, g = c - a, p = u * g - h * m, T = h * f - l * g, b = l * m - u * f;
|
|
1037
|
+
return 0.5 * Math.hypot(p, T, b);
|
|
1038
|
+
}
|
|
1039
|
+
function mr(t, e, a, r, s) {
|
|
1040
|
+
if (t.length >= Ur) return;
|
|
1041
|
+
const n = a * Rt, o = bo(
|
|
1042
|
+
e[n + sa] ?? 0,
|
|
1043
|
+
e[n + sa + 1] ?? 0,
|
|
1044
|
+
e[n + sa + 2] ?? 0
|
|
1045
|
+
);
|
|
1046
|
+
if (!(o > 0)) return;
|
|
1047
|
+
let i = e[n] ?? 0, c = e[n + 1] ?? 0, l = e[n + 2] ?? 0, u = e[n + 3] ?? 0, h = e[n + 4] ?? 0, f = e[n + 5] ?? 0, m = e[n + 6] ?? 0, g = e[n + 7] ?? 0, p = e[n + 8] ?? 0;
|
|
1048
|
+
s && ([i, c, l] = na(s, i, c, l), [u, h, f] = na(s, u, h, f), [m, g, p] = na(s, m, g, p));
|
|
1049
|
+
const T = yo(i, c, l, u, h, f, m, g, p);
|
|
1050
|
+
T > 0 && t.push({ tri: a, inst: r, area: T, power: Math.PI * T * o });
|
|
1051
|
+
}
|
|
1052
|
+
function To(t, e, a) {
|
|
1053
|
+
const r = [];
|
|
1054
|
+
if (a)
|
|
1055
|
+
for (let l = 0; l < a.length; l++) {
|
|
1056
|
+
const u = a[l];
|
|
1057
|
+
for (let h = 0; h < u.triCount; h++)
|
|
1058
|
+
mr(r, t, u.triBase + h, l, u.worldFromObject);
|
|
1059
|
+
}
|
|
1060
|
+
else
|
|
1061
|
+
for (let l = 0; l < e; l++)
|
|
1062
|
+
mr(r, t, l, po, null);
|
|
1063
|
+
const s = r.length;
|
|
1064
|
+
let n = 0;
|
|
1065
|
+
for (const l of r) n += l.power;
|
|
1066
|
+
const o = new ArrayBuffer(fr + Math.max(1, s) * dr), i = new DataView(o);
|
|
1067
|
+
i.setUint32(0, s, !0), i.setFloat32(4, n, !0);
|
|
1068
|
+
let c = 0;
|
|
1069
|
+
for (let l = 0; l < s; l++) {
|
|
1070
|
+
const u = r[l];
|
|
1071
|
+
c += u.power;
|
|
1072
|
+
const h = l === s - 1 || n <= 0 ? 1 : c / n, f = fr + l * dr;
|
|
1073
|
+
i.setUint32(f, u.tri, !0), i.setUint32(f + 4, u.inst, !0), i.setFloat32(f + 8, h, !0), i.setFloat32(f + 12, u.area, !0);
|
|
1074
|
+
}
|
|
1075
|
+
return { bytes: o, count: s, totalPower: n };
|
|
1076
|
+
}
|
|
1077
|
+
function pr(t, e) {
|
|
1078
|
+
return t ^= e >>> 0, Math.imul(t, 16777619) >>> 0;
|
|
1079
|
+
}
|
|
1080
|
+
function go(t, e) {
|
|
1081
|
+
let a = 2166136261;
|
|
1082
|
+
a = pr(a, t | 0);
|
|
1083
|
+
const r = Number.isFinite(e) ? Math.round(e * 1e4) : 0;
|
|
1084
|
+
return a = pr(a, r | 0), a >>> 0;
|
|
1085
|
+
}
|
|
1086
|
+
const oa = 20, br = Rt * 4;
|
|
1087
|
+
let Ce = null, yr = !1, ia = "";
|
|
1088
|
+
function Mo(t, e) {
|
|
1089
|
+
var r, s, n, o;
|
|
1090
|
+
let a = 0;
|
|
1091
|
+
for (const i of t) {
|
|
1092
|
+
const c = ((s = (r = i.mesh) == null ? void 0 : r.indices) == null ? void 0 : s.length) ?? 0;
|
|
1093
|
+
a += Math.floor(c / 3);
|
|
1094
|
+
}
|
|
1095
|
+
if (e)
|
|
1096
|
+
for (const i of e) {
|
|
1097
|
+
const c = ((o = (n = i.mesh) == null ? void 0 : n.indices) == null ? void 0 : o.length) ?? 0;
|
|
1098
|
+
c > 0 && i.count > 0 && (a += Math.floor(c / 3) * i.count);
|
|
1099
|
+
}
|
|
1100
|
+
return a;
|
|
1101
|
+
}
|
|
1102
|
+
let ca = null;
|
|
1103
|
+
function So() {
|
|
1104
|
+
return ca ?? (ca = new In()), ca.reset(), ca;
|
|
1105
|
+
}
|
|
1106
|
+
function Ao(t) {
|
|
1107
|
+
return (!Ce || Ce.byteLength < t) && (Ce = new ArrayBuffer(t)), Ce;
|
|
1108
|
+
}
|
|
1109
|
+
function ee(t, e, a, r, s) {
|
|
1110
|
+
t[0] = s[0] * e + s[4] * a + s[8] * r, t[1] = s[1] * e + s[5] * a + s[9] * r, t[2] = s[2] * e + s[6] * a + s[10] * r;
|
|
1111
|
+
const n = Math.hypot(t[0], t[1], t[2]);
|
|
1112
|
+
n > 1e-20 && (t[0] /= n, t[1] /= n, t[2] /= n);
|
|
1113
|
+
}
|
|
1114
|
+
const Tr = 36;
|
|
1115
|
+
let gr = !1;
|
|
1116
|
+
function Fe(t) {
|
|
1117
|
+
if (t) {
|
|
1118
|
+
if (typeof t == "object" && t !== null && "texture" in t) {
|
|
1119
|
+
const e = t.texture;
|
|
1120
|
+
if (e && typeof e == "object" && e !== null && "label" in e)
|
|
1121
|
+
return e;
|
|
1122
|
+
}
|
|
1123
|
+
if (typeof t == "object" && t !== null && "label" in t)
|
|
1124
|
+
return t;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
function vo(t) {
|
|
1128
|
+
var a, r;
|
|
1129
|
+
const e = (r = (a = t.properties) == null ? void 0 : a.get) == null ? void 0 : r.call(a, "normalScale");
|
|
1130
|
+
return typeof e == "number" && Number.isFinite(e) ? Math.max(0, Math.min(4, e)) : 1;
|
|
1131
|
+
}
|
|
1132
|
+
const va = { ox: 0, oy: 0, sx: 1, sy: 1, cos: 1, sin: 0, uvSet: 0 }, xa = { ox: 0, oy: 0, sx: 1, sy: 1, cos: 1, sin: 0, uvSet: 1 };
|
|
1133
|
+
function ue(t, e, a, r = 0) {
|
|
1134
|
+
var m, g, p, T;
|
|
1135
|
+
const s = (g = (m = t == null ? void 0 : t.properties) == null ? void 0 : m.get) == null ? void 0 : g.call(m, e), n = (T = (p = t == null ? void 0 : t.properties) == null ? void 0 : p.get) == null ? void 0 : T.call(p, a), o = s != null && Number.isFinite(Number(s[0])) ? Number(s[0]) : 0, i = s != null && Number.isFinite(Number(s[1])) ? Number(s[1]) : 0, c = s != null && Number.isFinite(Number(s[2])) ? Number(s[2]) : 1, l = s != null && Number.isFinite(Number(s[3])) ? Number(s[3]) : 1, u = n != null && Number.isFinite(Number(n[0])) ? Number(n[0]) : 1, h = n != null && Number.isFinite(Number(n[1])) ? Number(n[1]) : 0, f = n != null && Number.isFinite(Number(n[2])) ? Number(n[2]) : r;
|
|
1136
|
+
return { ox: o, oy: i, sx: c, sy: l, cos: u, sin: h, uvSet: f >= 0.5 ? 1 : 0 };
|
|
1137
|
+
}
|
|
1138
|
+
function Mr(t, e) {
|
|
1139
|
+
return t.uvSet === e.uvSet && Math.abs(t.ox - e.ox) <= 1e-6 && Math.abs(t.oy - e.oy) <= 1e-6 && Math.abs(t.sx - e.sx) <= 1e-6 && Math.abs(t.sy - e.sy) <= 1e-6 && Math.abs(t.cos - e.cos) <= 1e-6 && Math.abs(t.sin - e.sin) <= 1e-6;
|
|
1140
|
+
}
|
|
1141
|
+
function ae(t, e, a, r, s) {
|
|
1142
|
+
const n = s.uvSet === 1 ? a : t, o = s.uvSet === 1 ? r : e, i = n * s.sx, c = o * s.sy;
|
|
1143
|
+
return [s.cos * i + s.sin * c + s.ox, -s.sin * i + s.cos * c + s.oy];
|
|
1144
|
+
}
|
|
1145
|
+
function He(t) {
|
|
1146
|
+
if (!t)
|
|
1147
|
+
return {
|
|
1148
|
+
uv0Tf: va,
|
|
1149
|
+
uv1Tf: xa,
|
|
1150
|
+
ormUsesUv1Slot: !1,
|
|
1151
|
+
emissiveUsesUv1Slot: !1
|
|
1152
|
+
};
|
|
1153
|
+
const { albedo: e, orm: a, normal: r, emissive: s } = os(t), n = e ? ue(t, "uvTfAlbedoOs", "uvTfAlbedoRs", 0) : r ? ue(t, "uvTfNormalOs", "uvTfNormalRs", 0) : s ? ue(t, "uvTfEmissiveOs", "uvTfEmissiveRs", 0) : va, o = xo(t) ? 1 : 0, i = a ? ue(t, "uvTfOrmMrOs", "uvTfOrmMrRs", o) : null, c = i !== null && !Mr(n, i), l = s ? ue(t, "uvTfEmissiveOs", "uvTfEmissiveRs", 0) : null, u = l !== null && !Mr(n, l) && !c;
|
|
1154
|
+
return {
|
|
1155
|
+
uv0Tf: n,
|
|
1156
|
+
uv1Tf: c ? i : u ? l : xa,
|
|
1157
|
+
ormUsesUv1Slot: c,
|
|
1158
|
+
emissiveUsesUv1Slot: u
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
function Sr(t) {
|
|
1162
|
+
return `${t.uvSet},${t.ox},${t.oy},${t.sx},${t.sy},${t.cos},${t.sin}`;
|
|
1163
|
+
}
|
|
1164
|
+
function xo(t) {
|
|
1165
|
+
var a, r;
|
|
1166
|
+
const e = (r = (a = t.properties) == null ? void 0 : a.get) == null ? void 0 : r.call(a, "ormMrUvSet");
|
|
1167
|
+
return e === 1 || e === 1;
|
|
1168
|
+
}
|
|
1169
|
+
function la(t) {
|
|
1170
|
+
const e = t == null ? void 0 : t.shaderGraph;
|
|
1171
|
+
return !e || !Array.isArray(e.nodes) ? !1 : e.nodes.some((a) => (a == null ? void 0 : a.type) === "MeshMaps");
|
|
1172
|
+
}
|
|
1173
|
+
function ha(t) {
|
|
1174
|
+
var s, n;
|
|
1175
|
+
if (Fa(t)) return [0, 0, 0];
|
|
1176
|
+
const e = (n = (s = t.properties) == null ? void 0 : s.get) == null ? void 0 : n.call(s, "emissiveColor");
|
|
1177
|
+
if (e != null && typeof e[0] == "number")
|
|
1178
|
+
return [Number(e[0]), Number(e[1] ?? 0), Number(e[2] ?? 0)];
|
|
1179
|
+
const r = t.emissiveColor;
|
|
1180
|
+
return r != null && typeof r[0] == "number" ? [Number(r[0]), Number(r[1] ?? 0), Number(r[2] ?? 0)] : [0, 0, 0];
|
|
1181
|
+
}
|
|
1182
|
+
const Ar = /* @__PURE__ */ new WeakMap();
|
|
1183
|
+
let _o = 1;
|
|
1184
|
+
function we(t) {
|
|
1185
|
+
if (!t) return 0;
|
|
1186
|
+
const e = t;
|
|
1187
|
+
let a = Ar.get(e);
|
|
1188
|
+
return a === void 0 && (a = _o++, Ar.set(e, a)), a;
|
|
1189
|
+
}
|
|
1190
|
+
function os(t) {
|
|
1191
|
+
var c, l, u, h, f, m, g, p, T, b;
|
|
1192
|
+
const e = t.diffuseTexture, a = Fe((l = (c = t.properties) == null ? void 0 : c.get) == null ? void 0 : l.call(c, "baseColorTexture")), r = e ?? a;
|
|
1193
|
+
if (Fa(t))
|
|
1194
|
+
return { albedo: r };
|
|
1195
|
+
const n = ((h = (u = t.properties) == null ? void 0 : u.get) == null ? void 0 : h.call(u, "ormHasMrTex")) === 0 ? void 0 : Fe((m = (f = t.properties) == null ? void 0 : f.get) == null ? void 0 : m.call(f, "metallicRoughnessTexture")), o = t.normalTexture ?? Fe((p = (g = t.properties) == null ? void 0 : g.get) == null ? void 0 : p.call(g, "normalTexture")), i = Fe((b = (T = t.properties) == null ? void 0 : T.get) == null ? void 0 : b.call(T, "emissiveTexture"));
|
|
1196
|
+
return { albedo: r, orm: n, normal: o, emissive: i };
|
|
1197
|
+
}
|
|
1198
|
+
class Eo {
|
|
1199
|
+
constructor() {
|
|
1200
|
+
y(this, "slotByMaterialId", /* @__PURE__ */ new Map());
|
|
1201
|
+
y(this, "slotByTupleKey", /* @__PURE__ */ new Map());
|
|
1202
|
+
y(this, "textureSlotFlags", new Uint32Array(yt));
|
|
1203
|
+
y(this, "textureSlots", Array.from(
|
|
1204
|
+
{ length: yt },
|
|
1205
|
+
() => ({})
|
|
1206
|
+
));
|
|
1207
|
+
y(this, "matNormalScales", new Float32Array(yt));
|
|
1208
|
+
y(this, "nextSlot", 0);
|
|
1209
|
+
this.matNormalScales.fill(1);
|
|
1210
|
+
}
|
|
1211
|
+
getSlotIndex(e) {
|
|
1212
|
+
const a = typeof e.id == "number" ? e.id : -1;
|
|
1213
|
+
if (a < 0)
|
|
1214
|
+
return kt;
|
|
1215
|
+
const r = this.slotByMaterialId.get(a);
|
|
1216
|
+
if (r !== void 0)
|
|
1217
|
+
return r;
|
|
1218
|
+
const { albedo: s, orm: n, normal: o, emissive: i } = os(e);
|
|
1219
|
+
if (!s && !n && !o && !i)
|
|
1220
|
+
return this.slotByMaterialId.set(a, kt), kt;
|
|
1221
|
+
let c = 0;
|
|
1222
|
+
s && (c |= 1), n && (c |= 2), o && (c |= 4), i && (c |= 8);
|
|
1223
|
+
const l = He(e);
|
|
1224
|
+
n && l.ormUsesUv1Slot && (c |= _n), i && l.emissiveUsesUv1Slot && (c |= En);
|
|
1225
|
+
const u = o ? vo(e) : 1, h = `${we(s)}:${we(n)}:${we(o)}:${we(i)}:${c}:${Math.round(u * 1e4)}`, f = this.slotByTupleKey.get(h);
|
|
1226
|
+
if (f !== void 0)
|
|
1227
|
+
return this.slotByMaterialId.set(a, f), f;
|
|
1228
|
+
if (this.nextSlot >= yt)
|
|
1229
|
+
return gr || (gr = !0, console.warn(
|
|
1230
|
+
`[PathTracer] More than ${yt} distinct material texture tuples; only the first ${yt} bind in path trace — extras use factors only (can look flat vs raster). Unrelated to triangle cap.`
|
|
1231
|
+
)), this.slotByMaterialId.set(a, kt), kt;
|
|
1232
|
+
const m = this.nextSlot++;
|
|
1233
|
+
return this.slotByMaterialId.set(a, m), this.slotByTupleKey.set(h, m), this.textureSlots[m] = { albedo: s, orm: n, normal: o, emissive: i }, this.textureSlotFlags[m] = c, this.matNormalScales[m] = u, m;
|
|
1234
|
+
}
|
|
1235
|
+
get texturedSlotsUsed() {
|
|
1236
|
+
return this.nextSlot;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function ua(t, e) {
|
|
1240
|
+
if (e + 19 >= t.length) return [1, 1, 1];
|
|
1241
|
+
const a = t[e + 16], r = t[e + 17], s = t[e + 18], n = t[e + 19];
|
|
1242
|
+
return a === 0 && r === 0 && s === 0 && n === 0 ? [1, 1, 1] : [a, r, s];
|
|
1243
|
+
}
|
|
1244
|
+
function fa(t, e, a, r, s, n, o, i, c, l, u, h, f = !0, m = va, g = xa) {
|
|
1245
|
+
const p = Ft(), T = Ft(), b = Ft(), A = Ft(), M = n;
|
|
1246
|
+
for (let x = 0; x + 2 < s.length && !(e >= a); x += 3) {
|
|
1247
|
+
const P = s[x] * oa, v = s[x + 1] * oa, w = s[x + 2] * oa, d = e * Rt;
|
|
1248
|
+
dt(p, r[P], r[P + 1], r[P + 2]), Wt(p, p, M), t[d + 0] = p[0], t[d + 1] = p[1], t[d + 2] = p[2], dt(p, r[v], r[v + 1], r[v + 2]), Wt(p, p, M), t[d + 3] = p[0], t[d + 4] = p[1], t[d + 5] = p[2], dt(p, r[w], r[w + 1], r[w + 2]), Wt(p, p, M), t[d + 6] = p[0], t[d + 7] = p[1], t[d + 8] = p[2], dt(T, r[P + 7], r[P + 8], r[P + 9]), Wt(T, T, o), pe(T, T), t[d + 9] = T[0], t[d + 10] = T[1], t[d + 11] = T[2], dt(T, r[v + 7], r[v + 8], r[v + 9]), Wt(T, T, o), pe(T, T), t[d + 12] = T[0], t[d + 13] = T[1], t[d + 14] = T[2], dt(T, r[w + 7], r[w + 8], r[w + 9]), Wt(T, T, o), pe(T, T), t[d + 15] = T[0], t[d + 16] = T[1], t[d + 17] = T[2], ee(b, r[P + 10], r[P + 11], r[P + 12], M), t[d + 18] = b[0], t[d + 19] = b[1], t[d + 20] = b[2], ee(b, r[v + 10], r[v + 11], r[v + 12], M), t[d + 21] = b[0], t[d + 22] = b[1], t[d + 23] = b[2], ee(b, r[w + 10], r[w + 11], r[w + 12], M), t[d + 24] = b[0], t[d + 25] = b[1], t[d + 26] = b[2], ee(A, r[P + 13], r[P + 14], r[P + 15], M), t[d + 27] = A[0], t[d + 28] = A[1], t[d + 29] = A[2], ee(A, r[v + 13], r[v + 14], r[v + 15], M), t[d + 30] = A[0], t[d + 31] = A[1], t[d + 32] = A[2], ee(A, r[w + 13], r[w + 14], r[w + 15], M), t[d + 33] = A[0], t[d + 34] = A[1], t[d + 35] = A[2];
|
|
1249
|
+
const [S, _] = ae(
|
|
1250
|
+
r[P + 3],
|
|
1251
|
+
r[P + 4],
|
|
1252
|
+
r[P + 5],
|
|
1253
|
+
r[P + 6],
|
|
1254
|
+
m
|
|
1255
|
+
), [I, C] = ae(
|
|
1256
|
+
r[v + 3],
|
|
1257
|
+
r[v + 4],
|
|
1258
|
+
r[v + 5],
|
|
1259
|
+
r[v + 6],
|
|
1260
|
+
m
|
|
1261
|
+
), [F, R] = ae(
|
|
1262
|
+
r[w + 3],
|
|
1263
|
+
r[w + 4],
|
|
1264
|
+
r[w + 5],
|
|
1265
|
+
r[w + 6],
|
|
1266
|
+
m
|
|
1267
|
+
);
|
|
1268
|
+
t[d + 36] = S, t[d + 37] = _, t[d + 38] = I, t[d + 39] = C, t[d + 40] = F, t[d + 41] = R;
|
|
1269
|
+
const [B, H] = ae(
|
|
1270
|
+
r[P + 3],
|
|
1271
|
+
r[P + 4],
|
|
1272
|
+
r[P + 5],
|
|
1273
|
+
r[P + 6],
|
|
1274
|
+
g
|
|
1275
|
+
), [L, Q] = ae(
|
|
1276
|
+
r[v + 3],
|
|
1277
|
+
r[v + 4],
|
|
1278
|
+
r[v + 5],
|
|
1279
|
+
r[v + 6],
|
|
1280
|
+
g
|
|
1281
|
+
), [tt, W] = ae(
|
|
1282
|
+
r[w + 3],
|
|
1283
|
+
r[w + 4],
|
|
1284
|
+
r[w + 5],
|
|
1285
|
+
r[w + 6],
|
|
1286
|
+
g
|
|
1287
|
+
);
|
|
1288
|
+
t[d + 42] = B, t[d + 43] = H, t[d + 44] = L, t[d + 45] = Q, t[d + 46] = tt, t[d + 47] = W;
|
|
1289
|
+
let z = 1, V = 1, D = 1;
|
|
1290
|
+
if (f) {
|
|
1291
|
+
const et = ua(r, P), Z = ua(r, v), k = ua(r, w);
|
|
1292
|
+
z = (et[0] + Z[0] + k[0]) / 3, V = (et[1] + Z[1] + k[1]) / 3, D = (et[2] + Z[2] + k[2]) / 3;
|
|
1293
|
+
}
|
|
1294
|
+
t[d + 48] = i[0] * z, t[d + 49] = i[1] * V, t[d + 50] = i[2] * D, t[d + 51] = c, t[d + 52] = l, t[d + 53] = u[0], t[d + 54] = u[1], t[d + 55] = u[2], t[d + 56] = h, e++;
|
|
1295
|
+
}
|
|
1296
|
+
return e;
|
|
1297
|
+
}
|
|
1298
|
+
const vr = /* @__PURE__ */ new WeakMap();
|
|
1299
|
+
let Po = 1;
|
|
1300
|
+
function xr(t) {
|
|
1301
|
+
let e = vr.get(t);
|
|
1302
|
+
return e === void 0 && (e = Po++, vr.set(t, e)), e;
|
|
1303
|
+
}
|
|
1304
|
+
function Ro(t, e, a = Vt) {
|
|
1305
|
+
const r = a * br, s = Ao(r), n = new Float32Array(s);
|
|
1306
|
+
let o = 0;
|
|
1307
|
+
const i = Ke(), c = new Eo(), l = So(), u = (S) => S ? l.getIndex(S, c.getSlotIndex(S)) : 0, h = Mo(t, e), f = [];
|
|
1308
|
+
if (e)
|
|
1309
|
+
for (const S of e) {
|
|
1310
|
+
if (f.length >= be) break;
|
|
1311
|
+
const { mesh: _, instanceData: I, count: C, material: F } = S;
|
|
1312
|
+
if (!(!I || !(_ != null && _.vertices) || !(_ != null && _.indices)))
|
|
1313
|
+
for (let R = 0; R < C && !(f.length >= be); R++) {
|
|
1314
|
+
const B = R * Tr;
|
|
1315
|
+
f.push({
|
|
1316
|
+
vertices: _.vertices,
|
|
1317
|
+
indices: _.indices,
|
|
1318
|
+
material: F,
|
|
1319
|
+
worldFromObject: I.subarray(B, B + 16)
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
for (const S of t) {
|
|
1324
|
+
if (f.length >= be) break;
|
|
1325
|
+
f.push({
|
|
1326
|
+
vertices: S.mesh.vertices,
|
|
1327
|
+
indices: S.mesh.indices,
|
|
1328
|
+
material: S.material,
|
|
1329
|
+
worldFromObject: S.transform
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
const m = /* @__PURE__ */ new Map(), g = [], p = new Float32Array(3), T = new Float32Array(3), b = Ke();
|
|
1333
|
+
for (const S of f) {
|
|
1334
|
+
if (o >= a) break;
|
|
1335
|
+
const _ = S.material, I = _ ? Ye(_) : [0.5, 0.5, 0.5], C = _ ? je(_) : 0, F = _ ? qe(_) : 0.5, R = _ ? ha(_) : [0, 0, 0], B = !la(_), H = u(_), L = He(_), Q = typeof (_ == null ? void 0 : _.id) == "number" ? _.id : -1, tt = `${xr(S.vertices)}|${xr(S.indices)}|${Q}|${I[0]},${I[1]},${I[2]}|${C}|${F}|${R[0]},${R[1]},${R[2]}|${B ? 1 : 0}|${H}|${Sr(L.uv0Tf)}|${Sr(L.uv1Tf)}`;
|
|
1336
|
+
let W = m.get(tt);
|
|
1337
|
+
if (!W) {
|
|
1338
|
+
const V = o, D = o;
|
|
1339
|
+
o = fa(
|
|
1340
|
+
n,
|
|
1341
|
+
o,
|
|
1342
|
+
a,
|
|
1343
|
+
S.vertices,
|
|
1344
|
+
S.indices,
|
|
1345
|
+
i,
|
|
1346
|
+
i,
|
|
1347
|
+
I,
|
|
1348
|
+
C,
|
|
1349
|
+
F,
|
|
1350
|
+
R,
|
|
1351
|
+
H,
|
|
1352
|
+
B,
|
|
1353
|
+
L.uv0Tf,
|
|
1354
|
+
L.uv1Tf
|
|
1355
|
+
);
|
|
1356
|
+
const et = o - D;
|
|
1357
|
+
if (et <= 0) continue;
|
|
1358
|
+
const Z = n.subarray(
|
|
1359
|
+
V * Rt,
|
|
1360
|
+
o * Rt
|
|
1361
|
+
), k = fo(Z, et);
|
|
1362
|
+
if (!k) continue;
|
|
1363
|
+
W = {
|
|
1364
|
+
triBase: V,
|
|
1365
|
+
triCount: et,
|
|
1366
|
+
blasNodes: k.bvh.nodes,
|
|
1367
|
+
blasNodeCount: k.bvh.nodeCount,
|
|
1368
|
+
blasRootLocal: k.bvh.rootIndex,
|
|
1369
|
+
bmin: k.bmin,
|
|
1370
|
+
bmax: k.bmax
|
|
1371
|
+
}, m.set(tt, W);
|
|
1372
|
+
}
|
|
1373
|
+
const z = S.worldFromObject;
|
|
1374
|
+
Qa(b, z), co(z, W.bmin, W.bmax, p, T), g.push({
|
|
1375
|
+
worldFromObject: Ja(z),
|
|
1376
|
+
objectFromWorld: Ja(b),
|
|
1377
|
+
triBase: W.triBase,
|
|
1378
|
+
triCount: W.triCount,
|
|
1379
|
+
blasRootLocal: W.blasRootLocal,
|
|
1380
|
+
blasNodes: W.blasNodes,
|
|
1381
|
+
blasNodeCount: W.blasNodeCount,
|
|
1382
|
+
worldMin: new Float32Array(p),
|
|
1383
|
+
worldMax: new Float32Array(T)
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
let A = null, M = null, x = 0, P = !1;
|
|
1387
|
+
const v = mo(g);
|
|
1388
|
+
if (v && v.instanceCount > 0)
|
|
1389
|
+
A = v.bvh, M = v.instancesBuffer, x = v.instanceCount, P = !0;
|
|
1390
|
+
else if (o > 0) {
|
|
1391
|
+
o = 0;
|
|
1392
|
+
const S = Ke();
|
|
1393
|
+
if (e)
|
|
1394
|
+
for (const I of e) {
|
|
1395
|
+
if (o >= a) break;
|
|
1396
|
+
const { mesh: C, instanceData: F, count: R, material: B } = I;
|
|
1397
|
+
if (!F || !(C != null && C.vertices) || !(C != null && C.indices)) continue;
|
|
1398
|
+
const H = B, L = H ? Ye(H) : [0.5, 0.5, 0.5], Q = H ? je(H) : 0, tt = H ? qe(H) : 0.5, W = H ? ha(H) : [0, 0, 0], z = !la(H), V = u(H), D = He(H);
|
|
1399
|
+
for (let et = 0; et < R && !(o >= a); et++) {
|
|
1400
|
+
const Z = et * Tr;
|
|
1401
|
+
o = fa(
|
|
1402
|
+
n,
|
|
1403
|
+
o,
|
|
1404
|
+
a,
|
|
1405
|
+
C.vertices,
|
|
1406
|
+
C.indices,
|
|
1407
|
+
F.subarray(Z, Z + 16),
|
|
1408
|
+
F.subarray(Z + 16, Z + 32),
|
|
1409
|
+
L,
|
|
1410
|
+
Q,
|
|
1411
|
+
tt,
|
|
1412
|
+
W,
|
|
1413
|
+
V,
|
|
1414
|
+
z,
|
|
1415
|
+
D.uv0Tf,
|
|
1416
|
+
D.uv1Tf
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
for (const I of t) {
|
|
1421
|
+
if (o >= a) break;
|
|
1422
|
+
Qa(S, I.transform), Ys(S, S);
|
|
1423
|
+
const C = I.material, F = He(C);
|
|
1424
|
+
o = fa(
|
|
1425
|
+
n,
|
|
1426
|
+
o,
|
|
1427
|
+
a,
|
|
1428
|
+
I.mesh.vertices,
|
|
1429
|
+
I.mesh.indices,
|
|
1430
|
+
I.transform,
|
|
1431
|
+
S,
|
|
1432
|
+
Ye(C),
|
|
1433
|
+
je(C),
|
|
1434
|
+
qe(C),
|
|
1435
|
+
ha(C),
|
|
1436
|
+
u(C),
|
|
1437
|
+
!la(C),
|
|
1438
|
+
F.uv0Tf,
|
|
1439
|
+
F.uv1Tf
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
const _ = n.subarray(0, o * Rt);
|
|
1443
|
+
A = ns(_, o);
|
|
1444
|
+
}
|
|
1445
|
+
const w = a >= 1024 && o >= a && h > o;
|
|
1446
|
+
if (!yr && w && (yr = !0, console.warn(
|
|
1447
|
+
`[PathTracer] Triangle count hit the GPU cap (${a}): ${o} uploaded, scene demand ~${h}. Extra geometry is dropped (holes / broken edges). Simplify the GLB or raise PATH_TRACER_MAX_TRIANGLES (check GPU maxStorageBufferBindingSize).`
|
|
1448
|
+
)), o === 0)
|
|
1449
|
+
ia = "";
|
|
1450
|
+
else {
|
|
1451
|
+
const S = `${o}|${h}|${a}|${c.texturedSlotsUsed}|tl=${P ? 1 : 0}|inst=${x}`;
|
|
1452
|
+
S !== ia && (ia = S, console.info(
|
|
1453
|
+
`[PathTracer] Scene: ${o.toLocaleString()} tris uploaded (cap ${a.toLocaleString()}), demand ~${h.toLocaleString()}, textured material slots ${c.texturedSlotsUsed}/${yt}` + (P ? `, TLAS ${x} instances` : ", flat BVH") + (w ? " — geometry truncated at triangle cap." : ".")
|
|
1454
|
+
));
|
|
1455
|
+
}
|
|
1456
|
+
const d = To(
|
|
1457
|
+
n,
|
|
1458
|
+
o,
|
|
1459
|
+
P ? g.map((S) => ({
|
|
1460
|
+
triBase: S.triBase,
|
|
1461
|
+
triCount: S.triCount,
|
|
1462
|
+
worldFromObject: S.worldFromObject
|
|
1463
|
+
})) : null
|
|
1464
|
+
);
|
|
1465
|
+
return {
|
|
1466
|
+
data: s,
|
|
1467
|
+
triangleDataBytes: o * br,
|
|
1468
|
+
emissiveCatalog: d.bytes,
|
|
1469
|
+
emissiveCount: d.count,
|
|
1470
|
+
emissiveTotalPower: d.totalPower,
|
|
1471
|
+
triangleCount: o,
|
|
1472
|
+
sceneTriangleDemand: h,
|
|
1473
|
+
textureSlotFlags: c.textureSlotFlags,
|
|
1474
|
+
textureSlots: c.textureSlots,
|
|
1475
|
+
matNormalScales: c.matNormalScales,
|
|
1476
|
+
materialTable: l.data,
|
|
1477
|
+
materialCount: l.count,
|
|
1478
|
+
hasTransmission: l.hasTransmission,
|
|
1479
|
+
texturedMaterialSlotsUsed: c.texturedSlotsUsed,
|
|
1480
|
+
bvh: A,
|
|
1481
|
+
instances: M,
|
|
1482
|
+
instanceCount: x,
|
|
1483
|
+
useTwoLevel: P
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
const Co = 36;
|
|
1487
|
+
function mt(t, e) {
|
|
1488
|
+
return t ^= e >>> 0, Math.imul(t, 16777619) >>> 0;
|
|
1489
|
+
}
|
|
1490
|
+
function X(t, e) {
|
|
1491
|
+
const a = Math.round(e * 1e4);
|
|
1492
|
+
return mt(t, a | 0);
|
|
1493
|
+
}
|
|
1494
|
+
function _r(t, e) {
|
|
1495
|
+
if (!e || typeof e != "object") return mt(t, 0);
|
|
1496
|
+
const a = e;
|
|
1497
|
+
if (typeof a.id == "number" && (t = mt(t, a.id | 0)), typeof a.shadingModel == "string")
|
|
1498
|
+
for (let n = 0; n < a.shadingModel.length; n++) t = mt(t, a.shadingModel.charCodeAt(n));
|
|
1499
|
+
typeof a.metallic == "number" && (t = X(t, a.metallic)), typeof a.roughness == "number" && (t = X(t, a.roughness));
|
|
1500
|
+
const r = a.diffuseColor;
|
|
1501
|
+
r && r.length >= 3 && (t = X(t, r[0]), t = X(t, r[1]), t = X(t, r[2]));
|
|
1502
|
+
const s = a.properties;
|
|
1503
|
+
if (s instanceof Map) {
|
|
1504
|
+
const n = s.get("baseColor");
|
|
1505
|
+
Array.isArray(n) && n.length >= 3 && (t = X(t, Number(n[0])), t = X(t, Number(n[1])), t = X(t, Number(n[2])));
|
|
1506
|
+
const o = s.get("emissiveColor");
|
|
1507
|
+
Array.isArray(o) && o.length >= 3 && (t = X(t, Number(o[0])), t = X(t, Number(o[1])), t = X(t, Number(o[2])));
|
|
1508
|
+
const i = s.get("specularColorFactor");
|
|
1509
|
+
Array.isArray(i) && i.length >= 3 && (t = X(t, Number(i[0])), t = X(t, Number(i[1])), t = X(t, Number(i[2])));
|
|
1510
|
+
for (const c of [
|
|
1511
|
+
"metallic",
|
|
1512
|
+
"roughness",
|
|
1513
|
+
"emissive",
|
|
1514
|
+
"clearcoatFactor",
|
|
1515
|
+
"clearcoatRoughnessFactor",
|
|
1516
|
+
"specularFactor",
|
|
1517
|
+
"transmissionFactor",
|
|
1518
|
+
"ior",
|
|
1519
|
+
"opacity",
|
|
1520
|
+
"alphaCutoff",
|
|
1521
|
+
"bsdfKind",
|
|
1522
|
+
"ormHasMrTex",
|
|
1523
|
+
"ormMrUvSet"
|
|
1524
|
+
]) {
|
|
1525
|
+
const l = s.get(c);
|
|
1526
|
+
typeof l == "number" && (t = X(t, l));
|
|
1527
|
+
}
|
|
1528
|
+
for (const c of [
|
|
1529
|
+
"uvTfAlbedoOs",
|
|
1530
|
+
"uvTfAlbedoRs",
|
|
1531
|
+
"uvTfEmissiveOs",
|
|
1532
|
+
"uvTfEmissiveRs",
|
|
1533
|
+
"uvTfOrmMrOs",
|
|
1534
|
+
"uvTfOrmMrRs",
|
|
1535
|
+
"uvTfNormalOs",
|
|
1536
|
+
"uvTfNormalRs"
|
|
1537
|
+
]) {
|
|
1538
|
+
const l = s.get(c);
|
|
1539
|
+
if (Array.isArray(l))
|
|
1540
|
+
for (let u = 0; u < Math.min(l.length, 4); u++) t = X(t, Number(l[u]));
|
|
1541
|
+
}
|
|
1542
|
+
for (const c of [
|
|
1543
|
+
"baseColorTexture",
|
|
1544
|
+
"metallicRoughnessTexture",
|
|
1545
|
+
"normalTexture",
|
|
1546
|
+
"emissiveTexture"
|
|
1547
|
+
])
|
|
1548
|
+
t = mt(t, s.get(c) ? 1 : 0);
|
|
1549
|
+
}
|
|
1550
|
+
return t;
|
|
1551
|
+
}
|
|
1552
|
+
function Er(t, e) {
|
|
1553
|
+
for (let a = 0; a < 16; a++) t = X(t, e[a]);
|
|
1554
|
+
return t;
|
|
1555
|
+
}
|
|
1556
|
+
function Pr(t, e) {
|
|
1557
|
+
var r, s;
|
|
1558
|
+
if (e.name)
|
|
1559
|
+
for (let n = 0; n < e.name.length; n++) t = mt(t, e.name.charCodeAt(n));
|
|
1560
|
+
t = mt(t, ((r = e.vertices) == null ? void 0 : r.length) ?? 0), t = mt(t, ((s = e.indices) == null ? void 0 : s.length) ?? 0);
|
|
1561
|
+
const a = e.vertices;
|
|
1562
|
+
return a && a.length >= 3 && (t = X(t, a[0]), t = X(t, a[1]), t = X(t, a[2]), t = X(t, a[a.length - 3]), t = X(t, a[a.length - 2]), t = X(t, a[a.length - 1])), t;
|
|
1563
|
+
}
|
|
1564
|
+
function Fo(t, e, a) {
|
|
1565
|
+
let r = 2166136261;
|
|
1566
|
+
if (r = mt(r, a >>> 0), r = mt(r, t.length >>> 0), r = mt(r, (e == null ? void 0 : e.length) ?? 0), e)
|
|
1567
|
+
for (const s of e) {
|
|
1568
|
+
r = Pr(r, s.mesh ?? {}), r = _r(r, s.material), r = mt(r, s.count >>> 0);
|
|
1569
|
+
const n = s.instanceData;
|
|
1570
|
+
if (n)
|
|
1571
|
+
for (let o = 0; o < s.count; o++) {
|
|
1572
|
+
const i = o * Co;
|
|
1573
|
+
r = Er(r, n.subarray(i, i + 16));
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
for (const s of t)
|
|
1577
|
+
r = mt(r, s.entityId >>> 0), r = Pr(r, s.mesh), r = _r(r, s.material), r = Er(r, s.transform);
|
|
1578
|
+
return r >>> 0;
|
|
1579
|
+
}
|
|
1580
|
+
class wo {
|
|
1581
|
+
constructor() {
|
|
1582
|
+
y(this, "cached", null);
|
|
1583
|
+
y(this, "cachedFingerprint", 0);
|
|
1584
|
+
y(this, "stats", {
|
|
1585
|
+
buildsRequested: 0,
|
|
1586
|
+
rebuilds: 0,
|
|
1587
|
+
cacheHits: 0,
|
|
1588
|
+
lastFingerprint: 0
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
getStats() {
|
|
1592
|
+
return { ...this.stats };
|
|
1593
|
+
}
|
|
1594
|
+
clear() {
|
|
1595
|
+
this.cached = null, this.cachedFingerprint = 0;
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Return cached triangles+BVH when the scene fingerprint matches; otherwise rebuild.
|
|
1599
|
+
*/
|
|
1600
|
+
buildOrReuse(e, a, r) {
|
|
1601
|
+
this.stats.buildsRequested += 1;
|
|
1602
|
+
const s = Fo(e, a, r);
|
|
1603
|
+
return this.stats.lastFingerprint = s, this.cached && s === this.cachedFingerprint ? (this.stats.cacheHits += 1, this.cached) : (this.stats.rebuilds += 1, this.cached = Ro(e, a, r), this.cachedFingerprint = s, this.cached);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
function re(t, e) {
|
|
1607
|
+
return t ^= e >>> 0, Math.imul(t, 16777619) >>> 0;
|
|
1608
|
+
}
|
|
1609
|
+
function Ot(t, e) {
|
|
1610
|
+
const a = Number.isFinite(e) ? Math.round(e * 1e4) : 0;
|
|
1611
|
+
return re(t, a | 0);
|
|
1612
|
+
}
|
|
1613
|
+
function Io(t) {
|
|
1614
|
+
const e = [...t].sort((r, s) => r.id - s.id || r.type - s.type);
|
|
1615
|
+
let a = 2166136261;
|
|
1616
|
+
a = re(a, e.length);
|
|
1617
|
+
for (const r of e) {
|
|
1618
|
+
a = re(a, r.id | 0), a = re(a, r.type | 0);
|
|
1619
|
+
for (let s = 0; s < 16; s++) a = Ot(a, r.transform[s] ?? 0);
|
|
1620
|
+
a = Ot(a, r.color[0] ?? 0), a = Ot(a, r.color[1] ?? 0), a = Ot(a, r.color[2] ?? 0), a = Ot(a, r.intensity), a = Ot(a, r.range), a = Ot(a, r.inner), a = Ot(a, r.outer), a = re(a, r.shadows ? 1 : 0), a = re(a, r.shape | 0);
|
|
1621
|
+
}
|
|
1622
|
+
return a >>> 0;
|
|
1623
|
+
}
|
|
1624
|
+
const Bo = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
1625
|
+
function Ie(t, e, a, r, s, n, o, i, c, l) {
|
|
1626
|
+
return {
|
|
1627
|
+
id: t,
|
|
1628
|
+
type: e,
|
|
1629
|
+
transform: a ?? Bo,
|
|
1630
|
+
color: r,
|
|
1631
|
+
intensity: s,
|
|
1632
|
+
range: n,
|
|
1633
|
+
inner: o,
|
|
1634
|
+
outer: i,
|
|
1635
|
+
shadows: c ? 1 : 0,
|
|
1636
|
+
shape: l
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
function No(t) {
|
|
1640
|
+
const e = [];
|
|
1641
|
+
for (const [a, [r, s]] of t.query([ye, bt]).iter())
|
|
1642
|
+
Re(t, a) && e.push(
|
|
1643
|
+
Ie(
|
|
1644
|
+
a,
|
|
1645
|
+
0,
|
|
1646
|
+
s.worldTransform,
|
|
1647
|
+
r.color,
|
|
1648
|
+
r.intensity,
|
|
1649
|
+
0,
|
|
1650
|
+
0,
|
|
1651
|
+
0,
|
|
1652
|
+
r.shadowsEnabled,
|
|
1653
|
+
0
|
|
1654
|
+
)
|
|
1655
|
+
);
|
|
1656
|
+
for (const [a, [r, s]] of t.query([Hs, bt]).iter())
|
|
1657
|
+
Re(t, a) && e.push(
|
|
1658
|
+
Ie(
|
|
1659
|
+
a,
|
|
1660
|
+
1,
|
|
1661
|
+
s.worldTransform,
|
|
1662
|
+
r.color,
|
|
1663
|
+
r.intensity,
|
|
1664
|
+
r.range,
|
|
1665
|
+
0,
|
|
1666
|
+
0,
|
|
1667
|
+
r.shadowsEnabled,
|
|
1668
|
+
0
|
|
1669
|
+
)
|
|
1670
|
+
);
|
|
1671
|
+
for (const [a, [r, s]] of t.query([Ds, bt]).iter())
|
|
1672
|
+
Re(t, a) && e.push(
|
|
1673
|
+
Ie(
|
|
1674
|
+
a,
|
|
1675
|
+
2,
|
|
1676
|
+
s.worldTransform,
|
|
1677
|
+
r.color,
|
|
1678
|
+
r.intensity,
|
|
1679
|
+
r.range,
|
|
1680
|
+
r.innerAngle,
|
|
1681
|
+
r.outerAngle,
|
|
1682
|
+
r.shadowsEnabled,
|
|
1683
|
+
0
|
|
1684
|
+
)
|
|
1685
|
+
);
|
|
1686
|
+
for (const [a, [r, s]] of t.query([Os, bt]).iter())
|
|
1687
|
+
Re(t, a) && e.push(
|
|
1688
|
+
Ie(
|
|
1689
|
+
a,
|
|
1690
|
+
3,
|
|
1691
|
+
s.worldTransform,
|
|
1692
|
+
r.color,
|
|
1693
|
+
r.intensity,
|
|
1694
|
+
0,
|
|
1695
|
+
r.width,
|
|
1696
|
+
r.height,
|
|
1697
|
+
r.shadowsEnabled,
|
|
1698
|
+
r.shape === "disk" ? 1 : 0
|
|
1699
|
+
)
|
|
1700
|
+
);
|
|
1701
|
+
return e;
|
|
1702
|
+
}
|
|
1703
|
+
const Lo = `
|
|
1704
|
+
struct VsOut {
|
|
1705
|
+
@builtin(position) pos: vec4<f32>,
|
|
1706
|
+
@location(0) uv: vec2<f32>,
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
@vertex
|
|
1710
|
+
fn vs(@builtin(vertex_index) vertexIndex: u32) -> VsOut {
|
|
1711
|
+
let pos = array<vec2<f32>, 3>(
|
|
1712
|
+
vec2<f32>(-1.0, -1.0),
|
|
1713
|
+
vec2<f32>(3.0, -1.0),
|
|
1714
|
+
vec2<f32>(-1.0, 3.0)
|
|
1715
|
+
);
|
|
1716
|
+
let uv = array<vec2<f32>, 3>(
|
|
1717
|
+
vec2<f32>(0.0, 1.0),
|
|
1718
|
+
vec2<f32>(2.0, 1.0),
|
|
1719
|
+
vec2<f32>(0.0, -1.0)
|
|
1720
|
+
);
|
|
1721
|
+
var output: VsOut;
|
|
1722
|
+
output.pos = vec4<f32>(pos[vertexIndex], 0.0, 1.0);
|
|
1723
|
+
output.uv = uv[vertexIndex];
|
|
1724
|
+
return output;
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
@group(0) @binding(0) var srcTex: texture_2d<f32>;
|
|
1728
|
+
@group(0) @binding(1) var srcSamp: sampler;
|
|
1729
|
+
|
|
1730
|
+
fn srgb_to_linear_vec3(c: vec3<f32>) -> vec3<f32> {
|
|
1731
|
+
let x = clamp(c, vec3<f32>(0.0), vec3<f32>(1.0));
|
|
1732
|
+
let lo = x / 12.92;
|
|
1733
|
+
let hi = pow((x + vec3<f32>(0.055)) / 1.055, vec3<f32>(2.4));
|
|
1734
|
+
return select(lo, hi, x > vec3<f32>(0.04045));
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
@fragment
|
|
1738
|
+
fn fs(input: VsOut) -> @location(0) vec4<f32> {
|
|
1739
|
+
return textureSampleLevel(srcTex, srcSamp, input.uv, 0.0);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
@fragment
|
|
1743
|
+
fn fs_srgb_decode(input: VsOut) -> @location(0) vec4<f32> {
|
|
1744
|
+
let s = textureSampleLevel(srcTex, srcSamp, input.uv, 0.0);
|
|
1745
|
+
return vec4<f32>(srgb_to_linear_vec3(s.rgb), s.a);
|
|
1746
|
+
}
|
|
1747
|
+
`;
|
|
1748
|
+
function Ho(t, e, a) {
|
|
1749
|
+
if (!a)
|
|
1750
|
+
return {
|
|
1751
|
+
targetFormat: "rgba8unorm",
|
|
1752
|
+
decodeSrgbInShader: !1
|
|
1753
|
+
};
|
|
1754
|
+
if (typeof t == "string" && t.endsWith("-srgb"))
|
|
1755
|
+
return {
|
|
1756
|
+
targetFormat: "rgba8unorm-srgb",
|
|
1757
|
+
decodeSrgbInShader: !1
|
|
1758
|
+
};
|
|
1759
|
+
if (e && typeof t == "string") {
|
|
1760
|
+
const r = Br.getSrgbViewFormat(t);
|
|
1761
|
+
if (r)
|
|
1762
|
+
return {
|
|
1763
|
+
targetFormat: "rgba8unorm-srgb",
|
|
1764
|
+
sourceViewFormat: r,
|
|
1765
|
+
decodeSrgbInShader: !1
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
return typeof t == "string" && t.includes("float") ? {
|
|
1769
|
+
targetFormat: "rgba8unorm-srgb",
|
|
1770
|
+
decodeSrgbInShader: !1
|
|
1771
|
+
} : {
|
|
1772
|
+
targetFormat: "rgba8unorm-srgb",
|
|
1773
|
+
decodeSrgbInShader: !0
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1776
|
+
const Do = 20;
|
|
1777
|
+
function Oo(t, e, a = Qs, r = tn) {
|
|
1778
|
+
let s = 0;
|
|
1779
|
+
for (let h = 0; h < e.length; h++)
|
|
1780
|
+
(e[h] ?? 0) !== 0 && (s = h + 1);
|
|
1781
|
+
if (s === 0)
|
|
1782
|
+
return {
|
|
1783
|
+
totalSlots: 0,
|
|
1784
|
+
channelLayers: [0, 0, 0, 0],
|
|
1785
|
+
channelEdges: [0, 0, 0, 0],
|
|
1786
|
+
totalBytes: 0
|
|
1787
|
+
};
|
|
1788
|
+
const n = [0, 0, 0, 0], o = [1, 1, 1, 1];
|
|
1789
|
+
for (let h = 0; h < s; h++) {
|
|
1790
|
+
const f = t[h], m = e[h] ?? 0, g = [
|
|
1791
|
+
m & 1 ? f == null ? void 0 : f.albedo : void 0,
|
|
1792
|
+
m & 2 ? f == null ? void 0 : f.orm : void 0,
|
|
1793
|
+
m & 4 ? f == null ? void 0 : f.normal : void 0,
|
|
1794
|
+
m & 8 ? f == null ? void 0 : f.emissive : void 0
|
|
1795
|
+
];
|
|
1796
|
+
for (let p = 0; p < 4; p = p + 1) {
|
|
1797
|
+
const T = g[p];
|
|
1798
|
+
T && (n[p] = h + 1, o[p] = Math.max(o[p], T.width || 1, T.height || 1));
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
const i = [
|
|
1802
|
+
Math.max(1, n[0]),
|
|
1803
|
+
Math.max(1, n[1]),
|
|
1804
|
+
Math.max(1, n[2]),
|
|
1805
|
+
Math.max(1, n[3])
|
|
1806
|
+
], c = [
|
|
1807
|
+
n[0] > 0 ? Math.min(a, Math.max(1, o[0])) : 1,
|
|
1808
|
+
n[1] > 0 ? Math.min(a, Math.max(1, o[1])) : 1,
|
|
1809
|
+
n[2] > 0 ? Math.min(a, Math.max(1, o[2])) : 1,
|
|
1810
|
+
n[3] > 0 ? Math.min(a, Math.max(1, o[3])) : 1
|
|
1811
|
+
], l = () => (c[0] * c[0] * i[0] + c[1] * c[1] * i[1] + c[2] * c[2] * i[2] + c[3] * c[3] * i[3]) * 4, u = 64;
|
|
1812
|
+
for (; l() > r; ) {
|
|
1813
|
+
let h = -1, f = 0;
|
|
1814
|
+
for (let m = 0; m < 4; m++) {
|
|
1815
|
+
const g = c[m];
|
|
1816
|
+
if (g <= u) continue;
|
|
1817
|
+
const p = g * g * i[m] * 4;
|
|
1818
|
+
p > f && (f = p, h = m);
|
|
1819
|
+
}
|
|
1820
|
+
if (h < 0) break;
|
|
1821
|
+
c[h] = Math.max(
|
|
1822
|
+
u,
|
|
1823
|
+
Math.floor(c[h] / 2)
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
return {
|
|
1827
|
+
totalSlots: s,
|
|
1828
|
+
channelLayers: i,
|
|
1829
|
+
channelEdges: c,
|
|
1830
|
+
totalBytes: l()
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
class Go {
|
|
1834
|
+
constructor() {
|
|
1835
|
+
y(this, "device", null);
|
|
1836
|
+
y(this, "pipelineLinear", null);
|
|
1837
|
+
y(this, "pipelineSrgbLinearSrc", null);
|
|
1838
|
+
y(this, "pipelineSrgbDecodeSrc", null);
|
|
1839
|
+
y(this, "sampler", null);
|
|
1840
|
+
y(this, "bindGroupLayout", null);
|
|
1841
|
+
y(this, "albedo", null);
|
|
1842
|
+
y(this, "orm", null);
|
|
1843
|
+
y(this, "normal", null);
|
|
1844
|
+
y(this, "emissive", null);
|
|
1845
|
+
y(this, "sources", []);
|
|
1846
|
+
y(this, "channelEdges", [0, 0, 0, 0]);
|
|
1847
|
+
y(this, "channelLayers", [0, 0, 0, 0]);
|
|
1848
|
+
y(this, "warned", !1);
|
|
1849
|
+
}
|
|
1850
|
+
sync(e, a, r) {
|
|
1851
|
+
const s = Oo(a, r);
|
|
1852
|
+
if (s.totalSlots === 0) return;
|
|
1853
|
+
const { totalSlots: n, channelEdges: o, channelLayers: i } = s, c = new Array(n * 4);
|
|
1854
|
+
for (let u = 0; u < n; u++) {
|
|
1855
|
+
const h = a[u], f = r[u] ?? 0;
|
|
1856
|
+
c[u * 4 + 0] = f & 1 ? (h == null ? void 0 : h.albedo) ?? null : null, c[u * 4 + 1] = f & 2 ? (h == null ? void 0 : h.orm) ?? null : null, c[u * 4 + 2] = f & 4 ? (h == null ? void 0 : h.normal) ?? null : null, c[u * 4 + 3] = f & 8 ? (h == null ? void 0 : h.emissive) ?? null : null;
|
|
1857
|
+
}
|
|
1858
|
+
if (!(this.device === e && this.albedo !== null && this.channelEdges.every((u, h) => u === o[h]) && this.channelLayers.every((u, h) => u === i[h]) && this.sources.length === c.length && this.sources.every((u, h) => u === c[h])))
|
|
1859
|
+
try {
|
|
1860
|
+
this.rebuild(e, c, n, o, i);
|
|
1861
|
+
} catch (u) {
|
|
1862
|
+
this.warned || (this.warned = !0, console.warn(
|
|
1863
|
+
"[PathTracer] Material texture array pack failed; maps past the bind stay factors-only.",
|
|
1864
|
+
u
|
|
1865
|
+
));
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
bind(e) {
|
|
1869
|
+
!this.albedo || !this.orm || !this.normal || !this.emissive || (e.setOutput("pathTracerTexAlbedo", this.albedo), e.setOutput("pathTracerTexOrm", this.orm), e.setOutput("pathTracerTexNormal", this.normal), e.setOutput("pathTracerTexEmissive", this.emissive));
|
|
1870
|
+
}
|
|
1871
|
+
ensurePipeline(e) {
|
|
1872
|
+
if (this.device === e && this.pipelineLinear && this.pipelineSrgbLinearSrc && this.pipelineSrgbDecodeSrc && this.sampler && this.bindGroupLayout)
|
|
1873
|
+
return;
|
|
1874
|
+
this.device = e, this.pipelineLinear = null, this.pipelineSrgbLinearSrc = null, this.pipelineSrgbDecodeSrc = null, this.bindGroupLayout = e.createBindGroupLayout({
|
|
1875
|
+
label: "pathTracerTexArrayBlit",
|
|
1876
|
+
entries: [
|
|
1877
|
+
{
|
|
1878
|
+
binding: 0,
|
|
1879
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
1880
|
+
texture: { sampleType: "float", viewDimension: "2d" }
|
|
1881
|
+
},
|
|
1882
|
+
{ binding: 1, visibility: GPUShaderStage.FRAGMENT, sampler: { type: "filtering" } }
|
|
1883
|
+
]
|
|
1884
|
+
});
|
|
1885
|
+
const a = e.createShaderModule({ label: "pathTracerTexArrayBlit", code: Lo }), r = e.createPipelineLayout({
|
|
1886
|
+
bindGroupLayouts: [this.bindGroupLayout]
|
|
1887
|
+
});
|
|
1888
|
+
this.pipelineLinear = e.createRenderPipeline({
|
|
1889
|
+
label: "pathTracerTexArrayBlitLinear",
|
|
1890
|
+
layout: r,
|
|
1891
|
+
vertex: { module: a, entryPoint: "vs" },
|
|
1892
|
+
fragment: {
|
|
1893
|
+
module: a,
|
|
1894
|
+
entryPoint: "fs",
|
|
1895
|
+
targets: [{ format: "rgba8unorm" }]
|
|
1896
|
+
},
|
|
1897
|
+
primitive: { topology: "triangle-list" }
|
|
1898
|
+
}), this.pipelineSrgbLinearSrc = e.createRenderPipeline({
|
|
1899
|
+
label: "pathTracerTexArrayBlitSrgb",
|
|
1900
|
+
layout: r,
|
|
1901
|
+
vertex: { module: a, entryPoint: "vs" },
|
|
1902
|
+
fragment: {
|
|
1903
|
+
module: a,
|
|
1904
|
+
entryPoint: "fs",
|
|
1905
|
+
targets: [{ format: "rgba8unorm-srgb" }]
|
|
1906
|
+
},
|
|
1907
|
+
primitive: { topology: "triangle-list" }
|
|
1908
|
+
}), this.pipelineSrgbDecodeSrc = e.createRenderPipeline({
|
|
1909
|
+
label: "pathTracerTexArrayBlitSrgbDecode",
|
|
1910
|
+
layout: r,
|
|
1911
|
+
vertex: { module: a, entryPoint: "vs" },
|
|
1912
|
+
fragment: {
|
|
1913
|
+
module: a,
|
|
1914
|
+
entryPoint: "fs_srgb_decode",
|
|
1915
|
+
targets: [{ format: "rgba8unorm-srgb" }]
|
|
1916
|
+
},
|
|
1917
|
+
primitive: { topology: "triangle-list" }
|
|
1918
|
+
}), this.sampler = e.createSampler({
|
|
1919
|
+
label: "pathTracerTexArrayBlit",
|
|
1920
|
+
magFilter: "linear",
|
|
1921
|
+
minFilter: "linear",
|
|
1922
|
+
addressModeU: "clamp-to-edge",
|
|
1923
|
+
addressModeV: "clamp-to-edge"
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
rebuild(e, a, r, s, n) {
|
|
1927
|
+
this.ensurePipeline(e);
|
|
1928
|
+
const o = this.pipelineLinear, i = this.pipelineSrgbLinearSrc, c = this.pipelineSrgbDecodeSrc, l = this.sampler, u = this.bindGroupLayout;
|
|
1929
|
+
if (!o || !i || !c || !l || !u)
|
|
1930
|
+
return;
|
|
1931
|
+
const h = [this.albedo, this.orm, this.normal, this.emissive].filter(
|
|
1932
|
+
(M) => M !== null
|
|
1933
|
+
), f = (M, x, P, v) => e.createTexture({
|
|
1934
|
+
label: M,
|
|
1935
|
+
size: [P, P, v],
|
|
1936
|
+
format: x,
|
|
1937
|
+
usage: Do
|
|
1938
|
+
}), m = f(
|
|
1939
|
+
"pathTracerTexAlbedo",
|
|
1940
|
+
"rgba8unorm-srgb",
|
|
1941
|
+
s[0],
|
|
1942
|
+
n[0]
|
|
1943
|
+
), g = f("pathTracerTexOrm", "rgba8unorm", s[1], n[1]), p = f("pathTracerTexNormal", "rgba8unorm", s[2], n[2]), T = f(
|
|
1944
|
+
"pathTracerTexEmissive",
|
|
1945
|
+
"rgba8unorm-srgb",
|
|
1946
|
+
s[3],
|
|
1947
|
+
n[3]
|
|
1948
|
+
), b = [m, g, p, T], A = e.createCommandEncoder({ label: "pathTracerTexArrayBlit" });
|
|
1949
|
+
for (let M = 0; M < 4; M++) {
|
|
1950
|
+
const x = M === 0 || M === 3, P = n[M];
|
|
1951
|
+
for (let v = 0; v < Math.min(r, P); v++) {
|
|
1952
|
+
const w = a[v * 4 + M] ?? null;
|
|
1953
|
+
if (!w) continue;
|
|
1954
|
+
const d = b[M].createView({
|
|
1955
|
+
dimension: "2d",
|
|
1956
|
+
baseArrayLayer: v,
|
|
1957
|
+
arrayLayerCount: 1
|
|
1958
|
+
}), S = A.beginRenderPass({
|
|
1959
|
+
colorAttachments: [
|
|
1960
|
+
{
|
|
1961
|
+
view: d,
|
|
1962
|
+
loadOp: "clear",
|
|
1963
|
+
storeOp: "store",
|
|
1964
|
+
clearValue: { r: 1, g: 1, b: 1, a: 1 }
|
|
1965
|
+
}
|
|
1966
|
+
]
|
|
1967
|
+
}), _ = Ho(
|
|
1968
|
+
w.format,
|
|
1969
|
+
Br.supportsSrgbView(w),
|
|
1970
|
+
x
|
|
1971
|
+
), I = _.sourceViewFormat ? w.createView({ format: _.sourceViewFormat }) : w.createView(), C = e.createBindGroup({
|
|
1972
|
+
layout: u,
|
|
1973
|
+
entries: [
|
|
1974
|
+
{ binding: 0, resource: I },
|
|
1975
|
+
{ binding: 1, resource: l }
|
|
1976
|
+
]
|
|
1977
|
+
}), F = x ? _.decodeSrgbInShader ? c : i : o;
|
|
1978
|
+
S.setPipeline(F), S.setBindGroup(0, C), S.draw(3), S.end();
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
e.queue.submit([A.finish()]), this.albedo = m, this.orm = g, this.normal = p, this.emissive = T, this.sources = a, this.channelEdges = [...s], this.channelLayers = [...n], e.queue.onSubmittedWorkDone().then(() => {
|
|
1982
|
+
for (const M of h) M.destroy();
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
const Uo = [
|
|
1987
|
+
[0, 0],
|
|
1988
|
+
[1, 1],
|
|
1989
|
+
[1, 0],
|
|
1990
|
+
[0, 1]
|
|
1991
|
+
], zo = [
|
|
1992
|
+
[0, 0],
|
|
1993
|
+
[2, 2],
|
|
1994
|
+
[2, 0],
|
|
1995
|
+
[0, 2],
|
|
1996
|
+
[1, 1],
|
|
1997
|
+
[3, 3],
|
|
1998
|
+
[3, 1],
|
|
1999
|
+
[1, 3],
|
|
2000
|
+
[1, 0],
|
|
2001
|
+
[3, 2],
|
|
2002
|
+
[3, 0],
|
|
2003
|
+
[1, 2],
|
|
2004
|
+
[0, 1],
|
|
2005
|
+
[2, 3],
|
|
2006
|
+
[2, 1],
|
|
2007
|
+
[0, 3]
|
|
2008
|
+
];
|
|
2009
|
+
function Wo(t, e) {
|
|
2010
|
+
const a = Math.max(1, Math.min(4, Math.floor(t)));
|
|
2011
|
+
if (a <= 1) return { ox: 0, oy: 0 };
|
|
2012
|
+
const r = a * a, s = (e % r + r) % r;
|
|
2013
|
+
if (a === 2) {
|
|
2014
|
+
const [i, c] = Uo[s];
|
|
2015
|
+
return { ox: i, oy: c };
|
|
2016
|
+
}
|
|
2017
|
+
if (a === 3) {
|
|
2018
|
+
const i = s % 3, c = Math.floor(s / 3);
|
|
2019
|
+
return { ox: i, oy: c };
|
|
2020
|
+
}
|
|
2021
|
+
const [n, o] = zo[s];
|
|
2022
|
+
return { ox: n, oy: o };
|
|
2023
|
+
}
|
|
2024
|
+
function ko(t, e, a) {
|
|
2025
|
+
const r = Math.max(1, Math.floor(a));
|
|
2026
|
+
return {
|
|
2027
|
+
dispatchW: Math.max(1, Math.ceil(t / r)),
|
|
2028
|
+
dispatchH: Math.max(1, Math.ceil(e / r))
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function $o(t, e, a, r = 8) {
|
|
2032
|
+
const { dispatchW: s, dispatchH: n } = ko(t, e, a), o = Math.max(1, Math.floor(r));
|
|
2033
|
+
return [Math.ceil(s / o), Math.ceil(n / o), 1];
|
|
2034
|
+
}
|
|
2035
|
+
function Vo(t, e) {
|
|
2036
|
+
const a = Math.max(1, Math.floor(e));
|
|
2037
|
+
return t + 1 / (a * a);
|
|
2038
|
+
}
|
|
2039
|
+
function Yo(t, e) {
|
|
2040
|
+
const a = Math.max(1, Math.floor(t));
|
|
2041
|
+
return a <= 1 ? !0 : e > 0 && e % (a * a) === 0;
|
|
2042
|
+
}
|
|
2043
|
+
const da = 1, ma = 4, pa = 1e3 / 30, jo = 1e3 / 45;
|
|
2044
|
+
class qo {
|
|
2045
|
+
constructor(e = 2) {
|
|
2046
|
+
y(this, "ewmaMs", pa);
|
|
2047
|
+
y(this, "stride", 2);
|
|
2048
|
+
y(this, "alpha", 0.12);
|
|
2049
|
+
this.stride = Math.max(da, Math.min(ma, Math.floor(e)));
|
|
2050
|
+
}
|
|
2051
|
+
getStride() {
|
|
2052
|
+
return this.stride;
|
|
2053
|
+
}
|
|
2054
|
+
setStride(e) {
|
|
2055
|
+
this.stride = Math.max(da, Math.min(ma, Math.floor(e)));
|
|
2056
|
+
}
|
|
2057
|
+
/** Ingest frame delta (ms) and return the updated stride. */
|
|
2058
|
+
tick(e) {
|
|
2059
|
+
return !Number.isFinite(e) || e <= 0 ? this.stride : (this.ewmaMs = this.ewmaMs <= 0 ? e : this.ewmaMs * (1 - this.alpha) + e * this.alpha, this.ewmaMs > pa * 1.08 ? this.stride = Math.min(ma, this.stride + 1) : this.ewmaMs < jo && this.stride > da && (this.stride = this.stride - 1), this.stride);
|
|
2060
|
+
}
|
|
2061
|
+
reset() {
|
|
2062
|
+
this.ewmaMs = pa;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
const Xo = 8, Ko = 9, Zo = 10, Jo = 11, Qo = 12, ti = 13, ei = 14, ai = 15;
|
|
2066
|
+
function ri(t) {
|
|
2067
|
+
switch (t) {
|
|
2068
|
+
case "albedo":
|
|
2069
|
+
return 1;
|
|
2070
|
+
case "normal":
|
|
2071
|
+
return 2;
|
|
2072
|
+
case "depth":
|
|
2073
|
+
return 3;
|
|
2074
|
+
case "objectId":
|
|
2075
|
+
return 4;
|
|
2076
|
+
default:
|
|
2077
|
+
return 0;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
const si = 8;
|
|
2081
|
+
function is(t) {
|
|
2082
|
+
const e = Math.floor(Number.isFinite(t) ? t : 4);
|
|
2083
|
+
return Math.max(1, Math.min(8, e));
|
|
2084
|
+
}
|
|
2085
|
+
class ni {
|
|
2086
|
+
constructor(e = si) {
|
|
2087
|
+
y(this, "phase", "Interactive");
|
|
2088
|
+
y(this, "stillFrames", 0);
|
|
2089
|
+
y(this, "refiningHysteresis");
|
|
2090
|
+
y(this, "maxBouncesCap", 4);
|
|
2091
|
+
this.refiningHysteresis = Math.max(1, Math.floor(e));
|
|
2092
|
+
}
|
|
2093
|
+
setMaxBouncesCap(e) {
|
|
2094
|
+
this.maxBouncesCap = is(e);
|
|
2095
|
+
}
|
|
2096
|
+
getPhase() {
|
|
2097
|
+
return this.phase;
|
|
2098
|
+
}
|
|
2099
|
+
/** Preview pipeline (cheaper overrides) while camera/scene is moving or just settled. */
|
|
2100
|
+
isPreview() {
|
|
2101
|
+
return this.phase === "Interactive";
|
|
2102
|
+
}
|
|
2103
|
+
/** Bounce budget for WGSL `override MAX_BOUNCES`. */
|
|
2104
|
+
getMaxBounces() {
|
|
2105
|
+
return this.phase === "Interactive" ? Math.min(2, this.maxBouncesCap) : this.maxBouncesCap;
|
|
2106
|
+
}
|
|
2107
|
+
reset() {
|
|
2108
|
+
this.phase = "Interactive", this.stillFrames = 0;
|
|
2109
|
+
}
|
|
2110
|
+
tick(e) {
|
|
2111
|
+
if (e.interaction)
|
|
2112
|
+
return this.phase = "Interactive", this.stillFrames = 0, this.phase;
|
|
2113
|
+
switch (this.stillFrames += 1, this.phase) {
|
|
2114
|
+
case "Interactive":
|
|
2115
|
+
this.stillFrames >= this.refiningHysteresis && (this.phase = "Refining");
|
|
2116
|
+
break;
|
|
2117
|
+
case "Refining":
|
|
2118
|
+
e.converged && (this.phase = "Converged");
|
|
2119
|
+
break;
|
|
2120
|
+
case "Converged":
|
|
2121
|
+
e.denoised && (this.phase = "Denoised");
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
2124
|
+
return this.phase;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
const oi = 256;
|
|
2128
|
+
function ii(t, e) {
|
|
2129
|
+
let a = t, r = e;
|
|
2130
|
+
const s = 1 - Math.abs(a) - Math.abs(r), n = Math.max(-s, 0);
|
|
2131
|
+
a += a >= 0 ? -n : n, r += r >= 0 ? -n : n;
|
|
2132
|
+
const o = Math.hypot(a, r, s) || 1;
|
|
2133
|
+
return [a / o, r / o, s / o];
|
|
2134
|
+
}
|
|
2135
|
+
function mc(t, e, a) {
|
|
2136
|
+
const r = new Uint8ClampedArray(e * a * 4), s = e * a;
|
|
2137
|
+
for (let n = 0; n < s; n++) {
|
|
2138
|
+
const [o, i, c] = ii(t[n * 4], t[n * 4 + 1]), l = n * 4;
|
|
2139
|
+
r[l] = Math.round((o * 0.5 + 0.5) * 255), r[l + 1] = Math.round((i * 0.5 + 0.5) * 255), r[l + 2] = Math.round((c * 0.5 + 0.5) * 255), r[l + 3] = 255;
|
|
2140
|
+
}
|
|
2141
|
+
return r;
|
|
2142
|
+
}
|
|
2143
|
+
function ci(t, e, a) {
|
|
2144
|
+
return e || a ? 0 : t + 1;
|
|
2145
|
+
}
|
|
2146
|
+
function pc(t, e, a) {
|
|
2147
|
+
if (a) return !1;
|
|
2148
|
+
const r = typeof e == "number" && Number.isFinite(e) && e > 0 ? e : oi;
|
|
2149
|
+
return t >= r;
|
|
2150
|
+
}
|
|
2151
|
+
function cs() {
|
|
2152
|
+
return globalThis;
|
|
2153
|
+
}
|
|
2154
|
+
function bc() {
|
|
2155
|
+
return cs().__W3DTS_PATH_TRACER_INTERACTION_EPOCH__ ?? 0;
|
|
2156
|
+
}
|
|
2157
|
+
function ba() {
|
|
2158
|
+
const t = cs();
|
|
2159
|
+
t.__W3DTS_PATH_TRACER_INTERACTION_EPOCH__ = (t.__W3DTS_PATH_TRACER_INTERACTION_EPOCH__ ?? 0) + 1;
|
|
2160
|
+
}
|
|
2161
|
+
const Rr = 1e-6;
|
|
2162
|
+
function li(t) {
|
|
2163
|
+
return {
|
|
2164
|
+
fov: t.fov,
|
|
2165
|
+
projectionMode: t.projectionMode,
|
|
2166
|
+
orthographicHalfHeight: t.orthographicHalfHeight
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
function hi(t, e) {
|
|
2170
|
+
return t.projectionMode !== e.projectionMode ? !0 : e.projectionMode === "orthographic" ? Math.abs(t.orthographicHalfHeight - e.orthographicHalfHeight) > Rr : Math.abs(t.fov - e.fov) > Rr;
|
|
2171
|
+
}
|
|
2172
|
+
const ui = 1e-4, fi = 1e-6, Cr = 5e-3, Fr = 1e-4, di = 512, mi = 1;
|
|
2173
|
+
function pi() {
|
|
2174
|
+
var e;
|
|
2175
|
+
const t = (e = globalThis.__W3DTS_PATH_TRACER_CONFIG) == null ? void 0 : e.hybridTraceScale;
|
|
2176
|
+
return t === 0.25 || t === 0.5 || t === 1 ? t : 0.5;
|
|
2177
|
+
}
|
|
2178
|
+
function ls() {
|
|
2179
|
+
const t = typeof globalThis < "u" ? globalThis.__W3DTS_PATH_TRACER_CONFIG : void 0, e = (t == null ? void 0 : t.progressiveFrameStride) ?? 1, a = (t == null ? void 0 : t.denoiserKernelRadius) ?? 3, r = (t == null ? void 0 : t.fsrRcasSharpness) ?? 0.35, s = t == null ? void 0 : t.softSunAngularRadius, n = t == null ? void 0 : t.denoiserAlgorithm, o = n === "atrous" || n === "off" || n === "spatial" ? n : "spatial", i = t == null ? void 0 : t.atrousBlend;
|
|
2180
|
+
return {
|
|
2181
|
+
maxSamples: Math.max(
|
|
2182
|
+
en,
|
|
2183
|
+
Math.min(4096, (t == null ? void 0 : t.maxSamples) ?? di)
|
|
2184
|
+
),
|
|
2185
|
+
mirrorBouncesWhenStatic: Math.max(
|
|
2186
|
+
0,
|
|
2187
|
+
Math.min(4, (t == null ? void 0 : t.mirrorBouncesWhenStatic) ?? mi)
|
|
2188
|
+
),
|
|
2189
|
+
progressiveFrameStride: Math.max(1, Math.min(16, Math.floor(e))),
|
|
2190
|
+
tileSize: qr((t == null ? void 0 : t.tileSize) ?? Ca),
|
|
2191
|
+
enableGI: (t == null ? void 0 : t.enableGI) ?? !0,
|
|
2192
|
+
enableAO: (t == null ? void 0 : t.enableAO) ?? !0,
|
|
2193
|
+
enableReflection: (t == null ? void 0 : t.enableReflection) ?? !0,
|
|
2194
|
+
enableShadow: (t == null ? void 0 : t.enableShadow) ?? !0,
|
|
2195
|
+
denoiserKernelRadius: Math.max(1, Math.min(16, Math.floor(a))),
|
|
2196
|
+
spatialDenoiserEnabled: (t == null ? void 0 : t.spatialDenoiserEnabled) !== !1,
|
|
2197
|
+
fsrEasuEnabled: (t == null ? void 0 : t.fsrEasuEnabled) !== !1,
|
|
2198
|
+
fsrRcasEnabled: (t == null ? void 0 : t.fsrRcasEnabled) !== !1,
|
|
2199
|
+
fsrRcasSharpness: Math.max(0, Math.min(2, Number.isFinite(r) ? r : 0.35)),
|
|
2200
|
+
useBvh: (t == null ? void 0 : t.useBvh) !== !1,
|
|
2201
|
+
useEnvCubemap: (t == null ? void 0 : t.useEnvCubemap) !== !1,
|
|
2202
|
+
softSunAngularRadius: typeof s == "number" && Number.isFinite(s) ? Math.max(0, Math.min(0.5, s)) : 4e-3,
|
|
2203
|
+
softSunExtraRay: (t == null ? void 0 : t.softSunExtraRay) === !0,
|
|
2204
|
+
guidedDenoise: (t == null ? void 0 : t.guidedDenoise) !== !1,
|
|
2205
|
+
denoiserFireflySuppress: (t == null ? void 0 : t.denoiserFireflySuppress) !== !1,
|
|
2206
|
+
ggxReflection: (t == null ? void 0 : t.ggxReflection) !== !1,
|
|
2207
|
+
pathTraceTriangleBudget: Math.max(0, Math.floor((t == null ? void 0 : t.pathTraceTriangleBudget) ?? 0)),
|
|
2208
|
+
realtimeTargetFps: Math.max(0, Math.floor((t == null ? void 0 : t.realtimeTargetFps) ?? 0)),
|
|
2209
|
+
envIblIntensity: (() => {
|
|
2210
|
+
const c = t == null ? void 0 : t.envIblIntensity;
|
|
2211
|
+
return typeof c == "number" && Number.isFinite(c) ? Math.max(0.05, Math.min(8, c)) : 1;
|
|
2212
|
+
})(),
|
|
2213
|
+
emissiveIntensity: (() => {
|
|
2214
|
+
const c = t == null ? void 0 : t.emissiveIntensity;
|
|
2215
|
+
return typeof c == "number" && Number.isFinite(c) ? Math.max(0, Math.min(20, c)) : 1;
|
|
2216
|
+
})(),
|
|
2217
|
+
emissiveBounceScale: (() => {
|
|
2218
|
+
const c = t == null ? void 0 : t.emissiveBounceScale;
|
|
2219
|
+
return typeof c == "number" && Number.isFinite(c) ? Math.max(0, Math.min(5, c)) : 1;
|
|
2220
|
+
})(),
|
|
2221
|
+
denoiserAlgorithm: o,
|
|
2222
|
+
atrousBlend: typeof i == "number" && Number.isFinite(i) ? Math.max(0.05, Math.min(1, i)) : 0.45,
|
|
2223
|
+
transparentBackground: (t == null ? void 0 : t.transparentBackground) === !0,
|
|
2224
|
+
unlitAsDiffuse: (t == null ? void 0 : t.unlitMode) === "diffuse",
|
|
2225
|
+
progressiveSpatial: (t == null ? void 0 : t.progressiveSpatial) !== !1,
|
|
2226
|
+
maxBounces: is((t == null ? void 0 : t.maxBounces) ?? 4),
|
|
2227
|
+
aovDebugView: (() => {
|
|
2228
|
+
const c = t == null ? void 0 : t.aovDebugView;
|
|
2229
|
+
return c === "albedo" || c === "normal" || c === "depth" || c === "objectId" ? c : "off";
|
|
2230
|
+
})(),
|
|
2231
|
+
hybridReflRoughnessMax: Ti(t == null ? void 0 : t.hybridReflRoughnessMax),
|
|
2232
|
+
hybridAoRadius: bi(t == null ? void 0 : t.hybridAoRadius),
|
|
2233
|
+
hybridLightRadius: yi(t == null ? void 0 : t.hybridLightRadius)
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
function bi(t) {
|
|
2237
|
+
return typeof t != "number" || !Number.isFinite(t) ? 1 : Math.max(0, Math.min(10, t));
|
|
2238
|
+
}
|
|
2239
|
+
function yi(t) {
|
|
2240
|
+
return typeof t != "number" || !Number.isFinite(t) ? 0 : Math.max(0, Math.min(5, t));
|
|
2241
|
+
}
|
|
2242
|
+
function Ti(t) {
|
|
2243
|
+
return typeof t != "number" || !Number.isFinite(t) || t <= 0 ? 0.5 : Math.min(1, t);
|
|
2244
|
+
}
|
|
2245
|
+
function Pt(t) {
|
|
2246
|
+
const e = new Float32Array(1);
|
|
2247
|
+
return e[0] = t, new Uint32Array(e.buffer)[0];
|
|
2248
|
+
}
|
|
2249
|
+
function ya(t) {
|
|
2250
|
+
return Math.max(0.25, Math.min(1, t));
|
|
2251
|
+
}
|
|
2252
|
+
function wr(t, e, a) {
|
|
2253
|
+
const r = typeof globalThis < "u" ? globalThis.__W3DTS_PATH_TRACER_CONFIG : void 0;
|
|
2254
|
+
let s;
|
|
2255
|
+
return a ? typeof (r == null ? void 0 : r.pathTraceResolutionScale) == "number" && Number.isFinite(r.pathTraceResolutionScale) ? s = ya(r.pathTraceResolutionScale) : typeof (r == null ? void 0 : r.resolutionScale) == "number" && Number.isFinite(r.resolutionScale) ? s = ya(r.resolutionScale) : s = 1 : s = typeof (r == null ? void 0 : r.resolutionScale) == "number" && Number.isFinite(r.resolutionScale) ? ya(r.resolutionScale) : 1, s < 1 ? {
|
|
2256
|
+
w: Math.max(1, Math.floor(t * s)),
|
|
2257
|
+
h: Math.max(1, Math.floor(e * s))
|
|
2258
|
+
} : { w: t, h: e };
|
|
2259
|
+
}
|
|
2260
|
+
function _a() {
|
|
2261
|
+
if ((typeof globalThis < "u" ? globalThis.__W3DTS_ACTIVE_PROJECT ?? "" : "") !== "PathTracerStudio") return null;
|
|
2262
|
+
const e = Us();
|
|
2263
|
+
if (e !== "pathtrace" && e !== "hybrid") return null;
|
|
2264
|
+
const a = zs();
|
|
2265
|
+
return a.width <= 0 || a.height <= 0 ? null : { baseW: a.width, baseH: a.height };
|
|
2266
|
+
}
|
|
2267
|
+
function hs(t, e) {
|
|
2268
|
+
const a = _a();
|
|
2269
|
+
if (a)
|
|
2270
|
+
return wr(
|
|
2271
|
+
a.baseW,
|
|
2272
|
+
a.baseH,
|
|
2273
|
+
e
|
|
2274
|
+
);
|
|
2275
|
+
const r = t.webGPUContext.canvas.width, s = t.webGPUContext.canvas.height;
|
|
2276
|
+
return wr(r, s, e);
|
|
2277
|
+
}
|
|
2278
|
+
function gi(t, e) {
|
|
2279
|
+
for (const a of [t.renderGraph, t.gameRenderGraph]) {
|
|
2280
|
+
const r = a.getPasses().find((c) => c.name === "04e_HybridDenoisedSelect");
|
|
2281
|
+
if (!r || r.type !== "fullscreen" || !r.uniforms) continue;
|
|
2282
|
+
const s = r.uniforms.useDenoised;
|
|
2283
|
+
if (!s) continue;
|
|
2284
|
+
const n = a.getTexture("sceneColor"), o = a.getTexture("hybridDenoisedBeauty"), i = n != null && o != null && n.width > 1 && n.width === o.width && n.height === o.height;
|
|
2285
|
+
s.value = e > 0 && i ? 1 : 0;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
function us(t) {
|
|
2289
|
+
typeof globalThis > "u" || (globalThis.__W3DTS_PATH_TRACER_PROGRESS__ = t);
|
|
2290
|
+
}
|
|
2291
|
+
function Mi(t) {
|
|
2292
|
+
const e = ls(), a = e.maxSamples, r = Math.max(1, e.progressiveFrameStride), s = hs(t, !1), n = s.w, o = s.h, i = e.tileSize, c = Math.max(1, Math.ceil(n / i)), l = Math.max(1, Math.ceil(o / i)), u = c * l;
|
|
2293
|
+
return {
|
|
2294
|
+
progress: 0,
|
|
2295
|
+
progressPercent: 0,
|
|
2296
|
+
samplesDone: 0,
|
|
2297
|
+
samplesTotal: u * a,
|
|
2298
|
+
tileIndex: 0,
|
|
2299
|
+
totalTiles: u,
|
|
2300
|
+
gridCols: c,
|
|
2301
|
+
gridRows: l,
|
|
2302
|
+
accumFrameIndex: 0,
|
|
2303
|
+
maxSamples: a,
|
|
2304
|
+
converged: !1,
|
|
2305
|
+
traceThisFrame: !0,
|
|
2306
|
+
progressiveStride: r,
|
|
2307
|
+
estimatedSecondsRemaining: null,
|
|
2308
|
+
sceneWidth: n,
|
|
2309
|
+
sceneHeight: o,
|
|
2310
|
+
progressiveSpatial: e.progressiveSpatial !== !1
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
function Si(t) {
|
|
2314
|
+
typeof globalThis > "u" || globalThis.__W3DTS_PATH_TRACER_PROGRESS__ !== void 0 || us(Mi(t));
|
|
2315
|
+
}
|
|
2316
|
+
const fs = "__W3DTS_PATH_TRACER_ACCUM_PAUSED__";
|
|
2317
|
+
function Ai() {
|
|
2318
|
+
return typeof globalThis > "u" ? !1 : globalThis[fs] === !0;
|
|
2319
|
+
}
|
|
2320
|
+
function yc(t) {
|
|
2321
|
+
typeof globalThis > "u" || (globalThis[fs] = t);
|
|
2322
|
+
}
|
|
2323
|
+
function vi(t, e) {
|
|
2324
|
+
if (e <= 0) return 2166136261;
|
|
2325
|
+
const a = e >>> 2, r = new Uint32Array(t, 0, a);
|
|
2326
|
+
let s = 2166136261;
|
|
2327
|
+
for (let n = 0; n < r.length; n++)
|
|
2328
|
+
s ^= r[n], s = Math.imul(s, 16777619);
|
|
2329
|
+
return s >>> 0;
|
|
2330
|
+
}
|
|
2331
|
+
class ds {
|
|
2332
|
+
constructor() {
|
|
2333
|
+
/** Phase 0 progressive-plan baseline; published on `__W3DTS_PATH_TRACER_BASELINE__` each tick. */
|
|
2334
|
+
y(this, "baselineMetrics", new ao());
|
|
2335
|
+
/** Phase 1a: skip triangle+BVH rebuild when render-queue fingerprint is unchanged. */
|
|
2336
|
+
y(this, "sceneCache", new wo());
|
|
2337
|
+
/**
|
|
2338
|
+
* Per graph: scene data + destination buffers of the last triangle/BVH/instance upload.
|
|
2339
|
+
* These buffers reach tens of MB; re-uploading them every frame stalls the GPU queue.
|
|
2340
|
+
*/
|
|
2341
|
+
y(this, "uploadedScenePerGraph", /* @__PURE__ */ new WeakMap());
|
|
2342
|
+
y(this, "lastCameraPosition", Ft());
|
|
2343
|
+
y(this, "lastCameraForward", Ft());
|
|
2344
|
+
y(this, "lastCameraLens", null);
|
|
2345
|
+
y(this, "hasLastCamera", !1);
|
|
2346
|
+
y(this, "lastViewProj", new Float32Array(16));
|
|
2347
|
+
y(this, "hasHybridViewProj", !1);
|
|
2348
|
+
y(this, "hybridStaticFrames", 0);
|
|
2349
|
+
y(this, "hybridBeautyW", -1);
|
|
2350
|
+
y(this, "hybridBeautyH", -1);
|
|
2351
|
+
y(this, "lastResetReasons", []);
|
|
2352
|
+
y(this, "resetCounts", {});
|
|
2353
|
+
y(this, "lastTriangleHash", 0);
|
|
2354
|
+
y(this, "lastLightHash", 0);
|
|
2355
|
+
y(this, "hasLightHash", !1);
|
|
2356
|
+
y(this, "lastEmissiveHash", null);
|
|
2357
|
+
y(this, "lastShadowsEnabled", !1);
|
|
2358
|
+
y(this, "frameIndex", 0);
|
|
2359
|
+
/** Full-frame samples in spatial mode. Independent of the current stride. */
|
|
2360
|
+
y(this, "sppCoverage", 0);
|
|
2361
|
+
/** Unique seed per traced pass (uploaded as pathTracerParams[2]). */
|
|
2362
|
+
y(this, "rngFrame", 0);
|
|
2363
|
+
y(this, "lastEnableGI", !0);
|
|
2364
|
+
y(this, "lastEnableAO", !0);
|
|
2365
|
+
y(this, "lastEnableReflection", !0);
|
|
2366
|
+
y(this, "lastEnableShadow", !0);
|
|
2367
|
+
y(this, "pathTracerLightEntityId", null);
|
|
2368
|
+
/** Phase within progressiveFrameStride; trace when phase === 0. */
|
|
2369
|
+
y(this, "progressivePhase", 0);
|
|
2370
|
+
/** When true, trace resolution uses pathTraceResolutionScale (or resolutionScale) vs full canvas; Engine may stay full res (hybrid). */
|
|
2371
|
+
y(this, "decoupleTraceResolution", !1);
|
|
2372
|
+
/** Beauty path trace, or hybrid AOVs (full frame, no Bayer, no FSR). */
|
|
2373
|
+
y(this, "traceMode", "beauty");
|
|
2374
|
+
/** Bucket index for legacy tile rendering; unused when Phase 2 progressiveSpatial is on. */
|
|
2375
|
+
y(this, "tileIndex", 0);
|
|
2376
|
+
y(this, "lastSceneW", -1);
|
|
2377
|
+
y(this, "lastSceneH", -1);
|
|
2378
|
+
/** Phase 2: Bayer phase within stride² and spatial budget controller. */
|
|
2379
|
+
y(this, "interleavePhase", 0);
|
|
2380
|
+
y(this, "spatialBudget", new qo(2));
|
|
2381
|
+
y(this, "lastFrameWallMs", 0);
|
|
2382
|
+
/** Phase 3: Interactive → Refining → Converged (+ Denoised later). */
|
|
2383
|
+
y(this, "progressiveState", new ni());
|
|
2384
|
+
/**
|
|
2385
|
+
* When true, TileComposite skips beauty writes (keep last frame).
|
|
2386
|
+
* Not used for live camera orbit — that clears the composite instead so the Game view tracks the lens.
|
|
2387
|
+
*/
|
|
2388
|
+
y(this, "holdDisplayUntilRound", !1);
|
|
2389
|
+
y(this, "holdRoundStartPhase", 0);
|
|
2390
|
+
/** EWMA of "samples" per second for ETA (tile×sample units). */
|
|
2391
|
+
y(this, "ewmaSamplesPerSec", 0);
|
|
2392
|
+
y(this, "lastEwmaSampleDone", -1);
|
|
2393
|
+
y(this, "lastEwmaWallMs", 0);
|
|
2394
|
+
/**
|
|
2395
|
+
* Last {@link Renderer.getEnvironmentCubemap} used for path miss / IBL when `useEnvCubemap` is on.
|
|
2396
|
+
* When HDR / IBL cubemap is swapped, reference changes → reset accumulation (Path Tracer Studio, etc.).
|
|
2397
|
+
*/
|
|
2398
|
+
y(this, "lastEnvironmentCubemap", null);
|
|
2399
|
+
/** Last synced IBL scale; changing it must reset progressive accumulation or the image looks unchanged. */
|
|
2400
|
+
y(this, "lastEnvIblIntensity", Number.NaN);
|
|
2401
|
+
/** Last synced emissive radiance and bounce scales. */
|
|
2402
|
+
y(this, "lastEmissiveIntensity", Number.NaN);
|
|
2403
|
+
y(this, "lastEmissiveBounceScale", Number.NaN);
|
|
2404
|
+
/** Last transparent-background flag; toggling resets accumulation. */
|
|
2405
|
+
y(this, "lastTransparentBackground", !1);
|
|
2406
|
+
/** Last unlit-mode override (`false` = Khronos unlit, `true` = diffuse relight). */
|
|
2407
|
+
y(this, "lastUnlitAsDiffuse", !1);
|
|
2408
|
+
/** Last uploaded triangle stats (kept on stride-off frames so HUD does not flicker to 0). */
|
|
2409
|
+
y(this, "lastTriangleStats", {
|
|
2410
|
+
count: 0,
|
|
2411
|
+
demand: 0,
|
|
2412
|
+
cap: Vt
|
|
2413
|
+
});
|
|
2414
|
+
y(this, "matFactorsPad", new Float32Array(yt));
|
|
2415
|
+
y(this, "materialTextureArrays", new Go());
|
|
2416
|
+
y(this, "tileInfoScratch", new Uint32Array(16));
|
|
2417
|
+
y(this, "denoiserParamsScratch", new Uint32Array(8));
|
|
2418
|
+
y(this, "paramsScratch", new Uint32Array(kr));
|
|
2419
|
+
y(this, "envEmptyHeader", new Float32Array(4));
|
|
2420
|
+
y(this, "envWrittenSerial", /* @__PURE__ */ new WeakMap());
|
|
2421
|
+
y(this, "postParamsScratch", new Float32Array(ts));
|
|
2422
|
+
y(this, "fsrParamsScratch");
|
|
2423
|
+
y(this, "fsrParamsDataView");
|
|
2424
|
+
y(this, "fsrEasuFloats");
|
|
2425
|
+
this.fsrParamsScratch = new ArrayBuffer(ga), this.fsrParamsDataView = new DataView(this.fsrParamsScratch), this.fsrEasuFloats = new Float32Array(this.fsrParamsScratch, 0, 16);
|
|
2426
|
+
}
|
|
2427
|
+
/** Directional light entity used for sun color / intensity / shadow flag in the compute shader. */
|
|
2428
|
+
setPreferredLightEntity(e) {
|
|
2429
|
+
this.pathTracerLightEntityId = e;
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Hybrid Lit + PT: raster at full viewport; path trace uses {@link computePathTracerTracePixelDimensions} with
|
|
2433
|
+
* `pathTraceResolutionScale` when set.
|
|
2434
|
+
*/
|
|
2435
|
+
setDecoupleTraceResolution(e) {
|
|
2436
|
+
this.decoupleTraceResolution = e;
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* `hybridAov` traces the full frame for the raster AOVs: stride 1, no PathTrace / FSR / bloom.
|
|
2440
|
+
* Switching mode clears the accumulation so the toolbar spp matches the new buffers.
|
|
2441
|
+
*/
|
|
2442
|
+
setTraceMode(e) {
|
|
2443
|
+
this.traceMode !== e && (this.traceMode = e, this.resetAccumulationState());
|
|
2444
|
+
}
|
|
2445
|
+
/** Phase 1a cache stats (rebuild vs hit) for debugging / baseline. */
|
|
2446
|
+
getSceneCacheStats() {
|
|
2447
|
+
return this.sceneCache.getStats();
|
|
2448
|
+
}
|
|
2449
|
+
resetAccumulationState() {
|
|
2450
|
+
this.sceneCache.clear(), this.hasLastCamera = !1, this.hasHybridViewProj = !1, this.hybridStaticFrames = 0, this.lastTriangleHash = 0, this.lastLightHash = 0, this.hasLightHash = !1, this.lastEmissiveHash = null, this.frameIndex = 0, this.sppCoverage = 0, this.rngFrame = 0, this.progressivePhase = 0, this.tileIndex = 0, this.interleavePhase = 0, this.spatialBudget.reset(), this.lastFrameWallMs = 0, this.progressiveState.reset(), ba(), this.holdDisplayUntilRound = !1, this.holdRoundStartPhase = 0, this.lastSceneW = -1, this.lastSceneH = -1, this.ewmaSamplesPerSec = 0, this.lastEwmaSampleDone = -1, this.lastEwmaWallMs = 0, this.lastEnvironmentCubemap = null, this.lastEnvIblIntensity = Number.NaN, this.lastEmissiveIntensity = Number.NaN, this.lastEmissiveBounceScale = Number.NaN, this.lastTransparentBackground = !1, this.lastUnlitAsDiffuse = !1, this.lastResetReasons = [], this.resetCounts = {};
|
|
2451
|
+
}
|
|
2452
|
+
tick(e) {
|
|
2453
|
+
var Xa;
|
|
2454
|
+
Si(e);
|
|
2455
|
+
const {
|
|
2456
|
+
maxSamples: a,
|
|
2457
|
+
mirrorBouncesWhenStatic: r,
|
|
2458
|
+
progressiveFrameStride: s,
|
|
2459
|
+
tileSize: n,
|
|
2460
|
+
enableGI: o,
|
|
2461
|
+
enableAO: i,
|
|
2462
|
+
enableReflection: c,
|
|
2463
|
+
enableShadow: l,
|
|
2464
|
+
denoiserKernelRadius: u,
|
|
2465
|
+
spatialDenoiserEnabled: h,
|
|
2466
|
+
fsrEasuEnabled: f,
|
|
2467
|
+
fsrRcasEnabled: m,
|
|
2468
|
+
fsrRcasSharpness: g,
|
|
2469
|
+
useBvh: p,
|
|
2470
|
+
useEnvCubemap: T,
|
|
2471
|
+
softSunAngularRadius: b,
|
|
2472
|
+
softSunExtraRay: A,
|
|
2473
|
+
guidedDenoise: M,
|
|
2474
|
+
denoiserFireflySuppress: x,
|
|
2475
|
+
ggxReflection: P,
|
|
2476
|
+
pathTraceTriangleBudget: v,
|
|
2477
|
+
realtimeTargetFps: w,
|
|
2478
|
+
envIblIntensity: d,
|
|
2479
|
+
emissiveIntensity: S,
|
|
2480
|
+
emissiveBounceScale: _,
|
|
2481
|
+
denoiserAlgorithm: I,
|
|
2482
|
+
atrousBlend: C,
|
|
2483
|
+
transparentBackground: F,
|
|
2484
|
+
unlitAsDiffuse: R,
|
|
2485
|
+
progressiveSpatial: B,
|
|
2486
|
+
maxBounces: H,
|
|
2487
|
+
aovDebugView: L,
|
|
2488
|
+
hybridReflRoughnessMax: Q,
|
|
2489
|
+
hybridAoRadius: tt,
|
|
2490
|
+
hybridLightRadius: W
|
|
2491
|
+
} = ls(), z = sr(), V = (z == null ? void 0 : z.maxRadiance) ?? 0;
|
|
2492
|
+
this.progressiveState.setMaxBouncesCap(H);
|
|
2493
|
+
const D = this.traceMode === "hybridAov", et = B || D ? 1 : Math.max(1, s), Z = Ai();
|
|
2494
|
+
let k = !Z && this.progressivePhase === 0;
|
|
2495
|
+
Z || (this.progressivePhase = (this.progressivePhase + 1) % et);
|
|
2496
|
+
const wt = typeof performance < "u" ? performance.now() : 0;
|
|
2497
|
+
!Z && B && !D && this.lastFrameWallMs > 0 && this.spatialBudget.tick(wt - this.lastFrameWallMs), this.lastFrameWallMs = wt;
|
|
2498
|
+
const lt = D || !B ? 1 : this.spatialBudget.getStride(), Yt = v > 0 ? Math.min(Vt, v >>> 0) : Vt, E = k ? this.sceneCache.buildOrReuse(e.renderQueue, e.renderList, Yt) : null, jt = (E == null ? void 0 : E.data) ?? new ArrayBuffer(0), ne = (E == null ? void 0 : E.triangleCount) ?? 0;
|
|
2499
|
+
E && (this.lastTriangleStats = {
|
|
2500
|
+
count: E.triangleCount,
|
|
2501
|
+
demand: E.sceneTriangleDemand,
|
|
2502
|
+
cap: Yt
|
|
2503
|
+
});
|
|
2504
|
+
const Gt = this.sceneCache.getStats().lastFingerprint, qt = hs(e, this.decoupleTraceResolution), ot = qt.w, ct = qt.h, Ut = Math.max(1, Math.ceil(ot / n)), Xt = Math.max(1, Math.ceil(ct / n)), It = Ut * Xt;
|
|
2505
|
+
let Y = 0;
|
|
2506
|
+
const at = [];
|
|
2507
|
+
let J = !1, Bt = !1, Nt = !1;
|
|
2508
|
+
(ot !== this.lastSceneW || ct !== this.lastSceneH) && (this.lastSceneW = ot, this.lastSceneH = ct, Y = 1, at.push("resize"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1);
|
|
2509
|
+
const O = e.renderer.getEnvironmentCubemap(), nt = T ? O : null;
|
|
2510
|
+
nt !== this.lastEnvironmentCubemap && (Y = 1, at.push("environment"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastEnvironmentCubemap = nt, Number.isFinite(this.lastEnvIblIntensity) && Math.abs(d - this.lastEnvIblIntensity) > 1e-5 && (Y = 1, at.push("envIntensity"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastEnvIblIntensity = d, (Number.isFinite(this.lastEmissiveIntensity) && Math.abs(S - this.lastEmissiveIntensity) > 1e-5 || Number.isFinite(this.lastEmissiveBounceScale) && Math.abs(_ - this.lastEmissiveBounceScale) > 1e-5) && (Y = 1, at.push("emissiveIntensity"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastEmissiveIntensity = S, this.lastEmissiveBounceScale = _, F !== this.lastTransparentBackground && (Y = 1, at.push("background"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastTransparentBackground = F, R !== this.lastUnlitAsDiffuse && (Y = 1, at.push("features"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastUnlitAsDiffuse = R;
|
|
2511
|
+
const j = (E == null ? void 0 : E.triangleDataBytes) ?? 0;
|
|
2512
|
+
if (k && Gt !== this.lastTriangleHash) {
|
|
2513
|
+
const q = Gt !== 0 ? Gt : vi(jt, j);
|
|
2514
|
+
Y = 1, at.push("scene"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1, this.lastTriangleHash = q;
|
|
2515
|
+
}
|
|
2516
|
+
const La = Io(No(e.ecsWorld));
|
|
2517
|
+
if (this.hasLightHash && La !== this.lastLightHash && (Y = 1, at.push("lights"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastLightHash = La, this.hasLightHash = !0, k && E) {
|
|
2518
|
+
const N = go(
|
|
2519
|
+
E.emissiveCount,
|
|
2520
|
+
E.emissiveTotalPower
|
|
2521
|
+
);
|
|
2522
|
+
this.lastEmissiveHash !== null && N !== this.lastEmissiveHash && (Y = 1, at.push("scene"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1), this.lastEmissiveHash = N;
|
|
2523
|
+
}
|
|
2524
|
+
const Ss = _a() != null ? e.getGameCameraEntityId() : null, ke = (D ? e.getGameCameraEntityId() : null) ?? Ss ?? e.cameraControllerManager.getCameraEntity();
|
|
2525
|
+
if (ke !== null) {
|
|
2526
|
+
const N = e.ecsWorld.getComponent(ke, bt);
|
|
2527
|
+
if (N) {
|
|
2528
|
+
const q = N.position, rt = N.worldTransform, it = Te(-rt[8], -rt[9], -rt[10]);
|
|
2529
|
+
pe(it, it);
|
|
2530
|
+
const Ht = typeof globalThis < "u" && globalThis.__W3DTS_E2E_LOCK_PATHTRACER_STUDIO_PATHTRACE__ === !0, ht = e.ecsWorld.getComponent(ke, Gs), oe = ht != null && this.lastCameraLens != null && hi(this.lastCameraLens, ht);
|
|
2531
|
+
if (ht && (this.lastCameraLens = li(ht)), this.hasLastCamera) {
|
|
2532
|
+
const Dt = qs(q, this.lastCameraPosition), vt = Or(it, this.lastCameraForward), Jt = D ? Cr : ui, Qt = D ? Fr : fi;
|
|
2533
|
+
if (D && (Dt > Cr || 1 - vt > Fr || oe) && (Nt = !0), !D && !Ht && (Dt > Jt || 1 - vt > Qt || oe)) {
|
|
2534
|
+
Y = 1, at.push("camera"), Bt = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1, this.holdRoundStartPhase = 0;
|
|
2535
|
+
const Pe = typeof performance < "u" ? performance.now() : 0;
|
|
2536
|
+
this.baselineMetrics.markInteractive(Pe);
|
|
2537
|
+
}
|
|
2538
|
+
} else
|
|
2539
|
+
Y = 1, at.push("cameraInit"), J = !0, this.tileIndex = 0, this.holdDisplayUntilRound = !1;
|
|
2540
|
+
if (tr(this.lastCameraPosition, q), tr(this.lastCameraForward, it), this.hasLastCamera = !0, ht) {
|
|
2541
|
+
const Dt = ht.viewProjectionMatrix;
|
|
2542
|
+
if (this.hasHybridViewProj)
|
|
2543
|
+
for (let vt = 0; vt < 16; vt++)
|
|
2544
|
+
Math.abs(Dt[vt] - this.lastViewProj[vt]) > 1e-3 && (Nt = !0);
|
|
2545
|
+
this.lastViewProj.set(Dt), this.hasHybridViewProj = !0;
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
let Me = !1, zt = null;
|
|
2550
|
+
if (this.pathTracerLightEntityId !== null) {
|
|
2551
|
+
const N = e.ecsWorld.getComponent(
|
|
2552
|
+
this.pathTracerLightEntityId,
|
|
2553
|
+
ye
|
|
2554
|
+
);
|
|
2555
|
+
N && (zt = N);
|
|
2556
|
+
}
|
|
2557
|
+
if (!zt) {
|
|
2558
|
+
const N = e.ecsWorld.query([
|
|
2559
|
+
ye
|
|
2560
|
+
]);
|
|
2561
|
+
for (const [, [q]] of N.iter()) {
|
|
2562
|
+
if (q.shadowsEnabled) {
|
|
2563
|
+
zt = q;
|
|
2564
|
+
break;
|
|
2565
|
+
}
|
|
2566
|
+
zt || (zt = q);
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
zt && (Me = zt.shadowsEnabled), Me !== this.lastShadowsEnabled && (Y = 1, at.push("shadows"), J = !0, this.tileIndex = 0, this.lastShadowsEnabled = Me), (o !== this.lastEnableGI || i !== this.lastEnableAO || c !== this.lastEnableReflection || l !== this.lastEnableShadow) && (Y = 1, at.push("features"), J = !0, this.tileIndex = 0, this.lastEnableGI = o, this.lastEnableAO = i, this.lastEnableReflection = c, this.lastEnableShadow = l), !B && !D && !J && k && this.frameIndex >= a && this.tileIndex < It - 1 && (this.tileIndex++, Y = 1, at.push("tile"));
|
|
2570
|
+
const As = J || Bt ? 1 : 0;
|
|
2571
|
+
if (Y === 1) {
|
|
2572
|
+
this.lastResetReasons = at;
|
|
2573
|
+
for (const N of at)
|
|
2574
|
+
this.resetCounts[N] = (this.resetCounts[N] ?? 0) + 1;
|
|
2575
|
+
this.frameIndex = 0, this.sppCoverage = 0, this.rngFrame = 0, this.interleavePhase = 0, Bt && B && (this.holdRoundStartPhase = 0);
|
|
2576
|
+
}
|
|
2577
|
+
k && (B || D ? (this.interleavePhase += 1, this.sppCoverage = Vo(this.sppCoverage, lt), this.rngFrame = this.interleavePhase, this.holdDisplayUntilRound && Yo(lt, this.interleavePhase - this.holdRoundStartPhase) && (this.holdDisplayUntilRound = !1)) : (this.frameIndex++, this.rngFrame = this.frameIndex, this.holdDisplayUntilRound = !1));
|
|
2578
|
+
const vs = Y === 1 ? 0 : r, Ha = J || Bt;
|
|
2579
|
+
if ((Ha || D && Nt) && (this.progressiveState.tick({ interaction: !0, converged: !1 }), ba(), typeof globalThis < "u" && (globalThis.__W3DTS_PATH_TRACER_FINAL_DENOISED__ = !1)), D) {
|
|
2580
|
+
const N = e.gameRenderGraph.getTexture("sceneColor"), q = (N == null ? void 0 : N.width) ?? 0, rt = (N == null ? void 0 : N.height) ?? 0;
|
|
2581
|
+
(q !== this.hybridBeautyW || rt !== this.hybridBeautyH) && (this.hybridBeautyW > 0 && ba(), typeof globalThis < "u" && (globalThis.__W3DTS_PATH_TRACER_FINAL_DENOISED__ = !1)), this.hybridBeautyW = q, this.hybridBeautyH = rt;
|
|
2582
|
+
const Ht = q < 2 || rt < 2;
|
|
2583
|
+
this.hybridStaticFrames = ci(
|
|
2584
|
+
this.hybridStaticFrames,
|
|
2585
|
+
Nt || Ht,
|
|
2586
|
+
Y === 1
|
|
2587
|
+
);
|
|
2588
|
+
const ht = typeof globalThis < "u" && globalThis.__W3DTS_PATH_TRACER_FINAL_DENOISED__ === !0;
|
|
2589
|
+
gi(e, ht ? 1 : 0);
|
|
2590
|
+
}
|
|
2591
|
+
const Da = !D && typeof globalThis < "u" && globalThis.__W3DTS_PATH_TRACER_FINAL_DENOISED__ === !0;
|
|
2592
|
+
if (!D) {
|
|
2593
|
+
const N = {
|
|
2594
|
+
PREVIEW_MODE: this.progressiveState.isPreview(),
|
|
2595
|
+
MAX_BOUNCES: this.progressiveState.getMaxBounces()
|
|
2596
|
+
};
|
|
2597
|
+
e.renderGraph.setComputePassConstants("PathTrace", N), e.gameRenderGraph.setComputePassConstants("PathTrace", N);
|
|
2598
|
+
}
|
|
2599
|
+
const Oa = !h || I === "off", Ga = h && I === "atrous", xs = h && I === "spatial", Ua = B && lt > 1, $e = Y === 1 || Oa || Ga || !xs || Ua ? 1 : 0, _s = M && $e === 0 ? 1 : 0, Es = x && $e === 0 ? 1 : 0, Ps = Ga && !Oa && !Ua ? 1 : 0;
|
|
2600
|
+
this.denoiserParamsScratch[0] = $e, this.denoiserParamsScratch[1] = u, this.denoiserParamsScratch[2] = _s, this.denoiserParamsScratch[3] = Es, this.denoiserParamsScratch[4] = Ps, this.denoiserParamsScratch[5] = Pt(C), this.denoiserParamsScratch[6] = 0, this.denoiserParamsScratch[7] = 0;
|
|
2601
|
+
const Rs = l && Me, za = Wo(lt, Math.max(0, this.interleavePhase - 1));
|
|
2602
|
+
let Se, Ae, ve, xe;
|
|
2603
|
+
if (B || D)
|
|
2604
|
+
Se = 0, Ae = 0, ve = ot, xe = ct, this.tileIndex = 0;
|
|
2605
|
+
else {
|
|
2606
|
+
const N = this.tileIndex % Ut, q = Math.floor(this.tileIndex / Ut);
|
|
2607
|
+
Se = N * n, Ae = q * n, ve = Math.min(n, Math.max(0, ot - Se)), xe = Math.min(n, Math.max(0, ct - Ae));
|
|
2608
|
+
}
|
|
2609
|
+
const Wa = D || !B ? null : $o(ve, xe, lt);
|
|
2610
|
+
if (!D)
|
|
2611
|
+
e.renderGraph.setComputePassWorkgroupCount("PathTrace", Wa), e.gameRenderGraph.setComputePassWorkgroupCount("PathTrace", Wa);
|
|
2612
|
+
else {
|
|
2613
|
+
const N = e.gameRenderGraph.getTexture("hybridShadowAov"), q = (N == null ? void 0 : N.width) ?? ot, rt = (N == null ? void 0 : N.height) ?? ct, it = Y === 1 ? 1 : pi(), Ht = Math.max(1, Math.ceil(q * it)), ht = Math.max(1, Math.ceil(rt * it));
|
|
2614
|
+
e.gameRenderGraph.setComputePassWorkgroupCount("HybridPrimaryAov", [
|
|
2615
|
+
Math.ceil(Ht / 8),
|
|
2616
|
+
Math.ceil(ht / 8),
|
|
2617
|
+
1
|
|
2618
|
+
]);
|
|
2619
|
+
}
|
|
2620
|
+
this.tileInfoScratch.fill(0), this.tileInfoScratch[0] = Se, this.tileInfoScratch[1] = Ae, this.tileInfoScratch[2] = ot, this.tileInfoScratch[3] = ct, this.tileInfoScratch[4] = ve, this.tileInfoScratch[5] = xe, this.tileInfoScratch[6] = As, this.tileInfoScratch[7] = B && this.holdDisplayUntilRound && !J ? 1 : 0, this.tileInfoScratch[Xo] = B && !D ? lt : 1, this.tileInfoScratch[Ko] = B && !D ? za.ox : 0, this.tileInfoScratch[Zo] = B && !D ? za.oy : 0, this.tileInfoScratch[Jo] = B || D ? 1 : 0, this.tileInfoScratch[Qo] = ri(L), this.tileInfoScratch[ti] = Da ? 1 : 0, this.tileInfoScratch[ei] = D ? Pt(Q) : 0, this.tileInfoScratch[ai] = D ? Pt(20) : 0;
|
|
2621
|
+
let St = 0;
|
|
2622
|
+
p && (E != null && E.bvh) && E.bvh.nodeCount > 0 && (St |= bn), p && (E != null && E.useTwoLevel) && (E.instanceCount ?? 0) > 0 && (St |= vn), T && O && (St |= yn), b > 0 && (St |= Tn), A && (St |= Mn), M && (St |= gn), P && (St |= Sn), F && (St |= An), R && (St |= xn);
|
|
2623
|
+
const ka = p && (E != null && E.bvh) ? E.bvh.nodeCount >>> 0 : 0, Cs = p && (E != null && E.bvh) && ka > 0 ? E.bvh.rootIndex >>> 0 : 0;
|
|
2624
|
+
this.paramsScratch[0] = Y, this.paramsScratch[1] = Rs ? 1 : 0, this.paramsScratch[2] = this.rngFrame, this.paramsScratch[3] = a, this.paramsScratch[4] = vs, this.paramsScratch[5] = o ? 1 : 0, this.paramsScratch[6] = i ? 1 : 0, this.paramsScratch[7] = c ? 1 : 0, this.paramsScratch[8] = k ? 1 : 0, this.paramsScratch[9] = St >>> 0, this.paramsScratch[10] = ka, this.paramsScratch[11] = Cs, this.paramsScratch[12] = ne >>> 0, this.paramsScratch[13] = Pt(d), this.paramsScratch[14] = ((E == null ? void 0 : E.instanceCount) ?? 0) >>> 0, this.paramsScratch[15] = this.progressiveState.getMaxBounces() >>> 0, this.paramsScratch[16] = Hn(
|
|
2625
|
+
Ln(z ?? void 0, H)
|
|
2626
|
+
), this.paramsScratch[17] = Number.isFinite(V) && V > 0 ? Pt(V) : 0, this.paramsScratch[18] = E != null && E.hasTransmission ? on : 0, this.paramsScratch[19] = Pt(Math.max(b, 0)), this.paramsScratch[20] = Pt(tt), this.paramsScratch[21] = Pt(W), this.paramsScratch[22] = Pt(S - 1), this.paramsScratch[23] = Pt(_ - 1);
|
|
2627
|
+
const Kt = _a(), Fs = (Kt == null ? void 0 : Kt.baseW) ?? e.webGPUContext.canvas.width, ws = (Kt == null ? void 0 : Kt.baseH) ?? e.webGPUContext.canvas.height;
|
|
2628
|
+
to(ot, ct, ot, ct, Fs, ws, this.fsrEasuFloats);
|
|
2629
|
+
const _e = this.fsrParamsDataView;
|
|
2630
|
+
_e.setUint32(64, f ? 1 : 0, !0), _e.setUint32(68, m ? 1 : 0, !0), _e.setFloat32(72, Math.pow(2, -g), !0), _e.setUint32(76, 0, !0);
|
|
2631
|
+
const pt = e.webGPUContext.device.queue;
|
|
2632
|
+
k && E && this.materialTextureArrays.sync(
|
|
2633
|
+
e.webGPUContext.device,
|
|
2634
|
+
E.textureSlots,
|
|
2635
|
+
E.textureSlotFlags
|
|
2636
|
+
);
|
|
2637
|
+
for (const N of [e.renderGraph, e.gameRenderGraph]) {
|
|
2638
|
+
const q = N.getBuffer("sceneTriangles"), rt = N.getBuffer("pathTracerParams"), it = N.getBuffer("pathTracerSunDirection"), Ht = N.getBuffer("pathTracerDenoiserParams"), ht = N.getBuffer("pathTracerFsrParams"), oe = N.getBuffer("pathTracerTexSlotFlags"), Dt = N.getBuffer("pathTracerMatFactors"), vt = N.getBuffer("pathTracerMaterials"), Jt = N.getBuffer("pathTracerBvhNodes"), Qt = N.getBuffer("pathTracerInstances"), Pe = N.getBuffer("pathTracerTileInfo");
|
|
2639
|
+
if (q) {
|
|
2640
|
+
if (k) {
|
|
2641
|
+
const xt = this.uploadedScenePerGraph.get(N), ie = E !== null && ((xt == null ? void 0 : xt.scene) !== E || xt.triangles !== q || xt.bvhNodes !== Jt || xt.instances !== Qt);
|
|
2642
|
+
if (ie && j > 0 && pt.writeBuffer(q, 0, jt, 0, j), E && oe) {
|
|
2643
|
+
const ut = E.textureSlotFlags;
|
|
2644
|
+
pt.writeBuffer(oe, 0, ut.buffer, ut.byteOffset, ut.byteLength);
|
|
2645
|
+
}
|
|
2646
|
+
if (E && Dt && (this.matFactorsPad.fill(0), this.matFactorsPad.set(
|
|
2647
|
+
E.matNormalScales.subarray(0, yt)
|
|
2648
|
+
), pt.writeBuffer(Dt, 0, this.matFactorsPad)), E && vt) {
|
|
2649
|
+
const ut = E.materialTable;
|
|
2650
|
+
pt.writeBuffer(
|
|
2651
|
+
vt,
|
|
2652
|
+
0,
|
|
2653
|
+
ut.buffer,
|
|
2654
|
+
ut.byteOffset,
|
|
2655
|
+
E.materialCount * se * 4
|
|
2656
|
+
);
|
|
2657
|
+
}
|
|
2658
|
+
if (ie && Jt && (E != null && E.bvh) && p && E.bvh.nodeCount > 0) {
|
|
2659
|
+
const ut = E.bvh.nodeCount * 32;
|
|
2660
|
+
pt.writeBuffer(Jt, 0, E.bvh.nodes, 0, ut);
|
|
2661
|
+
}
|
|
2662
|
+
if (ie && Qt && (E != null && E.useTwoLevel) && E.instances && E.instanceCount > 0) {
|
|
2663
|
+
const ut = Math.min(
|
|
2664
|
+
E.instances.byteLength,
|
|
2665
|
+
E.instanceCount * De
|
|
2666
|
+
);
|
|
2667
|
+
pt.writeBuffer(Qt, 0, E.instances, 0, ut);
|
|
2668
|
+
}
|
|
2669
|
+
if (ie && E) {
|
|
2670
|
+
const ut = N.getBuffer("pathTracerEmissive");
|
|
2671
|
+
ut && E.emissiveCatalog && pt.writeBuffer(
|
|
2672
|
+
ut,
|
|
2673
|
+
0,
|
|
2674
|
+
E.emissiveCatalog,
|
|
2675
|
+
0,
|
|
2676
|
+
E.emissiveCatalog.byteLength
|
|
2677
|
+
), this.uploadedScenePerGraph.set(N, {
|
|
2678
|
+
scene: E,
|
|
2679
|
+
triangles: q,
|
|
2680
|
+
bvhNodes: Jt,
|
|
2681
|
+
instances: Qt
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
E && this.materialTextureArrays.bind(N), T && O && N.setOutput("pathTracerEnvCubemap", O);
|
|
2685
|
+
}
|
|
2686
|
+
if (rt && pt.writeBuffer(rt, 0, this.paramsScratch), it) {
|
|
2687
|
+
const xt = Dn();
|
|
2688
|
+
(this.envWrittenSerial.get(it) ?? -1) !== xt.serial && (pt.writeBuffer(it, 0, xt.data ?? this.envEmptyHeader), this.envWrittenSerial.set(it, xt.serial));
|
|
2689
|
+
}
|
|
2690
|
+
Ht && pt.writeBuffer(Ht, 0, this.denoiserParamsScratch), ht && pt.writeBuffer(
|
|
2691
|
+
ht,
|
|
2692
|
+
0,
|
|
2693
|
+
this.fsrParamsScratch,
|
|
2694
|
+
0,
|
|
2695
|
+
ga
|
|
2696
|
+
), Pe && pt.writeBuffer(
|
|
2697
|
+
Pe,
|
|
2698
|
+
0,
|
|
2699
|
+
this.tileInfoScratch.buffer,
|
|
2700
|
+
this.tileInfoScratch.byteOffset,
|
|
2701
|
+
this.tileInfoScratch.byteLength
|
|
2702
|
+
);
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
const $a = Math.max(1, ot * ct);
|
|
2706
|
+
let Lt, At, Zt;
|
|
2707
|
+
if (B || D) {
|
|
2708
|
+
Lt = $a * a;
|
|
2709
|
+
const N = Math.min(this.sppCoverage, a);
|
|
2710
|
+
At = Math.min(Lt, N * $a), Zt = a > 0 && this.sppCoverage >= a;
|
|
2711
|
+
} else {
|
|
2712
|
+
Lt = It * a;
|
|
2713
|
+
const N = Math.min(this.frameIndex, a);
|
|
2714
|
+
At = Math.min(Lt, this.tileIndex * a + N), Zt = a > 0 && this.tileIndex >= It - 1 && this.frameIndex >= a;
|
|
2715
|
+
}
|
|
2716
|
+
const Va = Lt > 0 ? At / Lt : 0, Ee = typeof performance < "u" ? performance.now() : 0;
|
|
2717
|
+
if (J)
|
|
2718
|
+
this.ewmaSamplesPerSec = 0, this.lastEwmaSampleDone = At, this.lastEwmaWallMs = Ee;
|
|
2719
|
+
else if (At > this.lastEwmaSampleDone)
|
|
2720
|
+
if (this.lastEwmaSampleDone < 0)
|
|
2721
|
+
this.lastEwmaSampleDone = At, this.lastEwmaWallMs = Ee;
|
|
2722
|
+
else {
|
|
2723
|
+
const N = (Ee - this.lastEwmaWallMs) / 1e3;
|
|
2724
|
+
if (N > 0.05) {
|
|
2725
|
+
const rt = (At - this.lastEwmaSampleDone) / N;
|
|
2726
|
+
this.ewmaSamplesPerSec = this.ewmaSamplesPerSec <= 0 ? rt : this.ewmaSamplesPerSec * 0.88 + rt * 0.12, this.lastEwmaSampleDone = At, this.lastEwmaWallMs = Ee;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
const Ya = Math.max(0, Lt - At);
|
|
2730
|
+
let Ve = null;
|
|
2731
|
+
if (Zt ? Ve = 0 : Ya > 0 && this.ewmaSamplesPerSec > 1e-6 && (Ve = Ya / this.ewmaSamplesPerSec), !Ha && (this.progressiveState.tick({
|
|
2732
|
+
interaction: !1,
|
|
2733
|
+
converged: Zt,
|
|
2734
|
+
denoised: Da
|
|
2735
|
+
}), !D)) {
|
|
2736
|
+
const N = {
|
|
2737
|
+
PREVIEW_MODE: this.progressiveState.isPreview(),
|
|
2738
|
+
MAX_BOUNCES: this.progressiveState.getMaxBounces()
|
|
2739
|
+
};
|
|
2740
|
+
e.renderGraph.setComputePassConstants("PathTrace", N), e.gameRenderGraph.setComputePassConstants("PathTrace", N);
|
|
2741
|
+
}
|
|
2742
|
+
const ja = this.progressiveState.getPhase(), Is = this.progressiveState.isPreview();
|
|
2743
|
+
this.uploadDisplayPost(e, ja);
|
|
2744
|
+
const qa = {
|
|
2745
|
+
progress: Va,
|
|
2746
|
+
progressPercent: Math.round(Va * 1e3) / 10,
|
|
2747
|
+
samplesDone: At,
|
|
2748
|
+
samplesTotal: Lt,
|
|
2749
|
+
tileIndex: this.tileIndex,
|
|
2750
|
+
totalTiles: It,
|
|
2751
|
+
gridCols: Ut,
|
|
2752
|
+
gridRows: Xt,
|
|
2753
|
+
accumFrameIndex: B || D ? Math.min(a, Math.floor(this.sppCoverage)) : this.frameIndex,
|
|
2754
|
+
maxSamples: a,
|
|
2755
|
+
converged: Zt,
|
|
2756
|
+
traceThisFrame: k,
|
|
2757
|
+
progressiveStride: B ? lt : et,
|
|
2758
|
+
estimatedSecondsRemaining: Ve,
|
|
2759
|
+
sceneWidth: ot,
|
|
2760
|
+
sceneHeight: ct,
|
|
2761
|
+
triangleCount: this.lastTriangleStats.count,
|
|
2762
|
+
sceneTriangleDemand: this.lastTriangleStats.demand,
|
|
2763
|
+
triangleCap: this.lastTriangleStats.cap,
|
|
2764
|
+
bvhNodeCount: (Xa = E == null ? void 0 : E.bvh) == null ? void 0 : Xa.nodeCount,
|
|
2765
|
+
samplesPerSecond: this.ewmaSamplesPerSec > 0 ? this.ewmaSamplesPerSec : void 0,
|
|
2766
|
+
pathTraceTriangleBudget: v > 0 ? v : void 0,
|
|
2767
|
+
realtimeTargetFps: w > 0 ? w : void 0,
|
|
2768
|
+
progressivePhase: ja,
|
|
2769
|
+
previewMode: Is,
|
|
2770
|
+
progressiveSpatial: B,
|
|
2771
|
+
accumPaused: Z,
|
|
2772
|
+
hybridStaticFrames: this.hybridStaticFrames,
|
|
2773
|
+
lastResetReasons: this.lastResetReasons,
|
|
2774
|
+
resetCounts: { ...this.resetCounts }
|
|
2775
|
+
};
|
|
2776
|
+
if (typeof globalThis < "u") {
|
|
2777
|
+
const N = a, q = B ? Math.min(N, Math.floor(this.sppCoverage)) : this.frameIndex;
|
|
2778
|
+
globalThis.__W3DTS_PATH_TRACER_E2E__ = {
|
|
2779
|
+
accumFrameIndex: q,
|
|
2780
|
+
maxSamples: N,
|
|
2781
|
+
converged: Zt,
|
|
2782
|
+
traceThisFrame: k
|
|
2783
|
+
}, us(qa);
|
|
2784
|
+
const rt = typeof performance < "u" ? performance.now() : 0, it = this.baselineMetrics.tick(qa, rt);
|
|
2785
|
+
globalThis.__W3DTS_PATH_TRACER_BASELINE__ = it;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
/** Grade + glare. The heavy gather is dispatched only in Converged / Denoised. */
|
|
2789
|
+
uploadDisplayPost(e, a) {
|
|
2790
|
+
var c, l, u, h, f;
|
|
2791
|
+
const r = Xn(sr(), a);
|
|
2792
|
+
Zn(
|
|
2793
|
+
this.postParamsScratch,
|
|
2794
|
+
r,
|
|
2795
|
+
ir(e.webGPUContext.canvasFormat)
|
|
2796
|
+
);
|
|
2797
|
+
const s = r.bloom.mode === "pyramid", n = s && r.bloomMix > 0, o = !s && r.bloomMix > 0, i = e.webGPUContext.device.queue;
|
|
2798
|
+
for (const m of [e.renderGraph, e.gameRenderGraph]) {
|
|
2799
|
+
for (const M of Qn) {
|
|
2800
|
+
const x = M === "BloomComposite" ? s : n;
|
|
2801
|
+
m.setComputePassWorkgroupCount(M, x ? null : [1, 1, 1]);
|
|
2802
|
+
}
|
|
2803
|
+
m.setComputePassWorkgroupCount("PathTracerBloom", o ? null : [1, 1, 1]);
|
|
2804
|
+
const g = m.getBuffer("pathTracerPostParams");
|
|
2805
|
+
g && i.writeBuffer(g, 0, this.postParamsScratch);
|
|
2806
|
+
const p = m.getPasses().find((M) => M.name === "BlitToScreen");
|
|
2807
|
+
if (p && p.type === "fullscreen") {
|
|
2808
|
+
const M = (l = (c = p.uniforms) == null ? void 0 : c.post) == null ? void 0 : l.value;
|
|
2809
|
+
if (Array.isArray(M))
|
|
2810
|
+
for (let x = 0; x < this.postParamsScratch.length && x < M.length; x++)
|
|
2811
|
+
M[x] = this.postParamsScratch[x];
|
|
2812
|
+
}
|
|
2813
|
+
const T = m.getPasses().find((M) => M.name === "05_ToneMapping");
|
|
2814
|
+
if (T && T.type === "fullscreen") {
|
|
2815
|
+
const M = (h = (u = T.uniforms) == null ? void 0 : u.post) == null ? void 0 : h.value;
|
|
2816
|
+
if (Array.isArray(M)) {
|
|
2817
|
+
for (let x = 0; x < this.postParamsScratch.length && x < M.length; x++)
|
|
2818
|
+
M[x] = this.postParamsScratch[x];
|
|
2819
|
+
M.length > 10 && (M[10] = 0);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
const b = m.getPasses().find((M) => M.name === "07_FXAA" || M.name === "07_HybridEncode"), A = (f = b == null ? void 0 : b.uniforms) == null ? void 0 : f.encodeSrgb;
|
|
2823
|
+
A && typeof A.value == "number" && (A.value = ir(e.webGPUContext.canvasFormat) ? 1 : 0);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
const ms = 4, fe = 15;
|
|
2828
|
+
function Be(t, e = "rgba8unorm") {
|
|
2829
|
+
return {
|
|
2830
|
+
name: t,
|
|
2831
|
+
type: "texture",
|
|
2832
|
+
format: e,
|
|
2833
|
+
sizeType: "absolute",
|
|
2834
|
+
width: 1,
|
|
2835
|
+
height: 1,
|
|
2836
|
+
arrayLayers: 1,
|
|
2837
|
+
sampledViewDimension: "2d-array",
|
|
2838
|
+
usage: ms
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
const xi = [
|
|
2842
|
+
Be("pathTracerTexAlbedo", "rgba8unorm-srgb"),
|
|
2843
|
+
Be("pathTracerTexOrm", "rgba8unorm"),
|
|
2844
|
+
Be("pathTracerTexNormal", "rgba8unorm"),
|
|
2845
|
+
Be("pathTracerTexEmissive", "rgba8unorm-srgb")
|
|
2846
|
+
], ps = {
|
|
2847
|
+
8: { handle: "pathTracerTexAlbedo", viewDimension: "2d-array" },
|
|
2848
|
+
9: { handle: "pathTracerTexOrm", viewDimension: "2d-array" },
|
|
2849
|
+
10: { handle: "pathTracerTexNormal", viewDimension: "2d-array" },
|
|
2850
|
+
11: { handle: "pathTracerTexEmissive", viewDimension: "2d-array" }
|
|
2851
|
+
};
|
|
2852
|
+
function We(t) {
|
|
2853
|
+
return {
|
|
2854
|
+
name: "PathTracerGraph",
|
|
2855
|
+
resources: [
|
|
2856
|
+
{
|
|
2857
|
+
name: "sceneTriangles",
|
|
2858
|
+
type: "buffer",
|
|
2859
|
+
sizeType: "fixed",
|
|
2860
|
+
size: zr,
|
|
2861
|
+
usage: 136
|
|
2862
|
+
},
|
|
2863
|
+
{
|
|
2864
|
+
name: "pathTracerParams",
|
|
2865
|
+
type: "buffer",
|
|
2866
|
+
sizeType: "fixed",
|
|
2867
|
+
size: cn,
|
|
2868
|
+
usage: 136
|
|
2869
|
+
},
|
|
2870
|
+
{
|
|
2871
|
+
name: "pathTracerTexSlotFlags",
|
|
2872
|
+
type: "buffer",
|
|
2873
|
+
sizeType: "fixed",
|
|
2874
|
+
size: yt * 4,
|
|
2875
|
+
usage: 136
|
|
2876
|
+
},
|
|
2877
|
+
{
|
|
2878
|
+
name: "pathTracerMatFactors",
|
|
2879
|
+
type: "buffer",
|
|
2880
|
+
sizeType: "fixed",
|
|
2881
|
+
size: rn,
|
|
2882
|
+
usage: 136
|
|
2883
|
+
},
|
|
2884
|
+
{
|
|
2885
|
+
name: "pathTracerMaterials",
|
|
2886
|
+
type: "buffer",
|
|
2887
|
+
sizeType: "fixed",
|
|
2888
|
+
size: Pn,
|
|
2889
|
+
usage: 136
|
|
2890
|
+
},
|
|
2891
|
+
{
|
|
2892
|
+
name: "pathTracerBvhNodes",
|
|
2893
|
+
type: "buffer",
|
|
2894
|
+
sizeType: "fixed",
|
|
2895
|
+
size: Wr,
|
|
2896
|
+
usage: 136
|
|
2897
|
+
},
|
|
2898
|
+
{
|
|
2899
|
+
name: "pathTracerInstances",
|
|
2900
|
+
type: "buffer",
|
|
2901
|
+
sizeType: "fixed",
|
|
2902
|
+
size: nn,
|
|
2903
|
+
usage: 136
|
|
2904
|
+
},
|
|
2905
|
+
{
|
|
2906
|
+
name: "pathTracerEmissive",
|
|
2907
|
+
type: "buffer",
|
|
2908
|
+
sizeType: "fixed",
|
|
2909
|
+
size: an,
|
|
2910
|
+
usage: 136
|
|
2911
|
+
},
|
|
2912
|
+
{
|
|
2913
|
+
name: "pathTracerDenoiserParams",
|
|
2914
|
+
type: "buffer",
|
|
2915
|
+
sizeType: "fixed",
|
|
2916
|
+
size: hn,
|
|
2917
|
+
usage: 136
|
|
2918
|
+
},
|
|
2919
|
+
{
|
|
2920
|
+
name: "pathTracerFsrParams",
|
|
2921
|
+
type: "buffer",
|
|
2922
|
+
sizeType: "fixed",
|
|
2923
|
+
size: ga,
|
|
2924
|
+
usage: 136
|
|
2925
|
+
},
|
|
2926
|
+
{
|
|
2927
|
+
name: "pathTracerPostParams",
|
|
2928
|
+
type: "buffer",
|
|
2929
|
+
sizeType: "fixed",
|
|
2930
|
+
size: es,
|
|
2931
|
+
usage: 136
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
name: "pathTracerSunDirection",
|
|
2935
|
+
type: "buffer",
|
|
2936
|
+
sizeType: "fixed",
|
|
2937
|
+
size: dn,
|
|
2938
|
+
usage: 136
|
|
2939
|
+
},
|
|
2940
|
+
{
|
|
2941
|
+
name: "pathTracerTileInfo",
|
|
2942
|
+
type: "buffer",
|
|
2943
|
+
sizeType: "fixed",
|
|
2944
|
+
size: Xr,
|
|
2945
|
+
usage: 136
|
|
2946
|
+
},
|
|
2947
|
+
// Phase 2: full-frame relative targets (spatial interleave). Former absolute tile buffers.
|
|
2948
|
+
{
|
|
2949
|
+
name: "pathTraceAccumRead",
|
|
2950
|
+
type: "texture",
|
|
2951
|
+
format: "rgba32float",
|
|
2952
|
+
sizeType: "relative",
|
|
2953
|
+
width: 1,
|
|
2954
|
+
height: 1,
|
|
2955
|
+
usage: 12
|
|
2956
|
+
},
|
|
2957
|
+
{
|
|
2958
|
+
name: "pathTraceAccumWrite",
|
|
2959
|
+
type: "texture",
|
|
2960
|
+
format: "rgba32float",
|
|
2961
|
+
sizeType: "relative",
|
|
2962
|
+
width: 1,
|
|
2963
|
+
height: 1,
|
|
2964
|
+
usage: 12
|
|
2965
|
+
},
|
|
2966
|
+
{
|
|
2967
|
+
name: "pathTraceOutput",
|
|
2968
|
+
type: "texture",
|
|
2969
|
+
format: "rgba32float",
|
|
2970
|
+
sizeType: "relative",
|
|
2971
|
+
width: 1,
|
|
2972
|
+
height: 1,
|
|
2973
|
+
usage: 12
|
|
2974
|
+
},
|
|
2975
|
+
{
|
|
2976
|
+
name: "pathTraceGuide",
|
|
2977
|
+
type: "texture",
|
|
2978
|
+
format: "rgba16float",
|
|
2979
|
+
sizeType: "relative",
|
|
2980
|
+
width: 1,
|
|
2981
|
+
height: 1,
|
|
2982
|
+
usage: 12
|
|
2983
|
+
},
|
|
2984
|
+
{
|
|
2985
|
+
name: "pathTraceAlbedo",
|
|
2986
|
+
type: "texture",
|
|
2987
|
+
format: "rgba16float",
|
|
2988
|
+
sizeType: "relative",
|
|
2989
|
+
width: 1,
|
|
2990
|
+
height: 1,
|
|
2991
|
+
usage: 12
|
|
2992
|
+
},
|
|
2993
|
+
{
|
|
2994
|
+
name: "pathTraceObjectId",
|
|
2995
|
+
type: "texture",
|
|
2996
|
+
format: "rgba16float",
|
|
2997
|
+
sizeType: "relative",
|
|
2998
|
+
width: 1,
|
|
2999
|
+
height: 1,
|
|
3000
|
+
usage: 12
|
|
3001
|
+
},
|
|
3002
|
+
{
|
|
3003
|
+
name: "denoisedOutput",
|
|
3004
|
+
type: "texture",
|
|
3005
|
+
format: "rgba16float",
|
|
3006
|
+
sizeType: "relative",
|
|
3007
|
+
width: 1,
|
|
3008
|
+
height: 1,
|
|
3009
|
+
usage: 12
|
|
3010
|
+
},
|
|
3011
|
+
{
|
|
3012
|
+
name: "denoiseAtrousTmp0",
|
|
3013
|
+
type: "texture",
|
|
3014
|
+
format: "rgba16float",
|
|
3015
|
+
sizeType: "relative",
|
|
3016
|
+
width: 1,
|
|
3017
|
+
height: 1,
|
|
3018
|
+
usage: 12
|
|
3019
|
+
},
|
|
3020
|
+
{
|
|
3021
|
+
name: "denoiseAtrousTmp1",
|
|
3022
|
+
type: "texture",
|
|
3023
|
+
format: "rgba16float",
|
|
3024
|
+
sizeType: "relative",
|
|
3025
|
+
width: 1,
|
|
3026
|
+
height: 1,
|
|
3027
|
+
usage: 12
|
|
3028
|
+
},
|
|
3029
|
+
{
|
|
3030
|
+
name: "holeFilledBeauty",
|
|
3031
|
+
type: "texture",
|
|
3032
|
+
format: "rgba16float",
|
|
3033
|
+
sizeType: "relative",
|
|
3034
|
+
width: 1,
|
|
3035
|
+
height: 1,
|
|
3036
|
+
usage: 12
|
|
3037
|
+
},
|
|
3038
|
+
{
|
|
3039
|
+
name: "pathTraceComposite",
|
|
3040
|
+
type: "texture",
|
|
3041
|
+
format: "rgba16float",
|
|
3042
|
+
sizeType: "relative",
|
|
3043
|
+
width: 1,
|
|
3044
|
+
height: 1,
|
|
3045
|
+
usage: fe
|
|
3046
|
+
},
|
|
3047
|
+
{
|
|
3048
|
+
name: "pathTraceNoisyComposite",
|
|
3049
|
+
type: "texture",
|
|
3050
|
+
format: "rgba16float",
|
|
3051
|
+
sizeType: "relative",
|
|
3052
|
+
width: 1,
|
|
3053
|
+
height: 1,
|
|
3054
|
+
usage: fe
|
|
3055
|
+
},
|
|
3056
|
+
{
|
|
3057
|
+
name: "pathTraceGuideComposite",
|
|
3058
|
+
type: "texture",
|
|
3059
|
+
format: "rgba16float",
|
|
3060
|
+
sizeType: "relative",
|
|
3061
|
+
width: 1,
|
|
3062
|
+
height: 1,
|
|
3063
|
+
usage: fe
|
|
3064
|
+
},
|
|
3065
|
+
{
|
|
3066
|
+
name: "pathTraceAlbedoComposite",
|
|
3067
|
+
type: "texture",
|
|
3068
|
+
format: "rgba16float",
|
|
3069
|
+
sizeType: "relative",
|
|
3070
|
+
width: 1,
|
|
3071
|
+
height: 1,
|
|
3072
|
+
usage: fe
|
|
3073
|
+
},
|
|
3074
|
+
{
|
|
3075
|
+
name: "pathTraceObjectIdComposite",
|
|
3076
|
+
type: "texture",
|
|
3077
|
+
format: "rgba16float",
|
|
3078
|
+
sizeType: "relative",
|
|
3079
|
+
width: 1,
|
|
3080
|
+
height: 1,
|
|
3081
|
+
usage: fe
|
|
3082
|
+
},
|
|
3083
|
+
{
|
|
3084
|
+
name: "pathTracerFsrEasuOut",
|
|
3085
|
+
type: "texture",
|
|
3086
|
+
format: "rgba16float",
|
|
3087
|
+
sizeType: "relative",
|
|
3088
|
+
width: 1,
|
|
3089
|
+
height: 1,
|
|
3090
|
+
/** Upscale target = full canvas; internal path trace may be `resize(sceneW, sceneH)`. */
|
|
3091
|
+
relativeSizeRef: "canvas",
|
|
3092
|
+
usage: 12
|
|
3093
|
+
},
|
|
3094
|
+
{
|
|
3095
|
+
name: "pathTracerFsrRcasOut",
|
|
3096
|
+
type: "texture",
|
|
3097
|
+
format: "rgba16float",
|
|
3098
|
+
sizeType: "relative",
|
|
3099
|
+
width: 1,
|
|
3100
|
+
height: 1,
|
|
3101
|
+
relativeSizeRef: "canvas",
|
|
3102
|
+
usage: 12
|
|
3103
|
+
},
|
|
3104
|
+
{
|
|
3105
|
+
name: "pathTracerBloom",
|
|
3106
|
+
type: "texture",
|
|
3107
|
+
format: "rgba16float",
|
|
3108
|
+
sizeType: "relative",
|
|
3109
|
+
width: 1,
|
|
3110
|
+
height: 1,
|
|
3111
|
+
relativeSizeRef: "canvas",
|
|
3112
|
+
usage: 12
|
|
3113
|
+
},
|
|
3114
|
+
...lr({
|
|
3115
|
+
input: "pathTracerFsrRcasOut",
|
|
3116
|
+
output: "pathTracerBloom",
|
|
3117
|
+
relativeSizeRef: "canvas"
|
|
3118
|
+
}).resources.filter((e) => e.name !== "pathTracerPostParams"),
|
|
3119
|
+
{
|
|
3120
|
+
name: "pathTracerEnvCubemap",
|
|
3121
|
+
type: "texture",
|
|
3122
|
+
format: "rgba8unorm",
|
|
3123
|
+
sizeType: "absolute",
|
|
3124
|
+
width: 1,
|
|
3125
|
+
height: 1,
|
|
3126
|
+
cubemapFaceSize: 1,
|
|
3127
|
+
sampledViewDimension: "cube",
|
|
3128
|
+
usage: ms
|
|
3129
|
+
},
|
|
3130
|
+
...xi
|
|
3131
|
+
],
|
|
3132
|
+
passes: [
|
|
3133
|
+
{
|
|
3134
|
+
name: "ClearPathTraceComposite",
|
|
3135
|
+
type: "compute",
|
|
3136
|
+
shaderPath: "/shaders/path-tracer/clear_composite_layers.compute.wgsl",
|
|
3137
|
+
entryPoint: "main",
|
|
3138
|
+
dispatchMode: "auto",
|
|
3139
|
+
workgroupSize: [8, 8, 1],
|
|
3140
|
+
bufferBindings: {
|
|
3141
|
+
0: { handle: "pathTracerTileInfo", type: "read-only-storage" },
|
|
3142
|
+
1: { handle: "pathTracerParams", type: "read-only-storage" }
|
|
3143
|
+
},
|
|
3144
|
+
textureBindings: {
|
|
3145
|
+
2: { handle: "pathTraceComposite", access: "write", format: "rgba16float" },
|
|
3146
|
+
3: { handle: "pathTraceNoisyComposite", access: "write", format: "rgba16float" },
|
|
3147
|
+
4: { handle: "pathTraceGuideComposite", access: "write", format: "rgba16float" },
|
|
3148
|
+
5: { handle: "pathTraceAlbedoComposite", access: "write", format: "rgba16float" },
|
|
3149
|
+
6: { handle: "pathTraceObjectIdComposite", access: "write", format: "rgba16float" }
|
|
3150
|
+
},
|
|
3151
|
+
inputs: [],
|
|
3152
|
+
outputs: [
|
|
3153
|
+
"pathTraceComposite",
|
|
3154
|
+
"pathTraceNoisyComposite",
|
|
3155
|
+
"pathTraceGuideComposite",
|
|
3156
|
+
"pathTraceAlbedoComposite",
|
|
3157
|
+
"pathTraceObjectIdComposite"
|
|
3158
|
+
]
|
|
3159
|
+
},
|
|
3160
|
+
{
|
|
3161
|
+
name: "ClearPathTraceTile",
|
|
3162
|
+
type: "compute",
|
|
3163
|
+
shaderPath: "/shaders/path-tracer/clear_path_trace_tile.compute.wgsl",
|
|
3164
|
+
entryPoint: "main",
|
|
3165
|
+
dispatchMode: "auto",
|
|
3166
|
+
workgroupSize: [8, 8, 1],
|
|
3167
|
+
bufferBindings: {
|
|
3168
|
+
0: { handle: "pathTracerParams", type: "read-only-storage" }
|
|
3169
|
+
},
|
|
3170
|
+
textureBindings: {
|
|
3171
|
+
1: { handle: "pathTraceOutput", access: "write", format: "rgba32float" },
|
|
3172
|
+
2: { handle: "pathTraceAccumWrite", access: "write", format: "rgba32float" },
|
|
3173
|
+
3: { handle: "pathTraceGuide", access: "write", format: "rgba16float" },
|
|
3174
|
+
4: { handle: "pathTraceAlbedo", access: "write", format: "rgba16float" },
|
|
3175
|
+
5: { handle: "pathTraceObjectId", access: "write", format: "rgba16float" }
|
|
3176
|
+
},
|
|
3177
|
+
inputs: [],
|
|
3178
|
+
outputs: [
|
|
3179
|
+
"pathTraceOutput",
|
|
3180
|
+
"pathTraceAccumWrite",
|
|
3181
|
+
"pathTraceGuide",
|
|
3182
|
+
"pathTraceAlbedo",
|
|
3183
|
+
"pathTraceObjectId"
|
|
3184
|
+
]
|
|
3185
|
+
},
|
|
3186
|
+
{
|
|
3187
|
+
name: "PathTrace",
|
|
3188
|
+
type: "compute",
|
|
3189
|
+
shaderPath: "/shaders/path-tracer/path_trace.compute.wgsl",
|
|
3190
|
+
entryPoint: "main",
|
|
3191
|
+
dispatchMode: "auto",
|
|
3192
|
+
workgroupSize: [8, 8, 1],
|
|
3193
|
+
useFrameUniforms: !0,
|
|
3194
|
+
/** Phase 3 defaults; overridden each frame via RenderGraph.setComputePassConstants. */
|
|
3195
|
+
constants: { PREVIEW_MODE: !1, MAX_BOUNCES: 4 },
|
|
3196
|
+
bufferBindings: {
|
|
3197
|
+
1: { handle: "sceneTriangles", type: "read-only-storage" },
|
|
3198
|
+
2: { handle: "pathTracerParams", type: "read-only-storage" },
|
|
3199
|
+
6: { handle: "pathTracerSunDirection", type: "read-only-storage" },
|
|
3200
|
+
7: { handle: "pathTracerTexSlotFlags", type: "read-only-storage" },
|
|
3201
|
+
52: { handle: "pathTracerMatFactors", type: "read-only-storage" },
|
|
3202
|
+
53: { handle: "pathTracerInstances", type: "read-only-storage" },
|
|
3203
|
+
54: { handle: "pathTracerBvhNodes", type: "read-only-storage" },
|
|
3204
|
+
57: { handle: "pathTracerTileInfo", type: "read-only-storage" },
|
|
3205
|
+
61: { handle: "pathTracerMaterials", type: "read-only-storage" },
|
|
3206
|
+
74: { handle: "pathTracerEmissive", type: "read-only-storage" }
|
|
3207
|
+
},
|
|
3208
|
+
textureBindings: {
|
|
3209
|
+
3: { handle: "pathTraceOutput", access: "write", format: "rgba32float" },
|
|
3210
|
+
5: { handle: "pathTraceAccumWrite", access: "write", format: "rgba32float" },
|
|
3211
|
+
59: { handle: "pathTraceGuide", access: "write", format: "rgba16float" },
|
|
3212
|
+
60: { handle: "pathTraceAlbedo", access: "write", format: "rgba16float" },
|
|
3213
|
+
63: { handle: "pathTraceObjectId", access: "write", format: "rgba16float" }
|
|
3214
|
+
},
|
|
3215
|
+
sampledTextureBindings: {
|
|
3216
|
+
4: { handle: "pathTraceAccumRead", sampleType: "unfilterable-float" },
|
|
3217
|
+
64: { handle: "pathTraceAlbedoComposite" },
|
|
3218
|
+
65: { handle: "pathTraceGuideComposite" },
|
|
3219
|
+
...ps,
|
|
3220
|
+
58: { handle: "pathTracerEnvCubemap", viewDimension: "cube" }
|
|
3221
|
+
},
|
|
3222
|
+
samplerBindings: {
|
|
3223
|
+
56: !0
|
|
3224
|
+
},
|
|
3225
|
+
inputs: ["pathTraceAccumRead", "pathTraceAlbedoComposite", "pathTraceGuideComposite"],
|
|
3226
|
+
outputs: [
|
|
3227
|
+
"pathTraceOutput",
|
|
3228
|
+
"pathTraceAccumWrite",
|
|
3229
|
+
"pathTraceGuide",
|
|
3230
|
+
"pathTraceAlbedo",
|
|
3231
|
+
"pathTraceObjectId"
|
|
3232
|
+
]
|
|
3233
|
+
},
|
|
3234
|
+
{
|
|
3235
|
+
name: "CopyAccum",
|
|
3236
|
+
type: "compute",
|
|
3237
|
+
shaderPath: "/shaders/path-tracer/copy_accum.compute.wgsl",
|
|
3238
|
+
entryPoint: "main",
|
|
3239
|
+
dispatchMode: "auto",
|
|
3240
|
+
workgroupSize: [8, 8, 1],
|
|
3241
|
+
textureBindings: {
|
|
3242
|
+
0: { handle: "pathTraceAccumWrite", access: "read", format: "rgba32float" },
|
|
3243
|
+
1: { handle: "pathTraceAccumRead", access: "write", format: "rgba32float" }
|
|
3244
|
+
},
|
|
3245
|
+
inputs: ["pathTraceAccumWrite"],
|
|
3246
|
+
outputs: ["pathTraceAccumRead"]
|
|
3247
|
+
},
|
|
3248
|
+
{
|
|
3249
|
+
name: "Denoise",
|
|
3250
|
+
type: "compute",
|
|
3251
|
+
shaderPath: "/shaders/path-tracer/denoise.compute.wgsl",
|
|
3252
|
+
entryPoint: "main",
|
|
3253
|
+
dispatchMode: "auto",
|
|
3254
|
+
workgroupSize: [8, 8, 1],
|
|
3255
|
+
bufferBindings: {
|
|
3256
|
+
3: { handle: "pathTracerDenoiserParams", type: "read-only-storage" }
|
|
3257
|
+
},
|
|
3258
|
+
textureBindings: {
|
|
3259
|
+
0: { handle: "pathTraceOutput", access: "read", format: "rgba32float" },
|
|
3260
|
+
1: { handle: "pathTraceGuide", access: "read", format: "rgba16float" },
|
|
3261
|
+
2: { handle: "denoisedOutput", access: "write", format: "rgba16float" }
|
|
3262
|
+
},
|
|
3263
|
+
inputs: ["pathTraceOutput", "pathTraceGuide"],
|
|
3264
|
+
outputs: ["denoisedOutput"]
|
|
3265
|
+
},
|
|
3266
|
+
{
|
|
3267
|
+
name: "DenoiseAtrousS1",
|
|
3268
|
+
type: "compute",
|
|
3269
|
+
shaderPath: "/shaders/path-tracer/denoise_atrous.compute.wgsl",
|
|
3270
|
+
entryPoint: "main_s1",
|
|
3271
|
+
dispatchMode: "auto",
|
|
3272
|
+
workgroupSize: [8, 8, 1],
|
|
3273
|
+
bufferBindings: {
|
|
3274
|
+
3: { handle: "pathTracerDenoiserParams", type: "read-only-storage" },
|
|
3275
|
+
44: { handle: "pathTracerTileInfo", type: "read-only-storage" }
|
|
3276
|
+
},
|
|
3277
|
+
textureBindings: {
|
|
3278
|
+
0: { handle: "denoisedOutput", access: "read", format: "rgba16float" },
|
|
3279
|
+
1: { handle: "pathTraceGuide", access: "read", format: "rgba16float" },
|
|
3280
|
+
2: { handle: "denoiseAtrousTmp0", access: "write", format: "rgba16float" }
|
|
3281
|
+
},
|
|
3282
|
+
inputs: ["denoisedOutput", "pathTraceGuide"],
|
|
3283
|
+
outputs: ["denoiseAtrousTmp0"]
|
|
3284
|
+
},
|
|
3285
|
+
{
|
|
3286
|
+
name: "DenoiseAtrousS2",
|
|
3287
|
+
type: "compute",
|
|
3288
|
+
shaderPath: "/shaders/path-tracer/denoise_atrous.compute.wgsl",
|
|
3289
|
+
entryPoint: "main_s2",
|
|
3290
|
+
dispatchMode: "auto",
|
|
3291
|
+
workgroupSize: [8, 8, 1],
|
|
3292
|
+
bufferBindings: {
|
|
3293
|
+
3: { handle: "pathTracerDenoiserParams", type: "read-only-storage" },
|
|
3294
|
+
44: { handle: "pathTracerTileInfo", type: "read-only-storage" }
|
|
3295
|
+
},
|
|
3296
|
+
textureBindings: {
|
|
3297
|
+
0: { handle: "denoiseAtrousTmp0", access: "read", format: "rgba16float" },
|
|
3298
|
+
1: { handle: "pathTraceGuide", access: "read", format: "rgba16float" },
|
|
3299
|
+
2: { handle: "denoisedOutput", access: "write", format: "rgba16float" }
|
|
3300
|
+
},
|
|
3301
|
+
inputs: ["denoiseAtrousTmp0", "pathTraceGuide"],
|
|
3302
|
+
outputs: ["denoisedOutput"]
|
|
3303
|
+
},
|
|
3304
|
+
{
|
|
3305
|
+
name: "HoleFill",
|
|
3306
|
+
type: "compute",
|
|
3307
|
+
shaderPath: "/shaders/path-tracer/hole_fill.compute.wgsl",
|
|
3308
|
+
entryPoint: "main",
|
|
3309
|
+
dispatchMode: "auto",
|
|
3310
|
+
workgroupSize: [8, 8, 1],
|
|
3311
|
+
bufferBindings: {
|
|
3312
|
+
0: { handle: "pathTracerTileInfo", type: "read-only-storage" }
|
|
3313
|
+
},
|
|
3314
|
+
textureBindings: {
|
|
3315
|
+
2: { handle: "holeFilledBeauty", access: "write", format: "rgba16float" }
|
|
3316
|
+
},
|
|
3317
|
+
sampledTextureBindings: {
|
|
3318
|
+
1: { handle: "denoisedOutput" }
|
|
3319
|
+
},
|
|
3320
|
+
inputs: ["denoisedOutput"],
|
|
3321
|
+
outputs: ["holeFilledBeauty"]
|
|
3322
|
+
},
|
|
3323
|
+
{
|
|
3324
|
+
name: "TileComposite",
|
|
3325
|
+
type: "compute",
|
|
3326
|
+
shaderPath: "/shaders/path-tracer/tile_composite_layers.compute.wgsl",
|
|
3327
|
+
entryPoint: "main",
|
|
3328
|
+
dispatchMode: "auto",
|
|
3329
|
+
workgroupSize: [8, 8, 1],
|
|
3330
|
+
dispatchTextureHandle: "holeFilledBeauty",
|
|
3331
|
+
bufferBindings: {
|
|
3332
|
+
0: { handle: "pathTracerTileInfo", type: "read-only-storage" }
|
|
3333
|
+
},
|
|
3334
|
+
textureBindings: {
|
|
3335
|
+
5: { handle: "pathTraceComposite", access: "write", format: "rgba16float" },
|
|
3336
|
+
6: { handle: "pathTraceNoisyComposite", access: "write", format: "rgba16float" },
|
|
3337
|
+
7: { handle: "pathTraceGuideComposite", access: "write", format: "rgba16float" },
|
|
3338
|
+
8: { handle: "pathTraceAlbedoComposite", access: "write", format: "rgba16float" },
|
|
3339
|
+
10: { handle: "pathTraceObjectIdComposite", access: "write", format: "rgba16float" }
|
|
3340
|
+
},
|
|
3341
|
+
sampledTextureBindings: {
|
|
3342
|
+
1: { handle: "holeFilledBeauty" },
|
|
3343
|
+
2: { handle: "pathTraceOutput" },
|
|
3344
|
+
3: { handle: "pathTraceGuide" },
|
|
3345
|
+
4: { handle: "pathTraceAlbedo" },
|
|
3346
|
+
9: { handle: "pathTraceObjectId" }
|
|
3347
|
+
},
|
|
3348
|
+
inputs: [
|
|
3349
|
+
"holeFilledBeauty",
|
|
3350
|
+
"pathTraceOutput",
|
|
3351
|
+
"pathTraceGuide",
|
|
3352
|
+
"pathTraceAlbedo",
|
|
3353
|
+
"pathTraceObjectId"
|
|
3354
|
+
],
|
|
3355
|
+
outputs: [
|
|
3356
|
+
"pathTraceComposite",
|
|
3357
|
+
"pathTraceNoisyComposite",
|
|
3358
|
+
"pathTraceGuideComposite",
|
|
3359
|
+
"pathTraceAlbedoComposite",
|
|
3360
|
+
"pathTraceObjectIdComposite"
|
|
3361
|
+
]
|
|
3362
|
+
},
|
|
3363
|
+
{
|
|
3364
|
+
name: "FsrEasuPath",
|
|
3365
|
+
type: "compute",
|
|
3366
|
+
shaderPath: "/shaders/path-tracer/fsr1_easu_path.compute.wgsl",
|
|
3367
|
+
entryPoint: "main",
|
|
3368
|
+
dispatchMode: "auto",
|
|
3369
|
+
workgroupSize: [8, 8, 1],
|
|
3370
|
+
dispatchTextureHandle: "pathTracerFsrEasuOut",
|
|
3371
|
+
bufferBindings: {
|
|
3372
|
+
0: { handle: "pathTracerFsrParams", type: "read-only-storage" }
|
|
3373
|
+
},
|
|
3374
|
+
textureBindings: {
|
|
3375
|
+
1: { handle: "pathTraceComposite", access: "read", format: "rgba16float" },
|
|
3376
|
+
2: { handle: "pathTracerFsrEasuOut", access: "write", format: "rgba16float" }
|
|
3377
|
+
},
|
|
3378
|
+
inputs: ["pathTraceComposite"],
|
|
3379
|
+
outputs: ["pathTracerFsrEasuOut"]
|
|
3380
|
+
},
|
|
3381
|
+
{
|
|
3382
|
+
name: "FsrRcasPath",
|
|
3383
|
+
type: "compute",
|
|
3384
|
+
shaderPath: "/shaders/path-tracer/fsr1_rcas_path.compute.wgsl",
|
|
3385
|
+
entryPoint: "main",
|
|
3386
|
+
dispatchMode: "auto",
|
|
3387
|
+
workgroupSize: [8, 8, 1],
|
|
3388
|
+
dispatchTextureHandle: "pathTracerFsrRcasOut",
|
|
3389
|
+
bufferBindings: {
|
|
3390
|
+
0: { handle: "pathTracerFsrParams", type: "read-only-storage" }
|
|
3391
|
+
},
|
|
3392
|
+
textureBindings: {
|
|
3393
|
+
1: { handle: "pathTracerFsrEasuOut", access: "read", format: "rgba16float" },
|
|
3394
|
+
2: { handle: "pathTracerFsrRcasOut", access: "write", format: "rgba16float" }
|
|
3395
|
+
},
|
|
3396
|
+
inputs: ["pathTracerFsrEasuOut"],
|
|
3397
|
+
outputs: ["pathTracerFsrRcasOut"]
|
|
3398
|
+
},
|
|
3399
|
+
...lr({
|
|
3400
|
+
input: "pathTracerFsrRcasOut",
|
|
3401
|
+
output: "pathTracerBloom",
|
|
3402
|
+
relativeSizeRef: "canvas"
|
|
3403
|
+
}).passes,
|
|
3404
|
+
{
|
|
3405
|
+
name: "PathTracerBloom",
|
|
3406
|
+
type: "compute",
|
|
3407
|
+
shaderPath: "/shaders/path-tracer/pt_bloom.compute.wgsl",
|
|
3408
|
+
entryPoint: "main",
|
|
3409
|
+
dispatchMode: "auto",
|
|
3410
|
+
workgroupSize: [8, 8, 1],
|
|
3411
|
+
dispatchTextureHandle: "pathTracerBloom",
|
|
3412
|
+
bufferBindings: {
|
|
3413
|
+
0: { handle: "pathTracerPostParams", type: "read-only-storage" }
|
|
3414
|
+
},
|
|
3415
|
+
textureBindings: {
|
|
3416
|
+
1: { handle: "pathTracerFsrRcasOut", access: "read", format: "rgba16float" },
|
|
3417
|
+
2: { handle: "pathTracerBloom", access: "write", format: "rgba16float" }
|
|
3418
|
+
},
|
|
3419
|
+
inputs: ["pathTracerFsrRcasOut"],
|
|
3420
|
+
outputs: ["pathTracerBloom"]
|
|
3421
|
+
},
|
|
3422
|
+
{
|
|
3423
|
+
name: "BlitToScreen",
|
|
3424
|
+
type: "fullscreen",
|
|
3425
|
+
shaderPath: "/shaders/path-tracer/pt_display.frag.wgsl",
|
|
3426
|
+
inputs: ["pathTracerFsrRcasOut", "pathTracerBloom"],
|
|
3427
|
+
outputs: ["FINAL_OUTPUT"],
|
|
3428
|
+
uniforms: {
|
|
3429
|
+
post: {
|
|
3430
|
+
type: "struct",
|
|
3431
|
+
value: [1, 0, 1, 2, 0, 4.5, 0, 0, 0, 0, 1, 0]
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
]
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
const Tc = We(), _i = /* @__PURE__ */ new Set([
|
|
3439
|
+
"sceneTriangles",
|
|
3440
|
+
"pathTracerParams",
|
|
3441
|
+
"pathTracerTexSlotFlags",
|
|
3442
|
+
"pathTracerMatFactors",
|
|
3443
|
+
"pathTracerMaterials",
|
|
3444
|
+
"pathTracerBvhNodes",
|
|
3445
|
+
"pathTracerInstances",
|
|
3446
|
+
"pathTracerEmissive",
|
|
3447
|
+
"pathTracerSunDirection",
|
|
3448
|
+
"pathTracerTileInfo",
|
|
3449
|
+
"pathTracerEnvCubemap",
|
|
3450
|
+
"pathTracerTexAlbedo",
|
|
3451
|
+
"pathTracerTexOrm",
|
|
3452
|
+
"pathTracerTexNormal",
|
|
3453
|
+
"pathTracerTexEmissive"
|
|
3454
|
+
]), Ei = [1, 2, 4, 8, 16];
|
|
3455
|
+
function de(t, e, a) {
|
|
3456
|
+
const r = Ei[t] ?? 1, s = (o) => `hybrid${o}${e}`, n = (o) => `hybrid${o}${a}`;
|
|
3457
|
+
return {
|
|
3458
|
+
name: `HybridAtrous${t}`,
|
|
3459
|
+
type: "compute",
|
|
3460
|
+
shaderPath: "/shaders/path-tracer/hybrid_atrous.compute.wgsl",
|
|
3461
|
+
entryPoint: "main",
|
|
3462
|
+
dispatchMode: "auto",
|
|
3463
|
+
workgroupSize: [8, 8, 1],
|
|
3464
|
+
dispatchTextureHandle: n("Shadow"),
|
|
3465
|
+
constants: { STEP: r, PASS: t },
|
|
3466
|
+
bufferBindings: {
|
|
3467
|
+
0: { handle: "hybridHistoryParams", type: "read-only-storage" },
|
|
3468
|
+
9: { handle: "pathTracerParams", type: "read-only-storage" }
|
|
3469
|
+
},
|
|
3470
|
+
textureBindings: {
|
|
3471
|
+
20: { handle: n("Shadow"), access: "write", format: "rgba16float" },
|
|
3472
|
+
21: { handle: n("Refl"), access: "write", format: "rgba16float" },
|
|
3473
|
+
22: { handle: n("Gi"), access: "write", format: "rgba16float" },
|
|
3474
|
+
23: { handle: n("LightVis"), access: "write", format: "rgba16float" }
|
|
3475
|
+
},
|
|
3476
|
+
sampledTextureBindings: {
|
|
3477
|
+
1: { handle: s("Shadow"), sampleType: "unfilterable-float" },
|
|
3478
|
+
2: { handle: s("Refl"), sampleType: "unfilterable-float" },
|
|
3479
|
+
3: { handle: s("Gi"), sampleType: "unfilterable-float" },
|
|
3480
|
+
4: { handle: s("LightVis"), sampleType: "unfilterable-float" },
|
|
3481
|
+
5: { handle: "hybridGDist", sampleType: "unfilterable-float" },
|
|
3482
|
+
6: { handle: "hybridGNormal", sampleType: "unfilterable-float" },
|
|
3483
|
+
7: { handle: "hybridMomentsFilt", sampleType: "unfilterable-float" },
|
|
3484
|
+
8: { handle: "hybridReflAov", sampleType: "unfilterable-float" }
|
|
3485
|
+
},
|
|
3486
|
+
inputs: [
|
|
3487
|
+
s("Shadow"),
|
|
3488
|
+
s("Refl"),
|
|
3489
|
+
s("Gi"),
|
|
3490
|
+
s("LightVis"),
|
|
3491
|
+
"hybridGDist",
|
|
3492
|
+
"hybridGNormal",
|
|
3493
|
+
"hybridMomentsFilt",
|
|
3494
|
+
"hybridReflAov",
|
|
3495
|
+
"hybridHistoryParams",
|
|
3496
|
+
"pathTracerParams"
|
|
3497
|
+
],
|
|
3498
|
+
outputs: [n("Shadow"), n("Refl"), n("Gi"), n("LightVis")]
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
const U = (t) => ({
|
|
3502
|
+
name: t,
|
|
3503
|
+
type: "texture",
|
|
3504
|
+
format: "rgba16float",
|
|
3505
|
+
sizeType: "relative",
|
|
3506
|
+
width: 1,
|
|
3507
|
+
height: 1,
|
|
3508
|
+
// COPY_SRC keeps GPU readback available for debugging.
|
|
3509
|
+
usage: 13
|
|
3510
|
+
});
|
|
3511
|
+
function Pi(t) {
|
|
3512
|
+
return {
|
|
3513
|
+
name: "HybridAovSubgraph",
|
|
3514
|
+
resources: [
|
|
3515
|
+
...We().resources.filter((a) => _i.has(a.name)),
|
|
3516
|
+
U("hybridShadowPrev"),
|
|
3517
|
+
U("hybridShadowAov"),
|
|
3518
|
+
U("hybridReflPrev"),
|
|
3519
|
+
U("hybridReflAov"),
|
|
3520
|
+
U("hybridGiPrev"),
|
|
3521
|
+
U("hybridGiAov"),
|
|
3522
|
+
U("hybridLightVisPrev"),
|
|
3523
|
+
U("hybridLightVisAov"),
|
|
3524
|
+
U("hybridShadowFilt"),
|
|
3525
|
+
U("hybridReflFilt"),
|
|
3526
|
+
U("hybridGiFilt"),
|
|
3527
|
+
U("hybridLightVisFilt"),
|
|
3528
|
+
U("hybridFastFilt"),
|
|
3529
|
+
U("hybridMomentsFilt"),
|
|
3530
|
+
U("hybridShadowAtA"),
|
|
3531
|
+
U("hybridReflAtA"),
|
|
3532
|
+
U("hybridGiAtA"),
|
|
3533
|
+
U("hybridLightVisAtA"),
|
|
3534
|
+
U("hybridShadowAtB"),
|
|
3535
|
+
U("hybridReflAtB"),
|
|
3536
|
+
U("hybridGiAtB"),
|
|
3537
|
+
U("hybridLightVisAtB"),
|
|
3538
|
+
U("hybridShadowDen"),
|
|
3539
|
+
U("hybridReflDen"),
|
|
3540
|
+
U("hybridGiDen"),
|
|
3541
|
+
U("hybridLightVisDen"),
|
|
3542
|
+
U("hybridShadowHist"),
|
|
3543
|
+
U("hybridReflHist"),
|
|
3544
|
+
U("hybridGiHist"),
|
|
3545
|
+
U("hybridLightVisHist"),
|
|
3546
|
+
{
|
|
3547
|
+
name: "hybridGDistPrev",
|
|
3548
|
+
type: "texture",
|
|
3549
|
+
format: "r32float",
|
|
3550
|
+
sizeType: "relative",
|
|
3551
|
+
width: 1,
|
|
3552
|
+
height: 1,
|
|
3553
|
+
usage: 12
|
|
3554
|
+
},
|
|
3555
|
+
{
|
|
3556
|
+
name: "hybridGNormalPrev",
|
|
3557
|
+
type: "texture",
|
|
3558
|
+
format: "rgba16float",
|
|
3559
|
+
sizeType: "relative",
|
|
3560
|
+
width: 1,
|
|
3561
|
+
height: 1,
|
|
3562
|
+
usage: 12
|
|
3563
|
+
},
|
|
3564
|
+
{
|
|
3565
|
+
name: "hybridFastHist",
|
|
3566
|
+
type: "texture",
|
|
3567
|
+
format: "rgba16float",
|
|
3568
|
+
sizeType: "relative",
|
|
3569
|
+
width: 1,
|
|
3570
|
+
height: 1,
|
|
3571
|
+
usage: 15
|
|
3572
|
+
},
|
|
3573
|
+
{
|
|
3574
|
+
name: "hybridMomentsHist",
|
|
3575
|
+
type: "texture",
|
|
3576
|
+
format: "rgba16float",
|
|
3577
|
+
sizeType: "relative",
|
|
3578
|
+
width: 1,
|
|
3579
|
+
height: 1,
|
|
3580
|
+
usage: 15
|
|
3581
|
+
}
|
|
3582
|
+
],
|
|
3583
|
+
passes: [
|
|
3584
|
+
{
|
|
3585
|
+
name: "HybridPrimaryAov",
|
|
3586
|
+
type: "compute",
|
|
3587
|
+
shaderPath: "/shaders/path-tracer/hybrid_primary_aov.compute.wgsl",
|
|
3588
|
+
entryPoint: "main",
|
|
3589
|
+
dispatchMode: "auto",
|
|
3590
|
+
workgroupSize: [8, 8, 1],
|
|
3591
|
+
dispatchTextureHandle: "hybridShadowAov",
|
|
3592
|
+
useFrameUniforms: !0,
|
|
3593
|
+
bufferBindings: {
|
|
3594
|
+
1: { handle: "sceneTriangles", type: "read-only-storage" },
|
|
3595
|
+
2: { handle: "pathTracerParams", type: "read-only-storage" },
|
|
3596
|
+
6: { handle: "pathTracerSunDirection", type: "read-only-storage" },
|
|
3597
|
+
7: { handle: "pathTracerTexSlotFlags", type: "read-only-storage" },
|
|
3598
|
+
52: { handle: "pathTracerMatFactors", type: "read-only-storage" },
|
|
3599
|
+
53: { handle: "pathTracerInstances", type: "read-only-storage" },
|
|
3600
|
+
54: { handle: "pathTracerBvhNodes", type: "read-only-storage" },
|
|
3601
|
+
57: { handle: "pathTracerTileInfo", type: "read-only-storage" },
|
|
3602
|
+
61: { handle: "pathTracerMaterials", type: "read-only-storage" },
|
|
3603
|
+
71: { handle: "hybridHistoryParams", type: "read-only-storage" },
|
|
3604
|
+
74: { handle: "pathTracerEmissive", type: "read-only-storage" }
|
|
3605
|
+
},
|
|
3606
|
+
textureBindings: {
|
|
3607
|
+
3: { handle: "hybridShadowAov", access: "write", format: "rgba16float" },
|
|
3608
|
+
5: { handle: "hybridReflAov", access: "write", format: "rgba16float" },
|
|
3609
|
+
67: { handle: "hybridGiAov", access: "write", format: "rgba16float" },
|
|
3610
|
+
69: { handle: "hybridLightVisAov", access: "write", format: "rgba16float" }
|
|
3611
|
+
},
|
|
3612
|
+
sampledTextureBindings: {
|
|
3613
|
+
4: { handle: "hybridShadowPrev", sampleType: "unfilterable-float" },
|
|
3614
|
+
66: { handle: "hybridReflPrev", sampleType: "unfilterable-float" },
|
|
3615
|
+
68: { handle: "hybridGiPrev", sampleType: "unfilterable-float" },
|
|
3616
|
+
70: { handle: "hybridLightVisPrev", sampleType: "unfilterable-float" },
|
|
3617
|
+
72: { handle: "hybridGDist", sampleType: "unfilterable-float" },
|
|
3618
|
+
73: { handle: "hybridGNormal", sampleType: "unfilterable-float" },
|
|
3619
|
+
...ps,
|
|
3620
|
+
58: { handle: "pathTracerEnvCubemap", viewDimension: "cube" }
|
|
3621
|
+
},
|
|
3622
|
+
samplerBindings: { 56: !0 },
|
|
3623
|
+
inputs: [
|
|
3624
|
+
"hybridShadowPrev",
|
|
3625
|
+
"hybridReflPrev",
|
|
3626
|
+
"hybridGiPrev",
|
|
3627
|
+
"hybridLightVisPrev",
|
|
3628
|
+
"hybridGDist",
|
|
3629
|
+
"hybridGNormal"
|
|
3630
|
+
],
|
|
3631
|
+
outputs: ["hybridShadowAov", "hybridReflAov", "hybridGiAov", "hybridLightVisAov"]
|
|
3632
|
+
},
|
|
3633
|
+
{
|
|
3634
|
+
name: "HybridTemporal",
|
|
3635
|
+
type: "compute",
|
|
3636
|
+
shaderPath: "/shaders/path-tracer/hybrid_temporal.compute.wgsl",
|
|
3637
|
+
entryPoint: "main",
|
|
3638
|
+
dispatchMode: "auto",
|
|
3639
|
+
workgroupSize: [8, 8, 1],
|
|
3640
|
+
dispatchTextureHandle: "hybridShadowFilt",
|
|
3641
|
+
bufferBindings: {
|
|
3642
|
+
0: { handle: "hybridHistoryParams", type: "read-only-storage" },
|
|
3643
|
+
14: { handle: "pathTracerParams", type: "read-only-storage" }
|
|
3644
|
+
},
|
|
3645
|
+
textureBindings: {
|
|
3646
|
+
20: { handle: "hybridShadowFilt", access: "write", format: "rgba16float" },
|
|
3647
|
+
21: { handle: "hybridReflFilt", access: "write", format: "rgba16float" },
|
|
3648
|
+
22: { handle: "hybridGiFilt", access: "write", format: "rgba16float" },
|
|
3649
|
+
23: { handle: "hybridLightVisFilt", access: "write", format: "rgba16float" },
|
|
3650
|
+
24: { handle: "hybridFastFilt", access: "write", format: "rgba16float" },
|
|
3651
|
+
25: { handle: "hybridMomentsFilt", access: "write", format: "rgba16float" }
|
|
3652
|
+
},
|
|
3653
|
+
sampledTextureBindings: {
|
|
3654
|
+
1: { handle: "hybridShadowAov", sampleType: "unfilterable-float" },
|
|
3655
|
+
2: { handle: "hybridReflAov", sampleType: "unfilterable-float" },
|
|
3656
|
+
3: { handle: "hybridGiAov", sampleType: "unfilterable-float" },
|
|
3657
|
+
4: { handle: "hybridLightVisAov", sampleType: "unfilterable-float" },
|
|
3658
|
+
5: { handle: "hybridShadowHist", sampleType: "unfilterable-float" },
|
|
3659
|
+
6: { handle: "hybridReflHist", sampleType: "unfilterable-float" },
|
|
3660
|
+
7: { handle: "hybridGiHist", sampleType: "unfilterable-float" },
|
|
3661
|
+
8: { handle: "hybridLightVisHist", sampleType: "unfilterable-float" },
|
|
3662
|
+
9: { handle: "hybridGDist", sampleType: "unfilterable-float" },
|
|
3663
|
+
10: { handle: "hybridGNormal", sampleType: "unfilterable-float" },
|
|
3664
|
+
11: { handle: "hybridGMotion", sampleType: "unfilterable-float" },
|
|
3665
|
+
12: { handle: "hybridGDistPrev", sampleType: "unfilterable-float" },
|
|
3666
|
+
13: { handle: "hybridGNormalPrev", sampleType: "unfilterable-float" },
|
|
3667
|
+
15: { handle: "hybridFastHist", sampleType: "unfilterable-float" },
|
|
3668
|
+
16: { handle: "hybridMomentsHist", sampleType: "unfilterable-float" }
|
|
3669
|
+
},
|
|
3670
|
+
inputs: [
|
|
3671
|
+
"hybridShadowAov",
|
|
3672
|
+
"hybridReflAov",
|
|
3673
|
+
"hybridGiAov",
|
|
3674
|
+
"hybridLightVisAov",
|
|
3675
|
+
"hybridShadowHist",
|
|
3676
|
+
"hybridReflHist",
|
|
3677
|
+
"hybridGiHist",
|
|
3678
|
+
"hybridLightVisHist",
|
|
3679
|
+
"hybridGDist",
|
|
3680
|
+
"hybridGNormal",
|
|
3681
|
+
"hybridGMotion",
|
|
3682
|
+
"hybridGDistPrev",
|
|
3683
|
+
"hybridGNormalPrev",
|
|
3684
|
+
"hybridFastHist",
|
|
3685
|
+
"hybridMomentsHist",
|
|
3686
|
+
"hybridHistoryParams",
|
|
3687
|
+
"pathTracerParams"
|
|
3688
|
+
],
|
|
3689
|
+
outputs: [
|
|
3690
|
+
"hybridShadowFilt",
|
|
3691
|
+
"hybridReflFilt",
|
|
3692
|
+
"hybridGiFilt",
|
|
3693
|
+
"hybridLightVisFilt",
|
|
3694
|
+
"hybridFastFilt",
|
|
3695
|
+
"hybridMomentsFilt"
|
|
3696
|
+
]
|
|
3697
|
+
},
|
|
3698
|
+
{
|
|
3699
|
+
name: "HybridCopyAov",
|
|
3700
|
+
type: "compute",
|
|
3701
|
+
shaderPath: "/shaders/path-tracer/hybrid_copy_aov.compute.wgsl",
|
|
3702
|
+
entryPoint: "main",
|
|
3703
|
+
dispatchMode: "auto",
|
|
3704
|
+
workgroupSize: [8, 8, 1],
|
|
3705
|
+
dispatchTextureHandle: "hybridShadowPrev",
|
|
3706
|
+
textureBindings: {
|
|
3707
|
+
0: { handle: "hybridShadowAov", access: "read", format: "rgba16float" },
|
|
3708
|
+
1: { handle: "hybridShadowPrev", access: "write", format: "rgba16float" },
|
|
3709
|
+
2: { handle: "hybridReflAov", access: "read", format: "rgba16float" },
|
|
3710
|
+
3: { handle: "hybridReflPrev", access: "write", format: "rgba16float" },
|
|
3711
|
+
4: { handle: "hybridGiAov", access: "read", format: "rgba16float" },
|
|
3712
|
+
5: { handle: "hybridGiPrev", access: "write", format: "rgba16float" },
|
|
3713
|
+
6: { handle: "hybridLightVisAov", access: "read", format: "rgba16float" },
|
|
3714
|
+
7: { handle: "hybridLightVisPrev", access: "write", format: "rgba16float" }
|
|
3715
|
+
},
|
|
3716
|
+
inputs: ["hybridShadowAov", "hybridReflAov", "hybridGiAov", "hybridLightVisAov"],
|
|
3717
|
+
outputs: ["hybridShadowPrev", "hybridReflPrev", "hybridGiPrev", "hybridLightVisPrev"]
|
|
3718
|
+
},
|
|
3719
|
+
de(0, "Filt", "AtA"),
|
|
3720
|
+
{
|
|
3721
|
+
name: "HybridHistoryCopy",
|
|
3722
|
+
type: "compute",
|
|
3723
|
+
shaderPath: "/shaders/path-tracer/hybrid_history_copy.compute.wgsl",
|
|
3724
|
+
entryPoint: "main",
|
|
3725
|
+
dispatchMode: "auto",
|
|
3726
|
+
workgroupSize: [8, 8, 1],
|
|
3727
|
+
dispatchTextureHandle: "hybridShadowHist",
|
|
3728
|
+
bufferBindings: {
|
|
3729
|
+
12: { handle: "pathTracerParams", type: "read-only-storage" }
|
|
3730
|
+
},
|
|
3731
|
+
textureBindings: {
|
|
3732
|
+
4: { handle: "hybridShadowHist", access: "write", format: "rgba16float" },
|
|
3733
|
+
5: { handle: "hybridReflHist", access: "write", format: "rgba16float" },
|
|
3734
|
+
6: { handle: "hybridGiHist", access: "write", format: "rgba16float" },
|
|
3735
|
+
7: { handle: "hybridLightVisHist", access: "write", format: "rgba16float" },
|
|
3736
|
+
10: { handle: "hybridGDistPrev", access: "write", format: "r32float" },
|
|
3737
|
+
11: { handle: "hybridGNormalPrev", access: "write", format: "rgba16float" }
|
|
3738
|
+
},
|
|
3739
|
+
sampledTextureBindings: {
|
|
3740
|
+
0: { handle: "hybridShadowAtA", sampleType: "unfilterable-float" },
|
|
3741
|
+
1: { handle: "hybridReflAtA", sampleType: "unfilterable-float" },
|
|
3742
|
+
2: { handle: "hybridGiAtA", sampleType: "unfilterable-float" },
|
|
3743
|
+
3: { handle: "hybridLightVisAtA", sampleType: "unfilterable-float" },
|
|
3744
|
+
8: { handle: "hybridGDist", sampleType: "unfilterable-float" },
|
|
3745
|
+
9: { handle: "hybridGNormal", sampleType: "unfilterable-float" }
|
|
3746
|
+
},
|
|
3747
|
+
inputs: [
|
|
3748
|
+
"hybridShadowAtA",
|
|
3749
|
+
"hybridReflAtA",
|
|
3750
|
+
"hybridGiAtA",
|
|
3751
|
+
"hybridLightVisAtA",
|
|
3752
|
+
"hybridGDist",
|
|
3753
|
+
"hybridGNormal",
|
|
3754
|
+
"pathTracerParams"
|
|
3755
|
+
],
|
|
3756
|
+
outputs: [
|
|
3757
|
+
"hybridShadowHist",
|
|
3758
|
+
"hybridReflHist",
|
|
3759
|
+
"hybridGiHist",
|
|
3760
|
+
"hybridLightVisHist",
|
|
3761
|
+
"hybridGDistPrev",
|
|
3762
|
+
"hybridGNormalPrev"
|
|
3763
|
+
]
|
|
3764
|
+
},
|
|
3765
|
+
de(1, "AtA", "AtB"),
|
|
3766
|
+
de(2, "AtB", "AtA"),
|
|
3767
|
+
de(3, "AtA", "AtB"),
|
|
3768
|
+
de(4, "AtB", "Den"),
|
|
3769
|
+
{
|
|
3770
|
+
name: "HybridFastCopy",
|
|
3771
|
+
type: "copy-texture",
|
|
3772
|
+
inputs: ["hybridFastFilt"],
|
|
3773
|
+
outputs: ["hybridFastHist"]
|
|
3774
|
+
},
|
|
3775
|
+
{
|
|
3776
|
+
name: "HybridMomentsCopy",
|
|
3777
|
+
type: "copy-texture",
|
|
3778
|
+
inputs: ["hybridMomentsFilt"],
|
|
3779
|
+
outputs: ["hybridMomentsHist"]
|
|
3780
|
+
}
|
|
3781
|
+
]
|
|
3782
|
+
};
|
|
3783
|
+
}
|
|
3784
|
+
function gc(t) {
|
|
3785
|
+
return Pi();
|
|
3786
|
+
}
|
|
3787
|
+
function bs() {
|
|
3788
|
+
const t = typeof globalThis < "u" ? globalThis.__W3DTS_PATH_TRACER_CONFIG : void 0;
|
|
3789
|
+
return qr((t == null ? void 0 : t.tileSize) ?? Ca);
|
|
3790
|
+
}
|
|
3791
|
+
class Mc extends Nr {
|
|
3792
|
+
constructor() {
|
|
3793
|
+
super("PathTracer");
|
|
3794
|
+
y(this, "logger", null);
|
|
3795
|
+
y(this, "engine", null);
|
|
3796
|
+
y(this, "uploadController", new ds());
|
|
3797
|
+
/** Entity id of the directional light created for the path tracer scene; used so inspector edits apply. */
|
|
3798
|
+
y(this, "pathTracerLightEntityId", null);
|
|
3799
|
+
}
|
|
3800
|
+
setStudioKeyLightEnabled(a) {
|
|
3801
|
+
!this.engine || this.pathTracerLightEntityId === null || Lr(this.engine.ecsWorld, this.pathTracerLightEntityId, a);
|
|
3802
|
+
}
|
|
3803
|
+
async initializeScene(a) {
|
|
3804
|
+
const { logger: r, engine: s, scene: n, world: o } = a;
|
|
3805
|
+
this.logger = r, this.engine = s;
|
|
3806
|
+
let i;
|
|
3807
|
+
try {
|
|
3808
|
+
const B = await fetch("/shader-graphs/PBRGraph.json");
|
|
3809
|
+
if (!B.ok) throw new Error(`HTTP ${B.status}`);
|
|
3810
|
+
i = await B.json();
|
|
3811
|
+
} catch (B) {
|
|
3812
|
+
r.warn(
|
|
3813
|
+
$t.EngineLifecycle,
|
|
3814
|
+
"PathTracer: PBR graph not found, scene will be empty.",
|
|
3815
|
+
B
|
|
3816
|
+
);
|
|
3817
|
+
return;
|
|
3818
|
+
}
|
|
3819
|
+
const c = Xe.createCube(1), l = Xe.createSphere(0.5, 24, 24), u = Xe.createPlane(10, 10);
|
|
3820
|
+
s.resourceManager.uploadMesh(c), s.resourceManager.uploadMesh(l), s.resourceManager.uploadMesh(u);
|
|
3821
|
+
const h = (B, H) => {
|
|
3822
|
+
const L = new Ka({
|
|
3823
|
+
name: B,
|
|
3824
|
+
shadingModel: "pbr",
|
|
3825
|
+
shaderGraph: i,
|
|
3826
|
+
properties: { baseColor: H, roughness: 0.9, metallic: 0 }
|
|
3827
|
+
});
|
|
3828
|
+
return s.resourceManager.uploadMaterial(L), L;
|
|
3829
|
+
}, f = h("PT_Cube", [0.8, 0.2, 0.2]), m = h("PT_Floor", [0.2, 0.7, 0.2]), g = h("PT_LeftWall", [0.8, 0.15, 0.15]), p = h("PT_RightWall", [0.15, 0.15, 0.8]), T = h("PT_BackWall", [0.85, 0.85, 0.85]), b = new Ka({
|
|
3830
|
+
name: "PT_Sphere",
|
|
3831
|
+
shadingModel: "pbr",
|
|
3832
|
+
shaderGraph: i,
|
|
3833
|
+
properties: {
|
|
3834
|
+
baseColor: [0.92, 0.92, 0.98],
|
|
3835
|
+
roughness: 0.05,
|
|
3836
|
+
metallic: 1
|
|
3837
|
+
}
|
|
3838
|
+
});
|
|
3839
|
+
s.resourceManager.uploadMaterial(b);
|
|
3840
|
+
const A = new te("Floor", o, u, m);
|
|
3841
|
+
n.add(A);
|
|
3842
|
+
const M = new te("Cube", o, c, f), x = o.getComponent(M.entityId, bt);
|
|
3843
|
+
x && (dt(x.position, 0, 0.5, 0), x.updateLocalTransform()), n.add(M);
|
|
3844
|
+
const P = new te("Sphere", o, l, b), v = o.getComponent(P.entityId, bt);
|
|
3845
|
+
v && (dt(v.position, 2, 0.5, 0), v.updateLocalTransform()), n.add(P);
|
|
3846
|
+
const w = new te("LeftWall", o, u, g), d = o.getComponent(w.entityId, bt);
|
|
3847
|
+
d && (dt(d.position, -5, 5, 0), Ne(d.rotation, [0, 0, 1], -Math.PI / 2), d.updateLocalTransform()), n.add(w);
|
|
3848
|
+
const S = new te("RightWall", o, u, p), _ = o.getComponent(S.entityId, bt);
|
|
3849
|
+
_ && (dt(_.position, 5, 5, 0), Ne(_.rotation, [0, 0, 1], Math.PI / 2), _.updateLocalTransform()), n.add(S);
|
|
3850
|
+
const I = new te("BackWall", o, u, T), C = o.getComponent(I.entityId, bt);
|
|
3851
|
+
C && (dt(C.position, 0, 5, -5), Ne(C.rotation, [1, 0, 0], Math.PI / 2), C.updateLocalTransform()), n.add(I);
|
|
3852
|
+
const F = o.createEntity(), R = new bt();
|
|
3853
|
+
dt(R.position, 5, 10, 5), R.updateLocalTransform(), o.addComponent(F, R), o.addComponent(
|
|
3854
|
+
F,
|
|
3855
|
+
new ye({
|
|
3856
|
+
color: Te(1, 1, 0.95),
|
|
3857
|
+
intensity: 1,
|
|
3858
|
+
shadowsEnabled: !0
|
|
3859
|
+
})
|
|
3860
|
+
), this.pathTracerLightEntityId = F, this.uploadController.setPreferredLightEntity(F), r.info($t.EngineLifecycle, "PathTracer: Cornell box scene initialized.");
|
|
3861
|
+
}
|
|
3862
|
+
async configureRenderGraph(a, r, s) {
|
|
3863
|
+
if (!this.logger) return;
|
|
3864
|
+
this.logger.info($t.RenderGraph, "Loading PathTracerGraph..."), new Hr(this.logger).loadFromData(We(bs()), a), this.logger.info(
|
|
3865
|
+
$t.RenderGraph,
|
|
3866
|
+
"PathTracerGraph loaded (SceneDirector will compile)."
|
|
3867
|
+
);
|
|
3868
|
+
}
|
|
3869
|
+
update(a, r) {
|
|
3870
|
+
this.engine && this.uploadController.tick(this.engine);
|
|
3871
|
+
}
|
|
3872
|
+
updateTime(a) {
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
class Sc extends Nr {
|
|
3876
|
+
constructor() {
|
|
3877
|
+
super("PathTracer2");
|
|
3878
|
+
y(this, "logger", null);
|
|
3879
|
+
y(this, "engine", null);
|
|
3880
|
+
y(this, "uploadController", new ds());
|
|
3881
|
+
y(this, "pathTracerLightEntityId", null);
|
|
3882
|
+
}
|
|
3883
|
+
setStudioKeyLightEnabled(a) {
|
|
3884
|
+
!this.engine || this.pathTracerLightEntityId === null || Lr(this.engine.ecsWorld, this.pathTracerLightEntityId, a);
|
|
3885
|
+
}
|
|
3886
|
+
async initializeScene(a) {
|
|
3887
|
+
const { logger: r, world: s } = a;
|
|
3888
|
+
this.logger = r, this.engine = a.engine;
|
|
3889
|
+
const n = s.createEntity(), o = new bt();
|
|
3890
|
+
dt(o.position, 2, 4, 4), o.updateLocalTransform(), s.addComponent(n, o), s.addComponent(
|
|
3891
|
+
n,
|
|
3892
|
+
new ye({
|
|
3893
|
+
color: Te(1, 1, 0.95),
|
|
3894
|
+
intensity: 1.2,
|
|
3895
|
+
shadowsEnabled: !0
|
|
3896
|
+
})
|
|
3897
|
+
), this.pathTracerLightEntityId = n, this.uploadController.setPreferredLightEntity(n), r.info(
|
|
3898
|
+
$t.EngineLifecycle,
|
|
3899
|
+
"PathTracer2: scene ready. Use Import GLB to load models."
|
|
3900
|
+
);
|
|
3901
|
+
}
|
|
3902
|
+
async configureRenderGraph(a, r, s) {
|
|
3903
|
+
if (!this.logger) return;
|
|
3904
|
+
this.logger.info($t.RenderGraph, "Loading PathTracerGraph (PathTracer2)..."), new Hr(this.logger).loadFromData(We(bs()), a), this.logger.info(
|
|
3905
|
+
$t.RenderGraph,
|
|
3906
|
+
"PathTracerGraph loaded (SceneDirector will compile)."
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3909
|
+
update(a, r) {
|
|
3910
|
+
this.engine && this.uploadController.tick(this.engine);
|
|
3911
|
+
}
|
|
3912
|
+
updateTime(a) {
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
const Ri = [
|
|
3916
|
+
[1.70507958, -0.62189138, -0.08318821],
|
|
3917
|
+
[-0.13025642, 1.14080405, -0.01054763],
|
|
3918
|
+
[-0.02400336, -0.12896897, 1.15297233]
|
|
3919
|
+
], Ci = 4, Fi = 12, wi = 32, Ta = 16;
|
|
3920
|
+
function Ii(t, e, a) {
|
|
3921
|
+
const r = Ri;
|
|
3922
|
+
return [
|
|
3923
|
+
r[0][0] * t + r[0][1] * e + r[0][2] * a,
|
|
3924
|
+
r[1][0] * t + r[1][1] * e + r[1][2] * a,
|
|
3925
|
+
r[2][0] * t + r[2][1] * e + r[2][2] * a
|
|
3926
|
+
];
|
|
3927
|
+
}
|
|
3928
|
+
function ys(t, e, a) {
|
|
3929
|
+
return 0.2126 * t + 0.7152 * e + 0.0722 * a;
|
|
3930
|
+
}
|
|
3931
|
+
function Ac(t, e) {
|
|
3932
|
+
const a = Math.cos(t), r = Math.sin(t), s = Math.cos(e), o = Math.sin(e) * a, i = s * a, c = -r, l = Math.hypot(o, i, c) || 1;
|
|
3933
|
+
return [o / l, i / l, c / l];
|
|
3934
|
+
}
|
|
3935
|
+
function vc(t) {
|
|
3936
|
+
const e = Math.min(Math.PI, Math.max(0, t * 0.5));
|
|
3937
|
+
return 2 * Math.PI * (1 - Math.cos(e));
|
|
3938
|
+
}
|
|
3939
|
+
function Bi(t, e) {
|
|
3940
|
+
return !(t > 0) || !(e > 0) ? 0 : t;
|
|
3941
|
+
}
|
|
3942
|
+
function Ni(t, e, a, r, s) {
|
|
3943
|
+
if (!(a > 0) || t < 0) return 0;
|
|
3944
|
+
let n = a;
|
|
3945
|
+
if (r >= 3) {
|
|
3946
|
+
const l = 2 * Math.PI / r, u = e / l - Math.floor(e / l), h = Math.abs(u - 0.5) * l;
|
|
3947
|
+
n = a * Math.cos(Math.PI / r) / Math.max(Math.cos(h), 1e-3);
|
|
3948
|
+
}
|
|
3949
|
+
const o = Math.min(Math.max(s, 0), 1), i = n * (1 - o);
|
|
3950
|
+
if (t >= n) return 0;
|
|
3951
|
+
if (t <= i) return 1;
|
|
3952
|
+
const c = (n - t) / Math.max(n - i, 1e-6);
|
|
3953
|
+
return c * c * (3 - 2 * c);
|
|
3954
|
+
}
|
|
3955
|
+
function xc(t, e, a, r, s, n, o) {
|
|
3956
|
+
const i = Math.hypot(t[0], t[1], t[2]) || 1, c = Math.hypot(e[0], e[1], e[2]) || 1, l = t[0] / i, u = t[1] / i, h = t[2] / i, f = e[0] / c, m = e[1] / c, g = e[2] / c, p = Math.min(1, Math.max(-1, l * f + u * m + h * g));
|
|
3957
|
+
let T, b, A;
|
|
3958
|
+
Math.abs(m) >= 0.999 ? (T = 0, b = g, A = -m) : (T = -g, b = 0, A = f);
|
|
3959
|
+
const M = Math.hypot(T, b, A) || 1;
|
|
3960
|
+
T /= M, b /= M, A /= M;
|
|
3961
|
+
const x = m * A - g * b, P = g * T - f * A, v = f * b - m * T, w = Math.atan2(l * x + u * P + h * v, l * T + u * b + h * A), d = Ni(Math.acos(p), w, s, n, o);
|
|
3962
|
+
return [a * r[0] * d, a * r[1] * d, a * r[2] * d];
|
|
3963
|
+
}
|
|
3964
|
+
function Li(t, e, a) {
|
|
3965
|
+
const r = new Float32Array(a), s = new Float32Array(e * a), n = new Float32Array(a);
|
|
3966
|
+
let o = 0;
|
|
3967
|
+
for (let c = 0; c < a; c++) {
|
|
3968
|
+
const l = Math.sin((c + 0.5) / a * Math.PI);
|
|
3969
|
+
let u = 0;
|
|
3970
|
+
const h = c * e;
|
|
3971
|
+
for (let m = 0; m < e; m++) {
|
|
3972
|
+
const g = (h + m) * 3, p = ys(t[g] ?? 0, t[g + 1] ?? 0, t[g + 2] ?? 0) * l;
|
|
3973
|
+
u += p, s[h + m] = u;
|
|
3974
|
+
}
|
|
3975
|
+
n[c] = u, o += u;
|
|
3976
|
+
const f = u > 0 ? 1 / u : 0;
|
|
3977
|
+
for (let m = 0; m < e; m++)
|
|
3978
|
+
s[h + m] = u > 0 ? (s[h + m] ?? 0) * f : (m + 1) / e;
|
|
3979
|
+
}
|
|
3980
|
+
let i = 0;
|
|
3981
|
+
for (let c = 0; c < a; c++)
|
|
3982
|
+
i += n[c] ?? 0, r[c] = o > 0 ? i / o : (c + 1) / a;
|
|
3983
|
+
return { width: e, height: a, marginal: r, conditional: s, sumWeight: o };
|
|
3984
|
+
}
|
|
3985
|
+
function _c(t, e, a, r) {
|
|
3986
|
+
return !(t > 0) || !(r > 0) || e < 1 || a < 1 ? 0 : t * e * a / (r * 2 * Math.PI * Math.PI);
|
|
3987
|
+
}
|
|
3988
|
+
function Ec(t, e) {
|
|
3989
|
+
const [a, r, s] = e;
|
|
3990
|
+
let n = t[0], o = t[1], i = t[2];
|
|
3991
|
+
const c = Math.cos(-r), l = Math.sin(-r), u = c * n + l * i, h = -l * n + c * i, f = Math.cos(-a), m = Math.sin(-a), g = f * o - m * h, p = m * o + f * h, T = Math.cos(-s), b = Math.sin(-s);
|
|
3992
|
+
return [T * u - b * g, b * u + T * g, p];
|
|
3993
|
+
}
|
|
3994
|
+
function Hi(t, e, a, r, s) {
|
|
3995
|
+
const n = (r % 1 + 1) % 1 * e - 0.5, o = Math.min(Math.max(s, 0), 1) * a - 0.5, i = Math.floor(n), c = Math.floor(o), l = n - i, u = o - c, h = (b) => (b % e + e) % e, f = (b) => Math.min(a - 1, Math.max(0, b)), m = (b, A) => {
|
|
3996
|
+
const M = (f(A) * e + h(b)) * 4;
|
|
3997
|
+
return [t[M] ?? 0, t[M + 1] ?? 0, t[M + 2] ?? 0];
|
|
3998
|
+
}, g = (b, A, M) => [b[0] + (A[0] - b[0]) * M, b[1] + (A[1] - b[1]) * M, b[2] + (A[2] - b[2]) * M], p = g(m(i, c), m(i + 1, c), l), T = g(m(i, c + 1), m(i + 1, c + 1), l);
|
|
3999
|
+
return g(p, T, u);
|
|
4000
|
+
}
|
|
4001
|
+
function Pc(t, e, a, r) {
|
|
4002
|
+
const s = ft, n = gt, o = new Float32Array(s * n * 3), i = Number.isFinite(r.powerScale) ? r.powerScale : 1, c = e === s && a === n;
|
|
4003
|
+
for (let l = 0; l < n; l++)
|
|
4004
|
+
for (let u = 0; u < s; u++) {
|
|
4005
|
+
let h, f, m;
|
|
4006
|
+
if (c) {
|
|
4007
|
+
const p = (l * e + u) * 4;
|
|
4008
|
+
h = t[p] ?? 0, f = t[p + 1] ?? 0, m = t[p + 2] ?? 0;
|
|
4009
|
+
} else {
|
|
4010
|
+
const p = Hi(t, e, a, (u + 0.5) / s, (l + 0.5) / n);
|
|
4011
|
+
h = p[0], f = p[1], m = p[2];
|
|
4012
|
+
}
|
|
4013
|
+
if (r.acescg) {
|
|
4014
|
+
const p = Ii(h, f, m);
|
|
4015
|
+
h = p[0], f = p[1], m = p[2];
|
|
4016
|
+
}
|
|
4017
|
+
const g = (l * s + u) * 3;
|
|
4018
|
+
o[g] = h * i, o[g + 1] = f * i, o[g + 2] = m * i;
|
|
4019
|
+
}
|
|
4020
|
+
return o;
|
|
4021
|
+
}
|
|
4022
|
+
function Di() {
|
|
4023
|
+
return {
|
|
4024
|
+
rgb: new Float32Array(ft * gt * 3),
|
|
4025
|
+
rotation: [0, 0, 0],
|
|
4026
|
+
lights: []
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
4029
|
+
function Rc(t) {
|
|
4030
|
+
const e = new Float32Array(jr);
|
|
4031
|
+
let a = 0;
|
|
4032
|
+
for (let s = 0; s < Math.min(t.length, ze); s++)
|
|
4033
|
+
t[s] && (a = s + 1);
|
|
4034
|
+
e[0] = a, e[1] = ft, e[2] = gt;
|
|
4035
|
+
const r = [];
|
|
4036
|
+
for (let s = 0; s < a; s++) {
|
|
4037
|
+
const n = t[s] ?? Di(), o = n.rotation;
|
|
4038
|
+
e[Ta + s * 4] = o[0] ?? 0, e[Ta + s * 4 + 1] = o[1] ?? 0, e[Ta + s * 4 + 2] = o[2] ?? 0;
|
|
4039
|
+
const i = Li(n.rgb, ft, gt);
|
|
4040
|
+
e[4 + s] = i.sumWeight;
|
|
4041
|
+
const c = $r + s * ft * gt * 4, l = Vr + s * gt, u = Yr + s * gt * ft;
|
|
4042
|
+
for (let h = 0; h < gt; h++) {
|
|
4043
|
+
e[l + h] = i.marginal[h] ?? 0;
|
|
4044
|
+
for (let f = 0; f < ft; f++) {
|
|
4045
|
+
const m = (h * ft + f) * 3, g = n.rgb[m] ?? 0, p = n.rgb[m + 1] ?? 0, T = n.rgb[m + 2] ?? 0, b = c + (h * ft + f) * 4;
|
|
4046
|
+
e[b] = g, e[b + 1] = p, e[b + 2] = T, e[b + 3] = ys(g, p, T), e[u + h * ft + f] = i.conditional[h * ft + f] ?? 0;
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
for (const h of n.lights)
|
|
4050
|
+
h.enabled && r.length < Ci && r.push(h);
|
|
4051
|
+
}
|
|
4052
|
+
e[3] = r.length;
|
|
4053
|
+
for (let s = 0; s < r.length; s++) {
|
|
4054
|
+
const n = r[s], o = wi + s * Fi;
|
|
4055
|
+
e[o] = n.direction[0], e[o + 1] = n.direction[1], e[o + 2] = n.direction[2], e[o + 3] = Bi(n.power, n.angleSize), e[o + 4] = n.color[0], e[o + 5] = n.color[1], e[o + 6] = n.color[2], e[o + 7] = n.angleSize * 0.5, e[o + 8] = n.sides, e[o + 9] = n.falloff, e[o + 10] = n.slot, e[o + 11] = n.enabled ? 1 : 0;
|
|
4056
|
+
}
|
|
4057
|
+
return e;
|
|
4058
|
+
}
|
|
4059
|
+
function Oe(t, e, a) {
|
|
4060
|
+
return Math.min(a, Math.max(e, t));
|
|
4061
|
+
}
|
|
4062
|
+
function Oi(t, e) {
|
|
4063
|
+
const a = e.finalPoint[0] - e.startPoint[0], r = e.finalPoint[1] - e.startPoint[1], s = a * a + r * r;
|
|
4064
|
+
if (s < 1e-12) return 0;
|
|
4065
|
+
const n = ((t[0] - e.startPoint[0]) * a + (t[1] - e.startPoint[1]) * r) / s, o = Oe(n, 0, 1), i = Oe(e.stretching, 0.025, 4) * 2;
|
|
4066
|
+
return Math.pow(o, i);
|
|
4067
|
+
}
|
|
4068
|
+
function Cc(t, e) {
|
|
4069
|
+
const a = Oi(t, e);
|
|
4070
|
+
return [
|
|
4071
|
+
e.startColor[0] + (e.finalColor[0] - e.startColor[0]) * a,
|
|
4072
|
+
e.startColor[1] + (e.finalColor[1] - e.startColor[1]) * a,
|
|
4073
|
+
e.startColor[2] + (e.finalColor[2] - e.startColor[2]) * a
|
|
4074
|
+
];
|
|
4075
|
+
}
|
|
4076
|
+
function Fc(t, e, a) {
|
|
4077
|
+
if (!(e > 1e-6)) return 1;
|
|
4078
|
+
const r = Oe(t / e, 0, 1), s = Oe(a, 0, 1);
|
|
4079
|
+
return r * (1 - s) + s;
|
|
4080
|
+
}
|
|
4081
|
+
function wc(t, e) {
|
|
4082
|
+
const a = fn;
|
|
4083
|
+
if (!(a + 12 > t.length)) {
|
|
4084
|
+
if (!e) {
|
|
4085
|
+
t[a] = 0;
|
|
4086
|
+
return;
|
|
4087
|
+
}
|
|
4088
|
+
t[a] = 1, t[a + 1] = e.startColor[0], t[a + 2] = e.startColor[1], t[a + 3] = e.startColor[2], t[a + 4] = e.finalColor[0], t[a + 5] = e.finalColor[1], t[a + 6] = e.finalColor[2], t[a + 7] = e.startPoint[0], t[a + 8] = e.startPoint[1], t[a + 9] = e.finalPoint[0], t[a + 10] = e.finalPoint[1], t[a + 11] = e.stretching;
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
const Ge = Math.PI, Ba = 1 / Math.PI, Ct = 1e-3, Gi = [
|
|
4092
|
+
0.999924,
|
|
4093
|
+
-0.092669,
|
|
4094
|
+
-1.258395,
|
|
4095
|
+
1.634141,
|
|
4096
|
+
-0.499105,
|
|
4097
|
+
1.353028,
|
|
4098
|
+
-3.099099,
|
|
4099
|
+
3.07122,
|
|
4100
|
+
-1.805599,
|
|
4101
|
+
-0.36945,
|
|
4102
|
+
-0.974641,
|
|
4103
|
+
1.35962,
|
|
4104
|
+
1272e-6,
|
|
4105
|
+
0.070821,
|
|
4106
|
+
0.051172,
|
|
4107
|
+
0.160882,
|
|
4108
|
+
-1.47429,
|
|
4109
|
+
0.923568,
|
|
4110
|
+
0.319898,
|
|
4111
|
+
-0.25319,
|
|
4112
|
+
1.128278,
|
|
4113
|
+
-0.803447,
|
|
4114
|
+
-0.207593,
|
|
4115
|
+
0.358534
|
|
4116
|
+
], Ui = [
|
|
4117
|
+
-2175e-6,
|
|
4118
|
+
-0.917854,
|
|
4119
|
+
0.836308,
|
|
4120
|
+
-0.095839,
|
|
4121
|
+
0.553706,
|
|
4122
|
+
-4.49085,
|
|
4123
|
+
6.554465,
|
|
4124
|
+
5.833246,
|
|
4125
|
+
-3.481972,
|
|
4126
|
+
1.340061,
|
|
4127
|
+
-5.427445,
|
|
4128
|
+
3.102214,
|
|
4129
|
+
1.007613,
|
|
4130
|
+
0.808866,
|
|
4131
|
+
-0.964218,
|
|
4132
|
+
-0.898438,
|
|
4133
|
+
9.808558,
|
|
4134
|
+
-5.132795,
|
|
4135
|
+
-7.785251,
|
|
4136
|
+
2.926538,
|
|
4137
|
+
-1.691786,
|
|
4138
|
+
-2.049945,
|
|
4139
|
+
3.756339,
|
|
4140
|
+
-3.624991
|
|
4141
|
+
];
|
|
4142
|
+
function K(t, e) {
|
|
4143
|
+
return t[0] * e[0] + t[1] * e[1] + t[2] * e[2];
|
|
4144
|
+
}
|
|
4145
|
+
function Ue(t, e) {
|
|
4146
|
+
return [t[1] * e[2] - t[2] * e[1], t[2] * e[0] - t[0] * e[2], t[0] * e[1] - t[1] * e[0]];
|
|
4147
|
+
}
|
|
4148
|
+
function Mt(t) {
|
|
4149
|
+
const e = Math.hypot(t[0], t[1], t[2]);
|
|
4150
|
+
return e <= 1e-12 ? [0, 0, 1] : [t[0] / e, t[1] / e, t[2] / e];
|
|
4151
|
+
}
|
|
4152
|
+
function zi(t, e) {
|
|
4153
|
+
const a = 2 * K(t, e);
|
|
4154
|
+
return [t[0] - a * e[0], t[1] - a * e[1], t[2] - a * e[2]];
|
|
4155
|
+
}
|
|
4156
|
+
function Ts(t) {
|
|
4157
|
+
const e = Math.abs(t[1]) < 0.999 ? [0, 1, 0] : [1, 0, 0], a = Mt(Ue(t, e)), r = Ue(t, a);
|
|
4158
|
+
return [a, r, t];
|
|
4159
|
+
}
|
|
4160
|
+
function Ea(t, e) {
|
|
4161
|
+
const a = Math.max(t * t, 1e-8);
|
|
4162
|
+
return 0.5 * (-1 + Math.sqrt(1 + e * e * (1 - a) / a));
|
|
4163
|
+
}
|
|
4164
|
+
function Na(t, e) {
|
|
4165
|
+
const a = G(t, 1e-4, 1), r = G(e, 0, 1), s = Math.pow(1 - a, 5);
|
|
4166
|
+
if (r <= 1e-4)
|
|
4167
|
+
return { a: 1 - s, b: s, ess: 1 };
|
|
4168
|
+
const n = r * r, o = n * n, i = n / Math.sqrt(a * a * (1 - o) + o + 1e-12), c = i * i, l = c * i, u = c * c, h = a * a, f = [
|
|
4169
|
+
1,
|
|
4170
|
+
i,
|
|
4171
|
+
c,
|
|
4172
|
+
l,
|
|
4173
|
+
u,
|
|
4174
|
+
n,
|
|
4175
|
+
n * i,
|
|
4176
|
+
n * c,
|
|
4177
|
+
n * l,
|
|
4178
|
+
o,
|
|
4179
|
+
o * i,
|
|
4180
|
+
o * c,
|
|
4181
|
+
s,
|
|
4182
|
+
s * i,
|
|
4183
|
+
s * c,
|
|
4184
|
+
s * n,
|
|
4185
|
+
a * i,
|
|
4186
|
+
a * c,
|
|
4187
|
+
a * n,
|
|
4188
|
+
a * o,
|
|
4189
|
+
r * i,
|
|
4190
|
+
r * c,
|
|
4191
|
+
h * n,
|
|
4192
|
+
h * o
|
|
4193
|
+
];
|
|
4194
|
+
let m = 0, g = 0;
|
|
4195
|
+
for (let b = 0; b < 24; b++)
|
|
4196
|
+
m += Gi[b] * f[b], g += Ui[b] * f[b];
|
|
4197
|
+
const p = G(m, 0.01, 1), T = G(g, 0, p);
|
|
4198
|
+
return { a: p - T, b: T, ess: p };
|
|
4199
|
+
}
|
|
4200
|
+
function Pa(t, e, a, r) {
|
|
4201
|
+
const s = Math.max(K(t, e), 1e-4);
|
|
4202
|
+
if (K(t, a) <= 0) return 0;
|
|
4203
|
+
const o = Math.max(r, Math.sqrt(Ct)), i = o * o, c = Mt([e[0] + a[0], e[1] + a[1], e[2] + a[2]]), l = Math.max(K(t, c), 0), u = Ra(l, o);
|
|
4204
|
+
return 1 / (1 + Ea(s, i)) * u / (4 * s);
|
|
4205
|
+
}
|
|
4206
|
+
function Ir(t, e, a, r, s) {
|
|
4207
|
+
const n = Math.max(a, Math.sqrt(Ct)), o = n * n, [i, c, l] = Ts(t), u = [K(i, e), K(c, e), Math.max(K(l, e), 1e-4)], h = Mt([o * u[0], o * u[1], u[2]]), f = h[0] * h[0] + h[1] * h[1], m = f > 1e-6 ? [-h[1] / Math.sqrt(f), h[0] / Math.sqrt(f), 0] : [1, 0, 0], g = Ue(h, m), p = Math.sqrt(G(r, 0, 1)), T = 2 * Ge * s, b = p * Math.cos(T);
|
|
4208
|
+
let A = p * Math.sin(T);
|
|
4209
|
+
const M = 0.5 * (1 + h[2]);
|
|
4210
|
+
A = (1 - M) * Math.sqrt(Math.max(0, 1 - b * b)) + M * A;
|
|
4211
|
+
const x = Math.sqrt(Math.max(0, 1 - b * b - A * A)), P = [
|
|
4212
|
+
b * m[0] + A * g[0] + x * h[0],
|
|
4213
|
+
b * m[1] + A * g[1] + x * h[1],
|
|
4214
|
+
Math.max(0, b * m[2] + A * g[2] + x * h[2])
|
|
4215
|
+
], v = [o * P[0], o * P[1], P[2]], w = Mt([
|
|
4216
|
+
i[0] * v[0] + c[0] * v[1] + l[0] * v[2],
|
|
4217
|
+
i[1] * v[0] + c[1] * v[1] + l[1] * v[2],
|
|
4218
|
+
i[2] * v[0] + c[2] * v[1] + l[2] * v[2]
|
|
4219
|
+
]), d = [-e[0], -e[1], -e[2]], S = Mt(zi(d, w)), _ = K(t, S);
|
|
4220
|
+
if (_ <= 0)
|
|
4221
|
+
return { l: S, h: w, g2OverG1: 0, pdf: 0 };
|
|
4222
|
+
const I = Math.max(K(t, e), 1e-4), C = Ea(I, o), F = Ea(_, o), R = (1 + C) / (1 + C + F), B = Pa(t, e, S, n);
|
|
4223
|
+
return { l: S, h: w, g2OverG1: R, pdf: B };
|
|
4224
|
+
}
|
|
4225
|
+
function Wi(t, e, a) {
|
|
4226
|
+
const r = 2 * Ge * e, s = Math.sqrt(G(1 - a, 0, 1)), n = Math.sqrt(G(a, 0, 1)), [o, i, c] = Ts(t), l = Math.cos(r) * n, u = Math.sin(r) * n, h = Mt([
|
|
4227
|
+
o[0] * l + i[0] * u + c[0] * s,
|
|
4228
|
+
o[1] * l + i[1] * u + c[1] * s,
|
|
4229
|
+
o[2] * l + i[2] * u + c[2] * s
|
|
4230
|
+
]);
|
|
4231
|
+
return { l: h, pdf: Math.max(K(t, h), 0) * Ba };
|
|
4232
|
+
}
|
|
4233
|
+
function gs(t) {
|
|
4234
|
+
const e = Math.max(t.ior ?? 1.5, 1), a = (e - 1) / (e + 1), r = a * a, s = G(t.specularFactor ?? 1, 0, 1), n = t.specularColorFactor ?? [1, 1, 1], o = [
|
|
4235
|
+
Math.min(r * n[0], 1) * s,
|
|
4236
|
+
Math.min(r * n[1], 1) * s,
|
|
4237
|
+
Math.min(r * n[2], 1) * s
|
|
4238
|
+
], i = G(t.metallic, 0, 1), c = Za(o, t.baseColor, i), l = Za([s, s, s], [1, 1, 1], i);
|
|
4239
|
+
return { f0: c, f90: l };
|
|
4240
|
+
}
|
|
4241
|
+
function ki(t, e, a, r) {
|
|
4242
|
+
const s = Math.max(K(t, a), 0), n = Math.max(K(t, e), 1e-4);
|
|
4243
|
+
if (s <= 0) return [0, 0, 0];
|
|
4244
|
+
const o = Math.max(G(r.roughness, 0, 1), Math.sqrt(Ct)), { f0: i, f90: c } = gs(r), l = G(r.metallic, 0, 1), u = Mt([e[0] + a[0], e[1] + a[1], e[2] + a[2]]), h = Math.max(K(t, u), 0), f = Math.max(K(e, u), 0), m = Ra(h, o), g = Dr(s, n, o), p = ks(f, i, c), T = Na(n, o), b = 1 - T.ess, A = [
|
|
4245
|
+
i[0] + (c[0] - i[0]) / 21,
|
|
4246
|
+
i[1] + (c[1] - i[1]) / 21,
|
|
4247
|
+
i[2] + (c[2] - i[2]) / 21
|
|
4248
|
+
], M = [
|
|
4249
|
+
1 / Math.max(1 - A[0] * b, 1e-4),
|
|
4250
|
+
1 / Math.max(1 - A[1] * b, 1e-4),
|
|
4251
|
+
1 / Math.max(1 - A[2] * b, 1e-4)
|
|
4252
|
+
], x = [
|
|
4253
|
+
i[0] * T.a + c[0] * T.b,
|
|
4254
|
+
i[1] * T.a + c[1] * T.b,
|
|
4255
|
+
i[2] * T.a + c[2] * T.b
|
|
4256
|
+
], P = [
|
|
4257
|
+
G(x[0] * M[0], 0, 1),
|
|
4258
|
+
G(x[1] * M[1], 0, 1),
|
|
4259
|
+
G(x[2] * M[2], 0, 1)
|
|
4260
|
+
], v = [
|
|
4261
|
+
m * g * p[0] * M[0] * s,
|
|
4262
|
+
m * g * p[1] * M[1] * s,
|
|
4263
|
+
m * g * p[2] * M[2] * s
|
|
4264
|
+
], w = [
|
|
4265
|
+
(1 - P[0]) * (1 - l),
|
|
4266
|
+
(1 - P[1]) * (1 - l),
|
|
4267
|
+
(1 - P[2]) * (1 - l)
|
|
4268
|
+
], d = Ba * s;
|
|
4269
|
+
return [
|
|
4270
|
+
v[0] + w[0] * r.baseColor[0] * d,
|
|
4271
|
+
v[1] + w[1] * r.baseColor[1] * d,
|
|
4272
|
+
v[2] + w[2] * r.baseColor[2] * d
|
|
4273
|
+
];
|
|
4274
|
+
}
|
|
4275
|
+
function $i(t, e, a, r, s) {
|
|
4276
|
+
const n = G(r, 0, 1);
|
|
4277
|
+
if (n <= 1e-5)
|
|
4278
|
+
return { coatCos: 0, baseAttenuation: 1 };
|
|
4279
|
+
const o = Math.max(K(t, e), 1e-4), i = Math.max(
|
|
4280
|
+
G(s, 0, 1),
|
|
4281
|
+
Math.sqrt(Ct)
|
|
4282
|
+
), c = Na(o, i), l = G(0.04 * c.a + c.b, 0, 1), u = 1 - n * l, h = Math.max(K(t, a), 0);
|
|
4283
|
+
if (h <= 0)
|
|
4284
|
+
return { coatCos: 0, baseAttenuation: u };
|
|
4285
|
+
const f = Mt([e[0] + a[0], e[1] + a[1], e[2] + a[2]]), m = Math.max(K(t, f), 0), g = Math.max(K(e, f), 0), p = Ra(m, i), T = Dr(h, o, i), b = 0.04 + 0.96 * Math.pow(1 - g, 5);
|
|
4286
|
+
return {
|
|
4287
|
+
coatCos: n * p * T * b * h,
|
|
4288
|
+
baseAttenuation: u
|
|
4289
|
+
};
|
|
4290
|
+
}
|
|
4291
|
+
function Vi(t, e, a, r) {
|
|
4292
|
+
const s = ki(t, e, a, r), n = $i(t, e, a, r.clearcoatFactor ?? 0, r.clearcoatRoughness ?? 0);
|
|
4293
|
+
return [
|
|
4294
|
+
s[0] * n.baseAttenuation + n.coatCos,
|
|
4295
|
+
s[1] * n.baseAttenuation + n.coatCos,
|
|
4296
|
+
s[2] * n.baseAttenuation + n.coatCos
|
|
4297
|
+
];
|
|
4298
|
+
}
|
|
4299
|
+
function Ms(t, e, a) {
|
|
4300
|
+
const r = Math.max(K(t, e), 1e-4), s = G(a.clearcoatFactor ?? 0, 0, 1);
|
|
4301
|
+
Math.max(
|
|
4302
|
+
G(a.clearcoatRoughness ?? 0, 0, 1),
|
|
4303
|
+
Math.sqrt(Ct)
|
|
4304
|
+
);
|
|
4305
|
+
const n = s > 1e-4 ? G(s * (0.04 + 0.96 * Math.pow(1 - r, 5)), 0.05 * s, 0.85) : 0, o = 1 - n, { f0: i, f90: c } = gs(a), l = G(a.metallic, 0, 1), u = Math.max(G(a.roughness, 0, 1), Math.sqrt(Ct)), h = Na(r, u), f = Math.max(
|
|
4306
|
+
i[0] * h.a + c[0] * h.b,
|
|
4307
|
+
i[1] * h.a + c[1] * h.b,
|
|
4308
|
+
i[2] * h.a + c[2] * h.b
|
|
4309
|
+
), m = (1 - l) * Math.max(a.baseColor[0], a.baseColor[1], a.baseColor[2], 1e-3);
|
|
4310
|
+
let g;
|
|
4311
|
+
return l >= 0.999 ? g = 1 : f <= 1e-6 ? g = 0 : g = G(f / (f + m), 0.05, 0.95), {
|
|
4312
|
+
pCoat: n,
|
|
4313
|
+
pSpec: o * g,
|
|
4314
|
+
pDiff: o * (1 - g)
|
|
4315
|
+
};
|
|
4316
|
+
}
|
|
4317
|
+
function Yi(t, e, a, r) {
|
|
4318
|
+
const s = K(t, a);
|
|
4319
|
+
if (s <= 0) return 0;
|
|
4320
|
+
const n = Ms(t, e, r), o = Math.max(G(r.roughness, 0, 1), Math.sqrt(Ct)), i = Math.max(
|
|
4321
|
+
G(r.clearcoatRoughness ?? 0, 0, 1),
|
|
4322
|
+
Math.sqrt(Ct)
|
|
4323
|
+
);
|
|
4324
|
+
let c = n.pDiff * (s * Ba);
|
|
4325
|
+
return n.pSpec > 0 && (c += n.pSpec * Pa(t, e, a, o)), n.pCoat > 0 && (c += n.pCoat * Pa(t, e, a, i)), c;
|
|
4326
|
+
}
|
|
4327
|
+
function Ic(t, e, a, r, s, n) {
|
|
4328
|
+
const o = Ms(t, e, a), i = Math.max(G(a.roughness, 0, 1), Math.sqrt(Ct)), c = Math.max(
|
|
4329
|
+
G(a.clearcoatRoughness ?? 0, 0, 1),
|
|
4330
|
+
Math.sqrt(Ct)
|
|
4331
|
+
);
|
|
4332
|
+
let l;
|
|
4333
|
+
if (r < o.pCoat ? l = Ir(t, e, c, s, n).l : r < o.pCoat + o.pSpec ? l = Ir(t, e, i, s, n).l : l = Wi(t, s, n).l, K(t, l) <= 0)
|
|
4334
|
+
return { l, pdf: 0, weight: [0, 0, 0] };
|
|
4335
|
+
const u = Yi(t, e, l, a);
|
|
4336
|
+
if (u <= 1e-8)
|
|
4337
|
+
return { l, pdf: 0, weight: [0, 0, 0] };
|
|
4338
|
+
const h = Vi(t, e, l, a);
|
|
4339
|
+
return {
|
|
4340
|
+
l,
|
|
4341
|
+
pdf: u,
|
|
4342
|
+
weight: Ws([h[0] / u, h[1] / u, h[2] / u], 0, 64)
|
|
4343
|
+
};
|
|
4344
|
+
}
|
|
4345
|
+
function ji(t, e, a, r) {
|
|
4346
|
+
const s = Mt(e.direction), n = Mt(e.tangent), o = Mt(Ue(n, s)), i = 0.5 * Math.max(e.width, 1e-4), c = 0.5 * Math.max(e.height, 1e-4);
|
|
4347
|
+
let l, u, h;
|
|
4348
|
+
if (e.isDisk) {
|
|
4349
|
+
const d = Math.sqrt(G(a, 0, 1)), S = 2 * Ge * r;
|
|
4350
|
+
l = d * Math.cos(S) * i, u = d * Math.sin(S) * c, h = Ge * i * c;
|
|
4351
|
+
} else
|
|
4352
|
+
l = (2 * G(a, 0, 1) - 1) * i, u = (2 * G(r, 0, 1) - 1) * c, h = 4 * i * c;
|
|
4353
|
+
const f = [
|
|
4354
|
+
e.position[0] + n[0] * l + o[0] * u,
|
|
4355
|
+
e.position[1] + n[1] * l + o[1] * u,
|
|
4356
|
+
e.position[2] + n[2] * l + o[2] * u
|
|
4357
|
+
], m = f[0] - t[0], g = f[1] - t[1], p = f[2] - t[2], T = m * m + g * g + p * p;
|
|
4358
|
+
if (T <= 1e-8)
|
|
4359
|
+
return { dir: [0, 1, 0], distance: 0, radianceOverPdf: [0, 0, 0], valid: !1 };
|
|
4360
|
+
const b = Math.sqrt(T), A = [m / b, g / b, p / b], M = -(s[0] * A[0] + s[1] * A[1] + s[2] * A[2]);
|
|
4361
|
+
if (M <= 1e-5)
|
|
4362
|
+
return { dir: A, distance: b, radianceOverPdf: [0, 0, 0], valid: !1 };
|
|
4363
|
+
let x = 1;
|
|
4364
|
+
const P = e.range ?? 0;
|
|
4365
|
+
if (P > 0) {
|
|
4366
|
+
const d = b / P, S = d * d;
|
|
4367
|
+
x = G(1 - S * S, 0, 1);
|
|
4368
|
+
}
|
|
4369
|
+
const v = h * M * x / T, w = e.intensity * v;
|
|
4370
|
+
return {
|
|
4371
|
+
dir: A,
|
|
4372
|
+
distance: b,
|
|
4373
|
+
radianceOverPdf: [e.color[0] * w, e.color[1] * w, e.color[2] * w],
|
|
4374
|
+
valid: w > 0
|
|
4375
|
+
};
|
|
4376
|
+
}
|
|
4377
|
+
function Bc(t, e, a, r = 16) {
|
|
4378
|
+
const s = Math.max(1, Math.floor(r)), n = s * s;
|
|
4379
|
+
let o = 0, i = 0, c = 0;
|
|
4380
|
+
for (let u = 0; u < s; u++)
|
|
4381
|
+
for (let h = 0; h < s; h++) {
|
|
4382
|
+
const f = (h + 0.5) / s, m = (u + 0.5) / s, g = ji(t, a, f, m);
|
|
4383
|
+
if (!g.valid) continue;
|
|
4384
|
+
const p = Math.max(K(e, g.dir), 0);
|
|
4385
|
+
p <= 0 || (o += g.radianceOverPdf[0] * p, i += g.radianceOverPdf[1] * p, c += g.radianceOverPdf[2] * p);
|
|
4386
|
+
}
|
|
4387
|
+
const l = 1 / n;
|
|
4388
|
+
return [o * l, i * l, c * l];
|
|
4389
|
+
}
|
|
4390
|
+
export {
|
|
4391
|
+
or as BLOOM_DOWNSAMPLE_WEIGHTS,
|
|
4392
|
+
Qn as BLOOM_PYRAMID_PASS_NAMES,
|
|
4393
|
+
oi as HYBRID_OIDN_FRAMES_DEFAULT,
|
|
4394
|
+
fn as PATH_TRACER_BACKPLATE_OFFSET,
|
|
4395
|
+
eo as PATH_TRACER_BASELINE_SPP_MILESTONES,
|
|
4396
|
+
Gn as PATH_TRACER_BLOOM_FALLOFF,
|
|
4397
|
+
Qe as PATH_TRACER_BLOOM_STEPS,
|
|
4398
|
+
Un as PATH_TRACER_BLOOM_WEIGHT_SCALE,
|
|
4399
|
+
Qi as PATH_TRACER_BSDF_SHADOW_CATCHER,
|
|
4400
|
+
Kr as PATH_TRACER_BSDF_UNLIT,
|
|
4401
|
+
Ji as PATH_TRACER_BUILD_CONSTANTS,
|
|
4402
|
+
st as PATH_TRACER_BVH_BIN_COUNT,
|
|
4403
|
+
io as PATH_TRACER_BVH_INSTANCE_LEAF,
|
|
4404
|
+
fc as PATH_TRACER_BVH_LEAF_SENTINEL,
|
|
4405
|
+
hr as PATH_TRACER_BVH_MAX_LEAF_TRIS,
|
|
4406
|
+
ss as PATH_TRACER_BVH_TRI_LEAF_BIT,
|
|
4407
|
+
me as PATH_TRACER_DEFAULT_DISPLAY_GRADE,
|
|
4408
|
+
hn as PATH_TRACER_DENOISER_PARAMS_BUFFER_BYTES,
|
|
4409
|
+
ln as PATH_TRACER_DENOISER_PARAMS_BUFFER_U32S,
|
|
4410
|
+
po as PATH_TRACER_EMISSIVE_INSTANCE_NONE,
|
|
4411
|
+
jr as PATH_TRACER_ENV_BUFFER_FLOATS,
|
|
4412
|
+
Yr as PATH_TRACER_ENV_CONDITIONAL_OFFSET,
|
|
4413
|
+
gt as PATH_TRACER_ENV_HEIGHT,
|
|
4414
|
+
ze as PATH_TRACER_ENV_LAYERS,
|
|
4415
|
+
Vr as PATH_TRACER_ENV_MARGINAL_OFFSET,
|
|
4416
|
+
$r as PATH_TRACER_ENV_RADIANCE_OFFSET,
|
|
4417
|
+
ft as PATH_TRACER_ENV_WIDTH,
|
|
4418
|
+
jn as PATH_TRACER_EXPOSURE_MAX_EV,
|
|
4419
|
+
Yn as PATH_TRACER_EXPOSURE_MIN_EV,
|
|
4420
|
+
An as PATH_TRACER_FLAG_TRANSPARENT_BG,
|
|
4421
|
+
xn as PATH_TRACER_FLAG_UNLIT_AS_DIFFUSE,
|
|
4422
|
+
vn as PATH_TRACER_FLAG_USE_TLAS,
|
|
4423
|
+
Rt as PATH_TRACER_FLOATS_PER_TRIANGLE,
|
|
4424
|
+
ga as PATH_TRACER_FSR_PARAMS_BUFFER_BYTES,
|
|
4425
|
+
nn as PATH_TRACER_INSTANCES_BUFFER_BYTES,
|
|
4426
|
+
De as PATH_TRACER_INSTANCE_BYTES,
|
|
4427
|
+
Pn as PATH_TRACER_MATERIALS_BUFFER_BYTES,
|
|
4428
|
+
Rn as PATH_TRACER_MATERIAL_FIELD,
|
|
4429
|
+
se as PATH_TRACER_MATERIAL_FLOATS,
|
|
4430
|
+
kt as PATH_TRACER_MATERIAL_SLOT_NONE,
|
|
4431
|
+
be as PATH_TRACER_MAX_INSTANCES,
|
|
4432
|
+
Le as PATH_TRACER_MAX_MATERIALS,
|
|
4433
|
+
Bn as PATH_TRACER_MAX_PATH_BOUNCES,
|
|
4434
|
+
yt as PATH_TRACER_MAX_TEXTURE_SLOTS,
|
|
4435
|
+
Vt as PATH_TRACER_MAX_TRIANGLES,
|
|
4436
|
+
en as PATH_TRACER_MIN_SAMPLES_PER_TILE,
|
|
4437
|
+
kr as PATH_TRACER_PARAMS_BUFFER_U32S,
|
|
4438
|
+
es as PATH_TRACER_POST_PARAMS_BUFFER_BYTES,
|
|
4439
|
+
ts as PATH_TRACER_POST_PARAMS_FLOATS,
|
|
4440
|
+
on as PATH_TRACER_SCENE_FLAG_HAS_TRANSMISSION,
|
|
4441
|
+
zr as PATH_TRACER_SCENE_TRIANGLES_BUFFER_BYTES,
|
|
4442
|
+
tn as PATH_TRACER_TEX_ARRAY_MAX_VRAM_BYTES,
|
|
4443
|
+
En as PATH_TRACER_TEX_FLAG_EMISSIVE_UV1,
|
|
4444
|
+
_n as PATH_TRACER_TEX_FLAG_ORM_UV1,
|
|
4445
|
+
Xr as PATH_TRACER_TILE_INFO_BUFFER_BYTES,
|
|
4446
|
+
Ca as PATH_TRACER_TILE_SIZE,
|
|
4447
|
+
pn as PATH_TRACER_TILE_SIZE_MAX,
|
|
4448
|
+
mn as PATH_TRACER_TILE_SIZE_MIN,
|
|
4449
|
+
Nn as PATH_TRACER_TRANSMISSION_HEADROOM,
|
|
4450
|
+
Sc as PathTracer2Project,
|
|
4451
|
+
ao as PathTracerBaselineMetricsCollector,
|
|
4452
|
+
ds as PathTracerFrameUploadController,
|
|
4453
|
+
In as PathTracerMaterialTable,
|
|
4454
|
+
Go as PathTracerMaterialTextureArrays,
|
|
4455
|
+
Mc as PathTracerProject,
|
|
4456
|
+
wo as PathTracerSceneCache,
|
|
4457
|
+
ni as ProgressiveRenderState,
|
|
4458
|
+
qo as SpatialBudgetController,
|
|
4459
|
+
cc as accumulateGlare,
|
|
4460
|
+
Wn as acesFittedChannel,
|
|
4461
|
+
Ii as acescgToLinearSrgb,
|
|
4462
|
+
ic as applyPathTracerDisplayGrade,
|
|
4463
|
+
mo as assembleTwoLevelBvh,
|
|
4464
|
+
Cc as backplateColor,
|
|
4465
|
+
Wo as bayerOffsetForPhase,
|
|
4466
|
+
nc as bloomCompositeGain,
|
|
4467
|
+
$n as bloomExceedsThreshold,
|
|
4468
|
+
sc as bloomKarisPrefilter,
|
|
4469
|
+
rc as bloomSoftExcess,
|
|
4470
|
+
To as buildEmissiveCatalog,
|
|
4471
|
+
Li as buildEnvImportance,
|
|
4472
|
+
fo as buildMeshBlasFromObjectTriangles,
|
|
4473
|
+
Ts as buildOrthonormalBasis,
|
|
4474
|
+
ns as buildPathTracerBvhFromTriangles,
|
|
4475
|
+
Ro as buildSceneTriangles,
|
|
4476
|
+
ba as bumpPathTracerInteractionEpoch,
|
|
4477
|
+
ir as canvasFormatNeedsSrgbEncode,
|
|
4478
|
+
Ia as clampPathTracerExposureEv,
|
|
4479
|
+
is as clampPathTracerMaxBounces,
|
|
4480
|
+
qr as clampPathTracerTileSize,
|
|
4481
|
+
lc as computeAutoExposureEvFromHdr,
|
|
4482
|
+
Ms as computeBsdfLobeProbabilities,
|
|
4483
|
+
to as computeFsrEasuCon,
|
|
4484
|
+
gs as computeKhronosF0F90,
|
|
4485
|
+
Oo as computeMaterialTextureArrayDimensions,
|
|
4486
|
+
Fo as computePathTracerSceneFingerprint,
|
|
4487
|
+
wr as computePathTracerTracePixelDimensions,
|
|
4488
|
+
vc as coneSolidAngle,
|
|
4489
|
+
lr as createBloomSubgraph,
|
|
4490
|
+
Pi as createHybridAovSubgraph,
|
|
4491
|
+
We as createPathTracerGraphDefinition,
|
|
4492
|
+
gc as createPathTracerSubgraphForHybrid,
|
|
4493
|
+
ii as decodeHybridOctNormal,
|
|
4494
|
+
dc as emissiveAreaPdf,
|
|
4495
|
+
Di as emptyEnvLayer,
|
|
4496
|
+
Si as ensurePathTracerProgressGlobal,
|
|
4497
|
+
ys as envLuminance,
|
|
4498
|
+
_c as envSolidAnglePdf,
|
|
4499
|
+
Ac as environmentLightDirection,
|
|
4500
|
+
Pc as equirectToEnvRgb,
|
|
4501
|
+
hc as estimateInitialExposureEvForPunctualLights,
|
|
4502
|
+
Yi as evalBsdfMixturePdf,
|
|
4503
|
+
$i as evalClearcoatLayer,
|
|
4504
|
+
Hc as evalKhrPunctualAttenuation,
|
|
4505
|
+
Dc as evalKhrSpotAttenuation,
|
|
4506
|
+
Vi as evalLayeredOpaqueBsdfCos,
|
|
4507
|
+
Ic as evalOneSampleMisBounce,
|
|
4508
|
+
ki as evalOpaqueBsdfCos,
|
|
4509
|
+
Bc as evalRectAreaLightIrradiance,
|
|
4510
|
+
rs as exposureMultiplier,
|
|
4511
|
+
uc as formatPathTracerBaselineReport,
|
|
4512
|
+
Dn as getPathTracerEnvironmentUpload,
|
|
4513
|
+
bc as getPathTracerInteractionEpoch,
|
|
4514
|
+
sr as getPathTracerSceneRenderSettings,
|
|
4515
|
+
bs as getPathTracerTileSizeFromGlobal,
|
|
4516
|
+
Na as ggxDirectionalAlbedoFit,
|
|
4517
|
+
Vn as glareRayAngle,
|
|
4518
|
+
go as hashEmissiveCatalog,
|
|
4519
|
+
mc as hybridOctNormalToBytes,
|
|
4520
|
+
pc as hybridOidnConverged,
|
|
4521
|
+
ko as interleaveDispatchSize,
|
|
4522
|
+
Yo as interleaveRoundComplete,
|
|
4523
|
+
Ai as isPathTracerAccumPaused,
|
|
4524
|
+
no as isPathTracerTriangleLeaf,
|
|
4525
|
+
Fa as isUnlitMaterialLike,
|
|
4526
|
+
ac as linearToSrgbByte,
|
|
4527
|
+
Ec as mapDirectionForLookup,
|
|
4528
|
+
la as materialUsesMeshMaps,
|
|
4529
|
+
ci as nextHybridStaticFrames,
|
|
4530
|
+
Hn as packPathTracerBounceBudget,
|
|
4531
|
+
Rc as packPathTracerEnvironments,
|
|
4532
|
+
ri as pathTracerAovDebugMode,
|
|
4533
|
+
Tc as pathTracerGraphDefinition,
|
|
4534
|
+
so as pathTracerTriangleLeafWord,
|
|
4535
|
+
Ho as resolveMaterialBlitSourceStrategy,
|
|
4536
|
+
Ln as resolvePathTracerBounceBudget,
|
|
4537
|
+
Xn as resolvePathTracerDisplayPost,
|
|
4538
|
+
Kn as resolvePathTracerPost,
|
|
4539
|
+
Wi as sampleCosineHemisphere,
|
|
4540
|
+
Ir as sampleGgxVndf,
|
|
4541
|
+
ji as sampleRectAreaLight,
|
|
4542
|
+
yc as setPathTracerAccumPaused,
|
|
4543
|
+
ec as setPathTracerEnvironmentBuffer,
|
|
4544
|
+
tc as setPathTracerSceneRenderSettings,
|
|
4545
|
+
Fc as shadowCatcherFactor,
|
|
4546
|
+
Ea as smithLambda,
|
|
4547
|
+
xc as softboxEmissionAlong,
|
|
4548
|
+
Bi as softboxRadiance,
|
|
4549
|
+
Ni as softboxWeight,
|
|
4550
|
+
oc as summarizePathTracerHdrHighlights,
|
|
4551
|
+
co as transformAabbByMat4,
|
|
4552
|
+
Pa as vndfReflectionPdf,
|
|
4553
|
+
wc as writeBackplate,
|
|
4554
|
+
Zn as writePathTracerPostParams
|
|
4555
|
+
};
|