VFX-JS
    Preparing search index...

    The main interface of VFX-JS.

    Index

    Constructors

    • Creates VFX instance and start playing immediately.

      Parameters

      Returns VFX

      When WebGL is not available in the current environment.

    Accessors

    • get maxTextureSize(): number

      Returns number

    • get time(): number

      Current virtual animation time in seconds (the value behind the
      time uniform).

      Returns number

    • get timeScale(): number

      Playback rate of the animation clock.

      1 is realtime, 0 pauses (frames still render), and negative
      values run time backwards. Can be changed at any time.

      Note: deltaTime follows this rate, so it goes negative while
      rewinding. Time-only effects handle that fine; effects that integrate
      motion over deltaTime (particles, fluid, datamosh) are not designed
      to run backwards and may behave unexpectedly.

      Returns number

    • set timeScale(scale: number): void

      Parameters

      • scale: number

      Returns void

    Methods

    • Register an element to track the position and render visual effects in the area.

      Parameters

      • element: HTMLElement
      • opts: VFXProps
      • OptionalinitialCapture: OffscreenCanvas

      Returns Promise<void>

    • Register an element using html-in-canvas API.
      Wraps the element in a <canvas layoutsubtree> and captures via drawElementImage.
      Falls back to add() if html-in-canvas is not supported.

      Parameters

      Returns Promise<void>

    • Destroy VFX and stop rendering.

      Returns void

    • Start rendering VFX.

      Returns void

    • Remove the element from VFX and stop rendering the shader.

      Parameters

      • element: HTMLElement

      Returns void

    • Render the whole scene once, manually.
      This is useful when you want to control the rendering timings manually by combining with autoplay: false.

      Returns void

    • Pin the animation clock to an absolute time in seconds.

      The next render() uses the value verbatim, so setTime(t); render()
      produces a deterministic frame — handy for scrubbing a timeline or
      capturing stable snapshots (e.g. visual regression tests):

      const vfx = new VFX({ autoplay: false });
      await vfx.add(img, { effect });
      vfx.setTime(1.5);
      vfx.render();

      Note: this drives deltaTime too, so a jump produces one large
      deltaTime on the next frame. Time-only effects are unaffected, but
      effects that integrate motion over deltaTime (particles, fluid,
      datamosh) may jump — pause first (timeScale = 0) when scrubbing them.

      Parameters

      • time: number

      Returns void

    • Stop rendering VFX.
      You can restart rendering by calling VFX.play() later.

      Returns void

    • Update the texture for the given element.

      For an HTMLImageElement, reloads its current src — call this
      after changing img.src. Videos refresh automatically (no-op).
      Otherwise re-snapshots the element's DOM subtree.

      Useful for elements whose contents change (input, textarea, or an
      <img> whose src swaps).

      Parameters

      • element: HTMLElement

      Returns Promise<void>

    • Replace the effect chain on an already-registered effect-path
      element in-place. Effects whose reference is unchanged keep their
      init state and GPU resources; only added/removed effects run
      init / dispose. The element's source texture is preserved.

      Useful for live UIs that reorder or toggle effects without paying
      the cost of vfx.remove + vfx.add (which reloads the source).

      Parameters

      Returns Promise<void>

    • Create a VFX instance if WebGL is available, or return null.

      Parameters

      Returns VFX | null