Animating a shader

Tween a shader's props with Motion, GSAP or anything else that animates a number.

A prop is a value the GPU reads every frame, so animating one is just changing it over time. Tween it the way you'd tween anything else and pass the result to the component.

Tweening a prop with Motion

This fades an Aurora's sheen in when the component mounts:

import { useEffect, useState } from 'react'
import { animate } from 'motion'

function Hero() {
  const [intensity, setIntensity] = useState(0)
  useEffect(() => {
    const controls = animate(0, 0.5, { duration: 1.2, ease: [0.16, 1, 0.3, 1], onUpdate: setIntensity })
    return () => controls.stop()
  }, [])

  return (
    <Shader className="w-full h-96">
      <Aurora intensity={intensity} />
    </Shader>
  )
}

Colours tween the same way (animate('#7C3AED', '#F97316', …)). For a position or a transform, tween each number and pass the object: transform={{ ...rest, rotation }}.

Tweening a prop with GSAP

GSAP tweens a plain object. Read it in onUpdate:

import gsap from 'gsap'

const state = { intensity: 0 }
gsap.to(state, {
  intensity: 0.5,
  duration: 1.2,
  ease: 'expo.out',
  onUpdate: () => setIntensity(state.intensity)
})

Scroll works the same way: Motion's scroll() or a GSAP ScrollTrigger with scrub: true drives the tween from scroll position.

Animations designed in the editor

An entrance, hover or scroll animation designed in the Shaders editor comes with the shader when your agent installs it (<Component>.animations.ts beside the component). The agent builds it with the motion library your project already uses. Tell it when each one should play: on load, on hover, as the section scrolls into view.

Keeping animations smooth

Changing an animated prop updates a uniform, so nothing recompiles. Two cases cost more:

  • Opacity reaching exactly 1: a layer at opacity 1 takes a different path than one below 1, so the effect recompiles once when a fade gets there. That's fine at the end of a fade. Don't cross 1 on every frame.
  • Compile-time props recompile the effect whenever they change, so don't animate them. See Props and reactivity.

For motion that runs forever inside the shader (a breathing glow, a light that follows the mouse), use dynamic props instead. They need no animation code.