Draft

Letters from the archive

A box of old letters, typed on onionskin paper, turned up in the basement. Most are about the weather. One of them is not.

Updated 2 min ago Open

How it works

Burning through a noise field

A dissolve is a threshold moving through a noise texture: every pixel has a random number, and once the progress passes it, the pixel is gone. The glowing edge is just the pixels whose number is about to be passed. One SVG filter does all of it, on live HTML.

1. A threshold field from feTurbulence

<feTurbulence type="fractalNoise"> fills the element with Perlin noise; its baseFrequency is the inverse of the Noise scale, so a scale of 48 px gives patches roughly that big. The filter reads the noise's alpha channel, the only one that is never premultiplied, copies it into red and makes the result opaque.

That noise is bell-shaped: values cluster around 0.5 (measured in Chromium: the 1st and 99th percentiles sit near 0.23 and 0.77, the standard deviation about 0.12). Moving a threshold linearly through it would burn almost nothing for the first third of the progress, rush through the middle and crawl at the end. An <feFuncR type="table"> fixes that: its tableValues are the normal distribution's CDF sampled at 33 points, which maps the noise to evenly spread values from 0 to 1. Now Progress 0.3 burns about 30% of the element (with the burn starting nowhere in particular; a direction ramp skews it).

With Burn starts at, a grey ramp is mixed in (an <feImage> of a 64×64 PNG stretched over the element, blended by feComposite operator="arithmetic" as (1 − strength)·noise + strength·ramp). Low values burn first, so a ramp that is dark at the bottom makes the fire climb upwards, and the noise keeps the front ragged.

2. Three steps through the same field

A soft step is one <feColorMatrix> row: A = k·(R − t), clamped to 0–1 by the browser, with k the Edge sharpness. The filter takes three of them at nested thresholds:

burnt
t = 0.406: below it nothing is left. This is the outer edge of the ember.
ember
t + ember width = 0.436: between the two, the edge glows.
intact
+ char width = 0.466: between ember and intact, a darker scorched band; above it, the original content.

The front t moves from −(ember + char) − 1/k at progress 0 to 1 at progress 1. Those end points are exact rather than approximate: at 0 even a field value of 0 is a full 1/k above the last step, so nothing changes, and at 1 no value is above the first. That is why the component can switch the filter on and off at the ends without a visible jump, and skips it entirely at rest.

3. Painting the bands

SourceGraphic operator="in" the intact mask is what remains of the content. Each band is an <feFlood> of its color, kept in the outer mask, cut out of the inner one and kept in SourceAlpha, so the edge only glows where the element actually had pixels: the transparent corners of a rounded card never catch fire. A blurred copy of the ember band is merged twice underneath for the glow.

The flip side: a soft box-shadow is pixels too, so it would catch fire as a smoky orange haze. Put the shadow on an element outside the dissolving one, or leave it off, as the demo card does.

<svg width="0" height="0" aria-hidden="true">
  <filter id="dissolve" x="-6%" y="-6%" width="112%" height="112%"
          color-interpolation-filters="sRGB">
    <feTurbulence type="fractalNoise" baseFrequency="0.02083" numOctaves="3" seed="7" result="turbulence" />
    <feColorMatrix in="turbulence" type="matrix" values="0 0 0 1 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 1" />
    <feComponentTransfer result="noise">
      <feFuncR type="table" tableValues="0 0 0.0001 0.0004 0.001 0.0022 0.0049 0.01 0.0194 0.0353 0.0606 0.0983 0.1508 0.2192 0.3027 0.3981 0.5 0.6019 0.6973 0.7808 0.8492 0.9017 0.9394 0.9647 0.9806 0.99 0.9951 0.9978 0.999 0.9996 0.9999 1 1" />
    </feComponentTransfer>
    <feImage href="data:image/png;base64,…" preserveAspectRatio="none" result="ramp" />
    <feComposite in="noise" in2="ramp" operator="arithmetic" k2="0.5" k3="0.5" result="field" />
    <feColorMatrix in="field" type="matrix" values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  50 0 0 0 -20.3" result="notBurnt" />
    <feColorMatrix in="field" type="matrix" values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  50 0 0 0 -21.8" result="unlit" />
    <feColorMatrix in="field" type="matrix" values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  50 0 0 0 -23.3" result="intact" />
    <feComposite in="SourceGraphic" in2="intact" operator="in" result="content" />
    <feFlood flood-color="#2a1208" />
    <feComposite in2="unlit" operator="in" />
    <feComposite in2="intact" operator="out" />
    <feComposite in2="SourceAlpha" operator="in" result="charBand" />
    <feFlood flood-color="#ffae3d" />
    <feComposite in2="notBurnt" operator="in" />
    <feComposite in2="unlit" operator="out" />
    <feComposite in2="SourceAlpha" operator="in" result="emberBand" />
    <feGaussianBlur in="emberBand" stdDeviation="4" result="glow" />
    <feMerge>
      <feMergeNode in="glow" />
      <feMergeNode in="glow" />
      <feMergeNode in="content" />
      <feMergeNode in="charBand" />
      <feMergeNode in="emberBand" />
    </feMerge>
  </filter>
</svg>

4. Driving it

CSS custom properties can't reach SVG filter attributes, so the progress has to come from script, which rewrites the three feColorMatrix values every frame. The <Dissolve> component takes a progress prop; drive it with a Tween, a scroll position or a slider like the one in the panel:

<script>
  import { Tween } from 'svelte/motion';
  import { cubicIn } from 'svelte/easing';
  import { Dissolve } from '@sunsided/web-visual-fx/svelte';
  const burn = new Tween(0, { duration: 1200, easing: cubicIn });
</script>

<Dissolve progress={burn.current}>
  <article>…</article>
</Dissolve>
<button onclick={() => burn.set(1)}>Dismiss</button>

For elements that come and go with {#if}, the dissolve transition does the same without a wrapper. It is a tick transition: it adds a hidden filter to document.body, points the element's filter at it, updates it per frame and removes it when the frames stop. Choose Play with: transition to see it.

<script>
  import { dissolve } from '@sunsided/web-visual-fx/svelte';
  let open = $state(true);
</script>

{#if open}
  <div class="toast" transition:dissolve={{ duration: 1200, origin: 'right' }}>
    Saved. <button onclick={() => (open = false)}>Dismiss</button>
  </div>
{/if}

Reduced motion and fallback

  • With prefers-reduced-motion: reduce, both the component (in mode="auto") and the transition turn into a plain opacity fade with the same timing. Fire spreading across the screen is exactly the kind of large motion that setting asks to avoid, and a fade still tells the user the element went away.
  • At progress 1 the wrapper is visibility: hidden, so a burnt card can't be clicked or reached by a screen reader. The text inside stays real text throughout.
  • This isn't a looping animation, so the page's pause toggle (data-motion) doesn't apply; it only plays when someone asks for it.

Browser support and performance

All primitives used here are part of SVG filters, Baseline widely available (webstatus.dev), and filter: url(#id) on HTML works in every current engine. Driving progress from CSS with @property would only be Baseline since July 2024 (webstatus.dev), but it couldn't reach the filter anyway, so nothing here depends on it. Checked in Chromium only; Firefox and Safari are untested.

  • During the transition the filter reruns on every frame over the whole element, and feTurbulence with several octaves is the expensive part. That is fine for a card or a toast; for a full-screen section, lower the octaves.
  • At rest (progress 0 or 1) no filter is applied, so a dismissable element costs nothing until it is dismissed.
  • The glow can reach up to the filter region, 6% beyond the element on each side. A wider glow on a large element is clipped there.

Back to the demo ↑