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

hologram

TextAlso in3D and product

@dioramajs/text/hologramSource

A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.

View as Markdown
On this page

Live keynote · 18:00 UTC

Orbital 7

The first satellite network you can rent by the minute. Join the stream for the unveiling.

Live preview needs WebGPU or WebGL 2. A satellite network launch page whose title is projected as a cyan hologram from an emitter disc, scanned in from the bottom.

This example failed to draw.

Switch the style and the trigger, or move the sliders. Move the pointer near the hologram to tip it toward you.
Params of hologram
style

projector stands on an emitter.

trigger

view scans in as it shows.

Usage

Put it on a heading, a label or a short line of text, best on a dark background. Not img, video, canvas, svg or form fields. start() registers hologram, 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 hologram
<section class="hg-launch">
<p class="hg-kicker">Live keynote · 18:00 UTC</p>
<h2 class="hg-title" data-dio="hologram">Orbital 7</h2>
<p class="hg-line">The first satellite network you can rent by the minute. Join the stream for the unveiling.</p>
</section>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.hg-title', 'hologram', {
style: 'projector',
trigger: 'view',
layers: 6,
depth: 0.3,
scan: 1,
flicker: 0.4,
sway: 6,
tilt: 8,
})
import { start } from '@dioramajs/diorama'
import hologram from '@dioramajs/text/hologram'
const app = start()
app.attach('.hg-title', hologram({
style: 'projector',
trigger: 'view',
layers: 6,
depth: 0.3,
scan: 1,
flicker: 0.4,
sway: 6,
tilt: 8,
}))

Page transitions

The projection fades with the page. 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'projector' | 'card' | 'ghost''projector'
  • projector stands on an emitter.
  • card sits on a foil card that tilts.
  • ghost trails echoes.
triggerrebuildsdata-dio-trigger'view' | 'hover' | 'loop''view'
  • view scans in as it shows.
  • hover powers up on pointer, focus or tap.
  • loop shimmers all the time.
colorrebuildsdata-dio-colorstring''Color of the projection and its light, any CSS color; empty uses cyan (ghost: ice blue).
layersdata-dio-layersnumber1 to 126Slices stacked in depth; 1 draws a flat projection.
depthdata-dio-depthnumber0 to 1 em0.3Depth of the stack of slices, in ems of the font size.
scandata-dio-scannumber0 to 21Strength of the scan lines, the sweep and the row shimmer; 0 for a clean projection.
flickerdata-dio-flickernumber0 to 10.4How often the projection stutters, drops out or tears; 0 holds it steady.
swaydata-dio-swaynumber0 to 20°6Largest slow turn of the hologram, degrees; 0 keeps it still.
tiltdata-dio-tiltnumber0 to 20°8Largest tip toward a pointer near it, degrees (card: 1.8 times); 0 ignores it.

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, width, x and y . Draws at a steady rate while it is on screen and stops when it leaves. trigger view: full rate while it scans in (about 1.5 s), then none. hover: 30 a second while powered up, full rate while powering up or down, none at rest. loop: 30 a second while on screen, none off screen. Full rate while it tips toward the pointer. 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. A still hologram at full power: no scan-in, no sweep, no shimmer, no flicker, no sway, no tip; it draws no frames of its own.

Runs on every device. No tip toward the pointer. With trigger hover a tap powers it up and down.

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

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

Cost and quality

Download
16.6 KB min+gzip the first time a page uses it
GPU
Four draws: the light on the page, the emitter, the cone and one instanced quad per slice with five texture reads per pixel.
Memory
A canvas of the text at twice its CSS size, with its mip levels for the glow.
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
lowThe text is rastered at 1 device pixel per CSS pixel instead of 2.

Recipes

A call to action that powers up on hover

With trigger="hover" the hologram rests at half power, still and readable, and powers up when the pointer or keyboard focus reaches it: the emitter brightens, the scan lines start to run and the text begins to sway. On a phone a tap switches it. Once the pointer leaves it powers down and draws nothing.

<a
href="/beta"
data-dio="hologram"
data-dio-trigger="hover"
data-dio-color="#ffb84a"
>Join the beta</a>

A holographic trading card

style="card" mounts the slices on a dark card with a foil border and a glossy foil in front. Tip it with the pointer: the slices shift against each other behind the foil and a rainbow sheen sweeps across. The card keeps its last pose when the pointer leaves, so it draws nothing at rest.

<h2
data-dio="hologram"
data-dio-style="card"
data-dio-color="#7cf3ff"
>Rare #07</h2>

A ghost

style="ghost" drops the projector: a pale, cool apparition that fades in from noise, drifts back and forth in depth and trails its echoes behind it. With trigger="loop" it keeps drifting while it is on screen.

<h2
data-dio="hologram"
data-dio-style="ghost"
data-dio-trigger="loop"
>Apparition</h2>

Notes

The hologram is built in 3D, not painted: the text is a stack of layers translucent slices spread over depth ems in front of the page, the emitter is a disc lying below it and the cone of light a real cone between them. As the hologram sways and tips toward the pointer, the slices shift against each other in perspective and the depth shows. The emitter lights the page around it.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the hologram is drawn the DOM text is hidden without being removed. The default color is cyan; color takes any CSS color. On a light page the projection is drawn darker over the paper instead of adding light.

With trigger="view" it draws frames only while it scans in, then rests; hover draws 30 frames a second while powered up; loop draws 30 a second while on screen and none off screen. Under reduced motion the hologram is still and at full power: no scan-in, no sweep, no flicker and no sway.

The canvas cannot draw some text the way the browser does: background-clip: text, -webkit-text-stroke and vertical writing modes. An element with any of them keeps its text as it is, and a warning in development names the reason. style, trigger and color rebuild the effect when they change; the other params change live.