evotars 0.0.11 → 0.0.13
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/dist/CanvasPool-323z5Bgc.js +46 -0
- package/dist/SharedSystems-CpNLwPlr.js +2134 -0
- package/dist/WebGLRenderer-8_UYFwzF.js +2564 -0
- package/dist/WebGPURenderer-D3yK12c3.js +1561 -0
- package/dist/browserAll--tlJ0wmH.js +1968 -0
- package/dist/colorToUniform-ZnVvWd8z.js +1308 -0
- package/dist/evotars.js +9 -26282
- package/dist/evotars.umd.cjs +902 -1069
- package/dist/getBatchSamplersUniformGroup-DIigPB-W.js +16 -0
- package/dist/index-RgERw5ms.js +14288 -0
- package/dist/index.d.ts +236 -5
- package/dist/webworkerAll-DxpydbmF.js +2661 -0
- package/package.json +3 -3
|
@@ -0,0 +1,1308 @@
|
|
|
1
|
+
import { k as mt, u as K, a as dt, c as T, i as ht, j as pt, n as X, w as gt, m as N } from "./index-RgERw5ms.js";
|
|
2
|
+
const C = /* @__PURE__ */ Object.create(null), Y = /* @__PURE__ */ Object.create(null);
|
|
3
|
+
function W(o, t) {
|
|
4
|
+
let e = Y[o];
|
|
5
|
+
return e === void 0 && (C[t] === void 0 && (C[t] = 1), Y[o] = e = C[t]++), e;
|
|
6
|
+
}
|
|
7
|
+
let M;
|
|
8
|
+
function xt() {
|
|
9
|
+
if (!M) {
|
|
10
|
+
M = "mediump";
|
|
11
|
+
const o = mt();
|
|
12
|
+
o && o.getShaderPrecisionFormat && (M = o.getShaderPrecisionFormat(o.FRAGMENT_SHADER, o.HIGH_FLOAT).precision ? "highp" : "mediump");
|
|
13
|
+
}
|
|
14
|
+
return M;
|
|
15
|
+
}
|
|
16
|
+
function vt(o, t, e) {
|
|
17
|
+
return t ? o : e ? (o = o.replace("out vec4 finalColor;", ""), `
|
|
18
|
+
|
|
19
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
20
|
+
#define in varying
|
|
21
|
+
#define finalColor gl_FragColor
|
|
22
|
+
#define texture texture2D
|
|
23
|
+
#endif
|
|
24
|
+
${o}
|
|
25
|
+
`) : `
|
|
26
|
+
|
|
27
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
28
|
+
#define in attribute
|
|
29
|
+
#define out varying
|
|
30
|
+
#endif
|
|
31
|
+
${o}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
function bt(o, t, e) {
|
|
35
|
+
const r = e ? t.maxSupportedFragmentPrecision : t.maxSupportedVertexPrecision;
|
|
36
|
+
if (o.substring(0, 9) !== "precision") {
|
|
37
|
+
let n = e ? t.requestedFragmentPrecision : t.requestedVertexPrecision;
|
|
38
|
+
return n === "highp" && r !== "highp" && (n = "mediump"), `precision ${n} float;
|
|
39
|
+
${o}`;
|
|
40
|
+
} else if (r !== "highp" && o.substring(0, 15) === "precision highp")
|
|
41
|
+
return o.replace("precision highp", "precision mediump");
|
|
42
|
+
return o;
|
|
43
|
+
}
|
|
44
|
+
function Pt(o, t) {
|
|
45
|
+
return t ? `#version 300 es
|
|
46
|
+
${o}` : o;
|
|
47
|
+
}
|
|
48
|
+
const yt = {}, _t = {};
|
|
49
|
+
function Gt(o, { name: t = "pixi-program" }, e = !0) {
|
|
50
|
+
t = t.replace(/\s+/g, "-"), t += e ? "-fragment" : "-vertex";
|
|
51
|
+
const r = e ? yt : _t;
|
|
52
|
+
return r[t] ? (r[t]++, t += `-${r[t]}`) : r[t] = 1, o.indexOf("#define SHADER_NAME") !== -1 ? o : `${`#define SHADER_NAME ${t}`}
|
|
53
|
+
${o}`;
|
|
54
|
+
}
|
|
55
|
+
function Mt(o, t) {
|
|
56
|
+
return t ? o.replace("#version 300 es", "") : o;
|
|
57
|
+
}
|
|
58
|
+
const $ = {
|
|
59
|
+
// strips any version headers..
|
|
60
|
+
stripVersion: Mt,
|
|
61
|
+
// adds precision string if not already present
|
|
62
|
+
ensurePrecision: bt,
|
|
63
|
+
// add some defines if WebGL1 to make it more compatible with WebGL2 shaders
|
|
64
|
+
addProgramDefines: vt,
|
|
65
|
+
// add the program name to the shader
|
|
66
|
+
setProgramName: Gt,
|
|
67
|
+
// add the version string to the shader header
|
|
68
|
+
insertVersion: Pt
|
|
69
|
+
}, U = /* @__PURE__ */ Object.create(null), ot = class L {
|
|
70
|
+
/**
|
|
71
|
+
* Creates a shiny new GlProgram. Used by WebGL renderer.
|
|
72
|
+
* @param options - The options for the program.
|
|
73
|
+
*/
|
|
74
|
+
constructor(t) {
|
|
75
|
+
t = { ...L.defaultOptions, ...t };
|
|
76
|
+
const e = t.fragment.indexOf("#version 300 es") !== -1, r = {
|
|
77
|
+
stripVersion: e,
|
|
78
|
+
ensurePrecision: {
|
|
79
|
+
requestedFragmentPrecision: t.preferredFragmentPrecision,
|
|
80
|
+
requestedVertexPrecision: t.preferredVertexPrecision,
|
|
81
|
+
maxSupportedVertexPrecision: "highp",
|
|
82
|
+
maxSupportedFragmentPrecision: xt()
|
|
83
|
+
},
|
|
84
|
+
setProgramName: {
|
|
85
|
+
name: t.name
|
|
86
|
+
},
|
|
87
|
+
addProgramDefines: e,
|
|
88
|
+
insertVersion: e
|
|
89
|
+
};
|
|
90
|
+
let n = t.fragment, s = t.vertex;
|
|
91
|
+
Object.keys($).forEach((a) => {
|
|
92
|
+
const i = r[a];
|
|
93
|
+
n = $[a](n, i, !0), s = $[a](s, i, !1);
|
|
94
|
+
}), this.fragment = n, this.vertex = s, this._key = W(`${this.vertex}:${this.fragment}`, "gl-program");
|
|
95
|
+
}
|
|
96
|
+
/** destroys the program */
|
|
97
|
+
destroy() {
|
|
98
|
+
this.fragment = null, this.vertex = null, this._attributeData = null, this._uniformData = null, this._uniformBlockData = null, this.transformFeedbackVaryings = null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Helper function that creates a program for a given source.
|
|
102
|
+
* It will check the program cache if the program has already been created.
|
|
103
|
+
* If it has that one will be returned, if not a new one will be created and cached.
|
|
104
|
+
* @param options - The options for the program.
|
|
105
|
+
* @returns A program using the same source
|
|
106
|
+
*/
|
|
107
|
+
static from(t) {
|
|
108
|
+
const e = `${t.vertex}:${t.fragment}`;
|
|
109
|
+
return U[e] || (U[e] = new L(t)), U[e];
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
ot.defaultOptions = {
|
|
113
|
+
preferredVertexPrecision: "highp",
|
|
114
|
+
preferredFragmentPrecision: "mediump"
|
|
115
|
+
};
|
|
116
|
+
let nt = ot;
|
|
117
|
+
const q = {
|
|
118
|
+
uint8x2: { size: 2, stride: 2, normalised: !1 },
|
|
119
|
+
uint8x4: { size: 4, stride: 4, normalised: !1 },
|
|
120
|
+
sint8x2: { size: 2, stride: 2, normalised: !1 },
|
|
121
|
+
sint8x4: { size: 4, stride: 4, normalised: !1 },
|
|
122
|
+
unorm8x2: { size: 2, stride: 2, normalised: !0 },
|
|
123
|
+
unorm8x4: { size: 4, stride: 4, normalised: !0 },
|
|
124
|
+
snorm8x2: { size: 2, stride: 2, normalised: !0 },
|
|
125
|
+
snorm8x4: { size: 4, stride: 4, normalised: !0 },
|
|
126
|
+
uint16x2: { size: 2, stride: 4, normalised: !1 },
|
|
127
|
+
uint16x4: { size: 4, stride: 8, normalised: !1 },
|
|
128
|
+
sint16x2: { size: 2, stride: 4, normalised: !1 },
|
|
129
|
+
sint16x4: { size: 4, stride: 8, normalised: !1 },
|
|
130
|
+
unorm16x2: { size: 2, stride: 4, normalised: !0 },
|
|
131
|
+
unorm16x4: { size: 4, stride: 8, normalised: !0 },
|
|
132
|
+
snorm16x2: { size: 2, stride: 4, normalised: !0 },
|
|
133
|
+
snorm16x4: { size: 4, stride: 8, normalised: !0 },
|
|
134
|
+
float16x2: { size: 2, stride: 4, normalised: !1 },
|
|
135
|
+
float16x4: { size: 4, stride: 8, normalised: !1 },
|
|
136
|
+
float32: { size: 1, stride: 4, normalised: !1 },
|
|
137
|
+
float32x2: { size: 2, stride: 8, normalised: !1 },
|
|
138
|
+
float32x3: { size: 3, stride: 12, normalised: !1 },
|
|
139
|
+
float32x4: { size: 4, stride: 16, normalised: !1 },
|
|
140
|
+
uint32: { size: 1, stride: 4, normalised: !1 },
|
|
141
|
+
uint32x2: { size: 2, stride: 8, normalised: !1 },
|
|
142
|
+
uint32x3: { size: 3, stride: 12, normalised: !1 },
|
|
143
|
+
uint32x4: { size: 4, stride: 16, normalised: !1 },
|
|
144
|
+
sint32: { size: 1, stride: 4, normalised: !1 },
|
|
145
|
+
sint32x2: { size: 2, stride: 8, normalised: !1 },
|
|
146
|
+
sint32x3: { size: 3, stride: 12, normalised: !1 },
|
|
147
|
+
sint32x4: { size: 4, stride: 16, normalised: !1 }
|
|
148
|
+
};
|
|
149
|
+
function St(o) {
|
|
150
|
+
return q[o] ?? q.float32;
|
|
151
|
+
}
|
|
152
|
+
const Tt = {
|
|
153
|
+
f32: "float32",
|
|
154
|
+
"vec2<f32>": "float32x2",
|
|
155
|
+
"vec3<f32>": "float32x3",
|
|
156
|
+
"vec4<f32>": "float32x4",
|
|
157
|
+
vec2f: "float32x2",
|
|
158
|
+
vec3f: "float32x3",
|
|
159
|
+
vec4f: "float32x4",
|
|
160
|
+
i32: "sint32",
|
|
161
|
+
"vec2<i32>": "sint32x2",
|
|
162
|
+
"vec3<i32>": "sint32x3",
|
|
163
|
+
"vec4<i32>": "sint32x4",
|
|
164
|
+
u32: "uint32",
|
|
165
|
+
"vec2<u32>": "uint32x2",
|
|
166
|
+
"vec3<u32>": "uint32x3",
|
|
167
|
+
"vec4<u32>": "uint32x4",
|
|
168
|
+
bool: "uint32",
|
|
169
|
+
"vec2<bool>": "uint32x2",
|
|
170
|
+
"vec3<bool>": "uint32x3",
|
|
171
|
+
"vec4<bool>": "uint32x4"
|
|
172
|
+
};
|
|
173
|
+
function Ct({ source: o, entryPoint: t }) {
|
|
174
|
+
const e = {}, r = o.indexOf(`fn ${t}`);
|
|
175
|
+
if (r !== -1) {
|
|
176
|
+
const n = o.indexOf("->", r);
|
|
177
|
+
if (n !== -1) {
|
|
178
|
+
const s = o.substring(r, n), a = /@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|$)/g;
|
|
179
|
+
let i;
|
|
180
|
+
for (; (i = a.exec(s)) !== null; ) {
|
|
181
|
+
const u = Tt[i[3]] ?? "float32";
|
|
182
|
+
e[i[2]] = {
|
|
183
|
+
location: parseInt(i[1], 10),
|
|
184
|
+
format: u,
|
|
185
|
+
stride: St(u).stride,
|
|
186
|
+
offset: 0,
|
|
187
|
+
instance: !1,
|
|
188
|
+
start: 0
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return e;
|
|
194
|
+
}
|
|
195
|
+
function A(o) {
|
|
196
|
+
var f, d;
|
|
197
|
+
const t = /(^|[^/])@(group|binding)\(\d+\)[^;]+;/g, e = /@group\((\d+)\)/, r = /@binding\((\d+)\)/, n = /var(<[^>]+>)? (\w+)/, s = /:\s*(\w+)/, a = /struct\s+(\w+)\s*{([^}]+)}/g, i = /(\w+)\s*:\s*([\w\<\>]+)/g, u = /struct\s+(\w+)/, l = (f = o.match(t)) == null ? void 0 : f.map((m) => ({
|
|
198
|
+
group: parseInt(m.match(e)[1], 10),
|
|
199
|
+
binding: parseInt(m.match(r)[1], 10),
|
|
200
|
+
name: m.match(n)[2],
|
|
201
|
+
isUniform: m.match(n)[1] === "<uniform>",
|
|
202
|
+
type: m.match(s)[1]
|
|
203
|
+
}));
|
|
204
|
+
if (!l)
|
|
205
|
+
return {
|
|
206
|
+
groups: [],
|
|
207
|
+
structs: []
|
|
208
|
+
};
|
|
209
|
+
const c = ((d = o.match(a)) == null ? void 0 : d.map((m) => {
|
|
210
|
+
const p = m.match(u)[1], x = m.match(i).reduce((v, b) => {
|
|
211
|
+
const [P, h] = b.split(":");
|
|
212
|
+
return v[P.trim()] = h.trim(), v;
|
|
213
|
+
}, {});
|
|
214
|
+
return x ? { name: p, members: x } : null;
|
|
215
|
+
}).filter(({ name: m }) => l.some((p) => p.type === m))) ?? [];
|
|
216
|
+
return {
|
|
217
|
+
groups: l,
|
|
218
|
+
structs: c
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
var y = /* @__PURE__ */ ((o) => (o[o.VERTEX = 1] = "VERTEX", o[o.FRAGMENT = 2] = "FRAGMENT", o[o.COMPUTE = 4] = "COMPUTE", o))(y || {});
|
|
222
|
+
function $t({ groups: o }) {
|
|
223
|
+
const t = [];
|
|
224
|
+
for (let e = 0; e < o.length; e++) {
|
|
225
|
+
const r = o[e];
|
|
226
|
+
t[r.group] || (t[r.group] = []), r.isUniform ? t[r.group].push({
|
|
227
|
+
binding: r.binding,
|
|
228
|
+
visibility: y.VERTEX | y.FRAGMENT,
|
|
229
|
+
buffer: {
|
|
230
|
+
type: "uniform"
|
|
231
|
+
}
|
|
232
|
+
}) : r.type === "sampler" ? t[r.group].push({
|
|
233
|
+
binding: r.binding,
|
|
234
|
+
visibility: y.FRAGMENT,
|
|
235
|
+
sampler: {
|
|
236
|
+
type: "filtering"
|
|
237
|
+
}
|
|
238
|
+
}) : r.type === "texture_2d" && t[r.group].push({
|
|
239
|
+
binding: r.binding,
|
|
240
|
+
visibility: y.FRAGMENT,
|
|
241
|
+
texture: {
|
|
242
|
+
sampleType: "float",
|
|
243
|
+
viewDimension: "2d",
|
|
244
|
+
multisampled: !1
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return t;
|
|
249
|
+
}
|
|
250
|
+
function Ut({ groups: o }) {
|
|
251
|
+
const t = [];
|
|
252
|
+
for (let e = 0; e < o.length; e++) {
|
|
253
|
+
const r = o[e];
|
|
254
|
+
t[r.group] || (t[r.group] = {}), t[r.group][r.name] = r.binding;
|
|
255
|
+
}
|
|
256
|
+
return t;
|
|
257
|
+
}
|
|
258
|
+
function At(o, t) {
|
|
259
|
+
const e = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), n = [...o.structs, ...t.structs].filter((a) => e.has(a.name) ? !1 : (e.add(a.name), !0)), s = [...o.groups, ...t.groups].filter((a) => {
|
|
260
|
+
const i = `${a.name}-${a.binding}`;
|
|
261
|
+
return r.has(i) ? !1 : (r.add(i), !0);
|
|
262
|
+
});
|
|
263
|
+
return { structs: n, groups: s };
|
|
264
|
+
}
|
|
265
|
+
const E = /* @__PURE__ */ Object.create(null);
|
|
266
|
+
class S {
|
|
267
|
+
/**
|
|
268
|
+
* Create a new GpuProgram
|
|
269
|
+
* @param options - The options for the gpu program
|
|
270
|
+
*/
|
|
271
|
+
constructor(t) {
|
|
272
|
+
var i, u;
|
|
273
|
+
this._layoutKey = 0;
|
|
274
|
+
const { fragment: e, vertex: r, layout: n, gpuLayout: s, name: a } = t;
|
|
275
|
+
if (this.name = a, this.fragment = e, this.vertex = r, e.source === r.source) {
|
|
276
|
+
const l = A(e.source);
|
|
277
|
+
this.structsAndGroups = l;
|
|
278
|
+
} else {
|
|
279
|
+
const l = A(r.source), c = A(e.source);
|
|
280
|
+
this.structsAndGroups = At(l, c);
|
|
281
|
+
}
|
|
282
|
+
this.layout = n ?? Ut(this.structsAndGroups), this.gpuLayout = s ?? $t(this.structsAndGroups), this.autoAssignGlobalUniforms = ((i = this.layout[0]) == null ? void 0 : i.globalUniforms) !== void 0, this.autoAssignLocalUniforms = ((u = this.layout[1]) == null ? void 0 : u.localUniforms) !== void 0, this._generateProgramKey();
|
|
283
|
+
}
|
|
284
|
+
// TODO maker this pure
|
|
285
|
+
_generateProgramKey() {
|
|
286
|
+
const { vertex: t, fragment: e } = this, r = t.source + e.source + t.entryPoint + e.entryPoint;
|
|
287
|
+
this._layoutKey = W(r, "program");
|
|
288
|
+
}
|
|
289
|
+
get attributeData() {
|
|
290
|
+
return this._attributeData ?? (this._attributeData = Ct(this.vertex)), this._attributeData;
|
|
291
|
+
}
|
|
292
|
+
/** destroys the program */
|
|
293
|
+
destroy() {
|
|
294
|
+
this.gpuLayout = null, this.layout = null, this.structsAndGroups = null, this.fragment = null, this.vertex = null;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Helper function that creates a program for a given source.
|
|
298
|
+
* It will check the program cache if the program has already been created.
|
|
299
|
+
* If it has that one will be returned, if not a new one will be created and cached.
|
|
300
|
+
* @param options - The options for the program.
|
|
301
|
+
* @returns A program using the same source
|
|
302
|
+
*/
|
|
303
|
+
static from(t) {
|
|
304
|
+
const e = `${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;
|
|
305
|
+
return E[e] || (E[e] = new S(t)), E[e];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const st = [
|
|
309
|
+
"f32",
|
|
310
|
+
"i32",
|
|
311
|
+
"vec2<f32>",
|
|
312
|
+
"vec3<f32>",
|
|
313
|
+
"vec4<f32>",
|
|
314
|
+
"mat2x2<f32>",
|
|
315
|
+
"mat3x3<f32>",
|
|
316
|
+
"mat4x4<f32>",
|
|
317
|
+
"mat3x2<f32>",
|
|
318
|
+
"mat4x2<f32>",
|
|
319
|
+
"mat2x3<f32>",
|
|
320
|
+
"mat4x3<f32>",
|
|
321
|
+
"mat2x4<f32>",
|
|
322
|
+
"mat3x4<f32>"
|
|
323
|
+
], Et = st.reduce((o, t) => (o[t] = !0, o), {});
|
|
324
|
+
function wt(o, t) {
|
|
325
|
+
switch (o) {
|
|
326
|
+
case "f32":
|
|
327
|
+
return 0;
|
|
328
|
+
case "vec2<f32>":
|
|
329
|
+
return new Float32Array(2 * t);
|
|
330
|
+
case "vec3<f32>":
|
|
331
|
+
return new Float32Array(3 * t);
|
|
332
|
+
case "vec4<f32>":
|
|
333
|
+
return new Float32Array(4 * t);
|
|
334
|
+
case "mat2x2<f32>":
|
|
335
|
+
return new Float32Array([
|
|
336
|
+
1,
|
|
337
|
+
0,
|
|
338
|
+
0,
|
|
339
|
+
1
|
|
340
|
+
]);
|
|
341
|
+
case "mat3x3<f32>":
|
|
342
|
+
return new Float32Array([
|
|
343
|
+
1,
|
|
344
|
+
0,
|
|
345
|
+
0,
|
|
346
|
+
0,
|
|
347
|
+
1,
|
|
348
|
+
0,
|
|
349
|
+
0,
|
|
350
|
+
0,
|
|
351
|
+
1
|
|
352
|
+
]);
|
|
353
|
+
case "mat4x4<f32>":
|
|
354
|
+
return new Float32Array([
|
|
355
|
+
1,
|
|
356
|
+
0,
|
|
357
|
+
0,
|
|
358
|
+
0,
|
|
359
|
+
0,
|
|
360
|
+
1,
|
|
361
|
+
0,
|
|
362
|
+
0,
|
|
363
|
+
0,
|
|
364
|
+
0,
|
|
365
|
+
1,
|
|
366
|
+
0,
|
|
367
|
+
0,
|
|
368
|
+
0,
|
|
369
|
+
0,
|
|
370
|
+
1
|
|
371
|
+
]);
|
|
372
|
+
}
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
const it = class at {
|
|
376
|
+
/**
|
|
377
|
+
* Create a new Uniform group
|
|
378
|
+
* @param uniformStructures - The structures of the uniform group
|
|
379
|
+
* @param options - The optional parameters of this uniform group
|
|
380
|
+
*/
|
|
381
|
+
constructor(t, e) {
|
|
382
|
+
this._touched = 0, this.uid = K("uniform"), this._resourceType = "uniformGroup", this._resourceId = K("resource"), this.isUniformGroup = !0, this._dirtyId = 0, this.destroyed = !1, e = { ...at.defaultOptions, ...e }, this.uniformStructures = t;
|
|
383
|
+
const r = {};
|
|
384
|
+
for (const n in t) {
|
|
385
|
+
const s = t[n];
|
|
386
|
+
if (s.name = n, s.size = s.size ?? 1, !Et[s.type])
|
|
387
|
+
throw new Error(`Uniform type ${s.type} is not supported. Supported uniform types are: ${st.join(", ")}`);
|
|
388
|
+
s.value ?? (s.value = wt(s.type, s.size)), r[n] = s.value;
|
|
389
|
+
}
|
|
390
|
+
this.uniforms = r, this._dirtyId = 1, this.ubo = e.ubo, this.isStatic = e.isStatic, this._signature = W(Object.keys(r).map(
|
|
391
|
+
(n) => `${n}-${t[n].type}`
|
|
392
|
+
).join("-"), "uniform-group");
|
|
393
|
+
}
|
|
394
|
+
/** Call this if you want the uniform groups data to be uploaded to the GPU only useful if `isStatic` is true. */
|
|
395
|
+
update() {
|
|
396
|
+
this._dirtyId++;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
it.defaultOptions = {
|
|
400
|
+
/** if true the UniformGroup is handled as an Uniform buffer object. */
|
|
401
|
+
ubo: !1,
|
|
402
|
+
/** if true, then you are responsible for when the data is uploaded to the GPU by calling `update()` */
|
|
403
|
+
isStatic: !1
|
|
404
|
+
};
|
|
405
|
+
let Ft = it;
|
|
406
|
+
var H = /* @__PURE__ */ ((o) => (o[o.WEBGL = 1] = "WEBGL", o[o.WEBGPU = 2] = "WEBGPU", o[o.BOTH = 3] = "BOTH", o))(H || {});
|
|
407
|
+
class ut extends dt {
|
|
408
|
+
constructor(t) {
|
|
409
|
+
super(), this._uniformBindMap = /* @__PURE__ */ Object.create(null), this._ownedBindGroups = [];
|
|
410
|
+
let {
|
|
411
|
+
gpuProgram: e,
|
|
412
|
+
glProgram: r,
|
|
413
|
+
groups: n,
|
|
414
|
+
resources: s,
|
|
415
|
+
compatibleRenderers: a,
|
|
416
|
+
groupMap: i
|
|
417
|
+
} = t;
|
|
418
|
+
this.gpuProgram = e, this.glProgram = r, a === void 0 && (a = 0, e && (a |= H.WEBGPU), r && (a |= H.WEBGL)), this.compatibleRenderers = a;
|
|
419
|
+
const u = {};
|
|
420
|
+
if (!s && !n && (s = {}), s && n)
|
|
421
|
+
throw new Error("[Shader] Cannot have both resources and groups");
|
|
422
|
+
if (!e && n && !i)
|
|
423
|
+
throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");
|
|
424
|
+
if (!e && n && i)
|
|
425
|
+
for (const l in i)
|
|
426
|
+
for (const c in i[l]) {
|
|
427
|
+
const f = i[l][c];
|
|
428
|
+
u[f] = {
|
|
429
|
+
group: l,
|
|
430
|
+
binding: c,
|
|
431
|
+
name: f
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
else if (e && n && !i) {
|
|
435
|
+
const l = e.structsAndGroups.groups;
|
|
436
|
+
i = {}, l.forEach((c) => {
|
|
437
|
+
i[c.group] = i[c.group] || {}, i[c.group][c.binding] = c.name, u[c.name] = c;
|
|
438
|
+
});
|
|
439
|
+
} else if (s) {
|
|
440
|
+
if (e) {
|
|
441
|
+
const l = e.structsAndGroups.groups;
|
|
442
|
+
i = {}, l.forEach((c) => {
|
|
443
|
+
i[c.group] = i[c.group] || {}, i[c.group][c.binding] = c.name, u[c.name] = c;
|
|
444
|
+
});
|
|
445
|
+
} else {
|
|
446
|
+
i = {}, n = {
|
|
447
|
+
99: new T()
|
|
448
|
+
}, this._ownedBindGroups.push(n[99]);
|
|
449
|
+
let l = 0;
|
|
450
|
+
for (const c in s)
|
|
451
|
+
u[c] = { group: 99, binding: l, name: c }, i[99] = i[99] || {}, i[99][l] = c, l++;
|
|
452
|
+
}
|
|
453
|
+
n = {};
|
|
454
|
+
for (const l in s) {
|
|
455
|
+
const c = l;
|
|
456
|
+
let f = s[l];
|
|
457
|
+
!f.source && !f._resourceType && (f = new Ft(f));
|
|
458
|
+
const d = u[c];
|
|
459
|
+
d && (n[d.group] || (n[d.group] = new T(), this._ownedBindGroups.push(n[d.group])), n[d.group].setResource(f, d.binding));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
this.groups = n, this._uniformBindMap = i, this.resources = this._buildResourceAccessor(n, u);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Sometimes a resource group will be provided later (for example global uniforms)
|
|
466
|
+
* In such cases, this method can be used to let the shader know about the group.
|
|
467
|
+
* @param name - the name of the resource group
|
|
468
|
+
* @param groupIndex - the index of the group (should match the webGPU shader group location)
|
|
469
|
+
* @param bindIndex - the index of the bind point (should match the webGPU shader bind point)
|
|
470
|
+
*/
|
|
471
|
+
addResource(t, e, r) {
|
|
472
|
+
var n, s;
|
|
473
|
+
(n = this._uniformBindMap)[e] || (n[e] = {}), (s = this._uniformBindMap[e])[r] || (s[r] = t), this.groups[e] || (this.groups[e] = new T(), this._ownedBindGroups.push(this.groups[e]));
|
|
474
|
+
}
|
|
475
|
+
_buildResourceAccessor(t, e) {
|
|
476
|
+
const r = {};
|
|
477
|
+
for (const n in e) {
|
|
478
|
+
const s = e[n];
|
|
479
|
+
Object.defineProperty(r, s.name, {
|
|
480
|
+
get() {
|
|
481
|
+
return t[s.group].getResource(s.binding);
|
|
482
|
+
},
|
|
483
|
+
set(a) {
|
|
484
|
+
t[s.group].setResource(a, s.binding);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return r;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Use to destroy the shader when its not longer needed.
|
|
492
|
+
* It will destroy the resources and remove listeners.
|
|
493
|
+
* @param destroyPrograms - if the programs should be destroyed as well.
|
|
494
|
+
* Make sure its not being used by other shaders!
|
|
495
|
+
*/
|
|
496
|
+
destroy(t = !1) {
|
|
497
|
+
var e, r;
|
|
498
|
+
this.emit("destroy", this), t && ((e = this.gpuProgram) == null || e.destroy(), (r = this.glProgram) == null || r.destroy()), this.gpuProgram = null, this.glProgram = null, this.removeAllListeners(), this._uniformBindMap = null, this._ownedBindGroups.forEach((n) => {
|
|
499
|
+
n.destroy();
|
|
500
|
+
}), this._ownedBindGroups = null, this.resources = null, this.groups = null;
|
|
501
|
+
}
|
|
502
|
+
static from(t) {
|
|
503
|
+
const { gpu: e, gl: r, ...n } = t;
|
|
504
|
+
let s, a;
|
|
505
|
+
return e && (s = S.from(e)), r && (a = nt.from(r)), new ut({
|
|
506
|
+
gpuProgram: s,
|
|
507
|
+
glProgram: a,
|
|
508
|
+
...n
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const zt = {
|
|
513
|
+
normal: 0,
|
|
514
|
+
add: 1,
|
|
515
|
+
multiply: 2,
|
|
516
|
+
screen: 3,
|
|
517
|
+
overlay: 4,
|
|
518
|
+
erase: 5,
|
|
519
|
+
"normal-npm": 6,
|
|
520
|
+
"add-npm": 7,
|
|
521
|
+
"screen-npm": 8
|
|
522
|
+
}, w = 0, F = 1, z = 2, O = 3, R = 4, B = 5, V = class ct {
|
|
523
|
+
constructor() {
|
|
524
|
+
this.data = 0, this.blendMode = "normal", this.polygonOffset = 0, this.blend = !0, this.depthMask = !0;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Activates blending of the computed fragment color values.
|
|
528
|
+
* @default true
|
|
529
|
+
*/
|
|
530
|
+
get blend() {
|
|
531
|
+
return !!(this.data & 1 << w);
|
|
532
|
+
}
|
|
533
|
+
set blend(t) {
|
|
534
|
+
!!(this.data & 1 << w) !== t && (this.data ^= 1 << w);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Activates adding an offset to depth values of polygon's fragments
|
|
538
|
+
* @default false
|
|
539
|
+
*/
|
|
540
|
+
get offsets() {
|
|
541
|
+
return !!(this.data & 1 << F);
|
|
542
|
+
}
|
|
543
|
+
set offsets(t) {
|
|
544
|
+
!!(this.data & 1 << F) !== t && (this.data ^= 1 << F);
|
|
545
|
+
}
|
|
546
|
+
/** The culling settings for this state none - No culling back - Back face culling front - Front face culling */
|
|
547
|
+
set cullMode(t) {
|
|
548
|
+
if (t === "none") {
|
|
549
|
+
this.culling = !1;
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
this.culling = !0, this.clockwiseFrontFace = t === "front";
|
|
553
|
+
}
|
|
554
|
+
get cullMode() {
|
|
555
|
+
return this.culling ? this.clockwiseFrontFace ? "front" : "back" : "none";
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Activates culling of polygons.
|
|
559
|
+
* @default false
|
|
560
|
+
*/
|
|
561
|
+
get culling() {
|
|
562
|
+
return !!(this.data & 1 << z);
|
|
563
|
+
}
|
|
564
|
+
set culling(t) {
|
|
565
|
+
!!(this.data & 1 << z) !== t && (this.data ^= 1 << z);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Activates depth comparisons and updates to the depth buffer.
|
|
569
|
+
* @default false
|
|
570
|
+
*/
|
|
571
|
+
get depthTest() {
|
|
572
|
+
return !!(this.data & 1 << O);
|
|
573
|
+
}
|
|
574
|
+
set depthTest(t) {
|
|
575
|
+
!!(this.data & 1 << O) !== t && (this.data ^= 1 << O);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Enables or disables writing to the depth buffer.
|
|
579
|
+
* @default true
|
|
580
|
+
*/
|
|
581
|
+
get depthMask() {
|
|
582
|
+
return !!(this.data & 1 << B);
|
|
583
|
+
}
|
|
584
|
+
set depthMask(t) {
|
|
585
|
+
!!(this.data & 1 << B) !== t && (this.data ^= 1 << B);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Specifies whether or not front or back-facing polygons can be culled.
|
|
589
|
+
* @default false
|
|
590
|
+
*/
|
|
591
|
+
get clockwiseFrontFace() {
|
|
592
|
+
return !!(this.data & 1 << R);
|
|
593
|
+
}
|
|
594
|
+
set clockwiseFrontFace(t) {
|
|
595
|
+
!!(this.data & 1 << R) !== t && (this.data ^= 1 << R);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* The blend mode to be applied when this state is set. Apply a value of `normal` to reset the blend mode.
|
|
599
|
+
* Setting this mode to anything other than NO_BLEND will automatically switch blending on.
|
|
600
|
+
* @default 'normal'
|
|
601
|
+
*/
|
|
602
|
+
get blendMode() {
|
|
603
|
+
return this._blendMode;
|
|
604
|
+
}
|
|
605
|
+
set blendMode(t) {
|
|
606
|
+
this.blend = t !== "none", this._blendMode = t, this._blendModeId = zt[t] || 0;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* The polygon offset. Setting this property to anything other than 0 will automatically enable polygon offset fill.
|
|
610
|
+
* @default 0
|
|
611
|
+
*/
|
|
612
|
+
get polygonOffset() {
|
|
613
|
+
return this._polygonOffset;
|
|
614
|
+
}
|
|
615
|
+
set polygonOffset(t) {
|
|
616
|
+
this.offsets = !!t, this._polygonOffset = t;
|
|
617
|
+
}
|
|
618
|
+
toString() {
|
|
619
|
+
return `[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* A quickly getting an instance of a State that is configured for 2d rendering.
|
|
623
|
+
* @returns a new State with values set for 2d rendering
|
|
624
|
+
*/
|
|
625
|
+
static for2d() {
|
|
626
|
+
const t = new ct();
|
|
627
|
+
return t.depthTest = !1, t.blend = !0, t;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
V.default2d = V.for2d();
|
|
631
|
+
let ee = V, Ot = 0;
|
|
632
|
+
class Rt {
|
|
633
|
+
/**
|
|
634
|
+
* @param textureOptions - options that will be passed to BaseRenderTexture constructor
|
|
635
|
+
* @param {SCALE_MODE} [textureOptions.scaleMode] - See {@link SCALE_MODE} for possible values.
|
|
636
|
+
*/
|
|
637
|
+
constructor(t) {
|
|
638
|
+
this._poolKeyHash = /* @__PURE__ */ Object.create(null), this._texturePool = {}, this.textureOptions = t || {}, this.enableFullScreen = !1;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Creates texture with params that were specified in pool constructor.
|
|
642
|
+
* @param pixelWidth - Width of texture in pixels.
|
|
643
|
+
* @param pixelHeight - Height of texture in pixels.
|
|
644
|
+
* @param antialias
|
|
645
|
+
*/
|
|
646
|
+
createTexture(t, e, r) {
|
|
647
|
+
const n = new ht({
|
|
648
|
+
...this.textureOptions,
|
|
649
|
+
width: t,
|
|
650
|
+
height: e,
|
|
651
|
+
resolution: 1,
|
|
652
|
+
antialias: r,
|
|
653
|
+
autoGarbageCollect: !0
|
|
654
|
+
});
|
|
655
|
+
return new pt({
|
|
656
|
+
source: n,
|
|
657
|
+
label: `texturePool_${Ot++}`
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Gets a Power-of-Two render texture or fullScreen texture
|
|
662
|
+
* @param frameWidth - The minimum width of the render texture.
|
|
663
|
+
* @param frameHeight - The minimum height of the render texture.
|
|
664
|
+
* @param resolution - The resolution of the render texture.
|
|
665
|
+
* @param antialias
|
|
666
|
+
* @returns The new render texture.
|
|
667
|
+
*/
|
|
668
|
+
getOptimalTexture(t, e, r = 1, n) {
|
|
669
|
+
let s = Math.ceil(t * r - 1e-6), a = Math.ceil(e * r - 1e-6);
|
|
670
|
+
s = X(s), a = X(a);
|
|
671
|
+
const i = (s << 17) + (a << 1) + (n ? 1 : 0);
|
|
672
|
+
this._texturePool[i] || (this._texturePool[i] = []);
|
|
673
|
+
let u = this._texturePool[i].pop();
|
|
674
|
+
return u || (u = this.createTexture(s, a, n)), u.source._resolution = r, u.source.width = s / r, u.source.height = a / r, u.source.pixelWidth = s, u.source.pixelHeight = a, u.frame.x = 0, u.frame.y = 0, u.frame.width = t, u.frame.height = e, u.updateUvs(), this._poolKeyHash[u.uid] = i, u;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Gets extra texture of the same size as input renderTexture
|
|
678
|
+
* @param texture - The texture to check what size it is.
|
|
679
|
+
* @param antialias - Whether to use antialias.
|
|
680
|
+
* @returns A texture that is a power of two
|
|
681
|
+
*/
|
|
682
|
+
getSameSizeTexture(t, e = !1) {
|
|
683
|
+
const r = t.source;
|
|
684
|
+
return this.getOptimalTexture(t.width, t.height, r._resolution, e);
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Place a render texture back into the pool.
|
|
688
|
+
* @param renderTexture - The renderTexture to free
|
|
689
|
+
*/
|
|
690
|
+
returnTexture(t) {
|
|
691
|
+
const e = this._poolKeyHash[t.uid];
|
|
692
|
+
this._texturePool[e].push(t);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Clears the pool.
|
|
696
|
+
* @param destroyTextures - Destroy all stored textures.
|
|
697
|
+
*/
|
|
698
|
+
clear(t) {
|
|
699
|
+
if (t = t !== !1, t)
|
|
700
|
+
for (const e in this._texturePool) {
|
|
701
|
+
const r = this._texturePool[e];
|
|
702
|
+
if (r)
|
|
703
|
+
for (let n = 0; n < r.length; n++)
|
|
704
|
+
r[n].destroy(!0);
|
|
705
|
+
}
|
|
706
|
+
this._texturePool = {};
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const re = new Rt();
|
|
710
|
+
function Z(o, t, e) {
|
|
711
|
+
if (o)
|
|
712
|
+
for (const r in o) {
|
|
713
|
+
const n = r.toLocaleLowerCase(), s = t[n];
|
|
714
|
+
if (s) {
|
|
715
|
+
let a = o[r];
|
|
716
|
+
r === "header" && (a = a.replace(/@in\s+[^;]+;\s*/g, "").replace(/@out\s+[^;]+;\s*/g, "")), e && s.push(`//----${e}----//`), s.push(a);
|
|
717
|
+
} else
|
|
718
|
+
gt(`${r} placement hook does not exist in shader`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
const Bt = /\{\{(.*?)\}\}/g;
|
|
722
|
+
function J(o) {
|
|
723
|
+
var r;
|
|
724
|
+
const t = {};
|
|
725
|
+
return (((r = o.match(Bt)) == null ? void 0 : r.map((n) => n.replace(/[{()}]/g, ""))) ?? []).forEach((n) => {
|
|
726
|
+
t[n] = [];
|
|
727
|
+
}), t;
|
|
728
|
+
}
|
|
729
|
+
function Q(o, t) {
|
|
730
|
+
let e;
|
|
731
|
+
const r = /@in\s+([^;]+);/g;
|
|
732
|
+
for (; (e = r.exec(o)) !== null; )
|
|
733
|
+
t.push(e[1]);
|
|
734
|
+
}
|
|
735
|
+
function tt(o, t, e = !1) {
|
|
736
|
+
const r = [];
|
|
737
|
+
Q(t, r), o.forEach((i) => {
|
|
738
|
+
i.header && Q(i.header, r);
|
|
739
|
+
});
|
|
740
|
+
const n = r;
|
|
741
|
+
e && n.sort();
|
|
742
|
+
const s = n.map((i, u) => ` @location(${u}) ${i},`).join(`
|
|
743
|
+
`);
|
|
744
|
+
let a = t.replace(/@in\s+[^;]+;\s*/g, "");
|
|
745
|
+
return a = a.replace("{{in}}", `
|
|
746
|
+
${s}
|
|
747
|
+
`), a;
|
|
748
|
+
}
|
|
749
|
+
function et(o, t) {
|
|
750
|
+
let e;
|
|
751
|
+
const r = /@out\s+([^;]+);/g;
|
|
752
|
+
for (; (e = r.exec(o)) !== null; )
|
|
753
|
+
t.push(e[1]);
|
|
754
|
+
}
|
|
755
|
+
function jt(o) {
|
|
756
|
+
const e = /\b(\w+)\s*:/g.exec(o);
|
|
757
|
+
return e ? e[1] : "";
|
|
758
|
+
}
|
|
759
|
+
function It(o) {
|
|
760
|
+
const t = /@.*?\s+/g;
|
|
761
|
+
return o.replace(t, "");
|
|
762
|
+
}
|
|
763
|
+
function kt(o, t) {
|
|
764
|
+
const e = [];
|
|
765
|
+
et(t, e), o.forEach((u) => {
|
|
766
|
+
u.header && et(u.header, e);
|
|
767
|
+
});
|
|
768
|
+
let r = 0;
|
|
769
|
+
const n = e.sort().map((u) => u.indexOf("builtin") > -1 ? u : `@location(${r++}) ${u}`).join(`,
|
|
770
|
+
`), s = e.sort().map((u) => ` var ${It(u)};`).join(`
|
|
771
|
+
`), a = `return VSOutput(
|
|
772
|
+
${e.sort().map((u) => ` ${jt(u)}`).join(`,
|
|
773
|
+
`)});`;
|
|
774
|
+
let i = t.replace(/@out\s+[^;]+;\s*/g, "");
|
|
775
|
+
return i = i.replace("{{struct}}", `
|
|
776
|
+
${n}
|
|
777
|
+
`), i = i.replace("{{start}}", `
|
|
778
|
+
${s}
|
|
779
|
+
`), i = i.replace("{{return}}", `
|
|
780
|
+
${a}
|
|
781
|
+
`), i;
|
|
782
|
+
}
|
|
783
|
+
function rt(o, t) {
|
|
784
|
+
let e = o;
|
|
785
|
+
for (const r in t) {
|
|
786
|
+
const n = t[r];
|
|
787
|
+
n.join(`
|
|
788
|
+
`).length ? e = e.replace(`{{${r}}}`, `//-----${r} START-----//
|
|
789
|
+
${n.join(`
|
|
790
|
+
`)}
|
|
791
|
+
//----${r} FINISH----//`) : e = e.replace(`{{${r}}}`, "");
|
|
792
|
+
}
|
|
793
|
+
return e;
|
|
794
|
+
}
|
|
795
|
+
const g = /* @__PURE__ */ Object.create(null), j = /* @__PURE__ */ new Map();
|
|
796
|
+
let Dt = 0;
|
|
797
|
+
function Nt({
|
|
798
|
+
template: o,
|
|
799
|
+
bits: t
|
|
800
|
+
}) {
|
|
801
|
+
const e = lt(o, t);
|
|
802
|
+
if (g[e])
|
|
803
|
+
return g[e];
|
|
804
|
+
const { vertex: r, fragment: n } = Ht(o, t);
|
|
805
|
+
return g[e] = ft(r, n, t), g[e];
|
|
806
|
+
}
|
|
807
|
+
function Lt({
|
|
808
|
+
template: o,
|
|
809
|
+
bits: t
|
|
810
|
+
}) {
|
|
811
|
+
const e = lt(o, t);
|
|
812
|
+
return g[e] || (g[e] = ft(o.vertex, o.fragment, t)), g[e];
|
|
813
|
+
}
|
|
814
|
+
function Ht(o, t) {
|
|
815
|
+
const e = t.map((a) => a.vertex).filter((a) => !!a), r = t.map((a) => a.fragment).filter((a) => !!a);
|
|
816
|
+
let n = tt(e, o.vertex, !0);
|
|
817
|
+
n = kt(e, n);
|
|
818
|
+
const s = tt(r, o.fragment, !0);
|
|
819
|
+
return {
|
|
820
|
+
vertex: n,
|
|
821
|
+
fragment: s
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
function lt(o, t) {
|
|
825
|
+
return t.map((e) => (j.has(e) || j.set(e, Dt++), j.get(e))).sort((e, r) => e - r).join("-") + o.vertex + o.fragment;
|
|
826
|
+
}
|
|
827
|
+
function ft(o, t, e) {
|
|
828
|
+
const r = J(o), n = J(t);
|
|
829
|
+
return e.forEach((s) => {
|
|
830
|
+
Z(s.vertex, r, s.name), Z(s.fragment, n, s.name);
|
|
831
|
+
}), {
|
|
832
|
+
vertex: rt(o, r),
|
|
833
|
+
fragment: rt(t, n)
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
const Vt = (
|
|
837
|
+
/* wgsl */
|
|
838
|
+
`
|
|
839
|
+
@in aPosition: vec2<f32>;
|
|
840
|
+
@in aUV: vec2<f32>;
|
|
841
|
+
|
|
842
|
+
@out @builtin(position) vPosition: vec4<f32>;
|
|
843
|
+
@out vUV : vec2<f32>;
|
|
844
|
+
@out vColor : vec4<f32>;
|
|
845
|
+
|
|
846
|
+
{{header}}
|
|
847
|
+
|
|
848
|
+
struct VSOutput {
|
|
849
|
+
{{struct}}
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
@vertex
|
|
853
|
+
fn main( {{in}} ) -> VSOutput {
|
|
854
|
+
|
|
855
|
+
var worldTransformMatrix = globalUniforms.uWorldTransformMatrix;
|
|
856
|
+
var modelMatrix = mat3x3<f32>(
|
|
857
|
+
1.0, 0.0, 0.0,
|
|
858
|
+
0.0, 1.0, 0.0,
|
|
859
|
+
0.0, 0.0, 1.0
|
|
860
|
+
);
|
|
861
|
+
var position = aPosition;
|
|
862
|
+
var uv = aUV;
|
|
863
|
+
|
|
864
|
+
{{start}}
|
|
865
|
+
|
|
866
|
+
vColor = vec4<f32>(1., 1., 1., 1.);
|
|
867
|
+
|
|
868
|
+
{{main}}
|
|
869
|
+
|
|
870
|
+
vUV = uv;
|
|
871
|
+
|
|
872
|
+
var modelViewProjectionMatrix = globalUniforms.uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
|
873
|
+
|
|
874
|
+
vPosition = vec4<f32>((modelViewProjectionMatrix * vec3<f32>(position, 1.0)).xy, 0.0, 1.0);
|
|
875
|
+
|
|
876
|
+
vColor *= globalUniforms.uWorldColorAlpha;
|
|
877
|
+
|
|
878
|
+
{{end}}
|
|
879
|
+
|
|
880
|
+
{{return}}
|
|
881
|
+
};
|
|
882
|
+
`
|
|
883
|
+
), Wt = (
|
|
884
|
+
/* wgsl */
|
|
885
|
+
`
|
|
886
|
+
@in vUV : vec2<f32>;
|
|
887
|
+
@in vColor : vec4<f32>;
|
|
888
|
+
|
|
889
|
+
{{header}}
|
|
890
|
+
|
|
891
|
+
@fragment
|
|
892
|
+
fn main(
|
|
893
|
+
{{in}}
|
|
894
|
+
) -> @location(0) vec4<f32> {
|
|
895
|
+
|
|
896
|
+
{{start}}
|
|
897
|
+
|
|
898
|
+
var outColor:vec4<f32>;
|
|
899
|
+
|
|
900
|
+
{{main}}
|
|
901
|
+
|
|
902
|
+
return outColor * vColor;
|
|
903
|
+
};
|
|
904
|
+
`
|
|
905
|
+
), Kt = (
|
|
906
|
+
/* glsl */
|
|
907
|
+
`
|
|
908
|
+
in vec2 aPosition;
|
|
909
|
+
in vec2 aUV;
|
|
910
|
+
|
|
911
|
+
out vec4 vColor;
|
|
912
|
+
out vec2 vUV;
|
|
913
|
+
|
|
914
|
+
{{header}}
|
|
915
|
+
|
|
916
|
+
void main(void){
|
|
917
|
+
|
|
918
|
+
mat3 worldTransformMatrix = uWorldTransformMatrix;
|
|
919
|
+
mat3 modelMatrix = mat3(
|
|
920
|
+
1.0, 0.0, 0.0,
|
|
921
|
+
0.0, 1.0, 0.0,
|
|
922
|
+
0.0, 0.0, 1.0
|
|
923
|
+
);
|
|
924
|
+
vec2 position = aPosition;
|
|
925
|
+
vec2 uv = aUV;
|
|
926
|
+
|
|
927
|
+
{{start}}
|
|
928
|
+
|
|
929
|
+
vColor = vec4(1.);
|
|
930
|
+
|
|
931
|
+
{{main}}
|
|
932
|
+
|
|
933
|
+
vUV = uv;
|
|
934
|
+
|
|
935
|
+
mat3 modelViewProjectionMatrix = uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
|
936
|
+
|
|
937
|
+
gl_Position = vec4((modelViewProjectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
|
|
938
|
+
|
|
939
|
+
vColor *= uWorldColorAlpha;
|
|
940
|
+
|
|
941
|
+
{{end}}
|
|
942
|
+
}
|
|
943
|
+
`
|
|
944
|
+
), Xt = (
|
|
945
|
+
/* glsl */
|
|
946
|
+
`
|
|
947
|
+
|
|
948
|
+
in vec4 vColor;
|
|
949
|
+
in vec2 vUV;
|
|
950
|
+
|
|
951
|
+
out vec4 finalColor;
|
|
952
|
+
|
|
953
|
+
{{header}}
|
|
954
|
+
|
|
955
|
+
void main(void) {
|
|
956
|
+
|
|
957
|
+
{{start}}
|
|
958
|
+
|
|
959
|
+
vec4 outColor;
|
|
960
|
+
|
|
961
|
+
{{main}}
|
|
962
|
+
|
|
963
|
+
finalColor = outColor * vColor;
|
|
964
|
+
}
|
|
965
|
+
`
|
|
966
|
+
), Yt = {
|
|
967
|
+
name: "global-uniforms-bit",
|
|
968
|
+
vertex: {
|
|
969
|
+
header: (
|
|
970
|
+
/* wgsl */
|
|
971
|
+
`
|
|
972
|
+
struct GlobalUniforms {
|
|
973
|
+
uProjectionMatrix:mat3x3<f32>,
|
|
974
|
+
uWorldTransformMatrix:mat3x3<f32>,
|
|
975
|
+
uWorldColorAlpha: vec4<f32>,
|
|
976
|
+
uResolution: vec2<f32>,
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
@group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms;
|
|
980
|
+
`
|
|
981
|
+
)
|
|
982
|
+
}
|
|
983
|
+
}, qt = {
|
|
984
|
+
name: "global-uniforms-bit",
|
|
985
|
+
vertex: {
|
|
986
|
+
header: (
|
|
987
|
+
/* glsl */
|
|
988
|
+
`
|
|
989
|
+
uniform mat3 uProjectionMatrix;
|
|
990
|
+
uniform mat3 uWorldTransformMatrix;
|
|
991
|
+
uniform vec4 uWorldColorAlpha;
|
|
992
|
+
uniform vec2 uResolution;
|
|
993
|
+
`
|
|
994
|
+
)
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
function oe({ bits: o, name: t }) {
|
|
998
|
+
const e = Nt({
|
|
999
|
+
template: {
|
|
1000
|
+
fragment: Wt,
|
|
1001
|
+
vertex: Vt
|
|
1002
|
+
},
|
|
1003
|
+
bits: [
|
|
1004
|
+
Yt,
|
|
1005
|
+
...o
|
|
1006
|
+
]
|
|
1007
|
+
});
|
|
1008
|
+
return S.from({
|
|
1009
|
+
name: t,
|
|
1010
|
+
vertex: {
|
|
1011
|
+
source: e.vertex,
|
|
1012
|
+
entryPoint: "main"
|
|
1013
|
+
},
|
|
1014
|
+
fragment: {
|
|
1015
|
+
source: e.fragment,
|
|
1016
|
+
entryPoint: "main"
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
function ne({ bits: o, name: t }) {
|
|
1021
|
+
return new nt({
|
|
1022
|
+
name: t,
|
|
1023
|
+
...Lt({
|
|
1024
|
+
template: {
|
|
1025
|
+
vertex: Kt,
|
|
1026
|
+
fragment: Xt
|
|
1027
|
+
},
|
|
1028
|
+
bits: [
|
|
1029
|
+
qt,
|
|
1030
|
+
...o
|
|
1031
|
+
]
|
|
1032
|
+
})
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
const se = {
|
|
1036
|
+
name: "color-bit",
|
|
1037
|
+
vertex: {
|
|
1038
|
+
header: (
|
|
1039
|
+
/* wgsl */
|
|
1040
|
+
`
|
|
1041
|
+
@in aColor: vec4<f32>;
|
|
1042
|
+
`
|
|
1043
|
+
),
|
|
1044
|
+
main: (
|
|
1045
|
+
/* wgsl */
|
|
1046
|
+
`
|
|
1047
|
+
vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
|
|
1048
|
+
`
|
|
1049
|
+
)
|
|
1050
|
+
}
|
|
1051
|
+
}, ie = {
|
|
1052
|
+
name: "color-bit",
|
|
1053
|
+
vertex: {
|
|
1054
|
+
header: (
|
|
1055
|
+
/* glsl */
|
|
1056
|
+
`
|
|
1057
|
+
in vec4 aColor;
|
|
1058
|
+
`
|
|
1059
|
+
),
|
|
1060
|
+
main: (
|
|
1061
|
+
/* glsl */
|
|
1062
|
+
`
|
|
1063
|
+
vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
|
|
1064
|
+
`
|
|
1065
|
+
)
|
|
1066
|
+
}
|
|
1067
|
+
}, I = {};
|
|
1068
|
+
function Zt(o) {
|
|
1069
|
+
const t = [];
|
|
1070
|
+
if (o === 1)
|
|
1071
|
+
t.push("@group(1) @binding(0) var textureSource1: texture_2d<f32>;"), t.push("@group(1) @binding(1) var textureSampler1: sampler;");
|
|
1072
|
+
else {
|
|
1073
|
+
let e = 0;
|
|
1074
|
+
for (let r = 0; r < o; r++)
|
|
1075
|
+
t.push(`@group(1) @binding(${e++}) var textureSource${r + 1}: texture_2d<f32>;`), t.push(`@group(1) @binding(${e++}) var textureSampler${r + 1}: sampler;`);
|
|
1076
|
+
}
|
|
1077
|
+
return t.join(`
|
|
1078
|
+
`);
|
|
1079
|
+
}
|
|
1080
|
+
function Jt(o) {
|
|
1081
|
+
const t = [];
|
|
1082
|
+
if (o === 1)
|
|
1083
|
+
t.push("outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);");
|
|
1084
|
+
else {
|
|
1085
|
+
t.push("switch vTextureId {");
|
|
1086
|
+
for (let e = 0; e < o; e++)
|
|
1087
|
+
e === o - 1 ? t.push(" default:{") : t.push(` case ${e}:{`), t.push(` outColor = textureSampleGrad(textureSource${e + 1}, textureSampler${e + 1}, vUV, uvDx, uvDy);`), t.push(" break;}");
|
|
1088
|
+
t.push("}");
|
|
1089
|
+
}
|
|
1090
|
+
return t.join(`
|
|
1091
|
+
`);
|
|
1092
|
+
}
|
|
1093
|
+
function ae(o) {
|
|
1094
|
+
return I[o] || (I[o] = {
|
|
1095
|
+
name: "texture-batch-bit",
|
|
1096
|
+
vertex: {
|
|
1097
|
+
header: `
|
|
1098
|
+
@in aTextureIdAndRound: vec2<u32>;
|
|
1099
|
+
@out @interpolate(flat) vTextureId : u32;
|
|
1100
|
+
`,
|
|
1101
|
+
main: `
|
|
1102
|
+
vTextureId = aTextureIdAndRound.y;
|
|
1103
|
+
`,
|
|
1104
|
+
end: `
|
|
1105
|
+
if(aTextureIdAndRound.x == 1)
|
|
1106
|
+
{
|
|
1107
|
+
vPosition = vec4<f32>(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
1108
|
+
}
|
|
1109
|
+
`
|
|
1110
|
+
},
|
|
1111
|
+
fragment: {
|
|
1112
|
+
header: `
|
|
1113
|
+
@in @interpolate(flat) vTextureId: u32;
|
|
1114
|
+
|
|
1115
|
+
${Zt(N())}
|
|
1116
|
+
`,
|
|
1117
|
+
main: `
|
|
1118
|
+
var uvDx = dpdx(vUV);
|
|
1119
|
+
var uvDy = dpdy(vUV);
|
|
1120
|
+
|
|
1121
|
+
${Jt(N())}
|
|
1122
|
+
`
|
|
1123
|
+
}
|
|
1124
|
+
}), I[o];
|
|
1125
|
+
}
|
|
1126
|
+
const k = {};
|
|
1127
|
+
function Qt(o) {
|
|
1128
|
+
const t = [];
|
|
1129
|
+
for (let e = 0; e < o; e++)
|
|
1130
|
+
e > 0 && t.push("else"), e < o - 1 && t.push(`if(vTextureId < ${e}.5)`), t.push("{"), t.push(` outColor = texture(uTextures[${e}], vUV);`), t.push("}");
|
|
1131
|
+
return t.join(`
|
|
1132
|
+
`);
|
|
1133
|
+
}
|
|
1134
|
+
function ue(o) {
|
|
1135
|
+
return k[o] || (k[o] = {
|
|
1136
|
+
name: "texture-batch-bit",
|
|
1137
|
+
vertex: {
|
|
1138
|
+
header: `
|
|
1139
|
+
in vec2 aTextureIdAndRound;
|
|
1140
|
+
out float vTextureId;
|
|
1141
|
+
|
|
1142
|
+
`,
|
|
1143
|
+
main: `
|
|
1144
|
+
vTextureId = aTextureIdAndRound.y;
|
|
1145
|
+
`,
|
|
1146
|
+
end: `
|
|
1147
|
+
if(aTextureIdAndRound.x == 1.)
|
|
1148
|
+
{
|
|
1149
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
1150
|
+
}
|
|
1151
|
+
`
|
|
1152
|
+
},
|
|
1153
|
+
fragment: {
|
|
1154
|
+
header: `
|
|
1155
|
+
in float vTextureId;
|
|
1156
|
+
|
|
1157
|
+
uniform sampler2D uTextures[${o}];
|
|
1158
|
+
|
|
1159
|
+
`,
|
|
1160
|
+
main: `
|
|
1161
|
+
|
|
1162
|
+
${Qt(N())}
|
|
1163
|
+
`
|
|
1164
|
+
}
|
|
1165
|
+
}), k[o];
|
|
1166
|
+
}
|
|
1167
|
+
const ce = {
|
|
1168
|
+
name: "round-pixels-bit",
|
|
1169
|
+
vertex: {
|
|
1170
|
+
header: (
|
|
1171
|
+
/* wgsl */
|
|
1172
|
+
`
|
|
1173
|
+
fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
|
|
1174
|
+
{
|
|
1175
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
1176
|
+
}
|
|
1177
|
+
`
|
|
1178
|
+
)
|
|
1179
|
+
}
|
|
1180
|
+
}, le = {
|
|
1181
|
+
name: "round-pixels-bit",
|
|
1182
|
+
vertex: {
|
|
1183
|
+
header: (
|
|
1184
|
+
/* glsl */
|
|
1185
|
+
`
|
|
1186
|
+
vec2 roundPixels(vec2 position, vec2 targetSize)
|
|
1187
|
+
{
|
|
1188
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
1189
|
+
}
|
|
1190
|
+
`
|
|
1191
|
+
)
|
|
1192
|
+
}
|
|
1193
|
+
}, D = {
|
|
1194
|
+
name: "local-uniform-bit",
|
|
1195
|
+
vertex: {
|
|
1196
|
+
header: (
|
|
1197
|
+
/* wgsl */
|
|
1198
|
+
`
|
|
1199
|
+
|
|
1200
|
+
struct LocalUniforms {
|
|
1201
|
+
uTransformMatrix:mat3x3<f32>,
|
|
1202
|
+
uColor:vec4<f32>,
|
|
1203
|
+
uRound:f32,
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
@group(1) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
1207
|
+
`
|
|
1208
|
+
),
|
|
1209
|
+
main: (
|
|
1210
|
+
/* wgsl */
|
|
1211
|
+
`
|
|
1212
|
+
vColor *= localUniforms.uColor;
|
|
1213
|
+
modelMatrix *= localUniforms.uTransformMatrix;
|
|
1214
|
+
`
|
|
1215
|
+
),
|
|
1216
|
+
end: (
|
|
1217
|
+
/* wgsl */
|
|
1218
|
+
`
|
|
1219
|
+
if(localUniforms.uRound == 1)
|
|
1220
|
+
{
|
|
1221
|
+
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
1222
|
+
}
|
|
1223
|
+
`
|
|
1224
|
+
)
|
|
1225
|
+
}
|
|
1226
|
+
}, fe = {
|
|
1227
|
+
...D,
|
|
1228
|
+
vertex: {
|
|
1229
|
+
...D.vertex,
|
|
1230
|
+
// replace the group!
|
|
1231
|
+
header: D.vertex.header.replace("group(1)", "group(2)")
|
|
1232
|
+
}
|
|
1233
|
+
}, me = {
|
|
1234
|
+
name: "local-uniform-bit",
|
|
1235
|
+
vertex: {
|
|
1236
|
+
header: (
|
|
1237
|
+
/* glsl */
|
|
1238
|
+
`
|
|
1239
|
+
|
|
1240
|
+
uniform mat3 uTransformMatrix;
|
|
1241
|
+
uniform vec4 uColor;
|
|
1242
|
+
uniform float uRound;
|
|
1243
|
+
`
|
|
1244
|
+
),
|
|
1245
|
+
main: (
|
|
1246
|
+
/* glsl */
|
|
1247
|
+
`
|
|
1248
|
+
vColor *= uColor;
|
|
1249
|
+
modelMatrix = uTransformMatrix;
|
|
1250
|
+
`
|
|
1251
|
+
),
|
|
1252
|
+
end: (
|
|
1253
|
+
/* glsl */
|
|
1254
|
+
`
|
|
1255
|
+
if(uRound == 1.)
|
|
1256
|
+
{
|
|
1257
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
1258
|
+
}
|
|
1259
|
+
`
|
|
1260
|
+
)
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
class de {
|
|
1264
|
+
constructor() {
|
|
1265
|
+
this.vertexSize = 4, this.indexSize = 6, this.location = 0, this.batcher = null, this.batch = null, this.roundPixels = 0;
|
|
1266
|
+
}
|
|
1267
|
+
get blendMode() {
|
|
1268
|
+
return this.renderable.groupBlendMode;
|
|
1269
|
+
}
|
|
1270
|
+
packAttributes(t, e, r, n) {
|
|
1271
|
+
const s = this.renderable, a = this.texture, i = s.groupTransform, u = i.a, l = i.b, c = i.c, f = i.d, d = i.tx, m = i.ty, p = this.bounds, x = p.maxX, v = p.minX, b = p.maxY, P = p.minY, h = a.uvs, _ = s.groupColorAlpha, G = n << 16 | this.roundPixels & 65535;
|
|
1272
|
+
t[r + 0] = u * v + c * P + d, t[r + 1] = f * P + l * v + m, t[r + 2] = h.x0, t[r + 3] = h.y0, e[r + 4] = _, e[r + 5] = G, t[r + 6] = u * x + c * P + d, t[r + 7] = f * P + l * x + m, t[r + 8] = h.x1, t[r + 9] = h.y1, e[r + 10] = _, e[r + 11] = G, t[r + 12] = u * x + c * b + d, t[r + 13] = f * b + l * x + m, t[r + 14] = h.x2, t[r + 15] = h.y2, e[r + 16] = _, e[r + 17] = G, t[r + 18] = u * v + c * b + d, t[r + 19] = f * b + l * v + m, t[r + 20] = h.x3, t[r + 21] = h.y3, e[r + 22] = _, e[r + 23] = G;
|
|
1273
|
+
}
|
|
1274
|
+
packIndex(t, e, r) {
|
|
1275
|
+
t[e] = r + 0, t[e + 1] = r + 1, t[e + 2] = r + 2, t[e + 3] = r + 0, t[e + 4] = r + 2, t[e + 5] = r + 3;
|
|
1276
|
+
}
|
|
1277
|
+
reset() {
|
|
1278
|
+
this.renderable = null, this.texture = null, this.batcher = null, this.batch = null, this.bounds = null;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
function he(o, t, e) {
|
|
1282
|
+
const r = (o >> 24 & 255) / 255;
|
|
1283
|
+
t[e++] = (o & 255) / 255 * r, t[e++] = (o >> 8 & 255) / 255 * r, t[e++] = (o >> 16 & 255) / 255 * r, t[e++] = r;
|
|
1284
|
+
}
|
|
1285
|
+
export {
|
|
1286
|
+
de as B,
|
|
1287
|
+
S as G,
|
|
1288
|
+
H as R,
|
|
1289
|
+
ee as S,
|
|
1290
|
+
re as T,
|
|
1291
|
+
Ft as U,
|
|
1292
|
+
se as a,
|
|
1293
|
+
ut as b,
|
|
1294
|
+
oe as c,
|
|
1295
|
+
W as d,
|
|
1296
|
+
D as e,
|
|
1297
|
+
nt as f,
|
|
1298
|
+
ae as g,
|
|
1299
|
+
St as h,
|
|
1300
|
+
he as i,
|
|
1301
|
+
ne as j,
|
|
1302
|
+
ie as k,
|
|
1303
|
+
fe as l,
|
|
1304
|
+
ue as m,
|
|
1305
|
+
le as n,
|
|
1306
|
+
me as o,
|
|
1307
|
+
ce as r
|
|
1308
|
+
};
|