Lens Flare
A WebGL2 shader of the glare a camera catches from the sun just out of frame: spectral ghosts, a rainbow halo arc and lit lens dust, swinging as it drifts.
Installation
pnpm dlx shadcn@latest add @breeze/lens-flareUsage
import { LensFlare } from "@/components/breeze/lens-flare"It sits behind a hero. The sun stays just out of frame, so you only see what it throws into the lens: glare spilling in, soft coloured ghosts mirrored through the centre, a rainbow halo arc and dust on the glass catching the light. The canvas is transparent, so your background shows through.
<section className="relative isolate overflow-hidden">
<LensFlare className="absolute inset-0 -z-10 h-full w-full" />
{/* content */}
</section>Props
| Prop | Type | Default | Description |
|---|---|---|---|
color | string | "#f3d29a" | Light colour, any CSS colour or var() |
x | number | 0.8 | Where the source sits across the box, 0 (left) to 1 (right) |
y | number | -0.05 | Where the source sits down the box. Just above 0 keeps the sun out of frame |
drift | number | 1 | How far the source wanders, like a hand-held camera. 0 holds it still |
ghosts | number | 1 | Brightness of the lens ghosts. 0 removes them |
dispersion | number | 1 | How far each ghost and the halo split into colours, like real glass. 0 keeps them white |
dirt | number | 0.6 | Dust and smudges on the lens, lit up near the source. 0 for clean glass |
streak | number | 1 | Brightness of the horizontal streak through the source |
glow | number | 1 | Overall brightness |
grain | number | 0 | Film grain amount. Off by default for a clean finish |
speed | number | 1 | Animation speed multiplier. 0 freezes the flare |
strength | number | 1 | Opacity multiplier |
fps | number | 60 | Frame rate cap |
Every prop updates live without restarting the animation. The ghosts sit on the line from the source through the centre, so they swing across the frame as the source moves. Each ghost splits into red, green and blue, so they come out in their own colours, and they bend toward the edges the way glass does. color tints the glare and dust; set dispersion={0} for white ghosts. It glows a little softer on dark pages. The animation pauses off-screen and shows a still frame with reduced motion.
Examples
Cool light from the left
<LensFlare
color="#bae6fd"
x={0.2}
y={-0.04}
className="absolute inset-0 h-full w-full"
/>