@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
package/dist/glsl.js CHANGED
@@ -1,6 +1,6 @@
1
- import { T as e, o as t, tn as n } from "./node-DzKv9CF2.js";
2
- import { t as r } from "./texture-D6vy0bam.js";
3
- import { t as i } from "./errors-CsQwshHA.js";
1
+ import { T as e, o as t, tn as n } from "./node-B6yoIC9V.js";
2
+ import { t as r } from "./errors-CsQwshHA.js";
3
+ import { t as i } from "./texture-BawKO_h9.js";
4
4
  import { n as a, r as o, t as s } from "./preprocess-CWGWlBWQ.js";
5
5
  //#region src/glsl.ts
6
6
  var c = {
@@ -30,8 +30,8 @@ var c = {
30
30
  };
31
31
  function _(e, t = {}, n = "fragment") {
32
32
  if (typeof e != "string" || !e.trim() || e.length > 65536) throw TypeError("glslToWGSL needs 1..65536 code units of GLSL source with a function in it");
33
- let { name: r, defines: c = {}, flipY: _ = !1, strict: v = !1 } = t ?? {};
34
- if (r !== void 0 && (typeof r != "string" || !d.test(r))) throw TypeError("glslFn name must be a GLSL identifier");
33
+ let { name: i, defines: c = {}, flipY: _ = !1, strict: v = !1 } = t ?? {};
34
+ if (i !== void 0 && (typeof i != "string" || !d.test(i))) throw TypeError("glslFn name must be a GLSL identifier");
35
35
  if (typeof _ != "boolean" || typeof v != "boolean") throw TypeError("glslFn flipY and strict must be booleans");
36
36
  if (typeof c != "object" || !c) throw TypeError("glslFn defines must be an object");
37
37
  for (let [e, t] of Object.entries(c)) if (!d.test(e) || ![
@@ -41,7 +41,7 @@ function _(e, t = {}, n = "fragment") {
41
41
  ].includes(typeof t) || /[\r\n\\]/.test(String(t))) throw TypeError(`glslFn define ${e} needs an identifier and a one-line string, number or boolean`);
42
42
  let y = n === "fragment", b = JSON.stringify([
43
43
  e,
44
- r ?? null,
44
+ i ?? null,
45
45
  c,
46
46
  _,
47
47
  v,
@@ -49,7 +49,7 @@ function _(e, t = {}, n = "fragment") {
49
49
  ]), x = p.get(b);
50
50
  if (x) return x;
51
51
  let S = [.../^\s*#\s*version\b/m.test(e) ? [] : ["#version 300 es"], ...Object.entries(c).map(([e, t]) => `#define ${e} ${typeof t == "boolean" ? +t : t}`)], C = { version: 100 }, w = s(S.length ? S.join("\n") + "\n" + e : e, C), T = S.length, E = (e, t) => {
52
- throw Object.assign(i("failed", `glslFn: ${e}`), f(w, t, S.length));
52
+ throw Object.assign(r("failed", `glslFn: ${e}`), f(w, t, S.length));
53
53
  }, D;
54
54
  try {
55
55
  D = new o(w, "GLSL function").parse();
@@ -64,7 +64,7 @@ function _(e, t = {}, n = "fragment") {
64
64
  let t = T;
65
65
  for (let n of w.matchAll(new RegExp(e, "g"))) t = n.index;
66
66
  return t;
67
- }, j = D.functions.filter((e) => e.body && (r === void 0 || e.name === r)).at(-1) ?? E(r === void 0 ? "the source defines no function" : `the source defines no function ${r}`, T), M = A(String.raw`\b${j.name}\s*\(`), N = j.params.map((e) => {
67
+ }, j = D.functions.filter((e) => e.body && (i === void 0 || e.name === i)).at(-1) ?? E(i === void 0 ? "the source defines no function" : `the source defines no function ${i}`, T), M = A(String.raw`\b${j.name}\s*\(`), N = j.params.map((e) => {
68
68
  if (/\b(out|inout)\b/.test(e.qualifier)) return E(`parameter ${e.name} of ${j.name} is ${e.qualifier}; the called function takes inputs only`, M);
69
69
  let t = u[e.type] ?? l(e.type);
70
70
  return t ? {
@@ -102,15 +102,15 @@ function _(e, t = {}, n = "fragment") {
102
102
  return p.size >= 256 && p.delete(p.keys().next().value), p.set(b, R), R;
103
103
  }
104
104
  function v(t, n) {
105
- let i = r("glslFn", n, t, e(0, "f32"), void 0), a;
106
- return i.emit({
105
+ let r = i("glslFn", n, t, e(0, "f32"), void 0), a;
106
+ return r.emit({
107
107
  resource: (e) => (a = e, "r"),
108
108
  expr: () => "0",
109
109
  stage: {
110
110
  kind: "vertex",
111
111
  builtins: {}
112
112
  }
113
- }, i), a;
113
+ }, r), a;
114
114
  }
115
115
  function y(r, i = {}) {
116
116
  let a = _(r, i), o = n();
@@ -138,10 +138,10 @@ function y(r, i = {}) {
138
138
  }
139
139
  function b(e, t, n = {}) {
140
140
  if (typeof t?.translateWGSL != "function") throw TypeError("toGLSL needs the layer's translator: toGLSL(target, await import('@margoengine/webgl2-compat/glsl'))");
141
- let r = e, a, o;
142
- if (r?.patched instanceof Map) {
143
- let e = [...(r.patchedOutputs instanceof Map && r.patchedOutputs.size ? r.patchedOutputs : r.patched).values()].at(-1);
144
- if (e === void 0) throw i("state", "toGLSL needs a NodeMaterial that has drawn once; render a frame with it first");
141
+ let i = e, a, o;
142
+ if (i?.patched instanceof Map) {
143
+ let e = [...(i.patchedOutputs instanceof Map && i.patchedOutputs.size ? i.patchedOutputs : i.patched).values()].at(-1);
144
+ if (e === void 0) throw r("state", "toGLSL needs a NodeMaterial that has drawn once; render a frame with it first");
145
145
  a = {
146
146
  source: e,
147
147
  entryPoint: "vertex"
@@ -149,8 +149,8 @@ function b(e, t, n = {}) {
149
149
  source: e,
150
150
  entryPoint: "fragment"
151
151
  };
152
- } else if (typeof r?.code == "function") {
153
- let e = r.code();
152
+ } else if (typeof i?.code == "function") {
153
+ let e = i.code();
154
154
  a = {
155
155
  source: e,
156
156
  entryPoint: "vertex"
@@ -158,7 +158,7 @@ function b(e, t, n = {}) {
158
158
  source: e,
159
159
  entryPoint: "fragment"
160
160
  };
161
- } else if (typeof r?.vertex == "string" && (r.fragment === void 0 || typeof r.fragment == "string")) a = { source: r.vertex }, o = r.fragment === void 0 ? void 0 : { source: r.fragment };
161
+ } else if (typeof i?.vertex == "string" && (i.fragment === void 0 || typeof i.fragment == "string")) a = { source: i.vertex }, o = i.fragment === void 0 ? void 0 : { source: i.fragment };
162
162
  else throw TypeError("toGLSL needs a NodePass, a NodeMaterial or { vertex, fragment } WGSL; pass one of them");
163
163
  return t.translateWGSL({
164
164
  ...n,
@@ -0,0 +1,55 @@
1
+ //#region ../shared/frame-resources.js
2
+ var e = (globalThis[Symbol.for("margoengine.frame-resources")] ??= { devices: /* @__PURE__ */ new WeakMap() }).devices;
3
+ function t(t) {
4
+ let n = e.get(t);
5
+ return n || (e.set(t, n = {
6
+ frame: 0,
7
+ open: !1,
8
+ lost: !1,
9
+ views: /* @__PURE__ */ new Set(),
10
+ drawing: 0,
11
+ retired: [],
12
+ written: /* @__PURE__ */ new WeakMap()
13
+ }), t.lost?.then?.(() => {
14
+ n.lost = !0;
15
+ let e = n.retired;
16
+ n.retired = [];
17
+ for (let t of e) t.destroy();
18
+ })), n;
19
+ }
20
+ function n(e, n) {
21
+ if (!n) return;
22
+ let r = t(e), i = [n, ...r.written.get(n)?.extras ?? []];
23
+ if (r.written.delete(n), !r.lost && r.open && (r.views.size > 1 || r.drawing > 0)) r.retired.push(...i);
24
+ else for (let e of i) e.destroy();
25
+ }
26
+ //#endregion
27
+ //#region ../shared/gpu.js
28
+ var r = "\nstruct Vertex { @builtin(position) position:vec4f,@location(0) uv:vec2f }\n@vertex fn vertex(@builtin(vertex_index) index:u32)->Vertex {\n let p=array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3))[index];\n return Vertex(vec4f(p,0,1),vec2f(p.x*0.5+0.5,0.5-p.y*0.5));\n}";
29
+ function i(e, t, n, r = {}) {
30
+ let i = e.createShaderModule({ code: t });
31
+ return e.createRenderPipeline({
32
+ layout: "auto",
33
+ vertex: {
34
+ module: i,
35
+ entryPoint: "vertex"
36
+ },
37
+ fragment: {
38
+ module: i,
39
+ entryPoint: "fragment",
40
+ targets: [{ format: n }]
41
+ },
42
+ ...r
43
+ });
44
+ }
45
+ function a(e, t, n = "main") {
46
+ return e.createComputePipeline({
47
+ layout: "auto",
48
+ compute: {
49
+ module: e.createShaderModule({ code: t }),
50
+ entryPoint: n
51
+ }
52
+ });
53
+ }
54
+ //#endregion
55
+ export { n as i, r as n, i as r, a as t };
package/dist/graph.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as e, Dt as t, Et as n, H as r, I as i, Kt as a, L as o, T as s, _t as c, bt as l, cn as u, dn as d, dt as f, ft as p, ht as m, m as h, nn as g, nt as _, ut as v, vt as y, wt as b, xt as x } from "./node-DzKv9CF2.js";
2
- import { t as S } from "./material-REzUrXtu.js";
1
+ import { D as e, Dt as t, Et as n, H as r, I as i, Kt as a, L as o, T as s, _t as c, bt as l, cn as u, dn as d, dt as f, ft as p, ht as m, m as h, nn as g, nt as _, ut as v, vt as y, wt as b, xt as x } from "./node-B6yoIC9V.js";
2
+ import { t as S } from "./material-CZ8V1FeA.js";
3
3
  //#region src/graph.ts
4
4
  var C = Object.freeze({
5
5
  nodes: 128,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './node.js';
2
+ export { attribute } from './attribute.js';
2
3
  export { texture, textureCube, texture3D, type BindableTexture } from './texture.js';
3
4
  export { block, If, Loop, While, Break, Continue, Switch, Var, Let, VarNode, type Branch, type Cases, type LoopRange, } from './control.js';
4
5
  export { NodeMaterial, materialColor, materialNormal, materialRoughness, materialMetalness, materialEmissive, frontFacing, type NodeMaterialOptions, } from './material.js';
package/dist/index.js CHANGED
@@ -1,8 +1,103 @@
1
- import { $ as e, $t as t, A as n, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as p, G as m, Gt as h, H as g, Ht as _, I as v, It as y, J as b, Jt as x, K as S, Kt as C, L as w, Lt as T, M as E, Mt as D, N as O, Nt as k, O as A, Ot as j, P as M, Pt as N, Q as P, Qt as F, R as I, Rt as L, S as R, St as z, T as B, Tt as V, U as H, Ut as U, V as W, Vt as G, W as K, Wt as q, X as J, Xt as Y, Y as X, Yt as Z, Z as Q, Zt as $, _ as ee, a as te, an as ne, at as re, b as ie, bt as ae, c as oe, cn as se, ct as ce, d as le, dn as ue, dt as de, en as fe, et as pe, f as me, fn as he, ft as ge, g as _e, gt as ve, h as ye, hn as be, ht as xe, i as Se, in as Ce, it as we, j as Te, jt as Ee, k as De, kt as Oe, l as ke, ln as Ae, lt as je, m as Me, mn as Ne, mt as Pe, n as Fe, nn as Ie, nt as Le, o as Re, on as ze, ot as Be, p as Ve, pn as He, pt as Ue, q as We, qt as Ge, r as Ke, rn as qe, rt as Je, s as Ye, sn as Xe, st as Ze, t as Qe, tn as $e, tt as et, u as tt, un as nt, ut as rt, v as it, vt as at, w as ot, wt as st, x as ct, xt as lt, y as ut, yt as dt, z as ft, zt as pt } from "./node-DzKv9CF2.js";
2
- import { i as mt, n as ht, r as gt } from "./texture-D6vy0bam.js";
3
- import { a as _t, c as vt, i as yt, l as bt, n as xt, o as St, r as Ct, s as wt, t as Tt, u as Et } from "./control-DvjfV7R0.js";
4
- import { t as Dt } from "./clock-BLGNexlt.js";
5
- import { a as Ot, c as kt, i as At, o as jt, r as Mt, s as Nt, t as Pt } from "./material-REzUrXtu.js";
6
- import { n as Ft, r as It, t as Lt } from "./post-DC62ZleD.js";
7
- import { a as Rt, d as zt, g as Bt, h as Vt, i as Ht, l as Ut, m as Wt, n as Gt, o as Kt, p as qt, r as Jt, s as Yt, t as Xt, u as Zt } from "./compute-D-BghbXj.js";
8
- export { Tt as Break, Qe as Builder, Xt as ComputePass, xt as Continue, Fe as FIXED, Ke as Fn, Ct as If, Se as LEAF, yt as Let, _t as Loop, te as MUTABLE, Re as Node, Pt as NodeMaterial, Lt as NodePass, Ye as ONCE, oe as OP, ke as Program, tt as STMT, Dt as ShaderClock, Gt as StorageBuffer, St as Switch, le as UniformNode, wt as Var, vt as VarNode, bt as While, Jt as WorkgroupArray, me as abs, Ve as acos, Me as add, ye as asin, _e as atan, ee as atan2, it as bitangentWorld, Et as block, ut as bool, ie as builtin, ct as call, R as cameraFar, o as cameraNear, ot as cameraPosition, B as cast, u as ceil, c as clamp, A as color, De as constant, n as cos, Te as cross, E as degrees, O as deltaTime, M as discard, f as distance, v as div, w as dot, I as dpdx, ft as dpdy, i as exp, W as exp2, g as float, H as floor, K as fract, Mt as frontFacing, m as fwidth, Ht as globalId, S as hdrTarget, Ft as inputColor, It as inputDepth, We as instanceColor, Rt as instanceIndex, b as instanceMatrix, X as instanceUV, J as int, Q as inverseSqrt, P as isMatrix, e as ivec2, pe as ivec3, et as ivec4, Le as length, Je as linearColor, we as linearDepth, Kt as localId, Yt as localIndex, re as log, Be as log2, Ze as loop, ce as mat3, je as mat4, At as materialColor, Ot as materialEmissive, jt as materialMetalness, Nt as materialNormal, kt as materialRoughness, rt as max, de as min, ge as mix, Ue as mod, Pe as modelMatrix, xe as mul, ve as negate, at as normalLocal, dt as normalView, ae as normalWorld, lt as normalize, z as not, s as oneMinus, st as positionLocal, V as positionView, d as positionWorld, l as pow, j as projectionMatrix, Oe as radians, r as reflect, Ee as refract, D as resolution, k as round, N as sameEntries, p as saturate, y as scalarOf, T as screenCoordinate, L as screenUV, pt as select, a as sign, G as sin, _ as sizeOf, U as smoothstep, q as sqrt, h as step, Ut as storage, Zt as storageBarrier, C as sub, Ge as tan, x as tangentLocal, Z as tangentWorld, Y as tanh, ht as texture, gt as texture3D, zt as textureBarrier, mt as textureCube, $ as time, F as trunc, t as uint, fe as uniform, $e as unique, Ie as uv, qe as uvec2, Ce as uvec3, ne as uvec4, ze as varying, Xe as vec2, se as vec3, Ae as vec4, nt as vecOf, ue as vertexColor, he as vertexIndex, He as viewDirection, Ne as viewMatrix, be as wgslFn, qt as workgroup, Wt as workgroupBarrier, Vt as workgroupCount, Bt as workgroupId };
1
+ import { $ as e, $t as t, A as n, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as ee, G as te, Gt as ne, H as re, Ht as ie, I as ae, It as oe, J as se, Jt as ce, K as p, Kt as m, L as h, Lt as g, M as _, Mt as v, N as y, Nt as b, O as x, Ot as S, P as C, Pt as w, Q as T, Qt as E, R as D, Rt as O, S as k, St as A, T as j, Tt as M, U as N, Ut as P, V as F, Vt as I, W as L, Wt as R, X as z, Xt as B, Y as V, Yt as H, Z as U, Zt as W, _ as G, a as le, an as ue, at as de, b as fe, bt as pe, c as me, cn as he, ct as ge, d as _e, dn as ve, dt as ye, en as be, et as xe, f as Se, fn as Ce, ft as we, g as Te, gt as Ee, h as De, hn as Oe, ht as ke, i as Ae, in as je, it as Me, j as Ne, jt as Pe, k as Fe, kt as Ie, l as Le, ln as Re, lt as ze, m as Be, mn as Ve, mt as He, n as Ue, nn as We, nt as Ge, o as K, on as Ke, ot as qe, p as Je, pn as Ye, pt as Xe, q as Ze, qt as Qe, r as $e, rn as et, rt as tt, s as nt, sn as rt, st as it, t as at, tn as ot, tt as st, u as ct, un as lt, ut, v as dt, vt as ft, w as pt, wt as mt, x as ht, xt as gt, y as _t, yt as vt, z as yt, zt as bt } from "./node-B6yoIC9V.js";
2
+ import { t as xt } from "./clock-BLGNexlt.js";
3
+ import { a as St, c as Ct, i as wt, l as Tt, n as Et, o as Dt, r as Ot, s as kt, t as At, u as jt } from "./control-CFjkGPBk.js";
4
+ import { a as Mt, d as Nt, g as Pt, h as Ft, i as It, l as Lt, m as Rt, n as q, o as zt, p as Bt, r as Vt, s as Ht, t as Ut, u as Wt } from "./compute-CXGG9qvI.js";
5
+ import { i as Gt, n as Kt, r as qt } from "./texture-BawKO_h9.js";
6
+ import { a as Jt, c as Yt, i as Xt, o as Zt, r as Qt, s as J, t as $t } from "./material-CZ8V1FeA.js";
7
+ import { n as en, r as tn, t as nn } from "./post-DLpZ110L.js";
8
+ import { MargoError as rn } from "@margoengine/math/errors";
9
+ //#region src/attribute.ts
10
+ var an = /^[A-Za-z_][A-Za-z0-9_]*$/, Y = /^(?:([fiu])32|vec([234])([fiu]))$/, X = (e) => +(Y.exec(e)[2] ?? 1), Z = (e) => Y.exec(e)[1] ?? Y.exec(e)[3], Q = {
11
+ i: [-2147483648, 2147483647],
12
+ u: [0, 4294967295]
13
+ }, on = class {
14
+ constructor() {
15
+ this.prefix = "ndat", this.bindings = 1, this.list = [], this.stride = 0;
16
+ }
17
+ add(e, t) {
18
+ let n = this.list.find((t) => t.name === e);
19
+ if (n) {
20
+ if (n.type !== t) throw TypeError(`attribute('${e}') is read as ${n.type} and as ${t}; read it with one type`);
21
+ } else this.list.push({
22
+ name: e,
23
+ type: t,
24
+ offset: this.stride
25
+ }), this.stride += X(t);
26
+ }
27
+ declare(e, t, n) {
28
+ return `@group(${t}) @binding(${n}) var<storage, read> ${e}:array<u32>;\nconst ${e}Stride:u32=${this.stride}u;\n` + this.list.map((t) => `const ${e}_${t.name}:u32=${t.offset}u;`).join("\n");
29
+ }
30
+ entries(e, t) {
31
+ let n = t.meshData;
32
+ if (!(n instanceof $) || n.reads !== this) throw new rn("state", "A material that reads attribute() draws a mesh's own geometry; use it on a mesh from createMesh or createInstancedMesh");
33
+ return [{ buffer: n.words.buffer(e) }];
34
+ }
35
+ read(e) {
36
+ let t = new $(this);
37
+ return t.prepare(e)(), t;
38
+ }
39
+ pack(e, t, n) {
40
+ let r = e.positions.length / 3, i = new Uint32Array(n * this.stride), a = {
41
+ f: new Float32Array(i.buffer),
42
+ i: new Int32Array(i.buffer),
43
+ u: i
44
+ };
45
+ for (let { name: i, type: o, offset: s } of this.list) {
46
+ let c = e.attributes?.[i], l = c && !("type" in c) ? {
47
+ data: c,
48
+ type: "f32"
49
+ } : c, u = X(o), d = Z(o);
50
+ if (!l) throw TypeError(`Mesh geometry has no attribute '${i}', which its material reads; add attributes: {${i}: {data, type: '${o}'}}`);
51
+ if (l.type !== o) throw TypeError(`Mesh geometry attribute '${i}' is ${l.type}, and its material reads it as ${o}; use it as ${o}`);
52
+ if (l.data?.length !== r * u) throw RangeError(`Mesh geometry attribute '${i}' needs ${r * u} values (${r} vertices of ${o}), not ${l.data?.length}`);
53
+ let f = a[d];
54
+ for (let e = 0; e < n; e++) for (let n = 0; n < u; n++) {
55
+ let r = l.data[(t + e) * u + n];
56
+ if (d === "f" ? !Number.isFinite(r) : !Number.isInteger(r) || r < Q[d][0] || r > Q[d][1]) throw RangeError(`Mesh geometry attribute '${i}' holds ${r}; give ${d === "f" ? "finite numbers" : `whole numbers that fit ${d}32`}`);
57
+ f[e * this.stride + s + n] = r;
58
+ }
59
+ }
60
+ return i;
61
+ }
62
+ get words() {
63
+ return this.stride;
64
+ }
65
+ }, $ = class {
66
+ constructor(e) {
67
+ this.reads = e;
68
+ }
69
+ prepare(e, t) {
70
+ let n = t?.start ?? 0, r = t?.count ?? e.positions.length / 3, i = this.reads.pack(e, n, r);
71
+ return () => {
72
+ if (!t && this.words?.data.length !== i.length) {
73
+ this.words?.dispose(), this.words = new q(i, "u32");
74
+ return;
75
+ }
76
+ let e = this.reads.words;
77
+ this.words.data.set(i, n * e), this.words.update(t && {
78
+ start: n * e,
79
+ count: r * e
80
+ });
81
+ };
82
+ }
83
+ dispose() {
84
+ this.words.dispose();
85
+ }
86
+ };
87
+ function sn(e, t) {
88
+ if (typeof e != "string" || !an.test(e)) throw TypeError(`attribute() needs a name of letters, digits and underscores, not '${e}'`);
89
+ if (!Y.test(t)) throw TypeError(`attribute('${e}') type '${t}' is not one to four of f32, i32 or u32; pass 'f32' to 'vec4u'`);
90
+ return new K(t, `at:${e}:${t}`, [], (n, r) => {
91
+ if (n.stage.kind === "fragment") return n.stage.varying(n, r);
92
+ if (n.stage.kind !== "vertex") throw TypeError("attribute() reads a mesh vertex; use it in the nodes of a NodeMaterial");
93
+ let i = n.program, a = i.attributes ??= new on();
94
+ a.add(e, t);
95
+ let o = n.resource(a), s = `${n.builtin("vertexIndex")}*${o}Stride+${o}_${e}`, c = (e) => {
96
+ let n = `${o}[${s}${e ? `+${e}u` : ""}]`;
97
+ return Z(t) === "u" ? n : `bitcast<${Z(t)}32>(${n})`;
98
+ }, l = X(t);
99
+ return l === 1 ? c(0) : `${t}(${Array.from({ length: l }, (e, t) => c(t)).join(",")})`;
100
+ });
101
+ }
102
+ //#endregion
103
+ export { At as Break, at as Builder, Ut as ComputePass, Et as Continue, Ue as FIXED, $e as Fn, Ot as If, Ae as LEAF, wt as Let, St as Loop, le as MUTABLE, K as Node, $t as NodeMaterial, nn as NodePass, nt as ONCE, me as OP, Le as Program, ct as STMT, xt as ShaderClock, q as StorageBuffer, Dt as Switch, _e as UniformNode, kt as Var, Ct as VarNode, Tt as While, Vt as WorkgroupArray, Se as abs, Je as acos, Be as add, De as asin, Te as atan, G as atan2, sn as attribute, dt as bitangentWorld, jt as block, _t as bool, fe as builtin, ht as call, k as cameraFar, o as cameraNear, pt as cameraPosition, j as cast, u as ceil, c as clamp, x as color, Fe as constant, n as cos, Ne as cross, _ as degrees, y as deltaTime, C as discard, f as distance, ae as div, h as dot, D as dpdx, yt as dpdy, i as exp, F as exp2, re as float, N as floor, L as fract, Qt as frontFacing, te as fwidth, It as globalId, p as hdrTarget, en as inputColor, tn as inputDepth, Ze as instanceColor, Mt as instanceIndex, se as instanceMatrix, V as instanceUV, z as int, U as inverseSqrt, T as isMatrix, e as ivec2, xe as ivec3, st as ivec4, Ge as length, tt as linearColor, Me as linearDepth, zt as localId, Ht as localIndex, de as log, qe as log2, it as loop, ge as mat3, ze as mat4, Xt as materialColor, Jt as materialEmissive, Zt as materialMetalness, J as materialNormal, Yt as materialRoughness, ut as max, ye as min, we as mix, Xe as mod, He as modelMatrix, ke as mul, Ee as negate, ft as normalLocal, vt as normalView, pe as normalWorld, gt as normalize, A as not, s as oneMinus, mt as positionLocal, M as positionView, d as positionWorld, l as pow, S as projectionMatrix, Ie as radians, r as reflect, Pe as refract, v as resolution, b as round, w as sameEntries, ee as saturate, oe as scalarOf, g as screenCoordinate, O as screenUV, bt as select, a as sign, I as sin, ie as sizeOf, P as smoothstep, R as sqrt, ne as step, Lt as storage, Wt as storageBarrier, m as sub, Qe as tan, ce as tangentLocal, H as tangentWorld, B as tanh, Kt as texture, qt as texture3D, Nt as textureBarrier, Gt as textureCube, W as time, E as trunc, t as uint, be as uniform, ot as unique, We as uv, et as uvec2, je as uvec3, ue as uvec4, Ke as varying, rt as vec2, he as vec3, Re as vec4, lt as vecOf, ve as vertexColor, Ce as vertexIndex, Ye as viewDirection, Ve as viewMatrix, Oe as wgslFn, Bt as workgroup, Rt as workgroupBarrier, Ft as workgroupCount, Pt as workgroupId };
@@ -1,5 +1,5 @@
1
- import { T as e, b as t, o as n } from "./node-DzKv9CF2.js";
2
- import { n as r, t as i } from "./material-REzUrXtu.js";
1
+ import { T as e, b as t, o as n } from "./node-B6yoIC9V.js";
2
+ import { n as r, t as i } from "./material-CZ8V1FeA.js";
3
3
  import { MargoError as a } from "@margoengine/math/errors";
4
4
  //#region ../shared/light-terms.js
5
5
  var o = "((1-mix(max(dielectricF0.r,max(dielectricF0.g,dielectricF0.b)),dielectricF90,pow(1-vh,5.0)))*(1-metal)*base/3.14159265+d*g*fresnel/max(4*nl*nv,0.0001))", s = "var<private> margoDirectVisible:vec3f=vec3f(1);", c = /*@__PURE__*/ t("sunDirection", "vec3f"), l = /*@__PURE__*/ t("sunColor", "vec3f"), u = /*@__PURE__*/ t("sunVisibility", "vec3f"), d = /*@__PURE__*/ t("ambientLight", "vec3f"), f = /*@__PURE__*/ t("localLight", "vec3f"), p = /*@__PURE__*/ t("litColor", "vec3f");
package/dist/lighting.js CHANGED
@@ -1 +1 @@
1
- export { t as LightingMaterial, n as ambientLight, r as environment, i as litColor, a as localLight, o as sunColor, s as sunDirection, c as sunVisibility } from "./lighting-Dx8_RsBz.js";
1
+ export { t as LightingMaterial, n as ambientLight, r as environment, i as litColor, a as localLight, o as sunColor, s as sunDirection, c as sunVisibility } from "./lighting-JU9yQPfM.js";
@@ -1,5 +1,5 @@
1
1
  import { t as e } from "./errors-CsQwshHA.js";
2
- import { r as t, s as n, t as r } from "./raw-D0W8U3Qa.js";
2
+ import { r as t, s as n, t as r } from "./raw-0AYej3Ak.js";
3
3
  import { n as i, r as a, t as o } from "./preprocess-CWGWlBWQ.js";
4
4
  //#region src/glsl/presets.ts
5
5
  var s = [