Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

flare

PhotoAlso inScroll scenes

@dioramajs/media/flareSource

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

View as Markdown
On this page
A green slope dropping to the sea under a bright sky

Live preview needs WebGPU or WebGL 2. A green slope over the sea with a lens flare that follows the pointer, its ghosts strung along the line through the center.

This example failed to draw.

Move the pointer over the photo. The light source follows it; switch the style to a glossy sweep or let the scroll drive it.
Params of flare
style

lens draws a glow with ghosts along the axis through the centre.

by

Usage

Put it on img, video. start() registers flare, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.

To change its code, copy the source into your effects folder; the copy replaces the built-in.

Terminal window
npx @dioramajs/diorama add flare
<figure class="fl-hero">
<img
src="/media/coast/slope-1440.avif"
width="1440"
height="960"
data-dio="flare"
data-dio-streak="0.4"
data-dio-rest="0.3"
/>
</figure>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('img', 'flare', {
style: 'lens',
by: 'pointer',
strength: 0.6,
glow: 0.25,
ghosts: 4,
streak: 0.4,
color: '#ffe8c8',
position: [0.8, 0.2],
travel: 0.6,
angle: 115,
width: 0.3,
rest: 0.3,
ease: 0.12,
duration: 0.4,
})
import { start } from '@dioramajs/diorama'
import flare from '@dioramajs/media/flare'
const app = start()
app.attach('img', flare({
style: 'lens',
by: 'pointer',
strength: 0.6,
glow: 0.25,
ghosts: 4,
streak: 0.4,
color: '#ffe8c8',
position: [0.8, 0.2],
travel: 0.6,
angle: 115,
width: 0.3,
rest: 0.3,
ease: 0.12,
duration: 0.4,
}))

Page transitions

Fades with the page transition; a flight carries the photo without the pointer light. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
stylerebuildsdata-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.
byrebuildsdata-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.
strengthdata-dio-strengthnumber0 to 20.6Brightness of the whole flare: 0 turns it off.
glowdata-dio-glownumber0 to 10.25Radius of the glow as a share of the photo's shorter side: 0 hides the glow.
ghostsdata-dio-ghostsnumber0 to 84Number of ghosts along the axis in lens style, up to 8: 0 shows none.
streakdata-dio-streaknumber0 to 10Brightness of a thin anamorphic streak across the frame, in a cool tint: 0 hides it.
colordata-dio-colorcolor'#ffe8c8'Color of the light; the streak takes a cooler shade of it.
positiondata-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.
traveldata-dio-travelnumber0 to 20.6With by scroll, how far the light moves across the photo, as a share of its width: 0 keeps it at position.
angledata-dio-anglenumber0 to 180°115Direction the sweep band runs across, like a CSS gradient angle: 90 is vertical.
widthdata-dio-widthnumber0.02 to 10.3Width of the sweep band as a share of the photo's diagonal.
restdata-dio-restnumber0 to 10With by pointer, the share of the light kept while the pointer is away, at position: 0 shows the plain photo at rest.
easedata-dio-easenumber0 to 0.5 s0.12Smoothing of the light following the pointer: 0 sticks to it.
durationdata-dio-durationnumber0 to 1.5 s0.4Length of the fade as the pointer light comes on and goes off.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads delta, height, presence, reducedMotion, size and 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. How a frame is decided.

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.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { flare: { reducedMotion: 'off' } } })

Cost and quality

Download
2.0 KB min+gzip 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.
Frames
Idle at rest

It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.

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.

<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.

<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.

<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.