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.

Props
Color
#f3d29a
X0.80
Y-0.05
Drift1.00
Ghosts1.00
Dispersion1.00
Lens dirt0.60
Streak1.00
Glow1.00
Grain0.0
Speed1.00
Strength1.00

Installation

pnpm dlx shadcn@latest add @breeze/lens-flare

Usage

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

PropTypeDefaultDescription
colorstring"#f3d29a"Light colour, any CSS colour or var()
xnumber0.8Where the source sits across the box, 0 (left) to 1 (right)
ynumber-0.05Where the source sits down the box. Just above 0 keeps the sun out of frame
driftnumber1How far the source wanders, like a hand-held camera. 0 holds it still
ghostsnumber1Brightness of the lens ghosts. 0 removes them
dispersionnumber1How far each ghost and the halo split into colours, like real glass. 0 keeps them white
dirtnumber0.6Dust and smudges on the lens, lit up near the source. 0 for clean glass
streaknumber1Brightness of the horizontal streak through the source
glownumber1Overall brightness
grainnumber0Film grain amount. Off by default for a clean finish
speednumber1Animation speed multiplier. 0 freezes the flare
strengthnumber1Opacity multiplier
fpsnumber60Frame 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