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:
ukimsanov
2026-05-19 16:11:24 -07:00
parent 852008bd44
commit a78e49c181
2 changed files with 17 additions and 12 deletions
+2 -2
View File
@@ -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 */
+15 -10
View File
@@ -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,