# smoke

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

Smoke drifts in from below, swirls and thickens into the shapes of the letters, and the letters sharpen out of it until the plain text takes over. Dissolving, the letters soften and break up while plumes curl off their tops and rise away. The smoke is a real volume with depth: it is lit from behind and above, so thin wisps glow at their edges and the thick parts fall into their own shadow, and its layers shift against each other as the page scrolls. Styles give grey-white smoke for dark pages, a soft pale fog for light ones, or ink blooming in water in the color of the text.

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

A distillery tour headline on a dark page that condenses out of drifting, backlit smoke, with a kicker and a short paragraph under it.

```html title="index.html"
<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>
```

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

```html
<h1 data-dio="smoke">Out of the smoke</h1>
```

In page transitions: Leaving a page, the heading dissolves up into smoke; entering, it condenses out of it.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-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. |
| `trigger` (rebuilds) | `data-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. |
| `density` | `data-dio-density` | `number` 0 to 3 | `1` | Thickness of the smoke; 0 leaves only the letters softening and fading. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `1` | Pace of the swirling and drifting; 0 freezes the smoke in place. |
| `rise` | `data-dio-rise` | `number` 0 to 3 | `1` | How far the smoke drifts upward as it leaves the letters; 0 keeps it in place. |
| `turbulence` | `data-dio-turbulence` | `number` 0 to 3 | `1` | Strength of the swirls; 0 lets the smoke drift without curling. |
| `duration` | `data-dio-duration` | `number` 0.5 to 8 s | `2.4` | Time the view trigger takes to condense, and a hover wisp takes to settle. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Any CSS color for the smoke; empty uses grey-white for smoke, a pale fog for mist or the text color for ink. |
| `seed` | `data-dio-seed` | `number` 1 to 100 | `1` | Picks the pattern of the swirls; the same seed drifts the same way. |

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

### Variants

- `style`: `smoke`, `mist`, `ink`
  - `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.
- `trigger`: `view`, `scroll`, `hover`, `loop`
  - `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.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`presence`](/docs/api/inputs#presence), [`size`](/docs/api/inputs#size), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-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. See [how a frame is decided](/docs/concepts/frames).

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

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

start({ effects: { smoke: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 13.6 KB 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.

- low: 8 steps through the volume without a light step, and the text rastered at 1 device pixel per CSS pixel.
- medium: 12 steps with one step toward the light.

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

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

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

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

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

## Related

- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
