hyperframes icon indicating copy to clipboard operation
hyperframes copied to clipboard

feat(shader-transitions): optional shader field — CSS crossfade mixing in HyperShader

Open ukimsanov opened this issue 6 months ago • 1 comments

What

Makes the shader field in TransitionConfig optional. When omitted, HyperShader performs a smooth CSS opacity crossfade instead of a WebGL effect — using the existing applyFallbackTransition() path that was already there for texture-load failures.

Why

Previously, using HyperShader.init() locked the entire composition into WebGL-only transitions. Any transition that didn't need a shader effect (smooth cuts, crossfades between related beats) still required picking the least-intrusive shader (flash-through-white at 0.01s). This was an all-or-nothing constraint that produced unwanted white flashes in practice.

Now shader and CSS crossfade transitions can be mixed freely in the same composition:

var tl = HyperShader.init({
  bgColor: "#000",
  scenes: ["beat-1", "beat-2", "beat-3", "beat-4"],
  transitions: [
    { time: 4.0, shader: "sdf-iris", duration: 0.7 },   // WebGL shader
    { time: 8.5, duration: 0.8 },                         // no shader → CSS crossfade
    { time: 13.0, shader: "domain-warp", duration: 0.6 }, // WebGL shader
  ],
});

How

  • TransitionConfig.shader changed from ShaderName (required) to ShaderName | undefined (optional)
  • In the program compilation loop: skip transitions with no shader
  • In the transition setup loop: isCssFallback = !t.shader — fallback transitions get prog: null, ready: true, fallback: true, dirty: false — no prewarming needed
  • renderShader call uses non-null assertion (state.prog!) — safe because the fallback path returns before this point
  • HfTransitionMeta.shader in both the local interface and engine/src/types.ts made optional to match
  • CachedTransition.prog type widened to WebGLProgram | null

Test plan

  • [x] Built packages/shader-transitions — clean TypeScript, no errors
  • [x] Tested with a 3-scene composition: sdf-iris shader + CSS crossfade + domain-warp shader
  • [x] Rendered to MP4 — both transition types composite correctly
  • [x] Verified CSS crossfade fallback uses applyFallbackTransition() smooth opacity interpolation
  • [x] Player scrubber works correctly (using HyperShader.init() without timeline: option)

ukimsanov avatar May 16 '26 05:05 ukimsanov

fix the failed ci checks btw

miguel-heygen avatar May 16 '26 05:05 miguel-heygen