material-designer-runtime 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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/document.d.ts +32 -0
  4. package/dist/graph/bake-service.d.ts +84 -0
  5. package/dist/graph/channel-baker.d.ts +10 -0
  6. package/dist/graph/compiler.d.ts +36 -0
  7. package/dist/graph/nodes/color/blend.d.ts +2 -0
  8. package/dist/graph/nodes/color/bright-contrast.d.ts +2 -0
  9. package/dist/graph/nodes/color/hue-sat-val.d.ts +2 -0
  10. package/dist/graph/nodes/color/invert.d.ts +2 -0
  11. package/dist/graph/nodes/color/rgb-curves.d.ts +2 -0
  12. package/dist/graph/nodes/converter/adapters.d.ts +4 -0
  13. package/dist/graph/nodes/converter/clamp.d.ts +2 -0
  14. package/dist/graph/nodes/converter/color-ramp.d.ts +2 -0
  15. package/dist/graph/nodes/converter/height-blend.d.ts +2 -0
  16. package/dist/graph/nodes/converter/levels.d.ts +2 -0
  17. package/dist/graph/nodes/converter/math.d.ts +2 -0
  18. package/dist/graph/nodes/converter/xyz.d.ts +3 -0
  19. package/dist/graph/nodes/group/group.d.ts +4 -0
  20. package/dist/graph/nodes/input/constant.d.ts +3 -0
  21. package/dist/graph/nodes/input/tex-coordinate.d.ts +2 -0
  22. package/dist/graph/nodes/output/material-output.d.ts +2 -0
  23. package/dist/graph/nodes/shader/emission.d.ts +2 -0
  24. package/dist/graph/nodes/shader/mix-shader.d.ts +2 -0
  25. package/dist/graph/nodes/shader/principled-bsdf.d.ts +2 -0
  26. package/dist/graph/nodes/texture/anisotropic-stripes.d.ts +2 -0
  27. package/dist/graph/nodes/texture/checker.d.ts +2 -0
  28. package/dist/graph/nodes/texture/fbm.d.ts +2 -0
  29. package/dist/graph/nodes/texture/gradient.d.ts +2 -0
  30. package/dist/graph/nodes/texture/scatter.d.ts +2 -0
  31. package/dist/graph/nodes/texture/screen-noise.d.ts +2 -0
  32. package/dist/graph/nodes/texture/shape.d.ts +2 -0
  33. package/dist/graph/nodes/texture/tile.d.ts +2 -0
  34. package/dist/graph/nodes/texture/tileable-noise.d.ts +2 -0
  35. package/dist/graph/nodes/texture/voronoi.d.ts +2 -0
  36. package/dist/graph/nodes/texture/wave.d.ts +2 -0
  37. package/dist/graph/nodes/vector/domain-warp.d.ts +2 -0
  38. package/dist/graph/nodes/vector/mapping.d.ts +2 -0
  39. package/dist/graph/nodes/vector/normal-from-height.d.ts +2 -0
  40. package/dist/graph/nodes/vector/normal-map.d.ts +2 -0
  41. package/dist/graph/nodes/vector/tileable-warp.d.ts +2 -0
  42. package/dist/graph/nodes/vector/vector-math.d.ts +2 -0
  43. package/dist/graph/registry.d.ts +15 -0
  44. package/dist/graph/textured-surface.d.ts +60 -0
  45. package/dist/graph/tiling-test.d.ts +21 -0
  46. package/dist/graph/types.d.ts +153 -0
  47. package/dist/index.d.ts +9 -0
  48. package/dist/index.js +4437 -0
  49. package/dist/runtime.d.ts +36 -0
  50. package/dist/topology.d.ts +3 -0
  51. package/dist/tsl/blender-color.d.ts +5 -0
  52. package/dist/tsl/blender-gradient.d.ts +4 -0
  53. package/dist/tsl/blender-mapping.d.ts +4 -0
  54. package/dist/tsl/blender-noise.d.ts +5 -0
  55. package/dist/tsl/blender-voronoi.d.ts +13 -0
  56. package/dist/tsl/blender-wave.d.ts +14 -0
  57. package/dist/tsl/curve.d.ts +4 -0
  58. package/dist/tsl/lloyd-points.d.ts +9 -0
  59. package/dist/tsl/noise/cellular.d.ts +5 -0
  60. package/dist/tsl/noise/erosion.d.ts +4 -0
  61. package/dist/tsl/noise/fbm.d.ts +5 -0
  62. package/dist/tsl/noise/flow.d.ts +8 -0
  63. package/dist/tsl/noise/gabor.d.ts +1 -0
  64. package/dist/tsl/noise/hash.d.ts +8 -0
  65. package/dist/tsl/noise/index.d.ts +8 -0
  66. package/dist/tsl/noise/screen.d.ts +8 -0
  67. package/dist/tsl/noise/simplex.d.ts +4 -0
  68. package/dist/tsl/noise/value.d.ts +4 -0
  69. package/dist/tsl/noise/wavelet.d.ts +4 -0
  70. package/dist/tsl/parallax.d.ts +5 -0
  71. package/dist/tsl/relaxed-voronoi.d.ts +7 -0
  72. package/dist/tsl/scatter.d.ts +16 -0
  73. package/dist/tsl/shape.d.ts +13 -0
  74. package/dist/tsl/tile.d.ts +23 -0
  75. package/dist/tsl/tileable-noise.d.ts +6 -0
  76. package/dist/tsl/triplanar-normal.d.ts +5 -0
  77. package/dist/tsl/triplanar.d.ts +6 -0
  78. package/dist/tsl/uv-debug-material.d.ts +2 -0
  79. package/package.json +63 -0
package/dist/index.js ADDED
@@ -0,0 +1,4437 @@
1
+ import * as e from "three";
2
+ import { NearestFilter as t, NoColorSpace as n, OrthographicCamera as r, RepeatWrapping as i, Scene as a, Vector3 as o } from "three";
3
+ import { MeshBasicNodeMaterial as s, MeshPhysicalNodeMaterial as c, QuadMesh as l, RenderTarget as u } from "three/webgpu";
4
+ import { Fn as d, abs as f, acos as p, asin as m, atan as h, attribute as g, bool as _, bumpMap as v, ceil as y, clamp as b, color as x, cos as S, cosh as C, cross as w, dFdx as T, dFdy as E, degrees as ee, dot as D, exp as O, exp2 as te, float as k, floatBitsToUint as ne, floor as A, fract as j, fwidth as re, int as M, inverseSqrt as ie, length as N, log as ae, luminance as oe, max as P, min as F, mix as I, mod as L, mx_noise_float as se, normalLocal as ce, normalMap as le, normalWorld as ue, normalize as de, parallaxDirection as fe, positionLocal as pe, positionWorld as me, pow as R, radians as he, reflect as ge, round as _e, sRGBTransferOETF as ve, saturate as ye, select as z, sign as be, sin as B, sinh as xe, smoothstep as V, sqrt as Se, step as Ce, tan as we, tanh as Te, texture as H, trunc as Ee, uint as U, uniform as W, uniformArray as De, uv as G, vec2 as K, vec3 as q, vec4 as Oe } from "three/tsl";
5
+ var ke = {
6
+ version: 2,
7
+ nodes: [{
8
+ id: "pr",
9
+ type: "principled-bsdf",
10
+ params: {},
11
+ position: {
12
+ x: 420,
13
+ y: 160
14
+ },
15
+ enabled: !0
16
+ }, {
17
+ id: "out",
18
+ type: "material-output",
19
+ params: {},
20
+ position: {
21
+ x: 740,
22
+ y: 180
23
+ },
24
+ enabled: !0
25
+ }],
26
+ edges: [{
27
+ fromNode: "pr",
28
+ fromOutput: "bsdf",
29
+ toNode: "out",
30
+ toInput: "surface"
31
+ }]
32
+ }, Ae = [
33
+ 0,
34
+ .25,
35
+ .5,
36
+ .75,
37
+ 1
38
+ ], je = [
39
+ "C",
40
+ "R",
41
+ "G",
42
+ "B"
43
+ ];
44
+ function Me(e) {
45
+ let t = (e) => Array.from({ length: 5 }, (t, n) => e?.[n] ?? Ae[n]);
46
+ return [
47
+ ...t(e?.C),
48
+ ...t(e?.R),
49
+ ...t(e?.G),
50
+ ...t(e?.B)
51
+ ];
52
+ }
53
+ var Ne = "group", Pe = "group-input", Fe = "group-output", Ie = "material-output", Le = [
54
+ "baseColor",
55
+ "normal",
56
+ "emission",
57
+ "roughness",
58
+ "metallic",
59
+ "ambientOcclusion"
60
+ ], Re = {
61
+ float: {
62
+ float: "identity",
63
+ vector: "float-to-vector",
64
+ color: "float-to-color"
65
+ },
66
+ vector: {
67
+ vector: "identity",
68
+ float: "vector-to-float",
69
+ color: "vector-to-color"
70
+ },
71
+ color: {
72
+ color: "identity",
73
+ float: "color-to-float",
74
+ vector: "color-to-vector"
75
+ },
76
+ shader: { shader: "identity" }
77
+ };
78
+ function ze(e, t) {
79
+ return Re[e]?.[t];
80
+ }
81
+ //#endregion
82
+ //#region src/tsl/blender-noise.ts
83
+ var J = (e, t) => e.shiftLeft(t).bitOr(e.shiftRight(32 - t));
84
+ function Be(e, t, n) {
85
+ let r = 3735928584, i = U(r).toVar(), a = U(r).toVar(), o = U(r).toVar();
86
+ return o.assign(o.add(n)), a.assign(a.add(t)), i.assign(i.add(e)), o.assign(o.bitXor(a)), o.assign(o.sub(J(a, 14))), i.assign(i.bitXor(o)), i.assign(i.sub(J(o, 11))), a.assign(a.bitXor(i)), a.assign(a.sub(J(i, 25))), o.assign(o.bitXor(a)), o.assign(o.sub(J(a, 16))), i.assign(i.bitXor(o)), i.assign(i.sub(J(o, 4))), a.assign(a.bitXor(i)), a.assign(a.sub(J(i, 14))), o.assign(o.bitXor(a)), o.assign(o.sub(J(a, 24))), o;
87
+ }
88
+ var Ve = (e, t, n) => Be(U(e), U(t), U(n)), He = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), Ue = (e, t) => z(t.notEqual(U(0)), e.negate(), e);
89
+ function We(e, t, n, r) {
90
+ let i = e.bitAnd(U(15)).toVar(), a = z(i.lessThan(U(8)), t, n), o = z(i.equal(U(12)).or(i.equal(U(14))), t, r), s = z(i.lessThan(U(4)), n, o);
91
+ return Ue(a, i.bitAnd(U(1))).add(Ue(s, i.bitAnd(U(2))));
92
+ }
93
+ function Ge(e, t, n, r) {
94
+ let i = k(1).sub(t), a = k(1).sub(n);
95
+ return k(1).sub(r).mul(a.mul(e[0].mul(i).add(e[1].mul(t))).add(n.mul(e[2].mul(i).add(e[3].mul(t))))).add(r.mul(a.mul(e[4].mul(i).add(e[5].mul(t))).add(n.mul(e[6].mul(i).add(e[7].mul(t))))));
96
+ }
97
+ function Ke(e) {
98
+ let t = A(e.x).toVar(), n = A(e.y).toVar(), r = A(e.z).toVar(), i = e.x.sub(t).toVar(), a = e.y.sub(n).toVar(), o = e.z.sub(r).toVar(), s = M(t), c = M(n), l = M(r), u = He(i), d = He(a), f = He(o), p = (e, t, n) => We(Ve(s.add(e), c.add(t), l.add(n)), i.sub(e), a.sub(t), o.sub(n));
99
+ return Ge([
100
+ p(0, 0, 0),
101
+ p(1, 0, 0),
102
+ p(0, 1, 0),
103
+ p(1, 1, 0),
104
+ p(0, 0, 1),
105
+ p(1, 0, 1),
106
+ p(0, 1, 1),
107
+ p(1, 1, 1)
108
+ ], u, d, f);
109
+ }
110
+ var qe = (e) => Ke(e).mul(.982);
111
+ function Je(e, t, n, r) {
112
+ let i = Math.max(0, Math.min(15, Math.floor(t)));
113
+ return d(() => {
114
+ let t = k(1).toVar(), a = k(1).toVar(), o = k(0).toVar(), s = k(0).toVar();
115
+ for (let c = 0; c <= i; c++) o.assign(o.add(qe(e.mul(a)).mul(t))), s.assign(s.add(t)), t.assign(t.mul(n)), a.assign(a.mul(r));
116
+ return o.div(s).mul(.5).add(.5);
117
+ })();
118
+ }
119
+ //#endregion
120
+ //#region src/graph/nodes/texture/fbm.ts
121
+ var Ye = {
122
+ type: "fbm",
123
+ nodeClass: "texture",
124
+ label: "Noise (FBM)",
125
+ inputs: [{
126
+ key: "coord",
127
+ kind: "vector"
128
+ }],
129
+ outputs: [{
130
+ key: "field",
131
+ kind: "float"
132
+ }],
133
+ params: [
134
+ {
135
+ key: "scale",
136
+ label: "scale",
137
+ type: "float",
138
+ min: .1,
139
+ max: 8,
140
+ step: .05,
141
+ default: 1.2
142
+ },
143
+ {
144
+ key: "octaves",
145
+ label: "detail",
146
+ type: "int",
147
+ min: 0,
148
+ max: 15,
149
+ step: 1,
150
+ default: 4
151
+ },
152
+ {
153
+ key: "lacunarity",
154
+ label: "lacunarity",
155
+ type: "float",
156
+ min: 1.5,
157
+ max: 3,
158
+ step: .05,
159
+ default: 2
160
+ },
161
+ {
162
+ key: "gain",
163
+ label: "roughness",
164
+ type: "float",
165
+ min: 0,
166
+ max: 1,
167
+ step: .01,
168
+ default: .5
169
+ }
170
+ ],
171
+ build(e) {
172
+ return { field: Je((e.inputs.coord ?? e.coord).mul(e.uniforms.scale), e.params.octaves ?? 4, e.uniforms.gain, e.uniforms.lacunarity) };
173
+ }
174
+ }, Xe = {
175
+ type: "domain-warp",
176
+ nodeClass: "vector",
177
+ label: "Domain Warp",
178
+ inputs: [{
179
+ key: "coord",
180
+ kind: "vector"
181
+ }],
182
+ outputs: [{
183
+ key: "coord",
184
+ kind: "vector"
185
+ }],
186
+ params: [{
187
+ key: "amount",
188
+ label: "amount",
189
+ type: "float",
190
+ min: 0,
191
+ max: 2,
192
+ step: .01,
193
+ default: .3
194
+ }, {
195
+ key: "scale",
196
+ label: "scale",
197
+ type: "float",
198
+ min: .1,
199
+ max: 8,
200
+ step: .05,
201
+ default: 1
202
+ }],
203
+ build(e) {
204
+ let t = e.inputs.coord ?? e.coord, n = t.div(e.uniforms.scale), r = se(n.add(q(11.3, 0, 0))), i = se(n.add(q(0, 47.7, 0))), a = se(n.add(q(0, 0, 93.1)));
205
+ return { coord: t.add(q(r, i, a).mul(e.uniforms.amount)) };
206
+ }
207
+ }, Ze = (e) => L(e.mul(34).add(1).mul(e), 289), Qe = (e) => e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10)), $e = d(([e, t]) => {
208
+ let n = A(e.xyxy).add(Oe(0, 0, 1, 1)), r = j(e.xyxy).sub(Oe(0, 0, 1, 1)), i = L(L(n, t.xyxy), 289), a = i.xzxz, o = i.yyww, s = r.xzxz, c = r.yyww, l = j(Ze(Ze(a).add(o)).mul(.0243902439)).mul(2).sub(1), u = f(l).sub(.5), d = l.sub(A(l.add(.5))), p = K(d.x, u.x), m = K(d.y, u.y), h = K(d.z, u.z), g = K(d.w, u.w), _ = k(1.79284291400159).sub(k(.85373472095314).mul(Oe(D(p, p), D(h, h), D(m, m), D(g, g))));
209
+ p = p.mul(_.x), h = h.mul(_.y), m = m.mul(_.z), g = g.mul(_.w);
210
+ let v = D(p, K(s.x, c.x)), y = D(m, K(s.y, c.y)), b = D(h, K(s.z, c.z)), x = D(g, K(s.w, c.w)), S = Qe(r.xy), C = I(K(v, b), K(y, x), S.x);
211
+ return I(C.x, C.y, S.y).mul(2.3);
212
+ });
213
+ function et(e, t, n, r, i, a, o = 2) {
214
+ let s = typeof t == "number" ? k(Math.max(1, Math.round(t))) : t, c = typeof n == "number" ? k(Math.max(1, Math.round(n))) : n, l = re(e), u = k(0), d = k(0), f = k(1), p = Math.max(2, Math.round(o));
215
+ for (let t = 0; t < Math.max(1, r); t++) {
216
+ let n = Math.round(p ** +t), r = K(s.mul(n), c.mul(n)), o = f;
217
+ if (a !== void 0) {
218
+ let e = P(r.x.mul(l.x), r.y.mul(l.y)), t = b(k(1).sub(V(.2, .5, e)), 0, 1);
219
+ o = f.mul(I(k(1), t, a));
220
+ }
221
+ u = u.add(o.mul($e(e.mul(r), r))), d = d.add(o), f = f.mul(i);
222
+ }
223
+ return I(k(0), u.div(d.max(1e-4)), F(d, 1));
224
+ }
225
+ //#endregion
226
+ //#region src/tsl/noise/fbm.ts
227
+ function tt(e, t, n, r, i, a, o, s = 2) {
228
+ let c = typeof t == "number" ? k(Math.max(1, Math.round(t))) : t, l = typeof n == "number" ? k(Math.max(1, Math.round(n))) : n, u = re(e), d = k(0), f = k(0), p = k(1), m = Math.max(2, Math.round(s));
229
+ for (let t = 0; t < Math.max(1, r); t++) {
230
+ let n = Math.round(m ** +t), r = c.mul(n), s = l.mul(n), h = e.mul(K(r, s)), g = p;
231
+ if (o !== void 0) {
232
+ let e = P(r.mul(u.x), s.mul(u.y)), t = b(k(1).sub(V(.2, .5, e)), 0, 1);
233
+ g = p.mul(I(k(1), t, o));
234
+ }
235
+ d = d.add(g.mul(a(h, r, s))), f = f.add(g), p = p.mul(i);
236
+ }
237
+ return I(k(.5), d.div(f.max(1e-4)), F(f, 1));
238
+ }
239
+ //#endregion
240
+ //#region src/tsl/noise/hash.ts
241
+ var nt = 1 / 2147483648, rt = d(([e, t, n]) => {
242
+ let r = e.mul(1664525).add(1013904223).toVar(), i = t.mul(1664525).add(1013904223).toVar(), a = n.mul(1664525).add(1013904223).toVar();
243
+ r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i))), r.assign(r.bitXor(r.shiftRight(16))), i.assign(i.bitXor(i.shiftRight(16))), a.assign(a.bitXor(a.shiftRight(16))), r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i)));
244
+ let o = M(2147483647);
245
+ return q(k(r.bitAnd(o)).mul(nt), k(i.bitAnd(o)).mul(nt), k(a.bitAnd(o)).mul(nt));
246
+ });
247
+ function it(e, t) {
248
+ return typeof t == "number" && t <= 0 ? e : e.sub(M(A(k(e).div(t))).mul(M(t)));
249
+ }
250
+ function at(e, t, n, r) {
251
+ return rt(it(e, n), it(t, r), M(0)).x;
252
+ }
253
+ function ot(e, t, n, r) {
254
+ return rt(it(e, n), it(t, r), M(0));
255
+ }
256
+ function st(e, t, n, r, i) {
257
+ return rt(it(e, r), it(t, i), M(n));
258
+ }
259
+ //#endregion
260
+ //#region src/tsl/noise/value.ts
261
+ function ct(e, t, n) {
262
+ let r = A(e), i = e.sub(r), a = i.mul(i).mul(k(3).sub(i.mul(2))), o = M(r.x), s = M(r.y), c = at(o, s, t, n), l = at(o.add(1), s, t, n), u = at(o, s.add(1), t, n), d = at(o.add(1), s.add(1), t, n);
263
+ return I(I(c, l, a.x), I(u, d, a.x), a.y);
264
+ }
265
+ //#endregion
266
+ //#region src/tsl/noise/cellular.ts
267
+ var lt = 2;
268
+ function ut(e, t, n) {
269
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = q(i.x, i.y, k(0)), c = k(1e10);
270
+ for (let e = -1; e <= 1; e++) for (let r = -1; r <= 1; r++) {
271
+ let i = ot(a.add(e), o.add(r), t, n), l = q(k(e).add(i.x), k(r).add(i.y), i.z);
272
+ c = F(c, N(l.sub(s)));
273
+ }
274
+ return b(k(1).sub(c), 0, 1);
275
+ }
276
+ function dt(e, t, n) {
277
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = k(0), c = k(0);
278
+ for (let e = -1; e <= 1; e++) for (let r = -1; r <= 1; r++) {
279
+ let l = ot(a.add(e), o.add(r), t, n), u = R(V(1.414, 0, N(K(e, r).sub(i).add(K(l.x, l.y)))), lt);
280
+ s = s.add(l.z.mul(u)), c = c.add(u);
281
+ }
282
+ return s.div(c.max(1e-4));
283
+ }
284
+ //#endregion
285
+ //#region src/tsl/noise/flow.ts
286
+ var ft = (e, t) => $e(e, K(t, t)), pt = d(([e, t]) => {
287
+ let n = k(.1), r = ft(e.add(K(n, 0)), t), i = ft(e.add(K(0, n)), t), a = ft(e.sub(K(n, 0)), t), o = ft(e.sub(K(0, n)), t);
288
+ return K(r.sub(a), i.sub(o)).div(n).mul(.5);
289
+ });
290
+ function mt(e, t, n) {
291
+ let r = pt(e, t);
292
+ return q(r.x, r.y, k(0));
293
+ }
294
+ function ht(e, t, n) {
295
+ return b(pt(e, t).length().mul(.6).add(.2), 0, 1);
296
+ }
297
+ function gt(e, t, n) {
298
+ let r = pt(e, t);
299
+ return b(P(f(r.x), f(r.y)), 0, 1);
300
+ }
301
+ function _t(e, t, n) {
302
+ let r = pt(e, t).mul(.4);
303
+ return ft(e.add(r), t).mul(.5).add(.5);
304
+ }
305
+ //#endregion
306
+ //#region src/tsl/noise/gabor.ts
307
+ var vt = 6.283185307179586, yt = Math.PI, bt = 8, xt = d(([e, t, n, r, i]) => {
308
+ let a = e.mul(t), o = A(a), s = a.sub(o), c = k(0).toVar();
309
+ for (let e = -1; e <= 1; e++) for (let a = -1; a <= 1; a++) {
310
+ let l = M(o.x).add(a), u = M(o.y).add(e), d = s.sub(K(a, e));
311
+ for (let e = 0; e < bt; e++) {
312
+ let a = st(l, u, e * 2, t, t), o = st(l, u, e * 2 + 1, t, t), s = i.add(o.x.sub(.5).mul(yt).mul(r)), f = d.sub(K(a.x, a.y)), p = D(f, f), m = O(p.mul(-yt)).mul(k(.5).add(S(p.mul(yt)).mul(.5))), h = D(f, K(S(s), B(s)).mul(n)).mul(vt), g = I(k(-1), k(1), Ce(.5, a.z)), _ = k(1).sub(Ce(1, p));
313
+ c.addAssign(B(h).mul(m).mul(g).mul(_));
314
+ }
315
+ }
316
+ return c.div(6).mul(.5).add(.5);
317
+ });
318
+ //#endregion
319
+ //#region src/tsl/noise/simplex.ts
320
+ function St(e, t, n) {
321
+ let r = K(e.x.add(e.y.mul(.5)), e.y), i = A(r), a = r.sub(i), o = Ce(a.y, a.x), s = K(o, k(1).sub(o)), c = K(i.x.sub(i.y.mul(.5)), i.y), l = K(c.x.add(s.x).sub(s.y.mul(.5)), c.y.add(s.y)), u = K(c.x.add(.5), c.y.add(1)), d = e.sub(c), f = e.sub(l), p = e.sub(u), m = L(q(c.x, l.x, u.x), k(t)), h = L(q(c.y, l.y, u.y), k(n)), g = A(m.add(h.mul(.5)).add(.5)), _ = A(h.add(.5)), v = L(g, 289);
322
+ v = L(v.mul(51).add(2).mul(v).add(_), 289), v = L(v.mul(34).add(10).mul(v), 289);
323
+ let y = v.mul(.07482), x = S(y), C = B(y), w = K(x.x, C.x), T = K(x.y, C.y), E = K(x.z, C.z), ee = P(k(.8).sub(q(D(d, d), D(f, f), D(p, p))), 0), O = ee.mul(ee);
324
+ return b(D(O.mul(O), q(D(w, d), D(T, f), D(E, p))).mul(10.9).mul(.5).add(.5), 0, 1);
325
+ }
326
+ //#endregion
327
+ //#region src/tsl/noise/wavelet.ts
328
+ var Ct = 6.283185307179586;
329
+ function wt(e, t, n) {
330
+ let r = A(e), i = j(e).sub(.5), a = at(M(r.x), M(r.y), t, n).mul(Ct), o = S(a), s = B(a), c = o.mul(i.x).sub(s.mul(i.y)), l = s.mul(i.x).add(o.mul(i.y)), u = V(.25, 0, D(K(c, l), K(c, l)));
331
+ return b(B(c.mul(10)).mul(u).mul(.5).add(.5), 0, 1);
332
+ }
333
+ //#endregion
334
+ //#region src/tsl/noise/erosion.ts
335
+ function Tt(e, t, n) {
336
+ let r = pt(e, t), i = $e(e.add(r.mul(.6)), K(t, t)).mul(.5).add(.5);
337
+ return b(k(1).sub(i.mul(2).sub(1).abs()), 0, 1);
338
+ }
339
+ //#endregion
340
+ //#region src/graph/nodes/texture/tileable-noise.ts
341
+ var Et = [
342
+ "perlin-fbm",
343
+ "value",
344
+ "worley",
345
+ "voronoi-smooth",
346
+ "gabor",
347
+ "stone",
348
+ "paper",
349
+ "wool",
350
+ "simplex",
351
+ "wavelet",
352
+ "erosion",
353
+ "curl"
354
+ ], Y = [
355
+ "octaves",
356
+ "gain",
357
+ "lacunarity",
358
+ "antialias",
359
+ "tileSize"
360
+ ], Dt = {
361
+ "perlin-fbm": ["aspect", ...Y],
362
+ value: ["aspect", ...Y],
363
+ worley: Y,
364
+ "voronoi-smooth": Y,
365
+ stone: Y,
366
+ paper: Y,
367
+ wool: Y,
368
+ simplex: Y,
369
+ wavelet: Y,
370
+ erosion: Y,
371
+ gabor: [
372
+ "gaborFreq",
373
+ "gaborAniso",
374
+ "gaborOrient",
375
+ "tileSize"
376
+ ],
377
+ curl: []
378
+ }, Ot = {
379
+ value: ct,
380
+ worley: ut,
381
+ "voronoi-smooth": dt,
382
+ stone: _t,
383
+ paper: ht,
384
+ wool: gt,
385
+ wavelet: wt,
386
+ erosion: Tt
387
+ }, kt = [{
388
+ key: "field",
389
+ kind: "float"
390
+ }], At = [{
391
+ key: "field",
392
+ kind: "float"
393
+ }, {
394
+ key: "vector",
395
+ kind: "vector"
396
+ }], jt = {
397
+ type: "tileable-noise",
398
+ nodeClass: "texture",
399
+ label: "Tileable Noise",
400
+ bakeTileable: !0,
401
+ inputs: [{
402
+ key: "coord",
403
+ kind: "vector"
404
+ }],
405
+ outputs: [{
406
+ key: "field",
407
+ kind: "float"
408
+ }],
409
+ params: [
410
+ {
411
+ key: "noiseType",
412
+ label: "type",
413
+ type: "select",
414
+ options: Et,
415
+ default: "perlin-fbm"
416
+ },
417
+ {
418
+ key: "scale",
419
+ label: "scale",
420
+ type: "float",
421
+ min: 1,
422
+ max: 128,
423
+ step: 1,
424
+ default: 5
425
+ },
426
+ {
427
+ key: "aspect",
428
+ label: "aspect",
429
+ type: "float",
430
+ min: 1,
431
+ max: 8,
432
+ step: .5,
433
+ default: 1
434
+ },
435
+ {
436
+ key: "octaves",
437
+ label: "detail",
438
+ type: "int",
439
+ min: 1,
440
+ max: 8,
441
+ step: 1,
442
+ default: 4
443
+ },
444
+ {
445
+ key: "gain",
446
+ label: "roughness",
447
+ type: "float",
448
+ min: 0,
449
+ max: 1,
450
+ step: .01,
451
+ default: .5
452
+ },
453
+ {
454
+ key: "lacunarity",
455
+ label: "lacunarity",
456
+ type: "float",
457
+ min: 2,
458
+ max: 8,
459
+ step: 1,
460
+ default: 2,
461
+ bakeStructural: !0
462
+ },
463
+ {
464
+ key: "antialias",
465
+ label: "anti-alias",
466
+ type: "float",
467
+ min: 0,
468
+ max: 1,
469
+ step: .01,
470
+ default: 1
471
+ },
472
+ {
473
+ key: "gaborFreq",
474
+ label: "gabor freq",
475
+ type: "float",
476
+ min: 0,
477
+ max: 16,
478
+ step: .1,
479
+ default: 2
480
+ },
481
+ {
482
+ key: "gaborAniso",
483
+ label: "gabor aniso",
484
+ type: "float",
485
+ min: 0,
486
+ max: 1,
487
+ step: .01,
488
+ default: 1
489
+ },
490
+ {
491
+ key: "gaborOrient",
492
+ label: "gabor angle",
493
+ type: "float",
494
+ min: 0,
495
+ max: 6.2832,
496
+ step: .01,
497
+ default: .785398
498
+ },
499
+ {
500
+ key: "tileSize",
501
+ label: "tile",
502
+ type: "select",
503
+ options: [
504
+ "off",
505
+ "64",
506
+ "128",
507
+ "256",
508
+ "512"
509
+ ],
510
+ default: "off"
511
+ }
512
+ ],
513
+ declare(e) {
514
+ return {
515
+ inputs: [{
516
+ key: "coord",
517
+ kind: "vector"
518
+ }],
519
+ outputs: e.noiseType === "curl" ? At : kt
520
+ };
521
+ },
522
+ paramsFor(e) {
523
+ let t = Dt[e.noiseType ?? "perlin-fbm"] ?? [], n = new Set([
524
+ "noiseType",
525
+ "scale",
526
+ ...t
527
+ ]);
528
+ return jt.params.filter((e) => n.has(e.key));
529
+ },
530
+ build(e) {
531
+ let t = e.inputs.coord ?? e.coord, n = Math.max(1, Math.round(Number.isFinite(Number(e.params.octaves)) ? Number(e.params.octaves) : 4)), r = Math.max(2, Math.round(Number.isFinite(Number(e.params.lacunarity)) ? Number(e.params.lacunarity) : 2)), i = e.params.noiseType ?? "perlin-fbm", a = e.uniforms.gain, o = e.uniforms.scale;
532
+ if (e.backend === "live") return { field: Je(t.mul(o), n, a, e.uniforms.lacunarity) };
533
+ let s = K(t.x, t.y), c = e.uniforms.antialias, l = Math.max(1, Math.round(e.tileRepeat ?? 1)), u = P(A((l > 1 ? o.div(k(l)) : o).add(.5)), k(1)), d = e.uniforms.aspect, f = P(A(u.mul(d).add(.5)), k(1));
534
+ if (i === "curl") {
535
+ let e = mt(s.mul(u), u, u);
536
+ return {
537
+ field: e.length(),
538
+ vector: e
539
+ };
540
+ }
541
+ if (i === "simplex") {
542
+ let e = u.add(L(u, k(2)));
543
+ return { field: tt(s, e, e, n, a, St, c, r) };
544
+ }
545
+ if (i === "gabor") {
546
+ let t = k(1).sub(e.uniforms.gaborAniso);
547
+ return { field: xt(s, u, e.uniforms.gaborFreq, t, e.uniforms.gaborOrient) };
548
+ }
549
+ let p = Ot[i];
550
+ return p ? { field: tt(s, i === "value" ? f : u, u, n, a, p, c, r) } : { field: et(s, f, u, n, a, c, r).mul(.5).add(.5) };
551
+ }
552
+ }, Mt = 4294967295;
553
+ function Nt(e) {
554
+ let t = ne(e.mul(K(141421356, 2718281828)));
555
+ return k(t.x.bitXor(t.y).mul(U(3141592653))).div(Mt);
556
+ }
557
+ function Pt(e) {
558
+ return j(k(52.9829189).mul(j(D(e, K(.06711056, .00583715)))));
559
+ }
560
+ function Ft(e) {
561
+ let t = U(e.x), n = U(e.y);
562
+ return k(t.mul(U(3242174889)).add(n.mul(U(2447445413)))).mul(te(-32));
563
+ }
564
+ function It(e) {
565
+ let t = k(0);
566
+ for (let n = 0; n < 9; n++) t = t.add(Nt(e.add(K(n % 3 - 1, Math.floor(n / 3) - 1))));
567
+ return k(.9).mul(k(1.125).mul(Nt(e)).sub(t.div(8))).add(.5);
568
+ }
569
+ var Lt = d(([e, t]) => {
570
+ let n = e.toVar(), r = t.toVar(), i = M(0).toVar();
571
+ for (let e = 256; e > 0; e >>= 1) {
572
+ let t = M(e), a = z(n.bitAnd(t).notEqual(M(0)), M(1), M(0)), o = z(r.bitAnd(t).notEqual(M(0)), M(1), M(0));
573
+ i.assign(i.add(t.mul(t).mul(a.shiftLeft(1).bitOr(a.bitXor(o)))));
574
+ let s = n.bitXor(r).mul(M(1).sub(o)).bitXor(M(e - 1).mul(a.bitAnd(M(1).sub(o))));
575
+ n.assign(n.bitXor(s)), r.assign(r.bitXor(s));
576
+ }
577
+ return i;
578
+ });
579
+ function Rt(e) {
580
+ let t = Lt(M(e.x), M(e.y));
581
+ return j(k(.6180339887498948).mul(k(t.mod(M(262144)))));
582
+ }
583
+ var zt = d(([e, t]) => {
584
+ let n = A(e).toVar(), r = e.sub(n);
585
+ n.x.assign(A(B(n.x.mul(51024)).mul(3104))), n.y.assign(A(B(n.y.mul(1324)).mul(554)));
586
+ let i = n.x.add(n.y);
587
+ r = r.mul(2).sub(1), r = r.mul(S(i)).add(K(r.y.negate(), r.x).mul(B(i))), r = r.add(B(n.x.sub(n.y))), r = r.mul(.5).add(.5);
588
+ let a = B(n.x.add(r.y.mul(3.1415))).add(B(n.y.add(r.y.mul(3.1415)))).mul(.2), o = f(r.x.sub(.5).add(a));
589
+ return o = k(.5).sub(o.mul(t)), o = V(-2, re(o).mul(1.5).add(16), o).mul(12), o.mul(r.y);
590
+ });
591
+ function Bt(e, t) {
592
+ let n = e, r = t, i = k(0);
593
+ for (let e = 0; e < 8; e++) i = P(i, zt(n, r)), n = K(n.x.sub(n.y.mul(.7)), n.x.mul(.7).add(n.y)).sub(12.31);
594
+ return i;
595
+ }
596
+ var Vt = {
597
+ type: "screen-noise",
598
+ nodeClass: "texture",
599
+ label: "Screen Noise",
600
+ inputs: [{
601
+ key: "coord",
602
+ kind: "vector"
603
+ }],
604
+ outputs: [{
605
+ key: "field",
606
+ kind: "float"
607
+ }],
608
+ params: [{
609
+ key: "noiseType",
610
+ label: "type",
611
+ type: "select",
612
+ options: [
613
+ "blue",
614
+ "hilbert-blue",
615
+ "ign",
616
+ "golden-ign",
617
+ "scratches"
618
+ ],
619
+ default: "blue"
620
+ }, {
621
+ key: "resolution",
622
+ label: "resolution",
623
+ type: "float",
624
+ min: 16,
625
+ max: 2048,
626
+ step: 1,
627
+ default: 512
628
+ }],
629
+ build(e) {
630
+ let t = e.inputs.coord ?? e.coord, n = K(t.x, t.y), r = e.params.noiseType ?? "blue", i = n.mul(e.uniforms.resolution);
631
+ switch (r) {
632
+ case "hilbert-blue": return { field: Rt(A(i)) };
633
+ case "ign": return { field: Pt(A(i)) };
634
+ case "golden-ign": return { field: Ft(A(i)) };
635
+ case "scratches": return { field: Bt(n.mul(5), k(3)) };
636
+ default: return { field: It(A(i)) };
637
+ }
638
+ }
639
+ }, Ht = {
640
+ type: "tileable-warp",
641
+ nodeClass: "vector",
642
+ label: "Tileable Warp",
643
+ inputs: [{
644
+ key: "coord",
645
+ kind: "vector"
646
+ }],
647
+ outputs: [{
648
+ key: "coord",
649
+ kind: "vector"
650
+ }],
651
+ params: [{
652
+ key: "amount",
653
+ label: "amount",
654
+ type: "float",
655
+ min: 0,
656
+ max: 1,
657
+ step: .01,
658
+ default: .15
659
+ }, {
660
+ key: "scale",
661
+ label: "scale",
662
+ type: "int",
663
+ min: 1,
664
+ max: 64,
665
+ step: 1,
666
+ default: 4
667
+ }],
668
+ build(e) {
669
+ let t = e.inputs.coord ?? e.coord, n = e.uniforms.amount;
670
+ if (e.backend === "live") {
671
+ let r = t.div(Math.max(1, Number(e.params.scale ?? 4))), i = se(r.add(q(11.3, 0, 0))), a = se(r.add(q(0, 47.7, 0))), o = se(r.add(q(0, 0, 93.1)));
672
+ return { coord: t.add(q(i, a, o).mul(n)) };
673
+ }
674
+ let r = Math.max(1, Math.round(Number(e.params.scale ?? 4))), i = K(t.x, t.y), a = K(r, r), o = $e(i.mul(r), a), s = $e(i.mul(r).add(K(5.2, 1.3)), a), c = i.add(K(o, s).mul(n));
675
+ return { coord: q(c.x, c.y, t.z) };
676
+ }
677
+ }, Ut = 1 / 2147483648;
678
+ function Wt(e, t, n) {
679
+ let r = e.mul(1664525).add(1013904223).toVar(), i = t.mul(1664525).add(1013904223).toVar(), a = n.mul(1664525).add(1013904223).toVar();
680
+ r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i))), r.assign(r.bitXor(r.shiftRight(16))), i.assign(i.bitXor(i.shiftRight(16))), a.assign(a.bitXor(a.shiftRight(16))), r.assign(r.add(i.mul(a))), i.assign(i.add(a.mul(r))), a.assign(a.add(r.mul(i)));
681
+ let o = M(2147483647);
682
+ return q(k(r.bitAnd(o)).mul(Ut), k(i.bitAnd(o)).mul(Ut), k(a.bitAnd(o)).mul(Ut));
683
+ }
684
+ function Gt(e, t) {
685
+ return e.sub(M(A(k(e).div(t))).mul(M(t)));
686
+ }
687
+ function Kt(e, t, n, r) {
688
+ return typeof r == "number" && r <= 0 ? Wt(e, t, n) : Wt(Gt(e, r), Gt(t, r), Gt(n, r));
689
+ }
690
+ function qt(e, t, n, r) {
691
+ let i = e.sub(t).abs();
692
+ if (n === 1) return i.x.add(i.y).add(i.z);
693
+ if (n === 2) return i.x.max(i.y.max(i.z));
694
+ if (n === 3) {
695
+ let e = r;
696
+ return R(R(i.x, e).add(R(i.y, e)).add(R(i.z, e)), k(1).div(e));
697
+ }
698
+ return e.sub(t).length();
699
+ }
700
+ function Jt(e, t, n, r, i, a) {
701
+ return d(() => {
702
+ let o = A(e), s = e.sub(o), c = M(o.x), l = M(o.y), u = M(o.z), d = k(1e10).toVar(), f = q(0, 0, 0).toVar(), p = q(0, 0, 0).toVar();
703
+ for (let e = -1; e <= 1; e++) for (let i = -1; i <= 1; i++) for (let o = -1; o <= 1; o++) {
704
+ let m = q(o, i, e), h = m.add(Kt(c.add(o), l.add(i), u.add(e), a).mul(t)), g = qt(h, s, n, r), _ = g.lessThan(d);
705
+ d.assign(_.select(g, d)), f.assign(_.select(m, f)), p.assign(_.select(h, p));
706
+ }
707
+ return i === "color" ? Kt(c.add(M(f.x)), l.add(M(f.y)), u.add(M(f.z)), a) : i === "position" ? p.add(o) : d;
708
+ })();
709
+ }
710
+ function Yt(e, t, n, r, i, a) {
711
+ return d(() => {
712
+ let o = A(e), s = e.sub(o), c = M(o.x), l = M(o.y), u = M(o.z), d = k(1e10).toVar(), f = k(1e10).toVar(), p = q(0, 0, 0).toVar(), m = q(0, 0, 0).toVar(), h = q(0, 0, 0).toVar(), g = q(0, 0, 0).toVar();
713
+ for (let e = -1; e <= 1; e++) for (let i = -1; i <= 1; i++) for (let o = -1; o <= 1; o++) {
714
+ let _ = q(o, i, e), v = _.add(Kt(c.add(o), l.add(i), u.add(e), a).mul(t)), y = qt(v, s, n, r), b = y.lessThan(d).toVar(), x = y.lessThan(f).toVar(), S = z(b, d, z(x, y, f)), C = z(b, p, z(x, _, m)), w = z(b, h, z(x, v, g)), T = z(b, y, d), E = z(b, _, p), ee = z(b, v, h);
715
+ f.assign(S), m.assign(C), g.assign(w), d.assign(T), p.assign(E), h.assign(ee);
716
+ }
717
+ return i === "color" ? Kt(c.add(M(m.x)), l.add(M(m.y)), u.add(M(m.z)), a) : i === "position" ? g.add(o) : f;
718
+ })();
719
+ }
720
+ var Xt = 1;
721
+ function Zt(e, t, n, r, i, a, o) {
722
+ return d(() => {
723
+ let s = A(e), c = e.sub(s), l = M(s.x), u = M(s.y), d = M(s.z), f = P(i, k(1e-6)), p = k(0).toVar(), m = q(0, 0, 0).toVar(), h = q(0, 0, 0).toVar(), g = k(-1).toVar();
724
+ for (let e = -1; e <= Xt; e++) for (let i = -1; i <= Xt; i++) for (let a = -1; a <= Xt; a++) {
725
+ let s = q(a, i, e), _ = Kt(l.add(a), u.add(i), d.add(e), o), v = s.add(_.mul(t)), y = qt(v, c, n, r);
726
+ g.assign(z(g.equal(-1), k(1), V(0, 1, k(.5).add(p.sub(y).mul(.5).div(f)))));
727
+ let b = f.mul(g).mul(k(1).sub(g)).toVar();
728
+ p.assign(I(p, y, g).sub(b)), b.assign(b.div(k(1).add(f.mul(3)))), m.assign(I(m, _, g).sub(b)), h.assign(I(h, v, g).sub(b));
729
+ }
730
+ return a === "color" ? m : a === "position" ? h.add(s) : p;
731
+ })();
732
+ }
733
+ var Qt = (e, t, n, r, i = 0) => Jt(e, t, n, r, "distance", i), $t = (e, t, n, r, i = 0) => Jt(e, t, n, r, "color", i), en = (e, t, n, r, i = 0) => Jt(e, t, n, r, "position", i), tn = (e, t, n, r, i = 0) => Yt(e, t, n, r, "distance", i), nn = (e, t, n, r, i = 0) => Yt(e, t, n, r, "color", i), rn = (e, t, n, r, i = 0) => Yt(e, t, n, r, "position", i), an = (e, t, n, r, i, a = 0) => Zt(e, t, n, r, i, "distance", a), on = (e, t, n, r, i, a = 0) => Zt(e, t, n, r, i, "color", a), sn = (e, t, n, r, i, a = 0) => Zt(e, t, n, r, i, "position", a);
734
+ function cn(e, t, n = 0) {
735
+ return d(() => {
736
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = M(r.z), c = (e, r, c) => q(e, r, c).add(Kt(a.add(e), o.add(r), s.add(c), n).mul(t)).sub(i), l = q(0, 0, 0).toVar(), u = k(1e10).toVar();
737
+ for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) for (let n = -1; n <= 1; n++) {
738
+ let r = c(n, t, e), i = r.dot(r), a = i.lessThan(u);
739
+ u.assign(a.select(i, u)), l.assign(a.select(r, l));
740
+ }
741
+ let d = k(1e10).toVar();
742
+ for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) for (let n = -1; n <= 1; n++) {
743
+ let r = c(n, t, e), i = r.sub(l), a = i.dot(i).greaterThan(1e-4), o = l.add(r).div(2).dot(i.normalize());
744
+ d.assign(a.select(d.min(o), d));
745
+ }
746
+ return d;
747
+ })();
748
+ }
749
+ //#endregion
750
+ //#region src/tsl/lloyd-points.ts
751
+ function ln(e, t, n) {
752
+ let r = Math.imul(e, 374761393) + Math.imul(t, 668265263) + Math.imul(n, 362437) >>> 0;
753
+ r = Math.imul(r ^ r >>> 13, 1274126177) >>> 0;
754
+ let i = (r & 65535) / 65536;
755
+ return r = Math.imul(r ^ r >>> 16, 2246822519) >>> 0, [i, (r >>> 8 & 65535) / 65536];
756
+ }
757
+ function un(e, t, n) {
758
+ let r = e - t;
759
+ return r -= n * Math.round(r / n), r;
760
+ }
761
+ function dn(e, t, n, r = 0) {
762
+ let i = e * e, a = new Float64Array(i), o = new Float64Array(i);
763
+ for (let n = 0; n < e; n++) for (let i = 0; i < e; i++) {
764
+ let [s, c] = ln(i, n, r), l = n * e + i;
765
+ a[l] = i + .5 + (s - .5) * t, o[l] = n + .5 + (c - .5) * t;
766
+ }
767
+ let s = Math.max(64, e * 24);
768
+ for (let t = 0; t < n; t++) {
769
+ let t = new Float64Array(i), n = new Float64Array(i), r = new Float64Array(i);
770
+ for (let i = 0; i < s; i++) {
771
+ let c = (i + .5) / s * e, l = Math.floor(c);
772
+ for (let i = 0; i < s; i++) {
773
+ let u = (i + .5) / s * e, d = Math.floor(u), f = Infinity, p = 0;
774
+ for (let t = -1; t <= 1; t++) for (let n = -1; n <= 1; n++) {
775
+ let r = ((d + n) % e + e) % e, i = ((l + t) % e + e) % e * e + r, s = un(a[i], u, e), m = un(o[i], c, e), h = s * s + m * m;
776
+ h < f && (f = h, p = i);
777
+ }
778
+ t[p] += a[p] + un(u, a[p], e), n[p] += o[p] + un(c, o[p], e), r[p]++;
779
+ }
780
+ }
781
+ for (let s = 0; s < i; s++) r[s] > 0 && (a[s] = (t[s] / r[s] % e + e) % e, o[s] = (n[s] / r[s] % e + e) % e);
782
+ }
783
+ let c = new Float32Array(i * 3);
784
+ for (let t = 0; t < e; t++) for (let n = 0; n < e; n++) {
785
+ let r = t * e + n, i = a[r] - n, s = o[r] - t;
786
+ i -= e * Math.round(i / e), s -= e * Math.round(s / e), c[r * 3 + 0] = i, c[r * 3 + 1] = s, c[r * 3 + 2] = 0;
787
+ }
788
+ return c;
789
+ }
790
+ //#endregion
791
+ //#region src/tsl/relaxed-voronoi.ts
792
+ function fn(e, t) {
793
+ return d(() => {
794
+ let n = A(e), r = e.sub(n), i = M(n.x), a = M(n.y), o = (e, n) => q(e, n, 0).add(t(i.add(e), a.add(n))).sub(r), s = q(0, 0, 0).toVar(), c = k(1e10).toVar();
795
+ for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
796
+ let n = o(t, e), r = n.dot(n), i = r.lessThan(c);
797
+ c.assign(i.select(r, c)), s.assign(i.select(n, s));
798
+ }
799
+ let l = k(1e10).toVar();
800
+ for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
801
+ let n = o(t, e), r = n.sub(s), i = r.dot(r).greaterThan(1e-4), a = s.add(n).div(2).dot(r.normalize());
802
+ l.assign(i.select(l.min(a), l));
803
+ }
804
+ return l;
805
+ })();
806
+ }
807
+ function pn(e, t, n) {
808
+ return d(() => {
809
+ let r = A(e), i = e.sub(r), a = M(r.x), o = M(r.y), s = (e, n) => q(e, n, 0).add(t(a.add(e), o.add(n))).sub(i), c = k(1e10).toVar(), l = M(0).toVar(), u = M(0).toVar();
810
+ for (let e = -1; e <= 1; e++) for (let t = -1; t <= 1; t++) {
811
+ let n = s(t, e), r = n.dot(n), i = r.lessThan(c);
812
+ c.assign(i.select(r, c)), l.assign(i.select(a.add(t), l)), u.assign(i.select(o.add(e), u));
813
+ }
814
+ return n(l, u);
815
+ })();
816
+ }
817
+ //#endregion
818
+ //#region src/graph/nodes/texture/voronoi.ts
819
+ var mn = [
820
+ "euclidean",
821
+ "manhattan",
822
+ "chebychev",
823
+ "minkowski"
824
+ ], hn = [
825
+ "f1",
826
+ "f2",
827
+ "smooth-f1",
828
+ "distance-to-edge"
829
+ ], gn = [
830
+ {
831
+ key: "distance",
832
+ label: "Distance",
833
+ kind: "float"
834
+ },
835
+ {
836
+ key: "color",
837
+ label: "Color",
838
+ kind: "color"
839
+ },
840
+ {
841
+ key: "position",
842
+ label: "Position",
843
+ kind: "vector"
844
+ }
845
+ ], _n = [{
846
+ key: "distance",
847
+ label: "Distance",
848
+ kind: "float"
849
+ }, {
850
+ key: "random",
851
+ label: "Random",
852
+ kind: "float"
853
+ }], vn = [{
854
+ key: "coord",
855
+ kind: "vector"
856
+ }];
857
+ function yn(e) {
858
+ let t = Array(e);
859
+ for (let n = 0; n < e; n++) {
860
+ let e = Math.sin(n * 12.9898 + 78.233) * 43758.5453;
861
+ t[n] = e - Math.floor(e);
862
+ }
863
+ return t;
864
+ }
865
+ var bn = {
866
+ type: "voronoi",
867
+ nodeClass: "texture",
868
+ label: "Voronoi",
869
+ inputs: vn,
870
+ outputs: gn,
871
+ params: [
872
+ {
873
+ key: "scale",
874
+ label: "scale",
875
+ type: "float",
876
+ min: .1,
877
+ max: 64,
878
+ step: .05,
879
+ default: 1
880
+ },
881
+ {
882
+ key: "randomness",
883
+ label: "randomness",
884
+ type: "float",
885
+ min: 0,
886
+ max: 1,
887
+ step: .01,
888
+ default: 1
889
+ },
890
+ {
891
+ key: "metric",
892
+ label: "metric",
893
+ type: "select",
894
+ options: mn,
895
+ default: "euclidean"
896
+ },
897
+ {
898
+ key: "feature",
899
+ label: "feature",
900
+ type: "select",
901
+ options: hn,
902
+ default: "f1"
903
+ },
904
+ {
905
+ key: "exponent",
906
+ label: "exponent",
907
+ type: "float",
908
+ min: .1,
909
+ max: 8,
910
+ step: .1,
911
+ default: 2
912
+ },
913
+ {
914
+ key: "smoothness",
915
+ label: "smoothness",
916
+ type: "float",
917
+ min: 0,
918
+ max: 1,
919
+ step: .01,
920
+ default: .25
921
+ },
922
+ {
923
+ key: "relax",
924
+ label: "relax",
925
+ type: "int",
926
+ min: 0,
927
+ max: 5,
928
+ step: 1,
929
+ default: 0
930
+ }
931
+ ],
932
+ declare(e) {
933
+ return {
934
+ inputs: vn,
935
+ outputs: (e.feature ?? "f1") === "distance-to-edge" ? _n : gn
936
+ };
937
+ },
938
+ paramsFor(e) {
939
+ let t = e.metric ?? "euclidean", n = e.feature ?? "f1", r = new Set([
940
+ "scale",
941
+ "randomness",
942
+ "metric",
943
+ "feature"
944
+ ]);
945
+ return t === "minkowski" && r.add("exponent"), n === "smooth-f1" && r.add("smoothness"), n === "distance-to-edge" && r.add("relax"), bn.params.filter((e) => r.has(e.key));
946
+ },
947
+ build(e) {
948
+ let t = e.backend === "offline", n = Math.max(0, mn.indexOf(e.params.metric)), r = e.uniforms.randomness, i = e.uniforms.exponent, a = e.uniforms.smoothness, s = e.params.feature ?? "f1", c = e.inputs.coord ?? e.coord, l = Math.max(0, Math.round(Number(e.params.relax ?? 0)));
949
+ if (s === "distance-to-edge" && t && l > 0) {
950
+ let t = Math.max(1, Math.round(Number(e.params.scale ?? 1))), n = c.mul(t), r = dn(t, Number(e.params.randomness ?? 1), l), i = [];
951
+ for (let e = 0; e < t * t; e++) i.push(new o(r[e * 3], r[e * 3 + 1], r[e * 3 + 2]));
952
+ let a = De(i), s = (e) => e.sub(M(A(k(e).div(t))).mul(M(t))), u = (e, n) => a.element(s(n).mul(t).add(s(e))), d = De(yn(t * t));
953
+ return {
954
+ distance: fn(n, u),
955
+ random: pn(n, u, (e, n) => d.element(s(n).mul(t).add(s(e))))
956
+ };
957
+ }
958
+ let u = e.uniforms.scale, d = P(A(u.add(.5)), k(1)), f = c.mul(t ? d : u), p = t ? d : 0;
959
+ switch (s) {
960
+ case "distance-to-edge": return {
961
+ distance: cn(f, r, p),
962
+ random: $t(f, r, n, i, p).x
963
+ };
964
+ case "f2": return {
965
+ distance: tn(f, r, n, i, p),
966
+ color: nn(f, r, n, i, p),
967
+ position: rn(f, r, n, i, p)
968
+ };
969
+ case "smooth-f1": return {
970
+ distance: an(f, r, n, i, a, p),
971
+ color: on(f, r, n, i, a, p),
972
+ position: sn(f, r, n, i, a, p)
973
+ };
974
+ default: return {
975
+ distance: Qt(f, r, n, i, p),
976
+ color: $t(f, r, n, i, p),
977
+ position: en(f, r, n, i, p)
978
+ };
979
+ }
980
+ }
981
+ }, xn = {
982
+ type: "checker",
983
+ nodeClass: "texture",
984
+ label: "Checker",
985
+ inputs: [
986
+ {
987
+ key: "coord",
988
+ kind: "vector"
989
+ },
990
+ {
991
+ key: "color1",
992
+ label: "Color1",
993
+ kind: "color"
994
+ },
995
+ {
996
+ key: "color2",
997
+ label: "Color2",
998
+ kind: "color"
999
+ }
1000
+ ],
1001
+ outputs: [{
1002
+ key: "color",
1003
+ kind: "color"
1004
+ }, {
1005
+ key: "fac",
1006
+ label: "Fac",
1007
+ kind: "float"
1008
+ }],
1009
+ params: [
1010
+ {
1011
+ key: "color1",
1012
+ label: "color1",
1013
+ type: "color",
1014
+ default: "#c4201e"
1015
+ },
1016
+ {
1017
+ key: "color2",
1018
+ label: "color2",
1019
+ type: "color",
1020
+ default: "#18b6b6"
1021
+ },
1022
+ {
1023
+ key: "scale",
1024
+ label: "scale",
1025
+ type: "float",
1026
+ min: .5,
1027
+ max: 32,
1028
+ step: .5,
1029
+ default: 4
1030
+ }
1031
+ ],
1032
+ build(e) {
1033
+ let t = (e.inputs.coord ?? e.coord).mul(e.uniforms.scale), n = L(A(t.x).add(A(t.y)).add(A(t.z)), 2).lessThan(1);
1034
+ return {
1035
+ color: z(n, e.inputs.color1 ?? e.uniforms.color1, e.inputs.color2 ?? e.uniforms.color2),
1036
+ fac: z(n, k(1), k(0))
1037
+ };
1038
+ }
1039
+ }, Sn = 6.283185307179586;
1040
+ function Cn(e, t, n) {
1041
+ let { columns: r, rows: i, offsetFreq: a } = t, o = d(() => {
1042
+ let t = K(e.x.mul(r), e.y.mul(i)), o = A(t.y), s = k(-1e9).toVar(), c = k(0).toVar();
1043
+ for (let e = -1; e <= 1; e++) {
1044
+ let l = o.add(e), u = M(l), d = z(L(l, k(a)).notEqual(0), n.rowOffset, k(0)), p = A(t.x.sub(d));
1045
+ for (let e = -1; e <= 1; e++) {
1046
+ let a = p.add(e), o = M(a), m = st(o, u, 0, r, i), h = st(o, u, 1, r, i), g = m.x.sub(.5).mul(n.posRandom), _ = m.y.sub(.5).mul(n.posRandom), v = a.add(.5).add(d).add(g), y = l.add(.5).add(_), b = t.x.sub(v).div(r), x = t.y.sub(y).div(i), C = h.x.sub(.5).mul(2).mul(n.rotRandom).mul(Sn * .5).negate(), w = S(C), T = B(C), E = w.mul(b).sub(T.mul(x)), ee = T.mul(b).add(w.mul(x)), D = k(1).add(m.z.sub(.5).mul(2).mul(n.sizeRandom)), O = k(.5).div(r).mul(D).sub(n.gap), te = k(.5).div(i).mul(D).sub(n.gap), ne = n.roundness.mul(F(O, te)), A = f(E).sub(O.sub(ne)), j = f(ee).sub(te.sub(ne)), re = N(K(P(A, 0), P(j, 0))), ie = F(P(A, j), 0), ae = re.add(ie).sub(ne).negate(), oe = ae.greaterThan(s);
1047
+ c.assign(z(oe, h.y, c)), s.assign(z(oe, ae, s));
1048
+ }
1049
+ }
1050
+ return K(V(0, n.edge.add(1e-5), s), c);
1051
+ })();
1052
+ return {
1053
+ mask: o.x,
1054
+ value: o.y
1055
+ };
1056
+ }
1057
+ function wn(e, t, n, r, i) {
1058
+ let a = t, o = n, s = d(() => {
1059
+ let t = K(e.x.mul(a), e.y.mul(o)), n = A(t.y), s = k(1e9).toVar(), c = k(0).toVar(), l = k(0).toVar(), u = k(0).toVar();
1060
+ for (let r = -1; r <= 1; r++) {
1061
+ let i = n.add(r), d = z(L(i, k(2)).notEqual(0), k(.5), k(0)), f = A(t.x.sub(d));
1062
+ for (let t = -1; t <= 1; t++) {
1063
+ let n = f.add(t), r = n.add(.5).add(d).div(a), p = i.add(.5).div(o), m = N(K(e.x.sub(r), e.y.sub(p))), h = m.lessThan(s);
1064
+ s.assign(z(h, m, s)), c.assign(z(h, r, c)), l.assign(z(h, p, l)), u.assign(z(h, at(M(n), M(i), a, o), u));
1065
+ }
1066
+ }
1067
+ let d = k(1e9).toVar();
1068
+ for (let r = -1; r <= 1; r++) {
1069
+ let i = n.add(r), s = z(L(i, k(2)).notEqual(0), k(.5), k(0)), u = A(t.x.sub(s));
1070
+ for (let t = -1; t <= 1; t++) {
1071
+ let n = u.add(t).add(.5).add(s).div(a), r = i.add(.5).div(o), f = n.sub(c), p = r.sub(l), m = N(K(f, p)).add(1e-9), h = c.add(n).mul(.5), g = l.add(r).mul(.5), _ = h.sub(e.x).mul(f.div(m)).add(g.sub(e.y).mul(p.div(m))), v = m.lessThan(1e-4);
1072
+ d.assign(F(d, z(v, k(1e9), _)));
1073
+ }
1074
+ }
1075
+ return K(V(r, r.add(i).add(1e-5), d), u);
1076
+ })();
1077
+ return {
1078
+ mask: s.x,
1079
+ value: s.y
1080
+ };
1081
+ }
1082
+ var Tn = {
1083
+ type: "tile",
1084
+ nodeClass: "texture",
1085
+ label: "Tile Generator",
1086
+ inputs: [{
1087
+ key: "coord",
1088
+ kind: "vector"
1089
+ }],
1090
+ outputs: [{
1091
+ key: "mask",
1092
+ label: "Mask",
1093
+ kind: "float"
1094
+ }, {
1095
+ key: "value",
1096
+ label: "Value",
1097
+ kind: "float"
1098
+ }],
1099
+ params: [
1100
+ {
1101
+ key: "lattice",
1102
+ label: "lattice",
1103
+ type: "select",
1104
+ options: ["square", "hex"],
1105
+ default: "square"
1106
+ },
1107
+ {
1108
+ key: "columns",
1109
+ label: "columns",
1110
+ type: "int",
1111
+ min: 1,
1112
+ max: 32,
1113
+ step: 1,
1114
+ default: 6
1115
+ },
1116
+ {
1117
+ key: "rows",
1118
+ label: "rows",
1119
+ type: "int",
1120
+ min: 1,
1121
+ max: 64,
1122
+ step: 1,
1123
+ default: 12
1124
+ },
1125
+ {
1126
+ key: "offset",
1127
+ label: "row offset",
1128
+ type: "float",
1129
+ min: 0,
1130
+ max: 1,
1131
+ step: .01,
1132
+ default: .5
1133
+ },
1134
+ {
1135
+ key: "offsetFreq",
1136
+ label: "offset every",
1137
+ type: "int",
1138
+ min: 1,
1139
+ max: 6,
1140
+ step: 1,
1141
+ default: 2
1142
+ },
1143
+ {
1144
+ key: "gap",
1145
+ label: "gap",
1146
+ type: "float",
1147
+ min: 0,
1148
+ max: .08,
1149
+ step: .001,
1150
+ default: .012
1151
+ },
1152
+ {
1153
+ key: "roundness",
1154
+ label: "roundness",
1155
+ type: "float",
1156
+ min: 0,
1157
+ max: 1,
1158
+ step: .01,
1159
+ default: .05
1160
+ },
1161
+ {
1162
+ key: "edge",
1163
+ label: "edge soft",
1164
+ type: "float",
1165
+ min: 0,
1166
+ max: .05,
1167
+ step: .001,
1168
+ default: .004
1169
+ },
1170
+ {
1171
+ key: "sizeRandom",
1172
+ label: "size rand",
1173
+ type: "float",
1174
+ min: 0,
1175
+ max: 1,
1176
+ step: .01,
1177
+ default: 0
1178
+ },
1179
+ {
1180
+ key: "posRandom",
1181
+ label: "pos rand",
1182
+ type: "float",
1183
+ min: 0,
1184
+ max: 1,
1185
+ step: .01,
1186
+ default: 0
1187
+ },
1188
+ {
1189
+ key: "rotRandom",
1190
+ label: "rot rand",
1191
+ type: "float",
1192
+ min: 0,
1193
+ max: 1,
1194
+ step: .01,
1195
+ default: 0
1196
+ }
1197
+ ],
1198
+ build(e) {
1199
+ let t = e.inputs.coord ?? e.coord, n = Math.max(1, Math.round(Number(e.params.columns ?? 6)));
1200
+ if (e.params.lattice === "hex") {
1201
+ let { mask: r, value: i } = wn(t, n, Math.max(2, Math.round(n * 2 / Math.sqrt(3) / 2) * 2), e.uniforms.gap, e.uniforms.edge);
1202
+ return {
1203
+ mask: r,
1204
+ value: i
1205
+ };
1206
+ }
1207
+ let r = Math.max(1, Math.round(Number(e.params.offsetFreq ?? 2))), i = Math.max(1, Math.round(Number(e.params.rows ?? 12))), { mask: a, value: o } = Cn(t, {
1208
+ columns: n,
1209
+ rows: Math.ceil(i / r) * r,
1210
+ offsetFreq: r
1211
+ }, {
1212
+ rowOffset: e.uniforms.offset,
1213
+ gap: e.uniforms.gap,
1214
+ roundness: e.uniforms.roundness,
1215
+ edge: e.uniforms.edge,
1216
+ sizeRandom: e.uniforms.sizeRandom,
1217
+ posRandom: e.uniforms.posRandom,
1218
+ rotRandom: e.uniforms.rotRandom
1219
+ });
1220
+ return {
1221
+ mask: a,
1222
+ value: o
1223
+ };
1224
+ }
1225
+ }, En = Math.PI;
1226
+ function Dn(e, t, n) {
1227
+ let r = t, i = d(() => {
1228
+ let t = K(e.x.mul(r), e.y.mul(r)), i = A(t.x), a = A(t.y), o = k(1e9).toVar(), s = k(10).toVar(), c = k(10).toVar(), l = k(0).toVar(), u = k(1).toVar();
1229
+ for (let e = -1; e <= 1; e++) {
1230
+ let d = a.add(e), f = M(d);
1231
+ for (let e = -1; e <= 1; e++) {
1232
+ let a = i.add(e), p = M(a), m = st(p, f, 0, r, r), h = st(p, f, 1, r, r), g = h.z.lessThan(n.amount), _ = k(1).add(m.z.sub(.5).mul(2).mul(n.sizeRandom)), v = n.radius.div(r).mul(_), y = m.x.sub(.5).mul(n.posRandom), b = m.y.sub(.5).mul(n.posRandom), x = a.add(.5).add(y), C = d.add(.5).add(b), w = t.x.sub(x).div(r), T = t.y.sub(C).div(r), E = z(g, N(K(w, T)), k(1e9)), ee = h.x.sub(.5).mul(2).mul(n.rotRandom).mul(En).negate(), D = S(ee), O = B(ee), te = D.mul(w).sub(O.mul(T)).div(v.add(1e-9)), ne = O.mul(w).add(D.mul(T)).div(v.add(1e-9)), A = E.lessThan(o);
1233
+ s.assign(z(A, te, s)), c.assign(z(A, ne, c)), l.assign(z(A, h.y, l)), u.assign(z(A, _, u)), o.assign(z(A, E, o));
1234
+ }
1235
+ }
1236
+ return Oe(s, c, l, u);
1237
+ })();
1238
+ return {
1239
+ coord: q(i.x, i.y, 0),
1240
+ value: i.z,
1241
+ size: i.w
1242
+ };
1243
+ }
1244
+ //#endregion
1245
+ //#region src/graph/nodes/texture/scatter.ts
1246
+ var On = {
1247
+ type: "scatter",
1248
+ nodeClass: "texture",
1249
+ label: "Scatter",
1250
+ inputs: [{
1251
+ key: "coord",
1252
+ kind: "vector"
1253
+ }],
1254
+ outputs: [
1255
+ {
1256
+ key: "coord",
1257
+ label: "Coord",
1258
+ kind: "vector"
1259
+ },
1260
+ {
1261
+ key: "value",
1262
+ label: "Value",
1263
+ kind: "float"
1264
+ },
1265
+ {
1266
+ key: "size",
1267
+ label: "Size",
1268
+ kind: "float"
1269
+ }
1270
+ ],
1271
+ params: [
1272
+ {
1273
+ key: "density",
1274
+ label: "density",
1275
+ type: "int",
1276
+ min: 1,
1277
+ max: 48,
1278
+ step: 1,
1279
+ default: 10
1280
+ },
1281
+ {
1282
+ key: "amount",
1283
+ label: "amount",
1284
+ type: "float",
1285
+ min: 0,
1286
+ max: 1,
1287
+ step: .01,
1288
+ default: .5
1289
+ },
1290
+ {
1291
+ key: "radius",
1292
+ label: "radius",
1293
+ type: "float",
1294
+ min: .05,
1295
+ max: 1,
1296
+ step: .01,
1297
+ default: .4
1298
+ },
1299
+ {
1300
+ key: "sizeRandom",
1301
+ label: "size rand",
1302
+ type: "float",
1303
+ min: 0,
1304
+ max: 1,
1305
+ step: .01,
1306
+ default: .6
1307
+ },
1308
+ {
1309
+ key: "posRandom",
1310
+ label: "pos rand",
1311
+ type: "float",
1312
+ min: 0,
1313
+ max: 1,
1314
+ step: .01,
1315
+ default: .85
1316
+ },
1317
+ {
1318
+ key: "rotRandom",
1319
+ label: "rot rand",
1320
+ type: "float",
1321
+ min: 0,
1322
+ max: 1,
1323
+ step: .01,
1324
+ default: 1
1325
+ }
1326
+ ],
1327
+ build(e) {
1328
+ let t = e.inputs.coord ?? e.coord, n = Math.round(Number(e.params.density ?? 10)), { coord: r, value: i, size: a } = Dn(t, Number.isFinite(n) ? Math.max(1, n) : 10, {
1329
+ amount: e.uniforms.amount,
1330
+ radius: e.uniforms.radius,
1331
+ sizeRandom: e.uniforms.sizeRandom,
1332
+ posRandom: e.uniforms.posRandom,
1333
+ rotRandom: e.uniforms.rotRandom
1334
+ });
1335
+ return {
1336
+ coord: r,
1337
+ value: i,
1338
+ size: a
1339
+ };
1340
+ }
1341
+ }, kn = 6.283185307179586;
1342
+ function An(e, t, n, r, i) {
1343
+ let a = r ?? k(0), o = d(() => {
1344
+ let r = N(K(e.x, e.y)), o = h(e.y, e.x), s, c;
1345
+ if (t === "polygon") {
1346
+ let e = Math.max(3, Math.round(n)), t = kn / e, a = S(A(o.div(t).add(.5)).mul(t).sub(o)).mul(r), l = Math.cos(Math.PI / e), u = b(a.div(l), 0, 1);
1347
+ s = V(0, i.edge.add(1e-4), u.oneMinus()), c = u.oneMinus();
1348
+ } else {
1349
+ let e = j(a.mul(13.13)).mul(kn), t = j(a.mul(27.71)).mul(kn), n = j(a.mul(51.37)).mul(kn), l = B(o.mul(2).add(e)).mul(.5).add(B(o.mul(3).add(t)).mul(.3)).add(B(o.mul(5).add(n)).mul(.2)), u = k(1).add(l.mul(i.irregularity.mul(.4))), d = b(r.div(u.add(1e-6)), 0, 1);
1350
+ s = V(0, i.edge.add(1e-4), d.oneMinus()), c = d.oneMinus();
1351
+ }
1352
+ let l = b(r, 0, 1), u = R(b(l.mul(l).oneMinus(), 0, 1), i.dome), d = V(0, .3, c), f = u.mul(d);
1353
+ return q(s, f, 0);
1354
+ })();
1355
+ return {
1356
+ mask: o.x,
1357
+ height: o.y
1358
+ };
1359
+ }
1360
+ var jn = {
1361
+ type: "shape",
1362
+ nodeClass: "texture",
1363
+ label: "Shape",
1364
+ inputs: [{
1365
+ key: "coord",
1366
+ kind: "vector"
1367
+ }, {
1368
+ key: "seed",
1369
+ label: "Seed",
1370
+ kind: "float"
1371
+ }],
1372
+ outputs: [{
1373
+ key: "mask",
1374
+ label: "Mask",
1375
+ kind: "float"
1376
+ }, {
1377
+ key: "height",
1378
+ label: "Height",
1379
+ kind: "float"
1380
+ }],
1381
+ params: [
1382
+ {
1383
+ key: "shape",
1384
+ label: "shape",
1385
+ type: "select",
1386
+ options: ["blob", "polygon"],
1387
+ default: "blob"
1388
+ },
1389
+ {
1390
+ key: "sides",
1391
+ label: "sides",
1392
+ type: "int",
1393
+ min: 3,
1394
+ max: 12,
1395
+ step: 1,
1396
+ default: 6
1397
+ },
1398
+ {
1399
+ key: "irregularity",
1400
+ label: "irregularity",
1401
+ type: "float",
1402
+ min: 0,
1403
+ max: 1,
1404
+ step: .01,
1405
+ default: .6
1406
+ },
1407
+ {
1408
+ key: "dome",
1409
+ label: "dome",
1410
+ type: "float",
1411
+ min: .2,
1412
+ max: 3,
1413
+ step: .05,
1414
+ default: .6
1415
+ },
1416
+ {
1417
+ key: "edge",
1418
+ label: "edge soft",
1419
+ type: "float",
1420
+ min: .002,
1421
+ max: .3,
1422
+ step: .002,
1423
+ default: .04
1424
+ }
1425
+ ],
1426
+ build(e) {
1427
+ let t = e.inputs.coord ?? e.coord, n = e.inputs.seed, r = e.params.shape ?? "blob", i = Math.round(Number(e.params.sides ?? 6)), { mask: a, height: o } = An(t, r, Number.isFinite(i) ? Math.max(3, i) : 6, n ?? null, {
1428
+ irregularity: e.uniforms.irregularity,
1429
+ dome: e.uniforms.dome,
1430
+ edge: e.uniforms.edge
1431
+ });
1432
+ return {
1433
+ mask: a,
1434
+ height: o
1435
+ };
1436
+ }
1437
+ }, Mn = Math.PI * 2;
1438
+ function Nn(e, t) {
1439
+ let n = e.x, r = e.y, i = e.z, a;
1440
+ switch (t) {
1441
+ case 1: {
1442
+ let e = n.max(0);
1443
+ a = e.mul(e);
1444
+ break;
1445
+ }
1446
+ case 2: {
1447
+ let e = n.clamp(0, 1), t = e.mul(e);
1448
+ a = t.mul(3).sub(t.mul(e).mul(2));
1449
+ break;
1450
+ }
1451
+ case 3:
1452
+ a = n.add(r).mul(.5);
1453
+ break;
1454
+ case 4:
1455
+ a = h(r, n).div(Mn).add(.5);
1456
+ break;
1457
+ case 5: {
1458
+ let e = k(.999999).sub(n.mul(n).add(r.mul(r)).add(i.mul(i)).sqrt()).max(0);
1459
+ a = e.mul(e);
1460
+ break;
1461
+ }
1462
+ case 6:
1463
+ a = k(.999999).sub(n.mul(n).add(r.mul(r)).add(i.mul(i)).sqrt()).max(0);
1464
+ break;
1465
+ default: a = n;
1466
+ }
1467
+ return a.clamp(0, 1);
1468
+ }
1469
+ //#endregion
1470
+ //#region src/graph/nodes/texture/gradient.ts
1471
+ var Pn = [
1472
+ "linear",
1473
+ "quadratic",
1474
+ "easing",
1475
+ "diagonal",
1476
+ "radial",
1477
+ "quadratic-sphere",
1478
+ "sphere"
1479
+ ], Fn = {
1480
+ type: "gradient",
1481
+ nodeClass: "texture",
1482
+ label: "Gradient",
1483
+ inputs: [{
1484
+ key: "coord",
1485
+ kind: "vector"
1486
+ }],
1487
+ outputs: [{
1488
+ key: "field",
1489
+ kind: "float"
1490
+ }],
1491
+ params: [{
1492
+ key: "scale",
1493
+ label: "scale",
1494
+ type: "float",
1495
+ min: .1,
1496
+ max: 8,
1497
+ step: .05,
1498
+ default: 1
1499
+ }, {
1500
+ key: "gradientType",
1501
+ label: "type",
1502
+ type: "select",
1503
+ options: Pn,
1504
+ default: "linear"
1505
+ }],
1506
+ build(e) {
1507
+ return { field: Nn((e.inputs.coord ?? e.coord).mul(e.uniforms.scale), Math.max(0, Pn.indexOf(e.params.gradientType))) };
1508
+ }
1509
+ }, X = Math.PI * 2, In = Math.PI / 2, Ln = 20, Rn = 10;
1510
+ function zn(e, t) {
1511
+ if (t === 0) return k(.5).add(B(e.sub(In)).mul(.5));
1512
+ if (t === 1) {
1513
+ let t = e.div(X);
1514
+ return t.sub(A(t));
1515
+ }
1516
+ let n = e.div(X);
1517
+ return n.sub(A(n.add(.5))).abs().mul(2);
1518
+ }
1519
+ function Bn(e, t, n, r, i) {
1520
+ let a = Math.max(1, Math.round(i.scaleNum * Ln / X)), o = Math.max(1, Math.round(i.scaleNum * Rn / X)), s;
1521
+ if (s = i.dir === 0 ? e.x.mul(a * X) : i.dir === 1 ? e.y.mul(a * X) : i.dir === 2 ? e.z.mul(a * X) : e.x.add(e.y).add(e.z).mul(o * X), s = s.add(t), i.withDistortion) {
1522
+ let t = Math.max(1, Math.round(i.scaleNum * i.detailScaleNum)), a = t, o = t;
1523
+ i.dir === 0 ? o = 2 : i.dir === 1 && (a = 2);
1524
+ let c = et(K(e.x, e.y), a, o, Math.max(1, i.detail), r);
1525
+ s = s.add(n.mul(c));
1526
+ }
1527
+ return zn(s, i.profile);
1528
+ }
1529
+ function Vn(e, t, n, r, i, a) {
1530
+ let o = (e) => e.sub(_e(e)), s;
1531
+ s = a.dir === 0 ? q(k(0), o(e.y), o(e.z)) : a.dir === 1 ? q(o(e.x), k(0), o(e.z)) : a.dir === 2 ? q(o(e.x), o(e.y), k(0)) : q(o(e.x), o(e.y), o(e.z));
1532
+ let c = s.length().mul(t).mul(Ln).add(n);
1533
+ if (a.withDistortion) {
1534
+ let t = Math.max(1, Math.round(a.scaleNum * a.detailScaleNum)), n = et(K(e.x, e.y), t, t, Math.max(1, a.detail), i);
1535
+ c = c.add(r.mul(n));
1536
+ }
1537
+ return zn(c, a.profile);
1538
+ }
1539
+ function Hn(e, t, n, r, i, a, o) {
1540
+ if (o.tileable) return o.waveType === 0 ? Bn(e, n, r, a, o) : Vn(e, t, n, r, a, o);
1541
+ let s = e.mul(t).add(1e-6).mul(.999999), c;
1542
+ if (o.waveType === 0) c = o.dir === 0 ? s.x.mul(Ln) : o.dir === 1 ? s.y.mul(Ln) : o.dir === 2 ? s.z.mul(Ln) : s.x.add(s.y).add(s.z).mul(Rn);
1543
+ else {
1544
+ let e = s;
1545
+ o.dir === 0 ? e = s.mul(q(0, 1, 1)) : o.dir === 1 ? e = s.mul(q(1, 0, 1)) : o.dir === 2 && (e = s.mul(q(1, 1, 0))), c = e.length().mul(Ln);
1546
+ }
1547
+ if (c = c.add(n), o.withDistortion) {
1548
+ let e = Je(s.mul(i), o.detail, a, k(2));
1549
+ c = c.add(r.mul(e.mul(2).sub(1)));
1550
+ }
1551
+ return zn(c, o.profile);
1552
+ }
1553
+ //#endregion
1554
+ //#region src/graph/nodes/texture/wave.ts
1555
+ var Un = ["bands", "rings"], Wn = [
1556
+ "x",
1557
+ "y",
1558
+ "z",
1559
+ "diagonal"
1560
+ ], Gn = [
1561
+ "sine",
1562
+ "saw",
1563
+ "triangle"
1564
+ ], Kn = {
1565
+ type: "wave",
1566
+ nodeClass: "texture",
1567
+ label: "Wave",
1568
+ inputs: [{
1569
+ key: "coord",
1570
+ kind: "vector"
1571
+ }],
1572
+ outputs: [{
1573
+ key: "field",
1574
+ kind: "float"
1575
+ }],
1576
+ params: [
1577
+ {
1578
+ key: "scale",
1579
+ label: "scale",
1580
+ type: "float",
1581
+ min: .1,
1582
+ max: 8,
1583
+ step: .05,
1584
+ default: 1,
1585
+ bakeStructural: !0
1586
+ },
1587
+ {
1588
+ key: "waveType",
1589
+ label: "type",
1590
+ type: "select",
1591
+ options: Un,
1592
+ default: "bands"
1593
+ },
1594
+ {
1595
+ key: "direction",
1596
+ label: "direction",
1597
+ type: "select",
1598
+ options: Wn,
1599
+ default: "x"
1600
+ },
1601
+ {
1602
+ key: "profile",
1603
+ label: "profile",
1604
+ type: "select",
1605
+ options: Gn,
1606
+ default: "sine"
1607
+ },
1608
+ {
1609
+ key: "phase",
1610
+ label: "phase",
1611
+ type: "float",
1612
+ min: 0,
1613
+ max: 20,
1614
+ step: .1,
1615
+ default: 0
1616
+ },
1617
+ {
1618
+ key: "distortion",
1619
+ label: "distortion",
1620
+ type: "float",
1621
+ min: 0,
1622
+ max: 10,
1623
+ step: .1,
1624
+ default: 0,
1625
+ bakeStructural: !0
1626
+ },
1627
+ {
1628
+ key: "detail",
1629
+ label: "detail",
1630
+ type: "int",
1631
+ min: 0,
1632
+ max: 8,
1633
+ step: 1,
1634
+ default: 2
1635
+ },
1636
+ {
1637
+ key: "detailScale",
1638
+ label: "detail scale",
1639
+ type: "float",
1640
+ min: 0,
1641
+ max: 8,
1642
+ step: .1,
1643
+ default: 1,
1644
+ bakeStructural: !0
1645
+ },
1646
+ {
1647
+ key: "detailRoughness",
1648
+ label: "detail rough",
1649
+ type: "float",
1650
+ min: 0,
1651
+ max: 1,
1652
+ step: .01,
1653
+ default: .5
1654
+ }
1655
+ ],
1656
+ build(e) {
1657
+ let t = e.inputs.coord ?? e.coord, n = {
1658
+ waveType: Math.max(0, Un.indexOf(e.params.waveType)),
1659
+ dir: Math.max(0, Wn.indexOf(e.params.direction)),
1660
+ profile: Math.max(0, Gn.indexOf(e.params.profile)),
1661
+ withDistortion: Number(e.params.distortion ?? 0) > 0,
1662
+ detail: e.params.detail ?? 2,
1663
+ tileable: e.backend === "offline",
1664
+ scaleNum: Number(e.params.scale ?? 1),
1665
+ detailScaleNum: Number(e.params.detailScale ?? 1)
1666
+ };
1667
+ return { field: Hn(t, e.uniforms.scale, e.uniforms.phase, e.uniforms.distortion, e.uniforms.detailScale, e.uniforms.detailRoughness, n) };
1668
+ }
1669
+ }, qn = 6.283185307179586, Jn = {
1670
+ type: "anisotropic-stripes",
1671
+ nodeClass: "texture",
1672
+ label: "Anisotropic Stripes",
1673
+ inputs: [{
1674
+ key: "coord",
1675
+ kind: "vector"
1676
+ }],
1677
+ outputs: [{
1678
+ key: "field",
1679
+ kind: "float"
1680
+ }],
1681
+ params: [
1682
+ {
1683
+ key: "count",
1684
+ label: "count",
1685
+ type: "float",
1686
+ min: 1,
1687
+ max: 64,
1688
+ step: 1,
1689
+ default: 22
1690
+ },
1691
+ {
1692
+ key: "sharpness",
1693
+ label: "sharpness",
1694
+ type: "float",
1695
+ min: .2,
1696
+ max: 8,
1697
+ step: .1,
1698
+ default: 2.2
1699
+ },
1700
+ {
1701
+ key: "waviness",
1702
+ label: "waviness",
1703
+ type: "float",
1704
+ min: 0,
1705
+ max: 2,
1706
+ step: .01,
1707
+ default: .18
1708
+ },
1709
+ {
1710
+ key: "contrast",
1711
+ label: "contrast",
1712
+ type: "float",
1713
+ min: 0,
1714
+ max: 1,
1715
+ step: .01,
1716
+ default: 1
1717
+ }
1718
+ ],
1719
+ build(e) {
1720
+ let t = e.inputs.coord ?? e.coord, n = h(t.z, t.x).div(qn), r = se(q(t.y.mul(.6), n.mul(6), k(0))).mul(e.uniforms.waviness);
1721
+ return { field: n.mul(e.uniforms.count).add(r).mul(qn).sin().mul(.5).add(.5).pow(e.uniforms.sharpness).mul(e.uniforms.contrast) };
1722
+ }
1723
+ }, Yn = /* @__PURE__ */ "add.subtract.multiply.divide.multiply-add.power.logarithm.sqrt.inverse-sqrt.absolute.exponent.min.max.less-than.greater-than.sign.compare.smooth-min.smooth-max.round.floor.ceil.truncate.fraction.modulo.floored-modulo.wrap.snap.pingpong.sine.cosine.tangent.arcsine.arccosine.arctangent.arctan2.sinh.cosh.tanh.radians.degrees.mix".split("."), Xn = new Set([
1724
+ "sqrt",
1725
+ "inverse-sqrt",
1726
+ "absolute",
1727
+ "exponent",
1728
+ "sign",
1729
+ "round",
1730
+ "floor",
1731
+ "ceil",
1732
+ "truncate",
1733
+ "fraction",
1734
+ "sine",
1735
+ "cosine",
1736
+ "tangent",
1737
+ "arcsine",
1738
+ "arccosine",
1739
+ "arctangent",
1740
+ "sinh",
1741
+ "cosh",
1742
+ "tanh",
1743
+ "radians",
1744
+ "degrees"
1745
+ ]), Zn = new Set([
1746
+ "multiply-add",
1747
+ "compare",
1748
+ "smooth-min",
1749
+ "smooth-max",
1750
+ "wrap"
1751
+ ]), Qn = {
1752
+ power: ["Base", "Exponent"],
1753
+ logarithm: ["Value", "Base"],
1754
+ "multiply-add": [
1755
+ "Value",
1756
+ "Multiplier",
1757
+ "Addend"
1758
+ ],
1759
+ compare: [
1760
+ "A",
1761
+ "B",
1762
+ "Epsilon"
1763
+ ],
1764
+ "smooth-min": [
1765
+ "A",
1766
+ "B",
1767
+ "Distance"
1768
+ ],
1769
+ "smooth-max": [
1770
+ "A",
1771
+ "B",
1772
+ "Distance"
1773
+ ],
1774
+ wrap: [
1775
+ "Value",
1776
+ "Max",
1777
+ "Min"
1778
+ ],
1779
+ snap: ["Value", "Increment"],
1780
+ pingpong: ["Value", "Scale"],
1781
+ radians: ["Degrees"],
1782
+ degrees: ["Radians"]
1783
+ };
1784
+ function $n(e) {
1785
+ let [t, n, r] = Qn[e] ?? [
1786
+ "A",
1787
+ "B",
1788
+ "C"
1789
+ ], i = [{
1790
+ key: "a",
1791
+ label: t,
1792
+ kind: "float"
1793
+ }];
1794
+ return Xn.has(e) || i.push({
1795
+ key: "b",
1796
+ label: n ?? "B",
1797
+ kind: "float"
1798
+ }), Zn.has(e) && i.push({
1799
+ key: "c",
1800
+ label: r ?? "C",
1801
+ kind: "float"
1802
+ }), i;
1803
+ }
1804
+ var er = {
1805
+ type: "math",
1806
+ nodeClass: "converter",
1807
+ label: "Math",
1808
+ inputs: [{
1809
+ key: "a",
1810
+ label: "A",
1811
+ kind: "float"
1812
+ }, {
1813
+ key: "b",
1814
+ label: "B",
1815
+ kind: "float"
1816
+ }],
1817
+ outputs: [{
1818
+ key: "field",
1819
+ kind: "float"
1820
+ }],
1821
+ params: [
1822
+ {
1823
+ key: "op",
1824
+ label: "op",
1825
+ type: "select",
1826
+ options: Yn,
1827
+ default: "mix"
1828
+ },
1829
+ {
1830
+ key: "factor",
1831
+ label: "factor / B",
1832
+ type: "float",
1833
+ min: 0,
1834
+ max: 1,
1835
+ step: .01,
1836
+ default: .5
1837
+ },
1838
+ {
1839
+ key: "c",
1840
+ label: "C",
1841
+ type: "float",
1842
+ min: 0,
1843
+ max: 1,
1844
+ step: .01,
1845
+ default: .5
1846
+ }
1847
+ ],
1848
+ declare(e) {
1849
+ return {
1850
+ inputs: $n(e.op ?? "mix"),
1851
+ outputs: [{
1852
+ key: "field",
1853
+ kind: "float"
1854
+ }]
1855
+ };
1856
+ },
1857
+ build(e) {
1858
+ let t = e.inputs.a ?? k(0), n = e.inputs.b ?? e.uniforms.factor, r = e.inputs.c ?? e.uniforms.c;
1859
+ switch (e.params.op) {
1860
+ case "add": return { field: t.add(n) };
1861
+ case "subtract": return { field: t.sub(n) };
1862
+ case "multiply": return { field: t.mul(n) };
1863
+ case "divide": return { field: z(n.equal(0), k(0), t.div(n)) };
1864
+ case "multiply-add": return { field: t.mul(n).add(r) };
1865
+ case "power": return { field: R(t, n) };
1866
+ case "logarithm": return { field: z(t.greaterThan(0).and(n.greaterThan(0)), ae(t).div(ae(n)), k(0)) };
1867
+ case "sqrt": return { field: Se(t) };
1868
+ case "inverse-sqrt": return { field: z(t.greaterThan(0), ie(t), k(0)) };
1869
+ case "absolute": return { field: f(t) };
1870
+ case "exponent": return { field: O(t) };
1871
+ case "min": return { field: F(t, n) };
1872
+ case "max": return { field: P(t, n) };
1873
+ case "less-than": return { field: z(t.lessThan(n), k(1), k(0)) };
1874
+ case "greater-than": return { field: z(t.greaterThan(n), k(1), k(0)) };
1875
+ case "sign": return { field: be(t) };
1876
+ case "compare": return { field: z(t.sub(n).abs().lessThanEqual(P(r, k(1e-5))), k(1), k(0)) };
1877
+ case "smooth-min": return { field: tr(t, n, r) };
1878
+ case "smooth-max": return { field: tr(t.negate(), n.negate(), r).negate() };
1879
+ case "round": return { field: _e(t) };
1880
+ case "floor": return { field: A(t) };
1881
+ case "ceil": return { field: y(t) };
1882
+ case "truncate": return { field: Ee(t) };
1883
+ case "fraction": return { field: j(t) };
1884
+ case "modulo": return { field: z(n.equal(0), k(0), t.sub(n.mul(Ee(t.div(n))))) };
1885
+ case "floored-modulo": return { field: z(n.equal(0), k(0), t.sub(n.mul(A(t.div(n))))) };
1886
+ case "wrap": return { field: nr(t, n, r) };
1887
+ case "snap": return { field: z(n.equal(0), k(0), A(t.div(n)).mul(n)) };
1888
+ case "pingpong": return { field: rr(t, n) };
1889
+ case "sine": return { field: B(t) };
1890
+ case "cosine": return { field: S(t) };
1891
+ case "tangent": return { field: we(t) };
1892
+ case "arcsine": return { field: z(t.abs().lessThanEqual(1), m(t), k(0)) };
1893
+ case "arccosine": return { field: z(t.abs().lessThanEqual(1), p(t), k(0)) };
1894
+ case "arctangent": return { field: h(t) };
1895
+ case "arctan2": return { field: h(t, n) };
1896
+ case "sinh": return { field: xe(t) };
1897
+ case "cosh": return { field: C(t) };
1898
+ case "tanh": return { field: Te(t) };
1899
+ case "radians": return { field: he(t) };
1900
+ case "degrees": return { field: ee(t) };
1901
+ default: return { field: I(t, n, e.uniforms.factor) };
1902
+ }
1903
+ }
1904
+ };
1905
+ function tr(e, t, n) {
1906
+ let r = P(n.sub(e.sub(t).abs()), k(0)).div(n), i = F(e, t).sub(r.mul(r).mul(r).mul(n).div(6));
1907
+ return z(n.equal(0), F(e, t), i);
1908
+ }
1909
+ function nr(e, t, n) {
1910
+ let r = t.sub(n);
1911
+ return z(r.equal(0), n, e.sub(r.mul(A(e.sub(n).div(r)))));
1912
+ }
1913
+ function rr(e, t) {
1914
+ let n = t.mul(2);
1915
+ return z(t.equal(0), k(0), j(e.sub(t).div(n)).mul(n).sub(t).abs());
1916
+ }
1917
+ //#endregion
1918
+ //#region src/graph/nodes/converter/levels.ts
1919
+ var ir = {
1920
+ type: "levels",
1921
+ nodeClass: "converter",
1922
+ label: "Levels / Remap",
1923
+ inputs: [{
1924
+ key: "field",
1925
+ kind: "float"
1926
+ }],
1927
+ outputs: [{
1928
+ key: "field",
1929
+ kind: "float"
1930
+ }],
1931
+ params: [
1932
+ {
1933
+ key: "min",
1934
+ label: "out min",
1935
+ type: "float",
1936
+ min: 0,
1937
+ max: 1,
1938
+ step: .01,
1939
+ default: 0
1940
+ },
1941
+ {
1942
+ key: "max",
1943
+ label: "out max",
1944
+ type: "float",
1945
+ min: 0,
1946
+ max: 1,
1947
+ step: .01,
1948
+ default: 1
1949
+ },
1950
+ {
1951
+ key: "invert",
1952
+ label: "invert",
1953
+ type: "bool",
1954
+ default: !1
1955
+ }
1956
+ ],
1957
+ build(e) {
1958
+ let t = e.inputs.field ?? k(.5), n = e.params.invert ? t.oneMinus() : t;
1959
+ return { field: I(e.uniforms.min, e.uniforms.max, n) };
1960
+ }
1961
+ }, ar = {
1962
+ type: "color-ramp",
1963
+ nodeClass: "converter",
1964
+ label: "Color Ramp",
1965
+ inputs: [{
1966
+ key: "field",
1967
+ kind: "float"
1968
+ }],
1969
+ outputs: [{
1970
+ key: "color",
1971
+ kind: "color"
1972
+ }],
1973
+ params: [
1974
+ {
1975
+ key: "colorA",
1976
+ label: "low",
1977
+ type: "color",
1978
+ default: "#3f2d1e"
1979
+ },
1980
+ {
1981
+ key: "colorB",
1982
+ label: "high",
1983
+ type: "color",
1984
+ default: "#8a6a4a"
1985
+ },
1986
+ {
1987
+ key: "low",
1988
+ label: "low stop",
1989
+ type: "float",
1990
+ min: 0,
1991
+ max: 1,
1992
+ step: .01,
1993
+ default: .3
1994
+ },
1995
+ {
1996
+ key: "high",
1997
+ label: "high stop",
1998
+ type: "float",
1999
+ min: 0,
2000
+ max: 1,
2001
+ step: .01,
2002
+ default: .75
2003
+ }
2004
+ ],
2005
+ build(e) {
2006
+ let t = e.inputs.field ?? k(.5), n = e.uniforms.low, r = e.uniforms.high, i = b(t.sub(n).div(r.sub(n).max(1e-5)), 0, 1);
2007
+ return { color: I(e.uniforms.colorA, e.uniforms.colorB, i) };
2008
+ }
2009
+ }, or = {
2010
+ type: "height-blend",
2011
+ nodeClass: "converter",
2012
+ label: "Height Blend",
2013
+ inputs: [
2014
+ {
2015
+ key: "heightA",
2016
+ label: "Height A",
2017
+ kind: "float"
2018
+ },
2019
+ {
2020
+ key: "heightB",
2021
+ label: "Height B",
2022
+ kind: "float"
2023
+ },
2024
+ {
2025
+ key: "breakup",
2026
+ label: "Breakup",
2027
+ kind: "float"
2028
+ }
2029
+ ],
2030
+ outputs: [{
2031
+ key: "fac",
2032
+ kind: "float"
2033
+ }],
2034
+ params: [
2035
+ {
2036
+ key: "transition",
2037
+ label: "transition",
2038
+ type: "float",
2039
+ min: 0,
2040
+ max: 1,
2041
+ step: .01,
2042
+ default: .5
2043
+ },
2044
+ {
2045
+ key: "width",
2046
+ label: "width",
2047
+ type: "float",
2048
+ min: .01,
2049
+ max: 1,
2050
+ step: .01,
2051
+ default: .25
2052
+ },
2053
+ {
2054
+ key: "breakup",
2055
+ label: "breakup amt",
2056
+ type: "float",
2057
+ min: 0,
2058
+ max: 1,
2059
+ step: .01,
2060
+ default: 0
2061
+ }
2062
+ ],
2063
+ build(e) {
2064
+ let t = e.inputs.heightA ?? k(.5), n = e.inputs.heightB ?? k(.5), r = e.uniforms.transition, i = e.uniforms.width;
2065
+ e.inputs.breakup !== void 0 && (n = n.add(e.inputs.breakup.sub(.5).mul(e.uniforms.breakup)));
2066
+ let a = n.sub(t).add(r.mul(2).sub(1));
2067
+ return { fac: V(i.negate(), i, a) };
2068
+ }
2069
+ }, sr = {
2070
+ type: "blend",
2071
+ nodeClass: "color",
2072
+ label: "Blend",
2073
+ inputs: [
2074
+ {
2075
+ key: "a",
2076
+ label: "base",
2077
+ kind: "color"
2078
+ },
2079
+ {
2080
+ key: "b",
2081
+ label: "over",
2082
+ kind: "color"
2083
+ },
2084
+ {
2085
+ key: "mask",
2086
+ kind: "float"
2087
+ }
2088
+ ],
2089
+ outputs: [{
2090
+ key: "color",
2091
+ kind: "color"
2092
+ }],
2093
+ params: [{
2094
+ key: "mode",
2095
+ label: "mode",
2096
+ type: "select",
2097
+ options: [
2098
+ "mix",
2099
+ "multiply",
2100
+ "screen",
2101
+ "add"
2102
+ ],
2103
+ default: "mix"
2104
+ }, {
2105
+ key: "opacity",
2106
+ label: "opacity",
2107
+ type: "float",
2108
+ min: 0,
2109
+ max: 1,
2110
+ step: .01,
2111
+ default: 1
2112
+ }],
2113
+ build(e) {
2114
+ let t = e.inputs.a ?? x(0), n = e.inputs.b ?? x(16777215), r;
2115
+ switch (e.params.mode) {
2116
+ case "multiply":
2117
+ r = t.mul(n);
2118
+ break;
2119
+ case "screen":
2120
+ r = t.oneMinus().mul(n.oneMinus()).oneMinus();
2121
+ break;
2122
+ case "add":
2123
+ r = t.add(n);
2124
+ break;
2125
+ default:
2126
+ r = n;
2127
+ break;
2128
+ }
2129
+ let i = (e.inputs.mask ?? k(1)).mul(e.uniforms.opacity);
2130
+ return { color: I(t, r, i) };
2131
+ }
2132
+ }, cr = {
2133
+ type: "invert",
2134
+ nodeClass: "color",
2135
+ label: "Invert Color",
2136
+ inputs: [{
2137
+ key: "fac",
2138
+ label: "Fac",
2139
+ kind: "float"
2140
+ }, {
2141
+ key: "color",
2142
+ label: "Color",
2143
+ kind: "color"
2144
+ }],
2145
+ outputs: [{
2146
+ key: "color",
2147
+ kind: "color"
2148
+ }],
2149
+ params: [{
2150
+ key: "fac",
2151
+ label: "fac",
2152
+ type: "float",
2153
+ min: 0,
2154
+ max: 1,
2155
+ step: .01,
2156
+ default: 1
2157
+ }],
2158
+ build(e) {
2159
+ let t = e.inputs.color ?? q(0, 0, 0), n = e.inputs.fac ?? e.uniforms.fac;
2160
+ return { color: I(t, q(1, 1, 1).sub(t), n) };
2161
+ }
2162
+ }, lr = {
2163
+ type: "bright-contrast",
2164
+ nodeClass: "color",
2165
+ label: "Bright / Contrast",
2166
+ inputs: [
2167
+ {
2168
+ key: "color",
2169
+ label: "Color",
2170
+ kind: "color"
2171
+ },
2172
+ {
2173
+ key: "bright",
2174
+ label: "Bright",
2175
+ kind: "float"
2176
+ },
2177
+ {
2178
+ key: "contrast",
2179
+ label: "Contrast",
2180
+ kind: "float"
2181
+ }
2182
+ ],
2183
+ outputs: [{
2184
+ key: "color",
2185
+ kind: "color"
2186
+ }],
2187
+ params: [{
2188
+ key: "bright",
2189
+ label: "bright",
2190
+ type: "float",
2191
+ min: -1,
2192
+ max: 1,
2193
+ step: .01,
2194
+ default: 0
2195
+ }, {
2196
+ key: "contrast",
2197
+ label: "contrast",
2198
+ type: "float",
2199
+ min: -1,
2200
+ max: 1,
2201
+ step: .01,
2202
+ default: 0
2203
+ }],
2204
+ build(e) {
2205
+ let t = e.inputs.color ?? q(0, 0, 0), n = e.inputs.contrast ?? e.uniforms.contrast, r = e.inputs.bright ?? e.uniforms.bright, i = k(1).add(n), a = r.sub(n.mul(.5));
2206
+ return { color: t.mul(i).add(a).max(0) };
2207
+ }
2208
+ }, ur = 1e-10;
2209
+ function dr(e) {
2210
+ let t = e.x, n = e.y, r = e.z, i = P(t, P(n, r)), a = F(t, F(n, r)), o = i.sub(a), s = i, c = z(i.equal(0), k(0), o.div(P(i, k(ur)))), l = q(i, i, i).sub(e).div(P(o, k(ur))), u = l.z.sub(l.y), d = k(2).add(l.x).sub(l.z), f = k(4).add(l.y).sub(l.x), p = z(n.equal(i), d, f);
2211
+ return p = z(t.equal(i), u, p), p = p.div(6), p = z(p.lessThan(0), p.add(1), p), p = z(c.equal(0), k(0), p), q(p, c, s);
2212
+ }
2213
+ function fr(e) {
2214
+ let t = e.x, n = e.y, r = e.z, i = z(t.equal(1), k(0), t).mul(6), a = A(i), o = i.sub(a), s = r.mul(k(1).sub(n)), c = r.mul(k(1).sub(n.mul(o))), l = r.mul(k(1).sub(n.mul(k(1).sub(o)))), u = q(r, s, c);
2215
+ return u = z(a.equal(4), q(l, s, r), u), u = z(a.equal(3), q(s, c, r), u), u = z(a.equal(2), q(s, r, l), u), u = z(a.equal(1), q(c, r, s), u), u = z(a.equal(0), q(r, l, s), u), z(n.equal(0), q(r, r, r), u);
2216
+ }
2217
+ //#endregion
2218
+ //#region src/graph/nodes/color/hue-sat-val.ts
2219
+ var pr = {
2220
+ type: "hue-sat-val",
2221
+ nodeClass: "color",
2222
+ label: "Hue / Saturation",
2223
+ inputs: [{
2224
+ key: "color",
2225
+ label: "Color",
2226
+ kind: "color"
2227
+ }],
2228
+ outputs: [{
2229
+ key: "color",
2230
+ kind: "color"
2231
+ }],
2232
+ params: [
2233
+ {
2234
+ key: "hue",
2235
+ label: "hue",
2236
+ type: "float",
2237
+ min: 0,
2238
+ max: 1,
2239
+ step: .001,
2240
+ default: .5
2241
+ },
2242
+ {
2243
+ key: "saturation",
2244
+ label: "saturation",
2245
+ type: "float",
2246
+ min: 0,
2247
+ max: 2,
2248
+ step: .01,
2249
+ default: 1
2250
+ },
2251
+ {
2252
+ key: "value",
2253
+ label: "value",
2254
+ type: "float",
2255
+ min: 0,
2256
+ max: 2,
2257
+ step: .01,
2258
+ default: 1
2259
+ },
2260
+ {
2261
+ key: "fac",
2262
+ label: "fac",
2263
+ type: "float",
2264
+ min: 0,
2265
+ max: 1,
2266
+ step: .01,
2267
+ default: 1
2268
+ }
2269
+ ],
2270
+ build(e) {
2271
+ let t = e.inputs.color ?? q(.8, .8, .8), n = dr(t);
2272
+ return { color: I(t, fr(q(j(n.x.add(e.uniforms.hue).add(.5)), n.y.mul(e.uniforms.saturation).clamp(0, 1), n.z.mul(e.uniforms.value))), e.uniforms.fac) };
2273
+ }
2274
+ }, mr = (e, t, n, r, i) => z(e.equal(0), t, z(e.equal(1), n, z(e.equal(2), r, i)));
2275
+ function hr(e, t) {
2276
+ let n = e.clamp(0, 1).mul(4), r = A(n).clamp(0, 3), i = n.sub(r), a = mr(r, t[0], t[0], t[1], t[2]), o = mr(r, t[0], t[1], t[2], t[3]), s = mr(r, t[1], t[2], t[3], t[4]), c = mr(r, t[2], t[3], t[4], t[4]), l = i.mul(i), u = l.mul(i);
2277
+ return o.mul(2).add(s.sub(a).mul(i)).add(a.mul(2).sub(o.mul(5)).add(s.mul(4)).sub(c).mul(l)).add(o.mul(3).sub(s.mul(3)).add(c).sub(a).mul(u)).mul(.5);
2278
+ }
2279
+ //#endregion
2280
+ //#region src/graph/nodes/color/rgb-curves.ts
2281
+ var gr = () => [...Ae], _r = {
2282
+ type: "rgb-curves",
2283
+ nodeClass: "color",
2284
+ label: "RGB Curves",
2285
+ inputs: [{
2286
+ key: "fac",
2287
+ label: "Fac",
2288
+ kind: "float"
2289
+ }, {
2290
+ key: "color",
2291
+ label: "Color",
2292
+ kind: "color"
2293
+ }],
2294
+ outputs: [{
2295
+ key: "color",
2296
+ kind: "color"
2297
+ }],
2298
+ params: [{
2299
+ key: "fac",
2300
+ label: "fac",
2301
+ type: "float",
2302
+ min: 0,
2303
+ max: 1,
2304
+ step: .01,
2305
+ default: 1
2306
+ }, {
2307
+ key: "curves",
2308
+ label: "curves",
2309
+ type: "curve",
2310
+ default: {
2311
+ C: gr(),
2312
+ R: gr(),
2313
+ G: gr(),
2314
+ B: gr()
2315
+ }
2316
+ }],
2317
+ build(e) {
2318
+ let t = e.inputs.color ?? q(0, 0, 0), n = e.uniforms.curves, r = (e) => [
2319
+ 0,
2320
+ 1,
2321
+ 2,
2322
+ 3,
2323
+ 4
2324
+ ].map((t) => n.element(e + t)), [i, a, o, s] = [
2325
+ r(0),
2326
+ r(5),
2327
+ r(10),
2328
+ r(15)
2329
+ ], c = hr(hr(t.x, i), a), l = hr(hr(t.y, i), o), u = hr(hr(t.z, i), s), d = e.inputs.fac ?? e.uniforms.fac;
2330
+ return { color: I(t, q(c, l, u), d) };
2331
+ }
2332
+ }, vr = {
2333
+ type: "luminance",
2334
+ nodeClass: "converter",
2335
+ label: "Luminance",
2336
+ inputs: [{
2337
+ key: "color",
2338
+ kind: "color"
2339
+ }],
2340
+ outputs: [{
2341
+ key: "field",
2342
+ kind: "float"
2343
+ }],
2344
+ params: [],
2345
+ build(e) {
2346
+ let t = e.inputs.color;
2347
+ return { field: t ? oe(t) : k(0) };
2348
+ }
2349
+ }, yr = {
2350
+ type: "split-channels",
2351
+ nodeClass: "converter",
2352
+ label: "Split Channels",
2353
+ inputs: [{
2354
+ key: "color",
2355
+ kind: "color"
2356
+ }],
2357
+ outputs: [
2358
+ {
2359
+ key: "r",
2360
+ kind: "float"
2361
+ },
2362
+ {
2363
+ key: "g",
2364
+ kind: "float"
2365
+ },
2366
+ {
2367
+ key: "b",
2368
+ kind: "float"
2369
+ }
2370
+ ],
2371
+ params: [],
2372
+ build(e) {
2373
+ let t = e.inputs.color;
2374
+ return t ? {
2375
+ r: t.x,
2376
+ g: t.y,
2377
+ b: t.z
2378
+ } : {
2379
+ r: k(0),
2380
+ g: k(0),
2381
+ b: k(0)
2382
+ };
2383
+ }
2384
+ }, br = {
2385
+ type: "combine-channels",
2386
+ nodeClass: "converter",
2387
+ label: "Combine Channels",
2388
+ inputs: [
2389
+ {
2390
+ key: "r",
2391
+ kind: "float"
2392
+ },
2393
+ {
2394
+ key: "g",
2395
+ kind: "float"
2396
+ },
2397
+ {
2398
+ key: "b",
2399
+ kind: "float"
2400
+ }
2401
+ ],
2402
+ outputs: [{
2403
+ key: "color",
2404
+ kind: "color"
2405
+ }],
2406
+ params: [],
2407
+ build(e) {
2408
+ return { color: q(e.inputs.r ?? k(0), e.inputs.g ?? k(0), e.inputs.b ?? k(0)) };
2409
+ }
2410
+ }, xr = {
2411
+ type: "clamp",
2412
+ nodeClass: "converter",
2413
+ label: "Clamp",
2414
+ inputs: [
2415
+ {
2416
+ key: "value",
2417
+ label: "Value",
2418
+ kind: "float"
2419
+ },
2420
+ {
2421
+ key: "min",
2422
+ label: "Min",
2423
+ kind: "float"
2424
+ },
2425
+ {
2426
+ key: "max",
2427
+ label: "Max",
2428
+ kind: "float"
2429
+ }
2430
+ ],
2431
+ outputs: [{
2432
+ key: "field",
2433
+ kind: "float"
2434
+ }],
2435
+ params: [
2436
+ {
2437
+ key: "mode",
2438
+ label: "mode",
2439
+ type: "select",
2440
+ options: ["minmax", "range"],
2441
+ default: "minmax"
2442
+ },
2443
+ {
2444
+ key: "min",
2445
+ label: "min",
2446
+ type: "float",
2447
+ min: -10,
2448
+ max: 10,
2449
+ step: .01,
2450
+ default: 0
2451
+ },
2452
+ {
2453
+ key: "max",
2454
+ label: "max",
2455
+ type: "float",
2456
+ min: -10,
2457
+ max: 10,
2458
+ step: .01,
2459
+ default: 1
2460
+ }
2461
+ ],
2462
+ build(e) {
2463
+ let t = e.inputs.value ?? k(0), n = e.inputs.min ?? e.uniforms.min, r = e.inputs.max ?? e.uniforms.max;
2464
+ return e.params.mode === "range" ? { field: t.clamp(F(n, r), P(n, r)) } : { field: b(t, n, r) };
2465
+ }
2466
+ }, Sr = {
2467
+ type: "separate-xyz",
2468
+ nodeClass: "converter",
2469
+ label: "Separate XYZ",
2470
+ inputs: [{
2471
+ key: "vector",
2472
+ kind: "vector"
2473
+ }],
2474
+ outputs: [
2475
+ {
2476
+ key: "x",
2477
+ kind: "float"
2478
+ },
2479
+ {
2480
+ key: "y",
2481
+ kind: "float"
2482
+ },
2483
+ {
2484
+ key: "z",
2485
+ kind: "float"
2486
+ }
2487
+ ],
2488
+ params: [],
2489
+ build(e) {
2490
+ let t = e.inputs.vector ?? q(0, 0, 0);
2491
+ return {
2492
+ x: t.x,
2493
+ y: t.y,
2494
+ z: t.z
2495
+ };
2496
+ }
2497
+ }, Cr = {
2498
+ type: "combine-xyz",
2499
+ nodeClass: "converter",
2500
+ label: "Combine XYZ",
2501
+ inputs: [
2502
+ {
2503
+ key: "x",
2504
+ kind: "float"
2505
+ },
2506
+ {
2507
+ key: "y",
2508
+ kind: "float"
2509
+ },
2510
+ {
2511
+ key: "z",
2512
+ kind: "float"
2513
+ }
2514
+ ],
2515
+ outputs: [{
2516
+ key: "vector",
2517
+ kind: "vector"
2518
+ }],
2519
+ params: [
2520
+ {
2521
+ key: "x",
2522
+ label: "x",
2523
+ type: "float",
2524
+ min: -10,
2525
+ max: 10,
2526
+ step: .01,
2527
+ default: 0
2528
+ },
2529
+ {
2530
+ key: "y",
2531
+ label: "y",
2532
+ type: "float",
2533
+ min: -10,
2534
+ max: 10,
2535
+ step: .01,
2536
+ default: 0
2537
+ },
2538
+ {
2539
+ key: "z",
2540
+ label: "z",
2541
+ type: "float",
2542
+ min: -10,
2543
+ max: 10,
2544
+ step: .01,
2545
+ default: 0
2546
+ }
2547
+ ],
2548
+ build(e) {
2549
+ return { vector: q(e.inputs.x ?? e.uniforms.x, e.inputs.y ?? e.uniforms.y, e.inputs.z ?? e.uniforms.z) };
2550
+ }
2551
+ }, wr = {
2552
+ type: "constant-field",
2553
+ nodeClass: "input",
2554
+ label: "Constant (Field)",
2555
+ inputs: [],
2556
+ outputs: [{
2557
+ key: "field",
2558
+ kind: "float"
2559
+ }],
2560
+ params: [{
2561
+ key: "value",
2562
+ label: "value",
2563
+ type: "float",
2564
+ min: 0,
2565
+ max: 1,
2566
+ step: .01,
2567
+ default: .5
2568
+ }],
2569
+ build(e) {
2570
+ return { field: e.uniforms.value };
2571
+ }
2572
+ }, Tr = {
2573
+ type: "constant-color",
2574
+ nodeClass: "input",
2575
+ label: "Constant (Color)",
2576
+ inputs: [],
2577
+ outputs: [{
2578
+ key: "color",
2579
+ kind: "color"
2580
+ }],
2581
+ params: [{
2582
+ key: "color",
2583
+ label: "color",
2584
+ type: "color",
2585
+ default: "#808080"
2586
+ }],
2587
+ build(e) {
2588
+ return { color: e.uniforms.color };
2589
+ }
2590
+ }, Er = {
2591
+ type: "tex-coordinate",
2592
+ nodeClass: "input",
2593
+ label: "Texture Coordinate",
2594
+ inputs: [],
2595
+ outputs: [
2596
+ {
2597
+ key: "generated",
2598
+ label: "Generated",
2599
+ kind: "vector"
2600
+ },
2601
+ {
2602
+ key: "uv",
2603
+ label: "UV",
2604
+ kind: "vector"
2605
+ },
2606
+ {
2607
+ key: "object",
2608
+ label: "Object",
2609
+ kind: "vector"
2610
+ },
2611
+ {
2612
+ key: "normal",
2613
+ label: "Normal",
2614
+ kind: "vector"
2615
+ }
2616
+ ],
2617
+ params: [],
2618
+ build(e) {
2619
+ let t = q(G().x, G().y, k(0));
2620
+ return e.backend === "offline" ? {
2621
+ generated: t,
2622
+ uv: t,
2623
+ object: t,
2624
+ normal: t
2625
+ } : {
2626
+ generated: pe,
2627
+ uv: t,
2628
+ object: pe,
2629
+ normal: ce
2630
+ };
2631
+ }
2632
+ }, Dr = [
2633
+ "add",
2634
+ "subtract",
2635
+ "multiply",
2636
+ "divide",
2637
+ "cross",
2638
+ "project",
2639
+ "reflect",
2640
+ "dot",
2641
+ "distance",
2642
+ "length",
2643
+ "scale",
2644
+ "normalize",
2645
+ "snap",
2646
+ "floor",
2647
+ "ceil",
2648
+ "fraction",
2649
+ "absolute",
2650
+ "minimum",
2651
+ "maximum",
2652
+ "sine",
2653
+ "cosine",
2654
+ "tangent"
2655
+ ], Or = new Set([
2656
+ "dot",
2657
+ "distance",
2658
+ "length"
2659
+ ]), kr = [{
2660
+ key: "vector1",
2661
+ label: "A",
2662
+ kind: "vector"
2663
+ }, {
2664
+ key: "vector2",
2665
+ label: "B",
2666
+ kind: "vector"
2667
+ }], Ar = {
2668
+ type: "vector-math",
2669
+ nodeClass: "vector",
2670
+ label: "Vector Math",
2671
+ inputs: kr,
2672
+ outputs: [{
2673
+ key: "vector",
2674
+ label: "Vector",
2675
+ kind: "vector"
2676
+ }],
2677
+ params: [{
2678
+ key: "operation",
2679
+ label: "op",
2680
+ type: "select",
2681
+ options: Dr,
2682
+ default: "add"
2683
+ }, {
2684
+ key: "scale",
2685
+ label: "scale",
2686
+ type: "float",
2687
+ min: -8,
2688
+ max: 8,
2689
+ step: .01,
2690
+ default: 1
2691
+ }],
2692
+ declare(e) {
2693
+ let t = e.operation ?? "add";
2694
+ return {
2695
+ inputs: kr,
2696
+ outputs: Or.has(t) ? [{
2697
+ key: "value",
2698
+ label: "Value",
2699
+ kind: "float"
2700
+ }] : [{
2701
+ key: "vector",
2702
+ label: "Vector",
2703
+ kind: "vector"
2704
+ }]
2705
+ };
2706
+ },
2707
+ build(e) {
2708
+ let t = e.inputs.vector1 ?? e.coord, n = e.inputs.vector2 ?? q(0, 0, 0), r = e.uniforms.scale;
2709
+ switch (e.params.operation ?? "add") {
2710
+ case "subtract": return { vector: t.sub(n) };
2711
+ case "multiply": return { vector: t.mul(n) };
2712
+ case "divide": return { vector: t.div(n) };
2713
+ case "cross": return { vector: w(t, n) };
2714
+ case "project": return { vector: n.mul(D(t, n).div(D(n, n))) };
2715
+ case "reflect": return { vector: ge(t, n.normalize()) };
2716
+ case "dot": return { value: D(t, n) };
2717
+ case "distance": return { value: t.sub(n).length() };
2718
+ case "length": return { value: t.length() };
2719
+ case "scale": return { vector: t.mul(r) };
2720
+ case "normalize": return { vector: t.normalize() };
2721
+ case "snap": return { vector: A(t.div(n)).mul(n) };
2722
+ case "floor": return { vector: A(t) };
2723
+ case "ceil": return { vector: y(t) };
2724
+ case "fraction": return { vector: j(t) };
2725
+ case "absolute": return { vector: t.abs() };
2726
+ case "minimum": return { vector: F(t, n) };
2727
+ case "maximum": return { vector: P(t, n) };
2728
+ case "sine": return { vector: B(t) };
2729
+ case "cosine": return { vector: S(t) };
2730
+ case "tangent": return { vector: we(t) };
2731
+ default: return { vector: t.add(n) };
2732
+ }
2733
+ }
2734
+ }, jr = 1, Mr = {
2735
+ type: "normal-from-height",
2736
+ nodeClass: "vector",
2737
+ label: "Normal From Height",
2738
+ bakeDerivative: !0,
2739
+ inputs: [{
2740
+ key: "height",
2741
+ kind: "float"
2742
+ }],
2743
+ outputs: [{
2744
+ key: "normal",
2745
+ kind: "vector"
2746
+ }],
2747
+ params: [{
2748
+ key: "strength",
2749
+ label: "strength",
2750
+ type: "float",
2751
+ min: 0,
2752
+ max: 2,
2753
+ step: .01,
2754
+ default: .2
2755
+ }],
2756
+ build(e) {
2757
+ let t = e.inputs.height ?? k(.5);
2758
+ if (e.backend === "live") return { normal: v(t, e.uniforms.strength) };
2759
+ let n = t, r = G(), i = T(n).div(T(r.x)), a = E(n).div(E(r.y)), o = e.uniforms.strength, s = K(i, a).mul(o), c = k(jr), l = s.mul(c.div(s.length().max(c)));
2760
+ return { normal: de(q(l.x.negate(), l.y.negate(), k(1))).mul(.5).add(.5) };
2761
+ }
2762
+ }, Nr = {
2763
+ type: "normal-map",
2764
+ nodeClass: "vector",
2765
+ label: "Normal Map",
2766
+ inputs: [{
2767
+ key: "color",
2768
+ label: "Color",
2769
+ kind: "color"
2770
+ }, {
2771
+ key: "strength",
2772
+ label: "Strength",
2773
+ kind: "float"
2774
+ }],
2775
+ outputs: [{
2776
+ key: "normal",
2777
+ kind: "vector"
2778
+ }],
2779
+ params: [{
2780
+ key: "strength",
2781
+ label: "strength",
2782
+ type: "float",
2783
+ min: 0,
2784
+ max: 4,
2785
+ step: .05,
2786
+ default: 1
2787
+ }],
2788
+ build(e) {
2789
+ return { normal: le(e.inputs.color ?? q(.5, .5, 1), e.inputs.strength ?? e.uniforms.strength) };
2790
+ }
2791
+ };
2792
+ //#endregion
2793
+ //#region src/tsl/blender-mapping.ts
2794
+ function Pr(e) {
2795
+ let t = S(e.x), n = S(e.y), r = S(e.z), i = B(e.x), a = B(e.y), o = B(e.z), s = t.mul(r), c = t.mul(o), l = i.mul(r), u = i.mul(o);
2796
+ return {
2797
+ m00: n.mul(r),
2798
+ m10: a.mul(l).sub(c),
2799
+ m20: a.mul(s).add(u),
2800
+ m01: n.mul(o),
2801
+ m11: a.mul(u).add(s),
2802
+ m21: a.mul(c).sub(l),
2803
+ m02: a.negate(),
2804
+ m12: n.mul(i),
2805
+ m22: n.mul(t)
2806
+ };
2807
+ }
2808
+ function Fr(e, t) {
2809
+ return q(e.m00.mul(t.x).add(e.m10.mul(t.y)).add(e.m20.mul(t.z)), e.m01.mul(t.x).add(e.m11.mul(t.y)).add(e.m21.mul(t.z)), e.m02.mul(t.x).add(e.m12.mul(t.y)).add(e.m22.mul(t.z)));
2810
+ }
2811
+ function Ir(e, t) {
2812
+ return q(e.m00.mul(t.x).add(e.m01.mul(t.y)).add(e.m02.mul(t.z)), e.m10.mul(t.x).add(e.m11.mul(t.y)).add(e.m12.mul(t.z)), e.m20.mul(t.x).add(e.m21.mul(t.y)).add(e.m22.mul(t.z)));
2813
+ }
2814
+ function Lr(e, t, n, r, i) {
2815
+ let a = Pr(n);
2816
+ return i === 1 ? Ir(a, e.sub(t)).div(r) : i === 2 ? Fr(a, e.mul(r)) : i === 3 ? Fr(a, e.div(r)).normalize() : Fr(a, e.mul(r)).add(t);
2817
+ }
2818
+ //#endregion
2819
+ //#region src/graph/nodes/vector/mapping.ts
2820
+ var Rr = [
2821
+ "point",
2822
+ "texture",
2823
+ "vector",
2824
+ "normal"
2825
+ ], zr = {
2826
+ type: "mapping",
2827
+ nodeClass: "vector",
2828
+ label: "Mapping",
2829
+ inputs: [{
2830
+ key: "vector",
2831
+ kind: "vector"
2832
+ }],
2833
+ outputs: [{
2834
+ key: "vector",
2835
+ kind: "vector"
2836
+ }],
2837
+ params: [
2838
+ {
2839
+ key: "mappingType",
2840
+ label: "type",
2841
+ type: "select",
2842
+ options: Rr,
2843
+ default: "point"
2844
+ },
2845
+ {
2846
+ key: "location",
2847
+ label: "location",
2848
+ type: "vec3",
2849
+ default: {
2850
+ x: 0,
2851
+ y: 0,
2852
+ z: 0
2853
+ }
2854
+ },
2855
+ {
2856
+ key: "rotation",
2857
+ label: "rotation",
2858
+ type: "vec3",
2859
+ default: {
2860
+ x: 0,
2861
+ y: 0,
2862
+ z: 0
2863
+ }
2864
+ },
2865
+ {
2866
+ key: "scale",
2867
+ label: "scale",
2868
+ type: "vec3",
2869
+ default: {
2870
+ x: 1,
2871
+ y: 1,
2872
+ z: 1
2873
+ }
2874
+ }
2875
+ ],
2876
+ build(e) {
2877
+ let t = e.inputs.vector ?? e.coord, n = Math.max(0, Rr.indexOf(e.params.mappingType));
2878
+ return { vector: Lr(t, e.uniforms.location, e.uniforms.rotation, e.uniforms.scale, n) };
2879
+ }
2880
+ }, Br = [
2881
+ {
2882
+ key: "baseColor",
2883
+ label: "base color",
2884
+ type: "color",
2885
+ default: "#cccccc"
2886
+ },
2887
+ {
2888
+ key: "metallic",
2889
+ label: "metallic",
2890
+ type: "float",
2891
+ min: 0,
2892
+ max: 1,
2893
+ step: .01,
2894
+ default: 0
2895
+ },
2896
+ {
2897
+ key: "roughness",
2898
+ label: "roughness",
2899
+ type: "float",
2900
+ min: 0,
2901
+ max: 1,
2902
+ step: .01,
2903
+ default: .5
2904
+ },
2905
+ {
2906
+ key: "ior",
2907
+ label: "IOR",
2908
+ type: "float",
2909
+ min: 1,
2910
+ max: 2.5,
2911
+ step: .01,
2912
+ default: 1.5
2913
+ },
2914
+ {
2915
+ key: "alpha",
2916
+ label: "alpha",
2917
+ type: "float",
2918
+ min: 0,
2919
+ max: 1,
2920
+ step: .01,
2921
+ default: 1,
2922
+ bakeStructural: !0
2923
+ },
2924
+ {
2925
+ key: "coat",
2926
+ label: "coat weight",
2927
+ type: "float",
2928
+ min: 0,
2929
+ max: 1,
2930
+ step: .01,
2931
+ default: 0
2932
+ },
2933
+ {
2934
+ key: "coatRoughness",
2935
+ label: "coat rough",
2936
+ type: "float",
2937
+ min: 0,
2938
+ max: 1,
2939
+ step: .01,
2940
+ default: .03
2941
+ },
2942
+ {
2943
+ key: "sheen",
2944
+ label: "sheen weight",
2945
+ type: "float",
2946
+ min: 0,
2947
+ max: 1,
2948
+ step: .01,
2949
+ default: 0
2950
+ },
2951
+ {
2952
+ key: "sheenRoughness",
2953
+ label: "sheen rough",
2954
+ type: "float",
2955
+ min: 0,
2956
+ max: 1,
2957
+ step: .01,
2958
+ default: .3
2959
+ },
2960
+ {
2961
+ key: "transmission",
2962
+ label: "transmission",
2963
+ type: "float",
2964
+ min: 0,
2965
+ max: 1,
2966
+ step: .01,
2967
+ default: 0
2968
+ },
2969
+ {
2970
+ key: "emission",
2971
+ label: "emission",
2972
+ type: "color",
2973
+ default: "#000000",
2974
+ bakeStructural: !0
2975
+ },
2976
+ {
2977
+ key: "emissionStrength",
2978
+ label: "emission str",
2979
+ type: "float",
2980
+ min: 0,
2981
+ max: 10,
2982
+ step: .1,
2983
+ default: 1
2984
+ }
2985
+ ], Vr = Object.fromEntries(Br.filter((e) => e.type === "float" || e.type === "int").map((e) => [e.key, e.default])), Hr = {
2986
+ type: "principled-bsdf",
2987
+ nodeClass: "shader",
2988
+ label: "Principled BSDF",
2989
+ inputs: [
2990
+ {
2991
+ key: "baseColor",
2992
+ label: "Base Color",
2993
+ kind: "color"
2994
+ },
2995
+ {
2996
+ key: "metallic",
2997
+ label: "Metallic",
2998
+ kind: "float"
2999
+ },
3000
+ {
3001
+ key: "roughness",
3002
+ label: "Roughness",
3003
+ kind: "float"
3004
+ },
3005
+ {
3006
+ key: "ior",
3007
+ label: "IOR",
3008
+ kind: "float"
3009
+ },
3010
+ {
3011
+ key: "alpha",
3012
+ label: "Alpha",
3013
+ kind: "float"
3014
+ },
3015
+ {
3016
+ key: "normal",
3017
+ label: "Normal",
3018
+ kind: "vector"
3019
+ },
3020
+ {
3021
+ key: "height",
3022
+ label: "Height",
3023
+ kind: "float"
3024
+ },
3025
+ {
3026
+ key: "ambientOcclusion",
3027
+ label: "Ambient Occlusion",
3028
+ kind: "float"
3029
+ },
3030
+ {
3031
+ key: "coat",
3032
+ label: "Coat Weight",
3033
+ kind: "float"
3034
+ },
3035
+ {
3036
+ key: "coatRoughness",
3037
+ label: "Coat Roughness",
3038
+ kind: "float"
3039
+ },
3040
+ {
3041
+ key: "sheen",
3042
+ label: "Sheen Weight",
3043
+ kind: "float"
3044
+ },
3045
+ {
3046
+ key: "sheenRoughness",
3047
+ label: "Sheen Roughness",
3048
+ kind: "float"
3049
+ },
3050
+ {
3051
+ key: "transmission",
3052
+ label: "Transmission",
3053
+ kind: "float"
3054
+ },
3055
+ {
3056
+ key: "emission",
3057
+ label: "Emission Color",
3058
+ kind: "color"
3059
+ },
3060
+ {
3061
+ key: "emissionStrength",
3062
+ label: "Emission Strength",
3063
+ kind: "float"
3064
+ }
3065
+ ],
3066
+ outputs: [{
3067
+ key: "bsdf",
3068
+ kind: "shader"
3069
+ }],
3070
+ params: Br,
3071
+ build(e) {
3072
+ let t = e.uniforms, n = (n) => e.inputs[n] ?? t[n], r = (t) => Number(e.params[t] ?? Vr[t] ?? 0), i = (n) => e.inputs[n] === void 0 ? r(n) > 0 ? t[n] : void 0 : e.inputs[n], a = e.inputs.emission !== void 0 || e.inputs.emissionStrength !== void 0 || (e.params.emission ?? "#000000") !== "#000000" ? (e.inputs.emission ?? t.emission).mul(e.inputs.emissionStrength ?? t.emissionStrength) : void 0, o = i("coat"), s = i("sheen");
3073
+ return { bsdf: {
3074
+ baseColor: n("baseColor"),
3075
+ metallic: n("metallic"),
3076
+ roughness: n("roughness"),
3077
+ ior: n("ior"),
3078
+ normal: e.inputs.normal,
3079
+ height: e.inputs.height,
3080
+ ambientOcclusion: e.inputs.ambientOcclusion,
3081
+ alpha: e.inputs.alpha === void 0 ? r("alpha") < 1 ? t.alpha : void 0 : e.inputs.alpha,
3082
+ emission: a,
3083
+ coat: o,
3084
+ coatRoughness: o === void 0 ? void 0 : n("coatRoughness"),
3085
+ sheen: s,
3086
+ sheenRoughness: s === void 0 ? void 0 : n("sheenRoughness"),
3087
+ transmission: i("transmission")
3088
+ } };
3089
+ }
3090
+ }, Ur = {
3091
+ type: "emission",
3092
+ nodeClass: "shader",
3093
+ label: "Emission",
3094
+ inputs: [{
3095
+ key: "color",
3096
+ label: "Color",
3097
+ kind: "color"
3098
+ }, {
3099
+ key: "strength",
3100
+ label: "Strength",
3101
+ kind: "float"
3102
+ }],
3103
+ outputs: [{
3104
+ key: "bsdf",
3105
+ kind: "shader"
3106
+ }],
3107
+ params: [{
3108
+ key: "color",
3109
+ label: "color",
3110
+ type: "color",
3111
+ default: "#ffffff"
3112
+ }, {
3113
+ key: "strength",
3114
+ label: "strength",
3115
+ type: "float",
3116
+ min: 0,
3117
+ max: 10,
3118
+ step: .1,
3119
+ default: 1
3120
+ }],
3121
+ build(e) {
3122
+ let t = e.inputs.color ?? e.uniforms.color, n = e.inputs.strength ?? e.uniforms.strength;
3123
+ return { bsdf: {
3124
+ baseColor: q(0),
3125
+ roughness: k(1),
3126
+ metallic: k(0),
3127
+ emission: t.mul(n)
3128
+ } };
3129
+ }
3130
+ }, Wr = {
3131
+ emission: q(0, 0, 0),
3132
+ ambientOcclusion: k(1),
3133
+ alpha: k(1),
3134
+ coat: k(0),
3135
+ sheen: k(0),
3136
+ transmission: k(0)
3137
+ }, Gr = [
3138
+ "baseColor",
3139
+ "metallic",
3140
+ "roughness",
3141
+ "ior",
3142
+ "alpha",
3143
+ "ambientOcclusion",
3144
+ "emission",
3145
+ "normal",
3146
+ "coat",
3147
+ "coatRoughness",
3148
+ "sheen",
3149
+ "sheenRoughness",
3150
+ "transmission"
3151
+ ];
3152
+ function Kr(e, t, n) {
3153
+ let r = {};
3154
+ for (let i of Gr) {
3155
+ let a = e[i], o = t[i];
3156
+ if (a === void 0 && o === void 0) continue;
3157
+ if (a !== void 0 && o !== void 0) {
3158
+ r[i] = I(a, o, n);
3159
+ continue;
3160
+ }
3161
+ let s = Wr[i];
3162
+ s === void 0 ? r[i] = a ?? o : r[i] = a === void 0 ? I(s, o, n) : I(a, s, n);
3163
+ }
3164
+ return r;
3165
+ }
3166
+ var qr = {
3167
+ type: "mix-shader",
3168
+ nodeClass: "shader",
3169
+ label: "Mix Shader",
3170
+ inputs: [
3171
+ {
3172
+ key: "shaderA",
3173
+ label: "Shader A",
3174
+ kind: "shader"
3175
+ },
3176
+ {
3177
+ key: "shaderB",
3178
+ label: "Shader B",
3179
+ kind: "shader"
3180
+ },
3181
+ {
3182
+ key: "fac",
3183
+ label: "Fac",
3184
+ kind: "float"
3185
+ }
3186
+ ],
3187
+ outputs: [{
3188
+ key: "shader",
3189
+ kind: "shader"
3190
+ }],
3191
+ params: [{
3192
+ key: "fac",
3193
+ label: "fac",
3194
+ type: "float",
3195
+ min: 0,
3196
+ max: 1,
3197
+ step: .01,
3198
+ default: .5
3199
+ }],
3200
+ build(e) {
3201
+ return { shader: Kr(e.inputs.shaderA ?? {}, e.inputs.shaderB ?? {}, e.inputs.fac ?? e.uniforms.fac) };
3202
+ }
3203
+ }, Jr = {
3204
+ type: "material-output",
3205
+ nodeClass: "output",
3206
+ label: "Material Output",
3207
+ inputs: [{
3208
+ key: "surface",
3209
+ label: "Surface",
3210
+ kind: "shader"
3211
+ }],
3212
+ outputs: [],
3213
+ params: [{
3214
+ key: "outputResolution",
3215
+ label: "output res",
3216
+ type: "select",
3217
+ options: [
3218
+ "128",
3219
+ "256",
3220
+ "512",
3221
+ "1024",
3222
+ "2048",
3223
+ "4096"
3224
+ ],
3225
+ default: "1024"
3226
+ }],
3227
+ build() {
3228
+ return {};
3229
+ }
3230
+ }, Yr = {
3231
+ type: "group",
3232
+ nodeClass: "group",
3233
+ label: "Group",
3234
+ inputs: [],
3235
+ outputs: [],
3236
+ params: [],
3237
+ build() {
3238
+ return {};
3239
+ }
3240
+ }, Xr = {
3241
+ type: "group-input",
3242
+ nodeClass: "input",
3243
+ label: "Group Input",
3244
+ inputs: [],
3245
+ outputs: [],
3246
+ params: [],
3247
+ build() {
3248
+ return {};
3249
+ }
3250
+ }, Zr = {
3251
+ type: "group-output",
3252
+ nodeClass: "output",
3253
+ label: "Group Output",
3254
+ inputs: [],
3255
+ outputs: [],
3256
+ params: [],
3257
+ build() {
3258
+ return {};
3259
+ }
3260
+ };
3261
+ //#endregion
3262
+ //#region src/graph/registry.ts
3263
+ function Z(e, t) {
3264
+ if (e.ports) return e.ports;
3265
+ let n = t.get(e.type);
3266
+ return n.declare ? n.declare(e.params) : {
3267
+ inputs: n.inputs,
3268
+ outputs: n.outputs
3269
+ };
3270
+ }
3271
+ function Qr(e, t) {
3272
+ let n = t.get(e.type);
3273
+ return n.paramsFor ? n.paramsFor(e.params) : n.params;
3274
+ }
3275
+ var $r = class {
3276
+ defs = /* @__PURE__ */ new Map();
3277
+ register(e) {
3278
+ if (this.defs.has(e.type)) throw Error(`Duplicate node type: ${e.type}`);
3279
+ return this.defs.set(e.type, e), this;
3280
+ }
3281
+ get(e) {
3282
+ let t = this.defs.get(e);
3283
+ if (!t) throw Error(`Unknown node type: ${e}`);
3284
+ return t;
3285
+ }
3286
+ has(e) {
3287
+ return this.defs.has(e);
3288
+ }
3289
+ all() {
3290
+ return [...this.defs.values()];
3291
+ }
3292
+ };
3293
+ function ei() {
3294
+ return new $r().register(Ye).register(Xe).register(jt).register(Vt).register(Ht).register(bn).register(xn).register(Tn).register(On).register(jn).register(Fn).register(Kn).register(Jn).register(er).register(ir).register(ar).register(or).register(sr).register(cr).register(lr).register(pr).register(_r).register(vr).register(yr).register(br).register(xr).register(Sr).register(Cr).register(wr).register(Tr).register(Er).register(Ar).register(Mr).register(Nr).register(zr).register(Hr).register(Ur).register(qr).register(Jr).register(Yr).register(Xr).register(Zr);
3295
+ }
3296
+ var ti = ei(), ni = 2048;
3297
+ function ri(e, t, n) {
3298
+ let r = new Map(t.nodes.map((e) => [e.id, e])), i = /* @__PURE__ */ new Set(), a = [e];
3299
+ for (; a.length;) {
3300
+ let e = a.pop();
3301
+ if (i.has(e)) continue;
3302
+ i.add(e);
3303
+ let o = r.get(e);
3304
+ if (o) {
3305
+ if (n.get(o.type).bakeDerivative) return !0;
3306
+ for (let n of t.edges) n.toNode === e && a.push(n.fromNode);
3307
+ }
3308
+ }
3309
+ return !1;
3310
+ }
3311
+ function ii(e, t) {
3312
+ let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = (e) => {
3313
+ let t = a.get(e);
3314
+ return t || (t = new Map(e.nodes.map((e) => [e.id, e])), a.set(e, t)), t;
3315
+ }, s = (e) => e.nodes.find((e) => e.type === Pe)?.id, c = (e, t, r, i) => {
3316
+ if (t === s(e)) {
3317
+ i(r);
3318
+ return;
3319
+ }
3320
+ let a = o(e).get(t);
3321
+ if (a) {
3322
+ if (a.type === "group" && a.subgraph) {
3323
+ n.add(`${a.id}/${r}`), u(a, r, e, i);
3324
+ return;
3325
+ }
3326
+ l(e, t, i);
3327
+ }
3328
+ }, l = (e, t, n) => {
3329
+ if (!r.has(t)) {
3330
+ r.add(t);
3331
+ for (let r of e.edges) r.toNode === t && c(e, r.fromNode, r.fromOutput, n);
3332
+ }
3333
+ }, u = (e, t, n, r) => {
3334
+ let a = `${e.id}/${t}`;
3335
+ if (i.has(a)) return;
3336
+ i.add(a);
3337
+ let o = e.subgraph;
3338
+ if (!o) return;
3339
+ let s = o.nodes.find((e) => e.type === Fe), l = s && o.edges.find((e) => e.toNode === s.id && e.toInput === t);
3340
+ l && c(o, l.fromNode, l.fromOutput, (t) => {
3341
+ for (let i of n.edges) i.toNode === e.id && i.toInput === t && c(n, i.fromNode, i.fromOutput, r);
3342
+ });
3343
+ }, d = (e, n) => {
3344
+ for (let r of e.nodes) t.get(r.type).bakeDerivative && l(e, r.id, n), r.type === "group" && r.subgraph && d(r.subgraph, (t) => {
3345
+ for (let i of e.edges) i.toNode === r.id && i.toInput === t && c(e, i.fromNode, i.fromOutput, n);
3346
+ });
3347
+ };
3348
+ return d(e, () => {}), n;
3349
+ }
3350
+ function ai(e, t) {
3351
+ return t === "float" ? q(e) : e;
3352
+ }
3353
+ function oi(e, t) {
3354
+ let n = H(e, G());
3355
+ return t === "float" ? n.r : n.xyz;
3356
+ }
3357
+ function si(e) {
3358
+ let t = e.nodes.find((e) => e.type === Ie)?.params?.outputResolution, n = typeof t == "string" ? Number(t) : typeof t == "number" ? t : NaN;
3359
+ return Number.isFinite(n) && n > 0 ? n : 1024;
3360
+ }
3361
+ function ci(e, t, n) {
3362
+ if (n.backend === "live" || !n.allocCache || !t.bakeTileable) return 1;
3363
+ let r = e.params.tileSize, i = typeof r == "string" && r !== "off" ? Number(r) : NaN;
3364
+ if (!Number.isFinite(i) || i <= 0) return 1;
3365
+ let a = n.outputResolution ?? 1024, o = Math.max(1, Math.round(Number(e.params.scale) || 1));
3366
+ return Math.max(1, Math.min(Math.round(a / i), o));
3367
+ }
3368
+ function li(e, t, n, r, i, a) {
3369
+ if (r.backend === "live" || !r.allocCache || !t.bakeTileable || n.vector !== void 0 || n.field === void 0) return;
3370
+ let o = e.params.tileSize, s = typeof o == "string" && o !== "off" ? Number(o) : NaN;
3371
+ if (!Number.isFinite(s) || s <= 0) return;
3372
+ let c = `${e.id}/field`, l = r.allocCache(c, "float", { size: s });
3373
+ return i.push({
3374
+ cacheId: c,
3375
+ kind: "float",
3376
+ colorNode: ai(n.field, "float"),
3377
+ sizing: { size: s }
3378
+ }), { field: H(l, G().mul(k(a))).r };
3379
+ }
3380
+ function ui(e) {
3381
+ let t = 0;
3382
+ for (let n of e.nodes) t += 1, n.type === "group" && n.subgraph && (t += ui(n.subgraph));
3383
+ return t;
3384
+ }
3385
+ function di(e, t, n) {
3386
+ let r = {
3387
+ ...n,
3388
+ outputResolution: n.outputResolution ?? si(e)
3389
+ }, i = r.backend === "live" ? me : q(G().x, G().y, k(0)), a = r.soloNodeId ? { id: r.soloNodeId } : void 0, o = [], { outputs: s, uniforms: c } = pi(e, t, r, i, o, r.allocCache ? ii(e, t) : /* @__PURE__ */ new Set(), void 0, a);
3390
+ return {
3391
+ bundle: a && a.value !== void 0 && a.kind && a.kind !== "shader" ? fi(a.value, a.kind) : Si(e, t, s),
3392
+ uniforms: c,
3393
+ cachePlan: o
3394
+ };
3395
+ }
3396
+ function fi(e, t) {
3397
+ return {
3398
+ baseColor: t === "float" ? q(e) : e,
3399
+ roughness: k(1),
3400
+ metallic: k(0)
3401
+ };
3402
+ }
3403
+ function pi(e, t, n, r, i, a, o, s) {
3404
+ wi(e, t, o !== void 0);
3405
+ let c = Ci(e), l = new Map(e.nodes.map((e) => [e.id, e])), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
3406
+ for (let f of c) {
3407
+ let c = l.get(f);
3408
+ if (!c) continue;
3409
+ let p = Z(c, t);
3410
+ if (c.type === "group-input") {
3411
+ let e = {};
3412
+ for (let t of p.outputs) e[t.key] = o?.[t.key];
3413
+ u.set(f, e);
3414
+ continue;
3415
+ }
3416
+ if (c.type === "group") {
3417
+ let o = mi(c, t, n, r, i, a, vi(c, e, u, l, t), s);
3418
+ u.set(f, o.outputs);
3419
+ for (let [e, t] of o.uniforms) d.set(e, t);
3420
+ continue;
3421
+ }
3422
+ let m = vi(c, e, u, l, t), h = t.get(c.type), g = xi(h, c);
3423
+ d.set(f, g);
3424
+ let _ = ci(c, h, n), v = {
3425
+ inputs: m,
3426
+ uniforms: g,
3427
+ params: c.params,
3428
+ coord: r,
3429
+ backend: n.backend,
3430
+ tileRepeat: _
3431
+ }, y = h.build(v);
3432
+ u.set(f, li(c, h, y, n, i, _) ?? y);
3433
+ }
3434
+ if (s && s.value === void 0) {
3435
+ let e = l.get(s.id), n = e ? Z(e, t).outputs[0] : void 0;
3436
+ e && n && (s.value = u.get(s.id)?.[n.key], s.kind = n.kind);
3437
+ }
3438
+ return {
3439
+ outputs: u,
3440
+ uniforms: d
3441
+ };
3442
+ }
3443
+ function mi(e, t, n, r, i, a, o, s) {
3444
+ let c = e.subgraph;
3445
+ if (!c) return {
3446
+ outputs: {},
3447
+ uniforms: /* @__PURE__ */ new Map()
3448
+ };
3449
+ let { outputs: l, uniforms: u } = pi(c, t, n, r, i, a, o, s), d = c.nodes.find((e) => e.type === Fe), f = {};
3450
+ if (!d) return {
3451
+ outputs: f,
3452
+ uniforms: u
3453
+ };
3454
+ let p = new Map(c.nodes.map((e) => [e.id, e]));
3455
+ for (let r of Z(d, t).inputs) {
3456
+ let o = c.edges.find((e) => e.toNode === d.id && e.toInput === r.key), u = o ? yi(o, r.kind, l, p, t) : void 0;
3457
+ if (n.allocCache && u !== void 0 && r.kind !== "shader" && !s) {
3458
+ let s = `${e.id}/${r.key}`, l = o && ri(o.fromNode, c, t) || a.has(s) ? { minSize: ni } : void 0, d = n.allocCache(s, r.kind, l);
3459
+ i.push({
3460
+ cacheId: s,
3461
+ kind: r.kind,
3462
+ colorNode: ai(u, r.kind),
3463
+ sizing: l
3464
+ }), f[r.key] = oi(d, r.kind);
3465
+ } else f[r.key] = u;
3466
+ }
3467
+ return {
3468
+ outputs: f,
3469
+ uniforms: u
3470
+ };
3471
+ }
3472
+ function hi() {
3473
+ return new c({
3474
+ metalness: 0,
3475
+ roughness: .9,
3476
+ side: e.DoubleSide,
3477
+ polygonOffset: !0,
3478
+ polygonOffsetFactor: 1,
3479
+ polygonOffsetUnits: 1
3480
+ });
3481
+ }
3482
+ function gi(e, t) {
3483
+ let n = g("vertexAo", "float");
3484
+ e.aoNode = t.ambientOcclusion ? t.ambientOcclusion.mul(n) : n, t.baseColor && (e.colorNode = t.baseColor), t.emission && (e.emissiveNode = t.emission), t.roughness && (e.roughnessNode = t.roughness), t.metallic && (e.metalnessNode = t.metallic), t.normal && (e.normalNode = t.normal), t.ior && (e.iorNode = t.ior), t.alpha && (e.opacityNode = t.alpha, e.transparent = !0), t.coat && (e.clearcoatNode = t.coat), t.coatRoughness && (e.clearcoatRoughnessNode = t.coatRoughness), t.sheen && (e.sheenNode = t.sheen), t.sheenRoughness && (e.sheenRoughnessNode = t.sheenRoughness), t.transmission && (e.transmissionNode = t.transmission);
3485
+ }
3486
+ function _i(e, t, n) {
3487
+ let { bundle: r, uniforms: i } = di(e, t, n), a = hi();
3488
+ return gi(a, r), {
3489
+ material: a,
3490
+ uniforms: i
3491
+ };
3492
+ }
3493
+ function vi(e, t, n, r, i) {
3494
+ let a = {};
3495
+ for (let o of Z(e, i).inputs) {
3496
+ let s = t.edges.find((t) => t.toNode === e.id && t.toInput === o.key);
3497
+ a[o.key] = s ? yi(s, o.kind, n, r, i) : void 0;
3498
+ }
3499
+ return a;
3500
+ }
3501
+ function yi(e, t, n, r, i) {
3502
+ let a = n.get(e.fromNode)?.[e.fromOutput];
3503
+ if (a === void 0) return;
3504
+ let o = r.get(e.fromNode), s = o ? Z(o, i).outputs.find((t) => t.key === e.fromOutput)?.kind : void 0;
3505
+ if (s && s !== t) {
3506
+ let e = ze(s, t);
3507
+ e && (a = bi(a, e));
3508
+ }
3509
+ return a;
3510
+ }
3511
+ function bi(e, t) {
3512
+ switch (t) {
3513
+ case "float-to-vector":
3514
+ case "float-to-color": return q(e);
3515
+ case "vector-to-float": return e.x.add(e.y).add(e.z).div(3);
3516
+ case "color-to-float": return oe(e);
3517
+ case "identity":
3518
+ case "vector-to-color":
3519
+ case "color-to-vector": return e;
3520
+ }
3521
+ }
3522
+ function xi(t, n) {
3523
+ let r = {};
3524
+ for (let i of t.params) {
3525
+ let t = n.params[i.key] ?? i.default;
3526
+ if (i.type === "color") r[i.key] = W(new e.Color(t));
3527
+ else if (i.type === "vec3") {
3528
+ let n = t ?? {
3529
+ x: 0,
3530
+ y: 0,
3531
+ z: 0
3532
+ };
3533
+ r[i.key] = W(new e.Vector3(n.x, n.y, n.z));
3534
+ } else if (i.type === "float" || i.type === "int") {
3535
+ let e = Number(t);
3536
+ r[i.key] = W(Number.isFinite(e) ? e : Number(i.default) || 0);
3537
+ } else i.type === "curve" && (r[i.key] = De(Me(t), "float"));
3538
+ }
3539
+ return r;
3540
+ }
3541
+ function Si(e, t, n) {
3542
+ let r = e.nodes.find((e) => e.type === Ie);
3543
+ if (!r) return {};
3544
+ let i = e.edges.find((e) => e.toNode === r.id && e.toInput === "surface");
3545
+ return i ? yi(i, "shader", n, new Map(e.nodes.map((e) => [e.id, e])), t) ?? {} : {};
3546
+ }
3547
+ function Ci(e) {
3548
+ let t = /* @__PURE__ */ new Map();
3549
+ for (let n of e.nodes) t.set(n.id, 0);
3550
+ let n = /* @__PURE__ */ new Map();
3551
+ for (let r of e.edges) !t.has(r.fromNode) || !t.has(r.toNode) || (n.set(r.fromNode, [...n.get(r.fromNode) ?? [], r.toNode]), t.set(r.toNode, (t.get(r.toNode) ?? 0) + 1));
3552
+ let r = e.nodes.filter((e) => (t.get(e.id) ?? 0) === 0).map((e) => e.id), i = [];
3553
+ for (; r.length > 0;) {
3554
+ let e = r.shift();
3555
+ i.push(e);
3556
+ for (let i of n.get(e) ?? []) {
3557
+ let e = (t.get(i) ?? 0) - 1;
3558
+ t.set(i, e), e === 0 && r.push(i);
3559
+ }
3560
+ }
3561
+ if (i.length !== e.nodes.length) throw Error("Material graph has a cycle");
3562
+ return i;
3563
+ }
3564
+ function wi(e, t, n = !1) {
3565
+ let r = n ? Fe : Ie, i = e.nodes.filter((e) => e.type === r);
3566
+ if (i.length !== 1) throw Error(`Expected exactly one ${r} node, found ${i.length}`);
3567
+ let a = new Map(e.nodes.map((e) => [e.id, e])), o = /* @__PURE__ */ new Set();
3568
+ for (let n of e.edges) {
3569
+ let e = a.get(n.fromNode), r = a.get(n.toNode);
3570
+ if (!e) throw Error(`Edge from unknown node '${n.fromNode}'`);
3571
+ if (!r) throw Error(`Edge to unknown node '${n.toNode}'`);
3572
+ let i = Z(e, t).outputs.find((e) => e.key === n.fromOutput), s = Z(r, t).inputs.find((e) => e.key === n.toInput);
3573
+ if (!i) throw Error(`Node '${e.type}' has no output '${n.fromOutput}'`);
3574
+ if (!s) throw Error(`Node '${r.type}' has no input '${n.toInput}'`);
3575
+ if (i.kind !== s.kind && !ze(i.kind, s.kind)) throw Error(`Type mismatch (no coercion): ${e.type}.${n.fromOutput} (${i.kind}) -> ${r.type}.${n.toInput} (${s.kind})`);
3576
+ let c = `${n.toNode}/${n.toInput}`;
3577
+ if (o.has(c)) throw Error(`Multiple connections into ${r.type}.${n.toInput}`);
3578
+ o.add(c);
3579
+ }
3580
+ }
3581
+ //#endregion
3582
+ //#region src/document.ts
3583
+ var Ti = 2;
3584
+ function Ei(e) {
3585
+ return structuredClone(e);
3586
+ }
3587
+ function Di() {
3588
+ return Ei(ke);
3589
+ }
3590
+ function Oi(e) {
3591
+ return {
3592
+ ...Ei(e),
3593
+ version: e.version ?? 2
3594
+ };
3595
+ }
3596
+ function ki(e, t) {
3597
+ return e.nodes.find((e) => e.id === t);
3598
+ }
3599
+ function Ai(e, t) {
3600
+ return e.find((e) => e.key === t);
3601
+ }
3602
+ function ji(e) {
3603
+ return e.type === "float" || e.type === "color" || e.type === "vec3" || e.type === "curve" ? "param" : "structural";
3604
+ }
3605
+ var Mi = class {
3606
+ registry;
3607
+ doc;
3608
+ listeners = /* @__PURE__ */ new Set();
3609
+ lastError_ = null;
3610
+ soloNode_ = null;
3611
+ constructor(e = Di(), t = ti) {
3612
+ this.registry = t, this.doc = Oi(e), this.validate(this.doc);
3613
+ }
3614
+ get document() {
3615
+ return this.doc;
3616
+ }
3617
+ get lastError() {
3618
+ return this.lastError_;
3619
+ }
3620
+ get soloNode() {
3621
+ return this.soloNode_;
3622
+ }
3623
+ getRegistry() {
3624
+ return this.registry;
3625
+ }
3626
+ compileBundle(e) {
3627
+ try {
3628
+ let t = di(this.doc, this.registry, e);
3629
+ return this.lastError_ = null, t;
3630
+ } catch (e) {
3631
+ throw this.lastError_ = e instanceof Error ? e.message : String(e), e;
3632
+ }
3633
+ }
3634
+ onChange(e) {
3635
+ return this.listeners.add(e), () => this.listeners.delete(e);
3636
+ }
3637
+ setDocument(e) {
3638
+ let t = Oi(e);
3639
+ this.validate(t), this.doc = t, this.emit({ kind: "structural" });
3640
+ }
3641
+ getDocument() {
3642
+ return Ei(this.doc);
3643
+ }
3644
+ setSoloNode(e) {
3645
+ e !== this.soloNode_ && (this.soloNode_ = e, this.emit({ kind: "structural" }));
3646
+ }
3647
+ setOutputResolution(e) {
3648
+ let t = this.doc.nodes.find((e) => e.type === Ie);
3649
+ if (!t) return;
3650
+ let n = String(e);
3651
+ t.params.outputResolution !== n && (t.params.outputResolution = n, this.emit({ kind: "structural" }));
3652
+ }
3653
+ setOutputTargets(e) {
3654
+ this.setOutputResolution(e.resolution ?? e.size ?? 1024);
3655
+ }
3656
+ setNodeParam(e, t, n) {
3657
+ let r = ki(this.doc, e);
3658
+ if (!r) return !1;
3659
+ let i = this.registry.get(r.type), a = Ai(Qr(r, this.registry), t) ?? Ai(i.params, t);
3660
+ return a ? Object.is(r.params[t], n) ? !0 : (r.params[t] = n, ji(a) === "param" ? this.emit({
3661
+ kind: "param",
3662
+ nodeId: e,
3663
+ key: t,
3664
+ paramType: a.type,
3665
+ value: n,
3666
+ bakeStructural: a.bakeStructural
3667
+ }) : this.emit({ kind: "structural" }), !0) : !1;
3668
+ }
3669
+ updateNodeParams(e, t) {
3670
+ let n = !1;
3671
+ for (let [r, i] of Object.entries(t)) n = this.setNodeParam(e, r, i) || n;
3672
+ return n;
3673
+ }
3674
+ validate(e) {
3675
+ di(e, this.registry, { backend: "live" }), this.lastError_ = null;
3676
+ }
3677
+ emit(e) {
3678
+ for (let t of this.listeners) t(e);
3679
+ }
3680
+ }, Ni = [
3681
+ "roughness",
3682
+ "metallic",
3683
+ "ambientOcclusion"
3684
+ ], Pi = ["baseColor", "emission"];
3685
+ function Fi(e, t) {
3686
+ return Ni.includes(t) ? q(e) : Pi.includes(t) ? ve(e) : e;
3687
+ }
3688
+ var Q = 2, Ii = new l(new s()), Li = new s(), $ = new u(Q, Q);
3689
+ $.texture.colorSpace = n, $.texture.minFilter = $.texture.magFilter = t, $.texture.wrapS = $.texture.wrapT = i;
3690
+ var Ri = W(K(1 / Q, 1 / Q));
3691
+ function zi(e) {
3692
+ let t = (Q - 1) / 2, n = q(0, 0, 0);
3693
+ for (let r = 0; r < Q; r++) for (let i = 0; i < Q; i++) {
3694
+ let a = K(i - t, r - t).mul(Ri), o = H($.texture, G().add(a)).xyz;
3695
+ e && (o = o.mul(2).sub(1)), n = n.add(o);
3696
+ }
3697
+ return n = n.div(Q * Q), e ? de(n).mul(.5).add(.5) : n;
3698
+ }
3699
+ var Bi = new s();
3700
+ Bi.colorNode = zi(!1);
3701
+ var Vi = new s();
3702
+ Vi.colorNode = zi(!0);
3703
+ var Hi = new l(Bi), Ui = new l(Vi);
3704
+ function Wi() {
3705
+ return new s();
3706
+ }
3707
+ var Gi = new a(), Ki = new r(-1, 1, 1, -1, 0, 1), qi = [];
3708
+ async function Ji(e, t) {
3709
+ for (; qi.length < t.length;) qi.push(new l());
3710
+ Gi.clear();
3711
+ for (let e = 0; e < t.length; e++) qi[e].material = t[e], Gi.add(qi[e]);
3712
+ let n = e.getRenderTarget();
3713
+ e.setRenderTarget($), await e.compileAsync(Gi, Ki), e.setRenderTarget(n);
3714
+ }
3715
+ function Yi(e, t, n) {
3716
+ Ii.material = t;
3717
+ let r = e.getRenderTarget();
3718
+ e.setRenderTarget(n), Ii.render(e), e.setRenderTarget(r);
3719
+ }
3720
+ function Xi(e, t, n, r = !1) {
3721
+ let i = n.width, a = n.height;
3722
+ ($.width !== i * Q || $.height !== a * Q) && $.setSize(i * Q, a * Q), Ri.value.set(1 / (i * Q), 1 / (a * Q)), Ii.material = t;
3723
+ let o = e.getRenderTarget();
3724
+ e.setRenderTarget($), Ii.render(e), e.setRenderTarget(n), (r ? Ui : Hi).render(e), e.setRenderTarget(o);
3725
+ }
3726
+ function Zi(e, t, n, r = !1) {
3727
+ Li.colorNode = t, Li.needsUpdate = !0, Xi(e, Li, n, r);
3728
+ }
3729
+ //#endregion
3730
+ //#region src/graph/bake-service.ts
3731
+ var Qi = 1024, $i = 8, ea = 4096;
3732
+ function ta(e, t) {
3733
+ let n = t?.size ?? Math.max(e, t?.minSize ?? 0);
3734
+ return Math.min(n, ea);
3735
+ }
3736
+ function na(e) {
3737
+ return e?.minSize != null;
3738
+ }
3739
+ var ra = typeof navigator < "u" && /chrome|chromium|crios|edg\//i.test(navigator.userAgent) && !/firefox|fxios/i.test(navigator.userAgent), ia = [
3740
+ "baseColor",
3741
+ "roughness",
3742
+ "metallic",
3743
+ "ambientOcclusion",
3744
+ "normal",
3745
+ "emission"
3746
+ ];
3747
+ function aa(t, n) {
3748
+ let r = new u(n, n), i = r.texture;
3749
+ return i.colorSpace = t !== "height" && Pi.includes(t) ? e.SRGBColorSpace : e.NoColorSpace, i.wrapS = i.wrapT = e.RepeatWrapping, i.generateMipmaps = !0, i.minFilter = e.LinearMipmapLinearFilter, i.magFilter = e.LinearFilter, i.anisotropy = $i, r;
3750
+ }
3751
+ function oa(t, n = !1) {
3752
+ let r = new u(t, t, { type: e.HalfFloatType }), i = r.texture;
3753
+ return i.colorSpace = e.NoColorSpace, i.wrapS = i.wrapT = e.RepeatWrapping, i.generateMipmaps = n, i.minFilter = n ? e.LinearMipmapLinearFilter : e.LinearFilter, i.magFilter = e.LinearFilter, r;
3754
+ }
3755
+ var sa = class {
3756
+ channels;
3757
+ targets = /* @__PURE__ */ new Map();
3758
+ mats = /* @__PURE__ */ new Map();
3759
+ cacheTargets = /* @__PURE__ */ new Map();
3760
+ cacheMats = /* @__PURE__ */ new Map();
3761
+ cachePlan = [];
3762
+ uniforms = /* @__PURE__ */ new Map();
3763
+ heightTarget = null;
3764
+ hasHeight = !1;
3765
+ present = /* @__PURE__ */ new Set();
3766
+ signature = "";
3767
+ size;
3768
+ constructor(e, t) {
3769
+ this.channels = t, this.size = e;
3770
+ }
3771
+ resize(e) {
3772
+ if (e !== this.size) {
3773
+ this.size = e;
3774
+ for (let t of this.targets.values()) t.setSize(e, e);
3775
+ this.heightTarget?.setSize(e, e), this.flushCaches();
3776
+ }
3777
+ }
3778
+ target(e) {
3779
+ let t = this.targets.get(e);
3780
+ return t || (t = aa(e, this.size), this.targets.set(e, t)), t;
3781
+ }
3782
+ channelMaterial(e) {
3783
+ let t = this.mats.get(e);
3784
+ return t || (t = Wi(), this.mats.set(e, t)), t;
3785
+ }
3786
+ cacheTarget(e, t = this.size, n = !1) {
3787
+ let r = this.cacheTargets.get(e);
3788
+ return r && r.texture.generateMipmaps !== n && (r.dispose(), this.cacheTargets.delete(e), r = void 0), r ? (r.width !== t || r.height !== t) && r.setSize(t, t) : (r = oa(t, n), this.cacheTargets.set(e, r)), r;
3789
+ }
3790
+ cacheMaterial(e) {
3791
+ let t = this.cacheMats.get(e);
3792
+ return t || (t = Wi(), this.cacheMats.set(e, t)), t;
3793
+ }
3794
+ cacheTexture(e, t, n = !1) {
3795
+ return this.cacheTarget(e, t, n).texture;
3796
+ }
3797
+ firstTarget() {
3798
+ for (let e of this.targets.values()) return e;
3799
+ return this.heightTarget;
3800
+ }
3801
+ ensureHeightTarget() {
3802
+ return this.heightTarget ||= aa("height", this.size), this.heightTarget;
3803
+ }
3804
+ texture(e) {
3805
+ return this.targets.get(e)?.texture ?? null;
3806
+ }
3807
+ flushCaches() {
3808
+ for (let e of this.mats.values()) e.dispose();
3809
+ this.mats.clear();
3810
+ for (let e of this.cacheTargets.values()) e.dispose();
3811
+ this.cacheTargets.clear();
3812
+ for (let e of this.cacheMats.values()) e.dispose();
3813
+ this.cacheMats.clear(), this.cachePlan = [], this.uniforms = /* @__PURE__ */ new Map();
3814
+ }
3815
+ dispose() {
3816
+ for (let e of this.targets.values()) e.dispose();
3817
+ this.targets.clear();
3818
+ for (let e of this.mats.values()) e.dispose();
3819
+ this.mats.clear();
3820
+ for (let e of this.cacheTargets.values()) e.dispose();
3821
+ this.cacheTargets.clear();
3822
+ for (let e of this.cacheMats.values()) e.dispose();
3823
+ this.cacheMats.clear(), this.cachePlan = [], this.heightTarget?.dispose(), this.heightTarget = null;
3824
+ }
3825
+ }, ca = class {
3826
+ renderer = null;
3827
+ compileGateDepth = 0;
3828
+ get rendererBusy() {
3829
+ return this.compileGateDepth > 0;
3830
+ }
3831
+ queue = Promise.resolve();
3832
+ completed = 0;
3833
+ total = 0;
3834
+ active = null;
3835
+ progressListeners = /* @__PURE__ */ new Set();
3836
+ reportListeners = /* @__PURE__ */ new Set();
3837
+ bakeRunId = 0;
3838
+ scratch = null;
3839
+ scratchSize = 0;
3840
+ scratchCaches = /* @__PURE__ */ new Map();
3841
+ scratchCacheSize = 0;
3842
+ attachRenderer(e) {
3843
+ this.renderer = e;
3844
+ }
3845
+ get hasRenderer() {
3846
+ return this.renderer !== null;
3847
+ }
3848
+ onProgress(e) {
3849
+ return this.progressListeners.add(e), () => this.progressListeners.delete(e);
3850
+ }
3851
+ emitProgress() {
3852
+ let e = {
3853
+ completed: this.completed,
3854
+ total: this.total,
3855
+ active: this.active
3856
+ };
3857
+ for (let t of this.progressListeners) t(e);
3858
+ }
3859
+ onBakeReport(e) {
3860
+ return this.reportListeners.add(e), () => this.reportListeners.delete(e);
3861
+ }
3862
+ emitReport(e) {
3863
+ for (let t of this.reportListeners) t(e);
3864
+ }
3865
+ enqueue(e, t) {
3866
+ this.total += 1, this.emitProgress();
3867
+ let n = this.queue.then(async () => {
3868
+ this.active = e, this.emitProgress();
3869
+ try {
3870
+ return await t();
3871
+ } finally {
3872
+ this.completed += 1, this.active = null, console.log(`[bake] ${this.completed}/${this.total} ${e}`), this.completed >= this.total && (this.completed = 0, this.total = 0), this.emitProgress();
3873
+ }
3874
+ });
3875
+ return this.queue = n.then(() => void 0, () => void 0), n;
3876
+ }
3877
+ createTextureSet(e = ia, t = Qi) {
3878
+ return new sa(t, e);
3879
+ }
3880
+ bakeInto(e, t, n = {}) {
3881
+ return this.enqueue(n.label ?? "surface", async () => {
3882
+ let r = this.renderer;
3883
+ if (!r) return !1;
3884
+ let i = performance.now(), { bundle: a, uniforms: o, cachePlan: s } = t.compileBundle({
3885
+ backend: "offline",
3886
+ soloNodeId: n.soloNodeId,
3887
+ allocCache: (t, n, r) => e.cacheTexture(t, ta(e.size, r), na(r))
3888
+ }), c = performance.now() - i, l = ui(t.document);
3889
+ e.uniforms = o, e.cachePlan = s;
3890
+ let u = n.channels ?? e.channels, d = /* @__PURE__ */ new Set(), f = [];
3891
+ for (let t of u) {
3892
+ let n = a[t];
3893
+ if (!n) continue;
3894
+ let r = e.channelMaterial(t);
3895
+ r.colorNode = Fi(n, t), r.needsUpdate = !0, f.push({
3896
+ mat: r,
3897
+ target: e.target(t),
3898
+ isNormal: t === "normal"
3899
+ }), d.add(t);
3900
+ }
3901
+ if (e.hasHeight = a.height !== void 0, e.hasHeight) {
3902
+ let t = e.channelMaterial("height");
3903
+ t.colorNode = q(a.height), t.needsUpdate = !0, f.push({
3904
+ mat: t,
3905
+ target: e.ensureHeightTarget(),
3906
+ isNormal: !1
3907
+ });
3908
+ }
3909
+ let p = {
3910
+ runId: ++this.bakeRunId,
3911
+ source: n.source,
3912
+ phase: "nodes",
3913
+ nodeCount: l,
3914
+ compileMs: c,
3915
+ texturesTotal: f.length,
3916
+ totalMs: 0
3917
+ };
3918
+ this.emitReport(p);
3919
+ for (let t of s) {
3920
+ let n = e.cacheMaterial(t.cacheId);
3921
+ n.colorNode = t.colorNode, n.needsUpdate = !0, Yi(r, n, e.cacheTarget(t.cacheId, ta(e.size, t.sizing), na(t.sizing)));
3922
+ }
3923
+ let m = 0;
3924
+ if (ra) {
3925
+ this.emitReport({
3926
+ ...p,
3927
+ phase: "shaders"
3928
+ });
3929
+ let e = performance.now();
3930
+ this.compileGateDepth += 1;
3931
+ try {
3932
+ await Ji(r, f.map((e) => e.mat));
3933
+ } finally {
3934
+ --this.compileGateDepth;
3935
+ }
3936
+ m = performance.now() - e;
3937
+ }
3938
+ let h = performance.now();
3939
+ for (let e of f) Xi(r, e.mat, e.target, e.isNormal);
3940
+ let g = performance.now() - h, _ = [...d].sort().join(",") + (e.hasHeight ? "|h" : ""), v = _ !== e.signature;
3941
+ e.present = d, e.signature = _;
3942
+ let y = performance.now();
3943
+ await this.gpuSync(e);
3944
+ let b = performance.now() - y, x = c + m + g + b;
3945
+ return this.emitReport({
3946
+ ...p,
3947
+ phase: "done",
3948
+ totalMs: x
3949
+ }), console.log(`[bake-prof] rebuild compile=${c.toFixed(1)} precompile=${m.toFixed(1)} dispatch=${g.toFixed(1)} gpuWait=${b.toFixed(1)} total=${x.toFixed(1)}ms`), v;
3950
+ });
3951
+ }
3952
+ async gpuSync(e) {
3953
+ let t = this.renderer;
3954
+ if (!t) return;
3955
+ let n = t.backend?.device?.queue;
3956
+ if (n?.onSubmittedWorkDone) {
3957
+ await n.onSubmittedWorkDone();
3958
+ return;
3959
+ }
3960
+ let r = e.firstTarget();
3961
+ r && await t.readRenderTargetPixelsAsync(r, 0, 0, 1, 1);
3962
+ }
3963
+ rerenderInto(e, t) {
3964
+ let n = this.queue.then(async () => {
3965
+ let n = this.renderer;
3966
+ if (!n) return;
3967
+ let r = e.present.size + (e.hasHeight && e.heightTarget ? 1 : 0), i = {
3968
+ runId: ++this.bakeRunId,
3969
+ source: t,
3970
+ phase: "render",
3971
+ nodeCount: 0,
3972
+ compileMs: 0,
3973
+ texturesTotal: r,
3974
+ totalMs: 0
3975
+ };
3976
+ this.emitReport(i);
3977
+ let a = performance.now();
3978
+ for (let t of e.cachePlan) Yi(n, e.cacheMaterial(t.cacheId), e.cacheTarget(t.cacheId, ta(e.size, t.sizing), na(t.sizing)));
3979
+ for (let t of e.present) Xi(n, e.channelMaterial(t), e.target(t), t === "normal");
3980
+ e.hasHeight && e.heightTarget && Xi(n, e.channelMaterial("height"), e.heightTarget, !1);
3981
+ let o = performance.now() - a, s = performance.now();
3982
+ await this.gpuSync(e);
3983
+ let c = performance.now() - s;
3984
+ this.emitReport({
3985
+ ...i,
3986
+ phase: "done",
3987
+ totalMs: o + c
3988
+ }), console.log(`[bake-prof] rerender dispatch=${o.toFixed(1)} gpuWait=${c.toFixed(1)}ms`);
3989
+ });
3990
+ return this.queue = n.then(() => void 0, () => void 0), n;
3991
+ }
3992
+ async bake(e, t = {}) {
3993
+ let n = this.createTextureSet(t.channels, t.size);
3994
+ return await this.bakeInto(n, e, t), n;
3995
+ }
3996
+ readImage(e, t, n = 512) {
3997
+ return this.enqueue(`read:${t}`, async () => {
3998
+ let r = this.renderer;
3999
+ if (!r) return null;
4000
+ let { bundle: i, cachePlan: a } = e.compileBundle({
4001
+ backend: "offline",
4002
+ allocCache: (e, t, r) => this.scratchCache(e, n, ta(n, r), na(r)).rt.texture
4003
+ }), o = i[t];
4004
+ if (!o) return null;
4005
+ for (let e of a) {
4006
+ let t = this.scratchCache(e.cacheId, n, ta(n, e.sizing), na(e.sizing));
4007
+ t.mat.colorNode = e.colorNode, t.mat.needsUpdate = !0, Yi(r, t.mat, t.rt);
4008
+ }
4009
+ let s = this.scratchTarget(n);
4010
+ Zi(r, Fi(o, t), s, t === "normal");
4011
+ let c = await r.readRenderTargetPixelsAsync(s, 0, 0, n, n), l = new Uint8ClampedArray(n * n * 4), u = n * 4;
4012
+ for (let e = 0; e < n; e++) {
4013
+ let t = (n - 1 - e) * u;
4014
+ l.set(c.subarray(t, t + u), e * u);
4015
+ }
4016
+ return new ImageData(l, n, n);
4017
+ });
4018
+ }
4019
+ scratchTarget(e) {
4020
+ return (!this.scratch || this.scratchSize !== e) && (this.scratch?.dispose(), this.scratch = new u(e, e), this.scratchSize = e), this.scratch;
4021
+ }
4022
+ scratchCache(e, t, n, r = !1) {
4023
+ if (this.scratchCacheSize !== t) {
4024
+ for (let e of this.scratchCaches.values()) e.rt.dispose(), e.mat.dispose();
4025
+ this.scratchCaches.clear(), this.scratchCacheSize = t;
4026
+ }
4027
+ let i = this.scratchCaches.get(e);
4028
+ return i && i.rt.texture.generateMipmaps !== r && (i.rt.dispose(), i.mat.dispose(), this.scratchCaches.delete(e), i = void 0), i ? (i.rt.width !== n || i.rt.height !== n) && i.rt.setSize(n, n) : (i = {
4029
+ rt: oa(n, r),
4030
+ mat: Wi()
4031
+ }, this.scratchCaches.set(e, i)), i;
4032
+ }
4033
+ }, la = new ca();
4034
+ //#endregion
4035
+ //#region src/tsl/triplanar.ts
4036
+ function ua(e) {
4037
+ let t = R(ue.abs(), e);
4038
+ return t.div(t.dot(q(1, 1, 1)).max(1e-4));
4039
+ }
4040
+ function da(e, t, n) {
4041
+ return d(() => {
4042
+ let r = me.mul(t), i = ua(n), a = H(e, r.yz).mul(i.x), o = H(e, r.zx).mul(i.y), s = H(e, r.xy).mul(i.z);
4043
+ return a.add(o).add(s);
4044
+ })();
4045
+ }
4046
+ //#endregion
4047
+ //#region src/tsl/triplanar-normal.ts
4048
+ function fa(e, t, n) {
4049
+ return d(() => {
4050
+ let r = me.mul(t), i = ua(n), a = ue.sign(), o = H(e, r.yz).xyz.mul(2).sub(1), s = H(e, r.zx).xyz.mul(2).sub(1), c = H(e, r.xy).xyz.mul(2).sub(1), l = q(o.x, o.y, o.z.mul(a.x)), u = q(s.x, s.y, s.z.mul(a.y)), d = q(c.x, c.y, c.z.mul(a.z));
4051
+ return l.zxy.mul(i.x).add(u.yzx.mul(i.y)).add(d.xyz.mul(i.z)).normalize();
4052
+ })();
4053
+ }
4054
+ //#endregion
4055
+ //#region src/tsl/parallax.ts
4056
+ var pa = .3;
4057
+ function ma(e, t, n, r) {
4058
+ return d(() => {
4059
+ let i = fe.normalize(), a = (t) => H(e, t).x, o = 1 / r, s = i.xy.div(i.z.abs().max(pa)).mul(n).mul(o), c = t.toVar(), l = _(!1).toVar(), u = t, d = k(1).sub(a(u));
4060
+ for (let e = 0; e < r; e++) {
4061
+ let t = u.sub(s), n = k(1).sub(a(t)), r = (e + 1) * o, i = k(r).greaterThanEqual(n), f = n.sub(r), p = d.sub(e * o), m = ye(f.div(f.sub(p).max(1e-5))), h = I(t, u, m);
4062
+ c.assign(z(l.not().and(i), h, c)), l.assign(l.or(i)), u = t, d = n;
4063
+ }
4064
+ return c;
4065
+ })();
4066
+ }
4067
+ //#endregion
4068
+ //#region src/graph/textured-surface.ts
4069
+ var ha = 12, ga = class {
4070
+ graph;
4071
+ service;
4072
+ source;
4073
+ offlineMat = hi();
4074
+ liveUniforms = /* @__PURE__ */ new Map();
4075
+ material_;
4076
+ scaleUniform = W(1.2);
4077
+ sharpnessUniform = W(8);
4078
+ roughnessFactor = W(1);
4079
+ metalnessFactor = W(1);
4080
+ colorTint = W(new e.Color(1, 1, 1));
4081
+ parallaxScale = W(0);
4082
+ lastBakeMs = 0;
4083
+ set;
4084
+ backend = "offline";
4085
+ debugNormals = !1;
4086
+ triplanar = !1;
4087
+ wiredOnce = !1;
4088
+ lastPresent = /* @__PURE__ */ new Set();
4089
+ updateInFlight = !1;
4090
+ pendingKind = "none";
4091
+ flushRequested = !1;
4092
+ listeners = /* @__PURE__ */ new Set();
4093
+ lastError_ = null;
4094
+ constructor(e, t, n) {
4095
+ this.graph = e, this.service = t, this.source = n, this.set = t.createTextureSet(ia, this.surfaceBakeSize()), this.material_ = this.buildLive(), this.graph.onChange((e) => this.onGraphChange(e));
4096
+ }
4097
+ get material() {
4098
+ return this.material_;
4099
+ }
4100
+ get lastError() {
4101
+ return this.lastError_;
4102
+ }
4103
+ getLastBakeMs() {
4104
+ return this.backend === "offline" ? this.lastBakeMs : 0;
4105
+ }
4106
+ onRebuilt(e) {
4107
+ return this.listeners.add(e), () => this.listeners.delete(e);
4108
+ }
4109
+ notify() {
4110
+ for (let e of this.listeners) e();
4111
+ }
4112
+ refresh() {
4113
+ return this.rebuild();
4114
+ }
4115
+ regenerate() {
4116
+ this.flushRequested = !0, this.requestUpdate("rebuild");
4117
+ }
4118
+ setScale(e) {
4119
+ this.scaleUniform.value = e;
4120
+ }
4121
+ setSharpness(e) {
4122
+ this.sharpnessUniform.value = e;
4123
+ }
4124
+ setRoughnessFactor(e) {
4125
+ this.roughnessFactor.value = e;
4126
+ }
4127
+ setMetalnessFactor(e) {
4128
+ this.metalnessFactor.value = e;
4129
+ }
4130
+ setColorTint(e) {
4131
+ this.colorTint.value.set(e);
4132
+ }
4133
+ setParallaxScale(e) {
4134
+ let t = this.parallaxScale.value > 0;
4135
+ this.parallaxScale.value = e, e > 0 !== t && this.wire(this.lastPresent);
4136
+ }
4137
+ setTriplanar(e) {
4138
+ e !== this.triplanar && (this.triplanar = e, this.wire(this.lastPresent));
4139
+ }
4140
+ setNormalDebug(e) {
4141
+ e !== this.debugNormals && (this.debugNormals = e, this.wire(this.lastPresent));
4142
+ }
4143
+ setBackend(e) {
4144
+ e !== this.backend && (this.backend = e, this.rebuild());
4145
+ }
4146
+ getBackend() {
4147
+ return this.backend;
4148
+ }
4149
+ onGraphChange(e) {
4150
+ if (e.kind !== "layout") {
4151
+ if (e.kind === "param") {
4152
+ if (this.backend === "live") {
4153
+ if (this.updateLiveUniform(e)) return;
4154
+ this.requestUpdate("rebuild");
4155
+ return;
4156
+ }
4157
+ if (this.updateOfflineUniform(e)) {
4158
+ this.requestUpdate("rerender");
4159
+ return;
4160
+ }
4161
+ this.requestUpdate("rebuild");
4162
+ return;
4163
+ }
4164
+ this.requestUpdate("rebuild");
4165
+ }
4166
+ }
4167
+ applyUniformValue(t, n) {
4168
+ if (n.paramType === "color") t.value = new e.Color(n.value);
4169
+ else if (n.paramType === "vec3") {
4170
+ let e = n.value;
4171
+ t.value.set(e.x, e.y, e.z);
4172
+ } else if (n.paramType === "curve") {
4173
+ let e = Me(n.value), r = t.array;
4174
+ for (let t = 0; t < e.length; t++) r[t] = e[t];
4175
+ } else t.value = Number(n.value);
4176
+ }
4177
+ updateLiveUniform(e) {
4178
+ let t = this.liveUniforms.get(e.nodeId)?.[e.key];
4179
+ return t ? (this.applyUniformValue(t, e), !0) : !1;
4180
+ }
4181
+ updateOfflineUniform(e) {
4182
+ if (e.bakeStructural) return !1;
4183
+ let t = this.set.uniforms.get(e.nodeId)?.[e.key];
4184
+ return t ? (this.applyUniformValue(t, e), !0) : !1;
4185
+ }
4186
+ requestUpdate(e) {
4187
+ (e === "rebuild" || this.pendingKind === "none") && (this.pendingKind = e), this.pump();
4188
+ }
4189
+ async pump() {
4190
+ if (!this.updateInFlight) {
4191
+ this.updateInFlight = !0;
4192
+ try {
4193
+ for (; this.pendingKind !== "none";) {
4194
+ let e = this.pendingKind;
4195
+ this.pendingKind = "none", e === "rebuild" ? await this.rebuild() : await this.rerenderOffline();
4196
+ }
4197
+ } finally {
4198
+ this.updateInFlight = !1;
4199
+ }
4200
+ }
4201
+ }
4202
+ async rerenderOffline() {
4203
+ if (!(this.backend !== "offline" || !this.service.hasRenderer)) try {
4204
+ await this.service.rerenderInto(this.set, this.source), this.lastError_ = this.graph.lastError;
4205
+ } catch (e) {
4206
+ this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] re-render failed:", this.lastError_);
4207
+ }
4208
+ }
4209
+ surfaceBakeSize() {
4210
+ return Math.max(64, Math.round(si(this.graph.document) / 64) * 64);
4211
+ }
4212
+ async rebuild() {
4213
+ try {
4214
+ if (this.backend === "offline" && this.service.hasRenderer) {
4215
+ let e = this.surfaceBakeSize();
4216
+ this.flushRequested && (this.flushRequested = !1, this.set.flushCaches()), this.set.resize(e);
4217
+ let t = this.graph.soloNode ?? void 0, n = performance.now(), r = await this.service.bakeInto(this.set, this.graph, {
4218
+ soloNodeId: t,
4219
+ label: "surface",
4220
+ source: this.source
4221
+ });
4222
+ this.lastBakeMs = performance.now() - n, (r || !this.wiredOnce) && (this.wire(this.set.present), this.wiredOnce = !0), this.material_ = this.offlineMat;
4223
+ } else this.material_ = this.buildLive();
4224
+ this.lastError_ = this.graph.lastError;
4225
+ } catch (e) {
4226
+ this.lastError_ = e instanceof Error ? e.message : String(e), console.warn("[textured-surface] rebuild failed:", this.lastError_);
4227
+ }
4228
+ this.notify();
4229
+ }
4230
+ buildLive() {
4231
+ let e = this.graph.soloNode ?? void 0, { material: t, uniforms: n } = _i(this.graph.document, this.graph.getRegistry(), {
4232
+ backend: "live",
4233
+ soloNodeId: e
4234
+ });
4235
+ return this.liveUniforms = n, t;
4236
+ }
4237
+ wire(e) {
4238
+ this.lastPresent = e;
4239
+ let t = this.offlineMat, n = this.scaleUniform, r = this.sharpnessUniform, i = this.set.hasHeight && !this.triplanar && this.parallaxScale.value > 0, a = G(), o = i ? ma(this.set.heightTarget.texture, a, this.parallaxScale, ha) : void 0, s = a.dFdx(), c = a.dFdy(), l = (e) => i ? H(e, o).grad(s, c) : H(e), u = (e) => this.triplanar ? da(this.set.texture(e), n, r) : l(this.set.texture(e)), d = e.has("normal") ? this.triplanar ? fa(this.set.texture("normal"), n, r) : le(l(this.set.texture("normal")).xyz, k(1)) : ue;
4240
+ if (this.debugNormals) {
4241
+ t.colorNode = q(0, 0, 0), t.emissiveNode = d.normalize().mul(.5).add(.5), t.roughnessNode = t.metalnessNode = t.aoNode = t.normalNode = null, t.needsUpdate = !0;
4242
+ return;
4243
+ }
4244
+ t.colorNode = e.has("baseColor") ? u("baseColor").mul(this.colorTint) : null, t.roughnessNode = e.has("roughness") ? u("roughness").r.mul(this.roughnessFactor) : null, t.metalnessNode = e.has("metallic") ? u("metallic").r.mul(this.metalnessFactor) : null;
4245
+ let f = g("vertexAo", "float");
4246
+ t.aoNode = e.has("ambientOcclusion") ? u("ambientOcclusion").r.mul(f) : f, t.normalNode = e.has("normal") ? d : null, t.emissiveNode = e.has("emission") ? u("emission") : null, t.needsUpdate = !0;
4247
+ }
4248
+ dispose() {
4249
+ this.set.dispose(), this.offlineMat.dispose();
4250
+ }
4251
+ }, _a = class {
4252
+ graph;
4253
+ surface;
4254
+ service;
4255
+ constructor(e = {}) {
4256
+ this.service = e.bakeService ?? la, this.graph = new Mi(e.document, e.registry ?? ti), this.surface = new ga(this.graph, this.service, e.source);
4257
+ }
4258
+ get material() {
4259
+ return this.surface.material;
4260
+ }
4261
+ get lastError() {
4262
+ return this.surface.lastError ?? this.graph.lastError;
4263
+ }
4264
+ setRenderer(e) {
4265
+ return this.service.attachRenderer(e), this;
4266
+ }
4267
+ setBackend(e) {
4268
+ return this.surface.setBackend(e), this;
4269
+ }
4270
+ getBackend() {
4271
+ return this.surface.getBackend();
4272
+ }
4273
+ fromDocument(e) {
4274
+ return this.setDocument(e);
4275
+ }
4276
+ setDocument(e) {
4277
+ return this.graph.setDocument(e), this;
4278
+ }
4279
+ getDocument() {
4280
+ return this.graph.getDocument();
4281
+ }
4282
+ setOutputResolution(e) {
4283
+ return this.graph.setOutputResolution(e), this;
4284
+ }
4285
+ setOutputTargets(e) {
4286
+ return this.graph.setOutputTargets(e), this;
4287
+ }
4288
+ setNodeParam(e, t, n) {
4289
+ return this.graph.setNodeParam(e, t, n), this;
4290
+ }
4291
+ updateNodeParams(e, t) {
4292
+ return this.graph.updateNodeParams(e, t), this;
4293
+ }
4294
+ refresh() {
4295
+ return this.surface.refresh();
4296
+ }
4297
+ regenerate() {
4298
+ return this.surface.regenerate(), this;
4299
+ }
4300
+ dispose() {
4301
+ this.surface.dispose();
4302
+ }
4303
+ };
4304
+ //#endregion
4305
+ //#region src/topology.ts
4306
+ function va(e) {
4307
+ return Array.isArray(e) ? `[${e.map(va).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}:${va(t)}`).join(",")}}` : JSON.stringify(e);
4308
+ }
4309
+ function ya(e, t) {
4310
+ let n = t.get(e.type), r = n.paramsFor ? n.paramsFor(e.params) : n.params, i = {};
4311
+ for (let t of r) (t.type === "int" || t.type === "bool" || t.type === "select" || t.bakeStructural) && (i[t.key] = e.params[t.key]);
4312
+ return i;
4313
+ }
4314
+ function ba(e, t) {
4315
+ return {
4316
+ id: e.id,
4317
+ type: e.type,
4318
+ enabled: e.enabled,
4319
+ ports: Z(e, t),
4320
+ params: ya(e, t),
4321
+ subgraph: e.subgraph ? xa(e.subgraph, t) : null
4322
+ };
4323
+ }
4324
+ function xa(e, t) {
4325
+ return {
4326
+ version: e.version,
4327
+ nodes: e.nodes.map((e) => ba(e, t)).sort((e, t) => String(e.id).localeCompare(String(t.id))),
4328
+ edges: [...e.edges].sort((e, t) => va(e).localeCompare(va(t)))
4329
+ };
4330
+ }
4331
+ function Sa(e, t) {
4332
+ return va(xa(e, t));
4333
+ }
4334
+ //#endregion
4335
+ //#region src/graph/tiling-test.ts
4336
+ function Ca(e) {
4337
+ return {
4338
+ version: 2,
4339
+ nodes: [
4340
+ {
4341
+ id: "n",
4342
+ type: "tileable-noise",
4343
+ params: {
4344
+ noiseType: e,
4345
+ scale: 5,
4346
+ octaves: 4,
4347
+ gain: .5
4348
+ },
4349
+ position: {
4350
+ x: 0,
4351
+ y: 0
4352
+ },
4353
+ enabled: !0
4354
+ },
4355
+ {
4356
+ id: "pr",
4357
+ type: "principled-bsdf",
4358
+ params: {},
4359
+ position: {
4360
+ x: 300,
4361
+ y: 0
4362
+ },
4363
+ enabled: !0
4364
+ },
4365
+ {
4366
+ id: "out",
4367
+ type: "material-output",
4368
+ params: {},
4369
+ position: {
4370
+ x: 600,
4371
+ y: 0
4372
+ },
4373
+ enabled: !0
4374
+ }
4375
+ ],
4376
+ edges: [{
4377
+ fromNode: "n",
4378
+ fromOutput: "field",
4379
+ toNode: "pr",
4380
+ toInput: "baseColor"
4381
+ }, {
4382
+ fromNode: "pr",
4383
+ fromOutput: "bsdf",
4384
+ toNode: "out",
4385
+ toInput: "surface"
4386
+ }]
4387
+ };
4388
+ }
4389
+ function wa(e, t) {
4390
+ let n = (n, r) => e.data[(r * t + n) * 4], r = 0, i = 0;
4391
+ for (let e = 0; e < t; e++) {
4392
+ r += Math.abs(n(t - 1, e) - n(0, e));
4393
+ for (let r = 1; r < t; r++) i += Math.abs(n(r, e) - n(r - 1, e));
4394
+ }
4395
+ let a = 0, o = 0;
4396
+ for (let e = 0; e < t; e++) {
4397
+ a += Math.abs(n(e, t - 1) - n(e, 0));
4398
+ for (let r = 1; r < t; r++) o += Math.abs(n(e, r) - n(e, r - 1));
4399
+ }
4400
+ return r /= t, a /= t, i /= t * (t - 1), o /= t * (t - 1), {
4401
+ wrapH: r,
4402
+ wrapV: a,
4403
+ interiorH: i,
4404
+ interiorV: o,
4405
+ ratioH: r / Math.max(i, .001),
4406
+ ratioV: a / Math.max(o, .001)
4407
+ };
4408
+ }
4409
+ async function Ta(e, t, n = {}) {
4410
+ let r = n.size ?? 256, i = n.threshold ?? 3, a = n.channel ?? "baseColor", o = t.get("tileable-noise").params.find((e) => e.key === "noiseType"), s = n.types ?? o?.options ?? [], c = [];
4411
+ for (let o of s) {
4412
+ let s = new Mi(Ca(o), t), l = await e.readImage(s, a, r);
4413
+ if (!l) {
4414
+ c.push({
4415
+ type: o,
4416
+ ratioH: NaN,
4417
+ ratioV: NaN,
4418
+ wrapH: NaN,
4419
+ wrapV: NaN,
4420
+ interiorH: NaN,
4421
+ interiorV: NaN,
4422
+ pass: !1
4423
+ });
4424
+ continue;
4425
+ }
4426
+ n.onTile && await n.onTile(o, l);
4427
+ let u = wa(l, r);
4428
+ c.push({
4429
+ type: o,
4430
+ ...u,
4431
+ pass: u.ratioH <= i && u.ratioV <= i
4432
+ });
4433
+ }
4434
+ return c;
4435
+ }
4436
+ //#endregion
4437
+ export { sa as BakedTextureSet, Re as COERCION_MATRIX, je as CURVE_CHANNELS, Ae as CURVE_IDENTITY, Pe as GROUP_INPUT_TYPE, Fe as GROUP_OUTPUT_TYPE, Ne as GROUP_TYPE, Ti as MATERIAL_DOCUMENT_VERSION, Ie as MATERIAL_OUTPUT_TYPE, ca as MaterialBakeService, _a as MaterialGraphRuntime, Mi as MaterialGraphSession, $r as NodeRegistry, Le as PBR_SOCKETS, ia as SURFACE_CHANNELS, ga as TexturedSurface, la as bakeService, Ei as cloneMaterialDocument, ze as coercionFor, _i as compileGraph, di as compileSockets, ui as countGraphNodes, Di as createDefaultMaterialDocument, ei as createDefaultRegistry, Sa as createMaterialTopologyKey, Me as curveToArray, ti as defaultRegistry, Oi as migrateMaterialDocument, hi as newSurfaceMaterial, Qr as nodeParamDefs, Z as nodePorts, si as readOutputResolution, Ta as runTilingTest };