currentFrame) each requestAnimationFrame tick and passing it to the shader as the u_time uniform (in seconds). Two props — speed and frame — give you full control over how time progresses.
speed
speed is a multiplier applied to the delta time on every frame. The default is 0 (paused at construction time); named shader components typically default to 1.
| Value | Effect |
|---|---|
1 | Normal forward playback |
0.5 | Half speed |
2 | Double speed |
-1 | Reverse playback |
0 | Stopped |
When
speed is 0, the requestAnimationFrame loop is cancelled entirely. A fully stopped shader has zero recurring CPU or GPU cost — it is as cheap as a static image.frame
frame is an offset applied to the starting u_time value, in milliseconds. It does not affect playback speed; it shifts where in the animation the shader starts.
Use frame whenever you need a deterministic result:
- Server-side rendering (SSR) — set a fixed frame so the initial HTML matches the first client render.
- Visual regression tests — snapshot a specific point in the animation.
- Resuming a saved state — store
getCurrentFrame()and restore it later.
Tab visibility
ShaderMount listens to the document visibilitychange event. When the tab is hidden, it resets the effective speed to 0 and cancels the animation loop. When the tab becomes visible again, it restores the original speed and resumes the loop. The currentFrame value does not advance while the tab is hidden, so animations resume from where they left off rather than jumping forward.
Methods
setSpeed(newSpeed)
Change speed at any time without recreating the shader.
speed prop in React.
setFrame(newFrame)
Jump to an exact point in the animation (milliseconds from time zero) and trigger an immediate re-render.
getCurrentFrame()
Returns the total number of animation milliseconds played so far, not counting time when the tab was hidden or speed was 0.
Examples
- React
- Vanilla JS