mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
feat(shader-transitions): make shader optional to support CSS crossfade mixing
Allow omitting the shader field in TransitionConfig to get a smooth CSS opacity crossfade instead of a WebGL effect. HyperShader manages all scene visibility regardless of transition type, so shader and CSS crossfade transitions can now be mixed freely in the same composition. When shader is omitted: - No WebGL program is compiled or cached for that transition - The existing applyFallbackTransition() path handles the crossfade - No texture prewarming needed — transition is marked ready immediately Tested: verified with a 3-scene composition (sdf-iris + CSS crossfade) rendered to MP4. Both transition types render correctly. engine/src/types.ts: HfTransitionMeta.shader is now optional to match
This commit is contained in:
@@ -45,8 +45,8 @@ export interface HfTransitionMeta {
|
||||
time: number;
|
||||
/** Transition duration (seconds) */
|
||||
duration: number;
|
||||
/** Shader identifier (e.g. "fade", "wipe") */
|
||||
shader: string;
|
||||
/** Shader identifier. Undefined when the transition is a CSS crossfade. */
|
||||
shader?: string;
|
||||
/** GSAP easing string (e.g. "power2.inOut") */
|
||||
ease: string;
|
||||
/** Scene id the transition starts from */
|
||||
|
||||
@@ -53,7 +53,8 @@ interface GsapTimeline {
|
||||
|
||||
export interface TransitionConfig {
|
||||
time: number;
|
||||
shader: ShaderName;
|
||||
/** Omit to use a CSS crossfade instead of a WebGL shader. */
|
||||
shader?: ShaderName;
|
||||
duration?: number;
|
||||
ease?: string;
|
||||
}
|
||||
@@ -100,7 +101,7 @@ interface CachedTransition {
|
||||
duration: number;
|
||||
fromId: string;
|
||||
toId: string;
|
||||
prog: WebGLProgram;
|
||||
prog: WebGLProgram | null; // null for CSS-fallback transitions
|
||||
frames: CachedTransitionFrame[];
|
||||
cacheKey: string;
|
||||
dirty: boolean;
|
||||
@@ -825,7 +826,7 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
interface HfTransitionMeta {
|
||||
time: number;
|
||||
duration: number;
|
||||
shader: string;
|
||||
shader?: string; // undefined = CSS crossfade (no WebGL required)
|
||||
ease: string;
|
||||
fromScene: string;
|
||||
toScene: string;
|
||||
@@ -902,6 +903,7 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
|
||||
const programs = new Map<string, WebGLProgram>();
|
||||
for (const t of transitions) {
|
||||
if (!t.shader) continue; // CSS-only transitions have no WebGL program
|
||||
if (!programs.has(t.shader)) {
|
||||
try {
|
||||
programs.set(t.shader, createProgram(gl, getFragSource(t.shader)));
|
||||
@@ -1164,7 +1166,7 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
renderShader(
|
||||
gl,
|
||||
quadBuf,
|
||||
state.prog,
|
||||
state.prog!, // non-null: fallback path returns before reaching here
|
||||
interpolatedFromTex,
|
||||
interpolatedToTex,
|
||||
state.progress,
|
||||
@@ -1293,8 +1295,11 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
const toId = scenes[i + 1];
|
||||
if (!fromId || !toId) continue;
|
||||
|
||||
const prog = programs.get(t.shader);
|
||||
if (!prog) continue;
|
||||
// CSS-only transition when shader is omitted — uses the fallback opacity
|
||||
// crossfade path. No WebGL program or texture prewarming needed.
|
||||
const isCssFallback = !t.shader;
|
||||
const prog = isCssFallback ? null : (programs.get(t.shader!) ?? null);
|
||||
if (!isCssFallback && !prog) continue; // shader requested but not compiled
|
||||
|
||||
const dur = t.duration ?? DEFAULT_DURATION;
|
||||
const ease = t.ease ?? DEFAULT_EASE;
|
||||
@@ -1309,10 +1314,10 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
prog,
|
||||
frames: [],
|
||||
cacheKey: "",
|
||||
dirty: true,
|
||||
ready: false,
|
||||
fallback: false,
|
||||
persisted: false,
|
||||
dirty: !isCssFallback,
|
||||
ready: isCssFallback, // CSS fallback needs no prewarming
|
||||
fallback: isCssFallback,
|
||||
persisted: isCssFallback,
|
||||
textureReady: false,
|
||||
texturePromise: null,
|
||||
textureGeneration: 0,
|
||||
|
||||
Reference in New Issue
Block a user