@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.
- package/LICENSE +201 -201
- package/NOTICE +4 -4
- package/README.md +1920 -1771
- package/dist/attribute.d.ts +28 -0
- package/dist/black-hole.js +3 -3
- package/dist/clock-BLGNexlt.js +3 -3
- package/dist/{compute-D-BghbXj.js → compute-CXGG9qvI.js} +76 -70
- package/dist/compute-texture.js +3 -3
- package/dist/compute-volume.js +3 -3
- package/dist/compute.d.ts +8 -2
- package/dist/{control-DvjfV7R0.js → control-CFjkGPBk.js} +1 -1
- package/dist/deform.js +2 -2
- package/dist/editor-pass.js +17 -17
- package/dist/effects.js +2 -2
- package/dist/glsl-material.js +2 -2
- package/dist/glsl-pass.js +5 -5
- package/dist/glsl.js +18 -18
- package/dist/gpu-DQJk2xAv.js +55 -0
- package/dist/graph.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +103 -8
- package/dist/{lighting-Dx8_RsBz.js → lighting-JU9yQPfM.js} +2 -2
- package/dist/lighting.js +1 -1
- package/dist/{material-CU7p-Q8u.js → material-C6bpqlnE.js} +1 -1
- package/dist/{material-REzUrXtu.js → material-CZ8V1FeA.js} +95 -71
- package/dist/material.d.ts +9 -4
- package/dist/{node-DzKv9CF2.js → node-B6yoIC9V.js} +126 -126
- package/dist/node.d.ts +7 -1
- package/dist/noise.js +1 -1
- package/dist/pass.d.ts +1 -0
- package/dist/pass.js +24 -21
- package/dist/{post-DC62ZleD.js → post-DLpZ110L.js} +17 -17
- package/dist/{raw-D0W8U3Qa.js → raw-0AYej3Ak.js} +422 -273
- package/dist/raw.d.ts +125 -15
- package/dist/raw.js +1 -1
- package/dist/readback.js +13 -12
- package/dist/serialization.js +12 -12
- package/dist/shadertoy.js +6 -6
- package/dist/shared/caster.d.ts +159 -152
- package/dist/shared/fog.d.ts +33 -33
- package/dist/shared/fractal.d.ts +9 -9
- package/dist/shared/msaa.d.ts +30 -25
- package/dist/shared/stack.d.ts +22 -22
- package/dist/subgroups.js +4 -4
- package/dist/{texture-D6vy0bam.js → texture-BawKO_h9.js} +1 -1
- package/dist/texture-array.js +2 -2
- package/dist/utils.js +32 -32
- package/package.json +151 -151
- 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: () =>
|
|
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: () =>
|
|
27
|
+
Program: () => Bt,
|
|
28
28
|
STMT: () => 4,
|
|
29
|
-
UniformNode: () =>
|
|
30
|
-
abs: () =>
|
|
31
|
-
acos: () =>
|
|
32
|
-
add: () =>
|
|
33
|
-
asin: () =>
|
|
34
|
-
atan: () =>
|
|
35
|
-
atan2: () =>
|
|
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: () =>
|
|
45
|
-
clamp: () =>
|
|
44
|
+
ceil: () => ye,
|
|
45
|
+
clamp: () => q,
|
|
46
46
|
color: () => Qe,
|
|
47
47
|
constant: () => g,
|
|
48
|
-
cos: () =>
|
|
49
|
-
cross: () =>
|
|
50
|
-
degrees: () =>
|
|
51
|
-
deltaTime: () =>
|
|
48
|
+
cos: () => E,
|
|
49
|
+
cross: () => De,
|
|
50
|
+
degrees: () => V,
|
|
51
|
+
deltaTime: () => kt,
|
|
52
52
|
discard: () => Ie,
|
|
53
|
-
distance: () =>
|
|
54
|
-
div: () =>
|
|
55
|
-
dot: () =>
|
|
56
|
-
dpdx: () =>
|
|
57
|
-
dpdy: () =>
|
|
58
|
-
exp: () =>
|
|
59
|
-
exp2: () =>
|
|
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: () =>
|
|
62
|
-
fract: () =>
|
|
63
|
-
fwidth: () =>
|
|
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: () =>
|
|
69
|
+
inverseSqrt: () => L,
|
|
70
70
|
isMatrix: () => p,
|
|
71
71
|
ivec2: () => We,
|
|
72
72
|
ivec3: () => Ge,
|
|
73
73
|
ivec4: () => Ke,
|
|
74
|
-
length: () =>
|
|
74
|
+
length: () => Oe,
|
|
75
75
|
linearColor: () => X,
|
|
76
76
|
linearDepth: () => pt,
|
|
77
|
-
log: () =>
|
|
78
|
-
log2: () =>
|
|
79
|
-
loop: () =>
|
|
77
|
+
log: () => P,
|
|
78
|
+
log2: () => F,
|
|
79
|
+
loop: () => Nt,
|
|
80
80
|
mat3: () => Xe,
|
|
81
81
|
mat4: () => Ze,
|
|
82
|
-
max: () =>
|
|
83
|
-
min: () =>
|
|
84
|
-
mix: () =>
|
|
85
|
-
mod: () =>
|
|
82
|
+
max: () => G,
|
|
83
|
+
min: () => W,
|
|
84
|
+
mix: () => Te,
|
|
85
|
+
mod: () => he,
|
|
86
86
|
modelMatrix: () => gt,
|
|
87
|
-
mul: () =>
|
|
87
|
+
mul: () => pe,
|
|
88
88
|
negate: () => Ne,
|
|
89
89
|
normalLocal: () => ot,
|
|
90
90
|
normalView: () => lt,
|
|
91
91
|
normalWorld: () => st,
|
|
92
|
-
normalize: () =>
|
|
92
|
+
normalize: () => z,
|
|
93
93
|
not: () => Pe,
|
|
94
|
-
oneMinus: () =>
|
|
94
|
+
oneMinus: () => Me,
|
|
95
95
|
positionLocal: () => it,
|
|
96
96
|
positionView: () => ct,
|
|
97
97
|
positionWorld: () => at,
|
|
98
|
-
pow: () =>
|
|
98
|
+
pow: () => K,
|
|
99
99
|
projectionMatrix: () => vt,
|
|
100
|
-
radians: () =>
|
|
101
|
-
reflect: () =>
|
|
102
|
-
refract: () =>
|
|
103
|
-
resolution: () =>
|
|
104
|
-
round: () =>
|
|
105
|
-
sameEntries: () =>
|
|
106
|
-
saturate: () =>
|
|
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: () =>
|
|
112
|
-
sin: () =>
|
|
111
|
+
sign: () => _e,
|
|
112
|
+
sin: () => T,
|
|
113
113
|
sizeOf: () => f,
|
|
114
|
-
smoothstep: () =>
|
|
115
|
-
sqrt: () =>
|
|
116
|
-
step: () =>
|
|
117
|
-
sub: () =>
|
|
118
|
-
tan: () =>
|
|
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: () =>
|
|
122
|
-
time: () =>
|
|
123
|
-
trunc: () =>
|
|
121
|
+
tanh: () => j,
|
|
122
|
+
time: () => Ot,
|
|
123
|
+
trunc: () => C,
|
|
124
124
|
uint: () => ze,
|
|
125
|
-
uniform: () =>
|
|
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: () =>
|
|
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: () =>
|
|
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
|
-
},
|
|
179
|
+
}, le = (e) => (...t) => {
|
|
180
180
|
let n = y(e, t);
|
|
181
181
|
return b(e, n, d(n[0].type), e);
|
|
182
|
-
},
|
|
183
|
-
function
|
|
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
|
|
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"),
|
|
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
|
|
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
|
|
260
|
+
return S(t, this, e, !0);
|
|
261
261
|
};
|
|
262
262
|
var tt = {
|
|
263
|
-
abs:
|
|
264
|
-
sign:
|
|
265
|
-
floor:
|
|
266
|
-
ceil:
|
|
267
|
-
round:
|
|
268
|
-
trunc:
|
|
269
|
-
fract:
|
|
270
|
-
sin:
|
|
271
|
-
cos:
|
|
272
|
-
tan:
|
|
273
|
-
asin:
|
|
274
|
-
acos:
|
|
275
|
-
atan:
|
|
276
|
-
tanh:
|
|
277
|
-
exp:
|
|
278
|
-
exp2:
|
|
279
|
-
log:
|
|
280
|
-
log2:
|
|
281
|
-
sqrt:
|
|
282
|
-
inverseSqrt:
|
|
283
|
-
saturate:
|
|
284
|
-
normalize:
|
|
285
|
-
radians:
|
|
286
|
-
degrees:
|
|
287
|
-
dpdx:
|
|
288
|
-
dpdy:
|
|
289
|
-
fwidth:
|
|
290
|
-
min:
|
|
291
|
-
max:
|
|
292
|
-
pow:
|
|
293
|
-
clamp:
|
|
294
|
-
step:
|
|
295
|
-
mix:
|
|
296
|
-
reflect:
|
|
297
|
-
cross:
|
|
298
|
-
length:
|
|
299
|
-
distance:
|
|
300
|
-
dot:
|
|
301
|
-
oneMinus:
|
|
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"),
|
|
318
|
-
function
|
|
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
|
|
322
|
-
function
|
|
323
|
-
let r = v(t), i =
|
|
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
|
|
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) =>
|
|
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
|
|
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
|
|
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
|
|
378
|
+
function Lt(e, t = {}) {
|
|
379
379
|
let n = typeof e == "string" ? 3 : typeof e == "number" ? 1 : e.length;
|
|
380
|
-
return new
|
|
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
|
|
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],
|
|
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
|
|
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 +
|
|
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 +
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
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,
|
|
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
|
|
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-
|
|
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
|
|
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-
|
|
5
|
-
import {
|
|
6
|
-
import { n as d
|
|
7
|
-
import { t as p } from "./
|
|
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,
|
|
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
|
-
},
|
|
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 (
|
|
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(
|
|
70
|
-
a = [...n.lines, ...n.values.map((e, t) => `${
|
|
71
|
-
}), this.patchedOutputs = /* @__PURE__ */ new Map(), this.lines = a, this.declared = r.map(
|
|
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
|
-
},
|
|
85
|
-
static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("
|
|
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:" +
|
|
91
|
-
this.names.forEach(
|
|
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((
|
|
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
|
|
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
|
|
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 =
|
|
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 {
|
|
239
|
+
export { T as PassMaterial, D as ScenePass, O as sceneColor };
|