Skip to content

Write HTML. Render video. Built for agents.

feat(shader-transitions): add playSeamTransitionLoop to preview a seam on a loop (#4307)

Miguel Ángel0f528ff2e8cd
diff --git a/bun.lock b/bun.lock
index dd3edec0fb..dd42c38398 100644
--- a/bun.lock
+++ b/bun.lock
@@ -334,6 +334,7 @@
"@hyperframes/parsers": "workspace:*",
"@hyperframes/player": "workspace:*",
"@hyperframes/sdk": "workspace:*",
+ "@hyperframes/shader-transitions": "workspace:*",
"@hyperframes/studio-server": "workspace:*",
"@mcp-b/global": "^5.0.1",
"@phosphor-icons/react": "^2.1.10",
diff --git a/packages/shader-transitions/src/hyper-shader.ts b/packages/shader-transitions/src/hyper-shader.ts
index 3223edb745..20d6d4dc87 100644
--- a/packages/shader-transitions/src/hyper-shader.ts
+++ b/packages/shader-transitions/src/hyper-shader.ts
@@ -8,6 +8,7 @@ import {
renderShader,
DEFAULT_WIDTH,
DEFAULT_HEIGHT,
+ DEFAULT_ACCENT_COLORS,
type AccentColors,
} from "./webgl.js";
import { getFragSource, type ShaderName } from "./shaders/registry.js";
@@ -867,7 +868,7 @@ export function init(config: HyperShaderConfig): GsapTimeline {
const accentColors: AccentColors = config.accentColor
? deriveAccentColors(config.accentColor)
- : { accent: [1, 0.6, 0.2], dark: [0.4, 0.15, 0], bright: [1, 0.85, 0.5] };
+ : DEFAULT_ACCENT_COLORS;
const root = document.querySelector<HTMLElement>("[data-composition-id]");
const compId = config.compositionId || root?.getAttribute("data-composition-id") || "main";
@@ -2319,7 +2320,7 @@ function initEngineMode(
const bgColor = config.bgColor ?? "#000";
const accentColors: AccentColors = config.accentColor
? deriveAccentColors(config.accentColor)
- : { accent: [1, 0.6, 0.2], dark: [0.4, 0.15, 0], bright: [1, 0.85, 0.5] };
+ : DEFAULT_ACCENT_COLORS;
const rawW = Number(root?.getAttribute("data-width"));
const rawH = Number(root?.getAttribute("data-height"));
const compWidth = Number.isFinite(rawW) && rawW > 0 ? rawW : 1920;
diff --git a/packages/shader-transitions/src/index.ts b/packages/shader-transitions/src/index.ts
index 265427f700..6d0cc7d18e 100644
--- a/packages/shader-transitions/src/index.ts
+++ b/packages/shader-transitions/src/index.ts
@@ -7,3 +7,9 @@ export {
PAGE_COMPOSITOR_BUILD_CANARY,
PAGE_COMPOSITOR_CANVAS_ID,
} from "./engineModePageComposite.js";
+export {
+ playSeamTransitionLoop,
+ type SeamTransitionFrameSource,
+ type SeamTransitionLoopHandle,
+ type SeamTransitionLoopOptions,
+} from "./seamTransitionLoop.js";
diff --git a/packages/shader-transitions/src/seamTransitionLoop.test.ts b/packages/shader-transitions/src/seamTransitionLoop.test.ts
new file mode 100644
index 0000000000..976300d8fe
--- /dev/null
+++ b/packages/shader-transitions/src/seamTransitionLoop.test.ts
@@ -0,0 +1,309 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+import {
+ playSeamTransitionLoop,
+ type SeamTransitionFrameSource,
+ type SeamTransitionLoopOptions,
+} from "./seamTransitionLoop.js";
+import { DEFAULT_ACCENT_COLORS } from "./webgl.js";
+
+/** Minimal WebGL double covering every gl call seamTransitionLoop's setup and
+ * per-frame render path make (webgl.ts's createContext/setupQuad/
+ * createProgram/createTexture/uploadTextureSource/renderShader). */
+function createMockGl() {
+ return {
+ VERTEX_SHADER: 1,
+ FRAGMENT_SHADER: 2,
+ COMPILE_STATUS: 3,
+ LINK_STATUS: 4,
+ ARRAY_BUFFER: 5,
+ STATIC_DRAW: 6,
+ TEXTURE_2D: 7,
+ TEXTURE_WRAP_S: 8,
+ TEXTURE_WRAP_T: 9,
+ CLAMP_TO_EDGE: 10,
+ TEXTURE_MIN_FILTER: 11,
+ TEXTURE_MAG_FILTER: 12,
+ LINEAR: 13,
+ RGBA: 14,
+ UNSIGNED_BYTE: 15,
+ TEXTURE0: 16,
+ TEXTURE1: 17,
+ TRIANGLE_STRIP: 18,
+ UNPACK_FLIP_Y_WEBGL: 19,
+ FLOAT: 20,
+ viewport: vi.fn(),
+ pixelStorei: vi.fn(),
+ createBuffer: vi.fn(() => ({})),
+ bindBuffer: vi.fn(),
+ bindTexture: vi.fn(),
+ bufferData: vi.fn(),
+ createShader: vi.fn(() => ({})),
+ shaderSource: vi.fn(),
+ compileShader: vi.fn(),
+ getShaderParameter: vi.fn(() => true),
+ getShaderInfoLog: vi.fn(() => ""),
+ createProgram: vi.fn(() => ({})),
+ attachShader: vi.fn(),
+ linkProgram: vi.fn(),
+ getProgramParameter: vi.fn(() => true),
+ getProgramInfoLog: vi.fn(() => ""),
+ createTexture: vi.fn(() => ({})),
+ texParameteri: vi.fn(),
+ texImage2D: vi.fn(),
+ useProgram: vi.fn(),
+ activeTexture: vi.fn(),
+ uniform1i: vi.fn(),
+ uniform1f: vi.fn(),
+ uniform2f: vi.fn(),
+ uniform3f: vi.fn(),
+ enableVertexAttribArray: vi.fn(),
+ vertexAttribPointer: vi.fn(),
+ drawArrays: vi.fn(),
+ getUniformLocation: vi.fn(() => ({})),
+ getAttribLocation: vi.fn(() => 0),
+ deleteShader: vi.fn(),
+ deleteTexture: vi.fn(),
+ deleteProgram: vi.fn(),
+ deleteBuffer: vi.fn(),
+ };
+}
+
+function createMockCanvas(
+ gl: ReturnType<typeof createMockGl> | null,
+ size: { width: number; height: number } = { width: 640, height: 360 },
+) {
+ return { getContext: vi.fn(() => gl), ...size } as unknown as HTMLCanvasElement;
+}
+
+function stubRaf() {
+ let pending: FrameRequestCallback | null = null;
+ vi.stubGlobal(
+ "requestAnimationFrame",
+ vi.fn((cb: FrameRequestCallback) => {
+ pending = cb;
+ return 1;
+ }),
+ );
+ vi.stubGlobal("cancelAnimationFrame", vi.fn());
+ return {
+ /** Runs the most recently scheduled frame, if any. */
+ flush: (nowMs = 0) => {
+ const cb = pending;
+ pending = null;
+ cb?.(nowMs);
+ },
+ };
+}
+
+const fromSource = {} as SeamTransitionFrameSource;
+const toSource = {} as SeamTransitionFrameSource;
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
+/** A loop not yet flushed, for tests that control frame timing or the shader themselves. */
+function startLoop(options?: SeamTransitionLoopOptions, shaderName = "whip-pan") {
+ const raf = stubRaf();
+ const gl = createMockGl();
+ const canvas = createMockCanvas(gl);
+ const handle = playSeamTransitionLoop(canvas, fromSource, toSource, shaderName, options);
+ return { raf, gl, canvas, handle };
+}
+
+/** A loop already past its first frame, for tests that only care about `stop()`. */
+function startRunningLoop() {
+ const loop = startLoop();
+ loop.raf.flush(0);
+ return loop;
+}
+
+describe("playSeamTransitionLoop", () => {
+ it.each(["not-a-real-shader", "constructor", "toString", "__proto__"])(
+ "throws synchronously for %s, a name with no WebGL implementation",
+ (name) => {
+ const canvas = createMockCanvas(createMockGl());
+ expect(() => playSeamTransitionLoop(canvas, fromSource, toSource, name)).toThrow(
+ /Unknown shader/,
+ );
+ },
+ );
+
+ it.each(["glitch", "domain-warp-dissolve", "chromatic-radial-split"])(
+ "resolves catalog block name %s (glitch is unaliased and unquoted; the others differ from their registry key)",
+ (catalogName) => {
+ const { raf, gl, handle } = startLoop(undefined, catalogName);
+ raf.flush(0);
+ expect(gl.drawArrays).toHaveBeenCalledTimes(1);
+ handle.stop();
+ },
+ );
+
+ it("throws synchronously when the canvas yields no WebGL context", () => {
+ stubRaf();
+ const canvas = createMockCanvas(null);
+ expect(() => playSeamTransitionLoop(canvas, fromSource, toSource, "whip-pan")).toThrow(
+ /No WebGL context/,
+ );
+ });
+
+ it("resolves ready only after the first frame is drawn", async () => {
+ const { raf, gl, handle } = startLoop();
+
+ let readyResolved = false;
+ void handle.ready.then(() => (readyResolved = true));
+ await Promise.resolve();
+ expect(readyResolved).toBe(false);
+ expect(gl.drawArrays).not.toHaveBeenCalled();
+
+ raf.flush(0);
+ await handle.ready;
+ expect(readyResolved).toBe(true);
+ expect(gl.drawArrays).toHaveBeenCalledTimes(1);
+
+ handle.stop();
+ });
+
+ it("stop() deletes its own program, textures and buffer, and is idempotent", () => {
+ const { gl, handle } = startRunningLoop();
+
+ handle.stop();
+ handle.stop();
+
+ expect(gl.deleteTexture).toHaveBeenCalledTimes(2);
+ expect(gl.deleteProgram).toHaveBeenCalledTimes(1);
+ expect(gl.deleteBuffer).toHaveBeenCalledTimes(1);
+ expect(cancelAnimationFrame).toHaveBeenCalledTimes(1);
+ });
+
+ it("does not lose the WebGL context on stop(), so the canvas is reusable", () => {
+ // The mock gl has no getExtension at all: a lost context can never be
+ // reacquired via canvas.getContext(), so stop() must never reach for
+ // WEBGL_lose_context. Calling it here would throw "not a function".
+ const { handle } = startRunningLoop();
+
+ expect(() => handle.stop()).not.toThrow();
+ });
+
+ it("resolves ready even if stop() runs before any frame is drawn", async () => {
+ const { gl, handle } = startLoop();
+
+ handle.stop();
+
+ await handle.ready;
+ expect(gl.drawArrays).not.toHaveBeenCalled();
+ });
+
+ it("starts progress at 0 relative to its own first frame, not the raw rAF timestamp", () => {
+ const { raf, gl, handle } = startLoop({ loopMs: 1000 });
+
+ // A page that has been open a while hands rAF an arbitrary large timestamp
+ // on the very first call, deliberately NOT a multiple of loopMs; that must
+ // still count as elapsed=0 for this loop, not (nowMs % loopMs) of the raw
+ // navigation-relative clock.
+ raf.flush(70_437);
+ expect(gl.uniform1f).toHaveBeenLastCalledWith(expect.anything(), 0);
+
+ raf.flush(70_437 + 300);
+ expect(gl.uniform1f).toHaveBeenLastCalledWith(expect.anything(), expect.closeTo(0.6, 5));
+
+ handle.stop();
+ });
+
+ it("comes back down in the second half of the loop instead of climbing past 1", () => {
+ const { raf, gl, handle } = startLoop({ loopMs: 1000 });
+
+ raf.flush(0); // elapsed 0 -> progress 0
+ raf.flush(500); // elapsed 500 -> the peak, progress 1
+ expect(gl.uniform1f).toHaveBeenLastCalledWith(expect.anything(), 1);
+
+ raf.flush(700); // elapsed 700 -> descending, progress 0.6
+ expect(gl.uniform1f).toHaveBeenLastCalledWith(expect.anything(), expect.closeTo(0.6, 5));
+
+ handle.stop();
+ });
+
+ it.each([
+ ["loopMs", { loopMs: 0 }],
+ ["loopMs", { loopMs: -1000 }],
+ ["loopMs", { loopMs: Number.NaN }],
+ ["loopMs", { loopMs: Number.POSITIVE_INFINITY }],
+ ["width", { width: 0 }],
+ ["width", { width: Number.NaN }],
+ ["height", { height: -180 }],
+ ] satisfies [string, SeamTransitionLoopOptions][])(
+ "throws synchronously for an invalid %s (%j)",
+ (name, options) => {
+ const canvas = createMockCanvas(createMockGl());
+ expect(() =>
+ playSeamTransitionLoop(canvas, fromSource, toSource, "whip-pan", options),
+ ).toThrow(new RegExp(name));
+ },
+ );
+
+ it("passes the default accent colors (hyper-shader.ts's own fallback), not none", () => {
+ const { gl, handle } = startRunningLoop();
+ expect(gl.uniform3f).toHaveBeenCalledWith(expect.anything(), ...DEFAULT_ACCENT_COLORS.accent);
+ expect(gl.uniform3f).toHaveBeenCalledWith(expect.anything(), ...DEFAULT_ACCENT_COLORS.dark);
+ expect(gl.uniform3f).toHaveBeenCalledWith(expect.anything(), ...DEFAULT_ACCENT_COLORS.bright);
+ handle.stop();
+ });
+
+ it("defaults width/height to the canvas's own drawing-buffer size", () => {
+ const raf = stubRaf();
+ const gl = createMockGl();
+ const canvas = createMockCanvas(gl, { width: 320, height: 180 });
+ const handle = playSeamTransitionLoop(canvas, fromSource, toSource, "whip-pan");
+
+ expect(gl.viewport).toHaveBeenCalledWith(0, 0, 320, 180);
+ raf.flush(0);
+ handle.stop();
+ });
+
+ it("an explicit width/height option overrides the canvas's own size", () => {
+ const raf = stubRaf();
+ const gl = createMockGl();
+ const canvas = createMockCanvas(gl, { width: 320, height: 180 });
+ const handle = playSeamTransitionLoop(canvas, fromSource, toSource, "whip-pan", {
+ width: 100,
+ height: 50,
+ });
+
+ expect(gl.viewport).toHaveBeenCalledWith(0, 0, 100, 50);
+ raf.flush(0);
+ handle.stop();
+ });
+
+ it("does not draw again after stop()", () => {
+ const { raf, gl, handle } = startRunningLoop();
+ expect(gl.drawArrays).toHaveBeenCalledTimes(1);
+
+ handle.stop();
+ raf.flush(16);
+ expect(gl.drawArrays).toHaveBeenCalledTimes(1);
+ });
+
+ it("frees whatever it already allocated when setup throws partway through", () => {
+ stubRaf();
+ const gl = createMockGl();
+ let texImage2DCalls = 0;
+ gl.texImage2D.mockImplementation(() => {
+ texImage2DCalls += 1;
+ // 1st/2nd calls are createTexture's placeholder upload for texFrom/texTo;
+ // 3rd is the real upload for texFrom. Fail on the 4th (texTo's real
+ // upload) once both textures already exist, to prove the ones that
+ // succeeded before the throw get cleaned up, not just skipped.
+ if (texImage2DCalls === 4) throw new Error("bad toSource");
+ });
+ const canvas = createMockCanvas(gl);
+
+ expect(() => playSeamTransitionLoop(canvas, fromSource, toSource, "whip-pan")).toThrow(
+ "bad toSource",
+ );
+
+ expect(gl.deleteTexture).toHaveBeenCalledTimes(2);
+ expect(gl.deleteProgram).toHaveBeenCalledTimes(1);
+ expect(gl.deleteBuffer).toHaveBeenCalledTimes(1);
+ expect(requestAnimationFrame).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/shader-transitions/src/seamTransitionLoop.ts b/packages/shader-transitions/src/seamTransitionLoop.ts
new file mode 100644
index 0000000000..587a1f6435
--- /dev/null
+++ b/packages/shader-transitions/src/seamTransitionLoop.ts
@@ -0,0 +1,138 @@
+import {
+ createContext,
+ setupQuad,
+ createProgram,
+ createTexture,
+ uploadTextureSource,
+ renderShader,
+} from "./webgl.js";
+import { getFragSource, type ShaderName } from "./shaders/registry.js";
+
+/** What texImage2D accepts; LINEAR filtering scales it to the canvas, so a larger frame adds no quality. */
+export type SeamTransitionFrameSource = HTMLImageElement | HTMLCanvasElement | ImageBitmap;
+
+/** Catalog names whose registry key differs; engine and producer render under those keys. */
+const CATALOG_SHADER_ALIASES = new Map<string, ShaderName>([
+ ["domain-warp-dissolve", "domain-warp"],
+ ["chromatic-radial-split", "chromatic-split"],
+]);
+
+export interface SeamTransitionLoopOptions {
+ /** Defaults to the canvas's own drawing-buffer size. */
+ width?: number;
+ height?: number;
+ loopMs?: number;
+}
+
+export interface SeamTransitionLoopHandle {
+ /** Frees what this call created and keeps the WebGL context for the canvas's next loop. Idempotent. */
+ stop: () => void;
+ /** Resolves at the first drawn frame or at `stop()`, whichever comes first. */
+ ready: Promise<void>;
+}
+
+function assertPositiveFinite(name: string, value: number): void {
+ if (!Number.isFinite(value) || value <= 0) {
+ throw new Error(
+ `[playSeamTransitionLoop] ${name} must be a finite number above 0, got ${value}`,
+ );
+ }
+}
+
+/** Loops a catalog shader transition between two frames; throws for an unknown shader, no WebGL or a bad size. */
+export function playSeamTransitionLoop(
+ canvas: HTMLCanvasElement,
+ fromSource: SeamTransitionFrameSource,
+ toSource: SeamTransitionFrameSource,
+ shaderName: string,
+ options: SeamTransitionLoopOptions = {},
+): SeamTransitionLoopHandle {
+ const fragSrc = getFragSource(CATALOG_SHADER_ALIASES.get(shaderName) ?? shaderName);
+
+ const width = options.width ?? canvas.width;
+ const height = options.height ?? canvas.height;
+ const loopMs = options.loopMs ?? 1000;
+ assertPositiveFinite("width", width);
+ assertPositiveFinite("height", height);
+ assertPositiveFinite("loopMs", loopMs);
+
+ const gl = createContext(canvas, width, height);
+ if (!gl) {
+ throw new Error(`[playSeamTransitionLoop] No WebGL context available for "${shaderName}"`);
+ }
+ const glContext = gl;
+
+ // A setup that throws midway frees what it made: the caller has no handle to stop().
+ let quadBuf: WebGLBuffer | null = null;
+ let prog: WebGLProgram | null = null;
+ let texFrom: WebGLTexture | null = null;
+ let texTo: WebGLTexture | null = null;
+ let resources: {
+ quadBuf: WebGLBuffer;
+ prog: WebGLProgram;
+ texFrom: WebGLTexture;
+ texTo: WebGLTexture;
+ };
+ try {
+ quadBuf = setupQuad(glContext);
+ prog = createProgram(glContext, fragSrc);
+ texFrom = createTexture(glContext);
+ texTo = createTexture(glContext);
+ uploadTextureSource(glContext, texFrom, fromSource);
+ uploadTextureSource(glContext, texTo, toSource);
+ resources = { quadBuf, prog, texFrom, texTo };
+ } catch (err) {
+ if (texFrom) glContext.deleteTexture(texFrom);
+ if (texTo) glContext.deleteTexture(texTo);
+ if (prog) glContext.deleteProgram(prog);
+ if (quadBuf) glContext.deleteBuffer(quadBuf);
+ throw err;
+ }
+
+ let stopped = false;
+ let rafId = 0;
+ let startMs: number | null = null;
+ let resolveReady: () => void = () => {};
+ const ready = new Promise<void>((resolve) => {
+ resolveReady = resolve;
+ });
+
+ function frame(nowMs: number): void {
+ if (stopped) return;
+ let isFirstFrame = false;
+ if (startMs === null) {
+ startMs = nowMs;
+ isFirstFrame = true;
+ }
+ const phase = ((nowMs - startMs) % loopMs) / loopMs;
+ const progress = phase < 0.5 ? phase * 2 : (1 - phase) * 2;
+ renderShader(
+ glContext,
+ resources.quadBuf,
+ resources.prog,
+ resources.texFrom,
+ resources.texTo,
+ progress,
+ undefined,
+ width,
+ height,
+ );
+ if (isFirstFrame) resolveReady();
+ rafId = requestAnimationFrame(frame);
+ }
+ rafId = requestAnimationFrame(frame);
+
+ return {
+ ready,
+ stop: () => {
+ if (stopped) return;
+ stopped = true;
+ cancelAnimationFrame(rafId);
+ resolveReady();
+ glContext.deleteTexture(resources.texFrom);
+ glContext.deleteTexture(resources.texTo);
+ glContext.deleteProgram(resources.prog);
+ glContext.deleteBuffer(resources.quadBuf);
+ },
+ };
+}
diff --git a/packages/shader-transitions/src/shaders/registry.ts b/packages/shader-transitions/src/shaders/registry.ts
index 6ce116ecd1..a11be49202 100644
--- a/packages/shader-transitions/src/shaders/registry.ts
+++ b/packages/shader-transitions/src/shaders/registry.ts
@@ -242,7 +242,7 @@ export type ShaderName = keyof typeof shaders;
export const SHADER_NAMES = Object.keys(shaders) as ShaderName[];
export function getFragSource(name: string): string {
- const def = shaders[name];
+ const def = Object.hasOwn(shaders, name) ? shaders[name] : undefined;
if (!def)
throw new Error(
`[HyperShader] Unknown shader: "${name}". Available: ${SHADER_NAMES.join(", ")}`,
diff --git a/packages/shader-transitions/src/webgl.test.ts b/packages/shader-transitions/src/webgl.test.ts
index 6b44fb99e8..687736609d 100644
--- a/packages/shader-transitions/src/webgl.test.ts
+++ b/packages/shader-transitions/src/webgl.test.ts
@@ -1,7 +1,10 @@
import { describe, expect, it, vi } from "vitest";
import { createProgram } from "./webgl.js";
-/** Model WebGL's rule that shader handles belong to the context that created them. */
+const FRAGMENT_SRC = "precision mediump float;void main(){gl_FragColor=vec4(1.0);}";
+
+/** Model WebGL's rule that shader handles belong to the context that created
+ * them, and that a delete actually removes the handle from that ownership set. */
function createMockContext() {
const shaders = new Set<WebGLShader>();
const gl = {
@@ -23,6 +26,7 @@ function createMockContext() {
}),
linkProgram: vi.fn(),
getProgramParameter: vi.fn(() => true),
+ deleteShader: vi.fn((shader: WebGLShader) => shaders.delete(shader)),
};
return gl;
}
@@ -31,14 +35,24 @@ describe("createProgram", () => {
it("uses context-owned shaders across multiple contexts and repeated calls", () => {
const first = createMockContext();
const second = createMockContext();
- const fragment = "precision mediump float;void main(){gl_FragColor=vec4(1.0);}";
for (const gl of [first, second, first, second]) {
// The test double implements only the WebGL methods used to create a program.
- expect(() => createProgram(gl as unknown as WebGLRenderingContext, fragment)).not.toThrow();
+ expect(() =>
+ createProgram(gl as unknown as WebGLRenderingContext, FRAGMENT_SRC),
+ ).not.toThrow();
}
expect(first.linkProgram).toHaveBeenCalledTimes(2);
expect(second.linkProgram).toHaveBeenCalledTimes(2);
});
+
+ it("deletes both shader objects once they're linked into the program", () => {
+ const gl = createMockContext();
+
+ createProgram(gl as unknown as WebGLRenderingContext, FRAGMENT_SRC);
+
+ // Vertex shader (createProgramWithVertex) + fragment shader (linkProgram).
+ expect(gl.deleteShader).toHaveBeenCalledTimes(2);
+ });
});
diff --git a/packages/shader-transitions/src/webgl.ts b/packages/shader-transitions/src/webgl.ts
index ed0bf931ad..a3f4c8de13 100644
--- a/packages/shader-transitions/src/webgl.ts
+++ b/packages/shader-transitions/src/webgl.ts
@@ -41,11 +41,15 @@ function linkProgram(
): WebGLProgram {
const p = gl.createProgram();
if (!p) throw new Error("[HyperShader] Failed to create program");
+ const fragmentShader = compileShader(gl, fragSrc, gl.FRAGMENT_SHADER);
gl.attachShader(p, vertexShader);
- gl.attachShader(p, compileShader(gl, fragSrc, gl.FRAGMENT_SHADER));
+ gl.attachShader(p, fragmentShader);
gl.linkProgram(p);
+ gl.deleteShader(fragmentShader);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
- throw new Error(`[HyperShader] Program link: ${gl.getProgramInfoLog(p) || "unknown"}`);
+ const log = gl.getProgramInfoLog(p) || "unknown";
+ gl.deleteProgram(p);
+ throw new Error(`[HyperShader] Program link: ${log}`);
}
return p;
}
@@ -59,7 +63,12 @@ export function createProgramWithVertex(
vertexSrc: string,
fragSrc: string,
): WebGLProgram {
- return linkProgram(gl, compileShader(gl, vertexSrc, gl.VERTEX_SHADER), fragSrc);
+ const vertexShader = compileShader(gl, vertexSrc, gl.VERTEX_SHADER);
+ try {
+ return linkProgram(gl, vertexShader, fragSrc);
+ } finally {
+ gl.deleteShader(vertexShader);
+ }
}
export interface AccentColors {
@@ -68,6 +77,12 @@ export interface AccentColors {
bright: [number, number, number];
}
+export const DEFAULT_ACCENT_COLORS: AccentColors = {
+ accent: [1, 0.6, 0.2],
+ dark: [0.4, 0.15, 0],
+ bright: [1, 0.85, 0.5],
+};
+
interface ProgramLocations {
from: WebGLUniformLocation | null;
to: WebGLUniformLocation | null;
@@ -105,7 +120,7 @@ export function renderShader(
texFrom: WebGLTexture,
texTo: WebGLTexture,
progress: number,
- colors?: AccentColors,
+ colors: AccentColors = DEFAULT_ACCENT_COLORS,
width: number = DEFAULT_WIDTH,
height: number = DEFAULT_HEIGHT,
): void {
@@ -119,11 +134,9 @@ export function renderShader(
gl.uniform1i(loc.to, 1);
gl.uniform1f(loc.progress, progress);
gl.uniform2f(loc.resolution, width, height);
- if (colors) {
- gl.uniform3f(loc.accent, ...colors.accent);
- gl.uniform3f(loc.accentDark, ...colors.dark);
- gl.uniform3f(loc.accentBright, ...colors.bright);
- }
+ gl.uniform3f(loc.accent, ...colors.accent);
+ gl.uniform3f(loc.accentDark, ...colors.dark);
+ gl.uniform3f(loc.accentBright, ...colors.bright);
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuf);
gl.enableVertexAttribArray(loc.aPos);
gl.vertexAttribPointer(loc.aPos, 2, gl.FLOAT, false, 0, 0);
diff --git a/packages/studio/package.json b/packages/studio/package.json
index 5ce6ffe8a0..18212604b0 100644
--- a/packages/studio/package.json
+++ b/packages/studio/package.json
@@ -78,6 +78,7 @@
"@hyperframes/parsers": "workspace:*",
"@hyperframes/player": "workspace:*",
"@hyperframes/sdk": "workspace:*",
+ "@hyperframes/shader-transitions": "workspace:*",
"@hyperframes/studio-server": "workspace:*",
"@mcp-b/global": "^5.0.1",
"@phosphor-icons/react": "^2.1.10",
diff --git a/packages/studio/src/index.ts b/packages/studio/src/index.ts
index 5760e68578..e18af36c86 100644
--- a/packages/studio/src/index.ts
+++ b/packages/studio/src/index.ts
@@ -183,3 +183,10 @@ export type { TimelinePaneProps } from "./components/nle/TimelinePane";
export { TimelineEditProvider } from "./contexts/TimelineEditContext";
export type { TimelineEditCallbacks } from "./player/components/timelineCallbacks";
export type { BlockedTimelineEditIntent } from "./player/components/timelineEditing";
+
+export {
+ playSeamTransitionLoop,
+ type SeamTransitionFrameSource,
+ type SeamTransitionLoopHandle,
+ type SeamTransitionLoopOptions,
+} from "@hyperframes/shader-transitions";