Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

28.3 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [
      {
        "name": "@remotion/transitions",
        "version": null
      }
    ],
    "dimensions": null,
    "displayName": "Hologram",
    "initialProps": null,
    "slug": "hologram",
    "sourceCode": "import { AbsoluteFill, Interactive, Sequence, isHtmlInCanvasSupported, useCurrentFrame, useDelayRender, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport React, { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { type TransitionPresentation, type TransitionPresentationComponentProps } from \"@remotion/transitions\";\n\nconst QUAD = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]);\n\nconst VERTEX_SHADER = `#version 300 es\nin vec2 a_pos;\nout vec2 v_uv;\nvoid main() {\n  v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);\n  gl_Position = vec4(a_pos, 0.0, 1.0);\n}`;\n\nconst LAYER: React.CSSProperties = {\n  position: \"absolute\",\n  inset: 0,\n  width: \"100%\",\n  height: \"100%\",\n};\n\nconst OUTPUT_LAYER: React.CSSProperties = { ...LAYER, pointerEvents: \"none\" };\n\nconst isCanvasTransitionSupported = (): boolean =>\n  isHtmlInCanvasSupported();\n\nconst isCanvasFilterSupported = (): boolean => isHtmlInCanvasSupported();\n\ntype SceneShaderFrame<Props> = {\n  gl: WebGL2RenderingContext;\n  uniform: (name: string) => WebGLUniformLocation | null;\n  width: number;\n  height: number;\n  progress: number;\n  passedProps: Props;\n};\n\ntype SceneShaderDrawParams<Props> = {\n  from: OffscreenCanvas | null;\n  to: OffscreenCanvas | null;\n  width: number;\n  height: number;\n  progress: number;\n  passedProps: Props;\n};\n\ntype SceneShaderInstance<Props> = {\n  draw: (params: SceneShaderDrawParams<Props>) => void;\n  clear: () => void;\n  cleanup: () => void;\n};\n\ntype SceneShader<Props> = (\n  canvas: OffscreenCanvas,\n) => SceneShaderInstance<Props>;\n\ntype SceneFilterFrame<Props> = {\n  gl: WebGL2RenderingContext;\n  uniform: (name: string) => WebGLUniformLocation | null;\n  width: number;\n  height: number;\n  frame: number;\n  time: number;\n  passedProps: Props;\n};\n\ntype SceneFilterDrawParams<Props> = {\n  scene: OffscreenCanvas | null;\n  width: number;\n  height: number;\n  frame: number;\n  time: number;\n  passedProps: Props;\n};\n\ntype SceneFilterInstance<Props> = {\n  draw: (params: SceneFilterDrawParams<Props>) => void;\n  clear: () => void;\n  cleanup: () => void;\n};\n\ntype SceneFilter<Props> = (\n  canvas: OffscreenCanvas,\n) => SceneFilterInstance<Props>;\n\nfunction compileShader(\n  gl: WebGL2RenderingContext,\n  source: string,\n  type: GLenum,\n): WebGLShader {\n  const shader = gl.createShader(type);\n  if (!shader) {\n    throw new Error(\"canvas-presentation: failed to create shader\");\n  }\n  gl.shaderSource(shader, source);\n  gl.compileShader(shader);\n  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n    const log = gl.getShaderInfoLog(shader);\n    gl.deleteShader(shader);\n    throw new Error(`canvas-presentation: failed to compile shader: ${log}`);\n  }\n  return shader;\n}\n\nfunction createProgram(\n  gl: WebGL2RenderingContext,\n  fragment: string,\n): WebGLProgram {\n  const program = gl.createProgram();\n  if (!program) {\n    throw new Error(\"canvas-presentation: failed to create program\");\n  }\n  const vs = compileShader(gl, VERTEX_SHADER, gl.VERTEX_SHADER);\n  const fs = compileShader(gl, fragment, gl.FRAGMENT_SHADER);\n  gl.attachShader(program, vs);\n  gl.attachShader(program, fs);\n  gl.linkProgram(program);\n  gl.deleteShader(vs);\n  gl.deleteShader(fs);\n  if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n    const log = gl.getProgramInfoLog(program);\n    gl.deleteProgram(program);\n    throw new Error(`canvas-presentation: failed to link program: ${log}`);\n  }\n  return program;\n}\n\nfunction createSceneTexture(gl: WebGL2RenderingContext): WebGLTexture {\n  const texture = gl.createTexture();\n  if (!texture) {\n    throw new Error(\"canvas-presentation: failed to create texture\");\n  }\n  gl.bindTexture(gl.TEXTURE_2D, texture);\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n  gl.texImage2D(\n    gl.TEXTURE_2D,\n    0,\n    gl.RGBA,\n    1,\n    1,\n    0,\n    gl.RGBA,\n    gl.UNSIGNED_BYTE,\n    new Uint8Array([0, 0, 0, 0]),\n  );\n  return texture;\n}\n\nfunction createQuadSurface(canvas: OffscreenCanvas, fragment: string) {\n  const gl = canvas.getContext(\"webgl2\", { premultipliedAlpha: true });\n  if (!gl) {\n    throw new Error(\"canvas-presentation: WebGL2 is unavailable\");\n  }\n\n  const program = createProgram(gl, fragment);\n  const vao = gl.createVertexArray();\n  gl.bindVertexArray(vao);\n  const buffer = gl.createBuffer();\n  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n  gl.bufferData(gl.ARRAY_BUFFER, QUAD, gl.STATIC_DRAW);\n  const aPos = gl.getAttribLocation(program, \"a_pos\");\n  gl.enableVertexAttribArray(aPos);\n  gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);\n\n  const locations = new Map<string, WebGLUniformLocation | null>();\n  const uniform = (name: string) => {\n    const cached = locations.get(name);\n    if (cached !== undefined) {\n      return cached;\n    }\n    const location = gl.getUniformLocation(program, name);\n    locations.set(name, location);\n    return location;\n  };\n\n  const clear = () => {\n    gl.clearColor(0, 0, 0, 0);\n    gl.clear(gl.COLOR_BUFFER_BIT);\n  };\n\n  const textures: WebGLTexture[] = [];\n  const createTexture = () => {\n    const texture = createSceneTexture(gl);\n    textures.push(texture);\n    return texture;\n  };\n\n  const begin = (width: number, height: number) => {\n    gl.viewport(0, 0, width, height);\n    clear();\n    gl.useProgram(program);\n    gl.bindVertexArray(vao);\n  };\n\n  const bindScene = (\n    image: OffscreenCanvas | null,\n    texture: WebGLTexture,\n    unit: number,\n    name: string,\n  ) => {\n    gl.activeTexture(gl.TEXTURE0 + unit);\n    gl.bindTexture(gl.TEXTURE_2D, texture);\n    if (image) {\n      gl.texImage2D(\n        gl.TEXTURE_2D,\n        0,\n        gl.RGBA,\n        gl.RGBA,\n        gl.UNSIGNED_BYTE,\n        image,\n      );\n    }\n    gl.uniform1i(uniform(name), unit);\n  };\n\n  const draw = () => gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n\n  const cleanup = () => {\n    gl.deleteProgram(program);\n    for (const texture of textures) {\n      gl.deleteTexture(texture);\n    }\n    gl.deleteBuffer(buffer);\n    gl.deleteVertexArray(vao);\n  };\n\n  return {\n    gl,\n    uniform,\n    clear,\n    createTexture,\n    begin,\n    bindScene,\n    draw,\n    cleanup,\n  };\n}\n\nfunction makeSceneShader<Props extends Record<string, unknown>>(\n  fragment: string,\n  setUniforms?: (frame: SceneShaderFrame<Props>) => void,\n): SceneShader<Props> {\n  return (canvas) => {\n    const surface = createQuadSurface(canvas, fragment);\n    const fromTexture = surface.createTexture();\n    const toTexture = surface.createTexture();\n\n    return {\n      clear: surface.clear,\n      cleanup: surface.cleanup,\n      draw: ({ from, to, width, height, progress, passedProps }) => {\n        surface.begin(width, height);\n        surface.bindScene(from, fromTexture, 0, \"u_from\");\n        surface.bindScene(to, toTexture, 1, \"u_to\");\n\n        surface.gl.uniform1f(surface.uniform(\"u_progress\"), progress);\n        surface.gl.uniform1f(surface.uniform(\"u_aspect\"), width / height);\n        setUniforms?.({\n          gl: surface.gl,\n          uniform: surface.uniform,\n          width,\n          height,\n          progress,\n          passedProps,\n        });\n\n        surface.draw();\n      },\n    };\n  };\n}\n\nfunction makeFilterShader<Props extends Record<string, unknown>>(\n  fragment: string,\n  setUniforms?: (frame: SceneFilterFrame<Props>) => void,\n): SceneFilter<Props> {\n  return (canvas) => {\n    const surface = createQuadSurface(canvas, fragment);\n    const sceneTexture = surface.createTexture();\n\n    return {\n      clear: surface.clear,\n      cleanup: surface.cleanup,\n      draw: ({ scene, width, height, frame, time, passedProps }) => {\n        surface.begin(width, height);\n        surface.bindScene(scene, sceneTexture, 0, \"u_scene\");\n\n        surface.gl.uniform1f(surface.uniform(\"u_frame\"), frame);\n        surface.gl.uniform1f(surface.uniform(\"u_time\"), time);\n        surface.gl.uniform1f(surface.uniform(\"u_aspect\"), width / height);\n        setUniforms?.({\n          gl: surface.gl,\n          uniform: surface.uniform,\n          width,\n          height,\n          frame,\n          time,\n          passedProps,\n        });\n\n        surface.draw();\n      },\n    };\n  };\n}\n\nconst transferred = new WeakMap<HTMLCanvasElement, OffscreenCanvas>();\n\nfunction takeOffscreen(canvas: HTMLCanvasElement): OffscreenCanvas {\n  const existing = transferred.get(canvas);\n  if (existing) {\n    return existing;\n  }\n  const created = canvas.transferControlToOffscreen();\n  transferred.set(canvas, created);\n  return created;\n}\n\nfunction makeCanvasComponent<Props extends Record<string, unknown>>(\n  shader: SceneShader<Props>,\n): React.FC<TransitionPresentationComponentProps<Props>> {\n  return function CanvasScenePresentation({\n    children,\n    presentationProgress,\n    presentationDirection,\n    passedProps,\n    onElementImage,\n    onUnmount,\n    bothEnteringAndExiting,\n  }) {\n    const layoutRef = React.useRef<HTMLCanvasElement | null>(null);\n    const outputRef = React.useRef<HTMLCanvasElement | null>(null);\n    const captureRef = React.useRef<OffscreenCanvas | null>(null);\n    const captureContextRef =\n      React.useRef<OffscreenCanvasRenderingContext2D | null>(null);\n    const outputSurfaceRef = React.useRef<OffscreenCanvas | null>(null);\n    const instanceRef = React.useRef<SceneShaderInstance<Props> | null>(null);\n    const passedPropsRef = React.useRef(passedProps);\n    passedPropsRef.current = passedProps;\n    const onElementImageRef = React.useRef(onElementImage);\n    onElementImageRef.current = onElementImage;\n    const onUnmountRef = React.useRef(onUnmount);\n    onUnmountRef.current = onUnmount;\n\n    const { delayRender, continueRender } = useDelayRender();\n    const passThrough =\n      bothEnteringAndExiting && presentationDirection === \"exiting\";\n\n    const drawRef = React.useRef<\n      (\n        prevImage: OffscreenCanvas | null,\n        nextImage: OffscreenCanvas | null,\n        progress: number,\n      ) => void\n    >(() => undefined);\n    drawRef.current = (prevImage, nextImage, progress) => {\n      const instance = instanceRef.current;\n      if (!instance) {\n        return;\n      }\n      const handle = delayRender(\"canvas-presentation: paint\");\n      const to = prevImage;\n      const from = nextImage;\n      const width = from?.width ?? to?.width ?? 0;\n      const height = from?.height ?? to?.height ?? 0;\n      if (width === 0 || height === 0) {\n        instance.clear();\n        continueRender(handle);\n        return;\n      }\n      instance.draw({\n        from,\n        to,\n        width,\n        height,\n        progress: !to ? 0 : !from ? 1 : progress,\n        passedProps: passedPropsRef.current,\n      });\n      continueRender(handle);\n    };\n\n    const draw = React.useCallback(\n      (\n        prevImage: OffscreenCanvas | null,\n        nextImage: OffscreenCanvas | null,\n        progress: number,\n      ) => drawRef.current(prevImage, nextImage, progress),\n      [],\n    );\n\n    React.useLayoutEffect(() => {\n      if (passThrough) {\n        return;\n      }\n      const layout = layoutRef.current;\n      const output = outputRef.current;\n      if (!layout || !output) {\n        return;\n      }\n      const capture = takeOffscreen(layout);\n      const context = capture.getContext(\"2d\");\n      if (!context) {\n        throw new Error(\"canvas-presentation: failed to acquire a 2D context\");\n      }\n      const surface = takeOffscreen(output);\n      captureRef.current = capture;\n      captureContextRef.current = context;\n      outputSurfaceRef.current = surface;\n      instanceRef.current = shader(surface);\n\n      return () => {\n        instanceRef.current?.cleanup();\n        instanceRef.current = null;\n        captureRef.current = null;\n        captureContextRef.current = null;\n        outputSurfaceRef.current = null;\n      };\n    }, [passThrough, shader]);\n\n    React.useLayoutEffect(() => {\n      if (passThrough) {\n        return;\n      }\n      const layout = layoutRef.current;\n      if (!layout) {\n        return;\n      }\n      layout.layoutSubtree = true;\n      const handlePaint = () => {\n        const scene = layout.firstElementChild;\n        const capture = captureRef.current;\n        const context = captureContextRef.current;\n        if (!scene || !capture || !context) {\n          return;\n        }\n        const elementImage = layout.captureElementImage(scene);\n        try {\n          context.reset();\n          context.drawElementImage(elementImage, 0, 0);\n        } finally {\n          elementImage.close();\n        }\n        onElementImageRef.current(capture, draw);\n      };\n      layout.addEventListener(\"paint\", handlePaint);\n      return () => layout.removeEventListener(\"paint\", handlePaint);\n    }, [passThrough, draw]);\n\n    React.useLayoutEffect(() => {\n      if (passThrough) {\n        return;\n      }\n      const layout = layoutRef.current;\n      if (!layout) {\n        return;\n      }\n      const observer = new ResizeObserver(([entry]) => {\n        const capture = captureRef.current;\n        const surface = outputSurfaceRef.current;\n        if (!capture || !surface) {\n          return;\n        }\n        const width = entry.devicePixelContentBoxSize[0].inlineSize;\n        const height = entry.devicePixelContentBoxSize[0].blockSize;\n        capture.width = width;\n        capture.height = height;\n        surface.width = width;\n        surface.height = height;\n        layout.requestPaint?.();\n      });\n      observer.observe(layout, { box: \"device-pixel-content-box\" });\n      return () => observer.disconnect();\n    }, [passThrough]);\n\n    // biome-ignore lint/correctness/useExhaustiveDependencies: presentationProgress is the intentional trigger — a new progress value is what schedules the next paint\n    React.useLayoutEffect(() => {\n      if (passThrough) {\n        return;\n      }\n      layoutRef.current?.requestPaint?.();\n    }, [passThrough, presentationProgress]);\n\n    React.useLayoutEffect(() => {\n      if (passThrough) {\n        return;\n      }\n      return () => onUnmountRef.current();\n    }, [passThrough]);\n\n    if (passThrough) {\n      return <>{children}</>;\n    }\n\n    return (\n      <AbsoluteFill>\n        <canvas ref={layoutRef} style={LAYER}>\n          {children}\n        </canvas>\n        <canvas ref={outputRef} style={OUTPUT_LAYER} />\n      </AbsoluteFill>\n    );\n  };\n}\n\ntype CanvasFilterProps = {\n  children: React.ReactNode;\n};\n\nfunction makeFilterComponent<Props extends Record<string, unknown>>(\n  shader: SceneFilter<Props>,\n): React.FC<Props & CanvasFilterProps> {\n  return function CanvasSceneFilter(props) {\n    const frame = useCurrentFrame();\n    const { fps } = useVideoConfig();\n    const { delayRender, continueRender } = useDelayRender();\n\n    const layoutRef = React.useRef<HTMLCanvasElement | null>(null);\n    const outputRef = React.useRef<HTMLCanvasElement | null>(null);\n    const captureRef = React.useRef<OffscreenCanvas | null>(null);\n    const captureContextRef =\n      React.useRef<OffscreenCanvasRenderingContext2D | null>(null);\n    const outputSurfaceRef = React.useRef<OffscreenCanvas | null>(null);\n    const instanceRef = React.useRef<SceneFilterInstance<Props> | null>(null);\n\n    const passedPropsRef = React.useRef(props);\n    passedPropsRef.current = props;\n    const frameRef = React.useRef(frame);\n    frameRef.current = frame;\n    const timeRef = React.useRef(frame / fps);\n    timeRef.current = frame / fps;\n\n    React.useLayoutEffect(() => {\n      const layout = layoutRef.current;\n      const output = outputRef.current;\n      if (!layout || !output) {\n        return;\n      }\n      const capture = takeOffscreen(layout);\n      const context = capture.getContext(\"2d\");\n      if (!context) {\n        throw new Error(\"canvas-presentation: failed to acquire a 2D context\");\n      }\n      const surface = takeOffscreen(output);\n      captureRef.current = capture;\n      captureContextRef.current = context;\n      outputSurfaceRef.current = surface;\n      instanceRef.current = shader(surface);\n\n      return () => {\n        instanceRef.current?.cleanup();\n        instanceRef.current = null;\n        captureRef.current = null;\n        captureContextRef.current = null;\n        outputSurfaceRef.current = null;\n      };\n    }, [shader]);\n\n    React.useLayoutEffect(() => {\n      const layout = layoutRef.current;\n      if (!layout) {\n        return;\n      }\n      layout.layoutSubtree = true;\n      const handlePaint = () => {\n        const scene = layout.firstElementChild;\n        const capture = captureRef.current;\n        const context = captureContextRef.current;\n        const instance = instanceRef.current;\n        if (!scene || !capture || !context || !instance) {\n          return;\n        }\n        const elementImage = layout.captureElementImage(scene);\n        try {\n          context.reset();\n          context.drawElementImage(elementImage, 0, 0);\n        } finally {\n          elementImage.close();\n        }\n        if (capture.width === 0 || capture.height === 0) {\n          instance.clear();\n          return;\n        }\n        instance.draw({\n          scene: capture,\n          width: capture.width,\n          height: capture.height,\n          frame: frameRef.current,\n          time: timeRef.current,\n          passedProps: passedPropsRef.current,\n        });\n      };\n      layout.addEventListener(\"paint\", handlePaint);\n      return () => layout.removeEventListener(\"paint\", handlePaint);\n    }, []);\n\n    React.useLayoutEffect(() => {\n      const layout = layoutRef.current;\n      if (!layout) {\n        return;\n      }\n      const observer = new ResizeObserver(([entry]) => {\n        const capture = captureRef.current;\n        const surface = outputSurfaceRef.current;\n        if (!capture || !surface) {\n          return;\n        }\n        const width = entry.devicePixelContentBoxSize[0].inlineSize;\n        const height = entry.devicePixelContentBoxSize[0].blockSize;\n        capture.width = width;\n        capture.height = height;\n        surface.width = width;\n        surface.height = height;\n        layout.requestPaint?.();\n      });\n      observer.observe(layout, { box: \"device-pixel-content-box\" });\n      return () => observer.disconnect();\n    }, []);\n\n    React.useLayoutEffect(() => {\n      const layout = layoutRef.current;\n      if (!layout) {\n        return;\n      }\n      const handle = delayRender(\"canvas-presentation: filter paint\");\n      const settle = () => continueRender(handle);\n      layout.addEventListener(\"paint\", settle, { once: true });\n      layout.requestPaint?.();\n      return () => {\n        layout.removeEventListener(\"paint\", settle);\n        continueRender(handle);\n      };\n    });\n\n    return (\n      <AbsoluteFill>\n        <canvas ref={layoutRef} style={LAYER}>\n          {props.children}\n        </canvas>\n        <canvas ref={outputRef} style={OUTPUT_LAYER} />\n      </AbsoluteFill>\n    );\n  };\n}\n\ntype CanvasPresentationOptions<Props extends Record<string, unknown>> = {\n  shader: SceneShader<Props>;\n  fallback: React.FC<TransitionPresentationComponentProps<Props>>;\n};\n\nfunction makeCanvasPresentation<Props extends Record<string, unknown>>({\n  shader,\n  fallback: Fallback,\n}: CanvasPresentationOptions<Props>): (\n  props: Props,\n) => TransitionPresentation<Props> {\n  const Canvas = makeCanvasComponent(shader);\n\n  const Presentation: React.FC<TransitionPresentationComponentProps<Props>> = (\n    props,\n  ) =>\n    isCanvasTransitionSupported() ? (\n      <Canvas {...props} />\n    ) : (\n      <Fallback {...props} />\n    );\n\n  return (props) => ({ component: Presentation, props });\n}\n\ntype CanvasFilterOptions<Props extends Record<string, unknown>> = {\n  shader: SceneFilter<Props>;\n  fallback: React.FC<Props & CanvasFilterProps>;\n};\n\nfunction makeCanvasFilter<Props extends Record<string, unknown>>({\n  shader,\n  fallback: Fallback,\n}: CanvasFilterOptions<Props>): React.FC<Props & CanvasFilterProps> {\n  const Canvas = makeFilterComponent(shader);\n\n  return function CanvasFilter(props) {\n    return isCanvasFilterSupported() ? (\n      <Canvas {...props} />\n    ) : (\n      <Fallback {...props} />\n    );\n  };\n}\n\ntype HologramProps = {\n  tint?: string;\n  glow?: number;\n  ghost?: number;\n  flicker?: number;\n  intensity?: number;\n};\n\nconst DEFAULTS = {\n  tint: \"#63e8ff\",\n  glow: 1,\n  ghost: 1,\n  flicker: 1,\n  intensity: 1,\n};\n\nconst FRAGMENT_SHADER = `#version 300 es\nprecision highp float;\n\nuniform sampler2D u_scene;\nuniform float u_aspect;\nuniform float u_frame;\nuniform vec3 u_tint;\nuniform float u_glow;\nuniform float u_ghost;\nuniform float u_flicker;\nuniform float u_intensity;\n\nin vec2 v_uv;\nout vec4 outColor;\n\nconst float PI = 3.141592653589793;\nconst float TAU = 6.28318530718;\nconst float GOLDEN = 2.39996323;\nconst int HALO_TAPS = 8;\nconst vec3 LUMA = vec3(0.299, 0.587, 0.114);\n\nfloat hash(vec2 p) {\n  return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123);\n}\n\nfloat lumaAt(vec2 uv) {\n  return dot(texture(u_scene, uv).rgb, LUMA);\n}\n\nvoid main() {\n  vec4 src = texture(u_scene, v_uv);\n  float amount = clamp(u_intensity, 0.0, 1.0);\n\n  if (!(amount > 0.001)) {\n    outColor = src;\n    return;\n  }\n\n  float row = floor(v_uv.y * 300.0);\n  float clock = floor(u_frame);\n  float slip =\n    (hash(vec2(row, clock)) - 0.5) * u_ghost * 0.006 * step(0.55, hash(vec2(row, clock + 3.0)));\n  vec2 base = vec2(v_uv.x + slip / u_aspect, v_uv.y);\n\n  vec4 held = texture(u_scene, base);\n  float lit = dot(held.rgb, LUMA);\n\n  vec2 apart = vec2(u_ghost * 0.0045 / u_aspect, u_ghost * 0.0035);\n  vec3 twin = texture(u_scene, base + apart).rgb;\n\n  float step2 = 0.0022;\n  float gx =\n    lumaAt(base + vec2(step2 / u_aspect, 0.0)) -\n    lumaAt(base - vec2(step2 / u_aspect, 0.0));\n  float gy = lumaAt(base + vec2(0.0, step2)) - lumaAt(base - vec2(0.0, step2));\n  float rim = clamp(length(vec2(gx, gy)) * 7.0, 0.0, 1.0);\n\n  vec3 halo = vec3(0.0);\n  for (int i = 0; i < HALO_TAPS; i++) {\n    float angle = float(i) * GOLDEN;\n    float reach = sqrt((float(i) + 0.5) / float(HALO_TAPS)) * u_glow * 0.022;\n    vec2 at = base + vec2(cos(angle) * reach / u_aspect, sin(angle) * reach);\n    halo += max(texture(u_scene, at).rgb - 0.34, vec3(0.0));\n  }\n  halo /= float(HALO_TAPS);\n\n  vec3 core = u_tint * (0.12 + lit * 1.55);\n  core = mix(core, held.rgb * u_tint * 1.9, 0.12);\n  core += u_tint * rim * 1.9 * u_glow;\n  core += halo * u_tint * 2.4 * u_glow;\n  core += twin * u_tint * 0.5 * u_ghost;\n\n  float interlace = mod(row, 2.0) < 1.0 ? 1.0 : 0.58;\n  core *= interlace;\n\n  float blink =\n    1.0 -\n    u_flicker *\n      (0.04 + 0.05 * hash(vec2(clock, 7.0))) *\n      (0.5 + 0.5 * sin(u_frame * TAU / 15.0));\n  core *= blink;\n\n  float presence = clamp(lit * 1.5 + rim * 0.8 + 0.03, 0.0, 1.0);\n  vec3 painted = clamp(u_tint * 0.035 + core * presence, 0.0, 1.0);\n\n  outColor = vec4(mix(src.rgb, painted, amount), src.a);\n}`;\n\nfunction toRgb(hex: string): [number, number, number] {\n  const value = hex.replace(\"#\", \"\");\n  const full =\n    value.length === 3\n      ? value\n          .split(\"\")\n          .map((c) => c + c)\n          .join(\"\")\n      : value;\n  const int = Number.parseInt(full, 16);\n  if (Number.isNaN(int)) return [1, 1, 1];\n  return [\n    ((int >> 16) & 255) / 255,\n    ((int >> 8) & 255) / 255,\n    (int & 255) / 255,\n  ];\n}\n\nconst shader = makeFilterShader<HologramProps>(\n  FRAGMENT_SHADER,\n  ({ gl, uniform, passedProps }) => {\n    const {\n      tint = DEFAULTS.tint,\n      glow = DEFAULTS.glow,\n      ghost = DEFAULTS.ghost,\n      flicker = DEFAULTS.flicker,\n      intensity = DEFAULTS.intensity,\n    } = passedProps;\n    gl.uniform3fv(uniform(\"u_tint\"), toRgb(tint));\n    gl.uniform1f(uniform(\"u_glow\"), glow);\n    gl.uniform1f(uniform(\"u_ghost\"), ghost);\n    gl.uniform1f(uniform(\"u_flicker\"), flicker);\n    gl.uniform1f(uniform(\"u_intensity\"), intensity);\n  },\n);\n\nconst HologramFallback: React.FC<HologramProps & CanvasFilterProps> = ({\n  children,\n  tint = DEFAULTS.tint,\n  intensity = DEFAULTS.intensity,\n}) => (\n  <AbsoluteFill>\n    <AbsoluteFill style={{ filter: `saturate(${1 - 0.5 * intensity})` }}>\n      {children}\n    </AbsoluteFill>\n    <AbsoluteFill\n      style={{\n        background: tint,\n        mixBlendMode: \"color\",\n        opacity: 0.75 * intensity,\n      }}\n    />\n    <AbsoluteFill\n      style={{\n        background:\n          \"repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.32) 0px, rgba(0, 0, 0, 0.32) 2px, transparent 2px, transparent 4px)\",\n        opacity: intensity,\n      }}\n    />\n  </AbsoluteFill>\n);\n\nconst HologramBase = makeCanvasFilter<HologramProps>({\n  shader,\n  fallback: HologramFallback,\n});\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  tint: {\n    type: \"color\",\n    default: \"#63e8ff\",\n    description: \"Tint\",\n  },\n  glow: {\n    type: \"number\",\n    min: 0,\n    max: 3,\n    step: 0.1,\n    default: 1,\n    description: \"Glow\",\n    hiddenFromList: false,\n  },\n  ghost: {\n    type: \"number\",\n    min: 0,\n    max: 3,\n    step: 0.1,\n    default: 1,\n    description: \"Ghost\",\n    hiddenFromList: false,\n  },\n  flicker: {\n    type: \"number\",\n    min: 0,\n    max: 3,\n    step: 0.1,\n    default: 1,\n    description: \"Flicker\",\n    hiddenFromList: false,\n  },\n  intensity: {\n    type: \"number\",\n    min: 0,\n    max: 1,\n    step: 0.05,\n    default: 1,\n    description: \"Intensity\",\n    hiddenFromList: false,\n  },\n  speed: {\n    type: \"number\",\n    default: 1,\n    min: 0.25,\n    max: 4,\n    step: 0.25,\n    description: \"Speed\",\n    hiddenFromList: false,\n  },\n  ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"tint\",\"glow\",\"ghost\",\"flicker\",\"intensity\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  tint: \"#63e8ff\",\n  glow: 1,\n  ghost: 1,\n  flicker: 1,\n  intensity: 1,\n  speed: 1,\n};\n\ntype HologramElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof HologramBase>;\n\nconst HologramInner = forwardRef<\n  HTMLDivElement,\n  HologramElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n  const outlineRef = useRef<HTMLDivElement>(null);\n  useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n  const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n  const sequenceProps: Record<string, unknown> = {};\n  for (const [key, value] of Object.entries(rest)) {\n    if (ELEMENT_PROP_KEYS.has(key)) {\n      if (value !== undefined) componentProps[key] = value;\n    } else {\n      sequenceProps[key] = value;\n    }\n  }\n  return (\n    <Sequence\n      layout=\"none\"\n      {...sequenceProps}\n      controls={controls}\n      name={name ?? \"<Hologram>\"}\n      outlineRef={outlineRef}\n    >\n      <div\n        ref={outlineRef}\n        style={{\n          position: \"relative\",\n          width: \"100%\",\n          height: \"100%\",\n          display: \"flex\",\n          alignItems: \"center\",\n          justifyContent: \"center\",\n          ...style,\n        }}\n      >\n        <HologramBase\n          {...(componentProps as unknown as ComponentProps<typeof HologramBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const Hologram = Interactive.withSchema({\n  Component: HologramInner,\n  componentName: \"<Hologram>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 90,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 90
}