Aurora shader preview: The northern lights folding over a starry sky, green below and violet above.
ittybitty

Aurora

The northern lights folding over a starry sky, green below and violet above.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add aurora.js, ittybitty-shader.js, runtime.js next to this page. Highlighted values follow the controls.

<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="aurora" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="aurora" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>

<script type="module">
  import { aurora } from './aurora.js';

  const canvas = document.getElementById('aurora');
  const effect = aurora(canvas, {
    showSky: true,
    showStars: true,
    showLights: true,
    speed: 0.4,
    zoom: 1,
    intensity: 1,
    height: 0.6,
    folds: 0.6,
    rays: 0.6,
    stars: 0.6,
    low: '#35ff9a',
    high: '#9a4dff',
    sky: '#050a18',
    // Performance
    dpr: 1.5,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

Curtains of light traced through a stack of altitudes, so they have real depth: thin sheets that fold and drift, combed into fine vertical rays, glowing green at their crisp lower edge and fading to violet in their high reaches, as the real aurora does.

Payload
5.5 KB brotli for aurora.js and ittybitty-shader.js and runtime.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 2.
Frame rate
Display rate.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Shows a single still frame. Controls still update it.
Layers
Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
Browsers
Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
Licence
MIT. Copy it, change it, ship it.