threejs-debug-compose 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/assets/readme-compose-banner.png +0 -0
- package/assets/viewport-compose-quad.png +0 -0
- package/dist/custom-debug-view.js +13 -0
- package/dist/debug-render-graph-plan.js +38 -0
- package/dist/debug-render-plan.js +86 -0
- package/dist/debug-view-definitions.js +91 -0
- package/dist/debug-view-layout.js +65 -0
- package/dist/debug-view-selection.js +33 -0
- package/dist/debug-viewport-labels.js +28 -0
- package/dist/debug-viewport-plan.js +51 -0
- package/dist/debug-viewport-presenter.js +33 -0
- package/dist/debug-views-post.js +329 -0
- package/dist/debug-views-tsl/ao-fallbacks.js +103 -0
- package/dist/debug-views-tsl/compositor.js +51 -0
- package/dist/debug-views-tsl/default-debug-nodes.js +61 -0
- package/dist/debug-views-tsl/uniforms.js +19 -0
- package/dist/debug-views-tsl/visualize.js +21 -0
- package/dist/index.js +11 -0
- package/dist/react.js +3 -0
- package/dist/shader-cost/cost-override.js +67 -0
- package/dist/shader-cost/material-cost.js +302 -0
- package/dist/types/custom-debug-view.d.ts +17 -0
- package/dist/types/debug-render-graph-plan.d.ts +17 -0
- package/dist/types/debug-render-plan.d.ts +26 -0
- package/dist/types/debug-view-definitions.d.ts +60 -0
- package/dist/types/debug-view-layout.d.ts +21 -0
- package/dist/types/debug-view-selection.d.ts +5 -0
- package/dist/types/debug-viewport-labels.d.ts +8 -0
- package/dist/types/debug-viewport-plan.d.ts +29 -0
- package/dist/types/debug-viewport-presenter.d.ts +28 -0
- package/dist/types/debug-views-post.d.ts +19 -0
- package/dist/types/debug-views-tsl/ao-fallbacks.d.ts +6 -0
- package/dist/types/debug-views-tsl/compositor.d.ts +20 -0
- package/dist/types/debug-views-tsl/default-debug-nodes.d.ts +35 -0
- package/dist/types/debug-views-tsl/node-types.d.ts +6 -0
- package/dist/types/debug-views-tsl/uniforms.d.ts +12 -0
- package/dist/types/debug-views-tsl/visualize.d.ts +5 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/react.d.ts +2 -0
- package/dist/types/shader-cost/cost-override.d.ts +20 -0
- package/dist/types/shader-cost/material-cost.d.ts +15 -0
- package/dist/types/use-debug-views-controls.d.ts +16 -0
- package/dist/use-debug-views-controls.js +77 -0
- package/package.json +101 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { resolveDebugViewLayout as e } from "./debug-view-layout.js";
|
|
2
|
+
import { getDefaultDebugViewSource as t, getResolvedDebugViewMode as n } from "./debug-view-selection.js";
|
|
3
|
+
import { createDebugViewportPlan as r } from "./debug-viewport-plan.js";
|
|
4
|
+
import { createDebugViewportRenderGraphPlan as i } from "./debug-render-graph-plan.js";
|
|
5
|
+
import { createDebugViewportRects as a, toDebugViewportPixels as o } from "./debug-viewport-presenter.js";
|
|
6
|
+
import { createDebugViewportLabels as s, createDebugViewportPlanLabels as c } from "./debug-viewport-labels.js";
|
|
7
|
+
import { createViewCompositor as l } from "./debug-views-tsl/compositor.js";
|
|
8
|
+
import { createDebugViewUniforms as u, updateDebugViewUniforms as d } from "./debug-views-tsl/uniforms.js";
|
|
9
|
+
import { createAoFallbacks as f } from "./debug-views-tsl/ao-fallbacks.js";
|
|
10
|
+
import { configureMaterialDetailPass as p, configureSceneDebugPass as m, createDefaultDebugNodeResolver as h } from "./debug-views-tsl/default-debug-nodes.js";
|
|
11
|
+
import { applyDebugTextureTypes as g, createDebugRenderPlan as _ } from "./debug-render-plan.js";
|
|
12
|
+
import { createShaderCostOverride as v } from "./shader-cost/cost-override.js";
|
|
13
|
+
import { pass as y } from "three/tsl";
|
|
14
|
+
import { useEffect as b, useMemo as x, useRef as S } from "react";
|
|
15
|
+
import { useFrame as C, useThree as w } from "@react-three/fiber";
|
|
16
|
+
import { Html as T } from "@react-three/drei";
|
|
17
|
+
import { RenderPipeline as E } from "three/webgpu";
|
|
18
|
+
import { MeshBasicMaterial as D, MeshStandardMaterial as O, Vector2 as k, Vector4 as A } from "three";
|
|
19
|
+
import { Fragment as j, jsx as M, jsxs as N } from "react/jsx-runtime";
|
|
20
|
+
//#region components/debug-views/debug-views-post.tsx
|
|
21
|
+
function P({ views: e, mode: t = "compose", viewportViews: n, activeView: r = 0, layout: i = "single", slots: a, columns: o, rows: s, showLabels: c = !1, viewportLabels: l, overlayOpacity: u = .35, enabled: d = !0 }) {
|
|
22
|
+
let f = x(() => ({
|
|
23
|
+
slots: a,
|
|
24
|
+
columns: o,
|
|
25
|
+
rows: s
|
|
26
|
+
}), [
|
|
27
|
+
a,
|
|
28
|
+
o,
|
|
29
|
+
s
|
|
30
|
+
]);
|
|
31
|
+
return d ? /* @__PURE__ */ M(F, {
|
|
32
|
+
views: e,
|
|
33
|
+
mode: t,
|
|
34
|
+
viewportViews: n,
|
|
35
|
+
activeView: r,
|
|
36
|
+
layout: i,
|
|
37
|
+
layoutOptions: f,
|
|
38
|
+
showLabels: c,
|
|
39
|
+
viewportLabels: l,
|
|
40
|
+
overlayOpacity: u
|
|
41
|
+
}) : null;
|
|
42
|
+
}
|
|
43
|
+
function F({ views: n, mode: a, viewportViews: o, activeView: s, layout: c, layoutOptions: l, showLabels: p, viewportLabels: m, overlayOpacity: h }) {
|
|
44
|
+
let { camera: g, gl: v, scene: y } = w(), b = x(() => u(), []), S = x(() => f(y), [y]), T = x(() => e(c, l), [c, l]), E = x(() => a === "viewport" ? r({
|
|
45
|
+
views: n,
|
|
46
|
+
viewportViews: o,
|
|
47
|
+
activeView: s,
|
|
48
|
+
layout: T
|
|
49
|
+
}) : void 0, [
|
|
50
|
+
a,
|
|
51
|
+
n,
|
|
52
|
+
o,
|
|
53
|
+
s,
|
|
54
|
+
T
|
|
55
|
+
]), D = x(() => E ? i(E) : void 0, [E]), O = E?.views ?? n, k = x(() => _(O, s, T), [
|
|
56
|
+
O,
|
|
57
|
+
s,
|
|
58
|
+
T
|
|
59
|
+
]), A = E?.views ?? k.views, P = x(() => A.some((e) => t(e) === "shaderCost"), [A]), F = z(a === "compose", y, g, k, T, W(v), b, S), R = B(a === "viewport", y, g, E, D, W(v), b, S);
|
|
60
|
+
return C(() => {
|
|
61
|
+
let e = y.background;
|
|
62
|
+
y.background = null;
|
|
63
|
+
try {
|
|
64
|
+
if (a === "viewport") {
|
|
65
|
+
let e = R.current;
|
|
66
|
+
e?.usesAoFallback && S.refresh(), e?.render();
|
|
67
|
+
} else d(b, 0, T, k.views.length, h), k.usesAoFallback && S.refresh(), F.current?.render();
|
|
68
|
+
} finally {
|
|
69
|
+
y.background = e;
|
|
70
|
+
}
|
|
71
|
+
}, 1), /* @__PURE__ */ N(j, { children: [p ? /* @__PURE__ */ M(I, {
|
|
72
|
+
views: A,
|
|
73
|
+
layout: T,
|
|
74
|
+
labels: m,
|
|
75
|
+
viewportPlan: E
|
|
76
|
+
}) : null, P ? /* @__PURE__ */ M(L, {}) : null] });
|
|
77
|
+
}
|
|
78
|
+
function I({ views: e, layout: t, labels: n, viewportPlan: r }) {
|
|
79
|
+
let i = x(() => r ? c(r, n) : s(e, t, n), [
|
|
80
|
+
e,
|
|
81
|
+
t,
|
|
82
|
+
n,
|
|
83
|
+
r
|
|
84
|
+
]);
|
|
85
|
+
return i.length === 0 ? null : /* @__PURE__ */ M(T, {
|
|
86
|
+
fullscreen: !0,
|
|
87
|
+
style: { pointerEvents: "none" },
|
|
88
|
+
children: /* @__PURE__ */ M("div", {
|
|
89
|
+
"aria-hidden": "true",
|
|
90
|
+
style: {
|
|
91
|
+
display: "grid",
|
|
92
|
+
gridTemplateColumns: `repeat(${t.columns}, minmax(0, 1fr))`,
|
|
93
|
+
gridTemplateRows: `repeat(${t.rows}, minmax(0, 1fr))`,
|
|
94
|
+
height: "100%",
|
|
95
|
+
inset: 0,
|
|
96
|
+
pointerEvents: "none",
|
|
97
|
+
position: "absolute",
|
|
98
|
+
width: "100%"
|
|
99
|
+
},
|
|
100
|
+
children: i.map((e, t) => /* @__PURE__ */ M("div", {
|
|
101
|
+
style: {
|
|
102
|
+
minWidth: 0,
|
|
103
|
+
position: "relative"
|
|
104
|
+
},
|
|
105
|
+
children: /* @__PURE__ */ M("span", {
|
|
106
|
+
style: {
|
|
107
|
+
backdropFilter: "blur(8px)",
|
|
108
|
+
background: "rgba(0, 0, 0, 0.58)",
|
|
109
|
+
border: "1px solid rgba(255, 255, 255, 0.16)",
|
|
110
|
+
borderRadius: 4,
|
|
111
|
+
color: "#fff",
|
|
112
|
+
fontFamily: "monospace",
|
|
113
|
+
fontSize: 11,
|
|
114
|
+
left: 10,
|
|
115
|
+
letterSpacing: "0.04em",
|
|
116
|
+
lineHeight: 1,
|
|
117
|
+
padding: "6px 8px",
|
|
118
|
+
position: "absolute",
|
|
119
|
+
textTransform: "uppercase",
|
|
120
|
+
top: 10,
|
|
121
|
+
whiteSpace: "nowrap"
|
|
122
|
+
},
|
|
123
|
+
children: e
|
|
124
|
+
})
|
|
125
|
+
}, `${t}:${e}`))
|
|
126
|
+
})
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function L() {
|
|
130
|
+
return /* @__PURE__ */ M(T, {
|
|
131
|
+
fullscreen: !0,
|
|
132
|
+
style: { pointerEvents: "none" },
|
|
133
|
+
children: /* @__PURE__ */ N("div", {
|
|
134
|
+
"aria-hidden": "true",
|
|
135
|
+
style: {
|
|
136
|
+
alignItems: "center",
|
|
137
|
+
bottom: 42,
|
|
138
|
+
display: "flex",
|
|
139
|
+
flexDirection: "column",
|
|
140
|
+
gap: 6,
|
|
141
|
+
left: "50%",
|
|
142
|
+
pointerEvents: "none",
|
|
143
|
+
position: "absolute",
|
|
144
|
+
transform: "translateX(-50%)",
|
|
145
|
+
width: "min(560px, calc(100vw - 48px))",
|
|
146
|
+
zIndex: 20
|
|
147
|
+
},
|
|
148
|
+
children: [/* @__PURE__ */ N("div", {
|
|
149
|
+
style: {
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
background: "rgba(0, 0, 0, 0.62)",
|
|
152
|
+
border: "1px solid rgba(255, 255, 255, 0.16)",
|
|
153
|
+
borderRadius: 6,
|
|
154
|
+
boxShadow: "0 10px 32px rgba(0, 0, 0, 0.32)",
|
|
155
|
+
display: "grid",
|
|
156
|
+
gap: 8,
|
|
157
|
+
gridTemplateColumns: "auto 1fr auto",
|
|
158
|
+
padding: "8px 10px",
|
|
159
|
+
width: "100%"
|
|
160
|
+
},
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ M("span", {
|
|
163
|
+
style: R,
|
|
164
|
+
children: "cheap"
|
|
165
|
+
}),
|
|
166
|
+
/* @__PURE__ */ M("div", { style: {
|
|
167
|
+
background: "linear-gradient(90deg, #000 0%, #000 6%, #00ff1f 18%, #fff000 48%, #ff0d00 80%, #fff 100%)",
|
|
168
|
+
border: "1px solid rgba(255, 255, 255, 0.24)",
|
|
169
|
+
borderRadius: 999,
|
|
170
|
+
height: 12,
|
|
171
|
+
overflow: "hidden"
|
|
172
|
+
} }),
|
|
173
|
+
/* @__PURE__ */ M("span", {
|
|
174
|
+
style: R,
|
|
175
|
+
children: "expensive"
|
|
176
|
+
})
|
|
177
|
+
]
|
|
178
|
+
}), /* @__PURE__ */ M("div", {
|
|
179
|
+
style: {
|
|
180
|
+
color: "rgba(255, 255, 255, 0.7)",
|
|
181
|
+
fontFamily: "monospace",
|
|
182
|
+
fontSize: 10,
|
|
183
|
+
letterSpacing: "0.04em",
|
|
184
|
+
textTransform: "uppercase"
|
|
185
|
+
},
|
|
186
|
+
children: "estimated shader complexity · black = no rendered material"
|
|
187
|
+
})]
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
var R = {
|
|
192
|
+
color: "#fff",
|
|
193
|
+
fontFamily: "monospace",
|
|
194
|
+
fontSize: 10,
|
|
195
|
+
letterSpacing: "0.08em",
|
|
196
|
+
textTransform: "uppercase"
|
|
197
|
+
};
|
|
198
|
+
function z(e, t, n, r, i, a, o, s) {
|
|
199
|
+
let c = S(null);
|
|
200
|
+
return b(() => {
|
|
201
|
+
if (!e) return;
|
|
202
|
+
let l = H(t, n, r, i, a, o);
|
|
203
|
+
return r.usesAoFallback && s.apply(), c.current = l.pipeline, () => {
|
|
204
|
+
l.dispose(), s.restore(), c.current = null;
|
|
205
|
+
};
|
|
206
|
+
}, [
|
|
207
|
+
e,
|
|
208
|
+
t,
|
|
209
|
+
n,
|
|
210
|
+
r,
|
|
211
|
+
i,
|
|
212
|
+
a,
|
|
213
|
+
o,
|
|
214
|
+
s
|
|
215
|
+
]), c;
|
|
216
|
+
}
|
|
217
|
+
function B(e, t, n, r, i, s, c, l) {
|
|
218
|
+
let u = S(null);
|
|
219
|
+
return b(() => {
|
|
220
|
+
if (!e || !r || !i) return;
|
|
221
|
+
let f = i.passes.map((e) => {
|
|
222
|
+
let r = _([e.view], 0, V);
|
|
223
|
+
return {
|
|
224
|
+
plan: r,
|
|
225
|
+
runtime: H(t, e.camera ?? n, r, V, s, c, e.resolutionScale)
|
|
226
|
+
};
|
|
227
|
+
}), p = a(r), m = new k(), h = new A(), g = new A(), v = f.some((e) => e.plan.usesAoFallback);
|
|
228
|
+
return v && l.apply(), u.current = {
|
|
229
|
+
usesAoFallback: v,
|
|
230
|
+
render: () => {
|
|
231
|
+
s.getSize(m);
|
|
232
|
+
let e = s.getScissorTest();
|
|
233
|
+
s.getViewport(h), s.getScissor(g), s.setScissorTest(!1), s.setViewport(0, 0, m.x, m.y), s.clear(!0, !0, !1), s.setScissorTest(!0);
|
|
234
|
+
try {
|
|
235
|
+
for (let e of i.cells) {
|
|
236
|
+
let t = p[e.index], n = f[e.passIndex];
|
|
237
|
+
if (!t || !n) continue;
|
|
238
|
+
let r = o(t.scissor, m);
|
|
239
|
+
s.setViewport(r.x, r.y, r.width, r.height), s.setScissor(r.x, r.y, r.width, r.height), d(c, 0, V, 1, 1), n.runtime.pipeline.render();
|
|
240
|
+
}
|
|
241
|
+
} finally {
|
|
242
|
+
s.setViewport(h), s.setScissor(g), s.setScissorTest(e);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}, () => {
|
|
246
|
+
for (let e of f) e.runtime.dispose();
|
|
247
|
+
l.restore(), u.current = null;
|
|
248
|
+
};
|
|
249
|
+
}, [
|
|
250
|
+
e,
|
|
251
|
+
t,
|
|
252
|
+
n,
|
|
253
|
+
r,
|
|
254
|
+
i,
|
|
255
|
+
s,
|
|
256
|
+
c,
|
|
257
|
+
l
|
|
258
|
+
]), u;
|
|
259
|
+
}
|
|
260
|
+
var V = {
|
|
261
|
+
mode: "single",
|
|
262
|
+
presentation: "single",
|
|
263
|
+
columns: 1,
|
|
264
|
+
rows: 1,
|
|
265
|
+
slots: 1
|
|
266
|
+
};
|
|
267
|
+
function H(e, r, i, a, o, s, c = 1) {
|
|
268
|
+
let u = y(e, r);
|
|
269
|
+
u.setResolutionScale(c), m(u, i.sceneOutputs), g(u, i.sceneTextureTypes);
|
|
270
|
+
let d = i.usesMaterialDetailPass ? y(e, r) : void 0;
|
|
271
|
+
d && (d.setResolutionScale(c), p(d, i.materialDetailOutputs), g(d, i.materialDetailTextureTypes));
|
|
272
|
+
let f = i.usesWireframePass ? y(e, r) : void 0;
|
|
273
|
+
f && (f.setResolutionScale(c), f.overrideMaterial = new D({
|
|
274
|
+
color: 16777215,
|
|
275
|
+
wireframe: !0,
|
|
276
|
+
toneMapped: !1
|
|
277
|
+
}));
|
|
278
|
+
let _ = i.usesLightingOnlyPass ? y(e, r) : void 0;
|
|
279
|
+
_ && (_.setResolutionScale(c), _.overrideMaterial = new O({
|
|
280
|
+
color: 16777215,
|
|
281
|
+
metalness: 0,
|
|
282
|
+
roughness: .72
|
|
283
|
+
}));
|
|
284
|
+
let b = i.usesReflectionOnlyPass ? y(e, r) : void 0;
|
|
285
|
+
b && (b.setResolutionScale(c), b.overrideMaterial = new O({
|
|
286
|
+
color: 0,
|
|
287
|
+
metalness: 1,
|
|
288
|
+
roughness: .18
|
|
289
|
+
}));
|
|
290
|
+
let x = i.usesShaderCostPass ? v() : void 0, S = i.usesShaderCostPass ? U(e, r, c, x) : void 0, C = h(u, {
|
|
291
|
+
lightingOnlyPass: _,
|
|
292
|
+
materialDetailPass: d,
|
|
293
|
+
reflectionOnlyPass: b,
|
|
294
|
+
shaderCostPass: S,
|
|
295
|
+
wireframePass: f
|
|
296
|
+
}), w = new E(o, l({
|
|
297
|
+
views: i.views.map((e) => ({
|
|
298
|
+
...e,
|
|
299
|
+
mode: n(e),
|
|
300
|
+
node: e.node ?? C(t(e))
|
|
301
|
+
})),
|
|
302
|
+
uniforms: s,
|
|
303
|
+
layout: a
|
|
304
|
+
}));
|
|
305
|
+
return {
|
|
306
|
+
pipeline: w,
|
|
307
|
+
dispose: () => {
|
|
308
|
+
w.dispose(), u.dispose(), d?.dispose(), _?.overrideMaterial?.dispose(), _?.dispose(), b?.overrideMaterial?.dispose(), b?.dispose(), S?.dispose(), x?.dispose(), f?.overrideMaterial?.dispose(), f?.dispose();
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function U(e, t, n, r) {
|
|
313
|
+
let i = y(e, t);
|
|
314
|
+
i.setResolutionScale(n);
|
|
315
|
+
let a = i.updateBefore.bind(i);
|
|
316
|
+
return i.updateBefore = (t) => {
|
|
317
|
+
let n = r?.apply(e);
|
|
318
|
+
try {
|
|
319
|
+
return a(t);
|
|
320
|
+
} finally {
|
|
321
|
+
n?.restore();
|
|
322
|
+
}
|
|
323
|
+
}, i;
|
|
324
|
+
}
|
|
325
|
+
function W(e) {
|
|
326
|
+
return e;
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
export { P as DebugViews };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { DataTexture as e, Material as t, RGBAFormat as n } from "three";
|
|
2
|
+
//#region components/debug-views/debug-views-tsl/ao-fallbacks.ts
|
|
3
|
+
var r = new e(new Uint8Array([
|
|
4
|
+
255,
|
|
5
|
+
255,
|
|
6
|
+
255,
|
|
7
|
+
255
|
|
8
|
+
]), 1, 1, n);
|
|
9
|
+
r.needsUpdate = !0;
|
|
10
|
+
function i(e) {
|
|
11
|
+
let n = /* @__PURE__ */ new WeakMap(), r = [], i = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = t.prototype, f = a(d), p = !1;
|
|
12
|
+
function m() {
|
|
13
|
+
p ||= (o(d), !0), e.traverse(_);
|
|
14
|
+
}
|
|
15
|
+
function h() {
|
|
16
|
+
for (let e of c) S(e);
|
|
17
|
+
}
|
|
18
|
+
function g() {
|
|
19
|
+
for (let e of [...r]) D(e);
|
|
20
|
+
p &&= (s(f), !1), r.length = 0;
|
|
21
|
+
for (let e of i) e.removeEventListener("childadded", y), e.removeEventListener("childremoved", b);
|
|
22
|
+
i.clear(), c.clear(), l.clear(), u.clear();
|
|
23
|
+
}
|
|
24
|
+
function _(e) {
|
|
25
|
+
v(e), S(e);
|
|
26
|
+
}
|
|
27
|
+
function v(e) {
|
|
28
|
+
i.has(e) || (e.addEventListener("childadded", y), e.addEventListener("childremoved", b), i.add(e));
|
|
29
|
+
}
|
|
30
|
+
function y(e) {
|
|
31
|
+
e.child.traverse(_);
|
|
32
|
+
}
|
|
33
|
+
function b(e) {
|
|
34
|
+
e.child.traverse(x);
|
|
35
|
+
}
|
|
36
|
+
function x(e) {
|
|
37
|
+
w(e), c.delete(e), i.delete(e) && (e.removeEventListener("childadded", y), e.removeEventListener("childremoved", b));
|
|
38
|
+
}
|
|
39
|
+
function S(e) {
|
|
40
|
+
let t = e.material, n = t ? E(t) : /* @__PURE__ */ new Set(), r = l.get(e);
|
|
41
|
+
if (r) for (let e of r) n.has(e) || T(e);
|
|
42
|
+
for (let e of n) r?.has(e) || C(e);
|
|
43
|
+
n.size > 0 ? (c.add(e), l.set(e, n)) : (c.delete(e), l.delete(e));
|
|
44
|
+
}
|
|
45
|
+
function C(e) {
|
|
46
|
+
let t = u.get(e);
|
|
47
|
+
if (t !== void 0) {
|
|
48
|
+
u.set(e, t + 1);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (e.aoMap?.isTexture === !0) return;
|
|
52
|
+
let i = a(e);
|
|
53
|
+
n.set(e, i), r.push(i), u.set(e, 1), o(e);
|
|
54
|
+
}
|
|
55
|
+
function w(e) {
|
|
56
|
+
let t = l.get(e);
|
|
57
|
+
if (t) {
|
|
58
|
+
for (let e of t) T(e);
|
|
59
|
+
l.delete(e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function T(e) {
|
|
63
|
+
let t = u.get(e);
|
|
64
|
+
if (t === void 0) return;
|
|
65
|
+
if (t > 1) {
|
|
66
|
+
u.set(e, t - 1);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
u.delete(e);
|
|
70
|
+
let r = n.get(e);
|
|
71
|
+
r && D(r);
|
|
72
|
+
}
|
|
73
|
+
function E(e) {
|
|
74
|
+
return Array.isArray(e) ? new Set(e) : new Set([e]);
|
|
75
|
+
}
|
|
76
|
+
function D(e) {
|
|
77
|
+
s(e), n.delete(e.material), u.delete(e.material);
|
|
78
|
+
let t = r.indexOf(e);
|
|
79
|
+
t >= 0 && r.splice(t, 1);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
apply: m,
|
|
83
|
+
refresh: h,
|
|
84
|
+
restore: g
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function a(e) {
|
|
88
|
+
return {
|
|
89
|
+
hadAoMap: Object.prototype.hasOwnProperty.call(e, "aoMap"),
|
|
90
|
+
hadAoMapIntensity: Object.prototype.hasOwnProperty.call(e, "aoMapIntensity"),
|
|
91
|
+
material: e,
|
|
92
|
+
previousAoMap: e.aoMap,
|
|
93
|
+
previousAoMapIntensity: e.aoMapIntensity
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function o(e) {
|
|
97
|
+
e.aoMap = r, e.aoMapIntensity = 0, e.needsUpdate = !0;
|
|
98
|
+
}
|
|
99
|
+
function s(e) {
|
|
100
|
+
e.hadAoMap ? e.material.aoMap = e.previousAoMap : delete e.material.aoMap, e.hadAoMapIntensity ? e.material.aoMapIntensity = e.previousAoMapIntensity : delete e.material.aoMapIntensity, e.material.needsUpdate = !0;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { i as createAoFallbacks };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LAYOUT_INDEX as e, isResolvedDebugViewLayout as t, resolveDebugViewLayout as n } from "../debug-view-layout.js";
|
|
2
|
+
import { visualizeDepth as r, visualizeHeatmap as i, visualizeNormal as a } from "./visualize.js";
|
|
3
|
+
import { float as o, mix as s, screenUV as c, vec4 as l } from "three/tsl";
|
|
4
|
+
//#region components/debug-views/debug-views-tsl/compositor.ts
|
|
5
|
+
function u(t) {
|
|
6
|
+
let { views: n, uniforms: r, layout: i } = t;
|
|
7
|
+
if (n.length === 0) return l(0, 0, 0, 1);
|
|
8
|
+
let a = n.map((e) => g(e));
|
|
9
|
+
if (i) return d(i, a, r);
|
|
10
|
+
let s = f(a, r.activeView), c = p(a, r.overlayOpacity), u = m(a, r.viewCount, 2, 1), h = m(a, r.viewCount, 1, 2), _ = m(a, r.viewCount, 2, 2), v = m(a, r.viewCount, r.gridColumns, r.gridRows), y = r.layout.equal(o(e.single)), b = r.layout.equal(o(e.overlay)), x = r.layout.equal(o(e["split-h"])), S = r.layout.equal(o(e["split-v"])), C = r.layout.equal(o(e.quad));
|
|
11
|
+
return y.select(s, b.select(c, x.select(u, S.select(h, C.select(_, v)))));
|
|
12
|
+
}
|
|
13
|
+
function d(e, r, i) {
|
|
14
|
+
let a = t(e) ? e : n(e);
|
|
15
|
+
switch (a.presentation) {
|
|
16
|
+
case "single": return f(r, i.activeView);
|
|
17
|
+
case "overlay": return p(r, i.overlayOpacity);
|
|
18
|
+
case "grid": return m(r, i.viewCount, a.columns, a.rows);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function f(e, t) {
|
|
22
|
+
let n = e[0];
|
|
23
|
+
for (let r = 1; r < e.length; r++) n = t.greaterThan(o(r - .5)).select(e[r], n);
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
function p(e, t) {
|
|
27
|
+
if (e.length === 1) return e[0];
|
|
28
|
+
let n = e[0];
|
|
29
|
+
for (let r = 1; r < e.length; r++) n = s(n, e[r], t);
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
function m(e, t, n, r) {
|
|
33
|
+
let i = c, a = h(n), s = h(r), u = i.x.mul(a).floor(), d = s.sub(o(1)).sub(i.y.mul(s).floor()).mul(a).add(u), f = o(.003), p = i.x.mul(a).fract(), m = i.y.mul(s).fract(), g = p.lessThan(f).or(m.lessThan(f)), _ = e[0];
|
|
34
|
+
for (let t = 1; t < e.length; t++) _ = d.equal(o(t)).select(e[t], _);
|
|
35
|
+
return _ = d.greaterThanEqual(t).select(e[0], _), _ = g.select(l(.12, .12, .12, 1), _), _;
|
|
36
|
+
}
|
|
37
|
+
function h(e) {
|
|
38
|
+
return typeof e == "number" ? o(e) : e;
|
|
39
|
+
}
|
|
40
|
+
function g(e) {
|
|
41
|
+
let { node: t, mode: n = "passthrough", scale: s, bias: c } = e;
|
|
42
|
+
if (!t) return l(0, 0, 0, 1);
|
|
43
|
+
switch (n) {
|
|
44
|
+
case "normal": return a(t);
|
|
45
|
+
case "depth": return r(t, s === void 0 ? void 0 : o(s), c === void 0 ? void 0 : o(c));
|
|
46
|
+
case "heatmap": return i(t, s === void 0 ? void 0 : o(s), c === void 0 ? void 0 : o(c));
|
|
47
|
+
default: return t;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { u as createViewCompositor };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { directionToColor as e, float as t, materialAO as n, materialColor as r, materialEmissive as i, materialMetalness as a, materialNormal as o, materialOpacity as s, materialRoughness as c, mrt as l, normalView as u, output as d, vec4 as f } from "three/tsl";
|
|
2
|
+
//#region components/debug-views/debug-views-tsl/default-debug-nodes.ts
|
|
3
|
+
var p = f(0, 0, 0, 1);
|
|
4
|
+
function m(t, n) {
|
|
5
|
+
let i = { output: b(d) };
|
|
6
|
+
n.normal && (i.normal = y(e(b(u)))), n.albedo && (i.albedo = y(b(r).rgb)), n.material && (i.material = _(n.material)), t.setMRT(l(i));
|
|
7
|
+
}
|
|
8
|
+
function h(t, n) {
|
|
9
|
+
let r = { output: p };
|
|
10
|
+
n.materialNormal && (r.materialNormal = y(e(b(o)))), n.emissive && (r.emissive = y(b(i).rgb)), t.setMRT(l(r));
|
|
11
|
+
}
|
|
12
|
+
function g(e, t = {}) {
|
|
13
|
+
let n = /* @__PURE__ */ new Map();
|
|
14
|
+
function r(e, t) {
|
|
15
|
+
let r = n.get(e);
|
|
16
|
+
if (r) return r;
|
|
17
|
+
let i = t();
|
|
18
|
+
return n.set(e, i), i;
|
|
19
|
+
}
|
|
20
|
+
function i() {
|
|
21
|
+
return b(r("material", () => e.getTextureNode("material")));
|
|
22
|
+
}
|
|
23
|
+
return function(n) {
|
|
24
|
+
switch (n) {
|
|
25
|
+
case "beauty":
|
|
26
|
+
case "passthrough": return r("beauty", () => e.getTextureNode("output"));
|
|
27
|
+
case "normal": return r("normal", () => e.getTextureNode("normal"));
|
|
28
|
+
case "depth": return r("depth", () => e.getViewZNode("depth").mul(-1));
|
|
29
|
+
case "albedo":
|
|
30
|
+
case "baseColor": return r("albedo", () => e.getTextureNode("albedo"));
|
|
31
|
+
case "materialNormal":
|
|
32
|
+
case "normalMap": return r(n, () => t.materialDetailPass?.getTextureNode("materialNormal") ?? p);
|
|
33
|
+
case "emissive": return r("emissive", () => t.materialDetailPass?.getTextureNode("emissive") ?? p);
|
|
34
|
+
case "roughness": return r("roughness", () => v(i().r));
|
|
35
|
+
case "metalness":
|
|
36
|
+
case "metallic": return r(n, () => v(i().g));
|
|
37
|
+
case "opacity": return r("opacity", () => v(i().a));
|
|
38
|
+
case "transparency": return r("transparency", () => v(i().a.oneMinus()));
|
|
39
|
+
case "ao": return r("ao", () => v(i().b));
|
|
40
|
+
case "wireframe": return r("wireframe", () => t.wireframePass?.getTextureNode("output") ?? p);
|
|
41
|
+
case "lightingOnly": return r("lightingOnly", () => t.lightingOnlyPass?.getTextureNode("output") ?? p);
|
|
42
|
+
case "reflectionOnly": return r("reflectionOnly", () => t.reflectionOnlyPass?.getTextureNode("output") ?? p);
|
|
43
|
+
case "shaderCost": return r("shaderCost", () => b(t.shaderCostPass?.getTextureNode("output") ?? p).r);
|
|
44
|
+
default: return r("beauty", () => e.getTextureNode("output"));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function _(e) {
|
|
49
|
+
return f(e.roughness ? b(c) : t(0), e.metalness ? b(a) : t(0), e.ao ? b(n) : t(0), e.opacity ? b(s) : t(1));
|
|
50
|
+
}
|
|
51
|
+
function v(e) {
|
|
52
|
+
return f(e, e, e, 1);
|
|
53
|
+
}
|
|
54
|
+
function y(e) {
|
|
55
|
+
return f(e.x, e.y, e.z, 1);
|
|
56
|
+
}
|
|
57
|
+
function b(e) {
|
|
58
|
+
return e;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { h as configureMaterialDetailPass, m as configureSceneDebugPass, g as createDefaultDebugNodeResolver };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LAYOUT_INDEX as e, resolveDebugViewLayout as t } from "../debug-view-layout.js";
|
|
2
|
+
import { uniform as n } from "three/tsl";
|
|
3
|
+
//#region components/debug-views/debug-views-tsl/uniforms.ts
|
|
4
|
+
function r() {
|
|
5
|
+
return {
|
|
6
|
+
activeView: n(0),
|
|
7
|
+
layout: n(0),
|
|
8
|
+
viewCount: n(3),
|
|
9
|
+
gridColumns: n(2),
|
|
10
|
+
gridRows: n(2),
|
|
11
|
+
overlayOpacity: n(.35)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function i(n, r, i = "single", a = 1, o = .35) {
|
|
15
|
+
let s = t(i), c = Math.max(1, a);
|
|
16
|
+
n.activeView.value = Math.max(0, Math.min(r, c - 1)), n.layout.value = e[s.mode], n.viewCount.value = c, n.gridColumns.value = s.columns, n.gridRows.value = s.rows, n.overlayOpacity.value = Math.max(0, Math.min(o, 1));
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { r as createDebugViewUniforms, i as updateDebugViewUniforms };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { clamp as e, float as t, mix as n, vec4 as r } from "three/tsl";
|
|
2
|
+
//#region components/debug-views/debug-views-tsl/visualize.ts
|
|
3
|
+
var i = .1;
|
|
4
|
+
function a(e) {
|
|
5
|
+
let t = e.xyz.mul(.5).add(.5);
|
|
6
|
+
return r(t.x, t.y, t.z, 1);
|
|
7
|
+
}
|
|
8
|
+
function o(n, i = t(1), a = t(0)) {
|
|
9
|
+
let o = e(n.mul(i).add(a), 0, 1);
|
|
10
|
+
return r(o, o, o, 1);
|
|
11
|
+
}
|
|
12
|
+
function s(n, a = t(i), o = t(0)) {
|
|
13
|
+
let s = e(n.mul(a).add(o), 0, 1), c = t(1).sub(s);
|
|
14
|
+
return r(c, c, c, 1);
|
|
15
|
+
}
|
|
16
|
+
function c(i, a = t(1), o = t(0)) {
|
|
17
|
+
let s = e(i.mul(a).add(o), 0, 1), c = r(0, 1, .12, 1), l = r(1, .9, 0, 1), u = r(1, .05, 0, 1), d = r(1, 1, 1, 1), f = e(s.sub(.25).mul(2.857143), 0, 1), p = e(s.sub(.6).mul(3.333333), 0, 1), m = e(s.sub(.9).mul(10), 0, 1), h = n(c, l, f), g = n(l, u, p), _ = n(u, d, m), v = s.lessThan(.6).select(h, s.lessThan(.9).select(g, _));
|
|
18
|
+
return s.lessThan(.001).select(r(0, 0, 0, 1), v);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { s as visualizeDepth, o as visualizeGrayscale, c as visualizeHeatmap, a as visualizeNormal };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_DEBUG_VIEWS as e, MATERIAL_DEBUG_VIEW_SOURCES as t, getDebugViewLabels as n } from "./debug-view-definitions.js";
|
|
2
|
+
import { createCustomDebugView as r } from "./custom-debug-view.js";
|
|
3
|
+
import { LAYOUT_INDEX as i, isResolvedDebugViewLayout as a, resolveDebugViewLayout as o } from "./debug-view-layout.js";
|
|
4
|
+
import { createDebugViewportPlan as s } from "./debug-viewport-plan.js";
|
|
5
|
+
import { createDebugViewportRenderGraphPlan as c } from "./debug-render-graph-plan.js";
|
|
6
|
+
import { createDebugViewportRects as l } from "./debug-viewport-presenter.js";
|
|
7
|
+
import { createDebugViewportLabels as u, createDebugViewportPlanLabels as d } from "./debug-viewport-labels.js";
|
|
8
|
+
import { visualizeDepth as f, visualizeGrayscale as p, visualizeHeatmap as m, visualizeNormal as h } from "./debug-views-tsl/visualize.js";
|
|
9
|
+
import { createViewCompositor as g } from "./debug-views-tsl/compositor.js";
|
|
10
|
+
import { createDebugViewUniforms as _, updateDebugViewUniforms as v } from "./debug-views-tsl/uniforms.js";
|
|
11
|
+
export { e as DEFAULT_DEBUG_VIEWS, i as LAYOUT_INDEX, t as MATERIAL_DEBUG_VIEW_SOURCES, r as createCustomDebugView, _ as createDebugViewUniforms, u as createDebugViewportLabels, s as createDebugViewportPlan, d as createDebugViewportPlanLabels, l as createDebugViewportRects, c as createDebugViewportRenderGraphPlan, g as createViewCompositor, n as getDebugViewLabels, a as isResolvedDebugViewLayout, o as resolveDebugViewLayout, v as updateDebugViewUniforms, f as visualizeDepth, p as visualizeGrayscale, m as visualizeHeatmap, h as visualizeNormal };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createMaterialCostCache as e } from "./material-cost.js";
|
|
2
|
+
import { Color as t, MeshBasicMaterial as n } from "three";
|
|
3
|
+
function r(t = {}) {
|
|
4
|
+
let n = u(t.bucketCount), r = t.cache ?? e(), a = i(n);
|
|
5
|
+
return {
|
|
6
|
+
apply(e) {
|
|
7
|
+
return o(e, a, r);
|
|
8
|
+
},
|
|
9
|
+
dispose() {
|
|
10
|
+
for (let e of a) e.dispose();
|
|
11
|
+
},
|
|
12
|
+
bucketCount: n,
|
|
13
|
+
materials: a
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function i(e = 16) {
|
|
17
|
+
let r = u(e);
|
|
18
|
+
return Array.from({ length: r }, (e, i) => {
|
|
19
|
+
let a = i / (r - 1);
|
|
20
|
+
return new n({
|
|
21
|
+
color: new t(a, a, a),
|
|
22
|
+
depthTest: !0,
|
|
23
|
+
depthWrite: !0,
|
|
24
|
+
name: `ShaderCostBucket:${i}`,
|
|
25
|
+
toneMapped: !1
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function a(e, t = 16) {
|
|
30
|
+
let n = u(t);
|
|
31
|
+
return Math.round(Math.max(0, Math.min(1, e)) * (n - 1));
|
|
32
|
+
}
|
|
33
|
+
function o(e, t, n) {
|
|
34
|
+
let r = [];
|
|
35
|
+
e.traverse((e) => {
|
|
36
|
+
l(e) && (r.push({
|
|
37
|
+
mesh: e,
|
|
38
|
+
material: e.material
|
|
39
|
+
}), e.material = s(e.material, t, n));
|
|
40
|
+
});
|
|
41
|
+
let i = !1;
|
|
42
|
+
return {
|
|
43
|
+
restore() {
|
|
44
|
+
if (!i) {
|
|
45
|
+
for (let e of r) e.mesh.material = e.material;
|
|
46
|
+
i = !0;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
get replacements() {
|
|
50
|
+
return r.length;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function s(e, t, n) {
|
|
55
|
+
return Array.isArray(e) ? e.map((e) => c(e, t, n)) : c(e, t, n);
|
|
56
|
+
}
|
|
57
|
+
function c(e, t, n) {
|
|
58
|
+
return t[a(n.get(e).cost, t.length)];
|
|
59
|
+
}
|
|
60
|
+
function l(e) {
|
|
61
|
+
return !!(e.isMesh && e.material);
|
|
62
|
+
}
|
|
63
|
+
function u(e = 16) {
|
|
64
|
+
return Math.max(2, Math.floor(e));
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { r as createShaderCostOverride };
|