@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
/**
|
|
5
|
+
* How `start()` reveals the new scene over the frozen frame: `'wipe'` left to right, `'dissolve'` per-pixel random,
|
|
6
|
+
* `'radial'` a clockwise sweep around the centre, `'chromatic'` a cross-fade with red/blue split by `displacement`.
|
|
7
|
+
*/
|
|
8
|
+
export type TransitionKind = 'wipe' | 'dissolve' | 'radial' | 'chromatic';
|
|
9
|
+
/**
|
|
10
|
+
* start() freezes the last rendered frame while the scene underneath changes. WebGPU only.
|
|
11
|
+
* @throws RangeError from `start` for an unknown kind, `seconds` outside (0, 60] or `displacement` outside 0-0.25.
|
|
12
|
+
* @throws MargoError `'unsupported'` on a WebGL engine, `'disposed'` after `dispose()`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Transitions implements EnginePlugin {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** Nest optional captures inside the built-in capture and composite them in reverse order. */
|
|
17
|
+
protected readonly captureLayer: number;
|
|
18
|
+
/** Shader source supplied by optional transition entries. */
|
|
19
|
+
protected shaderCode: string;
|
|
20
|
+
/** Image bindings used by optional entries; images remain owned by the capture. */
|
|
21
|
+
protected transitionBindings(before: GPUTexture, after: GPUTexture): GPUBindingResource[];
|
|
22
|
+
private engine?;
|
|
23
|
+
private uniform?;
|
|
24
|
+
private scene?;
|
|
25
|
+
private previous?;
|
|
26
|
+
private pipeline?;
|
|
27
|
+
private bind?;
|
|
28
|
+
private capture?;
|
|
29
|
+
private depth?;
|
|
30
|
+
private format?;
|
|
31
|
+
private request;
|
|
32
|
+
private duration;
|
|
33
|
+
private elapsed;
|
|
34
|
+
private readonly values;
|
|
35
|
+
private disposed;
|
|
36
|
+
constructor();
|
|
37
|
+
static attach(engine: EngineKernel): Transitions;
|
|
38
|
+
get progress(): number;
|
|
39
|
+
start(kind?: TransitionKind, seconds?: number, displacement?: number): void;
|
|
40
|
+
setup(engine: Engine): void;
|
|
41
|
+
registerPasses(graph: FrameGraph): void;
|
|
42
|
+
private release;
|
|
43
|
+
onDeviceRestored(engine: Engine): void;
|
|
44
|
+
dispose(): void;
|
|
45
|
+
[Symbol.dispose]: () => void;
|
|
46
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const s=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { c as e, i as t, n, o as r, r as i, s as a, t as o } from "./formats-C_gWhYlk.js";
|
|
5
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
6
|
+
import { MargoError as c } from "@margoengine/math/errors";
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
var l = class l {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
9
|
+
transitionBindings(e, t) {
|
|
10
|
+
return [
|
|
11
|
+
{ buffer: this.uniform },
|
|
12
|
+
e.createView(),
|
|
13
|
+
t.createView()
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
constructor() {
|
|
17
|
+
this.name = "transitions", this.captureLayer = 0, this.shaderCode = i, this.request = !1, this.duration = 1, this.elapsed = 1, this.values = new Float32Array([
|
|
18
|
+
1,
|
|
19
|
+
0,
|
|
20
|
+
.02,
|
|
21
|
+
0
|
|
22
|
+
]), this.disposed = !1;
|
|
23
|
+
}
|
|
24
|
+
static attach(e) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
25
|
+
let t = new l();
|
|
26
|
+
return s(e).use(t), t;
|
|
27
|
+
}
|
|
28
|
+
get progress() {
|
|
29
|
+
return Math.min(1, this.elapsed / this.duration);
|
|
30
|
+
}
|
|
31
|
+
start(e = "wipe", t = 1, r = .02) {
|
|
32
|
+
if (this.disposed) throw new c("disposed", "Transitions is disposed; create a new Transitions");
|
|
33
|
+
if (!n.includes(e) || !Number.isFinite(t) || t <= 0 || t > 60 || !Number.isFinite(r) || r < 0 || r > .25) throw RangeError("Transition needs a known kind, seconds up to 60 and displacement up to 0.25; check the arguments.");
|
|
34
|
+
this.duration = t, this.elapsed = 0, this.values[1] = n.indexOf(e), this.values[2] = r, this.request = !0;
|
|
35
|
+
}
|
|
36
|
+
setup(e) {
|
|
37
|
+
if (this.disposed || !e.gpu) throw new c(this.disposed ? "disposed" : "unsupported", "Transitions requires WebGPU; attach a new Transitions to a WebGPU engine; see https://margoengine.com/errors#unsupported");
|
|
38
|
+
this.engine = e, this.uniform = e.gpu.createBuffer({
|
|
39
|
+
size: 16,
|
|
40
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
registerPasses(n) {
|
|
44
|
+
n.add({
|
|
45
|
+
name: `${this.name}:capture`,
|
|
46
|
+
order: -80 + this.captureLayer,
|
|
47
|
+
execute: (t) => {
|
|
48
|
+
if (t.backend === "webgpu") {
|
|
49
|
+
if (!o(t.format, t.descriptor.multisample?.count ?? 1)) throw TypeError("Transitions need a float color render attachment with MSAA resolve support; choose rgba8unorm");
|
|
50
|
+
if (this.scene?.width !== t.width || this.scene?.height !== t.height || this.format !== t.format || this.depth?.format !== t.descriptor.depthStencil.format || this.capture?.samples !== (t.descriptor.multisample?.count ?? 1)) {
|
|
51
|
+
let n = this.request ? this.scene : this.elapsed < this.duration ? this.previous : void 0;
|
|
52
|
+
this.capture?.dispose(), this.depth?.destroy(), this.scene !== n && this.scene?.destroy(), this.previous !== n && this.previous?.destroy(), this.format = t.format, this.scene = t.device.createTexture({
|
|
53
|
+
size: [t.width, t.height],
|
|
54
|
+
format: t.format,
|
|
55
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC
|
|
56
|
+
}), this.previous = n ?? t.device.createTexture({
|
|
57
|
+
size: [t.width, t.height],
|
|
58
|
+
format: t.format,
|
|
59
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
|
|
60
|
+
}), this.depth = t.device.createTexture({
|
|
61
|
+
size: [t.width, t.height],
|
|
62
|
+
format: t.descriptor.depthStencil.format,
|
|
63
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
64
|
+
}), this.capture = new e(t.device, this.scene, this.depth, t.descriptor.multisample?.count ?? 1), this.pipeline = a(t.device, this.shaderCode, t.format, { multisample: t.descriptor.multisample }), this.bind = r(t.device, this.pipeline, this.transitionBindings(this.previous, this.scene)), this.request = !1;
|
|
65
|
+
}
|
|
66
|
+
this.request &&= ((this.previous.width !== t.width || this.previous.height !== t.height || this.previous.format !== t.format || !(this.previous.usage & GPUTextureUsage.COPY_DST)) && (this.previous.destroy(), this.previous = t.device.createTexture({
|
|
67
|
+
size: [t.width, t.height],
|
|
68
|
+
format: t.format,
|
|
69
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
|
|
70
|
+
}), this.bind = r(t.device, this.pipeline, this.transitionBindings(this.previous, this.scene))), t.encoder.copyTextureToTexture({ texture: this.scene }, { texture: this.previous }, [t.width, t.height]), !1), this.capture.begin(t);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}), n.add({
|
|
74
|
+
name: `${this.name}:blend`,
|
|
75
|
+
order: 50 - this.captureLayer,
|
|
76
|
+
execute: (e) => {
|
|
77
|
+
e.backend === "webgpu" && (this.elapsed = Math.min(this.duration, this.elapsed + e.delta), this.values[0] = this.progress, e.device.queue.writeBuffer(this.uniform, 0, this.values), this.capture.resolve(e.encoder, !0), this.capture.restore(e), t(e, this.pipeline, this.bind, "clear"));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
release() {
|
|
82
|
+
this.capture?.dispose(), this.depth?.destroy(), this.capture = void 0, this.depth = void 0, this.uniform?.destroy(), this.scene?.destroy(), this.previous?.destroy(), this.uniform = this.scene = this.previous = void 0, this.pipeline = this.bind = void 0;
|
|
83
|
+
}
|
|
84
|
+
onDeviceRestored(e) {
|
|
85
|
+
this.release(), this.elapsed = this.duration, this.request = !1, this.setup(e);
|
|
86
|
+
}
|
|
87
|
+
dispose() {
|
|
88
|
+
this.disposed || (this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.release(), this.engine = void 0);
|
|
89
|
+
}
|
|
90
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
91
|
+
this.dispose();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { l as Transitions };
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, Scene, Camera } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
import type { TransitionKind } from './index.js';
|
|
5
|
+
/** Cameras borrowed for the two scenes. Neither camera nor scene is disposed by the transition. */
|
|
6
|
+
export interface LiveTransitionOptions {
|
|
7
|
+
/** Initial built-in kind. Default crossfade. Use start(kind, seconds) to select another. */
|
|
8
|
+
kind?: TransitionKind | 'crossfade';
|
|
9
|
+
/** Optional greyscale mask. ImageData is copied; keep a borrowed ImageBitmap open through disposal. */
|
|
10
|
+
mask?: ImageData | ImageBitmap;
|
|
11
|
+
/** Mask threshold half-width. Default 0.02; zero is a hard edge, otherwise 0.000001..1. */
|
|
12
|
+
softness?: number;
|
|
13
|
+
/** Outgoing camera. Default engine.camera. */
|
|
14
|
+
beforeCamera?: Camera;
|
|
15
|
+
/** Incoming camera. Default engine.camera. */
|
|
16
|
+
afterCamera?: Camera;
|
|
17
|
+
}
|
|
18
|
+
/** One explicit frame of both scenes and their cross-fade. */
|
|
19
|
+
export interface LiveTransitionFrame {
|
|
20
|
+
/** Seconds to advance each scene and progress, finite 0..1. Default 0. */
|
|
21
|
+
delta?: number;
|
|
22
|
+
/** Optional borrowed single-sample output texture. Default full canvas. */
|
|
23
|
+
target?: GPUTexture;
|
|
24
|
+
/** Scene frustum culling. Default true. */
|
|
25
|
+
culling?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Renders two live scenes every frame, then composites their resolved RGBA8 images. WebGPU only. */
|
|
28
|
+
export declare class LiveTransitions implements EnginePlugin {
|
|
29
|
+
private readonly engine;
|
|
30
|
+
private readonly before;
|
|
31
|
+
private readonly after;
|
|
32
|
+
private readonly options;
|
|
33
|
+
readonly name = "transitions:live";
|
|
34
|
+
private output?;
|
|
35
|
+
private code;
|
|
36
|
+
private mask?;
|
|
37
|
+
private maskSource?;
|
|
38
|
+
private images;
|
|
39
|
+
private uniform?;
|
|
40
|
+
private pipeline?;
|
|
41
|
+
private bind?;
|
|
42
|
+
private format?;
|
|
43
|
+
private samples;
|
|
44
|
+
private elapsed;
|
|
45
|
+
private duration;
|
|
46
|
+
private disposed;
|
|
47
|
+
private readonly values;
|
|
48
|
+
private constructor();
|
|
49
|
+
/** Attaches an owned composite scene. Pass two distinct live scenes from this engine. */
|
|
50
|
+
static attach(engine: EngineKernel, before: Scene, after: Scene, options?: LiveTransitionOptions): LiveTransitions;
|
|
51
|
+
get progress(): number;
|
|
52
|
+
/** Restarts the current kind; duration defaults to 1 second, finite (0,60]. */
|
|
53
|
+
start(seconds?: number): void;
|
|
54
|
+
/** Selects a built-in kind. Displacement defaults to 0.02, finite 0..0.25. Masks and custom shaders ignore kind. */
|
|
55
|
+
start(kind: TransitionKind | 'crossfade', seconds?: number, displacement?: number): void;
|
|
56
|
+
private configureMask;
|
|
57
|
+
/** Validates trusted WGSL before attaching. Same transition function and sample helper as the custom entry. */
|
|
58
|
+
static custom(engine: EngineKernel, before: Scene, after: Scene, wgsl: string, options?: Omit<LiveTransitionOptions, 'mask' | 'softness' | 'kind'> & {
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
}): Promise<LiveTransitions>;
|
|
61
|
+
private live;
|
|
62
|
+
/** Draws both scenes once and then the composite. Use this instead of engine.render for transition frames. */
|
|
63
|
+
render({ delta, target, culling }?: LiveTransitionFrame): void;
|
|
64
|
+
setup(engine: Engine): void;
|
|
65
|
+
registerPasses(graph: FrameGraph): void;
|
|
66
|
+
private releaseImages;
|
|
67
|
+
onDeviceRestored(engine: Engine): void;
|
|
68
|
+
dispose(): void;
|
|
69
|
+
[Symbol.dispose]: () => void;
|
|
70
|
+
}
|
package/dist/live.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const u=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { t as e } from "./errors-CsQwshHA.js";
|
|
5
|
+
import { a as t, i as n, n as r, o as i, r as a, s as o, t as s } from "./formats-C_gWhYlk.js";
|
|
6
|
+
import { t as c } from "./custom-code-D9Y4mDt8.js";
|
|
7
|
+
import { Camera as l, engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
8
|
+
//#region src/live.ts
|
|
9
|
+
var d = class d {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
10
|
+
constructor(e, t, n, r) {
|
|
11
|
+
this.engine = e, this.before = t, this.after = n, this.options = r, this.name = "transitions:live", this.code = a, this.images = [], this.samples = 0, this.elapsed = 1, this.duration = 1, this.disposed = !1, this.values = new Float32Array([
|
|
12
|
+
1,
|
|
13
|
+
4,
|
|
14
|
+
.02,
|
|
15
|
+
0
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
static attach(t, n, i, a = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
19
|
+
let o = u(t);
|
|
20
|
+
if (!o.gpu) throw e("unsupported", "Live transitions require WebGPU; select a WebGPU engine");
|
|
21
|
+
if (o.disposed) throw e("disposed", "Engine is disposed; create a new engine");
|
|
22
|
+
if (n === i || !o.scenes.has(n) || !o.scenes.has(i)) throw TypeError("Live transitions need two distinct live scenes from this engine; use engine.createScene()");
|
|
23
|
+
if (a.beforeCamera && !(a.beforeCamera instanceof l) || a.afterCamera && !(a.afterCamera instanceof l)) throw TypeError("Live transition cameras must be Camera instances; use engine.camera or new Camera()");
|
|
24
|
+
let s = new d(o, n, i, { ...a }), c = a.kind ?? "crossfade";
|
|
25
|
+
if (c !== "crossfade" && !r.includes(c)) throw RangeError("Unknown live transition kind; choose wipe, dissolve, radial, chromatic or crossfade");
|
|
26
|
+
s.values[1] = c === "crossfade" ? 4 : r.indexOf(c), a.mask && s.configureMask(a.mask, a.softness ?? .02), s.output = t.createScene("transitions:live");
|
|
27
|
+
try {
|
|
28
|
+
s.output.use(s);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw s.dispose(), e;
|
|
31
|
+
}
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
get progress() {
|
|
35
|
+
return Math.min(1, this.elapsed / this.duration);
|
|
36
|
+
}
|
|
37
|
+
start(e = 1, t = 1, n = .02) {
|
|
38
|
+
this.live();
|
|
39
|
+
let i = typeof e == "number" ? this.values[1] : e === "crossfade" ? 4 : r.indexOf(e), a = typeof e == "number" ? e : t;
|
|
40
|
+
if (!Number.isFinite(a) || a <= 0 || a > 60 || i < 0 || !Number.isFinite(n) || n < 0 || n > .25) throw RangeError("Live transition needs a known kind, seconds in (0,60] and displacement in [0,0.25]; check start arguments");
|
|
41
|
+
this.duration = a, this.elapsed = 0, this.values[1] = i, this.values[2] = n;
|
|
42
|
+
}
|
|
43
|
+
configureMask(e, n) {
|
|
44
|
+
let r = typeof ImageData < "u" && e instanceof ImageData, i = typeof ImageBitmap < "u" && e instanceof ImageBitmap;
|
|
45
|
+
if (!r && !i || r && !(e.data instanceof Uint8ClampedArray)) throw TypeError("Live mask needs 8-bit ImageData or an open ImageBitmap; decode the image first");
|
|
46
|
+
let a = Math.min(4096, this.engine.gpu.limits.maxTextureDimension2D);
|
|
47
|
+
if (![e.width, e.height].every((e) => Number.isSafeInteger(e) && e > 0 && e <= a)) throw RangeError("Live mask dimensions exceed device limits; use an image of 1..min(4096, device limit)");
|
|
48
|
+
if (!Number.isFinite(n) || n < 0 || n > 1 || n > 0 && n < 1e-6) throw RangeError("Live mask softness is out of range; use zero or 0.000001..1");
|
|
49
|
+
this.maskSource = r ? {
|
|
50
|
+
width: e.width,
|
|
51
|
+
height: e.height,
|
|
52
|
+
data: e.data.slice()
|
|
53
|
+
} : e, this.code = `${t}
|
|
54
|
+
@group(0) @binding(0) var<uniform> settings:vec4f;
|
|
55
|
+
@group(0) @binding(1) var before:texture_2d<f32>;
|
|
56
|
+
@group(0) @binding(2) var after:texture_2d<f32>;
|
|
57
|
+
@group(0) @binding(3) var mask:texture_2d<f32>;
|
|
58
|
+
fn sample(t:texture_2d<f32>,pixel:vec2u,extent:vec2u)->vec4f {
|
|
59
|
+
let n=textureDimensions(t);let q=(pixel*n+n/2u)/extent;
|
|
60
|
+
return textureLoad(t,vec2i(min(q,n-1u)),0);
|
|
61
|
+
}
|
|
62
|
+
@fragment fn fragment(i:Vertex)->@location(0) vec4f {
|
|
63
|
+
let p=settings.x;let pixel=vec2u(i.position.xy);let extent=textureDimensions(after);
|
|
64
|
+
if(p<=0.0){return sample(before,pixel,extent);}if(p>=1.0){return sample(after,pixel,extent);}
|
|
65
|
+
let edge=sample(mask,pixel,extent).r;
|
|
66
|
+
let weight=${n === 0 ? "select(0.0,1.0,edge<=p)" : `1.0-smoothstep(p-f32(${n}),p+f32(${n}),edge)`};
|
|
67
|
+
return mix(sample(before,pixel,extent),sample(after,pixel,extent),weight);
|
|
68
|
+
}`;
|
|
69
|
+
}
|
|
70
|
+
static async custom(e, t, n, r, i = {}) {
|
|
71
|
+
let a = await c(e, r, i.signal), o = d.attach(e, t, n, i);
|
|
72
|
+
return o.code = a, o;
|
|
73
|
+
}
|
|
74
|
+
live() {
|
|
75
|
+
if (this.disposed || this.engine.disposed) throw e("disposed", "Live transition is disposed; attach a new one");
|
|
76
|
+
}
|
|
77
|
+
render({ delta: t = 0, target: n, culling: r = !0 } = {}) {
|
|
78
|
+
if (this.live(), !Number.isFinite(t) || t < 0 || t > 1) throw RangeError("Live transition delta must be finite in [0,1]; pass seconds");
|
|
79
|
+
let i = this.engine.gpu;
|
|
80
|
+
if (!i) throw e("state", "Live transition device is unavailable; wait for engine recovery");
|
|
81
|
+
if (!this.engine.scenes.has(this.before) || !this.engine.scenes.has(this.after)) throw e("state", "A live transition scene was disposed; attach two live scenes");
|
|
82
|
+
let a = n?.width ?? this.engine.canvas.width, o = n?.height ?? this.engine.canvas.height;
|
|
83
|
+
if (![a, o].every((e) => Number.isSafeInteger(e) && e > 0 && e <= i.limits.maxTextureDimension2D)) throw RangeError("Live transition dimensions must fit the device texture limit; resize the output");
|
|
84
|
+
if (n && (!(n.usage & GPUTextureUsage.RENDER_ATTACHMENT) || n.sampleCount !== 1 || n.dimension !== "2d" || n.depthOrArrayLayers !== 1 || !s(n.format, this.engine.renderTarget?.samples ?? 1) || this.images.includes(n))) throw TypeError("Live transition target must be a separate single-sample 2D float color render attachment with MSAA resolve support; choose rgba8unorm");
|
|
85
|
+
if (this.maskSource && Math.max(a, o) > 65535) throw RangeError("Live mask captures exceed integer addressing limits; use dimensions at most 65535");
|
|
86
|
+
if (this.images[0]?.width !== a || this.images[0]?.height !== o) {
|
|
87
|
+
this.releaseImages();
|
|
88
|
+
try {
|
|
89
|
+
for (let e = 0; e < 2; e++) this.images.push(i.createTexture({
|
|
90
|
+
size: [a, o],
|
|
91
|
+
format: "rgba8unorm",
|
|
92
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
93
|
+
}));
|
|
94
|
+
} catch (e) {
|
|
95
|
+
throw this.releaseImages(), e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.engine.render({
|
|
99
|
+
delta: t,
|
|
100
|
+
culling: r,
|
|
101
|
+
views: [
|
|
102
|
+
{
|
|
103
|
+
scene: this.before,
|
|
104
|
+
camera: this.options.beforeCamera ?? this.engine.camera,
|
|
105
|
+
viewport: [
|
|
106
|
+
0,
|
|
107
|
+
0,
|
|
108
|
+
1,
|
|
109
|
+
1
|
|
110
|
+
],
|
|
111
|
+
target: { color: this.images[0] }
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
scene: this.after,
|
|
115
|
+
camera: this.options.afterCamera ?? this.engine.camera,
|
|
116
|
+
viewport: [
|
|
117
|
+
0,
|
|
118
|
+
0,
|
|
119
|
+
1,
|
|
120
|
+
1
|
|
121
|
+
],
|
|
122
|
+
target: { color: this.images[1] }
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
scene: this.output,
|
|
126
|
+
camera: this.engine.camera,
|
|
127
|
+
viewport: [
|
|
128
|
+
0,
|
|
129
|
+
0,
|
|
130
|
+
1,
|
|
131
|
+
1
|
|
132
|
+
],
|
|
133
|
+
target: n ? { color: n } : void 0
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
setup(t) {
|
|
139
|
+
let n = this.maskSource;
|
|
140
|
+
if (n) {
|
|
141
|
+
if (n.width < 1 || n.height < 1) throw e("state", "Live mask bitmap is closed; keep it open until transition disposal");
|
|
142
|
+
this.mask = t.gpu.createTexture({
|
|
143
|
+
size: [n.width, n.height],
|
|
144
|
+
format: "rgba8unorm",
|
|
145
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
|
|
146
|
+
}), "data" in n ? t.gpu.queue.writeTexture({ texture: this.mask }, n.data, { bytesPerRow: n.width * 4 }, [n.width, n.height]) : t.gpu.queue.copyExternalImageToTexture({ source: n }, { texture: this.mask }, [n.width, n.height]);
|
|
147
|
+
}
|
|
148
|
+
this.uniform = t.gpu.createBuffer({
|
|
149
|
+
size: 16,
|
|
150
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
registerPasses(e) {
|
|
154
|
+
e.add({
|
|
155
|
+
name: this.name,
|
|
156
|
+
order: 50,
|
|
157
|
+
execute: (e) => {
|
|
158
|
+
if (e.backend !== "webgpu" || !this.images.length) return;
|
|
159
|
+
let t = e.descriptor.multisample?.count ?? 1;
|
|
160
|
+
(!this.pipeline || this.format !== e.format || this.samples !== t) && (this.pipeline = o(e.device, this.code, e.format, { multisample: { count: t } }), this.format = e.format, this.samples = t, this.bind = void 0), this.bind ??= i(e.device, this.pipeline, [
|
|
161
|
+
{ buffer: this.uniform },
|
|
162
|
+
this.images[0].createView(),
|
|
163
|
+
this.images[1].createView(),
|
|
164
|
+
...this.mask ? [this.mask.createView()] : []
|
|
165
|
+
]), this.elapsed = Math.min(this.duration, this.elapsed + e.delta), this.values[0] = this.progress, e.device.queue.writeBuffer(this.uniform, 0, this.values), n(e, this.pipeline, this.bind, "clear");
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
releaseImages() {
|
|
170
|
+
for (let e of this.images) e.destroy();
|
|
171
|
+
this.images = [], this.bind = void 0;
|
|
172
|
+
}
|
|
173
|
+
onDeviceRestored(e) {
|
|
174
|
+
this.releaseImages(), this.uniform?.destroy(), this.mask?.destroy(), this.mask = void 0, this.pipeline = void 0, this.setup(e);
|
|
175
|
+
}
|
|
176
|
+
dispose() {
|
|
177
|
+
this.disposed || (this.disposed = !0, this.engine.sceneOf(this)?.removePlugin(this.name), this.output?.dispose(), this.output = void 0, this.releaseImages(), this.uniform?.destroy(), this.mask?.destroy(), this.mask = void 0, this.maskSource = void 0, this.uniform = void 0, this.pipeline = void 0);
|
|
178
|
+
}
|
|
179
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
180
|
+
this.dispose();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
//#endregion
|
|
184
|
+
export { d as LiveTransitions };
|
package/dist/mask.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
2
|
+
import { Transitions } from './index.js';
|
|
3
|
+
/** Texture-mask edge settings. The red channel of a greyscale image sets reveal order. */
|
|
4
|
+
export interface MaskTransitionOptions {
|
|
5
|
+
/** Threshold half-width, default 0.02. Zero is hard; otherwise finite 0.000001..1. */
|
|
6
|
+
softness?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Attaches a greyscale texture wipe. Black reveals first and white last; alpha is ignored.
|
|
10
|
+
* ImageData bytes are snapshotted. A borrowed ImageBitmap must remain open until disposal, for device restoration.
|
|
11
|
+
* Images stretch to the full capture using clamped nearest sampling, top-left origin; image dimensions 1..min(4096, device limit).
|
|
12
|
+
* Capture dimensions must be at most 65535 for overflow-free integer centre addressing.
|
|
13
|
+
* Call the returned start('wipe', seconds); kind and displacement do not affect the mask.
|
|
14
|
+
* @throws TypeError for anything except 8-bit ImageData or an open ImageBitmap.
|
|
15
|
+
* @throws RangeError for invalid softness or image dimensions.
|
|
16
|
+
* @throws MargoError `unsupported` with help on WebGL2.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createMaskTransition(engine: EngineKernel, image: ImageData | ImageBitmap, options?: MaskTransitionOptions): Transitions;
|
package/dist/mask.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const r=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { t as e } from "./errors-CsQwshHA.js";
|
|
5
|
+
import { a as t } from "./formats-C_gWhYlk.js";
|
|
6
|
+
import { Transitions as n } from "./index.js";
|
|
7
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
8
|
+
//#region src/mask.ts
|
|
9
|
+
var i = class extends n {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
10
|
+
constructor(e, n) {
|
|
11
|
+
super(), this.source = e, this.name = "transitions:mask", this.captureLayer = 1, this.shaderCode = `${t}
|
|
12
|
+
@group(0) @binding(0) var<uniform> settings:vec4f;
|
|
13
|
+
@group(0) @binding(1) var before:texture_2d<f32>;
|
|
14
|
+
@group(0) @binding(2) var after:texture_2d<f32>;
|
|
15
|
+
@group(0) @binding(3) var mask:texture_2d<f32>;
|
|
16
|
+
|
|
17
|
+
fn sample(t:texture_2d<f32>,pixel:vec2u,extent:vec2u)->vec4f {
|
|
18
|
+
let n=textureDimensions(t);let q=(pixel*n+n/2u)/extent;
|
|
19
|
+
return textureLoad(t,vec2i(min(q,n-1u)),0);
|
|
20
|
+
}
|
|
21
|
+
@fragment fn fragment(i:Vertex)->@location(0) vec4f {
|
|
22
|
+
let p=settings.x;let pixel=vec2u(i.position.xy);let extent=textureDimensions(after);
|
|
23
|
+
if(p<=0.0){return sample(before,pixel,extent);}if(p>=1.0){return sample(after,pixel,extent);}
|
|
24
|
+
let edge=sample(mask,pixel,extent).r;
|
|
25
|
+
let weight=${n === 0 ? "select(0.0,1.0,edge<=p)" : `1.0-smoothstep(p-f32(${n}),p+f32(${n}),edge)`};
|
|
26
|
+
return mix(sample(before,pixel,extent),sample(after,pixel,extent),weight);
|
|
27
|
+
}`;
|
|
28
|
+
}
|
|
29
|
+
setup(t) {
|
|
30
|
+
if (this.source && (this.source.width < 1 || this.source.height < 1)) throw e("state", "Mask image was closed; create a transition with an open ImageBitmap");
|
|
31
|
+
super.setup(t);
|
|
32
|
+
let n = this.source;
|
|
33
|
+
this.mask = t.gpu.createTexture({
|
|
34
|
+
size: [n.width, n.height],
|
|
35
|
+
format: "rgba8unorm",
|
|
36
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
|
|
37
|
+
}), "data" in n ? t.gpu.queue.writeTexture({ texture: this.mask }, n.data, { bytesPerRow: n.width * 4 }, [n.width, n.height]) : t.gpu.queue.copyExternalImageToTexture({ source: n }, { texture: this.mask }, [n.width, n.height]), this.view = this.mask.createView();
|
|
38
|
+
}
|
|
39
|
+
transitionBindings(e, t) {
|
|
40
|
+
if (Math.max(e.width, e.height, t.width, t.height) > 65535) throw RangeError("Mask capture exceeds integer addressing limits; keep capture dimensions at most 65535");
|
|
41
|
+
return [...super.transitionBindings(e, t), this.view];
|
|
42
|
+
}
|
|
43
|
+
onDeviceRestored(e) {
|
|
44
|
+
this.mask?.destroy(), this.mask = void 0, this.view = void 0, super.onDeviceRestored(e);
|
|
45
|
+
}
|
|
46
|
+
dispose() {
|
|
47
|
+
this.mask?.destroy(), this.mask = void 0, this.view = void 0, this.source = void 0, super.dispose();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function a(t, n, a = {}) {
|
|
51
|
+
let o = r(t);
|
|
52
|
+
if (!o.gpu) throw e("unsupported", "Texture mask transitions require WebGPU; select a WebGPU engine");
|
|
53
|
+
let s = typeof ImageData < "u" && n instanceof ImageData, c = typeof ImageBitmap < "u" && n instanceof ImageBitmap;
|
|
54
|
+
if (!s && !c || s && !(n.data instanceof Uint8ClampedArray)) throw TypeError("Mask transition needs 8-bit ImageData or an open ImageBitmap; decode the image first");
|
|
55
|
+
let l = Math.min(4096, o.gpu.limits.maxTextureDimension2D);
|
|
56
|
+
if (![n.width, n.height].every((e) => Number.isSafeInteger(e) && e >= 1 && e <= l)) throw RangeError("Mask transition dimensions exceed limits; use 1..min(4096, device maxTextureDimension2D)");
|
|
57
|
+
let u = a.softness ?? .02;
|
|
58
|
+
if (!Number.isFinite(u) || u < 0 || u > 1 || u > 0 && u < 1e-6) throw RangeError("Mask softness is out of range; use zero or 0.000001..1");
|
|
59
|
+
let d = new i(s ? {
|
|
60
|
+
width: n.width,
|
|
61
|
+
height: n.height,
|
|
62
|
+
data: n.data.slice()
|
|
63
|
+
} : n, u);
|
|
64
|
+
return o.use(d), d;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { a as createMaskTransition };
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
/** Image-space transition library, written from geometric mappings rather than imported shader assets. */
|
|
6
|
+
export type TransitionPreset = 'slide' | 'push' | 'zoom' | 'iris' | 'cube' | 'page-curl' | 'swirl' | 'fade-through-color';
|
|
7
|
+
/** Finite parameters embedded as shader constants. Image coordinates have top-left origin. */
|
|
8
|
+
export interface TransitionPresetOptions {
|
|
9
|
+
/** Incoming edge direction, normalized internally; default [1,0] enters from right. Must be finite and nonzero. */
|
|
10
|
+
direction?: readonly [number, number];
|
|
11
|
+
/** Edge half-width in UV units, default 0.02, finite [0,0.5]. */
|
|
12
|
+
softness?: number;
|
|
13
|
+
/** Progress remapping. Default linear. Quadratic ease-in/out and cubic Hermite ease-in-out. */
|
|
14
|
+
easing?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
15
|
+
/** Iris, zoom and swirl center, default [0.5,0.5], each coordinate in [0,1]. */
|
|
16
|
+
center?: readonly [number, number];
|
|
17
|
+
/** RGBA background and fade-through colour, default opaque black, each component [0,1]. */
|
|
18
|
+
color?: readonly [number, number, number, number];
|
|
19
|
+
/** Swirl revolutions and zoom magnification control, default 1, finite (0,8]. */
|
|
20
|
+
strength?: number;
|
|
21
|
+
}
|
|
22
|
+
/** All available preset names, as an independent immutable list. */
|
|
23
|
+
export declare const transitionPresets: readonly TransitionPreset[];
|
|
24
|
+
/** Builds the custom entry's WGSL function contract. Source is pure and deterministic; no GPU work runs here. */
|
|
25
|
+
export declare function transitionPresetWGSL(kind: TransitionPreset, options?: TransitionPresetOptions): string;
|
|
26
|
+
/** Validates and attaches a frozen-frame preset. Call start('wipe',seconds); the supplied preset controls the effect. */
|
|
27
|
+
export declare function createPresetTransition(engine: EngineKernel, kind: TransitionPreset, options?: TransitionPresetOptions & CustomTransitionOptions): Promise<Transitions>;
|
|
28
|
+
/** Validates and attaches a preset between two live scenes; scenes and cameras remain borrowed. */
|
|
29
|
+
export declare function createLivePresetTransition(engine: EngineKernel, before: Scene, after: Scene, kind: TransitionPreset, options?: TransitionPresetOptions & Pick<LiveTransitionOptions, 'beforeCamera' | 'afterCamera'> & CustomTransitionOptions): Promise<LiveTransitions>;
|
package/dist/presets.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { t as e } from "./custom-CteHwFLg.js";
|
|
2
|
+
import { LiveTransitions as t } from "./live.js";
|
|
3
|
+
//#region src/presets.ts
|
|
4
|
+
var n = [
|
|
5
|
+
"slide",
|
|
6
|
+
"push",
|
|
7
|
+
"zoom",
|
|
8
|
+
"iris",
|
|
9
|
+
"cube",
|
|
10
|
+
"page-curl",
|
|
11
|
+
"swirl",
|
|
12
|
+
"fade-through-color"
|
|
13
|
+
], r = Object.freeze([...n]), i = (e) => `f32(${e})`;
|
|
14
|
+
function a(e, t = {}) {
|
|
15
|
+
if (!n.includes(e)) throw RangeError("Unknown transition preset; choose a name in transitionPresets");
|
|
16
|
+
let r = t.direction ?? [1, 0], a = t.center ?? [.5, .5], o = t.color ?? [
|
|
17
|
+
0,
|
|
18
|
+
0,
|
|
19
|
+
0,
|
|
20
|
+
1
|
|
21
|
+
], s = t.softness ?? .02, c = t.strength ?? 1, l = t.easing ?? "linear", u = Math.hypot(...r);
|
|
22
|
+
if (r.length !== 2 || !r.every(Number.isFinite) || !Number.isFinite(u) || u === 0) throw RangeError("Transition direction must be a finite nonzero 2-vector; choose [1,0]");
|
|
23
|
+
if (a.length !== 2 || !a.every((e) => Number.isFinite(e) && e >= 0 && e <= 1) || o.length !== 4 || !o.every((e) => Number.isFinite(e) && e >= 0 && e <= 1)) throw RangeError("Transition center and color must be normalized vectors; choose [0.5,0.5] and [0,0,0,1]");
|
|
24
|
+
if (!Number.isFinite(s) || s < 0 || s > .5 || !Number.isFinite(c) || c <= 0 || c > 8) throw RangeError("Transition softness or strength is out of range; use softness [0,0.5] and strength (0,8]");
|
|
25
|
+
let d = {
|
|
26
|
+
linear: "t",
|
|
27
|
+
"ease-in": "t*t",
|
|
28
|
+
"ease-out": "1.0-(1.0-t)*(1.0-t)",
|
|
29
|
+
"ease-in-out": "t*t*(3.0-2.0*t)"
|
|
30
|
+
}[l];
|
|
31
|
+
if (!d) throw RangeError("Unknown transition easing; choose linear, ease-in, ease-out or ease-in-out");
|
|
32
|
+
let f = r.map((e) => i(e / u)).join(","), p = a.map(i).join(","), m = o.map(i).join(","), h = `
|
|
33
|
+
fn presetUV(q:vec2f)->vec2f {let d=vec2f(${f});return vec2f(0.5)+d*(q.x-0.5)+vec2f(-d.y,d.x)*(q.y-0.5);}
|
|
34
|
+
fn presetCoverage(q:vec2f)->f32 {let edge=min(min(q.x,q.y),min(1.0-q.x,1.0-q.y));return ${s === 0 ? "select(0.0,1.0,edge>=0.0)" : `smoothstep(-${i(s)},${i(s)},edge)`};}
|
|
35
|
+
fn presetImage(image:texture_2d<f32>,q:vec2f)->vec4f {return mix(vec4f(${m}),sample(image,presetUV(q)),presetCoverage(q));}
|
|
36
|
+
fn transition(a:texture_2d<f32>,b:texture_2d<f32>,uv:vec2f,t:f32)->vec4f {
|
|
37
|
+
let p=${d};let dir=vec2f(${f});let center=vec2f(${p});
|
|
38
|
+
let q=vec2f(dot(uv-0.5,dir),dot(uv-0.5,vec2f(-dir.y,dir.x)))+0.5;
|
|
39
|
+
`, g;
|
|
40
|
+
switch (e) {
|
|
41
|
+
case "slide":
|
|
42
|
+
g = "let incoming=q-vec2f(1.0-p,0.0);return mix(sample(a,uv),sample(b,presetUV(incoming)),presetCoverage(incoming));";
|
|
43
|
+
break;
|
|
44
|
+
case "push":
|
|
45
|
+
g = `let old=q+vec2f(p,0.0);let next=q-vec2f(1.0-p,0.0);let w=${s === 0 ? "select(0.0,1.0,q.x>=1.0-p)" : `smoothstep(1.0-p-${i(s)},1.0-p+${i(s)},q.x)`};return mix(sample(a,presetUV(old)),sample(b,presetUV(next)),w);`;
|
|
46
|
+
break;
|
|
47
|
+
case "zoom":
|
|
48
|
+
g = `let out=sample(a,center+(uv-center)/(1.0+p*${i(c)}));let incoming=sample(b,center+(uv-center)*(1.0+(1.0-p)*${i(c)}));return mix(out,incoming,p);`;
|
|
49
|
+
break;
|
|
50
|
+
case "iris":
|
|
51
|
+
g = `let radius=p*max(max(distance(center,vec2f(0,0)),distance(center,vec2f(1,0))),max(distance(center,vec2f(0,1)),distance(center,vec2f(1,1))));let r=distance(uv,center);let w=${s === 0 ? "select(0.0,1.0,r<=radius)" : `1.0-smoothstep(radius-${i(s)},radius+${i(s)},r)`};return mix(sample(a,uv),sample(b,uv),w);`;
|
|
52
|
+
break;
|
|
53
|
+
case "swirl":
|
|
54
|
+
g = `let rel=uv-center;let angle=sin(p*3.14159265)*6.2831853*${i(c)}*max(0.0,1.0-length(rel)/0.70710678);let cs=cos(angle);let sn=sin(angle);let rotated=center+vec2f(cs*rel.x-sn*rel.y,sn*rel.x+cs*rel.y);return mix(sample(a,rotated),sample(b,rotated),p);`;
|
|
55
|
+
break;
|
|
56
|
+
case "fade-through-color":
|
|
57
|
+
g = `if(p<0.5){return mix(sample(a,uv),vec4f(${m}),p*2.0);}return mix(vec4f(${m}),sample(b,uv),p*2.0-1.0);`;
|
|
58
|
+
break;
|
|
59
|
+
case "cube":
|
|
60
|
+
g = `
|
|
61
|
+
let angle=p*1.570796327;let cs=cos(angle);let sn=sin(angle);
|
|
62
|
+
let ro=vec3f(-3.0*sn,0,3.0*cs);let screen=vec2f(q.x*2.0-1.0,1.0-q.y*2.0);
|
|
63
|
+
let rd=vec3f(cs*screen.x+2.0*sn,screen.y,sn*screen.x-2.0*cs);
|
|
64
|
+
var result=vec4f(${m});var nearest=1e20;
|
|
65
|
+
if(rd.z < -0.000001){let time=(1.0-ro.z)/rd.z;let hit=ro+rd*time;
|
|
66
|
+
if(time>0.0&&abs(hit.x)<=1.0&&abs(hit.y)<=1.0){nearest=time;result=presetImage(a,vec2f(hit.x+1.0,1.0-hit.y)*0.5);}}
|
|
67
|
+
if(rd.x>0.000001){let time=(-1.0-ro.x)/rd.x;let hit=ro+rd*time;
|
|
68
|
+
if(time>0.0&&time<nearest&&abs(hit.z)<=1.0&&abs(hit.y)<=1.0){result=presetImage(b,vec2f(hit.z+1.0,1.0-hit.y)*0.5);}}
|
|
69
|
+
return result;`;
|
|
70
|
+
break;
|
|
71
|
+
case "page-curl": g = "\n let radius=0.15;let edge=1.0-p*(1.0+3.14159265*radius);let x=q.x-edge;\n if(x<=0.0){return sample(a,uv);}\n let next=sample(b,uv);\n if(x>radius){return next;}\n let angle=asin(clamp(x/radius,0.0,1.0));let back=edge+radius*(3.14159265-angle);\n if(back<=1.0){let folded=sample(a,presetUV(vec2f(back,q.y)));let shade=0.65+0.35*cos(angle);let paper=vec4f(mix(folded.rgb,vec3f(1),0.2)*shade,folded.a);return mix(next,paper,presetCoverage(vec2f(back,q.y)));}\n let front=edge+radius*angle;\n if(front<=1.0){return sample(a,presetUV(vec2f(front,q.y)));}\n return next;";
|
|
72
|
+
}
|
|
73
|
+
return h + g + "\n}";
|
|
74
|
+
}
|
|
75
|
+
function o(t, n, r = {}) {
|
|
76
|
+
return e(t, a(n, r), r);
|
|
77
|
+
}
|
|
78
|
+
function s(e, n, r, i, o = {}) {
|
|
79
|
+
return t.custom(e, n, r, a(i, o), o);
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { s as createLivePresetTransition, o as createPresetTransition, a as transitionPresetWGSL, r as transitionPresets };
|