@roomle/web-sdk 5.1.0-alpha.4 → 5.1.0-alpha.5
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/lib/{BufferGeometry-Bl5whHAB.mjs → BufferGeometry-CxlpBjLq.mjs} +192 -195
- package/lib/BufferGeometry-CxlpBjLq.mjs.map +1 -0
- package/lib/ConfiguratorKernel.wasm +0 -0
- package/lib/{GLTFExporter-yQ7mMauu.mjs → GLTFExporter-DeNw0qAI.mjs} +86 -80
- package/lib/GLTFExporter-DeNw0qAI.mjs.map +1 -0
- package/lib/GaussianBlurNode-BR1cKBsX.mjs +65 -0
- package/lib/GaussianBlurNode-BR1cKBsX.mjs.map +1 -0
- package/lib/{Object3D-BHdngbxB.mjs → Object3D-CALIQdg1.mjs} +142 -59
- package/lib/Object3D-CALIQdg1.mjs.map +1 -0
- package/lib/{Pass-DLiMLT5k.mjs → Pass-DCljS3Z-.mjs} +4 -4
- package/lib/{Pass-DLiMLT5k.mjs.map → Pass-DCljS3Z-.mjs.map} +1 -1
- package/lib/{PointLightHelper-CuPSBuDU.mjs → PointLightHelper-C_0CYp7R.mjs} +35 -32
- package/lib/PointLightHelper-C_0CYp7R.mjs.map +1 -0
- package/lib/RoomleCore.wasm +0 -0
- package/lib/RoomleToolsCore.wasm +0 -0
- package/lib/{SpotLightHelper-m-Rh8vGU.mjs → SpotLightHelper-UUIHn43T.mjs} +22 -19
- package/lib/SpotLightHelper-UUIHn43T.mjs.map +1 -0
- package/lib/{USDZExporter-MdkuT226.mjs → USDZExporter-BBNw7Hey.mjs} +6 -3
- package/lib/USDZExporter-BBNw7Hey.mjs.map +1 -0
- package/lib/{Vector4-C7TlIAyy.mjs → Vector4-BOcWTZJI.mjs} +2 -2
- package/lib/Vector4-BOcWTZJI.mjs.map +1 -0
- package/lib/{api-Bznmr-xZ.mjs → api-CwEjmjrn.mjs} +2 -2
- package/lib/{api-Bznmr-xZ.mjs.map → api-CwEjmjrn.mjs.map} +1 -1
- package/lib/{banana-for-scale-DpKXNBt_.mjs → banana-for-scale-Cf41yXTl.mjs} +3 -3
- package/lib/{banana-for-scale-DpKXNBt_.mjs.map → banana-for-scale-Cf41yXTl.mjs.map} +1 -1
- package/lib/{common-utils-DbL4tku0.mjs → common-utils-OTJQGohe.mjs} +3 -3
- package/lib/common-utils-OTJQGohe.mjs.map +1 -0
- package/lib/{component-dimensioning-BaUqwqYJ.mjs → component-dimensioning-yPK46Y5o.mjs} +26 -26
- package/lib/{component-dimensioning-BaUqwqYJ.mjs.map → component-dimensioning-yPK46Y5o.mjs.map} +1 -1
- package/lib/{component-raycast-helper-4i8b4E5B.mjs → component-raycast-helper-CnpnRaFg.mjs} +15 -15
- package/lib/{component-raycast-helper-4i8b4E5B.mjs.map → component-raycast-helper-CnpnRaFg.mjs.map} +1 -1
- package/lib/{configurator-CDw_c6tB.mjs → configurator-iYlO_buA.mjs} +4 -4
- package/lib/{configurator-CDw_c6tB.mjs.map → configurator-iYlO_buA.mjs.map} +1 -1
- package/lib/configurator-y7zIaUe_.mjs +2 -0
- package/lib/{continuous-drawing-helper-DqHIR_qF.mjs → continuous-drawing-helper-CTfGRTfH.mjs} +3 -3
- package/lib/{continuous-drawing-helper-DqHIR_qF.mjs.map → continuous-drawing-helper-CTfGRTfH.mjs.map} +1 -1
- package/lib/dimensioning-helper-CQlesi-m.mjs +2 -0
- package/lib/{dimensioning-helper-CGPjS2hW.mjs → dimensioning-helper-DSlkLDmx.mjs} +42 -36
- package/lib/dimensioning-helper-DSlkLDmx.mjs.map +1 -0
- package/lib/{glb-viewer-B-Zr743e.mjs → glb-viewer-AGV-_xKd.mjs} +33 -33
- package/lib/{glb-viewer-B-Zr743e.mjs.map → glb-viewer-AGV-_xKd.mjs.map} +1 -1
- package/lib/glb-viewer-DSzNR4CI.mjs +2 -0
- package/lib/{highlight-coordinator-4gkjde82.mjs → highlight-coordinator-DU6oFunq.mjs} +6 -6
- package/lib/{highlight-coordinator-4gkjde82.mjs.map → highlight-coordinator-DU6oFunq.mjs.map} +1 -1
- package/lib/{homag-intelligence-D7S7r-Gc.mjs → homag-intelligence-D_yBv0ig.mjs} +3 -3
- package/lib/{homag-intelligence-D7S7r-Gc.mjs.map → homag-intelligence-D_yBv0ig.mjs.map} +1 -1
- package/lib/{hosek-wilkie-sky-iMar2iw-.mjs → hosek-wilkie-sky-DmTvnxMA.mjs} +33 -33
- package/lib/{hosek-wilkie-sky-iMar2iw-.mjs.map → hosek-wilkie-sky-DmTvnxMA.mjs.map} +1 -1
- package/lib/{imos-ix-poc-export-helper-CyGqK7nu.mjs → imos-ix-poc-export-helper-BGN97m8W.mjs} +3 -3
- package/lib/{imos-ix-poc-export-helper-CyGqK7nu.mjs.map → imos-ix-poc-export-helper-BGN97m8W.mjs.map} +1 -1
- package/lib/{kernel-utils-BvatnA7U.mjs → kernel-utils-BYKmP0mf.mjs} +13 -13
- package/lib/{kernel-utils-BvatnA7U.mjs.map → kernel-utils-BYKmP0mf.mjs.map} +1 -1
- package/lib/{material-viewer-CTsSfTfL.mjs → material-viewer-BuBSXGw6.mjs} +18 -18
- package/lib/{material-viewer-CTsSfTfL.mjs.map → material-viewer-BuBSXGw6.mjs.map} +1 -1
- package/lib/{packages-BXAZEcKa.mjs → packages-CduZDHYG.mjs} +5 -5
- package/lib/{packages-BXAZEcKa.mjs.map → packages-CduZDHYG.mjs.map} +1 -1
- package/lib/planner-B-SWR4R8.mjs +2 -0
- package/lib/{planner-jvLAnYww.mjs → planner-BuBkFbra.mjs} +3 -3
- package/lib/{planner-jvLAnYww.mjs.map → planner-BuBkFbra.mjs.map} +1 -1
- package/lib/{plugin-system-CRaC04G5.mjs → plugin-system-CPf99Zkf.mjs} +2 -2
- package/lib/{plugin-system-CRaC04G5.mjs.map → plugin-system-CPf99Zkf.mjs.map} +1 -1
- package/lib/{render-cache-DCPIQbO1.mjs → render-cache-CPppt7Rd.mjs} +5 -5
- package/lib/{render-cache-DCPIQbO1.mjs.map → render-cache-CPppt7Rd.mjs.map} +1 -1
- package/lib/{render-order-BPF2wDMw.mjs → render-order-a0QAbB7Q.mjs} +2 -2
- package/lib/{render-order-BPF2wDMw.mjs.map → render-order-a0QAbB7Q.mjs.map} +1 -1
- package/lib/roomle-headless.d.ts +0 -2
- package/lib/roomle-headless.js +14 -14
- package/lib/{roomle-renderer-Ato6RMrd.mjs → roomle-renderer-UJINLYxS.mjs} +2 -2
- package/lib/{roomle-renderer-Ato6RMrd.mjs.map → roomle-renderer-UJINLYxS.mjs.map} +1 -1
- package/lib/{roomle-sdk-CBwhwX_e.mjs → roomle-sdk-CcNdTp_n.mjs} +1844 -1889
- package/lib/roomle-sdk-CcNdTp_n.mjs.map +1 -0
- package/lib/roomle-sdk.d.ts +0 -2
- package/lib/roomle-sdk.js +7 -7
- package/lib/{roomle-webgpu-renderer-BfZKcXSz.mjs → roomle-webgpu-renderer-BSvxbopA.mjs} +900 -707
- package/lib/roomle-webgpu-renderer-BSvxbopA.mjs.map +1 -0
- package/lib/{scene-renderer-BHYZac3H.mjs → scene-renderer--DzrpIl_.mjs} +309 -309
- package/lib/{scene-renderer-BHYZac3H.mjs.map → scene-renderer--DzrpIl_.mjs.map} +1 -1
- package/lib/{script-loader-CvnG6LgL.mjs → script-loader-D6i0wQ_j.mjs} +2 -2
- package/lib/{script-loader-CvnG6LgL.mjs.map → script-loader-D6i0wQ_j.mjs.map} +1 -1
- package/lib/{shading-settings-BBhR7KcS.mjs → shading-settings-6v-7O_Sz.mjs} +49 -49
- package/lib/{shading-settings-BBhR7KcS.mjs.map → shading-settings-6v-7O_Sz.mjs.map} +1 -1
- package/lib/src-6KtBPZXp.mjs +2 -0
- package/lib/{src-HhklrVDg.mjs → src-Dg0wYIom.mjs} +150 -150
- package/lib/{src-HhklrVDg.mjs.map → src-Dg0wYIom.mjs.map} +1 -1
- package/lib/static/roomle-core-hsc/node_modules/roomle-core-hsc/package.json +1 -1
- package/lib/static/roomle-core-hsc/node_modules/roomle-core-hsc/wasm_modern/ConfiguratorKernel.wasm +0 -0
- package/lib/static/roomle-core-hsc/node_modules/roomle-core-hsc/wasm_modern/RoomleCore.wasm +0 -0
- package/lib/static/roomle-core-hsc/node_modules/roomle-core-hsc/wasm_modern/RoomleToolsCore.wasm +0 -0
- package/lib/{stats-helper-PndcZCzL.mjs → stats-helper-DYjPPDnz.mjs} +2 -2
- package/lib/{stats-helper-PndcZCzL.mjs.map → stats-helper-DYjPPDnz.mjs.map} +1 -1
- package/lib/{three.core-0KaTx8dm.mjs → three.core-BTUCraWz.mjs} +976 -884
- package/lib/three.core-BTUCraWz.mjs.map +1 -0
- package/lib/{three.module-dym6j3lO.mjs → three.module-DUSFrLM6.mjs} +1789 -1739
- package/lib/three.module-DUSFrLM6.mjs.map +1 -0
- package/lib/three.tsl-De6A-G56.mjs +158 -0
- package/lib/three.tsl-De6A-G56.mjs.map +1 -0
- package/lib/three.tsl-DtfvggFX.mjs +2 -0
- package/lib/three.webgpu-B1OhMci_.mjs +3 -0
- package/lib/{three.webgpu-D3nSEIjD.mjs → three.webgpu-wPiwbpFM.mjs} +5806 -4926
- package/lib/three.webgpu-wPiwbpFM.mjs.map +1 -0
- package/lib/{threejs-utils-v1uOvccg.mjs → threejs-utils-lVSsgAiQ.mjs} +68 -68
- package/lib/{threejs-utils-v1uOvccg.mjs.map → threejs-utils-lVSsgAiQ.mjs.map} +1 -1
- package/lib/{tools-core-B29U-88K.mjs → tools-core-CRGER_KC.mjs} +3 -3
- package/lib/{tools-core-B29U-88K.mjs.map → tools-core-CRGER_KC.mjs.map} +1 -1
- package/lib/{webgpu-BHAP6BLI.mjs → webgpu-BxYJfBjz.mjs} +555 -555
- package/lib/{webgpu-BHAP6BLI.mjs.map → webgpu-BxYJfBjz.mjs.map} +1 -1
- package/package.json +5 -5
- package/lib/BufferGeometry-Bl5whHAB.mjs.map +0 -1
- package/lib/GLTFExporter-yQ7mMauu.mjs.map +0 -1
- package/lib/GaussianBlurNode-DNBEf5-n.mjs +0 -59
- package/lib/GaussianBlurNode-DNBEf5-n.mjs.map +0 -1
- package/lib/Object3D-BHdngbxB.mjs.map +0 -1
- package/lib/PointLightHelper-CuPSBuDU.mjs.map +0 -1
- package/lib/SpotLightHelper-m-Rh8vGU.mjs.map +0 -1
- package/lib/USDZExporter-MdkuT226.mjs.map +0 -1
- package/lib/Vector4-C7TlIAyy.mjs.map +0 -1
- package/lib/common-utils-DbL4tku0.mjs.map +0 -1
- package/lib/configurator-BYQdWEvf.mjs +0 -2
- package/lib/dimensioning-helper-CGPjS2hW.mjs.map +0 -1
- package/lib/dimensioning-helper-VndKlIXS.mjs +0 -2
- package/lib/glb-viewer-Bd5Xn6Oq.mjs +0 -2
- package/lib/planner-DMk3T4ts.mjs +0 -2
- package/lib/roomle-sdk-CBwhwX_e.mjs.map +0 -1
- package/lib/roomle-webgpu-renderer-BfZKcXSz.mjs.map +0 -1
- package/lib/src-Bbq3Hqzn.mjs +0 -2
- package/lib/three.core-0KaTx8dm.mjs.map +0 -1
- package/lib/three.module-dym6j3lO.mjs.map +0 -1
- package/lib/three.tsl-BTc4fg8T.mjs +0 -2
- package/lib/three.tsl-Cf0-sCqB.mjs +0 -152
- package/lib/three.tsl-Cf0-sCqB.mjs.map +0 -1
- package/lib/three.webgpu-ClICiWlK.mjs +0 -3
- package/lib/three.webgpu-D3nSEIjD.mjs.map +0 -1
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
4
|
-
import { l as
|
|
5
|
-
import { At as
|
|
6
|
-
Object.defineProperty(
|
|
1
|
+
import { $r as e, Ai as t, Ar as n, Di as r, E as i, Ei as a, Gr as o, Jt as s, Kn as c, Nr as l, Pr as u, Qr as d, S as f, Ti as p, U as m, V as h, Wr as g, Xt as _, bn as v, cn as y, ct as b, di as x, h as ee, ht as S, jr as C, kn as te, li as ne, ln as re, m as w, sn as ie, un as ae, w as oe, xi as se } from "./three.core-BTUCraWz.mjs";
|
|
2
|
+
import { t as ce } from "./Pass-DCljS3Z-.mjs";
|
|
3
|
+
import { Bn as T, C as le, Dt as ue, H as de, Ln as fe, Un as pe, Wn as E, X as D, qn as me, un as he, vt as ge } from "./three.webgpu-wPiwbpFM.mjs";
|
|
4
|
+
import { l as _e, n as ve, o as ye, r as be, t as xe } from "./src-Dg0wYIom.mjs";
|
|
5
|
+
import { At as O, F as k, Gt as Se, H as Ce, Kt as A, Lt as we, Mt as Te, Nt as j, Ot as M, Pt as Ee, Rt as De, Tt as N, U as Oe, Vt as ke, gt as P, jt as Ae, k as F } from "./three.tsl-De6A-G56.mjs";
|
|
6
|
+
Object.defineProperty(E.prototype, "layout", { get() {
|
|
7
7
|
return this;
|
|
8
|
-
} }),
|
|
9
|
-
var
|
|
8
|
+
} }), E.prototype.isStruct = !0;
|
|
9
|
+
var je = new E({
|
|
10
10
|
min: "array<f32, 3>",
|
|
11
11
|
max: "array<f32, 3>"
|
|
12
12
|
}, "BVHBoundingBox");
|
|
13
|
-
|
|
14
|
-
var
|
|
13
|
+
je.getLength = () => 6;
|
|
14
|
+
var Me = new E({
|
|
15
15
|
bounds: "BVHBoundingBox",
|
|
16
16
|
rightChildOrTriangleOffset: "uint",
|
|
17
17
|
splitAxisOrTriangleCount: "uint"
|
|
18
18
|
}, "BVHNode");
|
|
19
|
-
|
|
20
|
-
var
|
|
19
|
+
Me.getLength = () => je.getLength() + 2;
|
|
20
|
+
var Ne = new E({
|
|
21
21
|
matrixWorld: "mat4x4f",
|
|
22
22
|
inverseMatrixWorld: "mat4x4f",
|
|
23
23
|
nodeOffset: "uint",
|
|
24
24
|
visible: "uint",
|
|
25
25
|
_alignment0: "uint",
|
|
26
26
|
_alignment1: "uint"
|
|
27
|
-
}, "TransformStruct"),
|
|
27
|
+
}, "TransformStruct"), I = new E({
|
|
28
28
|
origin: "vec3f",
|
|
29
29
|
direction: "vec3f"
|
|
30
|
-
}, "Ray"),
|
|
30
|
+
}, "Ray"), L = new E({
|
|
31
31
|
indices: "vec4u",
|
|
32
32
|
normal: "vec3f",
|
|
33
33
|
didHit: "bool",
|
|
@@ -35,7 +35,7 @@ var je = new D({
|
|
|
35
35
|
objectIndex: "uint",
|
|
36
36
|
side: "float",
|
|
37
37
|
dist: "float"
|
|
38
|
-
}, "IntersectionResult"),
|
|
38
|
+
}, "IntersectionResult"), Pe = new E({
|
|
39
39
|
faceIndices: "vec4u",
|
|
40
40
|
closestPoint: "vec3f",
|
|
41
41
|
found: "bool",
|
|
@@ -44,7 +44,7 @@ var je = new D({
|
|
|
44
44
|
faceNormal: "vec3f",
|
|
45
45
|
side: "float",
|
|
46
46
|
distanceSq: "float"
|
|
47
|
-
}, "PointQueryResult"),
|
|
47
|
+
}, "PointQueryResult"), Fe = me.nodeProxyConstructor ?? ((e, t) => new Proxy(e, {
|
|
48
48
|
get(e, n, r) {
|
|
49
49
|
let i = Reflect.get(t, n, r);
|
|
50
50
|
return i === void 0 && n === "functionNode" ? t : i;
|
|
@@ -52,7 +52,7 @@ var je = new D({
|
|
|
52
52
|
set(e, n, r) {
|
|
53
53
|
return Reflect.set(t, n, r);
|
|
54
54
|
}
|
|
55
|
-
})),
|
|
55
|
+
})), Ie = class extends ue {
|
|
56
56
|
static get type() {
|
|
57
57
|
return "ProxyCallNode";
|
|
58
58
|
}
|
|
@@ -62,7 +62,7 @@ var je = new D({
|
|
|
62
62
|
setup() {
|
|
63
63
|
return this.proxyNode.proxyNode.call(...this.params);
|
|
64
64
|
}
|
|
65
|
-
},
|
|
65
|
+
}, Le = class {
|
|
66
66
|
get isNode() {
|
|
67
67
|
return !0;
|
|
68
68
|
}
|
|
@@ -88,18 +88,18 @@ var je = new D({
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
},
|
|
92
|
-
let t = new
|
|
93
|
-
return
|
|
91
|
+
}, R = (...e) => new Le(...e), z = (...e) => {
|
|
92
|
+
let t = new Le(...e);
|
|
93
|
+
return Fe((...e) => new Ie(t, e), t);
|
|
94
94
|
};
|
|
95
95
|
//#endregion
|
|
96
96
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/utils/toObjectBVH.js
|
|
97
|
-
function
|
|
98
|
-
return e instanceof
|
|
97
|
+
function Re(e) {
|
|
98
|
+
return e instanceof ve ? e : (Array.isArray(e) || (e = [e]), new ve(e.map((e) => {
|
|
99
99
|
if (e.isObject3D) return e;
|
|
100
|
-
if (e.isBufferGeometry) return new
|
|
101
|
-
if (e instanceof
|
|
102
|
-
let t = new
|
|
100
|
+
if (e.isBufferGeometry) return new re(e);
|
|
101
|
+
if (e instanceof ye) {
|
|
102
|
+
let t = new re();
|
|
103
103
|
return t.geometry.boundsTree = e, t;
|
|
104
104
|
}
|
|
105
105
|
}), {
|
|
@@ -109,8 +109,8 @@ function Ie(e) {
|
|
|
109
109
|
}
|
|
110
110
|
//#endregion
|
|
111
111
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/utils/packBVHBufferUtils.js
|
|
112
|
-
var
|
|
113
|
-
function
|
|
112
|
+
var B = /* @__PURE__ */ new r(), V = /* @__PURE__ */ new r();
|
|
113
|
+
function ze(e, t) {
|
|
114
114
|
let n = e ? e.array : null, r = new Uint32Array(t.length * 3);
|
|
115
115
|
for (let e = 0, i = t.length; e < i; e++) {
|
|
116
116
|
let i = 3 * e, a = 3 * t[e];
|
|
@@ -118,7 +118,7 @@ function Le(e, t) {
|
|
|
118
118
|
}
|
|
119
119
|
return r;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function Be(e, t, n, r, i, a = !1) {
|
|
122
122
|
let o = new Uint16Array(i), s = new Uint32Array(i), c = new Float32Array(i), l = [], u = 0;
|
|
123
123
|
return e._roots.forEach((e) => {
|
|
124
124
|
let i = new Uint16Array(e), d = new Uint32Array(e);
|
|
@@ -138,47 +138,47 @@ function Re(e, t, n, r, i, a = !1) {
|
|
|
138
138
|
u += e, t += e;
|
|
139
139
|
}
|
|
140
140
|
o[h + 14] = t;
|
|
141
|
-
} else s[m + 6] = d[f + 6] + t, o[h + 14] = i[p + 14], o[h + 15] =
|
|
141
|
+
} else s[m + 6] = d[f + 6] + t, o[h + 14] = i[p + 14], o[h + 15] = _e;
|
|
142
142
|
else s[m + 6] = d[f + 6], s[m + 7] = d[f + 7];
|
|
143
143
|
r++;
|
|
144
144
|
}
|
|
145
145
|
}), l;
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function Ve(e, t, n, r, i) {
|
|
148
148
|
let { geometry: a } = e, { start: o, count: s, vertexStart: c } = t;
|
|
149
149
|
if (e.indirect) {
|
|
150
|
-
let t =
|
|
150
|
+
let t = ze(a.index, e._indirectBuffer);
|
|
151
151
|
for (let e = 0; e < t.length; e++) i[e + r] = t[e] - c + n;
|
|
152
152
|
} else if (a.index) for (let e = 0; e < s; e++) i[e + r] = a.index.getX(e + o) - c + n;
|
|
153
153
|
else for (let e = 0; e < s; e++) i[e + r] = e + o + n;
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function He(e, t, n, r, i, a) {
|
|
156
156
|
let { geometry: o, mesh: s = null } = e, { vertexStart: c, vertexCount: l } = t, u = new Float32Array(r), d = i.getLength();
|
|
157
157
|
i.membersLayout.forEach(({ name: e }, t) => {
|
|
158
158
|
let r = o.attributes[e];
|
|
159
|
-
a.getDefaultAttributeValue(e,
|
|
159
|
+
a.getDefaultAttributeValue(e, B);
|
|
160
160
|
for (let i = 0; i < l; i++) {
|
|
161
161
|
if (r) {
|
|
162
|
-
switch (
|
|
162
|
+
switch (V.fromBufferAttribute(r, i + c), r.itemSize) {
|
|
163
163
|
case 1:
|
|
164
|
-
|
|
164
|
+
V.y = B.y, V.z = B.z, V.w = B.w;
|
|
165
165
|
break;
|
|
166
166
|
case 2:
|
|
167
|
-
|
|
167
|
+
V.z = B.z, V.w = B.w;
|
|
168
168
|
break;
|
|
169
169
|
case 3:
|
|
170
|
-
|
|
170
|
+
V.w = B.w;
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
|
-
s && (e === "position" || e === "normal" || e === "tangent") && s.applyBoneTransform(i + c,
|
|
174
|
-
} else
|
|
175
|
-
|
|
173
|
+
s && (e === "position" || e === "normal" || e === "tangent") && s.applyBoneTransform(i + c, V);
|
|
174
|
+
} else V.copy(B);
|
|
175
|
+
V.toArray(u, (n + i) * d + t * 4);
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/nodes/WGSLTagFnNode.js
|
|
181
|
-
var
|
|
181
|
+
var Ue = me.nodeProxyConstructor ?? ((e, t) => new Proxy(e, {
|
|
182
182
|
get(e, n, r) {
|
|
183
183
|
let i = Reflect.get(t, n, r);
|
|
184
184
|
return i === void 0 && n === "functionNode" ? t : i;
|
|
@@ -186,14 +186,14 @@ var Ve = ue.nodeProxyConstructor ?? ((e, t) => new Proxy(e, {
|
|
|
186
186
|
set(e, n, r) {
|
|
187
187
|
return Reflect.set(t, n, r);
|
|
188
188
|
}
|
|
189
|
-
})),
|
|
189
|
+
})), We = class extends ue {
|
|
190
190
|
constructor(e) {
|
|
191
191
|
super(), this.literal = e;
|
|
192
192
|
}
|
|
193
193
|
build() {
|
|
194
194
|
return this.literal;
|
|
195
195
|
}
|
|
196
|
-
},
|
|
196
|
+
}, Ge = class extends ue {
|
|
197
197
|
constructor(e, t = "property") {
|
|
198
198
|
super(), this.node = e, this.output = t;
|
|
199
199
|
}
|
|
@@ -201,40 +201,40 @@ var Ve = ue.nodeProxyConstructor ?? ((e, t) => new Proxy(e, {
|
|
|
201
201
|
return this.node.build(e, this.output);
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
|
-
function
|
|
204
|
+
function Ke(e) {
|
|
205
205
|
return typeof e == "function" && e.functionNode && !e.isNode ? e.functionNode : e;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
return e =
|
|
207
|
+
function qe(e) {
|
|
208
|
+
return e = Ke(e), e.isNode ? new Ge(e) : null;
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function Je(e) {
|
|
211
211
|
let t = [];
|
|
212
212
|
for (let n of e) if (Array.isArray(n)) for (let e of n) {
|
|
213
|
-
let n =
|
|
213
|
+
let n = qe(e);
|
|
214
214
|
n && t.push(n);
|
|
215
215
|
}
|
|
216
216
|
return t;
|
|
217
217
|
}
|
|
218
|
-
function
|
|
219
|
-
return e.map((e) => (e =
|
|
218
|
+
function Ye(e) {
|
|
219
|
+
return e.map((e) => (e = Ke(e), e && e.isNode ? e instanceof Qe ? new Ge(e, "inline") : new Ge(e) : e));
|
|
220
220
|
}
|
|
221
|
-
function
|
|
221
|
+
function Xe(e, t, n) {
|
|
222
222
|
let r = "";
|
|
223
223
|
for (let i = 0, a = e.length; i < a; i++) if (r += e[i], i < t.length) {
|
|
224
|
-
let e =
|
|
224
|
+
let e = Ke(t[i]);
|
|
225
225
|
Array.isArray(e) || (typeof e == "string" || typeof e == "number" ? r += String(e) : r += e.build(n));
|
|
226
226
|
}
|
|
227
227
|
return r;
|
|
228
228
|
}
|
|
229
|
-
var
|
|
229
|
+
var Ze = class extends de {
|
|
230
230
|
static get type() {
|
|
231
231
|
return "WGSLTagFnNode";
|
|
232
232
|
}
|
|
233
233
|
constructor(e, t, n = "wgsl") {
|
|
234
|
-
super("",
|
|
234
|
+
super("", Je(t), n), this.tokens = e, this.args = t;
|
|
235
235
|
}
|
|
236
236
|
getNodeFunction(e) {
|
|
237
|
-
let { tokens: t } = this, n =
|
|
237
|
+
let { tokens: t } = this, n = Ye(this.args), r = e.getDataFromNode(this), i = r.nodeFunction;
|
|
238
238
|
if (i === void 0) {
|
|
239
239
|
let a = "";
|
|
240
240
|
for (let r = 0, i = t.length; r < i; r++) if (a += t[r], r < n.length) {
|
|
@@ -246,55 +246,55 @@ var Ye = class extends de {
|
|
|
246
246
|
return i;
|
|
247
247
|
}
|
|
248
248
|
generate(e, t) {
|
|
249
|
-
let n = super.generate(e, t), r =
|
|
249
|
+
let n = super.generate(e, t), r = Xe(this.tokens, Ye(this.args), e), { type: i } = this.getNodeFunction(e), a = e.getCodeFromNode(this, i);
|
|
250
250
|
return a.code = r.replace(/\/\/.+[\n\r]/g, "").replace(/->\s*void/, "").trim(), n;
|
|
251
251
|
}
|
|
252
|
-
},
|
|
252
|
+
}, Qe = class extends le {
|
|
253
253
|
static get type() {
|
|
254
254
|
return "WGSLTagCodeNode";
|
|
255
255
|
}
|
|
256
256
|
constructor(e, t, n = "wgsl") {
|
|
257
|
-
super("",
|
|
257
|
+
super("", Je(t), n), this.tokens = e, this.args = t;
|
|
258
258
|
}
|
|
259
259
|
build(e, t) {
|
|
260
|
-
return t === "inline" ?
|
|
260
|
+
return t === "inline" ? Xe(this.tokens, Ye(this.args), e) : super.build(e, t);
|
|
261
261
|
}
|
|
262
262
|
generate(e) {
|
|
263
263
|
super.generate(e);
|
|
264
264
|
let t = e.getCodeFromNode(this, this.getNodeType(e));
|
|
265
|
-
return t.code =
|
|
265
|
+
return t.code = Xe(this.tokens, Ye(this.args), e), t.code;
|
|
266
266
|
}
|
|
267
|
-
},
|
|
267
|
+
}, $e = (e) => Ue((...t) => {
|
|
268
268
|
if (t.length === 1 && t[0] && typeof t[0] == "object" && !t[0].isNode) {
|
|
269
269
|
let e = t[0];
|
|
270
|
-
for (let t in e) typeof e[t] == "string" && (e[t] = new
|
|
270
|
+
for (let t in e) typeof e[t] == "string" && (e[t] = new We(e[t]));
|
|
271
271
|
}
|
|
272
272
|
return e.call(...t);
|
|
273
|
-
}, e),
|
|
273
|
+
}, e), H = (e, ...t) => $e(new Ze(e, t)), U = (e, ...t) => new Qe(e, t), et = Te(60);
|
|
274
274
|
//#endregion
|
|
275
275
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/shapecastFns/getShapecastFn.js
|
|
276
|
-
function
|
|
276
|
+
function tt(e, t) {
|
|
277
277
|
let { name: n = `bvh_shapecast_fn_${Math.random().toString(36).substring(2, 7)}`, shapeStruct: r, resultStruct: i = null, boundsOrderFn: a = null, intersectsBoundsFn: o, intersectRangeFn: s, transformShapeFn: c = null, transformResultFn: l = null, resetShapeFn: u = null } = t, { nodes: d, transforms: f } = e.storage, p = "";
|
|
278
|
-
l && (p =
|
|
278
|
+
l && (p = U`${l}( result, i );`);
|
|
279
279
|
let m = "";
|
|
280
|
-
c && (m =
|
|
280
|
+
c && (m = U`${c}( &localShape, i );`);
|
|
281
281
|
let h = "";
|
|
282
|
-
u && (h =
|
|
282
|
+
u && (h = U`${u}( i );`);
|
|
283
283
|
let g = "";
|
|
284
|
-
a && (g =
|
|
284
|
+
a && (g = U`
|
|
285
285
|
let leftToRight = ${a}( shape, splitAxis, node );
|
|
286
286
|
c1 = select( rightIndex, leftIndex, leftToRight );
|
|
287
287
|
c2 = select( leftIndex, rightIndex, leftToRight );
|
|
288
288
|
`);
|
|
289
|
-
let _ = i ?
|
|
289
|
+
let _ = i ? U`result: ptr<function, ${i}>` : "", v = i ? "result" : "", y = (e) => U`
|
|
290
290
|
|
|
291
291
|
var pointer: i32 = 0;
|
|
292
|
-
var stack: array<u32, ${
|
|
292
|
+
var stack: array<u32, ${et}>;
|
|
293
293
|
stack[ 0 ] = rootNodeIndex;
|
|
294
294
|
|
|
295
295
|
loop {
|
|
296
296
|
|
|
297
|
-
if ( pointer < 0 || pointer >= i32( ${
|
|
297
|
+
if ( pointer < 0 || pointer >= i32( ${et} ) ) {
|
|
298
298
|
|
|
299
299
|
break;
|
|
300
300
|
|
|
@@ -340,12 +340,12 @@ function $e(e, t) {
|
|
|
340
340
|
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
`, b =
|
|
343
|
+
`, b = H`
|
|
344
344
|
// fn
|
|
345
345
|
fn ${n}_blas( shape: ${r}, rootNodeIndex: u32, ${_} ) -> bool {
|
|
346
346
|
|
|
347
347
|
var didHit = false;
|
|
348
|
-
${y(
|
|
348
|
+
${y(U`
|
|
349
349
|
|
|
350
350
|
didHit = ${s}( shape, offset, count, ${v} ) || didHit;
|
|
351
351
|
|
|
@@ -354,13 +354,13 @@ function $e(e, t) {
|
|
|
354
354
|
return didHit;
|
|
355
355
|
|
|
356
356
|
}
|
|
357
|
-
`, x =
|
|
357
|
+
`, x = H`
|
|
358
358
|
// fn
|
|
359
359
|
fn ${n}( shape: ${r}, ${_} ) -> bool {
|
|
360
360
|
|
|
361
361
|
const rootNodeIndex = 0u;
|
|
362
362
|
var didHit = false;
|
|
363
|
-
${y(
|
|
363
|
+
${y(U`
|
|
364
364
|
|
|
365
365
|
for ( var i = offset; i < offset + count; i ++ ) {
|
|
366
366
|
|
|
@@ -396,7 +396,7 @@ function $e(e, t) {
|
|
|
396
396
|
}
|
|
397
397
|
//#endregion
|
|
398
398
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/tsl/fns.js
|
|
399
|
-
var
|
|
399
|
+
var nt = H`
|
|
400
400
|
// fn
|
|
401
401
|
fn closestPointToTriangle(
|
|
402
402
|
p: vec3f,
|
|
@@ -442,13 +442,13 @@ var et = W`
|
|
|
442
442
|
return vec3f( w, u, v );
|
|
443
443
|
|
|
444
444
|
}
|
|
445
|
-
`,
|
|
445
|
+
`, rt = H`
|
|
446
446
|
// fn
|
|
447
|
-
fn intersectRayTriangle( ray: ${
|
|
447
|
+
fn intersectRayTriangle( ray: ${I}, a: vec3f, b: vec3f, c: vec3f, threshold: f32 ) -> ${L} {
|
|
448
448
|
|
|
449
449
|
const DET_EPSILON = 1e-15;
|
|
450
450
|
|
|
451
|
-
var result: ${
|
|
451
|
+
var result: ${L};
|
|
452
452
|
result.didHit = false;
|
|
453
453
|
|
|
454
454
|
let edge1 = b - a;
|
|
@@ -498,12 +498,12 @@ var et = W`
|
|
|
498
498
|
return result;
|
|
499
499
|
|
|
500
500
|
}
|
|
501
|
-
`,
|
|
501
|
+
`, it = H`
|
|
502
502
|
// fn
|
|
503
|
-
fn ndcToCameraRay( ndc: vec2f, inverseModelViewProjection: mat4x4f ) -> ${
|
|
503
|
+
fn ndcToCameraRay( ndc: vec2f, inverseModelViewProjection: mat4x4f ) -> ${I} {
|
|
504
504
|
|
|
505
505
|
var homogeneous = vec4f();
|
|
506
|
-
var ray: ${
|
|
506
|
+
var ray: ${I};
|
|
507
507
|
|
|
508
508
|
homogeneous = inverseModelViewProjection * vec4f( ndc, 0.0, 1.0 );
|
|
509
509
|
ray.origin = homogeneous.xyz / homogeneous.w;
|
|
@@ -517,21 +517,21 @@ var et = W`
|
|
|
517
517
|
`;
|
|
518
518
|
//#endregion
|
|
519
519
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/shapecastFns/getRaycastFirstHitFn.js
|
|
520
|
-
function
|
|
521
|
-
let { index: t, attributes: n, transforms: r } = e.storage, i =
|
|
520
|
+
function at(e) {
|
|
521
|
+
let { index: t, attributes: n, transforms: r } = e.storage, i = F(1).toVar(`bvh_rayScalar_${Math.random().toString(36).substring(2, 7)}`);
|
|
522
522
|
return e.getShapecastFn({
|
|
523
523
|
name: "bvh_RaycastFirstHit",
|
|
524
|
-
shapeStruct:
|
|
525
|
-
resultStruct:
|
|
526
|
-
boundsOrderFn:
|
|
527
|
-
fn getBoundsOrder( ray: ${
|
|
524
|
+
shapeStruct: I,
|
|
525
|
+
resultStruct: L,
|
|
526
|
+
boundsOrderFn: H`
|
|
527
|
+
fn getBoundsOrder( ray: ${I}, splitAxis: u32, node: ${Me} ) -> bool {
|
|
528
528
|
|
|
529
529
|
return ray.direction[ splitAxis ] >= 0.0;
|
|
530
530
|
|
|
531
531
|
}
|
|
532
532
|
`,
|
|
533
|
-
intersectsBoundsFn:
|
|
534
|
-
fn rayIntersectsBounds( ray: ${
|
|
533
|
+
intersectsBoundsFn: H`
|
|
534
|
+
fn rayIntersectsBounds( ray: ${I}, bounds: ${je}, result: ptr<function, ${L}> ) -> u32 {
|
|
535
535
|
|
|
536
536
|
let boundsMin = vec3( bounds.min[0], bounds.min[1], bounds.min[2] );
|
|
537
537
|
let boundsMax = vec3( bounds.max[0], bounds.max[1], bounds.max[2] );
|
|
@@ -573,8 +573,8 @@ function rt(e) {
|
|
|
573
573
|
}
|
|
574
574
|
|
|
575
575
|
`,
|
|
576
|
-
intersectRangeFn:
|
|
577
|
-
fn intersectRange( ray: ${
|
|
576
|
+
intersectRangeFn: H`
|
|
577
|
+
fn intersectRange( ray: ${I}, offset: u32, count: u32, result: ptr<function, ${L}> ) -> bool {
|
|
578
578
|
|
|
579
579
|
var didHit = false;
|
|
580
580
|
for ( var ti = offset; ti < offset + count; ti = ti + 1u ) {
|
|
@@ -587,7 +587,7 @@ function rt(e) {
|
|
|
587
587
|
let b = ${n}[ i1 ].position.xyz;
|
|
588
588
|
let c = ${n}[ i2 ].position.xyz;
|
|
589
589
|
|
|
590
|
-
var triResult = ${
|
|
590
|
+
var triResult = ${rt}( ray, a, b, c, 0.0 );
|
|
591
591
|
triResult.dist *= ${i};
|
|
592
592
|
if ( triResult.didHit && ( ! result.didHit || triResult.dist < result.dist ) ) {
|
|
593
593
|
|
|
@@ -608,8 +608,8 @@ function rt(e) {
|
|
|
608
608
|
|
|
609
609
|
}
|
|
610
610
|
`,
|
|
611
|
-
transformShapeFn:
|
|
612
|
-
fn transformRay( ray: ptr<function, ${
|
|
611
|
+
transformShapeFn: H`
|
|
612
|
+
fn transformRay( ray: ptr<function, ${I}>, objectIndex: u32 ) -> void {
|
|
613
613
|
|
|
614
614
|
let toLocal = ${r}[ objectIndex ].inverseMatrixWorld;
|
|
615
615
|
ray.origin = ( toLocal * vec4f( ray.origin, 1.0 ) ).xyz;
|
|
@@ -621,8 +621,8 @@ function rt(e) {
|
|
|
621
621
|
|
|
622
622
|
}
|
|
623
623
|
`,
|
|
624
|
-
transformResultFn:
|
|
625
|
-
fn transformResult( hit: ptr<function, ${
|
|
624
|
+
transformResultFn: H`
|
|
625
|
+
fn transformResult( hit: ptr<function, ${L}>, objectIndex: u32 ) -> void {
|
|
626
626
|
|
|
627
627
|
let toLocal = ${r}[ objectIndex ].inverseMatrixWorld;
|
|
628
628
|
hit.normal = normalize( ( transpose( toLocal ) * vec4f( hit.normal, 0.0 ) ).xyz );
|
|
@@ -630,7 +630,7 @@ function rt(e) {
|
|
|
630
630
|
|
|
631
631
|
}
|
|
632
632
|
`,
|
|
633
|
-
resetShapeFn:
|
|
633
|
+
resetShapeFn: H`
|
|
634
634
|
fn resetRayScalar( objectIndex: u32 ) -> void {
|
|
635
635
|
|
|
636
636
|
${i} = 1.0;
|
|
@@ -641,9 +641,9 @@ function rt(e) {
|
|
|
641
641
|
}
|
|
642
642
|
//#endregion
|
|
643
643
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/shapecastFns/getSampleTrianglePointFn.js
|
|
644
|
-
function
|
|
644
|
+
function ot(e) {
|
|
645
645
|
let { storage: t, structs: n } = e, r = n.attributes.membersLayout.map(({ name: e }) => `result.${e} = a0.${e} * barycoord.x + a1.${e} * barycoord.y + a2.${e} * barycoord.z;`).join("\n");
|
|
646
|
-
return
|
|
646
|
+
return H`
|
|
647
647
|
// fn
|
|
648
648
|
fn bvh_sampleTrianglePoint( barycoord: vec3f, indices: vec3u ) -> ${n.attributes} {
|
|
649
649
|
|
|
@@ -659,14 +659,14 @@ function it(e) {
|
|
|
659
659
|
}
|
|
660
660
|
//#endregion
|
|
661
661
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/shapecastFns/getClosestPointToPointFn.js
|
|
662
|
-
function
|
|
663
|
-
let { index: t, attributes: n, transforms: r } = e.storage, i =
|
|
662
|
+
function st(e) {
|
|
663
|
+
let { index: t, attributes: n, transforms: r } = e.storage, i = Oe().toVar("bvh_toWorldMat");
|
|
664
664
|
return e.getShapecastFn({
|
|
665
665
|
name: "bvh_ClosestPointToPoint",
|
|
666
666
|
shapeStruct: "vec3f",
|
|
667
|
-
resultStruct:
|
|
668
|
-
boundsOrderFn:
|
|
669
|
-
fn cppBoundsOrder( shape: vec3f, splitAxis: u32, node: ${
|
|
667
|
+
resultStruct: Pe,
|
|
668
|
+
boundsOrderFn: H`
|
|
669
|
+
fn cppBoundsOrder( shape: vec3f, splitAxis: u32, node: ${Me} ) -> bool {
|
|
670
670
|
|
|
671
671
|
let toWorld = ${i};
|
|
672
672
|
|
|
@@ -682,8 +682,8 @@ function at(e) {
|
|
|
682
682
|
|
|
683
683
|
}
|
|
684
684
|
`,
|
|
685
|
-
intersectsBoundsFn:
|
|
686
|
-
fn cppIntersectsBounds( shape: vec3f, bounds: ${
|
|
685
|
+
intersectsBoundsFn: H`
|
|
686
|
+
fn cppIntersectsBounds( shape: vec3f, bounds: ${je}, result: ptr<function, ${Pe}> ) -> u32 {
|
|
687
687
|
|
|
688
688
|
// return 1u;
|
|
689
689
|
// we need to check this no matter what if the result has not been found yet
|
|
@@ -714,8 +714,8 @@ function at(e) {
|
|
|
714
714
|
|
|
715
715
|
}
|
|
716
716
|
`,
|
|
717
|
-
intersectRangeFn:
|
|
718
|
-
fn cppIntersectsRange( shape: vec3f, offset: u32, count: u32, result: ptr<function, ${
|
|
717
|
+
intersectRangeFn: H`
|
|
718
|
+
fn cppIntersectsRange( shape: vec3f, offset: u32, count: u32, result: ptr<function, ${Pe}> ) -> bool {
|
|
719
719
|
|
|
720
720
|
var didHit = false;
|
|
721
721
|
let toWorld = ${i};
|
|
@@ -730,7 +730,7 @@ function at(e) {
|
|
|
730
730
|
let b = ( toWorld * vec4f( ${n}[ i1 ].position.xyz, 1.0 ) ).xyz;
|
|
731
731
|
let c = ( toWorld * vec4f( ${n}[ i2 ].position.xyz, 1.0 ) ).xyz;
|
|
732
732
|
|
|
733
|
-
let barycoord = ${
|
|
733
|
+
let barycoord = ${nt}( shape, a, b, c );
|
|
734
734
|
let closestPoint = barycoord.x * a + barycoord.y * b + barycoord.z * c;
|
|
735
735
|
let delta = shape - closestPoint;
|
|
736
736
|
let distSq = dot( delta, delta );
|
|
@@ -757,15 +757,15 @@ function at(e) {
|
|
|
757
757
|
|
|
758
758
|
}
|
|
759
759
|
`,
|
|
760
|
-
transformShapeFn:
|
|
760
|
+
transformShapeFn: H`
|
|
761
761
|
fn cppTransformShape( shape: ptr<function, vec3f>, objectIndex: u32 ) -> void {
|
|
762
762
|
|
|
763
763
|
${i} = ${r}[ objectIndex ].matrixWorld;
|
|
764
764
|
|
|
765
765
|
}
|
|
766
766
|
`,
|
|
767
|
-
transformResultFn:
|
|
768
|
-
fn cppTransformResult( result: ptr<function, ${
|
|
767
|
+
transformResultFn: H`
|
|
768
|
+
fn cppTransformResult( result: ptr<function, ${Pe}>, objectIndex: u32 ) -> void {
|
|
769
769
|
|
|
770
770
|
result.objectIndex = objectIndex;
|
|
771
771
|
|
|
@@ -775,8 +775,8 @@ function at(e) {
|
|
|
775
775
|
}
|
|
776
776
|
//#endregion
|
|
777
777
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/lib/three-mesh-bvh/BVHComputeData.js
|
|
778
|
-
var
|
|
779
|
-
function
|
|
778
|
+
var W = /* @__PURE__ */ new y(), ct = /* @__PURE__ */ new y();
|
|
779
|
+
function lt(e) {
|
|
780
780
|
let t = e;
|
|
781
781
|
for (; t;) {
|
|
782
782
|
if (t.visible === !1) return !1;
|
|
@@ -784,25 +784,25 @@ function st(e) {
|
|
|
784
784
|
}
|
|
785
785
|
return !0;
|
|
786
786
|
}
|
|
787
|
-
function
|
|
787
|
+
function ut(e) {
|
|
788
788
|
return e._roots.reduce((e, t) => e + t.byteLength, 0);
|
|
789
789
|
}
|
|
790
|
-
var
|
|
790
|
+
var dt = class {
|
|
791
791
|
constructor(e, t = {}) {
|
|
792
|
-
e =
|
|
792
|
+
e = Re(e);
|
|
793
793
|
let { attributes: n = { position: "vec4f" }, autogenerateBvh: r = !0 } = t;
|
|
794
|
-
this._bvhCache = /* @__PURE__ */ new Map(), this.autogenerateBvh = r, this.attributes = n, this.bvh = e, this.storage = new
|
|
795
|
-
raycastFirstHit:
|
|
796
|
-
closestPointToPoint:
|
|
794
|
+
this._bvhCache = /* @__PURE__ */ new Map(), this.autogenerateBvh = r, this.attributes = n, this.bvh = e, this.storage = new ft(), this.structs = new ft({ transform: Ne }), this.fns = new ft({
|
|
795
|
+
raycastFirstHit: at(this),
|
|
796
|
+
closestPointToPoint: st(this),
|
|
797
797
|
sampleTrianglePoint: null
|
|
798
|
-
},
|
|
798
|
+
}, z);
|
|
799
799
|
}
|
|
800
800
|
getShapecastFn(e) {
|
|
801
|
-
return
|
|
801
|
+
return tt(this, e);
|
|
802
802
|
}
|
|
803
803
|
update() {
|
|
804
804
|
this.dispose();
|
|
805
|
-
let { attributes: e, structs: t, bvh: n } = this, r = [], i = [], a =
|
|
805
|
+
let { attributes: e, structs: t, bvh: n } = this, r = [], i = [], a = ut(n), o = 0, s = 0;
|
|
806
806
|
n.primitiveBuffer.forEach((e) => {
|
|
807
807
|
let t = n.getObjectFromId(e), c = n.getInstanceFromId(e), l = {
|
|
808
808
|
start: 0,
|
|
@@ -819,7 +819,7 @@ var lt = class {
|
|
|
819
819
|
bvhNodeOffsets: null,
|
|
820
820
|
indexBufferOffset: null
|
|
821
821
|
};
|
|
822
|
-
a +=
|
|
822
|
+
a += ut(u), o += e.range.count, s += e.range.vertexCount, r.push(e);
|
|
823
823
|
}
|
|
824
824
|
let d = r.find((e) => u === e.bvh);
|
|
825
825
|
u._roots.forEach((n, r) => {
|
|
@@ -834,21 +834,21 @@ var lt = class {
|
|
|
834
834
|
});
|
|
835
835
|
let c = Math.max(i.length, 2);
|
|
836
836
|
o = Math.max(o, 2), s = Math.max(s, 2);
|
|
837
|
-
let l = new
|
|
838
|
-
|
|
839
|
-
e.bvhNodeOffsets =
|
|
837
|
+
let l = new E(e, "bvh_GeometryStruct"), u = 0, d = 0, f = 0, p = new Uint32Array(o), m = /* @__PURE__ */ new ArrayBuffer(s * l.getLength() * 4), h = new ArrayBuffer(a);
|
|
838
|
+
Be(n, 0, i, 0, h, !0), f += ut(n) / 32, r.forEach((e) => {
|
|
839
|
+
e.bvhNodeOffsets = Be(e.bvh, d / 3, i, f, h, !1), Ve(e.bvh, e.range, u, d, p), He(e.bvh, e.range, u, m, l, this), e.indexBufferOffset = d, d += e.range.count, u += e.range.vertexCount, f += ut(e.bvh) / 32;
|
|
840
840
|
});
|
|
841
841
|
let g = /* @__PURE__ */ new ArrayBuffer(t.transform.getLength() * c * 4);
|
|
842
842
|
i.forEach((e, t) => {
|
|
843
|
-
|
|
843
|
+
ct.copy(n.matrixWorld).invert(), this.writeTransformData(e, ct, t, g);
|
|
844
844
|
});
|
|
845
|
-
let _ =
|
|
846
|
-
this.storage.transforms = v, this.storage.nodes = _, this.storage.index = y, this.storage.attributes = b, this.structs.attributes = l, this.fns.sampleTrianglePoint =
|
|
845
|
+
let _ = N(new fe(new Uint32Array(h), 1), Me).toReadOnly().setName("bvh_nodes"), v = N(new fe(new Uint32Array(g), 1), t.transform).toReadOnly().setName("bvh_transforms"), y = N(new fe(p, 1), "uint").toReadOnly().setName("bvh_index"), b = N(new fe(new Uint32Array(m), l.getLength()), l).toReadOnly().setName("bvh_attributes");
|
|
846
|
+
this.storage.transforms = v, this.storage.nodes = _, this.storage.index = y, this.storage.attributes = b, this.structs.attributes = l, this.fns.sampleTrianglePoint = ot(this), this._bvhCache.clear();
|
|
847
847
|
}
|
|
848
848
|
writeTransformData(e, t, n, r) {
|
|
849
849
|
let { structs: i } = this, a = new Float32Array(r), o = new Uint32Array(r), { object: s, instanceId: c, root: l, data: u } = e, { bvhNodeOffsets: d } = u;
|
|
850
|
-
s.isInstancedMesh || s.isBatchedMesh ? (s.getMatrixAt(c,
|
|
851
|
-
let f =
|
|
850
|
+
s.isInstancedMesh || s.isBatchedMesh ? (s.getMatrixAt(c, W), W.premultiply(s.matrixWorld)) : W.copy(s.matrixWorld), W.premultiply(t), W.toArray(a, n * i.transform.getLength()), W.invert(), W.toArray(a, n * i.transform.getLength() + 16), o[n * i.transform.getLength() + 32] = d[l];
|
|
851
|
+
let f = lt(s);
|
|
852
852
|
s.isBatchedMesh && (f &&= s.getVisibleAt(c)), o[n * i.transform.getLength() + 33] = f ? 1 : 0;
|
|
853
853
|
}
|
|
854
854
|
getBVH(e, t, n) {
|
|
@@ -857,19 +857,19 @@ var lt = class {
|
|
|
857
857
|
let t = e.geometry;
|
|
858
858
|
if (n.count = t.index ? t.index.count : t.attributes.position.count, n.vertexCount = t.attributes.position.count, a = e.boundsTree || null, a === null && r) {
|
|
859
859
|
let t = e.uuid;
|
|
860
|
-
a = i.get(t) || new
|
|
860
|
+
a = i.get(t) || new xe(e), i.set(t, a);
|
|
861
861
|
}
|
|
862
862
|
} else if (e.isBatchedMesh) {
|
|
863
863
|
let o = e.getGeometryIdAt(t), s = e.getGeometryRangeAt(o);
|
|
864
864
|
if (Object.assign(n, s), a = e.boundsTrees[o] || null, a === null && r) {
|
|
865
865
|
let t = `batched_${e.geometry.uuid}_${s.start}_${s.count}`;
|
|
866
|
-
a = i.get(t) || new
|
|
866
|
+
a = i.get(t) || new be(e.geometry, { range: { ...n } }), i.set(t, a);
|
|
867
867
|
}
|
|
868
868
|
} else {
|
|
869
869
|
let t = e.geometry;
|
|
870
870
|
if (n.count = t.index ? t.index.count : t.attributes.position.count, n.vertexCount = t.attributes.position.count, a = e.geometry.boundsTree || null, a === null && r) {
|
|
871
871
|
let e = t.uuid;
|
|
872
|
-
a = i.get(e) || new
|
|
872
|
+
a = i.get(e) || new be(t), i.set(e, a);
|
|
873
873
|
}
|
|
874
874
|
}
|
|
875
875
|
return a;
|
|
@@ -888,8 +888,8 @@ var lt = class {
|
|
|
888
888
|
let { storage: e } = this;
|
|
889
889
|
for (let t in e) e[t].value?.dispose(), delete e[t];
|
|
890
890
|
}
|
|
891
|
-
},
|
|
892
|
-
constructor(e = {}, t =
|
|
891
|
+
}, ft = class {
|
|
892
|
+
constructor(e = {}, t = R) {
|
|
893
893
|
let n = {};
|
|
894
894
|
return new Proxy({ ...e }, {
|
|
895
895
|
get(e, r) {
|
|
@@ -900,7 +900,7 @@ var lt = class {
|
|
|
900
900
|
}
|
|
901
901
|
});
|
|
902
902
|
}
|
|
903
|
-
},
|
|
903
|
+
}, pt = A("\n fn sampleTexel( tex: texture_2d<f32>, coord: vec2f ) -> vec4f {\n\n // Manual bilinear filtering using textureLoad to support filterable float32 textures\n // on all devices\n let size = vec2f( textureDimensions( tex, 0 ) );\n let pxCoord = coord * size - 0.5;\n let px = vec2i( floor( pxCoord ) );\n let fr = fract( pxCoord );\n\n // get the four sibling samples\n let s00 = textureLoad( tex, clamp( px, vec2i( 0 ), vec2i( size ) - 1 ), 0 );\n let s10 = textureLoad( tex, clamp( px + vec2i( 1, 0 ), vec2i( 0 ), vec2i( size ) - 1 ), 0 );\n let s01 = textureLoad( tex, clamp( px + vec2i( 0, 1 ), vec2i( 0 ), vec2i( size ) - 1 ), 0 );\n let s11 = textureLoad( tex, clamp( px + vec2i( 1, 1 ), vec2i( 0 ), vec2i( size ) - 1 ), 0 );\n\n // interpolate on the x axis\n let y0 = mix( s00, s10, fr.x );\n let y1 = mix( s01, s11, fr.x );\n\n // then y\n return mix( y0, y1, fr.y );\n\n }\n"), mt = class extends ge {
|
|
904
904
|
get texture() {
|
|
905
905
|
return this._texNode.value;
|
|
906
906
|
}
|
|
@@ -933,36 +933,36 @@ var lt = class {
|
|
|
933
933
|
}
|
|
934
934
|
constructor(e) {
|
|
935
935
|
super();
|
|
936
|
-
let t =
|
|
936
|
+
let t = M(new T());
|
|
937
937
|
this._texNode = t;
|
|
938
|
-
let n =
|
|
938
|
+
let n = M(new T());
|
|
939
939
|
this._fromTexNode = n;
|
|
940
|
-
let r =
|
|
940
|
+
let r = De(we()), i = j(1);
|
|
941
941
|
this._transitionUniform = i;
|
|
942
|
-
let a =
|
|
942
|
+
let a = Ae(0, 1, H`
|
|
943
943
|
fn fade( uv: vec2f ) -> vec4f {
|
|
944
944
|
|
|
945
945
|
if ( ${i} <= 0.0 ) {
|
|
946
946
|
|
|
947
|
-
return ${
|
|
947
|
+
return ${pt}( ${n}, uv );
|
|
948
948
|
|
|
949
949
|
} else if ( ${i} >= 1.0 ) {
|
|
950
950
|
|
|
951
|
-
return ${
|
|
951
|
+
return ${pt}( ${t}, uv );
|
|
952
952
|
|
|
953
953
|
} else {
|
|
954
954
|
|
|
955
|
-
let col0 = ${
|
|
956
|
-
let col1 = ${
|
|
955
|
+
let col0 = ${pt}( ${n}, uv );
|
|
956
|
+
let col1 = ${pt}( ${t}, uv );
|
|
957
957
|
return mix( col0, col1, ${i} );
|
|
958
958
|
|
|
959
959
|
}
|
|
960
960
|
|
|
961
961
|
}
|
|
962
962
|
`(r));
|
|
963
|
-
this._toneMapping = a, this.transparent = !0, this.colorNode =
|
|
963
|
+
this._toneMapping = a, this.transparent = !0, this.colorNode = ke(a.rgb, a.a), this.setValues(e);
|
|
964
964
|
}
|
|
965
|
-
},
|
|
965
|
+
}, G = class {
|
|
966
966
|
get computeNode() {
|
|
967
967
|
return this.kernel.computeNode;
|
|
968
968
|
}
|
|
@@ -1000,13 +1000,13 @@ var lt = class {
|
|
|
1000
1000
|
let [i, a, o] = this.workgroupSize;
|
|
1001
1001
|
return r.length = 3, r[0] = Math.ceil(e / i), r[1] = Math.ceil(t / a), r[2] = Math.ceil(n / o), r;
|
|
1002
1002
|
}
|
|
1003
|
-
},
|
|
1004
|
-
|
|
1005
|
-
var
|
|
1006
|
-
|
|
1007
|
-
var
|
|
1003
|
+
}, ht = Se("\n\n struct PcgState {\n s0: vec4u,\n s1: vec4u,\n };\n\n var<private> g_state: PcgState;\n");
|
|
1004
|
+
A("\n fn pcgInitialize( pixelIndex: u32, pathIndex: u32, bounceIndex: u32 ) -> void {\n let pixel = vec2( ( pixelIndex >> 16 ) & 0xFF, pixelIndex & 0xFF );\n\n //white noise seed\n g_state.s0 = vec4u( pixel | vec2( bounceIndex << 16 ), pathIndex, pixel.x + pixel.y);\n\n //blue noise seed\n g_state.s1 = vec4u(pathIndex, pathIndex*15843, pathIndex*31 + 4566, pathIndex*2345 + 58585);\n\n }\n", [ht]);
|
|
1005
|
+
var gt = A("\n fn pcg4d(v: ptr<private, vec4u>) -> void {\n *v = *v * 1664525u + 1013904223u;\n *v = *v + v.yzxy * v.wxyz;\n *v = *v ^ (*v >> vec4u(16u));\n *v = *v + v.yzxy * v.wxyz;\n }\n");
|
|
1006
|
+
A("\n fn pcgRand( _id: u32 ) -> f32 {\n pcg4d(&g_state.s0);\n return abs( f32( g_state.s0.x ) / f32(0xffffffffu) );\n }\n", [gt, ht]), A("\n fn pcgRand2( _id: u32 ) -> vec2f {\n pcg4d(&g_state.s0);\n return abs( vec2f( g_state.s0.xy ) / f32(0xffffffffu) );\n }\n", [gt, ht]), A("\n fn pcgRand3( _id: u32 ) -> vec3f {\n pcg4d(&g_state.s0);\n return abs( vec3f( g_state.s0.xyz ) / f32(0xffffffffu) );\n }\n", [gt, ht]), A("\n fn pcgRand4( _id: u32 ) -> vec4f {\n pcg4d(&g_state.s0);\n return abs( vec4f( g_state.s0 ) / f32(0xffffffffu) );\n }\n", [gt, ht]), A("fn noop() -> void {}");
|
|
1007
|
+
var _t = Te(256 * 256), vt = F(1 / 16777216), yt = Se("\n\n const SOBOL_DIRECTIONS_1 = array<u32, 32>(\n 0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,\n 0x88000000u, 0xcc000000u, 0xaa000000u, 0xff000000u,\n 0x80800000u, 0xc0c00000u, 0xa0a00000u, 0xf0f00000u,\n 0x88880000u, 0xcccc0000u, 0xaaaa0000u, 0xffff0000u,\n 0x80008000u, 0xc000c000u, 0xa000a000u, 0xf000f000u,\n 0x88008800u, 0xcc00cc00u, 0xaa00aa00u, 0xff00ff00u,\n 0x80808080u, 0xc0c0c0c0u, 0xa0a0a0a0u, 0xf0f0f0f0u,\n 0x88888888u, 0xccccccccu, 0xaaaaaaaau, 0xffffffffu\n );\n\n const SOBOL_DIRECTIONS_2 = array<u32, 32>(\n 0x80000000u, 0xc0000000u, 0x60000000u, 0x90000000u,\n 0xe8000000u, 0x5c000000u, 0x8e000000u, 0xc5000000u,\n 0x68800000u, 0x9cc00000u, 0xee600000u, 0x55900000u,\n 0x80680000u, 0xc09c0000u, 0x60ee0000u, 0x90550000u,\n 0xe8808000u, 0x5cc0c000u, 0x8e606000u, 0xc5909000u,\n 0x6868e800u, 0x9c9c5c00u, 0xeeee8e00u, 0x5555c500u,\n 0x8000e880u, 0xc0005cc0u, 0x60008e60u, 0x9000c590u,\n 0xe8006868u, 0x5c009c9cu, 0x8e00eeeeu, 0xc5005555u\n );\n\n const SOBOL_DIRECTIONS_3 = array<u32, 32>(\n 0x80000000u, 0xc0000000u, 0x20000000u, 0x50000000u,\n 0xf8000000u, 0x74000000u, 0xa2000000u, 0x93000000u,\n 0xd8800000u, 0x25400000u, 0x59e00000u, 0xe6d00000u,\n 0x78080000u, 0xb40c0000u, 0x82020000u, 0xc3050000u,\n 0x208f8000u, 0x51474000u, 0xfbea2000u, 0x75d93000u,\n 0xa0858800u, 0x914e5400u, 0xdbe79e00u, 0x25db6d00u,\n 0x58800080u, 0xe54000c0u, 0x79e00020u, 0xb6d00050u,\n 0x800800f8u, 0xc00c0074u, 0x200200a2u, 0x50050093u\n );\n\n const SOBOL_DIRECTIONS_4 = array<u32, 32>(\n 0x80000000u, 0x40000000u, 0x20000000u, 0xb0000000u,\n 0xf8000000u, 0xdc000000u, 0x7a000000u, 0x9d000000u,\n 0x5a800000u, 0x2fc00000u, 0xa1600000u, 0xf0b00000u,\n 0xda880000u, 0x6fc40000u, 0x81620000u, 0x40bb0000u,\n 0x22878000u, 0xb3c9c000u, 0xfb65a000u, 0xddb2d000u,\n 0x78022800u, 0x9c0b3c00u, 0x5a0fb600u, 0x2d0ddb00u,\n 0xa2878080u, 0xf3c9c040u, 0xdb65a020u, 0x6db2d0b0u,\n 0x800228f8u, 0x400b3cdcu, 0x200fb67au, 0xb00ddb9du\n );\n\n"), bt = Te(0).toVar("sobolPixelIndex"), xt = Te(0).toVar("sobolPathIndex"), St = Te(0).toVar("sobolBounceIndex"), Ct = A("\n\n fn getMaskedSobol( index: u32, directions: array<u32, 32> ) -> u32 {\n\n var X = 0u;\n for ( var bit = 0u; bit < 32u; bit ++ ) {\n\n let mask = ( index >> bit ) & 1u;\n X ^= mask * directions[ bit ];\n\n }\n return X;\n\n }\n\n"), wt = (e = 1) => {
|
|
1008
1008
|
if (e <= 0) return;
|
|
1009
|
-
let t = e > 1 ? `vec${e}u` : "u32", n =
|
|
1009
|
+
let t = e > 1 ? `vec${e}u` : "u32", n = A(`
|
|
1010
1010
|
|
|
1011
1011
|
fn sobolReverseBits_${t}( in: ${t} ) -> ${t} {
|
|
1012
1012
|
|
|
@@ -1019,7 +1019,7 @@ var ht = De(256 * 256), gt = M(1 / 16777216), _t = Se("\n\n const SOBOL_DIRECTIO
|
|
|
1019
1019
|
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
1022
|
-
`), r =
|
|
1022
|
+
`), r = A(`
|
|
1023
1023
|
|
|
1024
1024
|
fn sobolHashCombine_${t}( seed: u32, v: ${t} ) -> ${t} {
|
|
1025
1025
|
|
|
@@ -1027,7 +1027,7 @@ var ht = De(256 * 256), gt = M(1 / 16777216), _t = Se("\n\n const SOBOL_DIRECTIO
|
|
|
1027
1027
|
|
|
1028
1028
|
}
|
|
1029
1029
|
|
|
1030
|
-
`), i =
|
|
1030
|
+
`), i = A(`
|
|
1031
1031
|
|
|
1032
1032
|
fn sobolLaineKarrasPermutation_${t}( in: ${t}, seed: ${t} ) -> ${t} {
|
|
1033
1033
|
|
|
@@ -1046,7 +1046,7 @@ var ht = De(256 * 256), gt = M(1 / 16777216), _t = Se("\n\n const SOBOL_DIRECTIO
|
|
|
1046
1046
|
reverseBits: n,
|
|
1047
1047
|
hashCombine: r,
|
|
1048
1048
|
lkPermutation: i,
|
|
1049
|
-
scramble:
|
|
1049
|
+
scramble: H`
|
|
1050
1050
|
|
|
1051
1051
|
fn nestedUniformScrambleBase2_${t}( x: ${t}, seed: ${t} ) -> ${t} {
|
|
1052
1052
|
|
|
@@ -1058,39 +1058,39 @@ var ht = De(256 * 256), gt = M(1 / 16777216), _t = Se("\n\n const SOBOL_DIRECTIO
|
|
|
1058
1058
|
|
|
1059
1059
|
`
|
|
1060
1060
|
};
|
|
1061
|
-
},
|
|
1062
|
-
${[
|
|
1061
|
+
}, K = Array.from({ length: 5 }, (e, t) => wt(t)), Tt = H`
|
|
1062
|
+
${[yt]}
|
|
1063
1063
|
|
|
1064
1064
|
fn generateSobolPoint( id: u32 ) -> vec4f {
|
|
1065
1065
|
|
|
1066
1066
|
var index = id;
|
|
1067
|
-
if ( index >= ${
|
|
1067
|
+
if ( index >= ${_t} ) {
|
|
1068
1068
|
|
|
1069
|
-
index = index % ${
|
|
1069
|
+
index = index % ${_t};
|
|
1070
1070
|
// return vec4( 0.0 );
|
|
1071
1071
|
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
1074
|
// NOTE: this sobol "direction" is also available but we can't write out 5 components
|
|
1075
1075
|
// uint x = index & 0x00ffffffu;
|
|
1076
|
-
let x = ${
|
|
1077
|
-
let y = ${
|
|
1078
|
-
let z = ${
|
|
1079
|
-
let w = ${
|
|
1076
|
+
let x = ${K[1].reverseBits}( ${Ct}( index, SOBOL_DIRECTIONS_1 ) ) & 0x00ffffffu;
|
|
1077
|
+
let y = ${K[1].reverseBits}( ${Ct}( index, SOBOL_DIRECTIONS_2 ) ) & 0x00ffffffu;
|
|
1078
|
+
let z = ${K[1].reverseBits}( ${Ct}( index, SOBOL_DIRECTIONS_3 ) ) & 0x00ffffffu;
|
|
1079
|
+
let w = ${K[1].reverseBits}( ${Ct}( index, SOBOL_DIRECTIONS_4 ) ) & 0x00ffffffu;
|
|
1080
1080
|
|
|
1081
|
-
return vec4( f32( x ), f32( y ), f32( z ), f32( w ) ) * ${
|
|
1081
|
+
return vec4( f32( x ), f32( y ), f32( z ), f32( w ) ) * ${vt};
|
|
1082
1082
|
|
|
1083
1083
|
}
|
|
1084
1084
|
|
|
1085
|
-
`,
|
|
1085
|
+
`, Et = A("\n\n fn sobolHash( in: u32 ) -> u32 {\n\n var x = in;\n // finalizer from murmurhash3\n x ^= x >> 16;\n x *= 0x85ebca6bu;\n x ^= x >> 13;\n x *= 0xc2b2ae35u;\n x ^= x >> 16;\n return x;\n\n }\n\n"), Dt = H`
|
|
1086
1086
|
|
|
1087
1087
|
fn sobolGetSeed( effect: u32 ) -> u32 {
|
|
1088
1088
|
|
|
1089
|
-
return ${
|
|
1090
|
-
${
|
|
1091
|
-
${
|
|
1092
|
-
${
|
|
1093
|
-
${
|
|
1089
|
+
return ${Et}(
|
|
1090
|
+
${K[1].hashCombine}(
|
|
1091
|
+
${K[1].hashCombine}(
|
|
1092
|
+
${Et}( ${St} ),
|
|
1093
|
+
${bt}
|
|
1094
1094
|
),
|
|
1095
1095
|
effect
|
|
1096
1096
|
)
|
|
@@ -1098,55 +1098,55 @@ var ht = De(256 * 256), gt = M(1 / 16777216), _t = Se("\n\n const SOBOL_DIRECTIO
|
|
|
1098
1098
|
|
|
1099
1099
|
}
|
|
1100
1100
|
|
|
1101
|
-
`,
|
|
1101
|
+
`, Ot = (e = 1, t = Tt) => {
|
|
1102
1102
|
if (e <= 0) return;
|
|
1103
1103
|
let n = e > 1 ? `vec${e}u` : "u32", r = e > 1 ? `vec${e}f` : "f32", i = ".r", a = "1u";
|
|
1104
|
-
return e === 2 ? (i = ".rg", a = "vec2( 1u, 2u )") : e === 3 ? (i = ".rgb", a = "vec3( 1u, 2u, 3u )") : e === 4 && (i = "", a = "vec4( 1u, 2u, 3u, 4u )"),
|
|
1104
|
+
return e === 2 ? (i = ".rg", a = "vec2( 1u, 2u )") : e === 3 ? (i = ".rgb", a = "vec3( 1u, 2u, 3u )") : e === 4 && (i = "", a = "vec4( 1u, 2u, 3u, 4u )"), H`
|
|
1105
1105
|
|
|
1106
1106
|
fn sobol${e}( effect: u32 ) -> ${r} {
|
|
1107
1107
|
|
|
1108
|
-
let seed = ${
|
|
1109
|
-
let index = ${
|
|
1108
|
+
let seed = ${Dt}( effect );
|
|
1109
|
+
let index = ${xt};
|
|
1110
1110
|
|
|
1111
|
-
let shuffle_seed = ${
|
|
1112
|
-
let shuffled_index = ${
|
|
1111
|
+
let shuffle_seed = ${K[1].hashCombine}( seed, 0u );
|
|
1112
|
+
let shuffled_index = ${K[1].scramble}( ${K[1].reverseBits}( index ), shuffle_seed );
|
|
1113
1113
|
let sobol_pt = ${t}( shuffled_index )${i};
|
|
1114
1114
|
var result = ${n}( sobol_pt * 16777216.0 );
|
|
1115
1115
|
|
|
1116
|
-
let seed2 = ${
|
|
1117
|
-
result = ${
|
|
1116
|
+
let seed2 = ${K[e].hashCombine}( seed, ${a} );
|
|
1117
|
+
result = ${K[e].scramble}( result, seed2 );
|
|
1118
1118
|
|
|
1119
|
-
return ${
|
|
1119
|
+
return ${vt} * ${r}( result >> ${n}( 8 ) );
|
|
1120
1120
|
|
|
1121
1121
|
}
|
|
1122
1122
|
|
|
1123
1123
|
`;
|
|
1124
|
-
},
|
|
1125
|
-
|
|
1126
|
-
var
|
|
1124
|
+
}, kt = Ot(1), q = Ot(2);
|
|
1125
|
+
Ot(3), Ot(4);
|
|
1126
|
+
var At = H`
|
|
1127
1127
|
|
|
1128
1128
|
fn sobolInit( pixelIndex: u32, pathIndex: u32, bounceIndex: u32 ) -> void {
|
|
1129
1129
|
|
|
1130
|
-
${
|
|
1131
|
-
${
|
|
1132
|
-
${
|
|
1130
|
+
${bt} = pixelIndex;
|
|
1131
|
+
${xt} = pathIndex;
|
|
1132
|
+
${St} = bounceIndex;
|
|
1133
1133
|
|
|
1134
1134
|
}
|
|
1135
1135
|
|
|
1136
|
-
`,
|
|
1136
|
+
`, jt = H`
|
|
1137
1137
|
|
|
1138
1138
|
fn sobolNextBounce() -> void {
|
|
1139
1139
|
|
|
1140
|
-
${
|
|
1140
|
+
${St}++;
|
|
1141
1141
|
|
|
1142
1142
|
}
|
|
1143
1143
|
|
|
1144
|
-
`,
|
|
1144
|
+
`, J = Se("\n\n const PI: f32 = 3.141592653589793;\n const EPSILON: f32 = 1e-5;\n const MIN_ROUGHNESS: f32 = 1e-3;\n\n"), Mt = new E({
|
|
1145
1145
|
color: "vec3f",
|
|
1146
1146
|
specularPdf: "float",
|
|
1147
1147
|
direction: "vec3f",
|
|
1148
1148
|
pdf: "float"
|
|
1149
|
-
}, "ScatterRecord"),
|
|
1149
|
+
}, "ScatterRecord"), Nt = new E({
|
|
1150
1150
|
color: "vec3",
|
|
1151
1151
|
map: "int",
|
|
1152
1152
|
metalness: "float",
|
|
@@ -1211,7 +1211,7 @@ var Ot = W`
|
|
|
1211
1211
|
specularColorMapTransform: "mat3",
|
|
1212
1212
|
specularIntensityMapTransform: "mat3",
|
|
1213
1213
|
alphaMapTransform: "mat3"
|
|
1214
|
-
}, "Material"),
|
|
1214
|
+
}, "Material"), Pt = new E({
|
|
1215
1215
|
volumeParticle: "bool",
|
|
1216
1216
|
faceNormal: "vec3f",
|
|
1217
1217
|
frontFace: "bool",
|
|
@@ -1242,16 +1242,16 @@ var Ot = W`
|
|
|
1242
1242
|
iridescenceThickness: "f32",
|
|
1243
1243
|
specularColor: "vec3f",
|
|
1244
1244
|
specularIntensity: "f32"
|
|
1245
|
-
}, "SurfaceRecord"),
|
|
1245
|
+
}, "SurfaceRecord"), Ft = new E({
|
|
1246
1246
|
rotation: "mat3x3f",
|
|
1247
1247
|
intensity: "float",
|
|
1248
1248
|
blur: "float"
|
|
1249
|
-
}, "EnvironmentInfo"),
|
|
1249
|
+
}, "EnvironmentInfo"), It = new E({
|
|
1250
1250
|
diffuse: "float",
|
|
1251
1251
|
specular: "float",
|
|
1252
1252
|
transmission: "float",
|
|
1253
1253
|
clearcoat: "float"
|
|
1254
|
-
}, "LobeWeights"),
|
|
1254
|
+
}, "LobeWeights"), Lt = new E({
|
|
1255
1255
|
NdotV: "float",
|
|
1256
1256
|
NdotL: "float",
|
|
1257
1257
|
NdotH: "float",
|
|
@@ -1259,7 +1259,7 @@ var Ot = W`
|
|
|
1259
1259
|
VdotNc: "float",
|
|
1260
1260
|
LdotNc: "float",
|
|
1261
1261
|
HdotNc: "float"
|
|
1262
|
-
}, "BxDFContext"),
|
|
1262
|
+
}, "BxDFContext"), Rt = A("\n\n fn inverse(m: mat3x3f) -> mat3x3f {\n var adj: mat3x3f;\n adj[0][0] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]);\n adj[1][0] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]);\n adj[2][0] = (m[1][0] * m[2][1] - m[2][0] * m[1][1]);\n adj[0][1] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]);\n adj[1][1] = (m[0][0] * m[2][2] - m[2][0] * m[0][2]);\n adj[2][1] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]);\n adj[0][2] = (m[0][1] * m[1][2] - m[1][1] * m[0][2]);\n adj[1][2] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]);\n adj[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]);\n\n let det = ( m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])\n - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])\n + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]));\n\n return adj * ( 1.0 / det );\n }\n\n"), zt = A("\n\n fn getBasisFromNormal( normal: vec3f ) -> mat3x3f {\n\n var other: vec3f;\n if ( abs( normal.x ) > 0.5 ) {\n\n other = vec3f( 0.0, 1.0, 0.0 );\n\n } else {\n\n other = vec3f( 1.0, 0.0, 0.0 );\n\n }\n\n let ortho = normalize( cross( normal, other ) );\n let ortho2 = normalize( cross( normal, ortho ) );\n return mat3x3f( ortho2, ortho, normal );\n\n }\n\n"), Bt = A("\n\n fn iorToF0( ior: f32 ) -> f32 {\n return pow( ( 1 - ior ) / ( 1 + ior ), 2 );\n }\n\n"), Vt = A("\n\n fn iorToF0General( transmittedIor: f32, incidentIor: f32 ) -> f32 {\n\n return pow( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ), 2 );\n\n }\n\n"), Ht = A("\n\n fn iorToF0GeneralVec( transmittedIor: vec3f, incidentIor: vec3f ) -> vec3f {\n\n let v = ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor );\n return v * v;\n\n }\n\n"), Ut = A("\n\n fn fresnel0ToIor( f0: vec3f ) -> vec3f {\n\n let sqrtF0 = sqrt( f0 );\n return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\n }\n\n"), Y = A("\n\n fn schlickFresnel( cosine: f32, f0: f32 ) -> f32 {\n\n return f0 + ( 1.0 - f0 ) * pow( 1.0 - cosine, 5.0 );\n\n }\n\n"), Wt = A("\n\n fn schlickFresnelVec( cosine: f32, f0: vec3f, f90: vec3f ) -> vec3f {\n\n return f0 + ( f90 - f0 ) * pow( 1.0 - cosine, 5.0 );\n\n }\n\n"), Gt = A("\n\n fn evaluateFresnel( cosine: f32, eta: f32, f0: vec3f, f90: vec3f ) -> vec3f {\n\n if ( totalInternalReflection( cosine, eta ) ) {\n\n return f90;\n\n }\n\n return f0 + ( f90 - f0 ) * pow( 1.0 - cosine, 5.0 );\n }\n\n", [A("\n\n fn totalInternalReflection( cosTheta: f32, eta: f32 ) -> bool {\n\n let sinTheta = sqrt( 1.0 - cosTheta * cosTheta );\n return eta * sinTheta > 1.0;\n\n }\n\n")]), Kt = A("\n\n fn isTerminatingScatter( scatterRec: ScatterRecord ) -> bool {\n return scatterRec.pdf <= 0;\n }\n\n", [Mt]), qt = A("\n\n fn applyWrap( v: f32, wrapMode: i32 ) -> f32 {\n\n var res = v;\n if ( wrapMode == 1 ) {\n\n // ClampToEdge\n res = clamp( res, 0.0, 1.0 );\n\n } else if ( wrapMode == 2 ) {\n\n // MirroredRepeat\n res = 1.0 - abs( 2.0 * fract( res * 0.5 ) - 1.0 );\n\n } else {\n\n // Repeat\n res = fract( res );\n\n }\n\n return res;\n\n }\n\n"), Jt = (e, t, n) => H`
|
|
1263
1263
|
|
|
1264
1264
|
fn sampleTexel( uv: vec2f, packed: i32, lod: f32 ) -> vec4f {
|
|
1265
1265
|
|
|
@@ -1277,8 +1277,8 @@ var Ot = W`
|
|
|
1277
1277
|
|
|
1278
1278
|
// wrap is applied on the logical uv first, then remapped into the tile
|
|
1279
1279
|
let wrappedUv = vec2f(
|
|
1280
|
-
${
|
|
1281
|
-
${
|
|
1280
|
+
${qt}( uv.x, wrapS ),
|
|
1281
|
+
${qt}( uv.y, wrapT ),
|
|
1282
1282
|
);
|
|
1283
1283
|
|
|
1284
1284
|
let pageDim = vec2f( textureDimensions( ${t}, 0 ).xy );
|
|
@@ -1303,43 +1303,43 @@ var Ot = W`
|
|
|
1303
1303
|
}
|
|
1304
1304
|
|
|
1305
1305
|
}
|
|
1306
|
-
`,
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
]),
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
]),
|
|
1306
|
+
`, Yt = A("\n\n fn diffuseDirection( wo: vec3f, uv: vec2f ) -> vec3f {\n\n var lightDirection = sampleSphere( uv );\n lightDirection.z += 1.0;\n lightDirection = normalize( lightDirection );\n\n return lightDirection;\n\n }\n\n", [A("\n\n fn sampleSphere( uv: vec2f ) -> vec3f {\n\n let u = ( uv.x - 0.5 ) * 2.0;\n let t = uv.y * PI * 2.0;\n let f = sqrt( 1.0 - u * u );\n\n return vec3f( f * cos( t ), f * sin( t ), u );\n\n }\n\n", [J])]), Xt = A("\n\n fn getLobeWeights(wo: vec3f, woClearcoat: vec3f, wh: vec3f, clearcoatIor: f32, surf: SurfaceRecord) -> LobeWeights {\n\n // TODO: experiment with this; I don't see any usage of normal?\n let metalness = surf.metalness;\n let transmission = surf.transmission;\n let HdotL = dot( wh, wo );\n let fEstimate = evaluateFresnel( HdotL, surf.eta, vec3f( surf.f0 ), vec3f( 1.0 ) ).x;\n\n let transSpecularProb = mix( max( 0.25, fEstimate ), 1.0, metalness );\n let diffSpecularProb = 0.5 + 0.5 * metalness;\n\n var weights: LobeWeights;\n weights.diffuse = ( 1.0 - transmission ) * ( 1.0 - diffSpecularProb );\n weights.specular = transmission * transSpecularProb + ( 1.0 - transmission ) * diffSpecularProb;\n\n let clearcoatF0 = iorToF0( clearcoatIor );\n let clearcoatFresnel = schlickFresnel( saturate( woClearcoat.z ), clearcoatF0 );\n weights.clearcoat = surf.clearcoat * clearcoatFresnel;\n\n weights.transmission = transmission * ( 1.0 - transSpecularProb );\n\n let totalWeight = weights.diffuse + weights.specular;\n if ( totalWeight > 0 ) {\n weights.diffuse = ( weights.diffuse / totalWeight ) * ( 1 - weights.clearcoat );\n weights.specular = ( weights.specular / totalWeight ) * ( 1 - weights.clearcoat );\n }\n // weights.transmission /= totalWeight;\n\n return weights;\n\n }\n\n", [
|
|
1307
|
+
Y,
|
|
1308
|
+
Bt,
|
|
1309
|
+
Gt,
|
|
1310
|
+
It,
|
|
1311
|
+
J
|
|
1312
|
+
]), Zt = A("\n\n fn sampleEnvironment(\n envMap: texture_2d<f32>,\n envMapSampler: sampler,\n env: EnvironmentInfo,\n direction: vec3f,\n uv: vec2f,\n ) -> vec4f {\n\n let offsetDir = sampleHemisphere( direction, uv ) * 0.5 * env.blur;\n let sampleDir = normalize( env.rotation * direction + offsetDir );\n let col = sampleEquirectColor( envMap, envMapSampler, sampleDir );\n\n return vec4f( env.intensity * col.rgb, col.a );\n\n }\n\n", [
|
|
1313
|
+
A("\n\n fn sampleEquirectColor( envMap: texture_2d<f32>, envMapSampler: sampler, direction: vec3f ) -> vec4f {\n\n return textureSampleLevel( envMap, envMapSampler, equirectDirectionToUv( direction ), 0 );\n\n }\n\n", [A("\n\n fn equirectDirectionToUv(direction: vec3f) -> vec2f {\n\n // from Spherical.setFromCartesianCoords\n var uv = vec2f( atan2( direction.z, direction.x ), acos( direction.y ) );\n uv /= vec2f( 2.0 * PI, PI );\n\n // apply adjustments to get values in range [0, 1] and y right side up\n uv.x += 0.5;\n uv.y = 1.0 - uv.y;\n return uv;\n\n }\n\n")]),
|
|
1314
|
+
A("\n\n fn sampleHemisphere( n: vec3f, uv: vec2f ) -> vec3f {\n\n // https://www.rorydriscoll.com/2009/01/07/better-sampling/\n // https://graphics.pixar.com/library/OrthonormalB/paper.pdf\n let sign = select( sign( n.z ), 1.0, n.z == 0.0 );\n let a = - 1.0 / ( sign + n.z );\n let b = n.x * n.y * a;\n let b1 = vec3( 1.0 + sign * n.x * n.x * a, sign * b, - sign * n.x );\n let b2 = vec3( b, sign + n.y * n.y * a, - n.y );\n\n let r = sqrt( uv.x );\n let theta = 2.0 * PI * uv.y;\n let x = r * cos( theta );\n let y = r * sin( theta );\n return x * b1 + y * b2 + sqrt( 1.0 - uv.x ) * n;\n\n }\n\n", [J]),
|
|
1315
|
+
Ft
|
|
1316
|
+
]), Qt = A("\n\n fn weightedAlphaBlend( prevColor: vec4f, newColor: vec4f, weight: f32 ) -> vec4f {\n\n let invWeight = 1.0 - weight;\n let totalAlpha = prevColor.a * invWeight + newColor.a * weight;\n var blendedColor = vec4f( 0 );\n if ( totalAlpha != 0.0 ) {\n\n let prevContrib = prevColor.rgb * invWeight * prevColor.a / totalAlpha;\n let resContrib = newColor.rgb * weight * newColor.a / totalAlpha;\n blendedColor = vec4f( prevContrib + resContrib, totalAlpha );\n\n }\n\n return blendedColor;\n\n }\n\n"), $t = class extends G {
|
|
1317
1317
|
constructor() {
|
|
1318
1318
|
let e = {
|
|
1319
1319
|
bvhData: { value: null },
|
|
1320
1320
|
material: { value: null },
|
|
1321
|
-
prevOutputTarget:
|
|
1322
|
-
outputTarget:
|
|
1323
|
-
sampleCountTarget:
|
|
1324
|
-
offset:
|
|
1325
|
-
tileSize:
|
|
1326
|
-
seed:
|
|
1327
|
-
bounces:
|
|
1328
|
-
inverseProjectionMatrix:
|
|
1329
|
-
cameraToModelMatrix:
|
|
1330
|
-
envMap:
|
|
1331
|
-
envMapSampler:
|
|
1332
|
-
envMapRotation:
|
|
1333
|
-
envMapIntensity:
|
|
1334
|
-
background:
|
|
1335
|
-
backgroundSampler:
|
|
1336
|
-
backgroundRotation:
|
|
1337
|
-
backgroundIntensity:
|
|
1338
|
-
backgroundBlurriness:
|
|
1339
|
-
textures:
|
|
1340
|
-
textureSampler:
|
|
1341
|
-
globalId:
|
|
1342
|
-
}, t =
|
|
1321
|
+
prevOutputTarget: O(new T(1, 1)).toReadOnly(),
|
|
1322
|
+
outputTarget: O(new T(1, 1)).toWriteOnly(),
|
|
1323
|
+
sampleCountTarget: O(new T(1, 1)).toReadWrite(),
|
|
1324
|
+
offset: j(new p()),
|
|
1325
|
+
tileSize: j(new p()),
|
|
1326
|
+
seed: j(0),
|
|
1327
|
+
bounces: j(5),
|
|
1328
|
+
inverseProjectionMatrix: j(new y()),
|
|
1329
|
+
cameraToModelMatrix: j(new y()),
|
|
1330
|
+
envMap: M(new h()),
|
|
1331
|
+
envMapSampler: P(new h()),
|
|
1332
|
+
envMapRotation: j(new ie()),
|
|
1333
|
+
envMapIntensity: j(1),
|
|
1334
|
+
background: M(new h()),
|
|
1335
|
+
backgroundSampler: P(new h()),
|
|
1336
|
+
backgroundRotation: j(new ie()),
|
|
1337
|
+
backgroundIntensity: j(1),
|
|
1338
|
+
backgroundBlurriness: j(0),
|
|
1339
|
+
textures: M(new h()),
|
|
1340
|
+
textureSampler: P(new h()),
|
|
1341
|
+
globalId: k
|
|
1342
|
+
}, t = R("bvhData.value.fns.raycastFirstHit.outputType", e), n = z("bvhData.value.fns.raycastFirstHit", e), r = z("bvhData.value.fns.sampleTrianglePoint", e), i = z("bvhData.value.fns.getSurfaceRecord", e), a = z("material.value.bsdfSample", e), o = H`
|
|
1343
1343
|
|
|
1344
1344
|
fn compute(
|
|
1345
1345
|
|
|
@@ -1370,8 +1370,8 @@ var Ot = W`
|
|
|
1370
1370
|
|
|
1371
1371
|
) -> void {
|
|
1372
1372
|
|
|
1373
|
-
let transforms = &${
|
|
1374
|
-
let materials = &${
|
|
1373
|
+
let transforms = &${R("bvhData.value.storage.transforms", e)};
|
|
1374
|
+
let materials = &${R("bvhData.value.storage.materials", e)};
|
|
1375
1375
|
|
|
1376
1376
|
let envInfo = EnvironmentInfo(
|
|
1377
1377
|
envMapRotation,
|
|
@@ -1405,11 +1405,11 @@ var Ot = W`
|
|
|
1405
1405
|
let ndc = uv * 2.0 - vec2f( 1.0 );
|
|
1406
1406
|
|
|
1407
1407
|
let pixelIndex = ( indexUV.x << 16 ) | indexUV.y;
|
|
1408
|
-
${
|
|
1408
|
+
${At}( pixelIndex, seed, 0 );
|
|
1409
1409
|
|
|
1410
1410
|
// scene ray
|
|
1411
|
-
var jitter = 2.0 * ${
|
|
1412
|
-
var ray = ${
|
|
1411
|
+
var jitter = 2.0 * ${q}( ${0} ) / vec2f( targetDimensions.xy );
|
|
1412
|
+
var ray = ${it}( ndc + jitter, cameraToModelMatrix * inverseProjectionMatrix );
|
|
1413
1413
|
ray.direction = normalize( ray.direction );
|
|
1414
1414
|
|
|
1415
1415
|
var resultColor = vec4f( 0, 0, 0, 1 );
|
|
@@ -1437,7 +1437,7 @@ var Ot = W`
|
|
|
1437
1437
|
|
|
1438
1438
|
let scatterRec = ${a}( - ray.direction, surface );
|
|
1439
1439
|
|
|
1440
|
-
if ( ${
|
|
1440
|
+
if ( ${Kt}( scatterRec ) ) {
|
|
1441
1441
|
|
|
1442
1442
|
break;
|
|
1443
1443
|
|
|
@@ -1454,14 +1454,14 @@ var Ot = W`
|
|
|
1454
1454
|
|
|
1455
1455
|
} else {
|
|
1456
1456
|
|
|
1457
|
-
let rng = ${
|
|
1457
|
+
let rng = ${q}( ${1} );
|
|
1458
1458
|
if ( bounce > 0u ) {
|
|
1459
1459
|
|
|
1460
|
-
resultColor += ${
|
|
1460
|
+
resultColor += ${Zt}( envMap, envMapSampler, envInfo, ray.direction, rng ) * vec4f( throughputColor, 0.0 );
|
|
1461
1461
|
|
|
1462
1462
|
} else {
|
|
1463
1463
|
|
|
1464
|
-
resultColor = ${
|
|
1464
|
+
resultColor = ${Zt}( background, backgroundSampler, backgroundInfo, ray.direction, rng );
|
|
1465
1465
|
|
|
1466
1466
|
}
|
|
1467
1467
|
|
|
@@ -1469,13 +1469,13 @@ var Ot = W`
|
|
|
1469
1469
|
|
|
1470
1470
|
}
|
|
1471
1471
|
|
|
1472
|
-
${
|
|
1472
|
+
${jt}();
|
|
1473
1473
|
|
|
1474
1474
|
}
|
|
1475
1475
|
|
|
1476
1476
|
let sampleCount = textureLoad( ${e.sampleCountTarget}, indexUV ).r + 1;
|
|
1477
1477
|
let prevColor = textureLoad( ${e.prevOutputTarget}, indexUV );
|
|
1478
|
-
let blendedColor = ${
|
|
1478
|
+
let blendedColor = ${Qt}( prevColor, resultColor, 1.0 / f32( sampleCount ) );
|
|
1479
1479
|
textureStore( ${e.sampleCountTarget}, indexUV, vec4( sampleCount ) );
|
|
1480
1480
|
textureStore( ${e.outputTarget}, indexUV, blendedColor );
|
|
1481
1481
|
|
|
@@ -1485,14 +1485,14 @@ var Ot = W`
|
|
|
1485
1485
|
};
|
|
1486
1486
|
//#endregion
|
|
1487
1487
|
//#region ../../node_modules/three-gpu-pathtracer/src/utils/TextureUtils.js
|
|
1488
|
-
function
|
|
1488
|
+
function en(e) {
|
|
1489
1489
|
let t = new Uint16Array(e.length);
|
|
1490
|
-
for (let n = 0, r = e.length; n < r; ++n) t[n] =
|
|
1490
|
+
for (let n = 0, r = e.length; n < r; ++n) t[n] = m.toHalfFloat(e[n]);
|
|
1491
1491
|
return t;
|
|
1492
1492
|
}
|
|
1493
1493
|
//#endregion
|
|
1494
1494
|
//#region ../../node_modules/three-gpu-pathtracer/src/uniforms/EquirectHdrInfoUniform.js
|
|
1495
|
-
function
|
|
1495
|
+
function tn(e, t, n = 0, r = e.length) {
|
|
1496
1496
|
let i = n, a = n + r - 1;
|
|
1497
1497
|
for (; i < a;) {
|
|
1498
1498
|
let n = i + a >> 1;
|
|
@@ -1500,97 +1500,97 @@ function en(e, t, n = 0, r = e.length) {
|
|
|
1500
1500
|
}
|
|
1501
1501
|
return i - n;
|
|
1502
1502
|
}
|
|
1503
|
-
function
|
|
1503
|
+
function nn(e, t, n) {
|
|
1504
1504
|
return .2126 * e + .7152 * t + .0722 * n;
|
|
1505
1505
|
}
|
|
1506
|
-
function
|
|
1507
|
-
let
|
|
1508
|
-
|
|
1509
|
-
let { width:
|
|
1510
|
-
if (
|
|
1511
|
-
|
|
1506
|
+
function rn(t, n = S) {
|
|
1507
|
+
let r = t.clone();
|
|
1508
|
+
r.source = new e({ ...r.image });
|
|
1509
|
+
let { width: i, height: a, data: o } = r.image, s = o;
|
|
1510
|
+
if (r.type !== n) {
|
|
1511
|
+
s = n === 1016 ? new Uint16Array(o.length) : new Float32Array(o.length);
|
|
1512
1512
|
let e;
|
|
1513
|
-
e =
|
|
1514
|
-
for (let
|
|
1515
|
-
let i =
|
|
1516
|
-
|
|
1513
|
+
e = o instanceof Int8Array || o instanceof Int16Array || o instanceof Int32Array ? 2 ** (8 * o.BYTES_PER_ELEMENT - 1) - 1 : 2 ** (8 * o.BYTES_PER_ELEMENT) - 1;
|
|
1514
|
+
for (let t = 0, i = o.length; t < i; t++) {
|
|
1515
|
+
let i = o[t];
|
|
1516
|
+
r.type === 1016 && (i = m.fromHalfFloat(o[t])), r.type !== 1015 && r.type !== 1016 && (i /= e), n === 1016 && (s[t] = m.toHalfFloat(i));
|
|
1517
1517
|
}
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
if (
|
|
1521
|
-
let e =
|
|
1522
|
-
|
|
1523
|
-
for (let t = 0; t <
|
|
1524
|
-
let
|
|
1525
|
-
|
|
1518
|
+
r.image.data = s, r.type = n;
|
|
1519
|
+
}
|
|
1520
|
+
if (r.flipY) {
|
|
1521
|
+
let e = s;
|
|
1522
|
+
s = s.slice();
|
|
1523
|
+
for (let t = 0; t < a; t++) for (let n = 0; n < i; n++) {
|
|
1524
|
+
let r = a - t - 1, o = 4 * (t * i + n), c = 4 * (r * i + n);
|
|
1525
|
+
s[c + 0] = e[o + 0], s[c + 1] = e[o + 1], s[c + 2] = e[o + 2], s[c + 3] = e[o + 3];
|
|
1526
1526
|
}
|
|
1527
|
-
|
|
1527
|
+
r.flipY = !1, r.image.data = s;
|
|
1528
1528
|
}
|
|
1529
|
-
return
|
|
1529
|
+
return r;
|
|
1530
1530
|
}
|
|
1531
|
-
var
|
|
1531
|
+
var an = class {
|
|
1532
1532
|
constructor() {
|
|
1533
|
-
let e = new
|
|
1533
|
+
let e = new h(en(new Float32Array([
|
|
1534
1534
|
0,
|
|
1535
1535
|
0,
|
|
1536
1536
|
0,
|
|
1537
1537
|
0
|
|
1538
1538
|
])), 1, 1);
|
|
1539
|
-
e.type =
|
|
1540
|
-
let t = new
|
|
1541
|
-
t.type =
|
|
1542
|
-
let
|
|
1539
|
+
e.type = S, e.format = c, e.minFilter = s, e.magFilter = s, e.wrapS = u, e.wrapT = u, e.generateMipmaps = !1, e.needsUpdate = !0;
|
|
1540
|
+
let t = new h(en(new Float32Array([0, 1])), 1, 2);
|
|
1541
|
+
t.type = S, t.format = n, t.minFilter = s, t.magFilter = s, t.generateMipmaps = !1, t.needsUpdate = !0;
|
|
1542
|
+
let r = new h(en(new Float32Array([
|
|
1543
1543
|
0,
|
|
1544
1544
|
0,
|
|
1545
1545
|
1,
|
|
1546
1546
|
1
|
|
1547
1547
|
])), 2, 2);
|
|
1548
|
-
|
|
1548
|
+
r.type = S, r.format = n, r.minFilter = s, r.magFilter = s, r.generateMipmaps = !1, r.needsUpdate = !0, this.map = e, this.marginalWeights = t, this.conditionalWeights = r, this.totalSum = 0;
|
|
1549
1549
|
}
|
|
1550
1550
|
dispose() {
|
|
1551
1551
|
this.marginalWeights.dispose(), this.conditionalWeights.dispose(), this.map.dispose();
|
|
1552
1552
|
}
|
|
1553
1553
|
updateFrom(e) {
|
|
1554
|
-
let t =
|
|
1555
|
-
t.wrapS =
|
|
1556
|
-
let { width: n, height: r, data: i } = t.image, a = new Float32Array(n * r),
|
|
1554
|
+
let t = rn(e);
|
|
1555
|
+
t.wrapS = u, t.wrapT = f;
|
|
1556
|
+
let { width: n, height: r, data: i } = t.image, a = new Float32Array(n * r), o = new Float32Array(n * r), s = new Float32Array(r), c = new Float32Array(r), l = 0, d = 0;
|
|
1557
1557
|
for (let e = 0; e < r; e++) {
|
|
1558
1558
|
let t = 0;
|
|
1559
1559
|
for (let r = 0; r < n; r++) {
|
|
1560
|
-
let
|
|
1561
|
-
t += c,
|
|
1560
|
+
let s = e * n + r, c = nn(m.fromHalfFloat(i[4 * s + 0]), m.fromHalfFloat(i[4 * s + 1]), m.fromHalfFloat(i[4 * s + 2]));
|
|
1561
|
+
t += c, l += c, a[s] = c, o[s] = t;
|
|
1562
1562
|
}
|
|
1563
|
-
if (t !== 0) for (let r = e * n, i = e * n + n; r < i; r++) a[r] /= t,
|
|
1564
|
-
|
|
1563
|
+
if (t !== 0) for (let r = e * n, i = e * n + n; r < i; r++) a[r] /= t, o[r] /= t;
|
|
1564
|
+
d += t, s[e] = t, c[e] = d;
|
|
1565
1565
|
}
|
|
1566
|
-
if (
|
|
1567
|
-
let
|
|
1566
|
+
if (d !== 0) for (let e = 0, t = s.length; e < t; e++) s[e] /= d, c[e] /= d;
|
|
1567
|
+
let p = new Uint16Array(r), h = new Uint16Array(n * r);
|
|
1568
1568
|
for (let e = 0; e < r; e++) {
|
|
1569
|
-
let t =
|
|
1570
|
-
|
|
1569
|
+
let t = tn(c, (e + 1) / r);
|
|
1570
|
+
p[e] = m.toHalfFloat((t + .5) / r);
|
|
1571
1571
|
}
|
|
1572
1572
|
for (let e = 0; e < r; e++) for (let t = 0; t < n; t++) {
|
|
1573
|
-
let r = e * n + t, i =
|
|
1574
|
-
h[r] =
|
|
1573
|
+
let r = e * n + t, i = tn(o, (t + 1) / n, e * n, n);
|
|
1574
|
+
h[r] = m.toHalfFloat((i + .5) / n);
|
|
1575
1575
|
}
|
|
1576
1576
|
this.dispose();
|
|
1577
1577
|
let { marginalWeights: g, conditionalWeights: _ } = this;
|
|
1578
1578
|
g.image = {
|
|
1579
1579
|
width: r,
|
|
1580
1580
|
height: 1,
|
|
1581
|
-
data:
|
|
1581
|
+
data: p
|
|
1582
1582
|
}, g.needsUpdate = !0, _.image = {
|
|
1583
1583
|
width: n,
|
|
1584
1584
|
height: r,
|
|
1585
1585
|
data: h
|
|
1586
|
-
}, _.needsUpdate = !0, this.totalSum =
|
|
1586
|
+
}, _.needsUpdate = !0, this.totalSum = l, this.map = t;
|
|
1587
1587
|
}
|
|
1588
|
-
},
|
|
1588
|
+
}, on = class extends G {
|
|
1589
1589
|
constructor() {
|
|
1590
1590
|
let e = {
|
|
1591
|
-
globalId:
|
|
1592
|
-
outputTarget:
|
|
1593
|
-
}, t =
|
|
1591
|
+
globalId: k,
|
|
1592
|
+
outputTarget: O(new T(1, 1)).toWriteOnly()
|
|
1593
|
+
}, t = H`
|
|
1594
1594
|
fn compute( globalId: vec3u ) -> void {
|
|
1595
1595
|
|
|
1596
1596
|
textureStore( ${e.outputTarget}, globalId.xy, vec4( 0, 0, 0, 1 ) );
|
|
@@ -1599,9 +1599,9 @@ var rn = class {
|
|
|
1599
1599
|
`;
|
|
1600
1600
|
super(t(e)), this.defineUniformAccessors({ target: e.outputTarget });
|
|
1601
1601
|
}
|
|
1602
|
-
},
|
|
1603
|
-
constructor(
|
|
1604
|
-
this.renderer =
|
|
1602
|
+
}, sn = class {
|
|
1603
|
+
constructor(e) {
|
|
1604
|
+
this.renderer = e, this.camera = null, this.samples = 0, this.bounces = 7, this.lowResMode = !1, this._renderTask = null, this.outputTarget = new T(1, 1), this.outputTarget.format = c, this.outputTarget.type = b, this.outputTarget.colorSpace = i.workingColorSpace, this.outputTarget.name = "Output #0", this.outputTarget.generateMipmaps = !1, this.prevOutputTarget = new T(1, 1), this.prevOutputTarget.format = c, this.prevOutputTarget.type = b, this.prevOutputTarget.colorSpace = i.workingColorSpace, this.prevOutputTarget.name = "Output #1", this.prevOutputTarget.generateMipmaps = !1, this.sampleCountTarget = new T(1, 1), this.sampleCountTarget.format = C, this.sampleCountTarget.type = se, this.sampleCountTarget.name = "Sample Count", this.sampleCountTarget.generateMipmaps = !1, this.sampleCountClearKernel = new on().setWorkgroupSize(8, 8, 1), this.outputTargetClearKernel = new on().setWorkgroupSize(8, 8, 1);
|
|
1605
1605
|
}
|
|
1606
1606
|
setCamera(e) {
|
|
1607
1607
|
this.camera = e, this.reset();
|
|
@@ -1633,9 +1633,9 @@ var rn = class {
|
|
|
1633
1633
|
dispose() {
|
|
1634
1634
|
this.outputTarget.dispose(), this.prevOutputTarget.dispose(), this.sampleCountTarget.dispose(), this._renderTask = null;
|
|
1635
1635
|
}
|
|
1636
|
-
},
|
|
1636
|
+
}, cn = class extends sn {
|
|
1637
1637
|
constructor(e) {
|
|
1638
|
-
super(e), this.tiles = new
|
|
1638
|
+
super(e), this.tiles = new p(2, 2), this.envInfo = new an(), this.samples = 0, this.kernel = new $t().setWorkgroupSize(8, 8, 1);
|
|
1639
1639
|
}
|
|
1640
1640
|
setBVHData(e) {
|
|
1641
1641
|
this.kernel.bvhData = e, this.kernel.needsUpdate = !0, this.reset();
|
|
@@ -1646,7 +1646,7 @@ var rn = class {
|
|
|
1646
1646
|
setEnvironment(e, t, n, r, i, a, o) {
|
|
1647
1647
|
let { kernel: s } = this;
|
|
1648
1648
|
s.background.isTexture && s.background.dispose(), e !== null && (this.envInfo.updateFrom(e), s.envMap = this.envInfo.map, s.kernel.computeNode.parameters.envMapSampler.node.value = this.envInfo.map);
|
|
1649
|
-
let c = new
|
|
1649
|
+
let c = new y().makeRotationFromEuler(n).invert();
|
|
1650
1650
|
s.envMapRotation.setFromMatrix4(c), s.envMapIntensity = t, s.background = r, s.kernel.computeNode.parameters.backgroundSampler.node.value = r, c.makeRotationFromEuler(a).invert(), s.backgroundRotation.setFromMatrix4(c), s.backgroundIntensity = i, s.backgroundBlurriness = o;
|
|
1651
1651
|
}
|
|
1652
1652
|
setTiles(e) {
|
|
@@ -1666,7 +1666,7 @@ var rn = class {
|
|
|
1666
1666
|
dispose() {
|
|
1667
1667
|
super.dispose(), this.envInfo.dispose();
|
|
1668
1668
|
}
|
|
1669
|
-
},
|
|
1669
|
+
}, X = new E({
|
|
1670
1670
|
origin: "vec3f",
|
|
1671
1671
|
seed: "uint",
|
|
1672
1672
|
direction: "vec3f",
|
|
@@ -1675,7 +1675,7 @@ var rn = class {
|
|
|
1675
1675
|
currentBounce: "uint",
|
|
1676
1676
|
pixel: "vec2u",
|
|
1677
1677
|
resultColor: "vec4f"
|
|
1678
|
-
}, "QueuedRay"),
|
|
1678
|
+
}, "QueuedRay"), Z = new E({
|
|
1679
1679
|
indices: "vec3u",
|
|
1680
1680
|
seed: "uint",
|
|
1681
1681
|
barycoord: "vec2f",
|
|
@@ -1688,18 +1688,18 @@ var rn = class {
|
|
|
1688
1688
|
normal: "vec3f",
|
|
1689
1689
|
side: "float",
|
|
1690
1690
|
resultColor: "vec4f"
|
|
1691
|
-
}, "QueuedHit"),
|
|
1691
|
+
}, "QueuedHit"), ln = class extends G {
|
|
1692
1692
|
constructor() {
|
|
1693
1693
|
let e = {
|
|
1694
|
-
rayWorkGroupSize:
|
|
1695
|
-
tileSize:
|
|
1696
|
-
tileCount:
|
|
1697
|
-
tileOffset:
|
|
1698
|
-
rayQueue:
|
|
1699
|
-
queueSizes:
|
|
1700
|
-
outputTileIndex:
|
|
1701
|
-
outputDispatch:
|
|
1702
|
-
},
|
|
1694
|
+
rayWorkGroupSize: j(new a()),
|
|
1695
|
+
tileSize: j(new p()),
|
|
1696
|
+
tileCount: j(new p()),
|
|
1697
|
+
tileOffset: j(1),
|
|
1698
|
+
rayQueue: N(new D(1, X.getLength()), X).toReadOnly(),
|
|
1699
|
+
queueSizes: N(new D(4, 1), "u32"),
|
|
1700
|
+
outputTileIndex: N(new D(2, 1), "u32").setName("outputTileIndex"),
|
|
1701
|
+
outputDispatch: N(new D(3, 1), "u32").setName("outputDispatch")
|
|
1702
|
+
}, t = H`
|
|
1703
1703
|
fn compute(
|
|
1704
1704
|
rayWorkGroupSize: vec3u,
|
|
1705
1705
|
|
|
@@ -1761,21 +1761,21 @@ var rn = class {
|
|
|
1761
1761
|
|
|
1762
1762
|
}
|
|
1763
1763
|
`;
|
|
1764
|
-
super(
|
|
1764
|
+
super(t(e)), this.defineUniformAccessors(e);
|
|
1765
1765
|
}
|
|
1766
|
-
},
|
|
1766
|
+
}, un = class extends G {
|
|
1767
1767
|
constructor() {
|
|
1768
1768
|
let e = {
|
|
1769
|
-
cameraToModelMatrix:
|
|
1770
|
-
inverseProjectionMatrix:
|
|
1771
|
-
seed:
|
|
1772
|
-
tileIndexBuffer:
|
|
1773
|
-
tileSize:
|
|
1774
|
-
rayQueue:
|
|
1775
|
-
queueSizes:
|
|
1776
|
-
sampleCountTarget:
|
|
1777
|
-
globalId:
|
|
1778
|
-
}, t =
|
|
1769
|
+
cameraToModelMatrix: j(new y()),
|
|
1770
|
+
inverseProjectionMatrix: j(new y()),
|
|
1771
|
+
seed: j(0),
|
|
1772
|
+
tileIndexBuffer: N(new D(2, 1), "u32"),
|
|
1773
|
+
tileSize: j(new p()),
|
|
1774
|
+
rayQueue: N(new D(1, X.getLength()), X),
|
|
1775
|
+
queueSizes: N(new D(4, 1), "u32").toAtomic(),
|
|
1776
|
+
sampleCountTarget: O(new T()).toReadWrite(),
|
|
1777
|
+
globalId: k
|
|
1778
|
+
}, t = H`
|
|
1779
1779
|
fn compute(
|
|
1780
1780
|
cameraToModelMatrix: mat4x4f,
|
|
1781
1781
|
inverseProjectionMatrix: mat4x4f,
|
|
@@ -1828,11 +1828,11 @@ var rn = class {
|
|
|
1828
1828
|
let index = atomicAdd( &queueSizes[ 1 ], 1 ) % queueCapacity;
|
|
1829
1829
|
|
|
1830
1830
|
let pixelIndex = ( indexUV.x << 16 ) | indexUV.y;
|
|
1831
|
-
${
|
|
1831
|
+
${At}( pixelIndex, seed, 0 );
|
|
1832
1832
|
|
|
1833
1833
|
// write the ray data
|
|
1834
|
-
var jitter = 2.0 * ${
|
|
1835
|
-
var ray = ${
|
|
1834
|
+
var jitter = 2.0 * ${q}( ${0} ) / vec2f( targetDimensions.xy );
|
|
1835
|
+
var ray = ${it}( ndc + jitter, cameraToModelMatrix * inverseProjectionMatrix );
|
|
1836
1836
|
ray.direction = normalize( ray.direction );
|
|
1837
1837
|
|
|
1838
1838
|
rayQueue[ index ].origin = ray.origin;
|
|
@@ -1850,27 +1850,27 @@ var rn = class {
|
|
|
1850
1850
|
`;
|
|
1851
1851
|
super(t(e)), this.defineUniformAccessors(e);
|
|
1852
1852
|
}
|
|
1853
|
-
},
|
|
1853
|
+
}, dn = class extends G {
|
|
1854
1854
|
constructor() {
|
|
1855
1855
|
let e = {
|
|
1856
1856
|
bvhData: { value: null },
|
|
1857
|
-
prevOutputTarget:
|
|
1858
|
-
outputTarget:
|
|
1859
|
-
sampleCountTarget:
|
|
1860
|
-
rayQueue:
|
|
1861
|
-
hitQueue:
|
|
1862
|
-
queueSizes:
|
|
1863
|
-
envMap:
|
|
1864
|
-
envMapSampler:
|
|
1865
|
-
envMapRotation:
|
|
1866
|
-
envMapIntensity:
|
|
1867
|
-
background:
|
|
1868
|
-
backgroundSampler:
|
|
1869
|
-
backgroundRotation:
|
|
1870
|
-
backgroundIntensity:
|
|
1871
|
-
backgroundBlurriness:
|
|
1872
|
-
globalId:
|
|
1873
|
-
}, t =
|
|
1857
|
+
prevOutputTarget: O(new T(1, 1)).toReadOnly(),
|
|
1858
|
+
outputTarget: O(new T(1, 1)).toWriteOnly(),
|
|
1859
|
+
sampleCountTarget: O(new T(1, 1)).toReadWrite(),
|
|
1860
|
+
rayQueue: N(new D(1, X.getLength()), X).toReadOnly(),
|
|
1861
|
+
hitQueue: N(new D(1, Z.getLength()), Z),
|
|
1862
|
+
queueSizes: N(new D(4, 1), "u32").toAtomic(),
|
|
1863
|
+
envMap: M(new h()),
|
|
1864
|
+
envMapSampler: P(new h()),
|
|
1865
|
+
envMapRotation: j(new ie()),
|
|
1866
|
+
envMapIntensity: j(1),
|
|
1867
|
+
background: M(new h()),
|
|
1868
|
+
backgroundSampler: P(new h()),
|
|
1869
|
+
backgroundRotation: j(new ie()),
|
|
1870
|
+
backgroundIntensity: j(1),
|
|
1871
|
+
backgroundBlurriness: j(0),
|
|
1872
|
+
globalId: k
|
|
1873
|
+
}, t = R("bvhData.value.fns.raycastFirstHit.outputType", e), n = R("bvhData.value.fns.raycastFirstHit", e), r = H`
|
|
1874
1874
|
|
|
1875
1875
|
fn compute(
|
|
1876
1876
|
// environment
|
|
@@ -1919,7 +1919,7 @@ var rn = class {
|
|
|
1919
1919
|
let indexUV = input.pixel;
|
|
1920
1920
|
|
|
1921
1921
|
let pixelIndex = ( indexUV.x << 16 ) | indexUV.y;
|
|
1922
|
-
${
|
|
1922
|
+
${At}( pixelIndex, input.seed, input.currentBounce );
|
|
1923
1923
|
|
|
1924
1924
|
// run intersection
|
|
1925
1925
|
let ray = Ray( input.origin, input.direction );
|
|
@@ -1943,21 +1943,21 @@ var rn = class {
|
|
|
1943
1943
|
|
|
1944
1944
|
} else {
|
|
1945
1945
|
|
|
1946
|
-
let rng = ${
|
|
1946
|
+
let rng = ${q}( ${1} );
|
|
1947
1947
|
var resultColor = input.resultColor;
|
|
1948
1948
|
if ( input.currentBounce > 0u ) {
|
|
1949
1949
|
|
|
1950
|
-
resultColor += ${
|
|
1950
|
+
resultColor += ${Zt}( envMap, envMapSampler, envInfo, input.direction, rng ) * vec4f( input.throughputColor, 0.0 );
|
|
1951
1951
|
|
|
1952
1952
|
} else {
|
|
1953
1953
|
|
|
1954
|
-
resultColor = ${
|
|
1954
|
+
resultColor = ${Zt}( background, backgroundSampler, backgroundInfo, input.direction, rng );
|
|
1955
1955
|
|
|
1956
1956
|
}
|
|
1957
1957
|
|
|
1958
1958
|
let sampleCount = ( textureLoad( ${e.sampleCountTarget}, indexUV ).r & ( ~ ACTIVE_FLAG ) ) + 1;
|
|
1959
1959
|
let prevColor = textureLoad( ${e.prevOutputTarget}, indexUV );
|
|
1960
|
-
let blendedColor = ${
|
|
1960
|
+
let blendedColor = ${Qt}( prevColor, resultColor, 1.0 / f32( sampleCount ) );
|
|
1961
1961
|
textureStore( ${e.sampleCountTarget}, indexUV, vec4( sampleCount ) );
|
|
1962
1962
|
textureStore( ${e.outputTarget}, indexUV, blendedColor );
|
|
1963
1963
|
|
|
@@ -1967,12 +1967,12 @@ var rn = class {
|
|
|
1967
1967
|
`;
|
|
1968
1968
|
super(r(e)), this.defineUniformAccessors(e);
|
|
1969
1969
|
}
|
|
1970
|
-
},
|
|
1970
|
+
}, fn = class extends G {
|
|
1971
1971
|
constructor() {
|
|
1972
1972
|
let e = {
|
|
1973
|
-
processed:
|
|
1974
|
-
queueSizes:
|
|
1975
|
-
}, t =
|
|
1973
|
+
processed: j(0),
|
|
1974
|
+
queueSizes: N(new D(4, 1), "u32")
|
|
1975
|
+
}, t = H`
|
|
1976
1976
|
fn compute( processed: u32 ) -> void {
|
|
1977
1977
|
|
|
1978
1978
|
let queueSizes = &${e.queueSizes};
|
|
@@ -1991,12 +1991,12 @@ var rn = class {
|
|
|
1991
1991
|
`;
|
|
1992
1992
|
super(t(e)), this.defineUniformAccessors(e);
|
|
1993
1993
|
}
|
|
1994
|
-
},
|
|
1994
|
+
}, pn = class extends G {
|
|
1995
1995
|
constructor(e = {}) {
|
|
1996
1996
|
let { type: t = "u32" } = e, n = {
|
|
1997
|
-
globalId:
|
|
1998
|
-
outputTarget:
|
|
1999
|
-
}, r =
|
|
1997
|
+
globalId: k,
|
|
1998
|
+
outputTarget: N(new D(1, 1), t)
|
|
1999
|
+
}, r = H`
|
|
2000
2000
|
fn compute( globalId: vec3u ) -> void {
|
|
2001
2001
|
|
|
2002
2002
|
${n.outputTarget}[ globalId.x ] = 0;
|
|
@@ -2005,23 +2005,23 @@ var rn = class {
|
|
|
2005
2005
|
`;
|
|
2006
2006
|
super(r(n)), this.defineUniformAccessors({ target: n.outputTarget });
|
|
2007
2007
|
}
|
|
2008
|
-
},
|
|
2008
|
+
}, mn = class extends G {
|
|
2009
2009
|
constructor() {
|
|
2010
2010
|
let e = {
|
|
2011
2011
|
bvhData: { value: null },
|
|
2012
2012
|
material: { value: null },
|
|
2013
|
-
prevOutputTarget:
|
|
2014
|
-
outputTarget:
|
|
2015
|
-
sampleCountTarget:
|
|
2016
|
-
smoothNormals:
|
|
2017
|
-
bounces:
|
|
2018
|
-
rayQueue:
|
|
2019
|
-
hitQueue:
|
|
2020
|
-
queueSizes:
|
|
2021
|
-
textures:
|
|
2022
|
-
textureSampler:
|
|
2023
|
-
globalId:
|
|
2024
|
-
}, t =
|
|
2013
|
+
prevOutputTarget: O(new T(1, 1)).toReadOnly(),
|
|
2014
|
+
outputTarget: O(new T(1, 1)).toWriteOnly(),
|
|
2015
|
+
sampleCountTarget: O(new T(1, 1)).toReadWrite(),
|
|
2016
|
+
smoothNormals: j(1),
|
|
2017
|
+
bounces: j(1),
|
|
2018
|
+
rayQueue: N(new D(1, X.getLength()), X),
|
|
2019
|
+
hitQueue: N(new D(1, Z.getLength()), Z),
|
|
2020
|
+
queueSizes: N(new D(4, 1), "u32").toAtomic(),
|
|
2021
|
+
textures: M(new h()),
|
|
2022
|
+
textureSampler: P(new h()),
|
|
2023
|
+
globalId: k
|
|
2024
|
+
}, t = z("bvhData.value.fns.sampleTrianglePoint", e), n = z("bvhData.value.fns.getSurfaceRecord", e), r = z("material.value.bsdfSample", e), i = H`
|
|
2025
2025
|
|
|
2026
2026
|
fn compute(
|
|
2027
2027
|
// settings
|
|
@@ -2035,8 +2035,8 @@ var rn = class {
|
|
|
2035
2035
|
let hitQueue = &${e.hitQueue};
|
|
2036
2036
|
let queueSizes = &${e.queueSizes};
|
|
2037
2037
|
|
|
2038
|
-
let materials = &${
|
|
2039
|
-
let transforms = &${
|
|
2038
|
+
let materials = &${R("bvhData.value.storage.materials", e)};
|
|
2039
|
+
let transforms = &${R("bvhData.value.storage.transforms", e)};
|
|
2040
2040
|
|
|
2041
2041
|
// skip any rays invocations beyond the ray count
|
|
2042
2042
|
let hitQueueCapacity = arrayLength( hitQueue );
|
|
@@ -2053,7 +2053,7 @@ var rn = class {
|
|
|
2053
2053
|
let indexUV = vec2u( input.pixel_x, input.pixel_y );
|
|
2054
2054
|
|
|
2055
2055
|
let pixelIndex = ( indexUV.x << 16 ) | indexUV.y;
|
|
2056
|
-
${
|
|
2056
|
+
${At}( pixelIndex, input.seed, input.currentBounce );
|
|
2057
2057
|
|
|
2058
2058
|
let object = transforms[ input.objectIndex ];
|
|
2059
2059
|
var material = materials[ object.materialIndex ];
|
|
@@ -2073,14 +2073,14 @@ var rn = class {
|
|
|
2073
2073
|
|
|
2074
2074
|
let resultColor = input.resultColor + vec4f( input.throughputColor * surface.emission, 0.0 );
|
|
2075
2075
|
|
|
2076
|
-
let isTerminated = input.currentBounce >= bounces || ${
|
|
2076
|
+
let isTerminated = input.currentBounce >= bounces || ${Kt}( scatterRec );
|
|
2077
2077
|
|
|
2078
2078
|
if ( isTerminated ) {
|
|
2079
2079
|
|
|
2080
2080
|
// terminate ray, write color
|
|
2081
2081
|
let sampleCount = ( textureLoad( ${e.sampleCountTarget}, indexUV ).r & ( ~ ACTIVE_FLAG ) ) + 1;
|
|
2082
2082
|
let prevColor = textureLoad( ${e.prevOutputTarget}, indexUV );
|
|
2083
|
-
let blendedColor = ${
|
|
2083
|
+
let blendedColor = ${Qt}( prevColor, resultColor, 1.0 / f32( sampleCount ) );
|
|
2084
2084
|
textureStore( ${e.sampleCountTarget}, indexUV, vec4( sampleCount ) );
|
|
2085
2085
|
textureStore( ${e.outputTarget}, indexUV, blendedColor );
|
|
2086
2086
|
|
|
@@ -2101,9 +2101,9 @@ var rn = class {
|
|
|
2101
2101
|
}`;
|
|
2102
2102
|
super(i(e)), this.defineUniformAccessors(e);
|
|
2103
2103
|
}
|
|
2104
|
-
},
|
|
2104
|
+
}, hn = 25e4, gn = 134217728, _n = Math.floor(gn / (X.getLength() * 4)), vn = Math.floor(gn / (Z.getLength() * 4)), yn = class extends sn {
|
|
2105
2105
|
constructor(e) {
|
|
2106
|
-
super(e), this.tiles = new
|
|
2106
|
+
super(e), this.tiles = new p(3, 3), this.envInfo = new an(), this.rayQueue = new D(_n, X.getLength()), this.rayQueue.name = "Ray Queue", this.hitQueue = new D(vn, Z.getLength()), this.hitQueue.name = "Hit Queue", this.queueSizes = new D(4, 1), this.queueSizes.name = "Queue Sizes", this.tileIndexBuffer = new D(2, 1), this.rayGenerationDispatch = new D(3, 1), this.hitProcessDispatch = new D(3, 1), this.primeRayGenerationDispatchKernel = new ln().setWorkgroupSize(1, 1, 1), this.enqueueRaysKernel = new un().setWorkgroupSize(8, 8, 1), this.rayIntersectionKernel = new dn().setWorkgroupSize(64, 1, 1), this.updateRayQueueParamsKernel = new fn().setWorkgroupSize(1, 1, 1), this.hitProcessKernel = new mn().setWorkgroupSize(64, 1, 1), this.zeroDispatchKernel = new pn().setWorkgroupSize(1, 1, 1), this.volumeKernel = null, this.lightConnectionKernel = null;
|
|
2107
2107
|
}
|
|
2108
2108
|
setBVHData(e) {
|
|
2109
2109
|
this.rayIntersectionKernel.bvhData = e, this.rayIntersectionKernel.needsUpdate = !0, this.hitProcessKernel.bvhData = e, this.hitProcessKernel.needsUpdate = !0, this.reset();
|
|
@@ -2114,7 +2114,7 @@ var rn = class {
|
|
|
2114
2114
|
setEnvironment(e, t, n, r, i, a, o) {
|
|
2115
2115
|
let s = this.rayIntersectionKernel;
|
|
2116
2116
|
s.background.isTexture && s.background.dispose(), e !== null && (this.envInfo.updateFrom(e), s.envMap = this.envInfo.map, s.kernel.computeNode.parameters.envMapSampler.node.value = this.envInfo.map);
|
|
2117
|
-
let c = new
|
|
2117
|
+
let c = new y().makeRotationFromEuler(n).invert();
|
|
2118
2118
|
s.envMapRotation.setFromMatrix4(c), s.envMapIntensity = t, s.background = r, s.kernel.computeNode.parameters.backgroundSampler.node.value = r, c.makeRotationFromEuler(a).invert(), s.backgroundRotation.setFromMatrix4(c), s.backgroundIntensity = i, s.backgroundBlurriness = o;
|
|
2119
2119
|
}
|
|
2120
2120
|
setTiles(e) {
|
|
@@ -2134,20 +2134,20 @@ var rn = class {
|
|
|
2134
2134
|
t.target = r, e.compute(t.kernel, u), n.target = o, e.compute(n.kernel, [o.count]), n.target = i, e.compute(n.kernel, [i.count]), n.target = a, e.compute(n.kernel, [a.count]), n.target = s, e.compute(n.kernel, [s.count]);
|
|
2135
2135
|
}
|
|
2136
2136
|
*createRenderTask() {
|
|
2137
|
-
let { renderer: e, camera: t, bounces: n, tiles: r, sampleCountTarget: i, rayQueue: a, hitQueue: o, queueSizes: s, rayGenerationDispatch: c, tileIndexBuffer:
|
|
2138
|
-
t.updateMatrixWorld(),
|
|
2139
|
-
let _ = new
|
|
2137
|
+
let { renderer: e, camera: t, bounces: n, tiles: r, sampleCountTarget: i, rayQueue: a, hitQueue: o, queueSizes: s, rayGenerationDispatch: c, tileIndexBuffer: l, primeRayGenerationDispatchKernel: u, enqueueRaysKernel: d, rayIntersectionKernel: f, updateRayQueueParamsKernel: m, hitProcessKernel: h, lowResMode: g } = this;
|
|
2138
|
+
t.updateMatrixWorld(), u.tileOffset = 0;
|
|
2139
|
+
let _ = new p(), v = hn / (i.width * i.height * n), y = g ? 5 : 1, b = 0;
|
|
2140
2140
|
for (;;) {
|
|
2141
|
-
for (let
|
|
2142
|
-
this.getTileSize(_), e.copyTextureToTexture(this.outputTarget, this.prevOutputTarget), [this.outputTarget, this.prevOutputTarget] = [this.prevOutputTarget, this.outputTarget],
|
|
2143
|
-
for (let t = 0; t < r.x * r.y; t++) e.compute(
|
|
2141
|
+
for (let p = 0; p < y; p++) {
|
|
2142
|
+
this.getTileSize(_), e.copyTextureToTexture(this.outputTarget, this.prevOutputTarget), [this.outputTarget, this.prevOutputTarget] = [this.prevOutputTarget, this.outputTarget], f.prevOutputTarget = this.prevOutputTarget, f.outputTarget = this.outputTarget, h.prevOutputTarget = this.prevOutputTarget, h.outputTarget = this.outputTarget, u.rayWorkGroupSize.set(8, 8, 1), u.tileCount.copy(r), u.tileSize.copy(_), u.rayQueue = a, u.queueSizes = s, u.outputTileIndex = l, u.outputDispatch = c, d.seed++, d.cameraToModelMatrix.copy(t.matrixWorld), d.inverseProjectionMatrix.copy(t.projectionMatrixInverse), d.tileIndexBuffer = l, d.tileSize.copy(_), d.rayQueue = a, d.queueSizes = s, d.sampleCountTarget = i;
|
|
2143
|
+
for (let t = 0; t < r.x * r.y; t++) e.compute(u.kernel, [
|
|
2144
2144
|
1,
|
|
2145
2145
|
1,
|
|
2146
2146
|
1
|
|
2147
|
-
]), e.compute(
|
|
2148
|
-
let
|
|
2149
|
-
|
|
2150
|
-
let g =
|
|
2147
|
+
]), e.compute(d.kernel, c), u.tileOffset = 1;
|
|
2148
|
+
let p = f.getDispatchSize(hn, 1, 1);
|
|
2149
|
+
f.sampleCountTarget = i, f.rayQueue = a, f.queueSizes = s, f.hitQueue = o, e.compute(f.kernel, p);
|
|
2150
|
+
let g = p[0] * f.workgroupSize[0];
|
|
2151
2151
|
m.processed = g, m.queueSizes = s, e.compute(m.kernel, [
|
|
2152
2152
|
1,
|
|
2153
2153
|
1,
|
|
@@ -2157,7 +2157,7 @@ var rn = class {
|
|
|
2157
2157
|
yield;
|
|
2158
2158
|
}
|
|
2159
2159
|
}
|
|
2160
|
-
},
|
|
2160
|
+
}, bn = "\n\n // TODO: possibly this should be renamed something related to material or path tracing logic\n\n #ifndef RAY_OFFSET\n #define RAY_OFFSET 1e-4\n #endif\n\n // adjust the hit point by the surface normal by a factor of some offset and the\n // maximum component-wise value of the current point to accommodate floating point\n // error as values increase.\n vec3 stepRayOrigin( vec3 rayOrigin, vec3 rayDirection, vec3 offset, float dist ) {\n\n vec3 point = rayOrigin + rayDirection * dist;\n vec3 absPoint = abs( point );\n float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) );\n return point + offset * ( maxPoint + 1.0 ) * RAY_OFFSET;\n\n }\n\n // https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md#attenuation\n vec3 transmissionAttenuation( float dist, vec3 attColor, float attDist ) {\n\n vec3 ot = - log( attColor ) / attDist;\n return exp( - ot * dist );\n\n }\n\n vec3 getHalfVector( vec3 wi, vec3 wo, float eta ) {\n\n // get the half vector - assuming if the light incident vector is on the other side\n // of the that it's transmissive.\n vec3 h;\n if ( wi.z > 0.0 ) {\n\n h = normalize( wi + wo );\n\n } else {\n\n // Scale by the ior ratio to retrieve the appropriate half vector\n // From Section 2.2 on computing the transmission half vector:\n // https://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf\n h = normalize( wi + wo * eta );\n\n }\n\n h *= sign( h.z );\n return h;\n\n }\n\n vec3 getHalfVector( vec3 a, vec3 b ) {\n\n return normalize( a + b );\n\n }\n\n // The discrepancy between interpolated surface normal and geometry normal can cause issues when a ray\n // is cast that is on the top side of the geometry normal plane but below the surface normal plane. If\n // we find a ray like that we ignore it to avoid artifacts.\n // This function returns if the direction is on the same side of both planes.\n bool isDirectionValid( vec3 direction, vec3 surfaceNormal, vec3 geometryNormal ) {\n\n bool aboveSurfaceNormal = dot( direction, surfaceNormal ) > 0.0;\n bool aboveGeometryNormal = dot( direction, geometryNormal ) > 0.0;\n return aboveSurfaceNormal == aboveGeometryNormal;\n\n }\n\n // ray sampling x and z are swapped to align with expected background view\n vec2 equirectDirectionToUv( vec3 direction ) {\n\n // from Spherical.setFromCartesianCoords\n vec2 uv = vec2( atan( direction.z, direction.x ), acos( direction.y ) );\n uv /= vec2( 2.0 * PI, PI );\n\n // apply adjustments to get values in range [0, 1] and y right side up\n uv.x += 0.5;\n uv.y = 1.0 - uv.y;\n return uv;\n\n }\n\n vec3 equirectUvToDirection( vec2 uv ) {\n\n // undo above adjustments\n uv.x -= 0.5;\n uv.y = 1.0 - uv.y;\n\n // from Vector3.setFromSphericalCoords\n float theta = uv.x * 2.0 * PI;\n float phi = uv.y * PI;\n\n float sinPhi = sin( phi );\n\n return vec3( sinPhi * cos( theta ), cos( phi ), sinPhi * sin( theta ) );\n\n }\n\n // power heuristic for multiple importance sampling\n float misHeuristic( float a, float b ) {\n\n float aa = a * a;\n float bb = b * b;\n return aa / ( aa + bb );\n\n }\n\n // tentFilter from Peter Shirley's 'Realistic Ray Tracing (2nd Edition)' book, pg. 60\n // erichlof/THREE.js-PathTracing-Renderer/\n float tentFilter( float x ) {\n\n return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) );\n\n }\n", xn = class extends o {
|
|
2161
2161
|
constructor() {
|
|
2162
2162
|
super({
|
|
2163
2163
|
uniforms: {
|
|
@@ -2175,7 +2175,7 @@ var rn = class {
|
|
|
2175
2175
|
#include <common>
|
|
2176
2176
|
#include <cube_uv_reflection_fragment>
|
|
2177
2177
|
|
|
2178
|
-
${
|
|
2178
|
+
${bn}
|
|
2179
2179
|
|
|
2180
2180
|
void main() {
|
|
2181
2181
|
|
|
@@ -2186,26 +2186,26 @@ var rn = class {
|
|
|
2186
2186
|
}`
|
|
2187
2187
|
}), this.depthWrite = !1, this.depthTest = !1;
|
|
2188
2188
|
}
|
|
2189
|
-
},
|
|
2189
|
+
}, Sn = class {
|
|
2190
2190
|
constructor(e) {
|
|
2191
|
-
this._renderer = e, this._quad = new
|
|
2191
|
+
this._renderer = e, this._quad = new ce(new xn());
|
|
2192
2192
|
}
|
|
2193
|
-
generate(e,
|
|
2193
|
+
generate(e, n = null, r = null) {
|
|
2194
2194
|
if (!e.isCubeTexture) throw Error("CubeToEquirectMaterial: Source can only be cube textures.");
|
|
2195
|
-
let
|
|
2196
|
-
|
|
2197
|
-
let l = new n
|
|
2198
|
-
type:
|
|
2199
|
-
colorSpace:
|
|
2200
|
-
}), d =
|
|
2201
|
-
|
|
2202
|
-
let
|
|
2203
|
-
|
|
2204
|
-
let x = new Uint16Array(
|
|
2205
|
-
|
|
2206
|
-
for (let e = 0, t =
|
|
2207
|
-
let C = new
|
|
2208
|
-
return C.minFilter =
|
|
2195
|
+
let i = e.images[0], a = this._renderer, o = this._quad;
|
|
2196
|
+
n === null && (n = 4 * i.height), r === null && (r = 2 * i.height);
|
|
2197
|
+
let l = new t(n, r, {
|
|
2198
|
+
type: b,
|
|
2199
|
+
colorSpace: i.colorSpace
|
|
2200
|
+
}), d = i.height, f = Math.log2(d) - 2, p = 1 / d, g = 1 / (3 * Math.max(2 ** f, 112));
|
|
2201
|
+
o.material.defines.CUBEUV_MAX_MIP = `${f}.0`, o.material.defines.CUBEUV_TEXEL_WIDTH = g, o.material.defines.CUBEUV_TEXEL_HEIGHT = p, o.material.uniforms.envMap.value = e, o.material.uniforms.flipEnvMap.value = e.isRenderTargetTexture ? 1 : -1, o.material.needsUpdate = !0;
|
|
2202
|
+
let v = a.getRenderTarget(), y = a.autoClear;
|
|
2203
|
+
a.autoClear = !0, a.setRenderTarget(l), o.render(a), a.setRenderTarget(v), a.autoClear = y;
|
|
2204
|
+
let x = new Uint16Array(n * r * 4), ee = new Float32Array(n * r * 4);
|
|
2205
|
+
a.readRenderTargetPixels(l, 0, 0, n, r, ee), l.dispose();
|
|
2206
|
+
for (let e = 0, t = ee.length; e < t; e++) x[e] = m.toHalfFloat(ee[e]);
|
|
2207
|
+
let C = new h(x, n, r, c, S);
|
|
2208
|
+
return C.minFilter = _, C.magFilter = s, C.wrapS = u, C.wrapT = u, C.mapping = 303, C.needsUpdate = !0, C;
|
|
2209
2209
|
}
|
|
2210
2210
|
dispose() {
|
|
2211
2211
|
this._quad.dispose();
|
|
@@ -2213,28 +2213,28 @@ var rn = class {
|
|
|
2213
2213
|
};
|
|
2214
2214
|
//#endregion
|
|
2215
2215
|
//#region ../../node_modules/three-gpu-pathtracer/src/core/utils/sceneUpdateUtils.js
|
|
2216
|
-
function
|
|
2216
|
+
function Cn(e) {
|
|
2217
2217
|
return `${e.source.uuid}:${e.colorSpace}`;
|
|
2218
2218
|
}
|
|
2219
2219
|
//#endregion
|
|
2220
2220
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/nodes/ggx.wgsl.js
|
|
2221
|
-
var Cn = I("\n\n fn ggxDirection( incidentDir: vec3f, alpha: vec2f, uv: vec2f ) -> vec3f {\n\n // Implementation from reference [1]\n // stretch view\n let V = normalize( vec3f( alpha * incidentDir.xy, incidentDir.z ) );\n\n // orthonormal basis\n var T1: vec3f;\n if ( V.z < 0.9999 ) {\n T1 = normalize( cross( V, vec3( 0.0, 0.0, 1.0 ) ) );\n } else {\n T1 = vec3( 1.0, 0.0, 0.0 );\n }\n\n let T2 = cross( T1, V );\n\n // sample point with polar coordinates (r, phi)\n let a = 1.0 / ( 1.0 + V.z );\n let r = sqrt( uv.x );\n var phi: f32;\n if ( uv.y < a ) {\n phi = uv.y / a * PI;\n } else {\n phi = PI + ( uv.y - a ) / ( 1.0 - a ) * PI;\n }\n let P1 = r * cos( phi );\n var P2 = r * sin( phi );\n if ( uv.y >= a ) {\n P2 *= V.z;\n }\n\n // compute normal\n var N = P1 * T1 + P2 * T2 + V * sqrt( max( 0.0, 1.0 - P1 * P1 - P2 * P2 ) );\n\n // unstretch\n N = normalize( vec3( alpha * N.xy, max( 0.0, N.z ) ) );\n\n return N;\n\n }\n\n", [X]), wn = I("\n\n fn ggxLamda( theta: f32, alpha: f32 ) -> f32 {\n\n let tanTheta = tan( theta );\n let tanTheta2 = tanTheta * tanTheta;\n let alpha2 = alpha * alpha;\n\n let numerator = - 1.0 + sqrt( 1.0 + alpha2 * tanTheta2 );\n return numerator / 2.0;\n\n }\n\n"), Tn = I("\n\n fn ggxShadowMaskG1( cosTheta: f32, alpha: f32 ) -> f32 {\n\n let a2 = alpha * alpha;\n let cosTheta2 = cosTheta * cosTheta;\n let denom = cosTheta + sqrt( cosTheta2 * ( 1 - a2 ) + a2 );\n return 2.0 * cosTheta / denom;\n\n }\n\n", [wn]), En = I("\n\n fn ggxSmithVisibility( NdotV: f32, NdotL: f32, alpha: f32 ) -> f32 {\n\n // Original formulation of G_SmithGGX Correlated\n // lambda_v = ( -1 + sqrt ( alphaG2 * (1 - NdotL2 ) / NdotL2 + 1)) * 0.5 f;\n // lambda_l = ( -1 + sqrt ( alphaG2 * (1 - NdotV2 ) / NdotV2 + 1)) * 0.5 f;\n // G_SmithGGXCorrelated = 1 / (1 + lambda_v + lambda_l );\n // V_SmithGGXCorrelated = G_SmithGGXCorrelated / (4.0 f * NdotL * NdotV );\n\n // This is an optimized version\n let alpha2 = alpha * alpha;\n // Caution: the \"NdotL *\" and \"NdotV *\" are explicitely inversed , this is not a mistake.\n let Lambda_GGXV = NdotL * sqrt (( - NdotV * alpha2 + NdotV ) * NdotV + alpha2 );\n let Lambda_GGXL = NdotV * sqrt (( - NdotL * alpha2 + NdotL ) * NdotL + alpha2 );\n\n return 0.5 / ( Lambda_GGXV + Lambda_GGXL );\n\n }\n\n", [wn]), Dn = I("\n fn ggxDistribution( NdotH: f32, alpha: f32 ) -> f32 {\n\n let a2 = max( alpha * alpha, EPSILON );\n let denom = NdotH * NdotH * ( a2 - 1 ) + 1;\n\n return ( a2 / ( PI * denom * denom ) );\n\n }\n"), On = I("\n fn ggxReflectionAdjustedPDF( NdotV: f32, NdotH: f32, alpha: f32 ) -> f32 {\n\n let D = ggxDistribution( NdotH, alpha );\n let G1 = ggxShadowMaskG1( NdotV, alpha );\n\n return D * G1 / ( 4 * NdotV );\n\n }\n", [Dn, Tn]), kn = (e) => I("\n\n fn getSurfaceRecord(\n material: Material,\n vertexData: bvh_GeometryStruct,\n side: f32,\n faceNormal: vec3f,\n ) -> SurfaceRecord {\n let uv = vertexData.uv.xy;\n\n var normal = faceNormal * side;\n if ( material.flatShading == 0 ) {\n\n normal = vertexData.normal.xyz;\n\n }\n normal = normalize( normal );\n let baseNormal = normal;\n\n if ( material.normalMap != -1 ) {\n\n // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate\n // resulting in NaNs and slow path tracing.\n if ( length( vertexData.tangent.xyz ) > 0.0 && vertexData.tangent.w != 0.0 ) {\n\n let tangent = normalize( vertexData.tangent.xyz );\n let bitangent = normalize( cross( baseNormal, tangent ) * vertexData.tangent.w );\n let vTBN = mat3x3f( tangent, bitangent, baseNormal );\n\n let uvPrime = material.normalMapTransform * vec3( uv, 1.0 );\n var texNormal = sampleTexel( uvPrime.xy, material.normalMap, 0 ).xyz;\n texNormal = texNormal * 2.0 - 1.0;\n texNormal = texNormal * vec3f( material.normalScale, 1.0 );\n normal = normalize( vTBN * texNormal );\n\n }\n\n }\n\n normal *= side;\n\n var albedo = vec4( material.color, material.opacity );\n\n if ( material.vertexColors == 1 ) {\n\n let vertexColor = vertexData.color.xyz;\n albedo *= vec4f( vertexColor, 1.0 );\n\n }\n\n if ( material.map != -1 ) {\n\n let uvPrime = material.mapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.map, 0 );\n albedo *= vec4f( texColor.rgb, 1.0 );\n\n }\n\n var roughness = material.roughness;\n if ( material.roughnessMap != -1 ) {\n\n let uvPrime = material.roughnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.roughnessMap, 0 );\n roughness *= texColor.g;\n\n }\n\n var metalness = material.metalness;\n if ( material.metalnessMap != -1 ) {\n\n let uvPrime = material.metalnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.metalnessMap, 0 );\n metalness *= texColor.b;\n\n }\n\n var emission = material.emissiveIntensity * material.emissive;\n if ( material.emissiveMap != -1 ) {\n\n let uvPrime = material.emissiveMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.emissiveMap, 0 );\n emission *= texColor.rgb;\n\n }\n\n var transmission = material.transmission;\n if ( material.transmissionMap != -1 ) {\n\n let uvPrime = material.transmissionMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.transmissionMap, 0 );\n transmission *= texColor.r;\n\n }\n\n var clearcoat = material.clearcoat;\n if ( material.clearcoatMap != -1 ) {\n\n let uvPrime = material.clearcoatMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.clearcoatMap, 0 );\n clearcoat *= texColor.r;\n\n }\n\n var clearcoatRoughness = material.clearcoatRoughness;\n if ( material.clearcoatRoughnessMap != -1 ) {\n\n let uvPrime = material.clearcoatRoughnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.clearcoatRoughnessMap, 0 );\n clearcoatRoughness *= texColor.g;\n\n }\n\n var clearcoatNormal = baseNormal;\n if ( material.clearcoatNormalMap != -1 ) {\n\n // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate\n // resulting in NaNs and slow path tracing.\n if ( length( vertexData.tangent.xyz ) > 0.0 && vertexData.tangent.w != 0.0 ) {\n\n let tangent = normalize( vertexData.tangent.xyz );\n let bitangent = normalize( cross( baseNormal, tangent ) * vertexData.tangent.w );\n let vTBN = mat3x3f( tangent, bitangent, baseNormal );\n\n let uvPrime = material.clearcoatNormalMapTransform * vec3( uv, 1.0 );\n var texNormal = sampleTexel( uvPrime.xy, material.clearcoatNormalMap, 0 ).xyz;\n texNormal = texNormal * 2.0 - 1.0;\n texNormal = texNormal * vec3f( material.clearcoatNormalScale, 1.0 );\n clearcoatNormal = normalize( vTBN * texNormal );\n\n }\n\n }\n clearcoatNormal *= side;\n\n var sheenColor = material.sheenColor;\n if ( material.sheenColorMap != -1 ) {\n\n let uvPrime = material.sheenColorMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.sheenColorMap, 0 );\n sheenColor *= texColor.rgb;\n\n }\n\n var sheenRoughness = material.sheenRoughness;\n if ( material.sheenRoughnessMap != -1 ) {\n\n let uvPrime = material.sheenRoughnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.sheenRoughnessMap, 0 );\n sheenRoughness *= texColor.r;\n\n }\n\n var iridescence = material.iridescence;\n if ( material.iridescenceMap != -1 ) {\n\n let uvPrime = material.iridescenceMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.iridescenceMap, 0 );\n iridescence *= texColor.r;\n\n }\n\n var iridescenceThickness = material.iridescenceThicknessMaximum;\n if ( material.iridescenceThicknessMap != -1 ) {\n\n let uvPrime = material.iridescenceThicknessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.iridescenceThicknessMap, 0 );\n\n iridescenceThickness = mix(\n material.iridescenceThicknessMinimum,\n material.iridescenceThicknessMaximum,\n texColor.g,\n );\n\n }\n\n var specularColor = material.specularColor;\n if ( material.specularColorMap != -1 ) {\n\n let uvPrime = material.specularColorMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.specularColorMap, 0 );\n specularColor *= texColor.rgb;\n\n }\n\n var specularIntensity = material.specularIntensity;\n if ( material.specularIntensityMap != -1 ) {\n\n let uvPrime = material.specularIntensityMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.specularIntensityMap, 0 );\n specularIntensity *= texColor.r;\n\n }\n\n var surf: SurfaceRecord;\n\n surf.volumeParticle = false;\n surf.faceNormal = faceNormal;\n surf.normal = normal;\n\n surf.metalness = metalness;\n surf.color = albedo.rgb;\n surf.emission = emission;\n\n surf.ior = material.ior;\n surf.transmission = transmission;\n surf.thinFilm = material.thinFilm == 1;\n surf.attenuationColor = material.attenuationColor;\n surf.attenuationDistance = material.attenuationDistance;\n\n surf.clearcoatNormal = clearcoatNormal;\n surf.clearcoat = clearcoat;\n\n surf.iridescence = iridescence;\n surf.iridescenceIor = material.iridescenceIor;\n surf.iridescenceThickness = iridescenceThickness;\n\n surf.specularColor = specularColor;\n surf.specularIntensity = specularIntensity;\n\n surf.roughness = clamp( roughness, MIN_ROUGHNESS, 1.0 );\n surf.clearcoatRoughness = clamp( clearcoatRoughness, MIN_ROUGHNESS, 1.0 );\n surf.sheenRoughness = clamp( sheenRoughness, MIN_ROUGHNESS, 1.0 );\n\n // frontFace is used to determine transmissive properties and PDF. If no transmission is used\n // then we can just always assume this is a front face.\n surf.frontFace = side == 1.0 || transmission == 0.0;\n if ( material.thinFilm == 1 || surf.frontFace ) {\n surf.eta = 1.0 / material.ior;\n } else {\n surf.eta = material.ior;\n }\n surf.f0 = iorToF0( surf.eta );\n\n // get the normal frames\n surf.normalBasis = getBasisFromNormal( surf.normal );\n surf.normalInvBasis = inverse( surf.normalBasis );\n\n surf.clearcoatBasis = getBasisFromNormal( surf.clearcoatNormal );\n surf.clearcoatInvBasis = inverse( surf.clearcoatBasis );\n\n return surf;\n }\n\n", [
|
|
2222
|
-
It,
|
|
2221
|
+
var wn = A("\n\n fn ggxDirection( incidentDir: vec3f, alpha: vec2f, uv: vec2f ) -> vec3f {\n\n // Implementation from reference [1]\n // stretch view\n let V = normalize( vec3f( alpha * incidentDir.xy, incidentDir.z ) );\n\n // orthonormal basis\n var T1: vec3f;\n if ( V.z < 0.9999 ) {\n T1 = normalize( cross( V, vec3( 0.0, 0.0, 1.0 ) ) );\n } else {\n T1 = vec3( 1.0, 0.0, 0.0 );\n }\n\n let T2 = cross( T1, V );\n\n // sample point with polar coordinates (r, phi)\n let a = 1.0 / ( 1.0 + V.z );\n let r = sqrt( uv.x );\n var phi: f32;\n if ( uv.y < a ) {\n phi = uv.y / a * PI;\n } else {\n phi = PI + ( uv.y - a ) / ( 1.0 - a ) * PI;\n }\n let P1 = r * cos( phi );\n var P2 = r * sin( phi );\n if ( uv.y >= a ) {\n P2 *= V.z;\n }\n\n // compute normal\n var N = P1 * T1 + P2 * T2 + V * sqrt( max( 0.0, 1.0 - P1 * P1 - P2 * P2 ) );\n\n // unstretch\n N = normalize( vec3( alpha * N.xy, max( 0.0, N.z ) ) );\n\n return N;\n\n }\n\n", [J]), Tn = A("\n\n fn ggxLamda( theta: f32, alpha: f32 ) -> f32 {\n\n let tanTheta = tan( theta );\n let tanTheta2 = tanTheta * tanTheta;\n let alpha2 = alpha * alpha;\n\n let numerator = - 1.0 + sqrt( 1.0 + alpha2 * tanTheta2 );\n return numerator / 2.0;\n\n }\n\n"), En = A("\n\n fn ggxShadowMaskG1( cosTheta: f32, alpha: f32 ) -> f32 {\n\n let a2 = alpha * alpha;\n let cosTheta2 = cosTheta * cosTheta;\n let denom = cosTheta + sqrt( cosTheta2 * ( 1 - a2 ) + a2 );\n return 2.0 * cosTheta / denom;\n\n }\n\n", [Tn]), Dn = A("\n\n fn ggxSmithVisibility( NdotV: f32, NdotL: f32, alpha: f32 ) -> f32 {\n\n // Original formulation of G_SmithGGX Correlated\n // lambda_v = ( -1 + sqrt ( alphaG2 * (1 - NdotL2 ) / NdotL2 + 1)) * 0.5 f;\n // lambda_l = ( -1 + sqrt ( alphaG2 * (1 - NdotV2 ) / NdotV2 + 1)) * 0.5 f;\n // G_SmithGGXCorrelated = 1 / (1 + lambda_v + lambda_l );\n // V_SmithGGXCorrelated = G_SmithGGXCorrelated / (4.0 f * NdotL * NdotV );\n\n // This is an optimized version\n let alpha2 = alpha * alpha;\n // Caution: the \"NdotL *\" and \"NdotV *\" are explicitely inversed , this is not a mistake.\n let Lambda_GGXV = NdotL * sqrt (( - NdotV * alpha2 + NdotV ) * NdotV + alpha2 );\n let Lambda_GGXL = NdotV * sqrt (( - NdotL * alpha2 + NdotL ) * NdotL + alpha2 );\n\n return 0.5 / ( Lambda_GGXV + Lambda_GGXL );\n\n }\n\n", [Tn]), On = A("\n fn ggxDistribution( NdotH: f32, alpha: f32 ) -> f32 {\n\n let a2 = max( alpha * alpha, EPSILON );\n let denom = NdotH * NdotH * ( a2 - 1 ) + 1;\n\n return ( a2 / ( PI * denom * denom ) );\n\n }\n"), kn = A("\n fn ggxReflectionAdjustedPDF( NdotV: f32, NdotH: f32, alpha: f32 ) -> f32 {\n\n let D = ggxDistribution( NdotH, alpha );\n let G1 = ggxShadowMaskG1( NdotV, alpha );\n\n return D * G1 / ( 4 * NdotV );\n\n }\n", [On, En]), An = (e) => A("\n\n fn getSurfaceRecord(\n material: Material,\n vertexData: bvh_GeometryStruct,\n side: f32,\n faceNormal: vec3f,\n ) -> SurfaceRecord {\n let uv = vertexData.uv.xy;\n\n var normal = faceNormal * side;\n if ( material.flatShading == 0 ) {\n\n normal = vertexData.normal.xyz;\n\n }\n normal = normalize( normal );\n let baseNormal = normal;\n\n if ( material.normalMap != -1 ) {\n\n // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate\n // resulting in NaNs and slow path tracing.\n if ( length( vertexData.tangent.xyz ) > 0.0 && vertexData.tangent.w != 0.0 ) {\n\n let tangent = normalize( vertexData.tangent.xyz );\n let bitangent = normalize( cross( baseNormal, tangent ) * vertexData.tangent.w );\n let vTBN = mat3x3f( tangent, bitangent, baseNormal );\n\n let uvPrime = material.normalMapTransform * vec3( uv, 1.0 );\n var texNormal = sampleTexel( uvPrime.xy, material.normalMap, 0 ).xyz;\n texNormal = texNormal * 2.0 - 1.0;\n texNormal = texNormal * vec3f( material.normalScale, 1.0 );\n normal = normalize( vTBN * texNormal );\n\n }\n\n }\n\n normal *= side;\n\n var albedo = vec4( material.color, material.opacity );\n\n if ( material.vertexColors == 1 ) {\n\n let vertexColor = vertexData.color.xyz;\n albedo *= vec4f( vertexColor, 1.0 );\n\n }\n\n if ( material.map != -1 ) {\n\n let uvPrime = material.mapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.map, 0 );\n albedo *= vec4f( texColor.rgb, 1.0 );\n\n }\n\n var roughness = material.roughness;\n if ( material.roughnessMap != -1 ) {\n\n let uvPrime = material.roughnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.roughnessMap, 0 );\n roughness *= texColor.g;\n\n }\n\n var metalness = material.metalness;\n if ( material.metalnessMap != -1 ) {\n\n let uvPrime = material.metalnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.metalnessMap, 0 );\n metalness *= texColor.b;\n\n }\n\n var emission = material.emissiveIntensity * material.emissive;\n if ( material.emissiveMap != -1 ) {\n\n let uvPrime = material.emissiveMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.emissiveMap, 0 );\n emission *= texColor.rgb;\n\n }\n\n var transmission = material.transmission;\n if ( material.transmissionMap != -1 ) {\n\n let uvPrime = material.transmissionMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.transmissionMap, 0 );\n transmission *= texColor.r;\n\n }\n\n var clearcoat = material.clearcoat;\n if ( material.clearcoatMap != -1 ) {\n\n let uvPrime = material.clearcoatMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.clearcoatMap, 0 );\n clearcoat *= texColor.r;\n\n }\n\n var clearcoatRoughness = material.clearcoatRoughness;\n if ( material.clearcoatRoughnessMap != -1 ) {\n\n let uvPrime = material.clearcoatRoughnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.clearcoatRoughnessMap, 0 );\n clearcoatRoughness *= texColor.g;\n\n }\n\n var clearcoatNormal = baseNormal;\n if ( material.clearcoatNormalMap != -1 ) {\n\n // some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate\n // resulting in NaNs and slow path tracing.\n if ( length( vertexData.tangent.xyz ) > 0.0 && vertexData.tangent.w != 0.0 ) {\n\n let tangent = normalize( vertexData.tangent.xyz );\n let bitangent = normalize( cross( baseNormal, tangent ) * vertexData.tangent.w );\n let vTBN = mat3x3f( tangent, bitangent, baseNormal );\n\n let uvPrime = material.clearcoatNormalMapTransform * vec3( uv, 1.0 );\n var texNormal = sampleTexel( uvPrime.xy, material.clearcoatNormalMap, 0 ).xyz;\n texNormal = texNormal * 2.0 - 1.0;\n texNormal = texNormal * vec3f( material.clearcoatNormalScale, 1.0 );\n clearcoatNormal = normalize( vTBN * texNormal );\n\n }\n\n }\n clearcoatNormal *= side;\n\n var sheenColor = material.sheenColor;\n if ( material.sheenColorMap != -1 ) {\n\n let uvPrime = material.sheenColorMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.sheenColorMap, 0 );\n sheenColor *= texColor.rgb;\n\n }\n\n var sheenRoughness = material.sheenRoughness;\n if ( material.sheenRoughnessMap != -1 ) {\n\n let uvPrime = material.sheenRoughnessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.sheenRoughnessMap, 0 );\n sheenRoughness *= texColor.r;\n\n }\n\n var iridescence = material.iridescence;\n if ( material.iridescenceMap != -1 ) {\n\n let uvPrime = material.iridescenceMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.iridescenceMap, 0 );\n iridescence *= texColor.r;\n\n }\n\n var iridescenceThickness = material.iridescenceThicknessMaximum;\n if ( material.iridescenceThicknessMap != -1 ) {\n\n let uvPrime = material.iridescenceThicknessMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.iridescenceThicknessMap, 0 );\n\n iridescenceThickness = mix(\n material.iridescenceThicknessMinimum,\n material.iridescenceThicknessMaximum,\n texColor.g,\n );\n\n }\n\n var specularColor = material.specularColor;\n if ( material.specularColorMap != -1 ) {\n\n let uvPrime = material.specularColorMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.specularColorMap, 0 );\n specularColor *= texColor.rgb;\n\n }\n\n var specularIntensity = material.specularIntensity;\n if ( material.specularIntensityMap != -1 ) {\n\n let uvPrime = material.specularIntensityMapTransform * vec3f( uv, 1 );\n let texColor = sampleTexel( uvPrime.xy, material.specularIntensityMap, 0 );\n specularIntensity *= texColor.r;\n\n }\n\n var surf: SurfaceRecord;\n\n surf.volumeParticle = false;\n surf.faceNormal = faceNormal;\n surf.normal = normal;\n\n surf.metalness = metalness;\n surf.color = albedo.rgb;\n surf.emission = emission;\n\n surf.ior = material.ior;\n surf.transmission = transmission;\n surf.thinFilm = material.thinFilm == 1;\n surf.attenuationColor = material.attenuationColor;\n surf.attenuationDistance = material.attenuationDistance;\n\n surf.clearcoatNormal = clearcoatNormal;\n surf.clearcoat = clearcoat;\n\n surf.iridescence = iridescence;\n surf.iridescenceIor = material.iridescenceIor;\n surf.iridescenceThickness = iridescenceThickness;\n\n surf.specularColor = specularColor;\n surf.specularIntensity = specularIntensity;\n\n surf.roughness = clamp( roughness, MIN_ROUGHNESS, 1.0 );\n surf.clearcoatRoughness = clamp( clearcoatRoughness, MIN_ROUGHNESS, 1.0 );\n surf.sheenRoughness = clamp( sheenRoughness, MIN_ROUGHNESS, 1.0 );\n\n // frontFace is used to determine transmissive properties and PDF. If no transmission is used\n // then we can just always assume this is a front face.\n surf.frontFace = side == 1.0 || transmission == 0.0;\n if ( material.thinFilm == 1 || surf.frontFace ) {\n surf.eta = 1.0 / material.ior;\n } else {\n surf.eta = material.ior;\n }\n surf.f0 = iorToF0( surf.eta );\n\n // get the normal frames\n surf.normalBasis = getBasisFromNormal( surf.normal );\n surf.normalInvBasis = inverse( surf.normalBasis );\n\n surf.clearcoatBasis = getBasisFromNormal( surf.clearcoatNormal );\n surf.clearcoatInvBasis = inverse( surf.clearcoatBasis );\n\n return surf;\n }\n\n", [
|
|
2223
2222
|
Rt,
|
|
2224
|
-
Lt,
|
|
2225
|
-
e,
|
|
2226
|
-
Mt,
|
|
2227
|
-
X
|
|
2228
|
-
]), An = I("\n\n fn diffuseBrdf( NdotV: f32, NdotL: f32, VdotH: f32, surf: SurfaceRecord ) -> vec3f {\n\n // https://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf\n // See equation (4)\n\n let fl = schlickFresnel( NdotL, 0.0 );\n let fv = schlickFresnel( NdotV, 0.0 );\n\n let alpha = surf.roughness * surf.roughness;\n let bias = mix( 0.0, 0.5, alpha ) - 1;\n let energyFactor = mix( 1.0, 1.0 / 1.51, alpha );\n\n let rr = 2.0 * alpha * VdotH * VdotH;\n let retro = rr * ( fl + fv + fl * fv * ( rr + 2.0 * bias ) );\n let fresnel = ( 1.0 + bias * fl ) * ( 1.0f + bias * fv );\n\n // TODO: subsurface approx?\n\n return energyFactor * ( surf.color / PI ) * ( retro + fresnel );\n\n }\n\n", [
|
|
2229
|
-
X,
|
|
2230
|
-
Ht,
|
|
2231
|
-
Mt
|
|
2232
|
-
]), jn = I("\n\n fn specularBrdf( NdotL: f32, NdotV: f32, NdotH: f32, alpha: f32 ) -> vec3f {\n\n let Vis = ggxSmithVisibility( NdotV, NdotL, alpha );\n let D = ggxDistribution( NdotH, alpha );\n\n return vec3f( D * Vis );\n\n }\n\n", [En, Dn]), Mn = I("\n\n fn fresnelMix( VdotH: f32, ior: f32, base: vec3f, layer: vec3f ) -> vec3f {\n\n let f0 = iorToF0( ior );\n let F = schlickFresnel( abs( VdotH ), f0 );\n\n return base + F * layer;\n\n }\n\n", [Ht, Rt]), Nn = Oe(3.2404542, -.969266, .0556434, -1.5371385, 1.8760108, -.2040259, -.4985314, .041556, 1.0572252), Pn = I("\n\n fn iridescentFresnel(\n cosTheta1: f32, baseF0: vec3f, iridescenceIor: f32,\n outsideIor: f32, iridescenceThickness: f32,\n ) -> vec3f {\n\n let sinTheta2Sq = pow( outsideIor / iridescenceIor, 2.0 ) * ( 1.0 - pow( cosTheta1, 2.0 ) );\n let cosTheta2Sq = 1.0 - sinTheta2Sq;\n\n // Handle total internal reflection\n if ( cosTheta2Sq < 0.0 ) {\n\n return vec3( 1.0 );\n\n }\n\n let cosTheta2 = sqrt( cosTheta2Sq );\n\n // First interface: air -> iridescent thin film\n let R0 = iorToF0General( iridescenceIor, outsideIor );\n let R12 = schlickFresnel( cosTheta1, R0 );\n let R21 = R12;\n let T121 = 1.0 - R12;\n let phi12 = select( 0.0, PI, iridescenceIor < outsideIor );\n let phi21 = PI - phi12;\n\n // Second interface: iridescent thin film -> base material\n let baseIor = fresnel0ToIor( baseF0 + 0.0001 ); // guard against 1.0\n let R1 = iorToF0GeneralVec( baseIor, vec3( iridescenceIor ) );\n let R23 = schlickFresnelVec( cosTheta2, R1, vec3( 1.0 ) );\n let phi23 = select( vec3( 0.0 ), vec3( PI ), baseIor < vec3( iridescenceIor ) );\n\n // Phase shift\n let OPD = 2.0 * iridescenceIor * iridescenceThickness * cosTheta2;\n let phi = vec3( phi21 ) + phi23;\n\n // Analytical integration\n // Compound terms\n let R123 = clamp( R12 * R23, vec3( 1e-5 ), vec3( 0.9999 ) );\n let r123 = sqrt( R123 );\n let Rs = T121 * T121 * R23 / ( vec3( 1.0 ) - R123 );\n\n // Reflectance term for m = 0 (DC term amplitude)\n let C0 = R12 + Rs;\n var I = C0;\n\n // Reflectance term for m > 0 (pairs of diracs)\n var Cm = Rs - T121;\n for (var m = 1; m <= 2; m += 1) {\n\n Cm *= r123;\n let Sm = 2.0 * evalSensitivity( f32( m ) * OPD, f32( m ) * phi );\n I += Cm * Sm;\n\n }\n\n return max( I, vec3(0.0) );\n\n }\n\n", [
|
|
2233
|
-
zt,
|
|
2234
2223
|
Bt,
|
|
2235
|
-
|
|
2224
|
+
zt,
|
|
2225
|
+
e,
|
|
2226
|
+
Pt,
|
|
2227
|
+
J
|
|
2228
|
+
]), jn = A("\n\n fn diffuseBrdf( NdotV: f32, NdotL: f32, VdotH: f32, surf: SurfaceRecord ) -> vec3f {\n\n // https://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf\n // See equation (4)\n\n let fl = schlickFresnel( NdotL, 0.0 );\n let fv = schlickFresnel( NdotV, 0.0 );\n\n let alpha = surf.roughness * surf.roughness;\n let bias = mix( 0.0, 0.5, alpha ) - 1;\n let energyFactor = mix( 1.0, 1.0 / 1.51, alpha );\n\n let rr = 2.0 * alpha * VdotH * VdotH;\n let retro = rr * ( fl + fv + fl * fv * ( rr + 2.0 * bias ) );\n let fresnel = ( 1.0 + bias * fl ) * ( 1.0f + bias * fv );\n\n // TODO: subsurface approx?\n\n return energyFactor * ( surf.color / PI ) * ( retro + fresnel );\n\n }\n\n", [
|
|
2229
|
+
J,
|
|
2230
|
+
Y,
|
|
2231
|
+
Pt
|
|
2232
|
+
]), Mn = A("\n\n fn specularBrdf( NdotL: f32, NdotV: f32, NdotH: f32, alpha: f32 ) -> vec3f {\n\n let Vis = ggxSmithVisibility( NdotV, NdotL, alpha );\n let D = ggxDistribution( NdotH, alpha );\n\n return vec3f( D * Vis );\n\n }\n\n", [Dn, On]), Nn = A("\n\n fn fresnelMix( VdotH: f32, ior: f32, base: vec3f, layer: vec3f ) -> vec3f {\n\n let f0 = iorToF0( ior );\n let F = schlickFresnel( abs( VdotH ), f0 );\n\n return base + F * layer;\n\n }\n\n", [Y, Bt]), Pn = Ce(3.2404542, -.969266, .0556434, -1.5371385, 1.8760108, -.2040259, -.4985314, .041556, 1.0572252), Fn = A("\n\n fn iridescentFresnel(\n cosTheta1: f32, baseF0: vec3f, iridescenceIor: f32,\n outsideIor: f32, iridescenceThickness: f32,\n ) -> vec3f {\n\n let sinTheta2Sq = pow( outsideIor / iridescenceIor, 2.0 ) * ( 1.0 - pow( cosTheta1, 2.0 ) );\n let cosTheta2Sq = 1.0 - sinTheta2Sq;\n\n // Handle total internal reflection\n if ( cosTheta2Sq < 0.0 ) {\n\n return vec3( 1.0 );\n\n }\n\n let cosTheta2 = sqrt( cosTheta2Sq );\n\n // First interface: air -> iridescent thin film\n let R0 = iorToF0General( iridescenceIor, outsideIor );\n let R12 = schlickFresnel( cosTheta1, R0 );\n let R21 = R12;\n let T121 = 1.0 - R12;\n let phi12 = select( 0.0, PI, iridescenceIor < outsideIor );\n let phi21 = PI - phi12;\n\n // Second interface: iridescent thin film -> base material\n let baseIor = fresnel0ToIor( baseF0 + 0.0001 ); // guard against 1.0\n let R1 = iorToF0GeneralVec( baseIor, vec3( iridescenceIor ) );\n let R23 = schlickFresnelVec( cosTheta2, R1, vec3( 1.0 ) );\n let phi23 = select( vec3( 0.0 ), vec3( PI ), baseIor < vec3( iridescenceIor ) );\n\n // Phase shift\n let OPD = 2.0 * iridescenceIor * iridescenceThickness * cosTheta2;\n let phi = vec3( phi21 ) + phi23;\n\n // Analytical integration\n // Compound terms\n let R123 = clamp( R12 * R23, vec3( 1e-5 ), vec3( 0.9999 ) );\n let r123 = sqrt( R123 );\n let Rs = T121 * T121 * R23 / ( vec3( 1.0 ) - R123 );\n\n // Reflectance term for m = 0 (DC term amplitude)\n let C0 = R12 + Rs;\n var I = C0;\n\n // Reflectance term for m > 0 (pairs of diracs)\n var Cm = Rs - T121;\n for (var m = 1; m <= 2; m += 1) {\n\n Cm *= r123;\n let Sm = 2.0 * evalSensitivity( f32( m ) * OPD, f32( m ) * phi );\n I += Cm * Sm;\n\n }\n\n return max( I, vec3(0.0) );\n\n }\n\n", [
|
|
2236
2233
|
Vt,
|
|
2237
|
-
|
|
2234
|
+
Ht,
|
|
2235
|
+
Y,
|
|
2236
|
+
Ut,
|
|
2237
|
+
H`
|
|
2238
2238
|
|
|
2239
2239
|
fn evalSensitivity( OPD: f32, shift: vec3f ) -> vec3f {
|
|
2240
2240
|
|
|
@@ -2247,17 +2247,17 @@ var Cn = I("\n\n fn ggxDirection( incidentDir: vec3f, alpha: vec2f, uv: vec2f )
|
|
|
2247
2247
|
xyz.x += 9.7470e-14 * sqrt(2.0 * ${Math.PI} * 4.5282e+09) * cos(2.2399e+06 * phase + shift.x) * exp(-4.5282e+09 * phase * phase);
|
|
2248
2248
|
xyz /= 1.0685e-7;
|
|
2249
2249
|
|
|
2250
|
-
let rgb = ${
|
|
2250
|
+
let rgb = ${Pn} * xyz;
|
|
2251
2251
|
return rgb;
|
|
2252
2252
|
|
|
2253
2253
|
}
|
|
2254
2254
|
|
|
2255
2255
|
`
|
|
2256
|
-
]),
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
]),
|
|
2256
|
+
]), In = A("\n\n fn iridescentDielectricLayer(\n dielectricBase: vec3f, base: vec3f, specular: vec3f, HdotL: f32,\n outsideIor: f32, baseIor: f32, iridescenceIor: f32, thickness: f32, strength: f32,\n ) -> vec3f {\n\n let baseF0 = vec3( iorToF0( baseIor ) );\n\n let iridescentF = iridescentFresnel( HdotL, baseF0, iridescenceIor, outsideIor, thickness );\n\n return mix( dielectricBase, rgbMix( base, specular, iridescentF ), strength );\n\n }\n\n", [
|
|
2257
|
+
Bt,
|
|
2258
|
+
Fn,
|
|
2259
|
+
A("\n\n fn rgbMix( base: vec3f, specular: vec3f, rgbAlpha: vec3f ) -> vec3f {\n\n let alphaMax = max( max( rgbAlpha.x, rgbAlpha.y ), rgbAlpha.z );\n return ( 1 - alphaMax ) * base + rgbAlpha * specular;\n\n }\n\n")
|
|
2260
|
+
]), Ln = A("\n\n fn iridescentConductorLayer(\n metalBase: vec3f, specular: vec3f, baseF0: vec3f, HdotL: f32,\n outsideIor: f32, iridescenceIor: f32, thickness: f32, strength: f32,\n ) -> vec3f {\n\n let iridescenceF = iridescentFresnel( HdotL, baseF0, iridescenceIor, outsideIor, thickness );\n\n return mix( metalBase, specular * iridescenceF, strength );\n\n }\n\n", [Fn]), Rn = (e) => A("\n\n fn conductorFresnel( NdotV: f32, VdotH: f32, f0: vec3f, bsdf: vec3f, alpha: f32 ) -> vec3f {\n\n let ss = bsdf * schlickFresnelVec( abs( VdotH ), f0, vec3f( 1 ) );\n\n let uv = vec2( NdotV, sqrt( alpha ) );\n let energySs = max( textureSampleLevel( turquinTexture, turquinTexture_sampler, uv, 0 ).r, 1e-5 );\n\n return ss * ( 1.0 + f0 * ( 1.0 - energySs ) / energySs );\n\n }\n\n", [Wt, e]), zn = A("\n\n fn fresnelCoat( VdotNc: f32, ior: f32, base: vec3f, layer: vec3f, weight: f32 ) -> vec3f {\n\n let f0 = iorToF0( ior );\n let F = schlickFresnel( abs( VdotNc ), f0 );\n\n return mix( base, layer, weight * F );\n\n }\n\n", [Bt, Y]), Bn = H`
|
|
2261
2261
|
|
|
2262
2262
|
fn albedo(
|
|
2263
2263
|
texture: texture_storage_2d<r16float, write>,
|
|
@@ -2267,7 +2267,7 @@ var Cn = I("\n\n fn ggxDirection( incidentDir: vec3f, alpha: vec2f, uv: vec2f )
|
|
|
2267
2267
|
|
|
2268
2268
|
const INTEGRATION_SAMPLES = ( 1 << 20 );
|
|
2269
2269
|
let pixelIndex = ( globalId.x << 16 ) | globalId.y;
|
|
2270
|
-
${
|
|
2270
|
+
${At}( pixelIndex, 0, 0 );
|
|
2271
2271
|
|
|
2272
2272
|
let dimensions = textureDimensions( texture ).xy;
|
|
2273
2273
|
let uv = ( vec2f( globalId.xy ) + vec2f( 0.5 ) ) / vec2f( dimensions );
|
|
@@ -2282,15 +2282,15 @@ var Cn = I("\n\n fn ggxDirection( incidentDir: vec3f, alpha: vec2f, uv: vec2f )
|
|
|
2282
2282
|
var result = 0.0;
|
|
2283
2283
|
for ( var i = 0; i < INTEGRATION_SAMPLES; i++ ) {
|
|
2284
2284
|
|
|
2285
|
-
let wh = ${
|
|
2285
|
+
let wh = ${wn}( wo, vec2( alpha ), ${q}(${3}) );
|
|
2286
2286
|
var wi = - reflect( wo, wh );
|
|
2287
2287
|
|
|
2288
2288
|
let NdotV = max( wo.z, EPSILON );
|
|
2289
2289
|
let NdotL = saturate( wi.z );
|
|
2290
2290
|
let NdotH = saturate( wh.z );
|
|
2291
2291
|
|
|
2292
|
-
let specular = ${
|
|
2293
|
-
let pdf = ${
|
|
2292
|
+
let specular = ${Mn}( NdotL, NdotV, NdotH, alpha );
|
|
2293
|
+
let pdf = ${kn}( NdotV, NdotH, alpha );
|
|
2294
2294
|
|
|
2295
2295
|
var weight = 0.0;
|
|
2296
2296
|
if ( pdf != 0.0 ) {
|
|
@@ -2307,11 +2307,11 @@ var Cn = I("\n\n fn ggxDirection( incidentDir: vec3f, alpha: vec2f, uv: vec2f )
|
|
|
2307
2307
|
|
|
2308
2308
|
}
|
|
2309
2309
|
|
|
2310
|
-
`,
|
|
2311
|
-
function
|
|
2310
|
+
`, Vn = 4096, Hn = new oe();
|
|
2311
|
+
function Un(e) {
|
|
2312
2312
|
return `${e.source.uuid}:${e.source.version}`;
|
|
2313
2313
|
}
|
|
2314
|
-
function
|
|
2314
|
+
function Wn(e, t, n, r) {
|
|
2315
2315
|
if (e[t].x + n > r) return -1;
|
|
2316
2316
|
let i = n, a = 0, o = t;
|
|
2317
2317
|
for (; i > 0;) {
|
|
@@ -2320,7 +2320,7 @@ function Un(e, t, n, r) {
|
|
|
2320
2320
|
}
|
|
2321
2321
|
return a;
|
|
2322
2322
|
}
|
|
2323
|
-
function
|
|
2323
|
+
function Gn(e, t, n, r) {
|
|
2324
2324
|
let i = t + r, a = [], o = !1;
|
|
2325
2325
|
for (let s = 0; s < e.length; s++) {
|
|
2326
2326
|
let c = e[s], l = c.x + c.width;
|
|
@@ -2348,18 +2348,18 @@ function Wn(e, t, n, r) {
|
|
|
2348
2348
|
r && r.y === n.y && r.x + r.width === n.x ? r.width += n.width : e.push(n);
|
|
2349
2349
|
}
|
|
2350
2350
|
}
|
|
2351
|
-
function
|
|
2351
|
+
function Kn(e, t, n, r, i) {
|
|
2352
2352
|
let a = Infinity, o = 0, s = -1;
|
|
2353
2353
|
for (let c = 0; c < e.length; c++) {
|
|
2354
|
-
let l =
|
|
2354
|
+
let l = Wn(e, c, t, r);
|
|
2355
2355
|
l >= 0 && l + n <= i && l < a && (a = l, o = e[c].x, s = c);
|
|
2356
2356
|
}
|
|
2357
|
-
return s === -1 ? null : (
|
|
2357
|
+
return s === -1 ? null : (Gn(e, o, a + n, t), {
|
|
2358
2358
|
x: o,
|
|
2359
2359
|
y: a
|
|
2360
2360
|
});
|
|
2361
2361
|
}
|
|
2362
|
-
var
|
|
2362
|
+
var qn = class {
|
|
2363
2363
|
get width() {
|
|
2364
2364
|
return this.renderTarget.width;
|
|
2365
2365
|
}
|
|
@@ -2373,20 +2373,20 @@ var Kn = class {
|
|
|
2373
2373
|
return this.renderTarget.texture;
|
|
2374
2374
|
}
|
|
2375
2375
|
constructor(e = {}) {
|
|
2376
|
-
this.renderTarget = new
|
|
2376
|
+
this.renderTarget = new l(1, 1, {
|
|
2377
2377
|
depthBuffer: !1,
|
|
2378
2378
|
depth: 1,
|
|
2379
2379
|
...e
|
|
2380
|
-
}), this.texture.isArrayTexture = !0, this.textureInfo = [new
|
|
2380
|
+
}), this.texture.isArrayTexture = !0, this.textureInfo = [new r()], this.hashes = [], this.quadMesh = new he(new ae()), this.quadMesh.material.blending = 0;
|
|
2381
2381
|
}
|
|
2382
2382
|
setTextures(e, t) {
|
|
2383
2383
|
if (this._hashesMatch(t)) return;
|
|
2384
2384
|
let n = t.reduce((e, t) => Math.max(e, t.width, t.height), 1);
|
|
2385
|
-
n = Math.min(
|
|
2385
|
+
n = Math.min(Vn, n);
|
|
2386
2386
|
let r = n, i = n, { renderTarget: a } = this, { placements: o, pageCount: s } = this._packTextures(t, r, i);
|
|
2387
2387
|
a.setSize(r, i, s), this.texture.isArrayTexture = !0, this._buildTextureInfo(o), this._renderTextures(e, t, o);
|
|
2388
2388
|
let c = Array(t.length);
|
|
2389
|
-
for (let e = 0, n = t.length; e < n; e++) c[e] =
|
|
2389
|
+
for (let e = 0, n = t.length; e < n; e++) c[e] = Un(t[e]);
|
|
2390
2390
|
this.hashes = c;
|
|
2391
2391
|
}
|
|
2392
2392
|
dispose() {
|
|
@@ -2395,7 +2395,7 @@ var Kn = class {
|
|
|
2395
2395
|
_hashesMatch(e) {
|
|
2396
2396
|
let t = this.hashes;
|
|
2397
2397
|
if (t.length !== e.length) return !1;
|
|
2398
|
-
for (let n = 0, r = e.length; n < r; n++) if (t[n] !==
|
|
2398
|
+
for (let n = 0, r = e.length; n < r; n++) if (t[n] !== Un(e[n])) return !1;
|
|
2399
2399
|
return !0;
|
|
2400
2400
|
}
|
|
2401
2401
|
_packTextures(e, t, n) {
|
|
@@ -2411,7 +2411,7 @@ var Kn = class {
|
|
|
2411
2411
|
let i = r.sort((e, t) => t.h - e.h), a = Array(e.length), o = [];
|
|
2412
2412
|
for (let e = 0, r = i.length; e < r; e++) {
|
|
2413
2413
|
let r = i[e], s = null, c = -1;
|
|
2414
|
-
for (let e = 0; e < o.length; e++) if (s =
|
|
2414
|
+
for (let e = 0; e < o.length; e++) if (s = Kn(o[e], r.w, r.h, t, n), s) {
|
|
2415
2415
|
c = e;
|
|
2416
2416
|
break;
|
|
2417
2417
|
}
|
|
@@ -2421,7 +2421,7 @@ var Kn = class {
|
|
|
2421
2421
|
y: 0,
|
|
2422
2422
|
width: t
|
|
2423
2423
|
}];
|
|
2424
|
-
s =
|
|
2424
|
+
s = Kn(e, r.w, r.h, t, n), o.push(e), c = o.length - 1;
|
|
2425
2425
|
}
|
|
2426
2426
|
a[r.index] = {
|
|
2427
2427
|
x: s.x,
|
|
@@ -2439,23 +2439,23 @@ var Kn = class {
|
|
|
2439
2439
|
_buildTextureInfo(e) {
|
|
2440
2440
|
let t = this.textureInfo;
|
|
2441
2441
|
t.length = 0;
|
|
2442
|
-
for (let n = 0,
|
|
2443
|
-
let { x:
|
|
2444
|
-
|
|
2442
|
+
for (let n = 0, i = e.length; n < i; n++) {
|
|
2443
|
+
let { x: i, y: a, w: o, h: s, page: c } = e[n], l = new r();
|
|
2444
|
+
l.x = i & 65535 | (a & 65535) << 16, l.y = o & 65535 | (s & 65535) << 16, l.z = c & 65535, l.w = 0, t.push(l);
|
|
2445
2445
|
}
|
|
2446
|
-
t.length === 0 && t.push(new
|
|
2446
|
+
t.length === 0 && t.push(new r(0, 0, 0, 0));
|
|
2447
2447
|
}
|
|
2448
2448
|
_renderTextures(e, t, n) {
|
|
2449
2449
|
let { quadMesh: r, renderTarget: i, width: a, height: o } = this, s = e.getRenderTarget(), c = e.toneMapping, l = e.autoClear, u = e.getScissorTest(), d = e.getClearAlpha();
|
|
2450
|
-
e.getClearColor(
|
|
2450
|
+
e.getClearColor(Hn), e.toneMapping = 0, e.autoClear = !1, e.setScissorTest(!0), e.setClearColor(0, 0);
|
|
2451
2451
|
for (let t = 0, n = i.depth; t < n; t++) i.viewport.set(0, 0, a, o), i.scissor.set(0, 0, a, o), e.setRenderTarget(i, t), e.clear();
|
|
2452
2452
|
for (let a = 0, o = t.length; a < o; a++) {
|
|
2453
2453
|
let { x: o, y: s, w: c, h: l, page: u } = n[a], d = t[a].clone();
|
|
2454
2454
|
d.matrixAutoUpdate = !1, d.matrix.identity(), d.needsUpdate = !0, r.material.map = d, i.viewport.set(o, s, c, l), i.scissor.set(o, s, c, l), e.setRenderTarget(i, u), r.render(e), d.dispose();
|
|
2455
2455
|
}
|
|
2456
|
-
i.viewport.set(0, 0, a, o), i.scissor.set(0, 0, a, o), r.material.map = null, e.setClearColor(
|
|
2456
|
+
i.viewport.set(0, 0, a, o), i.scissor.set(0, 0, a, o), r.material.map = null, e.setClearColor(Hn, d), e.setScissorTest(u), e.autoClear = l, e.setRenderTarget(s), e.toneMapping = c;
|
|
2457
2457
|
}
|
|
2458
|
-
},
|
|
2458
|
+
}, Jn = new r(), Yn = new E({
|
|
2459
2459
|
matrixWorld: "mat4x4f",
|
|
2460
2460
|
inverseMatrixWorld: "mat4x4f",
|
|
2461
2461
|
nodeOffset: "uint",
|
|
@@ -2463,7 +2463,7 @@ var Kn = class {
|
|
|
2463
2463
|
materialIndex: "uint",
|
|
2464
2464
|
_alignment0: "uint",
|
|
2465
2465
|
color: "vec4f"
|
|
2466
|
-
}, "TransformStruct"),
|
|
2466
|
+
}, "TransformStruct"), Xn = class extends dt {
|
|
2467
2467
|
constructor(e, t = {}) {
|
|
2468
2468
|
super(e, {
|
|
2469
2469
|
attributes: {
|
|
@@ -2474,25 +2474,25 @@ var Kn = class {
|
|
|
2474
2474
|
uv: "vec4f"
|
|
2475
2475
|
},
|
|
2476
2476
|
...t
|
|
2477
|
-
}), this.structs.transform =
|
|
2477
|
+
}), this.structs.transform = Yn, this.structs.material = Nt, this.storage.materials = null, this.materials = [], this.bvhMap = /* @__PURE__ */ new Map(), this.textureAtlas = new qn();
|
|
2478
2478
|
}
|
|
2479
2479
|
useTransparencyRaycastFn() {
|
|
2480
|
-
let { textureAtlas: e, storage: t, structs: n, fns: r } = this, i = e.texture, a =
|
|
2481
|
-
r.getSurfaceRecord =
|
|
2482
|
-
let o = new
|
|
2480
|
+
let { textureAtlas: e, storage: t, structs: n, fns: r } = this, i = e.texture, a = Jt(Ee(e.textureInfo, "uvec4"), M(i), P(i));
|
|
2481
|
+
r.getSurfaceRecord = An(a);
|
|
2482
|
+
let o = new pe(n.material).toVar("bvh_material"), s = F(1).toVar("bvh_rayScalar"), c = F(1).toVar("bvh_baseOpacity");
|
|
2483
2483
|
r.raycastFirstHit = this.getShapecastFn({
|
|
2484
2484
|
name: "raycastFirstHit",
|
|
2485
|
-
shapeStruct:
|
|
2486
|
-
resultStruct:
|
|
2487
|
-
boundsOrderFn:
|
|
2488
|
-
fn getBoundsOrder( ray: ${
|
|
2485
|
+
shapeStruct: I,
|
|
2486
|
+
resultStruct: L,
|
|
2487
|
+
boundsOrderFn: H`
|
|
2488
|
+
fn getBoundsOrder( ray: ${I}, splitAxis: u32, node: ${Me} ) -> bool {
|
|
2489
2489
|
|
|
2490
2490
|
return ray.direction[ splitAxis ] >= 0.0;
|
|
2491
2491
|
|
|
2492
2492
|
}
|
|
2493
2493
|
`,
|
|
2494
|
-
intersectsBoundsFn:
|
|
2495
|
-
fn rayIntersectsBounds( ray: ${
|
|
2494
|
+
intersectsBoundsFn: H`
|
|
2495
|
+
fn rayIntersectsBounds( ray: ${I}, bounds: ${je}, result: ptr<function, ${L}> ) -> u32 {
|
|
2496
2496
|
|
|
2497
2497
|
// early-out if our object is completely transparent
|
|
2498
2498
|
if ( ${c} == 0.0 ) {
|
|
@@ -2532,8 +2532,8 @@ var Kn = class {
|
|
|
2532
2532
|
}
|
|
2533
2533
|
|
|
2534
2534
|
`,
|
|
2535
|
-
intersectRangeFn:
|
|
2536
|
-
fn intersectRange( ray: ${
|
|
2535
|
+
intersectRangeFn: H`
|
|
2536
|
+
fn intersectRange( ray: ${I}, offset: u32, count: u32, result: ptr<function, ${L}> ) -> bool {
|
|
2537
2537
|
|
|
2538
2538
|
var didHit = false;
|
|
2539
2539
|
for ( var ti = offset; ti < offset + count; ti = ti + 1u ) {
|
|
@@ -2546,7 +2546,7 @@ var Kn = class {
|
|
|
2546
2546
|
let b = ${t.attributes}[ i1 ].position.xyz;
|
|
2547
2547
|
let c = ${t.attributes}[ i2 ].position.xyz;
|
|
2548
2548
|
|
|
2549
|
-
var triResult = ${
|
|
2549
|
+
var triResult = ${rt}( ray, a, b, c, 1e-5 );
|
|
2550
2550
|
triResult.dist *= ${s};
|
|
2551
2551
|
if ( triResult.didHit && ( ! result.didHit || triResult.dist < result.dist ) ) {
|
|
2552
2552
|
|
|
@@ -2591,7 +2591,7 @@ var Kn = class {
|
|
|
2591
2591
|
|
|
2592
2592
|
}
|
|
2593
2593
|
|
|
2594
|
-
if ( material.transparent != 0 && opacity < ${
|
|
2594
|
+
if ( material.transparent != 0 && opacity < ${kt}( ${4} + ti ) ) {
|
|
2595
2595
|
|
|
2596
2596
|
continue;
|
|
2597
2597
|
|
|
@@ -2622,8 +2622,8 @@ var Kn = class {
|
|
|
2622
2622
|
|
|
2623
2623
|
}
|
|
2624
2624
|
`,
|
|
2625
|
-
transformShapeFn:
|
|
2626
|
-
fn transformRay( ray: ptr<function, ${
|
|
2625
|
+
transformShapeFn: H`
|
|
2626
|
+
fn transformRay( ray: ptr<function, ${I}>, objectIndex: u32 ) -> void {
|
|
2627
2627
|
|
|
2628
2628
|
let toLocal = ${t.transforms}[ objectIndex ].inverseMatrixWorld;
|
|
2629
2629
|
ray.origin = ( toLocal * vec4f( ray.origin, 1.0 ) ).xyz;
|
|
@@ -2647,8 +2647,8 @@ var Kn = class {
|
|
|
2647
2647
|
|
|
2648
2648
|
}
|
|
2649
2649
|
`,
|
|
2650
|
-
transformResultFn:
|
|
2651
|
-
fn transformResult( hit: ptr<function, ${
|
|
2650
|
+
transformResultFn: H`
|
|
2651
|
+
fn transformResult( hit: ptr<function, ${L}>, objectIndex: u32 ) -> void {
|
|
2652
2652
|
|
|
2653
2653
|
let toLocal = ${t.transforms}[ objectIndex ].inverseMatrixWorld;
|
|
2654
2654
|
hit.normal = normalize( ( transpose( toLocal ) * vec4f( hit.normal, 0.0 ) ).xyz );
|
|
@@ -2662,24 +2662,24 @@ var Kn = class {
|
|
|
2662
2662
|
super.update();
|
|
2663
2663
|
let { materials: e, structs: t } = this, { materialData: n, textures: r } = this.writeMaterialsBuffer(e);
|
|
2664
2664
|
this.textures = r;
|
|
2665
|
-
let i =
|
|
2665
|
+
let i = N(new fe(n, t.material.getLength()), t.material).toReadOnly().setName("bvh_materials");
|
|
2666
2666
|
this.storage.materials = i, this.bvhMap.clear(), this.materials.length = 0, this.useTransparencyRaycastFn();
|
|
2667
2667
|
}
|
|
2668
2668
|
writeMaterialsBuffer(e) {
|
|
2669
2669
|
function t(e) {
|
|
2670
2670
|
switch (e) {
|
|
2671
|
-
case
|
|
2672
|
-
case
|
|
2673
|
-
case
|
|
2671
|
+
case u: return 0;
|
|
2672
|
+
case f: return 1;
|
|
2673
|
+
case v: return 2;
|
|
2674
2674
|
default: return 0;
|
|
2675
2675
|
}
|
|
2676
2676
|
}
|
|
2677
2677
|
function n(e, n) {
|
|
2678
2678
|
if (n in e && e[n]) {
|
|
2679
|
-
let r = e[n], i =
|
|
2680
|
-
|
|
2681
|
-
let a =
|
|
2682
|
-
return (r.magFilter === 1003 ? 1 : 0) << 28 |
|
|
2679
|
+
let r = e[n], i = Cn(r);
|
|
2680
|
+
o.has(i) || (o.set(i, o.size), s.push(r));
|
|
2681
|
+
let a = o.get(i), c = t(r.wrapS), l = t(r.wrapT);
|
|
2682
|
+
return (r.magFilter === 1003 ? 1 : 0) << 28 | l << 26 | c << 24 | a;
|
|
2683
2683
|
} else return -1;
|
|
2684
2684
|
}
|
|
2685
2685
|
function r(e, t, n) {
|
|
@@ -2694,30 +2694,30 @@ var Kn = class {
|
|
|
2694
2694
|
}
|
|
2695
2695
|
return 12;
|
|
2696
2696
|
}
|
|
2697
|
-
let a = 0,
|
|
2697
|
+
let a = 0, o = /* @__PURE__ */ new Map(), s = [], c = Math.max(e.length, 2), l = new Float32Array(c * this.structs.material.getLength()), d = new Int32Array(l.buffer);
|
|
2698
2698
|
for (let t = 0, o = e.length; t < o; t++) {
|
|
2699
2699
|
let o = e[t];
|
|
2700
|
-
|
|
2700
|
+
l[a++] = o.color.r, l[a++] = o.color.g, l[a++] = o.color.b, d[a++] = n(o, "map"), l[a++] = r(o, "metalness", 0), d[a++] = n(o, "metalnessMap"), l[a++] = r(o, "roughness", 0), d[a++] = n(o, "roughnessMap"), l[a++] = r(o, "ior", 1.5), l[a++] = r(o, "transmission", 0), d[a++] = n(o, "transmissionMap"), l[a++] = r(o, "emissiveIntensity", 0), "emissive" in o ? (l[a++] = o.emissive.r, l[a++] = o.emissive.g, l[a++] = o.emissive.b) : (l[a++] = 0, l[a++] = 0, l[a++] = 0), d[a++] = n(o, "emissiveMap"), d[a++] = n(o, "normalMap"), a++, "normalScale" in o ? (l[a++] = o.normalScale.x, l[a++] = o.normalScale.y) : (l[a++] = 1, l[a++] = 1), l[a++] = r(o, "clearcoat", 0), d[a++] = n(o, "clearcoatMap"), d[a++] = n(o, "clearcoatNormalMap"), a++, "clearcoatNormalScale" in o ? (l[a++] = o.clearcoatNormalScale.x, l[a++] = o.clearcoatNormalScale.y) : (l[a++] = 1, l[a++] = 1), l[a++] = r(o, "clearcoatRoughness", 0), d[a++] = n(o, "clearcoatRoughnessMap"), d[a++] = n(o, "iridescenceMap"), d[a++] = n(o, "iridescenceThicknessMap"), l[a++] = r(o, "iridescence", 0), l[a++] = r(o, "iridescenceIOR", 1.3);
|
|
2701
2701
|
let s = r(o, "iridescenceThicknessRange", [100, 400]);
|
|
2702
|
-
|
|
2702
|
+
l[a++] = s[0], l[a++] = s[1], a++, a++, "specularColor" in o ? (l[a++] = o.specularColor.r, l[a++] = o.specularColor.g, l[a++] = o.specularColor.b) : (l[a++] = 1, l[a++] = 1, l[a++] = 1), d[a++] = n(o, "specularColorMap"), l[a++] = r(o, "specularIntensity", 1), d[a++] = n(o, "specularIntensityMap");
|
|
2703
2703
|
let c = r(o, "thickness", 0) === 0 && r(o, "attenuationDistance", Infinity) === Infinity;
|
|
2704
|
-
if (
|
|
2704
|
+
if (d[a++] = Number(c), a++, "attenuationColor" in o ? (l[a++] = o.attenuationColor.r, l[a++] = o.attenuationColor.g, l[a++] = o.attenuationColor.b) : (l[a++] = 1, l[a++] = 1, l[a++] = 1), l[a++] = r(o, "attenuationDistance", Infinity), d[a++] = n(o, "alphaMap"), d[a++] = Number(r(o, "castShadow", !0)), l[a++] = o.opacity, l[a++] = o.alphaTest, !c && o.transmission > 0) l[a++] = 0;
|
|
2705
2705
|
else switch (o.side) {
|
|
2706
2706
|
case 0:
|
|
2707
|
-
|
|
2707
|
+
l[a++] = 1;
|
|
2708
2708
|
break;
|
|
2709
2709
|
case 1:
|
|
2710
|
-
|
|
2710
|
+
l[a++] = -1;
|
|
2711
2711
|
break;
|
|
2712
2712
|
case 2:
|
|
2713
|
-
|
|
2713
|
+
l[a++] = 0;
|
|
2714
2714
|
break;
|
|
2715
2715
|
}
|
|
2716
|
-
|
|
2716
|
+
d[a++] = Number(r(o, "matte", !1)), l[a++] = r(o, "sheen", 0), a++, "sheenColor" in o ? (l[a++] = o.sheenColor.r, l[a++] = o.sheenColor.g, l[a++] = o.sheenColor.b) : (l[a++] = 0, l[a++] = 0, l[a++] = 0), d[a++] = n(o, "sheenColorMap"), l[a++] = r(o, "sheenRoughness", 0), d[a++] = n(o, "sheenRoughnessMap"), d[a++] = Number(o.vertexColors), d[a++] = Number(o.flatShading), d[a++] = Number(o.transparent), d[a++] = 0, a++, a++, a += i(o, "map", l, a), a += i(o, "metalnessMap", l, a), a += i(o, "roughnessMap", l, a), a += i(o, "transmissionMap", l, a), a += i(o, "emissiveMap", l, a), a += i(o, "normalMap", l, a), a += i(o, "clearcoatMap", l, a), a += i(o, "clearcoatNormalMap", l, a), a += i(o, "clearcoatRoughnessMap", l, a), a += i(o, "sheenColorMap", l, a), a += i(o, "sheenRoughnessMap", l, a), a += i(o, "iridescenceMap", l, a), a += i(o, "iridescenceThicknessMap", l, a), a += i(o, "specularColorMap", l, a), a += i(o, "specularIntensityMap", l, a), a += i(o, "alphaMap", l, a);
|
|
2717
2717
|
}
|
|
2718
2718
|
return {
|
|
2719
|
-
materialData:
|
|
2720
|
-
textures:
|
|
2719
|
+
materialData: l,
|
|
2720
|
+
textures: s
|
|
2721
2721
|
};
|
|
2722
2722
|
}
|
|
2723
2723
|
writeTransformData(e, t, n, r) {
|
|
@@ -2730,21 +2730,21 @@ var Kn = class {
|
|
|
2730
2730
|
let l = i.indexOf(c);
|
|
2731
2731
|
l === -1 && (l = i.length, i.push(c));
|
|
2732
2732
|
let u = new Uint32Array(r);
|
|
2733
|
-
u[n *
|
|
2733
|
+
u[n * Yn.getLength() + 34] = l, a.isInstancedMesh && a.instanceColor ? (a.getColorAt(o, Jn), Jn.w = 1) : a.isBatchedMesh && a._colorsTexture ? a.getColorAt(o, Jn) : Jn.setScalar(1);
|
|
2734
2734
|
let d = new Float32Array(r);
|
|
2735
|
-
|
|
2735
|
+
Jn.toArray(d, n * Yn.getLength() + 36);
|
|
2736
2736
|
}
|
|
2737
2737
|
getBVH(e, t, n) {
|
|
2738
2738
|
let { bvhMap: r } = this, i = super.getBVH(e, t, n);
|
|
2739
2739
|
if (r.has(i)) {
|
|
2740
2740
|
let e = r.get(i);
|
|
2741
|
-
if (Object.assign(n, e.range), i !== e.bvh && i instanceof
|
|
2741
|
+
if (Object.assign(n, e.range), i !== e.bvh && i instanceof xe) {
|
|
2742
2742
|
let t = i.mesh, n = e.bvh.mesh;
|
|
2743
2743
|
n.matrixWorld.copy(t.matrixWorld).decompose(n.position, n.quaternion, n.scale), i.refit();
|
|
2744
2744
|
}
|
|
2745
2745
|
return e.bvh;
|
|
2746
2746
|
} else if (i.indirect) {
|
|
2747
|
-
let e = new
|
|
2747
|
+
let e = new ee();
|
|
2748
2748
|
e.attributes = i.geometry.attributes;
|
|
2749
2749
|
let t;
|
|
2750
2750
|
if (i.geometry.index) t = i.geometry.index.array.slice(n.start, n.count + n.start);
|
|
@@ -2753,15 +2753,15 @@ var Kn = class {
|
|
|
2753
2753
|
t = new Uint32Array(r);
|
|
2754
2754
|
for (let r = 0, i = n.count; r < i; r++) t[r] = e + r;
|
|
2755
2755
|
}
|
|
2756
|
-
e.index = new
|
|
2756
|
+
e.index = new w(t, 1), n.start = 0;
|
|
2757
2757
|
let a;
|
|
2758
|
-
if (i instanceof
|
|
2759
|
-
let t = i.mesh, n = new
|
|
2760
|
-
n.copy(t), n.matrixWorld.copy(t.matrixWorld).decompose(n.position, n.quaternion, n.scale), a = new
|
|
2758
|
+
if (i instanceof xe) {
|
|
2759
|
+
let t = i.mesh, n = new d(e);
|
|
2760
|
+
n.copy(t), n.matrixWorld.copy(t.matrixWorld).decompose(n.position, n.quaternion, n.scale), a = new xe(n, {
|
|
2761
2761
|
strategy: 2,
|
|
2762
2762
|
maxLeafSize: 5
|
|
2763
2763
|
});
|
|
2764
|
-
} else a = new
|
|
2764
|
+
} else a = new be(e, {
|
|
2765
2765
|
strategy: 2,
|
|
2766
2766
|
maxLeafSize: 5
|
|
2767
2767
|
});
|
|
@@ -2771,7 +2771,7 @@ var Kn = class {
|
|
|
2771
2771
|
}), a;
|
|
2772
2772
|
} else return i;
|
|
2773
2773
|
}
|
|
2774
|
-
},
|
|
2774
|
+
}, Zn = class extends ge {
|
|
2775
2775
|
set texture(e) {
|
|
2776
2776
|
this._texNode.value = e;
|
|
2777
2777
|
}
|
|
@@ -2779,12 +2779,12 @@ var Kn = class {
|
|
|
2779
2779
|
this._layerUniform.value = e;
|
|
2780
2780
|
}
|
|
2781
2781
|
constructor() {
|
|
2782
|
-
super(), this.blending = 0, this._texNode =
|
|
2782
|
+
super(), this.blending = 0, this._texNode = M(new h()), this._layerUniform = j(0), this.colorNode = A("\n fn atlasDebug( tex: texture_2d_array<f32>, coord: vec2f, layer: f32 ) -> vec4f {\n\n // flip y so texel origin shows at the top-left\n let dims = vec2f( textureDimensions( tex, 0 ).xy );\n let texel = vec2i( vec2f( coord.x, 1.0 - coord.y ) * dims );\n return textureLoad( tex, texel, i32( layer ), 0 );\n\n }\n ")(this._texNode, De(we()), this._layerUniform);
|
|
2783
2783
|
}
|
|
2784
2784
|
};
|
|
2785
2785
|
//#endregion
|
|
2786
2786
|
//#region ../../node_modules/three-gpu-pathtracer/src/core/utils/GeometryPreparationUtils.js
|
|
2787
|
-
function
|
|
2787
|
+
function Qn(e, t) {
|
|
2788
2788
|
if (!e.index) {
|
|
2789
2789
|
let t = e.attributes.position.count, n = Array(t);
|
|
2790
2790
|
for (let e = 0; e < t; e++) n[e] = e;
|
|
@@ -2792,35 +2792,35 @@ function Zn(e, t) {
|
|
|
2792
2792
|
}
|
|
2793
2793
|
if (!e.attributes.normal && t && t.includes("normal") && e.computeVertexNormals(), !e.attributes.uv && t && t.includes("uv")) {
|
|
2794
2794
|
let t = e.attributes.position.count;
|
|
2795
|
-
e.setAttribute("uv", new
|
|
2795
|
+
e.setAttribute("uv", new w(new Float32Array(t * 2), 2, !1));
|
|
2796
2796
|
}
|
|
2797
2797
|
if (!e.attributes.uv2 && t && t.includes("uv2")) {
|
|
2798
2798
|
let t = e.attributes.position.count;
|
|
2799
|
-
e.setAttribute("uv2", new
|
|
2799
|
+
e.setAttribute("uv2", new w(new Float32Array(t * 2), 2, !1));
|
|
2800
2800
|
}
|
|
2801
2801
|
if (!e.attributes.tangent && t && t.includes("tangent")) if (e.attributes.uv && e.attributes.normal) e.computeTangents();
|
|
2802
2802
|
else {
|
|
2803
2803
|
let t = e.attributes.position.count;
|
|
2804
|
-
e.setAttribute("tangent", new
|
|
2804
|
+
e.setAttribute("tangent", new w(new Float32Array(t * 4), 4, !1));
|
|
2805
2805
|
}
|
|
2806
2806
|
if (!e.attributes.color && t && t.includes("color")) {
|
|
2807
2807
|
let t = e.attributes.position.count, n = new Float32Array(t * 4);
|
|
2808
|
-
n.fill(1), e.setAttribute("color", new
|
|
2808
|
+
n.fill(1), e.setAttribute("color", new w(n, 4));
|
|
2809
2809
|
}
|
|
2810
2810
|
}
|
|
2811
2811
|
//#endregion
|
|
2812
2812
|
//#region ../../node_modules/three-gpu-pathtracer/src/webgpu/materials/PathtracingMaterial.js
|
|
2813
|
-
var
|
|
2813
|
+
var $n = class {
|
|
2814
2814
|
init() {}
|
|
2815
2815
|
getBsdfNode() {
|
|
2816
|
-
return
|
|
2816
|
+
return H`
|
|
2817
2817
|
|
|
2818
2818
|
fn bsdfSample( worldWo: vec3f, surf: SurfaceRecord ) -> ScatterRecord {
|
|
2819
2819
|
|
|
2820
2820
|
var record: ScatterRecord;
|
|
2821
2821
|
|
|
2822
2822
|
let wo = normalize( surf.normalInvBasis * worldWo );
|
|
2823
|
-
let wi = ${
|
|
2823
|
+
let wi = ${Yt}( wo, ${q}( ${3} ) );
|
|
2824
2824
|
record.color = surf.color * max( wi.z, 0.0 );
|
|
2825
2825
|
record.pdf = max( wi.z, 0.0 ) / PI;
|
|
2826
2826
|
record.direction = normalize( surf.normalBasis * wi );
|
|
@@ -2834,19 +2834,19 @@ var Qn = class {
|
|
|
2834
2834
|
getData() {
|
|
2835
2835
|
return { bsdfSample: this.getBsdfNode() };
|
|
2836
2836
|
}
|
|
2837
|
-
},
|
|
2837
|
+
}, er = new URL("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACsUlEQVR4AcTWjXISMRiF4WTb3v+1dqblH5QnzsGPdUF0tDDzepLdJe9JEGX69uTXdDqd2jNf0/v7e1PifBBP6TGtVqu22+0uJb66yNR7b0rs9/t2PB6bAnP+59FMb29vbbvdts1m01KiFiGfFzJ3/V8wvb6+jp0rAR/H4XAY1/zdAGGINPO/yawhR4HeeyMlh5OAkwgpkqxiC/0J9b3T+dXgIqkCMIZiKSEVCN4Dc/kI86Jn9zQKuGEhQmIlYAzXFQieDcR1bP4o41vw8vLSeu/jG0BABmIYVzwzJwVcz1jOi7gW3BsFeu+jgFNw0SIRKlBPwjx4xrMVi5vLW3DA/VHg/DmMAr3/OAU3LUIAQiVgjFw3hnnw3iUI4Z7EZNe9/zwBczfgwSwqiaAIjCueCa5nbJ1bjAKkvXcxcAIp4I0WyoIyKAFzGczn1DWMw6XAMJ//IIcCUADeUBetsoxr1meN3ZNzfilw7jC+DSkRuQKoC1h0Cf+izll6zlqXAoQVu4cCqPIsZoG56JG59+c5v4jGjrNz0kBcUQLEFqlkwZr+g7uF59xbPIEUkAqQBvKQAhYLFr3Her1uwXOjgKMnSxoTVxSIWN6SK2JhkqQx/O6QMMblI6hyBZAC5IE83CpBDKIkmbmsjAJklYjlI2JFsvMIyVBln5+f49eXDFcfgRKkiLhmdi5JQ+RJJaBASJGIk+MEcvzElcgJQ6TJSJOES3LXU0Iq8PHx0UYBO0fkESeX5IQVUrhGFsgqxJXxEZCHeYnIa2b3kjAoEFIgeavEOIH6EWTX8p50LleCnFDCONQCGTuJUcDus3NJHmoJY2IQBjLM566lQDJyeVUgJX4nJg8RJgmXiDxJDvOrEyCvJ2DHIdIkqbEEcdI4kNRx5hJXBe7JFalCsntE6pmMk8TG8jsAAAD//yGAaM0AAAAGSURBVAMAifCfleVLEBEAAAAASUVORK5CYII=", "" + import.meta.url).toString(), tr = await new ne().loadAsync(er), nr = F(1.5), rr = F(.001), ir = class extends $n {
|
|
2838
2838
|
constructor(e = {}) {
|
|
2839
2839
|
super();
|
|
2840
|
-
let { specularBrdf: t =
|
|
2841
|
-
|
|
2842
|
-
let
|
|
2843
|
-
this.specularBrdf = t, this.diffuseBrdf =
|
|
2840
|
+
let { specularBrdf: t = Mn, diffuseBrdf: r = jn, fresnelMix: i = Nn, conductorFresnel: a = Rn, fresnelCoat: o = zn, iridescentDielectricLayer: c = In, iridescentConductorLayer: l = Ln, calculateTurquinTexture: u = !1 } = e;
|
|
2841
|
+
u ? (this.turquinTexture = new T(32, 32), this.turquinTexture.type = S) : (this.turquinTexture = tr, this.turquinTexture.flipY = !1), this.turquinTexture.format = n, this.turquinTexture.minFilter = s, this.turquinTexture.magFilter = s;
|
|
2842
|
+
let d = M(this.turquinTexture).setName("turquinTexture");
|
|
2843
|
+
this.specularBrdf = t, this.diffuseBrdf = r, this.fresnelMix = i, this.conductorFresnel = a(d), this.fresnelCoat = o, this.iridescentDielectricLayer = c, this.iridescentConductorLayer = l, this.calculateTurquinTexture = u;
|
|
2844
2844
|
}
|
|
2845
2845
|
init(e) {
|
|
2846
2846
|
if (!this.calculateTurquinTexture) return;
|
|
2847
|
-
let t = new
|
|
2848
|
-
texture:
|
|
2849
|
-
globalId:
|
|
2847
|
+
let t = new G(Bn({
|
|
2848
|
+
texture: O(this.turquinTexture).toWriteOnly(),
|
|
2849
|
+
globalId: k
|
|
2850
2850
|
}), { workgroupSize: [
|
|
2851
2851
|
16,
|
|
2852
2852
|
16,
|
|
@@ -2859,11 +2859,11 @@ var Qn = class {
|
|
|
2859
2859
|
]);
|
|
2860
2860
|
}
|
|
2861
2861
|
getBsdfNode() {
|
|
2862
|
-
return
|
|
2862
|
+
return H`
|
|
2863
2863
|
|
|
2864
|
-
fn bsdfSample( worldWo: vec3f, surf: ${
|
|
2864
|
+
fn bsdfSample( worldWo: vec3f, surf: ${Pt} ) -> ${Mt} {
|
|
2865
2865
|
|
|
2866
|
-
var result: ${
|
|
2866
|
+
var result: ${Mt};
|
|
2867
2867
|
result.pdf = 0.0;
|
|
2868
2868
|
|
|
2869
2869
|
let alpha = surf.roughness * surf.roughness;
|
|
@@ -2888,7 +2888,7 @@ var Qn = class {
|
|
|
2888
2888
|
|
|
2889
2889
|
}
|
|
2890
2890
|
|
|
2891
|
-
let weights = ${
|
|
2891
|
+
let weights = ${Xt}( wo, woClearcoat, vec3( 0, 0, 1 ), ${nr}, surf );
|
|
2892
2892
|
|
|
2893
2893
|
var cdf: vec4f;
|
|
2894
2894
|
cdf.x = weights.diffuse;
|
|
@@ -2896,9 +2896,9 @@ var Qn = class {
|
|
|
2896
2896
|
cdf.z = weights.clearcoat + cdf.y;
|
|
2897
2897
|
cdf.w = 0; // weights.transmission + cdf.z;
|
|
2898
2898
|
|
|
2899
|
-
let r = ${
|
|
2899
|
+
let r = ${kt}( ${2} ) * cdf.z;
|
|
2900
2900
|
|
|
2901
|
-
let directionUV = ${
|
|
2901
|
+
let directionUV = ${q}( ${3} );
|
|
2902
2902
|
var wi: vec3f;
|
|
2903
2903
|
var wiClearcoat: vec3f;
|
|
2904
2904
|
var wh: vec3f;
|
|
@@ -2906,7 +2906,7 @@ var Qn = class {
|
|
|
2906
2906
|
|
|
2907
2907
|
if ( r <= cdf.x ) { // diffuse
|
|
2908
2908
|
|
|
2909
|
-
wi = ${
|
|
2909
|
+
wi = ${Yt}( wo, directionUV );
|
|
2910
2910
|
wh = normalize( wi + wo );
|
|
2911
2911
|
|
|
2912
2912
|
wiClearcoat = normalize( invClearcoatBasis * normalBasis * wi );
|
|
@@ -2914,7 +2914,7 @@ var Qn = class {
|
|
|
2914
2914
|
|
|
2915
2915
|
} else if ( r <= cdf.y ) { // specular
|
|
2916
2916
|
|
|
2917
|
-
wh = ${
|
|
2917
|
+
wh = ${wn}( wo, vec2( alpha ), directionUV );
|
|
2918
2918
|
wi = - normalize( reflect( wo, wh ) );
|
|
2919
2919
|
|
|
2920
2920
|
wiClearcoat = normalize( invClearcoatBasis * normalBasis * wi );
|
|
@@ -2922,7 +2922,7 @@ var Qn = class {
|
|
|
2922
2922
|
|
|
2923
2923
|
} else if ( r <= cdf.z ) { // clearcoat
|
|
2924
2924
|
|
|
2925
|
-
whClearcoat = ${
|
|
2925
|
+
whClearcoat = ${wn}( woClearcoat, vec2( clearcoatAlpha ), directionUV );
|
|
2926
2926
|
wiClearcoat = - normalize( reflect( woClearcoat, whClearcoat ) );
|
|
2927
2927
|
|
|
2928
2928
|
wi = normalize( invBasis * clearcoatBasis * wiClearcoat );
|
|
@@ -2934,14 +2934,14 @@ var Qn = class {
|
|
|
2934
2934
|
|
|
2935
2935
|
}
|
|
2936
2936
|
|
|
2937
|
-
var ctx: ${
|
|
2938
|
-
ctx.NdotV = max( wo.z, ${
|
|
2939
|
-
ctx.NdotL = max( wi.z, ${
|
|
2937
|
+
var ctx: ${Lt};
|
|
2938
|
+
ctx.NdotV = max( wo.z, ${rr} );
|
|
2939
|
+
ctx.NdotL = max( wi.z, ${rr} );
|
|
2940
2940
|
ctx.NdotH = saturate( wh.z );
|
|
2941
2941
|
ctx.VdotH = saturate( dot( wo, wh ) );
|
|
2942
2942
|
|
|
2943
|
-
ctx.VdotNc = max( woClearcoat.z, ${
|
|
2944
|
-
ctx.LdotNc = max( wiClearcoat.z, ${
|
|
2943
|
+
ctx.VdotNc = max( woClearcoat.z, ${rr} );
|
|
2944
|
+
ctx.LdotNc = max( wiClearcoat.z, ${rr} );
|
|
2945
2945
|
ctx.HdotNc = saturate( whClearcoat.z );
|
|
2946
2946
|
|
|
2947
2947
|
if ( weights.diffuse > 0.0 ) {
|
|
@@ -2952,19 +2952,19 @@ var Qn = class {
|
|
|
2952
2952
|
|
|
2953
2953
|
if ( weights.specular > 0.0 && wi.z > 0.0 ) {
|
|
2954
2954
|
|
|
2955
|
-
result.pdf += weights.specular * ${
|
|
2955
|
+
result.pdf += weights.specular * ${kn}( ctx.NdotV, ctx.NdotH, alpha );
|
|
2956
2956
|
|
|
2957
2957
|
}
|
|
2958
2958
|
|
|
2959
2959
|
if ( weights.clearcoat > 0.0 && wiClearcoat.z > 0.0 ) {
|
|
2960
2960
|
|
|
2961
|
-
result.pdf += weights.clearcoat * ${
|
|
2961
|
+
result.pdf += weights.clearcoat * ${kn}( ctx.VdotNc, ctx.HdotNc, clearcoatAlpha );
|
|
2962
2962
|
|
|
2963
2963
|
}
|
|
2964
2964
|
|
|
2965
|
-
result.color = ${
|
|
2965
|
+
result.color = ${H`
|
|
2966
2966
|
|
|
2967
|
-
fn bsdfEval( ctx: ${
|
|
2967
|
+
fn bsdfEval( ctx: ${Lt}, surf: ${Pt} ) -> vec3f {
|
|
2968
2968
|
|
|
2969
2969
|
let alpha = surf.roughness * surf.roughness;
|
|
2970
2970
|
|
|
@@ -2989,7 +2989,7 @@ var Qn = class {
|
|
|
2989
2989
|
let clearcoatAlpha = surf.clearcoatRoughness * surf.clearcoatRoughness;
|
|
2990
2990
|
let clearcoat = ${this.specularBrdf}( ctx.LdotNc, ctx.VdotNc, ctx.HdotNc, clearcoatAlpha );
|
|
2991
2991
|
|
|
2992
|
-
let coatedMaterial = ${this.fresnelCoat}( ctx.VdotNc, ${
|
|
2992
|
+
let coatedMaterial = ${this.fresnelCoat}( ctx.VdotNc, ${nr}, material, clearcoat, surf.clearcoat );
|
|
2993
2993
|
|
|
2994
2994
|
return coatedMaterial;
|
|
2995
2995
|
|
|
@@ -3005,7 +3005,7 @@ var Qn = class {
|
|
|
3005
3005
|
|
|
3006
3006
|
`;
|
|
3007
3007
|
}
|
|
3008
|
-
},
|
|
3008
|
+
}, Q = new p(), $ = new oe(), ar = class {
|
|
3009
3009
|
get bounces() {
|
|
3010
3010
|
return this._pathTracer.bounces;
|
|
3011
3011
|
}
|
|
@@ -3022,38 +3022,38 @@ var Qn = class {
|
|
|
3022
3022
|
return this._bvhData.textureAtlas;
|
|
3023
3023
|
}
|
|
3024
3024
|
useMegakernel(e) {
|
|
3025
|
-
this._pathTracer.dispose(), this._pathTracer = e ? new
|
|
3025
|
+
this._pathTracer.dispose(), this._pathTracer = e ? new cn(this._renderer) : new yn(this._renderer), this._pathTracer.setBVHData(this._bvhData), this._pathTracer.setMaterial(this.material), this.setCamera(this.camera), this.updateEnvironment();
|
|
3026
3026
|
}
|
|
3027
3027
|
constructor(e) {
|
|
3028
|
-
this._renderer = e, this._timer = new
|
|
3028
|
+
this._renderer = e, this._timer = new x(), this._envColorTexture = new h(), this._envColorTexture.image.data = new Uint8Array([
|
|
3029
3029
|
255,
|
|
3030
3030
|
255,
|
|
3031
3031
|
255,
|
|
3032
3032
|
255
|
|
3033
|
-
]), this._envColorTexture.needsUpdate = !0, this._envColorTexture.minFilter =
|
|
3033
|
+
]), this._envColorTexture.needsUpdate = !0, this._envColorTexture.minFilter = s, this._envColorTexture.magFilter = s, this._backgroundColorTexture = new h(), this._backgroundColorTexture.image.data = new Uint8Array([
|
|
3034
3034
|
255,
|
|
3035
3035
|
255,
|
|
3036
3036
|
255,
|
|
3037
3037
|
255
|
|
3038
|
-
]), this._backgroundColorTexture.needsUpdate = !0, this._backgroundColorTexture.minFilter =
|
|
3038
|
+
]), this._backgroundColorTexture.needsUpdate = !0, this._backgroundColorTexture.minFilter = s, this._backgroundColorTexture.magFilter = s, this._resetTime = -1, this._fadeState = 0, this._size = new p(), this._blitQuad = new ce(new mt()), this._lowResTarget = new T(1, 1), this._lowResTarget.type = b, this._lowResTarget.generateMipmaps = !1, this.minSamples = 1, this.renderDelay = 500, this.fadeDuration = 500, this.dynamicLowRes = !0, this.lowResScale = .2, this.renderScale = 1, this.synchronizeRenderSize = !0, this.generateMissingAttributes = !0, this.commonAttributes = [
|
|
3039
3039
|
"normal",
|
|
3040
3040
|
"uv",
|
|
3041
3041
|
"tangent",
|
|
3042
3042
|
"color"
|
|
3043
|
-
], this.material = new
|
|
3043
|
+
], this.material = new ir(), this._pathTracer = new cn(e), this.setScene(new g(), new te());
|
|
3044
3044
|
}
|
|
3045
3045
|
setScene(e, t) {
|
|
3046
3046
|
e.updateMatrixWorld(!0), t.updateMatrixWorld(), e.traverse((e) => {
|
|
3047
|
-
this.generateMissingAttributes && e.geometry?.isBufferGeometry &&
|
|
3047
|
+
this.generateMissingAttributes && e.geometry?.isBufferGeometry && Qn(e.geometry, this.commonAttributes), e.isSkinnedMesh ? e.boundsTree ? e.boundsTree.refit() : e.boundsTree = new xe(e, {
|
|
3048
3048
|
strategy: 2,
|
|
3049
3049
|
maxLeafSize: 5,
|
|
3050
3050
|
indirect: !0
|
|
3051
|
-
}) : e.isMesh && (e.geometry.boundsTree || (e.geometry.boundsTree = new
|
|
3051
|
+
}) : e.isMesh && (e.geometry.boundsTree || (e.geometry.boundsTree = new be(e.geometry, {
|
|
3052
3052
|
strategy: 2,
|
|
3053
3053
|
maxLeafSize: 5
|
|
3054
3054
|
})));
|
|
3055
3055
|
});
|
|
3056
|
-
let n = new
|
|
3056
|
+
let n = new Xn(e);
|
|
3057
3057
|
n.update(), n.textureAtlas.setTextures(this._renderer, n.textures), this.scene = e, this._bvhData = n, this._pathTracer.setBVHData(n), this.setCamera(t), this.updateEnvironment();
|
|
3058
3058
|
}
|
|
3059
3059
|
getMaterial() {
|
|
@@ -3073,7 +3073,7 @@ var Qn = class {
|
|
|
3073
3073
|
e.updateMatrixWorld(), this._pathTracer.setCamera(e), this.reset();
|
|
3074
3074
|
}
|
|
3075
3075
|
updateEnvironment() {
|
|
3076
|
-
let { _renderer: e, _pathTracer: t, scene: n, _envColorTexture: r, _backgroundColorTexture: i } = this, a = or(e, n.environment ||
|
|
3076
|
+
let { _renderer: e, _pathTracer: t, scene: n, _envColorTexture: r, _backgroundColorTexture: i } = this, a = or(e, n.environment || $.set(0), r), o = or(e, n.background, i);
|
|
3077
3077
|
t.setEnvironment(a, n.environmentIntensity, n.environmentRotation, o, n.backgroundIntensity, n.backgroundRotation, n.backgroundBlurriness);
|
|
3078
3078
|
}
|
|
3079
3079
|
setSize(e, t) {
|
|
@@ -3090,19 +3090,19 @@ var Qn = class {
|
|
|
3090
3090
|
this._resetTime += f;
|
|
3091
3091
|
let p = e.toneMapping, m = e.toneMappingExposure, h = e.getRenderTarget(), g = e.autoClear;
|
|
3092
3092
|
if (e.toneMapping = 0, e.toneMappingExposure = 1, c) {
|
|
3093
|
-
e.getDrawingBufferSize(
|
|
3094
|
-
let t = Math.floor(l *
|
|
3093
|
+
e.getDrawingBufferSize(Q);
|
|
3094
|
+
let t = Math.floor(l * Q.x), n = Math.floor(l * Q.y);
|
|
3095
3095
|
this.setSize(t, n);
|
|
3096
3096
|
}
|
|
3097
3097
|
let { width: _, height: v } = t, y = this._resetTime < o;
|
|
3098
|
-
y && (_ = Math.ceil(u * _), v = Math.ceil(u * v)), r.getSize(
|
|
3098
|
+
y && (_ = Math.ceil(u * _), v = Math.ceil(u * v)), r.getSize(Q), (Q.x !== _ || Q.y !== v) && (!y && s && (i.setSize(Math.ceil(u * _), Math.ceil(u * v)), e.copyTextureToTexture(r.outputTarget, i)), r.setSize(_, v)), !y && r.samples >= d && (this._fadeState += f / this.fadeDuration, this._fadeState = Math.min(1, this._fadeState)), (!y || y && s) && (r.lowResMode = y, r.update());
|
|
3099
3099
|
let b = y && s ? 1 : this._fadeState;
|
|
3100
3100
|
e.autoClear = s ? !0 : b === 1, n.material.transition = s ? b : 1, n.material.opacity = s ? 1 : b, n.material.fromTexture = i, n.material.texture = r.outputTarget, n.material.toneMapping = p, n.material.toneMappingExposure = m, n.render(e), e.autoClear = g, e.toneMapping = p, e.toneMappingExposure = m, e.setRenderTarget(h);
|
|
3101
3101
|
}
|
|
3102
3102
|
renderTextureAtlas(e = 0) {
|
|
3103
3103
|
let t = this._renderer;
|
|
3104
3104
|
if (!t._initialized) return;
|
|
3105
|
-
this._atlasDebugQuad ||= new
|
|
3105
|
+
this._atlasDebugQuad ||= new ce(new Zn());
|
|
3106
3106
|
let n = this._atlasDebugQuad;
|
|
3107
3107
|
n.material.texture = this.textureAtlas.texture, n.material.layer = e, t.setRenderTarget(null), n.render(t);
|
|
3108
3108
|
}
|
|
@@ -3127,14 +3127,14 @@ var Qn = class {
|
|
|
3127
3127
|
}
|
|
3128
3128
|
};
|
|
3129
3129
|
function or(e, t, n) {
|
|
3130
|
-
if (t) t.isColor ? (n.image.data[0] = t.r * 255, n.image.data[1] = t.g * 255, n.image.data[2] = t.b * 255, n.image.data[3] = 255, n.needsUpdate = !0, t = n) : t?.isCubeTexture && (t = new
|
|
3130
|
+
if (t) t.isColor ? (n.image.data[0] = t.r * 255, n.image.data[1] = t.g * 255, n.image.data[2] = t.b * 255, n.image.data[3] = 255, n.needsUpdate = !0, t = n) : t?.isCubeTexture && (t = new Sn(e).generate(t));
|
|
3131
3131
|
else {
|
|
3132
3132
|
let r = e.getClearAlpha();
|
|
3133
|
-
e.getClearColor(
|
|
3133
|
+
e.getClearColor($), n.image.data[0] = $.r * 255, n.image.data[1] = $.g * 255, n.image.data[2] = $.b * 255, n.image.data[3] = r * 255, n.needsUpdate = !0, t = n;
|
|
3134
3134
|
}
|
|
3135
3135
|
return t;
|
|
3136
3136
|
}
|
|
3137
3137
|
//#endregion
|
|
3138
3138
|
export { ar as WebGPUPathTracer };
|
|
3139
3139
|
|
|
3140
|
-
//# sourceMappingURL=webgpu-
|
|
3140
|
+
//# sourceMappingURL=webgpu-BxYJfBjz.mjs.map
|