@margoengine/transitions 0.0.0-stage → 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 -0
- package/NOTICE +4 -0
- package/README.md +140 -2
- package/dist/builtin.d.ts +2 -0
- package/dist/custom-CteHwFLg.js +56 -0
- package/dist/custom-code-D9Y4mDt8.js +79 -0
- package/dist/custom-code.d.ts +2 -0
- package/dist/custom.d.ts +16 -0
- package/dist/custom.js +1 -0
- package/dist/errors-CsQwshHA.js +7 -0
- package/dist/formats-C_gWhYlk.js +283 -0
- package/dist/formats.d.ts +1 -0
- package/dist/glsl.d.ts +23 -0
- package/dist/glsl.js +1261 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +95 -0
- package/dist/live.d.ts +70 -0
- package/dist/live.js +184 -0
- package/dist/mask.d.ts +18 -0
- package/dist/mask.js +67 -0
- package/dist/presets.d.ts +29 -0
- package/dist/presets.js +82 -0
- package/package.json +68 -4
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
//#region ../shared/view-rect.js
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e?.view?.viewport;
|
|
4
|
+
}
|
|
5
|
+
function t(t, n) {
|
|
6
|
+
let r = e(n);
|
|
7
|
+
if (!r) return;
|
|
8
|
+
t.setViewport(r[0], r[1], r[2], r[3], 0, 1);
|
|
9
|
+
let i = n.view.scissor ?? r;
|
|
10
|
+
t.setScissorRect(i[0], i[1], i[2], i[3]);
|
|
11
|
+
}
|
|
12
|
+
function n(e, t = "clear") {
|
|
13
|
+
return e?.view?.index ? "load" : t;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region ../shared/frame-resources.js
|
|
17
|
+
var r = (globalThis[Symbol.for("margoengine.frame-resources")] ??= { devices: /* @__PURE__ */ new WeakMap() }).devices;
|
|
18
|
+
function i(e) {
|
|
19
|
+
let t = r.get(e);
|
|
20
|
+
return t || (r.set(e, t = {
|
|
21
|
+
frame: 0,
|
|
22
|
+
open: !1,
|
|
23
|
+
lost: !1,
|
|
24
|
+
views: /* @__PURE__ */ new Set(),
|
|
25
|
+
drawing: 0,
|
|
26
|
+
retired: [],
|
|
27
|
+
written: /* @__PURE__ */ new WeakMap()
|
|
28
|
+
}), e.lost?.then?.(() => {
|
|
29
|
+
t.lost = !0;
|
|
30
|
+
let e = t.retired;
|
|
31
|
+
t.retired = [];
|
|
32
|
+
for (let t of e) t.destroy();
|
|
33
|
+
})), t;
|
|
34
|
+
}
|
|
35
|
+
function a(e, t) {
|
|
36
|
+
if (!t) return;
|
|
37
|
+
let n = i(e), r = [t, ...n.written.get(t)?.extras ?? []];
|
|
38
|
+
if (n.written.delete(t), !n.lost && n.open && (n.views.size > 1 || n.drawing > 0)) n.retired.push(...r);
|
|
39
|
+
else for (let e of r) e.destroy();
|
|
40
|
+
}
|
|
41
|
+
function o(e) {
|
|
42
|
+
return e?.adapterInfo?.vendor === "margo-webgl2" ? "webgl2" : "native";
|
|
43
|
+
}
|
|
44
|
+
function s(e) {
|
|
45
|
+
return o(e) === "native" && e?.features?.has("core-features-and-limits") === !1;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region ../shared/msaa.js
|
|
49
|
+
var c = "@vertex fn vertex(@builtin(vertex_index) i:u32)->@builtin(position) vec4f {return vec4f(array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3))[i],0,1);}", l = (e, t, n) => e.createBindGroup({
|
|
50
|
+
layout: t.getBindGroupLayout(0),
|
|
51
|
+
entries: [{
|
|
52
|
+
binding: 0,
|
|
53
|
+
resource: n
|
|
54
|
+
}]
|
|
55
|
+
}), u = Symbol.for("margoengine.optional.msaa"), d = c + "\n@group(0) @binding(0) var source:texture_depth_multisampled_2d;\n@fragment fn fragment(@builtin(position) p:vec4f)->@builtin(frag_depth) f32 {\n let q=vec2i(p.xy);\n return max(max(textureLoad(source,q,0),textureLoad(source,q,1)),max(textureLoad(source,q,2),textureLoad(source,q,3)));\n}";
|
|
56
|
+
function f(e, t, n, r, i, a = !1) {
|
|
57
|
+
let o = (e) => d.replace(/return max[^;]+;/, `return textureLoad(source,q,${e});`), c = (n, r) => {
|
|
58
|
+
let a = e.createShaderModule({ code: n }), o = e.createRenderPipeline({
|
|
59
|
+
layout: "auto",
|
|
60
|
+
vertex: {
|
|
61
|
+
module: a,
|
|
62
|
+
entryPoint: "vertex"
|
|
63
|
+
},
|
|
64
|
+
fragment: {
|
|
65
|
+
module: a,
|
|
66
|
+
entryPoint: "fragment",
|
|
67
|
+
targets: []
|
|
68
|
+
},
|
|
69
|
+
depthStencil: {
|
|
70
|
+
format: i,
|
|
71
|
+
depthWriteEnabled: !0,
|
|
72
|
+
depthCompare: "always"
|
|
73
|
+
},
|
|
74
|
+
multisample: r
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
pipeline: o,
|
|
78
|
+
group: l(e, o, t)
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
draws: a ? [c(o(0).replace("_multisampled", ""), { count: r })] : r === 4 ? s(e) ? [
|
|
83
|
+
0,
|
|
84
|
+
1,
|
|
85
|
+
2,
|
|
86
|
+
3
|
|
87
|
+
].map((e) => c(o(e), {
|
|
88
|
+
count: r,
|
|
89
|
+
mask: 1 << e
|
|
90
|
+
})) : [c(o("i32(sample)").replace("p:vec4f)", "p:vec4f,@builtin(sample_index) sample:u32)"), { count: r })] : [c(d, { count: r })],
|
|
91
|
+
descriptor: {
|
|
92
|
+
colorAttachments: [],
|
|
93
|
+
depthStencilAttachment: {
|
|
94
|
+
view: n,
|
|
95
|
+
depthLoadOp: "clear",
|
|
96
|
+
depthClearValue: 0,
|
|
97
|
+
depthStoreOp: "store",
|
|
98
|
+
stencilReadOnly: !0
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function p(e, n, r, i, a, o) {
|
|
104
|
+
let s = e.pipelines.get(i);
|
|
105
|
+
s || e.pipelines.set(i, s = /* @__PURE__ */ new Map());
|
|
106
|
+
let c = s.get(a);
|
|
107
|
+
if (!c) {
|
|
108
|
+
let t = e.samples === 1;
|
|
109
|
+
s.set(a, c = f(e.device, e.depthSource, r, i, a, t));
|
|
110
|
+
}
|
|
111
|
+
c.descriptor.depthStencilAttachment.view = r, c.descriptor.depthStencilAttachment.depthLoadOp = o?.view ? "load" : "clear";
|
|
112
|
+
let l = n.beginRenderPass(c.descriptor);
|
|
113
|
+
o && t(l, o);
|
|
114
|
+
let u = c.draws;
|
|
115
|
+
for (let e = 0; e < u.length; e++) l.setPipeline(u[e].pipeline), l.setBindGroup(0, u[e].group), l.draw(3);
|
|
116
|
+
l.end();
|
|
117
|
+
}
|
|
118
|
+
var m = class {
|
|
119
|
+
constructor(e, t, n, r = 4) {
|
|
120
|
+
if (r !== 1 && r !== 4) throw RangeError("Scene samples must be 1 or 4");
|
|
121
|
+
this.samples = r, this.device = e, this.resolvedColor = t, this.resolvedDepth = n, this.textures = [], this.pipelines = /* @__PURE__ */ new Map();
|
|
122
|
+
try {
|
|
123
|
+
if (r === 1) {
|
|
124
|
+
this.color = t.createView(), this.depth = n.createView();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
for (let r of [t, n]) this.textures.push(e.createTexture({
|
|
128
|
+
size: [r.width, r.height],
|
|
129
|
+
format: r.format,
|
|
130
|
+
sampleCount: 4,
|
|
131
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
132
|
+
}));
|
|
133
|
+
this.color = this.textures[0].createView(), this.depth = this.textures[1].createView(), this.resolution = { colorAttachments: [{
|
|
134
|
+
view: this.color,
|
|
135
|
+
resolveTarget: t.createView(),
|
|
136
|
+
loadOp: "load",
|
|
137
|
+
storeOp: "store"
|
|
138
|
+
}] }, this.finalResolution = {
|
|
139
|
+
colorAttachments: [{
|
|
140
|
+
...this.resolution.colorAttachments[0],
|
|
141
|
+
storeOp: "discard"
|
|
142
|
+
}],
|
|
143
|
+
depthStencilAttachment: {
|
|
144
|
+
view: this.depth,
|
|
145
|
+
depthLoadOp: "load",
|
|
146
|
+
depthStoreOp: "discard",
|
|
147
|
+
stencilReadOnly: !0
|
|
148
|
+
}
|
|
149
|
+
}, this.depthSource = this.textures[1].createView({ aspect: "depth-only" }), this.resolvedDepthView = n.createView();
|
|
150
|
+
} catch (e) {
|
|
151
|
+
throw this.dispose(), e;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
begin(e) {
|
|
155
|
+
(this.viewContext ??= {}).view = e.view, Object.assign(this.original ??= {}, {
|
|
156
|
+
color: e.color,
|
|
157
|
+
depth: e.depth,
|
|
158
|
+
format: e.format,
|
|
159
|
+
descriptor: e.descriptor,
|
|
160
|
+
owner: h(e)
|
|
161
|
+
}), e.color = this.color, e.depth = this.depth, e.format = this.resolvedColor.format, this.baseDescriptor !== e.descriptor && (this.baseDescriptor = e.descriptor, this.descriptor = {
|
|
162
|
+
...e.descriptor,
|
|
163
|
+
depthStencil: {
|
|
164
|
+
...e.descriptor.depthStencil,
|
|
165
|
+
format: this.resolvedDepth.format
|
|
166
|
+
},
|
|
167
|
+
multisample: { count: this.samples }
|
|
168
|
+
}), e.descriptor = this.descriptor, e[u] = this, this.retired = !1, this.resized = e.width !== void 0 && (e.width !== this.resolvedDepth.width || e.height !== this.resolvedDepth.height);
|
|
169
|
+
}
|
|
170
|
+
copyDepth(e, t, n, r = this.resolvedDepth.format) {
|
|
171
|
+
this.depthSource ??= this.resolvedDepth.createView({ aspect: "depth-only" }), p(this, e, t, n, r, this.viewContext);
|
|
172
|
+
}
|
|
173
|
+
resolve(e, t = !1, n = !0) {
|
|
174
|
+
if (this.samples === 1) t && this.give(e);
|
|
175
|
+
else {
|
|
176
|
+
if (n && this.copyDepth(e, this.resolvedDepthView, 1), t) {
|
|
177
|
+
let t = this.viewContext?.view ? "store" : "discard";
|
|
178
|
+
this.finalResolution.colorAttachments[0].storeOp = t, this.finalResolution.depthStencilAttachment.depthStoreOp = t, this.give(e);
|
|
179
|
+
}
|
|
180
|
+
e.beginRenderPass(t ? this.finalResolution : this.resolution).end();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
give(e) {
|
|
184
|
+
let t = this.original;
|
|
185
|
+
this.retired || !t || this.resized || (this.copyDepth(e, t.depth, t.descriptor.multisample?.count ?? 1, t.descriptor.depthStencil.format), this.retired = !0);
|
|
186
|
+
}
|
|
187
|
+
restore(e) {
|
|
188
|
+
let t = this.original;
|
|
189
|
+
this.give(e.encoder), Object.assign(e, {
|
|
190
|
+
color: t.color,
|
|
191
|
+
depth: t.depth,
|
|
192
|
+
format: t.format,
|
|
193
|
+
descriptor: t.descriptor
|
|
194
|
+
}), e[u] = t.owner;
|
|
195
|
+
}
|
|
196
|
+
present(e) {
|
|
197
|
+
this.resolve(e.encoder, !0), this.restore(e);
|
|
198
|
+
let r = e.descriptor.multisample?.count ?? 1;
|
|
199
|
+
if (!this.presentation || this.presentationFormat !== e.format || this.presentationSamples !== r) {
|
|
200
|
+
let t = this.device.createShaderModule({ code: c + "@group(0) @binding(0) var source:texture_2d<f32>;@fragment fn fragment(@builtin(position) p:vec4f)->@location(0) vec4f{return textureLoad(source,vec2i(p.xy),0);}" });
|
|
201
|
+
this.presentation = this.device.createRenderPipeline({
|
|
202
|
+
layout: "auto",
|
|
203
|
+
vertex: {
|
|
204
|
+
module: t,
|
|
205
|
+
entryPoint: "vertex"
|
|
206
|
+
},
|
|
207
|
+
fragment: {
|
|
208
|
+
module: t,
|
|
209
|
+
entryPoint: "fragment",
|
|
210
|
+
targets: [{ format: e.format }]
|
|
211
|
+
},
|
|
212
|
+
multisample: e.descriptor.multisample
|
|
213
|
+
}), this.presentationGroup = l(this.device, this.presentation, this.resolvedColor.createView()), this.presentationFormat = e.format, this.presentationSamples = r;
|
|
214
|
+
}
|
|
215
|
+
let i = this.presentationPass ??= { colorAttachments: [{
|
|
216
|
+
view: e.color,
|
|
217
|
+
loadOp: "clear",
|
|
218
|
+
storeOp: "store"
|
|
219
|
+
}] };
|
|
220
|
+
i.colorAttachments[0].view = e.color, i.colorAttachments[0].loadOp = n(e, "clear");
|
|
221
|
+
let a = e.encoder.beginRenderPass(i);
|
|
222
|
+
a.setPipeline(this.presentation), a.setBindGroup(0, this.presentationGroup), t(a, e), a.draw(3), a.end();
|
|
223
|
+
}
|
|
224
|
+
dispose() {
|
|
225
|
+
for (let e of this.textures) a(this.device, e);
|
|
226
|
+
this.textures = [], this.pipelines.clear();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function h(e) {
|
|
230
|
+
let t = e[u];
|
|
231
|
+
return t?.color === e.color && t.depth === e.depth ? t : void 0;
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region ../shared/gpu.js
|
|
235
|
+
var g = "\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}";
|
|
236
|
+
function _(e, t, n) {
|
|
237
|
+
return e.createBindGroup({
|
|
238
|
+
layout: t.getBindGroupLayout(0),
|
|
239
|
+
entries: n.map((e, t) => ({
|
|
240
|
+
binding: t,
|
|
241
|
+
resource: e
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function v(e, t, n, r = {}) {
|
|
246
|
+
let i = e.createShaderModule({ code: t });
|
|
247
|
+
return e.createRenderPipeline({
|
|
248
|
+
layout: "auto",
|
|
249
|
+
vertex: {
|
|
250
|
+
module: i,
|
|
251
|
+
entryPoint: "vertex"
|
|
252
|
+
},
|
|
253
|
+
fragment: {
|
|
254
|
+
module: i,
|
|
255
|
+
entryPoint: "fragment",
|
|
256
|
+
targets: [{ format: n }]
|
|
257
|
+
},
|
|
258
|
+
...r
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function y(e, r, i, a = "load") {
|
|
262
|
+
let o = e.encoder.beginRenderPass({ colorAttachments: [{
|
|
263
|
+
view: e.color,
|
|
264
|
+
loadOp: n(e, a),
|
|
265
|
+
storeOp: "store"
|
|
266
|
+
}] });
|
|
267
|
+
o.setPipeline(r), o.setBindGroup(0, i), t(o, e), o.draw(3), o.end();
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/builtin.ts
|
|
271
|
+
var b = [
|
|
272
|
+
"wipe",
|
|
273
|
+
"dissolve",
|
|
274
|
+
"radial",
|
|
275
|
+
"chromatic"
|
|
276
|
+
], x = g + "\n@group(0) @binding(0) var<uniform> settings:vec4f;\n@group(0) @binding(1) var before:texture_2d<f32>;\n@group(0) @binding(2) var after:texture_2d<f32>;\nfn sample(t:texture_2d<f32>,uv:vec2f)->vec4f {let size=vec2i(textureDimensions(t));return textureLoad(t,clamp(vec2i(uv*vec2f(size)),vec2i(0),size-1),0);}\n\n\nfn dissolvePcg(v:u32)->u32 {let s=v*747796405u+2891336453u;let w=((s>>((s>>28u)+4u))^s)*277803737u;return (w>>22u)^w;}\nfn dissolveThreshold(pixel:vec2u)->f32 {return f32(dissolvePcg(pixel.x+dissolvePcg(pixel.y))>>8u)*5.9604645e-8;}\n@fragment fn fragment(i:Vertex)->@location(0) vec4f {\n let uv=i.position.xy/vec2f(textureDimensions(after));\n let p=settings.x;if(p<=0.0){return sample(before,uv);}if(p>=1.0){return sample(after,uv);}\n if(settings.y==4.0){return mix(sample(before,uv),sample(after,uv),p);}\n var edge=uv.x;\n if(settings.y==1.0){edge=dissolveThreshold(vec2u(i.position.xy));}\n if(settings.y==2.0){edge=fract(atan2(uv.x-0.5,0.5-uv.y)/6.2831853+1.0);}\n if(settings.y==3.0){let shift=vec2f(sin(p*3.14159265)*settings.z,0);let a=sample(after,uv+shift);let b=sample(after,uv-shift);return mix(sample(before,uv),vec4f(a.r,sample(after,uv).g,b.b,1),p);}\n return mix(sample(before,uv),sample(after,uv),1.0-smoothstep(p-0.01,p+0.01,edge));\n}";
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/formats.ts
|
|
279
|
+
function S(e, t) {
|
|
280
|
+
return /^(?:(?:r|rg|rgba)(?:8|16|32)(?:unorm|snorm|float)(?:-srgb)?|bgra8unorm(?:-srgb)?|rgb10a2unorm|rg11b10ufloat)$/.test(e) && !(t > 1 && /32float$/.test(e));
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
export { g as a, m as c, y as i, b as n, _ as o, x as r, v as s, S as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function floatOutput(format: GPUTextureFormat, samples: number): boolean;
|
package/dist/glsl.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EngineKernel, Scene } from '@margoengine/core';
|
|
2
|
+
import { type CustomTransitionOptions } from './custom.js';
|
|
3
|
+
import { LiveTransitions, type LiveTransitionOptions } from './live.js';
|
|
4
|
+
import type { Transitions } from './index.js';
|
|
5
|
+
/** A scalar or flattened vector, column-major matrix or fixed array uniform value. */
|
|
6
|
+
export type GLSLUniformValue = number | boolean | readonly (number | boolean)[];
|
|
7
|
+
/** Values and coordinate convention for importing a GLSL transition. */
|
|
8
|
+
export interface GLSLTransitionOptions {
|
|
9
|
+
/** Additional uniform values, snapshotted into WGSL constants. Default values come from // = JSON annotations. */
|
|
10
|
+
uniforms?: Readonly<Record<string, GLSLUniformValue>>;
|
|
11
|
+
/** GLSL UVs use bottom-left origin by default; false preserves the custom entry's top-left origin. Default true. */
|
|
12
|
+
flipY?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Translates trusted GLSL ES 1.00 or 3.00 (`#version 300 es`) containing vec4 transition(vec2 uv) to the custom WGSL function contract.
|
|
16
|
+
* Exposes progress, ratio, getFromColor/getToColor, and from/to sampler2D aliases. No external shader assets are bundled.
|
|
17
|
+
* Syntax/type diagnostics carry code failed; asynchronous factory compilation validates the emitted WGSL before attachment.
|
|
18
|
+
*/
|
|
19
|
+
export declare function translateGLSLTransition(source: string, options?: GLSLTransitionOptions): string;
|
|
20
|
+
/** Compiles and attaches a frozen GLSL transition. Call start('wipe',seconds); supplied GLSL controls the treatment. */
|
|
21
|
+
export declare function createGLSLTransition(engine: EngineKernel, source: string, options?: GLSLTransitionOptions & CustomTransitionOptions): Promise<Transitions>;
|
|
22
|
+
/** Compiles and attaches a GLSL transition between borrowed live scenes and cameras. */
|
|
23
|
+
export declare function createLiveGLSLTransition(engine: EngineKernel, before: Scene, after: Scene, source: string, options?: GLSLTransitionOptions & Pick<LiveTransitionOptions, 'beforeCamera' | 'afterCamera'> & CustomTransitionOptions): Promise<LiveTransitions>;
|