# flare

A lens flare or a glossy light sweep over a photo that follows the pointer or the scroll.

A warm light source sits on the photo: a soft glow with a hot core and, in lens style, a row of tinted ghosts along the line from the light through the centre of the frame, like a real lens. In sweep style a glossy band runs through the light at angle and catches the highlights of the picture, the way light slides over chrome or a watch case. The light follows the pointer and fades out when it leaves, travels across the photo with the scroll, or stays put. It is screened over the photo, so it brightens without clipping to white.

Module `media`, category Photo. Import `@dioramajs/media/flare`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/media/src/flare.ts)

A green slope over the sea with a lens flare that follows the pointer, its ghosts strung along the line through the center.

```html title="index.html"
<figure class="fl-hero">
  <img src="/media/coast/slope-1440.avif" alt="A green slope dropping to the sea under a bright sky" width="1440" height="960" data-dio="flare" data-dio-streak="0.4" data-dio-rest="0.3" />
</figure>
```

## Usage

Put it on: img, video.

`start()` registers `flare`, so the attribute alone puts it on an element.

```html
<img src="/cars/coupe.avif" alt="Silver coupe on a coastal road at dusk" data-dio="flare" data-dio-streak="0.4" data-dio-rest="0.3" />
```

In page transitions: Fades with the page transition; a flight carries the photo without the pointer light.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'lens' \| 'sweep'` | `'lens'` | lens draws a glow with ghosts along the axis through the centre; sweep draws a glossy band through the light that brightens the highlights. |
| `by` (rebuilds) | `data-dio-by` | `'pointer' \| 'scroll' \| 'fixed'` | `'pointer'` | pointer: the light follows the pointer and fades out when it leaves; scroll: it travels across the photo as the page scrolls; fixed: it stays at position. |
| `strength` | `data-dio-strength` | `number` 0 to 2 | `0.6` | Brightness of the whole flare: 0 turns it off. |
| `glow` | `data-dio-glow` | `number` 0 to 1 | `0.25` | Radius of the glow as a share of the photo's shorter side: 0 hides the glow. |
| `ghosts` | `data-dio-ghosts` | `number` 0 to 8 | `4` | Number of ghosts along the axis in lens style, up to 8: 0 shows none. |
| `streak` | `data-dio-streak` | `number` 0 to 1 | `0` | Brightness of a thin anamorphic streak across the frame, in a cool tint: 0 hides it. |
| `color` | `data-dio-color` | `color` | `'#ffe8c8'` | Color of the light; the streak takes a cooler shade of it. |
| `position` | `data-dio-position` | `[number, number]` 0 to 1 | `[0.8, 0.2]` | Where the light rests, sits with by fixed and travels through with by scroll, as shares of the box from its top left. |
| `travel` | `data-dio-travel` | `number` 0 to 2 | `0.6` | With by scroll, how far the light moves across the photo, as a share of its width: 0 keeps it at position. |
| `angle` | `data-dio-angle` | `number` 0 to 180° | `115` | Direction the sweep band runs across, like a CSS gradient angle: 90 is vertical. |
| `width` | `data-dio-width` | `number` 0.02 to 1 | `0.3` | Width of the sweep band as a share of the photo's diagonal. |
| `rest` | `data-dio-rest` | `number` 0 to 1 | `0` | With by pointer, the share of the light kept while the pointer is away, at position: 0 shows the plain photo at rest. |
| `ease` | `data-dio-ease` | `number` 0 to 0.5 s | `0.12` | Smoothing of the light following the pointer: 0 sticks to it. |
| `duration` | `data-dio-duration` | `number` 0 to 1.5 s | `0.4` | Length of the fade as the pointer light comes on and goes off. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `lens`, `sweep`
  - `lens` draws a glow with ghosts along the axis through the centre.
  - `sweep` draws a glossy band through the light that brightens the highlights.
- `by`: `pointer`, `scroll`, `fixed`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width). Draws only while something on it moves, then stops. With by pointer, only while the light fades or trails the pointer; with by scroll, only while the page scrolls; none at rest and none with by fixed. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. No fade and no smoothing: the pointer light appears, jumps and goes at once. With by scroll the light stays at position.

Runs on every device. With by pointer the light follows a finger while it is pressed and goes when it lifts; add touch-action: none to the image to keep a drag from scrolling the page. by scroll works the same on phones.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { flare: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 2.0 KB the first time a page uses it. GPU: One texture read per pixel and a handful of exponentials; the ghosts are math, not reads. Memory: The image only.

See [the quality plugin](/docs/effects/quality).

## Recipes

### A hero shot that catches the light

For cars, watches, jewelry or any photo that should feel lit, the flare follows the pointer, and `rest` keeps a little of it when the pointer is away.

```html
<img
  src="/cars/coupe.avif"
  data-dio="flare"
  data-dio-streak="0.4"
  data-dio-rest="0.3"
/>
```

### Light sliding over a product as the page scrolls

`style="sweep"` draws a glossy band instead of a lens flare; with `by="scroll"` it slides across as the image passes through the viewport.

```html
<img
  src="/watch/case.avif"
  data-dio="flare"
  data-dio-style="sweep"
  data-dio-by="scroll"
  data-dio-travel="1.2"
  data-dio-glow="0.1"
/>
```

### A low sun in the corner

With `by="fixed"` the light stays where `position` puts it, for a landscape that should feel shot into the sun.

```html
<img
  src="/trips/ridge.avif"
  data-dio="flare"
  data-dio-by="fixed"
  data-dio-position="0.85 0.15"
  data-dio-ghosts="6"
/>
```

## Notes

Keep the flare subtle on photos with text or faces. Under reduced motion the pointer light appears and moves without fades or smoothing, and with `by="scroll"` it stays at `position`.

`style` and `by` rebuild the effect; the other params change live.

## Related

- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [compare](/docs/effects/compare.md): Two pictures in one box, before and after, split by a line you drag, hover or scroll.
- [frost](/docs/effects/frost.md): Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.
- [glitch](/docs/effects/glitch.md): A digital glitch in short bursts: blocks slide sideways, color channels split, scanlines flicker.
- [image](/docs/effects/image.md): Draws the image or video unchanged, as a GL copy that page flights and other effects build on.
- [liquid](/docs/effects/liquid.md): The pointer leaves a fluid trail on a photo that settles back like water.
- [parallax](/docs/effects/parallax.md): The image drifts inside its frame with the pointer and the scroll; with a depth map, in 2.5D.
- [pixelate](/docs/effects/pixelate.md): The image resolves from big pixels to sharp as it scrolls into view, or breaks into pixels on hover.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
