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

smoke

TextAlso in3D and productScroll scenes

@dioramajs/text/smokeSource

A heading condenses out of drifting volumetric smoke as it comes into view, or dissolves into it as it leaves.

View as Markdown
On this page

Islay · Distillery tours

Peat, smoke and sea air

Walk the malting floor, stand by the kiln while the peat burns, and taste a ten-year cask straight from the warehouse. Daily at eleven and three.

Live preview needs WebGPU or WebGL 2. A distillery tour headline on a dark page that condenses out of drifting, backlit smoke, with a kicker and a short paragraph under it.

This example failed to draw.

Press Condense again to dissolve the heading and bring it back. Switch the style or the trigger, or move the sliders; mist and ink switch the example to a light page.

Leaving the page dissolves the heading into smoke; entering condenses it.

Params of smoke
style

smoke is grey-white smoke lit from behind, for dark pages.

trigger

view condenses the heading when it comes into view, a first-screen heading included.

Usage

Put it on a large heading or a short line of display text. Not img, video, canvas, svg or form fields. Text with text-shadow, a text stroke, background-clip: text or vertical writing stays as it is. start() registers smoke, 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 smoke
<div class="sm-hero">
<p class="sm-kicker">Islay · Distillery tours</p>
<h2
class="sm-headline"
data-dio="smoke"
>Peat, smoke and sea air</h2>
<p class="sm-lede">Walk the malting floor, stand by the kiln while the peat burns, and taste a ten-year cask straight from the warehouse. Daily at eleven and three.</p>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.sm-headline', 'smoke', {
style: 'smoke',
trigger: 'view',
density: 1,
speed: 1,
rise: 1,
turbulence: 1,
duration: 2.4,
})
import { start } from '@dioramajs/diorama'
import smoke from '@dioramajs/text/smoke'
const app = start()
app.attach('.sm-headline', smoke({
style: 'smoke',
trigger: 'view',
density: 1,
speed: 1,
rise: 1,
turbulence: 1,
duration: 2.4,
}))

Page transitions

Leaving a page, the heading dissolves up into smoke; entering, it condenses out of it. 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'smoke' | 'mist' | 'ink''smoke'
  • smoke is grey-white smoke lit from behind, for dark pages.
  • mist is a soft pale fog for light pages.
  • ink blooms in the color of the text, like ink in water.
triggerrebuildsdata-dio-trigger'view' | 'scroll' | 'hover' | 'loop''view'
  • view condenses the heading when it comes into view, a first-screen heading included.
  • scroll condenses it toward the middle of the viewport and dissolves it as it leaves.
  • hover lets wisps curl off the letters under the pointer.
  • loop keeps smoke rising off the letters.
densitydata-dio-densitynumber0 to 31Thickness of the smoke; 0 leaves only the letters softening and fading.
speeddata-dio-speednumber0 to 31Pace of the swirling and drifting; 0 freezes the smoke in place.
risedata-dio-risenumber0 to 31How far the smoke drifts upward as it leaves the letters; 0 keeps it in place.
turbulencedata-dio-turbulencenumber0 to 31Strength of the swirls; 0 lets the smoke drift without curling.
durationdata-dio-durationnumber0.5 to 8 s2.4Time the view trigger takes to condense, and a hover wisp takes to settle.
colorrebuildsdata-dio-colorstring''Any CSS color for the smoke; empty uses grey-white for smoke, a pale fog for mist or the text color for ink.
seeddata-dio-seednumber1 to 1001Picks the pattern of the swirls; the same seed drifts the same way.

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, presence, size, x and y . Draws at a steady rate while it is on screen and stops when it leaves. While the view trigger condenses, while scrolling with the scroll trigger and while hover wisps settle; none at rest. The loop trigger draws 30 frames a second while it is on screen. How a frame is decided.

Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: the text shows as it is, without smoke.

Runs on every device. The same as with a mouse; with the hover trigger a tap breathes a wisp off the letters.

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

import { start } from '@dioramajs/diorama'
start({ effects: { smoke: { reducedMotion: 'static' } } })

Cost and quality

Download
13.6 KB min+gzip the first time a page uses it
GPU
One quad over the text and the room its smoke needs, marching 16 steps through the volume per pixel at the high tier, each with up to eight texture reads; empty air costs three.
Memory
A canvas of the text at twice its CSS size, a coarse half-float field of the glyphs and a 32 by 32 by 32 noise cube shared by every heading: about 3 MB for a large heading.
Frames
Draws while on screen

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
low8 steps through the volume without a light step, and the text rastered at 1 device pixel per CSS pixel.
medium12 steps with one step toward the light.

Recipes

Fog that lifts as the visitor scrolls

data-dio-trigger="scroll" ties the smoke to the heading’s place in the window: it condenses as the heading rises toward the middle, stays plain text around the middle, and dissolves upward as it leaves the top. Scrolling back runs it in reverse. A heading on the first screen starts as text and only dissolves once the page scrolls. mist is a pale fog for light pages, mixed from the page color and the text color.

<h2
data-dio="smoke"
data-dio-style="mist"
data-dio-trigger="scroll"
>Morning on the lake</h2>

Ink blooming in water

ink takes the text color and lets it billow out in dark plumes that curl more and rise less, the way ink spreads in a glass of water. A higher turbulence curls it further.

<h2
data-dio="smoke"
data-dio-style="ink"
data-dio-turbulence="1.6"
style="color: #1c3f8a"
>Written in water</h2>

A heading that keeps smoldering

data-dio-trigger="loop" keeps the letters crisp while thin plumes rise off a few of them at a time, at 30 frames a second while the heading is on screen and none off screen. speed="0" freezes the smoke, and rise sets how high it climbs.

<h2
data-dio="smoke"
data-dio-trigger="loop"
data-dio-rise="1.4"
>Slow burn</h2>

Notes

The smoke is a volume, not a flat picture: each pixel marches a short ray through it, front to back, from a little in front of the page to a little behind it. Its shape comes from a coarse field of the glyphs (their distance, two blurs and a plume that streams up off their tops), swirled by a tiling 3D noise and carried upward over time. Light comes from behind and above: each step looks once or twice toward the light for the smoke in the way, so thin wisps glow at their edges and the thick parts fall into their own shadow. The letters themselves sit in the middle of the volume, so smoke in front of them veils them and smoke behind them does not. Because the ray goes through the page camera, the layers of smoke shift against each other as the heading moves through the window.

At rest the heading is plain DOM text: the view trigger draws only while it condenses, the scroll trigger only while scrolling and the hover trigger only while wisps settle. Under reduced motion the text shows as it is, without smoke. Text with text-shadow, -webkit-text-stroke, background-clip: text or a vertical writing mode stays as it is, with a warning in development. style, trigger and color rebuild the effect when they change.