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

@dioramajs/effects/kit

Helpers for effect modules and site effects, loaded in lazy chunks only.

View as Markdown
On this page
import { approach, between, chase } from '@dioramajs/effects/kit'

Functions

approachMoves `current` towards `target` by at most `step`: a linear fade, `delta / seconds` a frame.
betweenWhere `value` is between `start` and `end`, 0..1: a step at `start` when `end` is not past it.
chaseMoves `at` towards `aim` with `damp` on both axes and lands on it once within `near` (a distance), like `damp`'s own `near`. Returns whether it is still on its way, which an update can return to keep frames coming. `seconds` 0 jumps.
cornerRadiusThe radius of the corner `point` is nearest to, for `point` from the box centre with y up and `corners` the four radii of `radii` (top left, top right, bottom right, bottom left), for a `roundedBox` with corners that differ.
dampExponential approach, frame-rate independent: `seconds` is the time to cover ~63%, 0 jumps. Within `near` of the target it lands there, so a caller can tell when it has settled. Without `near` it lands only when floating point reaches the target, seconds later: to stop drawing once it settles, pass a step too small to see, such as 0.5 for px or 1e-3 for a 0..1 value.
dither±0.5/255 from the integer hash of the screen pixel, against banding in gradients. With `rgb`, ±0.5/255 after the sRGB encoding of that linear colour: the dither scaled by the slope of the decoding curve there, so dark gradients get as much as light ones. Add it to the colour.
easeEasing curves on 0..1, clamped.
enteringScroll progress of a box coming into view, 0..1: 0 while less than `share` of it shows, 1 once it is centred in the viewport. `progress` is `input.progress`, `height` the box height and `viewport` the viewport height in px.
flagsReads a switch list param such as `close="esc backdrop swipe"`: the known names it holds, in any order, separated by spaces or commas. `'all'` or `'*'` turns on all of them, an empty string none. Unknown names are left out and returned, so the effect can note them once.
followFollows the pointer the way a light or a brush on an element wants it: a mouse or pen while it is over the element, the first finger while it is pressed on it. Touch never blocks the page's scroll: the browser takes the finger with `pointercancel` when one starts. Each change asks for a frame. Listeners go with `ctx.signal`. Returns the live pointer; `on` adds callbacks.
fresnelSchlick's Fresnel: the share of light a surface reflects at `cosine` between its normal and the view, `f0` head-on (0.04 for glass and plastic, 0.02 for water). Edges catch more light.
fromOklabLinear sRGB of an OKLab colour into `out`, clamped to the gamut.
inViewWhether `share` 0..1 of a box is in view, counted above the bottom tenth of the viewport: a box peeking in at the edge has not been looked at yet. `top` and `height` are the box's in viewport px (`input.y`, `input.height`), `viewport` the viewport height. An empty box never is.
maxTextureSizeLargest 2D texture side the device takes: the WebGPU device limit (8192 for three r187, which asks for default limits), WebGL 2 `MAX_TEXTURE_SIZE`, else 4096. Caps decodes of big pictures.
mixOklab`a` and `b` mixed in OKLab by `t` 0..1, into `out`.
noiseTiling value noise, baked on the CPU, linear, RepeatWrapping. Shared per renderer and options with a reference count tied to `ctx`: never dispose it.
oklabToLinear`fromOklab` in a shader: linear sRGB of an OKLab colour, clamped to the gamut.
paletteThe colours of a list as `#rrggbb`, such as a brand palette in a param: any CSS colour, `var(--brand)` (its value or fallback, followed 8 levels deep) and `currentColor` read from the element's computed style, as `cssColor` of `@dioramajs/render` reads them. Spaces and commas outside parentheses separate the colours; words that are no colour are left out. Read at the call: a later change of a variable shows when the effect reads the list again.
radiiThe corner radii of an element in px as CSS draws them: top left, top right, bottom right, bottom left. A `%` counts against the shorter side of the `width` × `height` box, and no corner takes more than half of that side, so `999px` draws a pill.
rngmulberry32: the same sequence for the same seed on every load and backend.
roundedBoxSigned distance in px from a rounded box, negative inside: `point` from the box centre, `half` its half size, `radius` its corners. `clamp(0.5 - d, 0, 1)` is a 1 px antialiased mask.
spiralBlurA soft blur: the mean of `taps` reads on a golden-angle spiral over the disc of `radius` (in the units of `uv`) around `uv`. `turn` rotates the spiral; turned per pixel, the taps read as grain instead of ghost copies. One tap reads `uv` itself.
toBoxA point in client px, such as an event's `clientX` and `clientY`, in px of `box` from its bottom left: the units of the shader's `box` times `u.size`. Pass `input` as the box in the update, since the page may scroll under a still pointer. Writes into `out` when given.
toOklabOKLab (Björn Ottosson) of a linear sRGB colour, three's working space. Mixed in OKLab, two colours meet through a clean middle instead of a muddy grey.

Interfaces

FollowedPointerThe pointer `follow` tracks. Live: read it in the update.
FollowHandlersCallbacks of `follow`. Each gets the pointer event; the pointer is already updated.
NoiseOptionsOptions of `noise`.

Types

ClientBoxThe box `toBox` measures from: its left and top edges in client px and its height.
OklabA colour in OKLab: lightness, a, b.