@margoengine/shader 0.1.0 → 1.0.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 (49) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +1920 -1771
  4. package/dist/attribute.d.ts +28 -0
  5. package/dist/black-hole.js +3 -3
  6. package/dist/clock-BLGNexlt.js +3 -3
  7. package/dist/{compute-D-BghbXj.js → compute-CXGG9qvI.js} +76 -70
  8. package/dist/compute-texture.js +3 -3
  9. package/dist/compute-volume.js +3 -3
  10. package/dist/compute.d.ts +8 -2
  11. package/dist/{control-DvjfV7R0.js → control-CFjkGPBk.js} +1 -1
  12. package/dist/deform.js +2 -2
  13. package/dist/editor-pass.js +17 -17
  14. package/dist/effects.js +2 -2
  15. package/dist/glsl-material.js +2 -2
  16. package/dist/glsl-pass.js +5 -5
  17. package/dist/glsl.js +18 -18
  18. package/dist/gpu-DQJk2xAv.js +55 -0
  19. package/dist/graph.js +2 -2
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +103 -8
  22. package/dist/{lighting-Dx8_RsBz.js → lighting-JU9yQPfM.js} +2 -2
  23. package/dist/lighting.js +1 -1
  24. package/dist/{material-CU7p-Q8u.js → material-C6bpqlnE.js} +1 -1
  25. package/dist/{material-REzUrXtu.js → material-CZ8V1FeA.js} +95 -71
  26. package/dist/material.d.ts +9 -4
  27. package/dist/{node-DzKv9CF2.js → node-B6yoIC9V.js} +126 -126
  28. package/dist/node.d.ts +7 -1
  29. package/dist/noise.js +1 -1
  30. package/dist/pass.d.ts +1 -0
  31. package/dist/pass.js +24 -21
  32. package/dist/{post-DC62ZleD.js → post-DLpZ110L.js} +17 -17
  33. package/dist/{raw-D0W8U3Qa.js → raw-0AYej3Ak.js} +422 -273
  34. package/dist/raw.d.ts +125 -15
  35. package/dist/raw.js +1 -1
  36. package/dist/readback.js +13 -12
  37. package/dist/serialization.js +12 -12
  38. package/dist/shadertoy.js +6 -6
  39. package/dist/shared/caster.d.ts +159 -152
  40. package/dist/shared/fog.d.ts +33 -33
  41. package/dist/shared/fractal.d.ts +9 -9
  42. package/dist/shared/msaa.d.ts +30 -25
  43. package/dist/shared/stack.d.ts +22 -22
  44. package/dist/subgroups.js +4 -4
  45. package/dist/{texture-D6vy0bam.js → texture-BawKO_h9.js} +1 -1
  46. package/dist/texture-array.js +2 -2
  47. package/dist/utils.js +32 -32
  48. package/package.json +151 -151
  49. package/dist/gpu-DQ5Jmggz.js +0 -31
@@ -16,23 +16,23 @@ var n = Object.defineProperty, r = (e, t) => {
16
16
  i.list = t, i.store = n, i.flush = r;
17
17
  }
18
18
  }, o = /* @__PURE__ */ r({
19
- Builder: () => $,
19
+ Builder: () => Wt,
20
20
  FIXED: () => 8,
21
- Fn: () => Ft,
21
+ Fn: () => Pt,
22
22
  LEAF: () => 1,
23
23
  MUTABLE: () => 32,
24
24
  Node: () => u,
25
25
  ONCE: () => 16,
26
26
  OP: () => 2,
27
- Program: () => Vt,
27
+ Program: () => Bt,
28
28
  STMT: () => 4,
29
- UniformNode: () => Lt,
30
- abs: () => w,
31
- acos: () => F,
32
- add: () => ue,
33
- asin: () => P,
34
- atan: () => I,
35
- atan2: () => he,
29
+ UniformNode: () => It,
30
+ abs: () => ge,
31
+ acos: () => k,
32
+ add: () => de,
33
+ asin: () => O,
34
+ atan: () => A,
35
+ atan2: () => xe,
36
36
  bitangentWorld: () => ft,
37
37
  bool: () => Be,
38
38
  builtin: () => Q,
@@ -41,94 +41,94 @@ var n = Object.defineProperty, r = (e, t) => {
41
41
  cameraNear: () => mt,
42
42
  cameraPosition: () => Tt,
43
43
  cast: () => _,
44
- ceil: () => D,
45
- clamp: () => Ce,
44
+ ceil: () => ye,
45
+ clamp: () => q,
46
46
  color: () => Qe,
47
47
  constant: () => g,
48
- cos: () => M,
49
- cross: () => Oe,
50
- degrees: () => K,
51
- deltaTime: () => At,
48
+ cos: () => E,
49
+ cross: () => De,
50
+ degrees: () => V,
51
+ deltaTime: () => kt,
52
52
  discard: () => Ie,
53
- distance: () => Ae,
54
- div: () => pe,
55
- dot: () => je,
56
- dpdx: () => _e,
57
- dpdy: () => ve,
58
- exp: () => R,
59
- exp2: () => z,
53
+ distance: () => ke,
54
+ div: () => me,
55
+ dot: () => Ae,
56
+ dpdx: () => H,
57
+ dpdy: () => Se,
58
+ exp: () => M,
59
+ exp2: () => N,
60
60
  float: () => Le,
61
- floor: () => E,
62
- fract: () => A,
63
- fwidth: () => ye,
61
+ floor: () => ve,
62
+ fract: () => w,
63
+ fwidth: () => U,
64
64
  hdrTarget: () => Ct,
65
65
  instanceColor: () => xt,
66
66
  instanceMatrix: () => bt,
67
67
  instanceUV: () => St,
68
68
  int: () => Re,
69
- inverseSqrt: () => H,
69
+ inverseSqrt: () => L,
70
70
  isMatrix: () => p,
71
71
  ivec2: () => We,
72
72
  ivec3: () => Ge,
73
73
  ivec4: () => Ke,
74
- length: () => ke,
74
+ length: () => Oe,
75
75
  linearColor: () => X,
76
76
  linearDepth: () => pt,
77
- log: () => B,
78
- log2: () => V,
79
- loop: () => Pt,
77
+ log: () => P,
78
+ log2: () => F,
79
+ loop: () => Nt,
80
80
  mat3: () => Xe,
81
81
  mat4: () => Ze,
82
- max: () => xe,
83
- min: () => be,
84
- mix: () => Ee,
85
- mod: () => me,
82
+ max: () => G,
83
+ min: () => W,
84
+ mix: () => Te,
85
+ mod: () => he,
86
86
  modelMatrix: () => gt,
87
- mul: () => fe,
87
+ mul: () => pe,
88
88
  negate: () => Ne,
89
89
  normalLocal: () => ot,
90
90
  normalView: () => lt,
91
91
  normalWorld: () => st,
92
- normalize: () => W,
92
+ normalize: () => z,
93
93
  not: () => Pe,
94
- oneMinus: () => q,
94
+ oneMinus: () => Me,
95
95
  positionLocal: () => it,
96
96
  positionView: () => ct,
97
97
  positionWorld: () => at,
98
- pow: () => Se,
98
+ pow: () => K,
99
99
  projectionMatrix: () => vt,
100
- radians: () => G,
101
- reflect: () => De,
102
- refract: () => Me,
103
- resolution: () => jt,
104
- round: () => O,
105
- sameEntries: () => Ht,
106
- saturate: () => U,
100
+ radians: () => B,
101
+ reflect: () => Ee,
102
+ refract: () => je,
103
+ resolution: () => At,
104
+ round: () => be,
105
+ sameEntries: () => Vt,
106
+ saturate: () => R,
107
107
  scalarOf: () => d,
108
108
  screenCoordinate: () => Et,
109
109
  screenUV: () => Dt,
110
110
  select: () => Fe,
111
- sign: () => T,
112
- sin: () => j,
111
+ sign: () => _e,
112
+ sin: () => T,
113
113
  sizeOf: () => f,
114
- smoothstep: () => Te,
115
- sqrt: () => ge,
116
- step: () => we,
117
- sub: () => de,
118
- tan: () => N,
114
+ smoothstep: () => we,
115
+ sqrt: () => I,
116
+ step: () => Ce,
117
+ sub: () => fe,
118
+ tan: () => D,
119
119
  tangentLocal: () => ut,
120
120
  tangentWorld: () => dt,
121
- tanh: () => L,
122
- time: () => kt,
123
- trunc: () => k,
121
+ tanh: () => j,
122
+ time: () => Ot,
123
+ trunc: () => C,
124
124
  uint: () => ze,
125
- uniform: () => Rt,
125
+ uniform: () => Lt,
126
126
  unique: () => l,
127
127
  uv: () => nt,
128
128
  uvec2: () => qe,
129
129
  uvec3: () => Je,
130
130
  uvec4: () => Ye,
131
- varying: () => Mt,
131
+ varying: () => jt,
132
132
  vec2: () => Ve,
133
133
  vec3: () => He,
134
134
  vec4: () => Ue,
@@ -137,7 +137,7 @@ var n = Object.defineProperty, r = (e, t) => {
137
137
  vertexIndex: () => yt,
138
138
  viewDirection: () => wt,
139
139
  viewMatrix: () => _t,
140
- wgslFn: () => It
140
+ wgslFn: () => Ft
141
141
  }), s = 1, c = 2, ee = 4, te = 8, ne = 16, re = 32, ie = 0, l = () => ie++, u = class {
142
142
  constructor(e, t, n, r, i = 0) {
143
143
  this.type = e, this.key = t, this.args = n, this.emit = r, this.flags = i;
@@ -176,21 +176,21 @@ function b(e, t, n, r = e) {
176
176
  var x = (e, t = e) => (...n) => {
177
177
  let r = y(e, n);
178
178
  return b(e, r, r[0].type, t);
179
- }, S = (e) => (...t) => {
179
+ }, le = (e) => (...t) => {
180
180
  let n = y(e, t);
181
181
  return b(e, n, d(n[0].type), e);
182
- }, le = (e, t) => new u(t.type, "u" + e, [t], (t, n) => e + t.wrap(n.args[0]), 2);
183
- function C(e, t, n, r) {
182
+ }, ue = (e, t) => new u(t.type, "u" + e, [t], (t, n) => e + t.wrap(n.args[0]), 2);
183
+ function S(e, t, n, r) {
184
184
  let i = v(t), a = v(n);
185
185
  t instanceof u || (i = _(t, d(a.type))), n instanceof u || (a = _(n, d(i.type)));
186
186
  let o, s = d(i.type);
187
187
  return r || e === "&&" || e === "||" ? ([i, a] = y(e, [i, a]), o = m("bool", f(i.type)), !r && s !== "bool" && h(`${e} needs bool operands`)) : i.type === a.type ? o = i.type : s === d(a.type) && (f(i.type) === 1 && !p(i.type) || f(a.type) === 1 && !p(a.type)) ? o = f(i.type) === 1 && !p(i.type) ? a.type : i.type : e === "*" && p(i.type) && a.type === `vec${i.type[3]}f` ? o = a.type : e === "*" && p(a.type) && i.type === `vec${a.type[3]}f` && (o = i.type), !o || s === "bool" && !r && e !== "&&" && e !== "||" ? h(`${i.type} ${e} ${a.type}: operand types do not combine`) : new u(o, "o" + e, [i, a], (t, n) => `${t.wrap(n.args[0])} ${e} ${t.wrap(n.args[1])}`, 2);
188
188
  }
189
- var ue = (e, t) => C("+", e, t, !1), de = (e, t) => C("-", e, t, !1), fe = (e, t) => C("*", e, t, !1), pe = (e, t) => C("/", e, t, !1), me = (e, t) => C("%", e, t, !1), w = x("abs"), T = x("sign"), E = x("floor"), D = x("ceil"), O = x("round"), k = x("trunc"), A = x("fract"), j = x("sin"), M = x("cos"), N = x("tan"), P = x("asin"), F = x("acos"), I = x("atan"), L = x("tanh"), he = x("atan2"), R = x("exp"), z = x("exp2"), B = x("log"), V = x("log2"), ge = x("sqrt"), H = x("inverseSqrt"), U = x("saturate"), W = x("normalize"), G = x("radians"), K = x("degrees"), _e = x("dpdx"), ve = x("dpdy"), ye = x("fwidth"), be = x("min"), xe = x("max"), Se = x("pow"), Ce = x("clamp"), we = x("step"), Te = x("smoothstep"), Ee = x("mix"), De = x("reflect"), Oe = x("cross"), ke = S("length"), Ae = S("distance"), je = S("dot"), Me = (e, t, n) => b("refract", [
189
+ var de = (e, t) => S("+", e, t, !1), fe = (e, t) => S("-", e, t, !1), pe = (e, t) => S("*", e, t, !1), me = (e, t) => S("/", e, t, !1), he = (e, t) => S("%", e, t, !1), ge = x("abs"), _e = x("sign"), ve = x("floor"), ye = x("ceil"), be = x("round"), C = x("trunc"), w = x("fract"), T = x("sin"), E = x("cos"), D = x("tan"), O = x("asin"), k = x("acos"), A = x("atan"), j = x("tanh"), xe = x("atan2"), M = x("exp"), N = x("exp2"), P = x("log"), F = x("log2"), I = x("sqrt"), L = x("inverseSqrt"), R = x("saturate"), z = x("normalize"), B = x("radians"), V = x("degrees"), H = x("dpdx"), Se = x("dpdy"), U = x("fwidth"), W = x("min"), G = x("max"), K = x("pow"), q = x("clamp"), Ce = x("step"), we = x("smoothstep"), Te = x("mix"), Ee = x("reflect"), De = x("cross"), Oe = le("length"), ke = le("distance"), Ae = le("dot"), je = (e, t, n) => b("refract", [
190
190
  _(e, "vec3f"),
191
191
  _(t, "vec3f"),
192
192
  _(n, "f32")
193
- ], "vec3f"), q = (e) => C("-", 1, e, !1), Ne = (e) => le("-", e), Pe = (e) => d(e.type) === "bool" ? le("!", e) : h("not() needs bool");
193
+ ], "vec3f"), Me = (e) => S("-", 1, e, !1), Ne = (e) => ue("-", e), Pe = (e) => d(e.type) === "bool" ? ue("!", e) : h("not() needs bool");
194
194
  function Fe(e, t, n) {
195
195
  let [r, i] = y("select", [t, n]);
196
196
  return b("select", [
@@ -247,7 +247,7 @@ for (let [e, t] of [
247
247
  ["and", "&&"],
248
248
  ["or", "||"]
249
249
  ]) Z[e] = function(e) {
250
- return C(t, this, e, !1);
250
+ return S(t, this, e, !1);
251
251
  };
252
252
  for (let [e, t] of [
253
253
  ["lessThan", "<"],
@@ -257,48 +257,48 @@ for (let [e, t] of [
257
257
  ["equal", "=="],
258
258
  ["notEqual", "!="]
259
259
  ]) Z[e] = function(e) {
260
- return C(t, this, e, !0);
260
+ return S(t, this, e, !0);
261
261
  };
262
262
  var tt = {
263
- abs: w,
264
- sign: T,
265
- floor: E,
266
- ceil: D,
267
- round: O,
268
- trunc: k,
269
- fract: A,
270
- sin: j,
271
- cos: M,
272
- tan: N,
273
- asin: P,
274
- acos: F,
275
- atan: I,
276
- tanh: L,
277
- exp: R,
278
- exp2: z,
279
- log: B,
280
- log2: V,
281
- sqrt: ge,
282
- inverseSqrt: H,
283
- saturate: U,
284
- normalize: W,
285
- radians: G,
286
- degrees: K,
287
- dpdx: _e,
288
- dpdy: ve,
289
- fwidth: ye,
290
- min: be,
291
- max: xe,
292
- pow: Se,
293
- clamp: Ce,
294
- step: we,
295
- mix: Ee,
296
- reflect: De,
297
- cross: Oe,
298
- length: ke,
299
- distance: Ae,
300
- dot: je,
301
- oneMinus: q,
263
+ abs: ge,
264
+ sign: _e,
265
+ floor: ve,
266
+ ceil: ye,
267
+ round: be,
268
+ trunc: C,
269
+ fract: w,
270
+ sin: T,
271
+ cos: E,
272
+ tan: D,
273
+ asin: O,
274
+ acos: k,
275
+ atan: A,
276
+ tanh: j,
277
+ exp: M,
278
+ exp2: N,
279
+ log: P,
280
+ log2: F,
281
+ sqrt: I,
282
+ inverseSqrt: L,
283
+ saturate: R,
284
+ normalize: z,
285
+ radians: B,
286
+ degrees: V,
287
+ dpdx: H,
288
+ dpdy: Se,
289
+ fwidth: U,
290
+ min: W,
291
+ max: G,
292
+ pow: K,
293
+ clamp: q,
294
+ step: Ce,
295
+ mix: Te,
296
+ reflect: Ee,
297
+ cross: De,
298
+ length: Oe,
299
+ distance: ke,
300
+ dot: Ae,
301
+ oneMinus: Me,
302
302
  negate: Ne,
303
303
  not: Pe,
304
304
  toFloat: (e) => J(e, m("f32", f(e.type))),
@@ -314,13 +314,13 @@ Z.element = function(e) {
314
314
  let n = e instanceof u ? e : g(e, "i32");
315
315
  return new u(t ? m("f32", +this.type[3]) : d(this.type), "[]", [this, n], (e, t) => `${e.wrap(t.args[0])}[${e.expr(t.args[1])}]`);
316
316
  };
317
- var Q = (e, t) => new u(t, "b" + e, [], (t) => t.builtin(e), 1), nt = () => Q("uv", "vec2f"), rt = () => Q("vertexColor", "vec4f"), it = /*@__PURE__*/ Q("positionLocal", "vec3f"), at = /*@__PURE__*/ Q("positionWorld", "vec3f"), ot = /*@__PURE__*/ Q("normalLocal", "vec3f"), st = /*@__PURE__*/ Q("normalWorld", "vec3f"), ct = /*@__PURE__*/ Q("positionView", "vec3f"), lt = /*@__PURE__*/ Q("normalView", "vec3f"), ut = /*@__PURE__*/ Q("tangentLocal", "vec3f"), dt = /*@__PURE__*/ Q("tangentWorld", "vec3f"), ft = /*@__PURE__*/ Q("bitangentWorld", "vec3f"), pt = /*@__PURE__*/ Q("linearDepth", "f32"), mt = /*@__PURE__*/ Q("cameraNear", "f32"), ht = /*@__PURE__*/ Q("cameraFar", "f32"), gt = /*@__PURE__*/ Q("modelMatrix", "mat4x4f"), _t = /*@__PURE__*/ Q("viewMatrix", "mat4x4f"), vt = /*@__PURE__*/ Q("projectionMatrix", "mat4x4f"), yt = /*@__PURE__*/ Q("vertexIndex", "u32"), bt = /*@__PURE__*/ Q("instanceMatrix", "mat4x4f"), xt = /*@__PURE__*/ Q("instanceColor", "vec4f"), St = /*@__PURE__*/ Q("instanceUV", "vec4f"), Ct = /*@__PURE__*/ Q("hdrTarget", "f32"), wt = /*@__PURE__*/ Q("viewDirection", "vec3f"), Tt = /*@__PURE__*/ Q("cameraPosition", "vec3f"), Et = /*@__PURE__*/ Q("screenCoordinate", "vec2f"), Dt = /*@__PURE__*/ Q("screenUV", "vec2f"), Ot = (e, t) => new u(t, "f" + e, [], (n) => n.frame(e, t), 1), kt = /*@__PURE__*/ Ot("time", "f32"), At = /*@__PURE__*/ Ot("deltaTime", "f32"), jt = /*@__PURE__*/ Ot("resolution", "vec2f");
318
- function Mt(e) {
317
+ var Q = (e, t) => new u(t, "b" + e, [], (t) => t.builtin(e), 1), nt = () => Q("uv", "vec2f"), rt = () => Q("vertexColor", "vec4f"), it = /*@__PURE__*/ Q("positionLocal", "vec3f"), at = /*@__PURE__*/ Q("positionWorld", "vec3f"), ot = /*@__PURE__*/ Q("normalLocal", "vec3f"), st = /*@__PURE__*/ Q("normalWorld", "vec3f"), ct = /*@__PURE__*/ Q("positionView", "vec3f"), lt = /*@__PURE__*/ Q("normalView", "vec3f"), ut = /*@__PURE__*/ Q("tangentLocal", "vec3f"), dt = /*@__PURE__*/ Q("tangentWorld", "vec3f"), ft = /*@__PURE__*/ Q("bitangentWorld", "vec3f"), pt = /*@__PURE__*/ Q("linearDepth", "f32"), mt = /*@__PURE__*/ Q("cameraNear", "f32"), ht = /*@__PURE__*/ Q("cameraFar", "f32"), gt = /*@__PURE__*/ Q("modelMatrix", "mat4x4f"), _t = /*@__PURE__*/ Q("viewMatrix", "mat4x4f"), vt = /*@__PURE__*/ Q("projectionMatrix", "mat4x4f"), yt = /*@__PURE__*/ Q("vertexIndex", "u32"), bt = /*@__PURE__*/ Q("instanceMatrix", "mat4x4f"), xt = /*@__PURE__*/ Q("instanceColor", "vec4f"), St = /*@__PURE__*/ Q("instanceUV", "vec4f"), Ct = /*@__PURE__*/ Q("hdrTarget", "f32"), wt = /*@__PURE__*/ Q("viewDirection", "vec3f"), Tt = /*@__PURE__*/ Q("cameraPosition", "vec3f"), Et = /*@__PURE__*/ Q("screenCoordinate", "vec2f"), Dt = /*@__PURE__*/ Q("screenUV", "vec2f"), $ = (e, t) => new u(t, "f" + e, [], (n) => n.frame(e, t), 1), Ot = /*@__PURE__*/ $("time", "f32"), kt = /*@__PURE__*/ $("deltaTime", "f32"), At = /*@__PURE__*/ $("resolution", "vec2f");
318
+ function jt(e) {
319
319
  return (d(e.type) === "bool" || p(e.type)) && h("varying() needs a numeric scalar or vector"), new u(e.type, "y", [e], (e, t) => e.stage.varying ? e.stage.varying(e, t.args[0]) : e.expr(t.args[0]), 1);
320
320
  }
321
- var Nt = (e) => new u(e, "p" + l(), [], (e, t) => e.param(t), 1);
322
- function Pt(e, t, n) {
323
- let r = v(t), i = Nt("i32"), o = Nt(r.type), s = _(a(() => n(i, o)), r.type, "loop body result"), c = e instanceof u ? e.type === "i32" ? e : J(e, "i32") : g(e, "i32");
321
+ var Mt = (e) => new u(e, "p" + l(), [], (e, t) => e.param(t), 1);
322
+ function Nt(e, t, n) {
323
+ let r = v(t), i = Mt("i32"), o = Mt(r.type), s = _(a(() => n(i, o)), r.type, "loop body result"), c = e instanceof u ? e.type === "i32" ? e : J(e, "i32") : g(e, "i32");
324
324
  return new u(r.type, "r" + l(), [
325
325
  c,
326
326
  r,
@@ -334,13 +334,13 @@ function Pt(e, t, n) {
334
334
  return e.line(` ${a} = ${c};`), e.line("}"), a;
335
335
  }, 4);
336
336
  }
337
- function Ft(e, t = "func") {
337
+ function Pt(e, t = "func") {
338
338
  (!/^[a-zA-Z]\w*$/.test(t) || t.startsWith("nd") || t === "fn") && h("Fn names are WGSL identifiers not starting with nd");
339
339
  let n = /* @__PURE__ */ new Map();
340
340
  return (...r) => {
341
341
  let i = r.map((e) => v(e)), o = i.map((e) => e.type).join(), s = n.get(o);
342
342
  if (!s) {
343
- let r = i.map((e) => Nt(e.type));
343
+ let r = i.map((e) => Mt(e.type));
344
344
  s = {
345
345
  name: t,
346
346
  id: l(),
@@ -352,11 +352,11 @@ function Ft(e, t = "func") {
352
352
  return new u(c.result.type, "n" + c.id, i, (e, t) => `${e.fn(c)}(${t.args.map((t) => e.expr(t)).join(", ")})`);
353
353
  };
354
354
  }
355
- function It(e) {
355
+ function Ft(e) {
356
356
  let t = /fn\s+(\w+)\s*\(([^)]*)\)\s*->\s*([\w<>]+)/.exec(e) ?? h("wgslFn needs \"fn name(params) -> type\""), n = t[2].split(",").filter((e) => e.trim()).map((e) => e.split(":")[1]?.trim());
357
357
  return (...r) => (r.length !== n.length && h(`${t[1]} takes ${n.length} arguments, got ${r.length}`), new u(t[3], "w" + e, r.map((e, r) => _(e, n[r], `${t[1]} argument ${r + 1}`)), (n, r) => (n.declare(e, e), `${t[1]}(${r.args.map((e) => n.expr(e)).join(", ")})`)));
358
358
  }
359
- var Lt = class extends u {
359
+ var It = class extends u {
360
360
  constructor(e, t, n) {
361
361
  super(t, "u" + l(), [], (e, t) => e.uniform(t), 1), this.name = n, d(t) === "bool" && h("Uniforms cannot be bool; use u32"), n !== void 0 && (!/^[a-zA-Z]\w*$/.test(n) || /^(alias|break|case|const|const_assert|continue|continuing|default|diagnostic|discard|else|enable|false|fn|for|if|let|loop|override|requires|return|struct|switch|true|var|while|[fiu]32|f16|bool|vec\d\w*|mat\d\w*|array|atomic|ptr|sampler\w*|texture\w*)$/.test(n)) && h(`Uniform name ${n} is not a usable WGSL identifier`), this.data = [], this.value = e;
362
362
  }
@@ -375,9 +375,9 @@ var Lt = class extends u {
375
375
  });
376
376
  }
377
377
  };
378
- function Rt(e, t = {}) {
378
+ function Lt(e, t = {}) {
379
379
  let n = typeof e == "string" ? 3 : typeof e == "number" ? 1 : e.length;
380
- return new Lt(e, t.type ?? {
380
+ return new It(e, t.type ?? {
381
381
  1: "f32",
382
382
  2: "vec2f",
383
383
  3: "vec3f",
@@ -386,18 +386,18 @@ function Rt(e, t = {}) {
386
386
  16: "mat4x4f"
387
387
  }[n] ?? h("Unsupported uniform value"), t.name);
388
388
  }
389
- var zt = (e) => p(e) ? e[3] === "2" ? 8 : 16 : [
389
+ var Rt = (e) => p(e) ? e[3] === "2" ? 8 : 16 : [
390
390
  4,
391
391
  8,
392
392
  16,
393
393
  16
394
- ][f(e) - 1], Bt = (e) => p(e) ? e[3] === "2" ? 16 : e[3] * 16 : f(e) * 4, Vt = class {
394
+ ][f(e) - 1], zt = (e) => p(e) ? e[3] === "2" ? 16 : e[3] * 16 : f(e) * 4, Bt = class {
395
395
  constructor(e = 0, t = !1) {
396
396
  this.base = e, this.compute = t, this.members = [], this.resources = [], this.varyings = [], this.functions = /* @__PURE__ */ new Map(), this.declarations = /* @__PURE__ */ new Map(), this.canonical = /* @__PURE__ */ new Map(), this.canonOf = /* @__PURE__ */ new Map(), this.ids = /* @__PURE__ */ new Map(), this.refs = /* @__PURE__ */ new Map(), this.mutable = /* @__PURE__ */ new Map(), this.size = 16, this.counter = 0, this.buffers = /* @__PURE__ */ new WeakMap(), this.next = e;
397
397
  }
398
398
  stage(e, t) {
399
399
  for (let e of t) this.count(e);
400
- let n = new $(this, e), r = t.map((e) => n.expr(e));
400
+ let n = new Wt(this, e), r = t.map((e) => n.expr(e));
401
401
  return {
402
402
  lines: n.pop(),
403
403
  values: r
@@ -493,23 +493,23 @@ var zt = (e) => p(e) ? e[3] === "2" ? 8 : 16 : [
493
493
  }, this.resources.push(this.block));
494
494
  let a = t, o = 1;
495
495
  for (; this.members.some((e) => e.name === a);) a = t + o++;
496
- let s = Math.ceil((this.members.length ? this.members.at(-1).offset + Bt(this.members.at(-1).type) : 0) / zt(e)) * zt(e);
496
+ let s = Math.ceil((this.members.length ? this.members.at(-1).offset + zt(this.members.at(-1).type) : 0) / Rt(e)) * Rt(e);
497
497
  i = {
498
498
  name: a,
499
499
  type: e,
500
500
  offset: s,
501
501
  node: n,
502
502
  frame: r
503
- }, this.members.push(i), this.size = Math.max(16, Math.ceil((s + Bt(e)) / 16) * 16);
503
+ }, this.members.push(i), this.size = Math.max(16, Math.ceil((s + zt(e)) / 16) * 16);
504
504
  }
505
505
  return "ndu." + i.name;
506
506
  }
507
- }, Ht = (e, t) => e.length === t.length && e.every((e, n) => {
507
+ }, Vt = (e, t) => e.length === t.length && e.every((e, n) => {
508
508
  let r = e.resource, i = t[n].resource;
509
509
  return e.binding === t[n].binding && (r === i || !!r?.buffer && r.buffer === i?.buffer && r.offset === i.offset && r.size === i.size);
510
- }), $ = class e {
510
+ }), Ht = /^(?:vec[234][fhiu]?|mat[234]x[234][fh]?|f32|f16|i32|u32|bool|true|false|abs|acos|asin|atan|atan2|ceil|clamp|cos|cosh|cross|degrees|determinant|distance|dot|exp|exp2|floor|fract|inverseSqrt|length|log|log2|max|min|mix|normalize|pow|radians|reflect|round|saturate|sign|sin|sinh|smoothstep|sqrt|step|tan|tanh|transpose|trunc)$/, Ut = (e, t) => (e.match(/(?<![\w.])[A-Za-z_]\w*/g) ?? []).every((e) => Ht.test(e) || t.has(e)), Wt = class e {
511
511
  constructor(e, t) {
512
- this.program = e, this.stage = t, this.inFn = !1, this.epoch = 0, this.scopes = [[]], this.memo = /* @__PURE__ */ new Map(), this.params = /* @__PURE__ */ new Map();
512
+ this.program = e, this.stage = t, this.inFn = !1, this.epoch = 0, this.scopes = [[]], this.memo = /* @__PURE__ */ new Map(), this.params = /* @__PURE__ */ new Map(), this.consts = /* @__PURE__ */ new Set();
513
513
  }
514
514
  expr(e) {
515
515
  let t = this.program.canon(e), n = this.memo.get(t);
@@ -523,7 +523,7 @@ var zt = (e) => p(e) ? e[3] === "2" ? 8 : 16 : [
523
523
  }), r;
524
524
  if (t.flags & 1 || !this.program.shared(t)) return r;
525
525
  let o = this.program.name();
526
- return this.line(`let ${o} = ${r};`), this.memo.set(t, {
526
+ return (f(t.type) > 1 || p(t.type)) && Ut(r, this.consts) ? (this.consts.add(o), this.line(`const ${o}: ${t.type} = ${r};`)) : this.line(`let ${o} = ${r};`), this.memo.set(t, {
527
527
  name: o,
528
528
  scope: i,
529
529
  epoch: a
@@ -587,4 +587,4 @@ var zt = (e) => p(e) ? e[3] === "2" ? 8 : 16 : [
587
587
  }
588
588
  };
589
589
  //#endregion
590
- export { We as $, ze as $t, M as A, De as At, R as B, T as Bt, mt as C, q as Ct, Ce as D, Se as Dt, D as E, at as Et, Ae as F, U as Ft, ye as G, we as Gt, Le as H, f as Ht, pe as I, d as It, bt as J, ut as Jt, Ct as K, de as Kt, je as L, Et as Lt, K as M, jt as Mt, At as N, O as Nt, Qe as O, vt as Ot, Ie as P, Ht as Pt, p as Q, k as Qt, _e as R, Dt as Rt, ht as S, Pe as St, _ as T, ct as Tt, E as U, Te as Ut, z as V, j as Vt, A as W, ge as Wt, Re as X, L as Xt, St as Y, dt as Yt, H as Z, kt as Zt, he as _, o as _t, re as a, Ye as an, B as at, Q as b, st as bt, c, He as cn, Xe as ct, Lt as d, rt as dn, be as dt, Rt as en, Ge as et, w as f, yt as fn, Ee as ft, I as g, i as gn, Ne as gt, P as h, It as hn, fe as ht, s as i, Je as in, pt as it, Oe as j, Me as jt, g as k, G as kt, Vt as l, Ue as ln, Ze as lt, ue as m, _t as mn, gt as mt, te as n, nt as nn, ke as nt, u as o, Mt as on, V as ot, F as p, wt as pn, me as pt, xt as q, N as qt, Ft as r, qe as rn, X as rt, ne as s, Ve as sn, Pt as st, $ as t, l as tn, Ke as tt, ee as u, m as un, xe as ut, ft as v, ot as vt, Tt as w, it as wt, b as x, W as xt, Be as y, lt as yt, ve as z, Fe as zt };
590
+ export { We as $, ze as $t, E as A, Ee as At, M as B, _e as Bt, mt as C, Me as Ct, q as D, K as Dt, ye as E, at as Et, ke as F, R as Ft, U as G, Ce as Gt, Le as H, f as Ht, me as I, d as It, bt as J, ut as Jt, Ct as K, fe as Kt, Ae as L, Et as Lt, V as M, At as Mt, kt as N, be as Nt, Qe as O, vt as Ot, Ie as P, Vt as Pt, p as Q, C as Qt, H as R, Dt as Rt, ht as S, Pe as St, _ as T, ct as Tt, ve as U, we as Ut, N as V, T as Vt, w as W, I as Wt, Re as X, j as Xt, St as Y, dt as Yt, L as Z, Ot as Zt, xe as _, o as _t, re as a, Ye as an, P as at, Q as b, st as bt, c, He as cn, Xe as ct, It as d, rt as dn, W as dt, Lt as en, Ge as et, ge as f, yt as fn, Te as ft, A as g, i as gn, Ne as gt, O as h, Ft as hn, pe as ht, s as i, Je as in, pt as it, De as j, je as jt, g as k, B as kt, Bt as l, Ue as ln, Ze as lt, de as m, _t as mn, gt as mt, te as n, nt as nn, Oe as nt, u as o, jt as on, F as ot, k as p, wt as pn, he as pt, xt as q, D as qt, Pt as r, qe as rn, X as rt, ne as s, Ve as sn, Nt as st, Wt as t, l as tn, Ke as tt, ee as u, m as un, G as ut, ft as v, ot as vt, Tt as w, it as wt, b as x, z as xt, Be as y, lt as yt, Se as z, Fe as zt };
package/dist/node.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { MaterialMeshData, MeshGeometry } from '@margoengine/materials';
1
2
  type N = 2 | 3 | 4;
2
3
  /** WGSL scalar types a node can have. */
3
4
  export type Scalar = 'f32' | 'f16' | 'i32' | 'u32' | 'bool';
@@ -352,6 +353,10 @@ export declare class Program {
352
353
  binding: number;
353
354
  }[];
354
355
  readonly varyings: Node[];
356
+ /** @internal The mesh attributes `attribute()` reads, and what packs a mesh's geometry for them. */
357
+ attributes?: Resource & {
358
+ read(geometry: MeshGeometry): MaterialMeshData;
359
+ };
355
360
  /** @internal Fn specialisation key to WGSL name. */ readonly functions: Map<string, string>;
356
361
  private readonly declarations;
357
362
  private readonly canonical;
@@ -393,7 +398,7 @@ export declare class Program {
393
398
  }
394
399
  /** True when two entry lists bind the same resources (a uniform `{buffer}` compares by buffer). */
395
400
  export declare const sameEntries: (a: readonly GPUBindGroupEntry[], b: readonly GPUBindGroupEntry[]) => boolean;
396
- /** Emits one stage. Expressions referenced more than once become `let ndN`; everything else is inlined. */
401
+ /** Emits one stage. Expressions referenced more than once become `let ndN` (`const ndN` for a constant vector or matrix); everything else is inlined. */
397
402
  export declare class Builder {
398
403
  readonly program: Program;
399
404
  readonly stage: ShaderStage;
@@ -403,6 +408,7 @@ export declare class Builder {
403
408
  private scopes;
404
409
  private readonly memo;
405
410
  private readonly params;
411
+ private readonly consts;
406
412
  constructor(program: Program, stage: ShaderStage);
407
413
  expr(n: Node): string;
408
414
  /** The expression, parenthesised when it is an inlined operator. */
package/dist/noise.js CHANGED
@@ -1,4 +1,4 @@
1
- import { T as e, cn as t, ln as n, o as r, sn as i } from "./node-DzKv9CF2.js";
1
+ import { T as e, cn as t, ln as n, o as r, sn as i } from "./node-B6yoIC9V.js";
2
2
  //#region ../shared/fractal.js
3
3
  function a({ octaves: e = 5, lacunarity: t = 2, gain: n = .5, frequency: r = 1 }) {
4
4
  if (!Number.isInteger(e) || e < 1 || e > 16 || ![
package/dist/pass.d.ts CHANGED
@@ -68,6 +68,7 @@ export declare class ScenePass implements EnginePlugin {
68
68
  constructor({ outputs, order }: ScenePassOptions);
69
69
  /** Module-scope WGSL for the capture shader of `code`: a variable per output a material did not declare, and the outputs. */
70
70
  private tail;
71
+ private outputs;
71
72
  private begin;
72
73
  /** Draws `model` in this pass from the next frame, beside any SSR, SSGI or other ScenePass that captures it. Returns a remover. */
73
74
  add(model: ScenePassModel): () => void;
package/dist/pass.js CHANGED
@@ -1,10 +1,10 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
- import { Et as e, K as t, Ot as n, Rt as r, T as i, en as a, ln as o, mn as s, sn as c, zt as l } from "./node-DzKv9CF2.js";
5
- import { n as u } from "./texture-D6vy0bam.js";
6
- import { n as d, t as f } from "./material-REzUrXtu.js";
7
- import { t as p } from "./view-rect-Bm1ac-TK.js";
4
+ import { Et as e, K as t, Ot as n, Rt as r, T as i, en as a, ln as o, mn as s, sn as c, zt as l } from "./node-B6yoIC9V.js";
5
+ import { t as u } from "./view-rect-Bm1ac-TK.js";
6
+ import { n as d } from "./texture-BawKO_h9.js";
7
+ import { n as f, t as p } from "./material-CZ8V1FeA.js";
8
8
  import { MargoError as m } from "@margoengine/math/errors";
9
9
  import { acquireOpaqueColor as h } from "@margoengine/materials";
10
10
  //#region ../shared/capture.js
@@ -55,20 +55,20 @@ function b(e, t, n) {
55
55
  }
56
56
  //#endregion
57
57
  //#region src/pass.ts
58
- var x = (e) => "margoOut" + e, S = (e) => `var<private> ${x(e)}:vec4f;\n`, C = (e) => {
58
+ var x = /struct MargoMaterial\s*\{/, S = (e) => "margoOut" + e, C = (e) => `var<private> ${S(e)}:vec4f;\n`, w = (e) => {
59
59
  if (!/^[A-Za-z][A-Za-z0-9]*$/.test(e)) throw TypeError(`Output name "${e}" must be letters and digits, starting with a letter`);
60
- }, w = class extends f {
60
+ }, T = class extends p {
61
61
  constructor(e = {}) {
62
62
  let { outputs: t = {}, ...n } = e, r = Object.keys(t);
63
63
  r.forEach((e) => {
64
- if (C(e), e === "color") throw TypeError("The color output is the lit colour; pick another name for a node");
64
+ if (w(e), e === "color") throw TypeError("The color output is the lit colour; pick another name for a node");
65
65
  i(t[e], "vec4f", `output ${e}`);
66
66
  });
67
67
  let a = "";
68
68
  super(n, (e) => {
69
- let n = e.stage(d, Object.values(t));
70
- a = [...n.lines, ...n.values.map((e, t) => `${x(r[t])}=${e};`)].join("\n ");
71
- }), this.patchedOutputs = /* @__PURE__ */ new Map(), this.lines = a, this.declared = r.map(S).join("");
69
+ let n = e.stage(f, Object.values(t));
70
+ a = [...n.lines, ...n.values.map((e, t) => `${S(r[t])}=${e};`)].join("\n ");
71
+ }), this.patchedOutputs = /* @__PURE__ */ new Map(), this.lines = a, this.declared = r.map(C).join("");
72
72
  }
73
73
  shader(e, t) {
74
74
  let n = super.shader(e, t);
@@ -81,14 +81,14 @@ var x = (e) => "margoOut" + e, S = (e) => `var<private> ${x(e)}:vec4f;\n`, C = (
81
81
  }
82
82
  return r;
83
83
  }
84
- }, T = 0, E = class t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
85
- static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
84
+ }, E = 0, D = class t {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
85
+ static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
86
86
  let r = new t(n);
87
87
  return e.use(r), r;
88
88
  }
89
89
  constructor({ outputs: e, order: t = .5 }) {
90
- if (this.name = "shader:scene:" + T++, this.models = /* @__PURE__ */ new Map(), this.views = /* @__PURE__ */ new Map(), this.bound = /* @__PURE__ */ new Map(), this.tails = /* @__PURE__ */ new Map(), this.previous = a(Array(16).fill(0), { type: "mat4x4f" }), this.textures = [], this.width = 0, this.height = 0, this.depthFormat = "", this.disposed = !1, this.names = Object.keys(e ?? {}), this.formats = Object.values(e ?? {}), !this.names.length) throw TypeError("ScenePass needs at least one output: {glow: \"rgba16float\"}");
91
- this.names.forEach(C);
90
+ if (this.name = "shader:scene:" + E++, this.models = /* @__PURE__ */ new Map(), this.views = /* @__PURE__ */ new Map(), this.bound = /* @__PURE__ */ new Map(), this.tails = /* @__PURE__ */ new Map(), this.previous = a(Array(16).fill(0), { type: "mat4x4f" }), this.textures = [], this.width = 0, this.height = 0, this.depthFormat = "", this.disposed = !1, this.names = Object.keys(e ?? {}), this.formats = Object.values(e ?? {}), !this.names.length) throw TypeError("ScenePass needs at least one output: {glow: \"rgba16float\"}");
91
+ this.names.forEach(w);
92
92
  for (let e of this.formats) if (/32float|int$|depth|stencil/.test(e)) throw TypeError(`ScenePass output format ${e} must be a filterable colour format such as rgba16float`);
93
93
  if (!Number.isFinite(t) || t <= 0) throw RangeError("ScenePass order must be a number > 0");
94
94
  this.order = t, this.hook = {
@@ -100,11 +100,14 @@ var x = (e) => "margoOut" + e, S = (e) => `var<private> ${x(e)}:vec4f;\n`, C = (
100
100
  tail(e) {
101
101
  let t = this.tails.get(e);
102
102
  if (t === void 0) {
103
- let n = this.names.includes("color");
104
- t = this.names.filter((t) => t !== "color" && !e.includes(S(t))).map(S).join("") + (n ? "var<private> margoBeauty:vec4f;\n" : "") + `struct MargoCapture {${this.names.map((e, t) => `@location(${t}) o${t}:vec4f`).join(",")}}\nfn margoCapture(s:Surface,v:vec3f,k:vec3f)->MargoCapture {return MargoCapture(${this.names.map((e) => e === "color" ? "margoBeauty" : x(e)).join(",")});}\n`, this.tails.size >= 64 && this.tails.clear(), this.tails.set(e, t);
103
+ let n = x.test(e), r = (t) => n ? RegExp(`var\\s*<\\s*private\\s*>\\s*${t}\\s*:`).test(e) : e.includes(`var<private> ${t}:vec4f;\n`), i = this.names.includes("color") && !(n && r("margoBeauty"));
104
+ t = this.names.filter((e) => e !== "color" && !r(S(e))).map(C).join("") + (i ? "var<private> margoBeauty:vec4f;\n" : "") + `struct MargoCapture {${this.names.map((e, t) => `@location(${t}) o${t}:vec4f`).join(",")}}\n` + (n ? `fn margoCapture(m:MargoMaterial)->MargoCapture {${i ? "margoBeauty=vec4f(m.base,1);" : "_=m;"}return MargoCapture(${this.outputs()});}\n` : `fn margoCapture(s:Surface,v:vec3f,k:vec3f)->MargoCapture {return MargoCapture(${this.outputs()});}\n`), this.tails.size >= 64 && this.tails.clear(), this.tails.set(e, t);
105
105
  }
106
106
  return t;
107
107
  }
108
+ outputs() {
109
+ return this.names.map((e) => e === "color" ? "margoBeauty" : S(e)).join(",");
110
+ }
108
111
  begin() {
109
112
  if (this.pass) return this.pass;
110
113
  let e = this.context, t = !e.view?.index, n = this.depthFormat.includes("stencil") ? {
@@ -132,7 +135,7 @@ var x = (e) => "margoOut" + e, S = (e) => `var<private> ${x(e)}:vec4f;\n`, C = (
132
135
  ...n
133
136
  }
134
137
  });
135
- return p(r, e), r;
138
+ return u(r, e), r;
136
139
  }
137
140
  add(e) {
138
141
  if (this.disposed) throw new m("disposed", "ScenePass is disposed; create a new ScenePass.");
@@ -214,7 +217,7 @@ var x = (e) => "margoOut" + e, S = (e) => `var<private> ${x(e)}:vec4f;\n`, C = (
214
217
  this.dispose();
215
218
  }
216
219
  };
217
- function D(e) {
220
+ function O(e) {
218
221
  let n = h(e, () => {}), a = /* @__PURE__ */ new WeakMap(), o = { bind(e) {
219
222
  let t = a.get(e);
220
223
  return t || a.set(e, t = e.createSampler({
@@ -225,7 +228,7 @@ function D(e) {
225
228
  return {
226
229
  texture: o,
227
230
  read(e = r) {
228
- let n = u(o, i(e, "vec2f", "sceneColor coordinate")).rgb;
231
+ let n = d(o, i(e, "vec2f", "sceneColor coordinate")).rgb;
229
232
  return l(t.greaterThan(.5), n, l(n.lessThanEqual(.04045), n.div(12.92), n.add(.055).div(1.055).pow(2.4)));
230
233
  },
231
234
  dispose: s,
@@ -233,4 +236,4 @@ function D(e) {
233
236
  };
234
237
  }
235
238
  //#endregion
236
- export { w as PassMaterial, E as ScenePass, D as sceneColor };
239
+ export { T as PassMaterial, D as ScenePass, O as sceneColor };