Contents

Reference

Nodes: lamino/fx

The effect nodes: import { glow, grain } from "lamino/fx". They compute in linear light and do not clamp.

This page as Markdown

Sources

fractalNoise

Fractal noise generator: gradient, turbulent, ridged or cellular, with an evolution axis.

Module lamino/fx, category Sources, output image, pointwise (fused with its neighbours)

Parameter Type Default Range Unit Keys Description
type enum "basic" Noise character: basic (smooth), turbulent (creased, billowy), ridged (bright veins) or cell (cellular / Worley). Values: basic turbulent ridged cell
scale float 0.1 0.0001 or more width units yes Size of the largest features in width units.
aspect float 1 0.01 to 100 yes Vertical stretch of the pattern (feature height = scale · aspect).
rotation float 0 degrees yes Rotation of the pattern about the display centre in degrees, clockwise positive.
offset vec2 [0, 0] width units yes Moves the pattern, [x, y] in width units.
octaves int 4 1 to 12 Number of octaves (levels of detail).
lacunarity float 2 1 to 8 Frequency ratio between octaves.
gain float 0.5 0 to 1 yes Amplitude ratio between octaves (lower = smoother).
evolution float 0 yes Position on the third (time) axis; 1.0 = one lattice cell.
evolutionCycle int 0 0 to 4096 Period of evolution for a seamless loop (0 = no loop).
contrast float 1 0 or more yes Scales v about 0.5.
brightness float 0 yes Added to v.
seed int 0 Pattern seed.

A grey, opaque picture over the display window: rgb = v, alpha = 1 (v is not clamped; contrast can push it below 0 or above 1). Everything is a function of the pixel centre in width units, so the pattern is the same at every resolution and proxy level, and of lamino_hash on the integer lattice, so CPU and GPU use the same lattice values. Coordinates: q = pixel centre − display centre − offset, rotated by rotation (the pattern turns clockwise), then u = (q.x / scale, q.y / (scale·aspect)): scale is the size of the largest features (one lattice cell of the first octave). Octave i of octaves (i = 0 …): frequency f = lacunarity^i, amplitude a = gain^i, the 3-D point (u·f + o_i, evolution + z_i) with a per-octave offset from the seed. Term per type: basic = n (improved gradient noise scaled to about −1..1); turbulent = |n|; ridged = max(1 − |n|, 0)²; cell = the distance to the nearest of one feature point per lattice cell, at most 1. v = Σ a·term / Σ a; for basic v = 0.5 + 0.5·v. Then v = (v − 0.5)·contrast + 0.5 + brightness. Time: the node never reads the frame. Animate evolution (1.0 = one lattice cell along the third axis; t((f) => f * 0.02) is a slow boil); with evolutionCycle = N > 0 the third axis repeats every N, so evolution 0 and N give the same picture (a seamless loop). Proxies: an octave whose lattice cell is under two pixels at this proxy level is blended towards its mean (fully under one pixel), so a proxy looks like the reduced full-resolution picture instead of aliasing; the full resolution does the same for octaves it cannot resolve. seed picks another pattern.

Examples:

// Clouds
const clouds = fractalNoise({ scale: 0.25, octaves: 6, evolution: t((f) => f * 0.01) });

// Seamless 48-frame loop
const loopNoise = fractalNoise({ type: "turbulent", evolution: t((f) => (f - 1) / 12), evolutionCycle: 4 });

curlNoise

Divergence-free flow field (curl noise) for swirling, fluid-like displacement.

Module lamino/fx, category Sources, output image, pointwise (fused with its neighbours)

Parameter Type Default Range Unit Keys Description
scale float 0.2 0.0001 or more width units yes Size of the largest swirls in width units.
offset vec2 [0, 0] width units yes Moves the field, [x, y] in width units.
octaves int 2 1 to 12 Number of octaves (finer swirls on top of the large ones).
lacunarity float 2 1 to 8 Frequency ratio between octaves.
gain float 0.5 0 to 1 yes Amplitude ratio between octaves.
evolution float 0 yes Position on the third (time) axis; 1.0 = one lattice cell.
evolutionCycle int 0 0 to 4096 Period of evolution for a seamless loop (0 = no loop).
strength float 1 yes Multiplier on the velocity.
boundary float 0 0 or more width units yes Width of the band along the display's edges in which the flow turns to slide along them (0 = off).
seed int 0 Pattern seed.

A flow field that neither piles the picture up nor tears it apart: the curl of a noise potential (Bridson, Hourihan, Nordenstam, "Curl-Noise for Procedural Fluid Flow", SIGGRAPH 2007). Output, opaque: r = 0.5 + 0.5·v.x, g = 0.5 + 0.5·v.y, b = 0.5 + 0.5·ψ (the potential), a = 1, which is what displace reads with its defaults: displace(img, curlNoise({ … }), { amount }) moves each pixel by up to amount along the flow. Potential: with q = pixel centre − display centre − offset and u = q / scale, P(u) = K·Σ a_i·w_i·n(u·f_i + o_i, evolution + z_i) / sqrt(Σ (a_i·f_i)²) over the octaves (f_i = lacunarity^i, a_i = gain^i; n, the lattice, the per-octave offsets and the proxy weights w_i are those of fractalNoise; K = 0.3), ψ = scale·P. Velocity v = strength·(∂ψ/∂y, −∂ψ/∂x), from the analytic derivatives of the noise (no finite differences), so the divergence ∂v.x/∂x + ∂v.y/∂y is zero up to rounding; each component of v stays within about ±0.9 for strength 1 (99 % of the pixels; displace clips at ±1). boundary > 0 makes the flow slide along the edges of the display window instead of crossing them: ψ is multiplied by r(tx)·r(ty), the ramp r(t) = 15t/8 − 10t³/8 + 3t⁵/8 (1 for t ≥ 1) of t = (distance to the nearer edge along that axis) / boundary, and v is the curl of that product (the paper's boundary handling, one ramp per axis so the corners stay smooth), so a displaced full-frame plate keeps its border. Keep boundary at most half the display's shorter side: beyond it the two bands meet in a crease along the centre line. Time: the node never reads the frame; animate evolution (evolutionCycle = N loops it every N). It is a field, not a simulation: nothing is carried from frame to frame. Not clamped.

Examples:

// Fluid-like warp
const flow = curlNoise({ scale: 0.15, octaves: 3, evolution: t((f) => f * 0.02) });
const liquid = displace(plate, flow, { amount: [0.02, 0.02], edge: "clamp" });

// A plate that keeps its border
const swirl = displace(plate, curlNoise({ scale: 0.3, boundary: 0.1 }), { amount: [0.03, 0.03] });

lensFlare

Lens flare of one light: ghosts traced through a lens, a diffraction starburst, glare and a streak.

Module lamino/fx, category Sources, output image

Parameter Type Default Range Unit Keys Description
position vec2 [0.3, 0.15] width units yes Position of the light in the picture, [x, y] in width units (it may lie outside the frame).
brightness float 1 0 or more yes Brightness of the light (multiplies every element).
color vec3 [1, 1, 1] yes Colour of the light (working space rgb multiplier).
lens enum "standard" Bundled lens prescription (ignored when elements is given). Values: standard wide tele
elements json [] Your own lens: [{ radius, thickness, nd, vd, aperture?, stop? }, …] front to back, mm; empty = use lens.
sensorWidth float 36 1 or more Width of the picture on the sensor in mm.
aperture float 0.5 0.05 to 1 yes Opening of the iris: 1 = wide open, smaller = stopped down.
blades int 6 0 to 16 Number of iris blades; below 3 = a circle.
roundness float 0.2 0 to 1 yes 0 = straight blades, 1 = a circle.
rotation float 0 degrees yes Rotation of the iris in degrees.
ghosts float 1 0 or more yes Multiplier on the ghosts.
ghostSoftness float 0.05 0 to 1 yes Softness of the ghosts' edges as a fraction of their radius.
spectral int 5 3 to 12 Wavelengths traced per ghost (3 = cheapest, more = smoother colour fringes).
coating float 550 380 to 780 yes Design wavelength of the anti-reflection coatings in nm (sets the colour of the ghosts).
coatingSpread float 80 0 to 200 Spread of the design wavelength between surfaces in nm.
seed int 0 Seed of the per-surface coating variation.
starburst float 1 0 or more yes Multiplier on the diffraction starburst.
starburstSize float 0.25 0.0001 or more width units yes Radius of the starburst in width units.
glare float 1 0 or more yes Multiplier on the veil around the light.
glareSize float 0.02 0.0001 or more width units yes Radius of the core of the glare in width units.
streak float 0 0 or more yes Multiplier on the horizontal streak (0 = none).
streakLength float 0.3 0.0001 or more width units yes Half-length of the streak in width units.
streakTint vec3 [0.35, 0.55, 1] yes Colour of the streak (working space rgb multiplier).

The flare a bright light leaves in a camera lens, as pure light (rgb ≥ 0, alpha 0) over the display window: add it to the plate (plate.add(flare)). Nothing is read from a picture: the light is position, brightness and color; animate them (one node per light). Ghosts are the images of the iris formed by light that reflects twice between lens surfaces. They are traced with the paraxial ray-transfer matrices of the lens (Lee and Eisemann, "Practical Real-Time Lens-Flare Rendering", EGSR 2013): for every pair of surfaces i < j on the same side of the iris and every sampled wavelength, the path entrance → reflect at j → back to i → reflect at i → sensor gives two linear maps of the ray's entrance point r (in entrance-pupil radii) and the light's position p (width units from the display centre): the sensor point x = A·r + B·p and the point in the iris plane a = C·r + D·p (iris radii). A pixel x is lit by a ghost when r = (x − B·p)/A lies in the pupil (|r| ≤ 1) and a lies in the iris (the shape of lensBlur: blades, roundness, rotation; aperture scales the iris radius, 1 = wide open). So the ghosts line up through the centre of the picture, move against the light, and are clipped into iris shapes exactly as the lens geometry says. Irradiance of a ghost = 25·R_i·R_j / max(A², 0.004²): the light through the pupil spread over the ghost's area (a ghost focused to a point is drawn with the radius 0.004). R = the reflectance of a surface with a quarter-wave anti-reflection coating (single layer, normal incidence, exact thin-film formula: index max(sqrt(n_a·n_b), 1.38), designed for the wavelength coating ± coatingSpread, drawn per surface from seed), which is what colours the ghosts; a cemented surface (glass on both sides) is uncoated. Glass dispersion: n(λ) = A + B/λ² through n_d and the Abbe number, so the matrices differ per wavelength and the ghosts get colour fringes. spectral wavelengths, evenly spaced in 400–700 nm, are weighted to rgb with the CIE 1931 colour matching functions (the analytic fit of Wyman, Sloan and Shirley, JCGT 2013) through the Rec.709 matrix, each channel's weights normalised to sum to 1; the result is used as working-space rgb. Edges are one pixel soft, or ghostSoftness of the ghost's radius. The paraxial model is exact near the axis and draws every ghost as a scaled, clipped iris: it has no aberrations (no deformed or caustic ghosts). Lens: lens picks a bundled prescription (standard: a six-element double-Gauss type, wide: a retrofocus type, tele: a telephoto type; generic designs made for this node, not a product), or elements gives your own: [{ radius, thickness, nd, vd, aperture?, stop? }, …] front to back in mm (radius > 0 = centre of curvature towards the sensor, 0 = flat; thickness = distance to the next surface; nd, vd = the medium behind the surface, nd 1 = air; aperture = semi-diameter, needed on the first surface and the stop; exactly one flat surface in air has stop: true; vd may be left out in air; an unknown key, a thickness ≤ 0 other than the last, an aperture ≤ 0, a vd ≤ 0 on glass and more than 32 surfaces are errors). A surface with the same medium on both sides reflects nothing. The sensor is put at the paraxial focus for infinity at 550 nm; sensorWidth is the width of the picture on it in mm. Starburst: the Fraunhofer diffraction pattern of the iris, the squared magnitude of its Fourier transform (Hullin, Eisemann, Seidel and Lee, "Physically-Based Real-Time Lens Flare Rendering", SIGGRAPH 2011), summed over 400–700 nm with the pattern scaled in proportion to the wavelength (which smears the rings into rays with coloured tips): a polygon of n blades gives n rays (2n for odd n), a circle gives none. It is a CPU-prepared picture centred on the light, starburstSize in radius, read with bilinear interpolation; its core is soft-clipped, T/(T + 0.002), so that it does not outshine the rays (the core is about a thousand times brighter than they are). Glare: a veil around the light, glare·1/(1 + (d/glareSize)²)^1.5 (the θ^−3 tail of Spencer et al. 1995). Streak (not physical; the horizontal line of anamorphic lenses): streak·streakTint·exp(−|dy|/w)/(1 + (dx/streakLength)²), w = max(0.003, 1.5 px). Everything is multiplied by brightness·color; negative sums of the spectral weights are clamped to 0 at the end.

Examples:

// Sun flare over a plate
const flare = lensFlare({ position: [0.72, 0.12], brightness: 3, color: [1.0, 0.9, 0.75] });
const shot = plate.add(flare);

// Stopped-down wide lens, animated light
const flare = lensFlare({ lens: "wide", aperture: 0.25, blades: 8, position: keys([[1, [0.1, 0.2]], [48, [0.9, 0.3]]]) });

// Anamorphic streak
const flare = lensFlare({ position: [0.5, 0.25], streak: 2, streakLength: 0.6, ghosts: 0.5 });

Filters

grain

Film grain: seeded, luminance-weighted noise added in straight RGB.

Module lamino/fx, category Filters, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
amount float 0.03 0 or more yes Noise amplitude (0.03 is subtle).
size float 1 0.5 or more yes Cell size in 4K pixels.
response float 0.5 0 to 1 0 = uniform, 1 = scales with luminance.
monochrome bool false Same noise on r, g and b.
seed int 0 Noise seed.
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights.

Deterministic lamino_hash noise per (pixel cell, frame, seed). size is the grain cell size relative to a pixel of a 3840-wide frame (1.0 = one 4K pixel), so the grain looks the same at any resolution or proxy level; cells are sampled with bilinear interpolation of the noise. Response: noise · amount · mix(1, luma, response); shadows get less grain as response → 1. monochrome uses one noise value for rgb. Alpha is untouched; rgb is re-premultiplied by alpha where > 0. Pixels with alpha == 0 are unchanged (the grain is additive, its a → 0 limit is zero).

Examples:

// Plate grain
const final = grain(out, { amount: 0.03, size: 1.2, seed: 7 });

vignette

Darken (or lighten) towards the edges with a soft elliptical falloff.

Module lamino/fx, category Filters, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
amount float 0.5 -1 to 1 yes Strength (negative lightens).
radius float 0.45 0 or more width units yes Distance where the falloff starts, in width units.
softness float 0.6 0 or more yes Width of the transition in units of radius.
center vec2 [-1, -1] width units yes Centre [x, y] in width units; [-1,-1] = display centre.
roundness float 0.5 0 to 1 1 = circle, 0 = follows the frame aspect.

d = normalised distance from center (width units) scaled so that radius → 1 (an ellipse when roundness < 1, matching the frame aspect at 0). falloff = smoothstep(1, 1 + softness, d); out.rgb = rgb · (1 − amount · falloff). Premultiplied rgb is scaled directly (alpha untouched).

Examples:

// Subtle
const v = vignette(comp, { amount: 0.3 });

rgbSplit

Offset red, green and blue separately: channel shift and lateral chromatic aberration.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
r vec2 [0, 0] width units yes Offset of red, [x, y] in width units.
g vec2 [0, 0] width units yes Offset of green, [x, y] in width units.
b vec2 [0, 0] width units yes Offset of blue, [x, y] in width units.
radial float 0 -0.5 to 0.5 yes Magnification difference about center: blue is scaled by 1 + radial, red by 1 − radial (0.002 is a visible lens fringe).
center vec2 [-1, -1] width units yes Centre of radial, [x, y] in width units; [-1,-1] = display centre.

Each colour channel is the input sampled at its own position (bilinear, premultiplied, transparent black outside the data window). For the pixel centre q (width units) and c = center: red is read at c + (q − c)·(1 + radial) − r, green at q − g, blue at c + (q − c)·(1 − radial) − b. So a positive offset moves that channel's picture by the offset (r: [0.01, 0] shifts red 1 % of the width to the right), and a positive radial magnifies blue and shrinks red about the centre by that fraction (lateral chromatic aberration: no shift at the centre, growing linearly towards the corners; at a corner of a 16:9 frame the shift is radial · 0.574 width units). Alpha is the largest of the three samples' alphas, so a fringe that leaves the picture keeps coverage (each premultiplied channel stays ≤ alpha). Output window (RoiFn of lamino-nodes) = the bounding box of the three displaced copies of the input window; the input region of an output box is the bounding box of the three read positions, grown by one pixel for the bilinear taps.

Examples:

// Lens fringe
const ca = rgbSplit(comp, { radial: 0.002 });

// Channel shift on a title
const split = rgbSplit(title, { r: [0.004, 0], b: [-0.004, 0] });

displace

Shift each pixel by an amount read from a map image (displacement map).

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
  • Input map (image): Displacement map (an image; its values are numbers here, not colours).
Parameter Type Default Range Unit Keys Description
amount vec2 [0.01, 0.01] width units yes Largest displacement [x, y] in width units (at a map value of 1; −amount at 0).
xChannel enum "r" Map channel that drives the horizontal displacement. Values: r g b a luma
yChannel enum "g" Map channel that drives the vertical displacement. Values: r g b a luma
center float 0.5 yes Map value that means no displacement.
edge enum "transparent" Outside the input's data window: transparent black, the nearest edge pixel, the mirrored picture or the repeated picture. Values: transparent clamp mirror wrap
filter enum "bilinear" Resampling filter of the input. Values: nearest bilinear bicubic
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights for the luma channel choice (default AP1 / ACEScg).

For the output pixel p, m = the map at p (xChannel for x, yChannel for y; luma = the rgb weighted by luma; the map's values are used as stored, premultiplied like every image, so use an opaque map). Displacement in width units: d = clamp((m − center)·2, −1, 1) · amount per axis, so a map value of center (0.5: mid grey) moves nothing, 1 moves by +amount and 0 by −amount, and values beyond that range move no further (the node never reads further than amount). out(p) = in(p − d): a bright map pushes the picture right / down by up to amount. Where the map has no pixel (outside its data window, or not connected) nothing is displaced. filter resamples the input (nearest; bilinear; bicubic = Catmull-Rom). edge decides what lies outside the input's data window: transparent (default) transparent black; clamp the nearest edge pixel; mirror the picture reflected at each edge; wrap the picture repeated (tiled). Output window (RoiFn of lamino-nodes): transparent = the input window grown by ceil(max(|amount.x|, |amount.y|)·W) px; the other edges = the input window. Input region of an output box: grown by that padding plus the filter's support (mirror / wrap request the whole input: the far side of the picture is read); the map is read at the output pixels only. This is the simple model: for a full vector field in pixels use uvMap.

Examples:

// Heat haze from a noise map
const haze = displace(plate, fractalNoise({ scale: 0.05, evolution: t((f) => f * 0.05) }), { amount: [0.003, 0.003], xChannel: "r", yChannel: "r", edge: "clamp" });

directionalBlur

Blur along a direction (motion streak), two-sided or as a one-sided trail.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
length float 0.02 0 or more width units yes Total streak length in width units.
angle float 0 degrees yes Direction in degrees, clockwise from +x.
samples int 32 2 to 256 Number of taps.
falloff enum "box" Weight along the streak: equal, falling linearly to 0 at the end, or exponential (soft, long tail). Values: box linear exp
oneSided bool false Trail in one direction only (towards angle) instead of both.

samples bilinear taps along angle (degrees, clockwise from +x), weighted by falloff, summed in index order and divided by the summed weights. Two-sided (default): tap i of n at t = −0.5 + i/(n−1), read at p + dir·length·t, with u = 2·|t| (0 at the pixel, 1 at both ends). oneSided: t = i/(n−1), read at p − dir·length·t, u = t, so light trails away from its source towards angle over the whole length (the streak of a star glow). Weights: box = 1; linear = 1 − u·(1 − 1/n) (the far tap keeps 1/n); exp = exp(−4·u). Output window (RoiFn of lamino-nodes) = the input window grown by ceil(length·W/2) px (two-sided) or ceil(length·W) px (oneSided); taps outside the data window read transparent black.

Examples:

// Streak
const streak = directionalBlur(lights, { length: 0.05, angle: 20 });

// One soft ray to the right
const ray = directionalBlur(lights, { length: 0.2, falloff: "exp", oneSided: true, samples: 96 });

radialBlur

Zoom or spin blur about a centre.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
mode enum "zoom" Blur shape. Values: zoom spin
amount float 0.1 0 to 1 yes Zoom: fraction of the radius blurred over.
angle float 10 0 or more degrees yes Spin: total arc in degrees.
center vec2 [-1, -1] width units yes Centre [x, y] in width units; [-1,-1] = display centre.
samples int 32 2 to 256 Number of taps.

zoom: taps along the ray from center, scale 1 − amount·t; spin: taps along the arc, ±angle/2 degrees. Bilinear, averaged in fixed order. Output window = input 0's (taps outside read transparent black).

Examples:

// Light burst
const burst = radialBlur(glow, { amount: 0.3, samples: 48 });

edgeExtend

Spread straight colour outward from the alpha edge (fills transparent pixels with the nearest colour).

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
size float 0.005 0 or more width units yes How far to extend, in width units.
threshold float 0.001 0 to 1 Alpha below which a pixel is filled.
keepStraight bool false Return straight rgb (not re-premultiplied).

Iterative one-pixel dilation of unpremultiplied rgb into pixels with alpha below threshold, repeated ceil(size·W) times at the current proxy level (WGSL: one pass with Repeat::FromParamPx), so the reach is size width units. Alpha is unchanged; the result is re-premultiplied by the original alpha where > 0 unless keepStraight is true (then rgb is left straight for use as a light-wrap/texture source). Pixels with alpha == 0: they never act as fill sources (they have no straight colour); without keepStraight their rgb passes through unchanged (the a → 0 limit of the premultiplied fill is zero, and emissive rgb survives); with keepStraight they receive the filled straight colour like every other pixel below threshold. The input is premultiplied like every image (the node divides by alpha itself; do not unpremult() before it). The output window is the input's data window grown by size, so the fill reaches past the data window (e.g. the edge of a transformed plate): there the pixels have alpha 0 and receive the colour only with keepStraight.

Examples:

// Before blur
const fill = edgeExtend(fg, { size: 0.01 });

// Extend a placed plate past its data window (opaque straight colour up to 0.05 width units out)
const extended = placed.edgeExtend({ size: 0.05, threshold: 0.999, keepStraight: true }).shuffle({ a: "1" });

glitch

Digital glitch: seeded horizontal block displacement and channel split.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
amount float 0.3 0 to 1 yes Probability a block is displaced.
blockSize float 0.02 0.0001 or more width units yes Block height in width units.
shift float 0.05 0 or more width units yes Max horizontal shift in width units.
colorSplit float 0.005 0 or more width units yes Max rgb offset in width units.
seed int 0 Seed.

Rows are grouped into blocks of blockSize; each block (per frame and seed) is shifted horizontally by up to shift with probability amount, and rgb channels are offset by up to colorSplit. Everything is a deterministic lamino_hash of (block, frame, seed). Output window = input grown horizontally by shift + colorSplit (computed).

Examples:

// Flicker
const g = glitch(title, { amount: 0.5, shift: 0.08, seed: 11 });

edgeDetect

Edge strength (Sobel) of the colour, the alpha or the luma.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
amount float 1 0 or more yes Gain on the edge strength.
channels enum "rgb" What the edges are taken from. Values: rgb alpha luma
invert bool false Dark edges on white.
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights (default AP1 / ACEScg).

3×3 Sobel on the stored (premultiplied) values, taps outside the data window clamped to its edge pixels: gx, gy per channel, strength = sqrt(gx² + gy²)·amount·W/1920/4 (W = the display width at this proxy level, so a soft gradient gives the same strength at every proxy level; a hard edge is one pixel wide at every level, which is thinner in the picture at full resolution). channels: rgb = the strength of each colour channel, alpha kept; alpha = the strength of alpha in all four channels (an outline matte); luma = the strength of dot(luma, rgb) in r, g and b, alpha kept. invert gives 1 − strength in the channels that hold it. Output window = the input's.

Examples:

// Outline matte of a keyed element
const rim = edgeDetect(fg, { channels: "alpha", amount: 4 });

shadowRay

Long cast shadow of a picture's alpha towards a directional or point light, with opacity, softness and colour changing along its length (the kernel of castShadow).

Module lamino/fx, category Filters, output image

  • Input in (image): The shape that casts the shadow (its alpha), and the picture put over the shadow.
  • Input soft1 (image, optional): in blurred by σmax/3 (built by castShadow).
  • Input soft2 (image, optional): in blurred by 2·σmax/3 (built by castShadow).
  • Input soft3 (image, optional): in blurred by σmax (built by castShadow).
Parameter Type Default Range Unit Keys Description
light enum "directional" Parallel light from angle, or a point light at center (the shadow fans out from it). Values: directional point
angle float 45 degrees yes Direction the shadow falls (directional light), degrees clockwise from +x.
center vec2 [-1, -1] width units yes Position of the point light in width units; [-1, -1] = the display centre.
length float 0.1 0 or more width units yes How far the shadow reaches from its caster, in width units.
softness float 0 0 or more width units yes Blur sigma of the shadow where it starts, in width units.
softnessEnd float 0.01 0 or more width units yes Blur sigma of the shadow at length, in width units.
opacity float 1 0 to 1 yes Opacity where the shadow starts.
opacityEnd float 0 0 to 1 yes Opacity at length.
color color [0, 0, 0, 1] yes Shadow colour where it starts.
colorEnd color [0, 0, 0, 1] yes Shadow colour at length.
curve float 1 0.05 to 20 yes Exponent on the position along the shadow before start and end are mixed: above 1 keeps the start values longer, below 1 reaches the end values sooner.
inner bool false Inner shadow: cast by the outside of the shape onto its inside.
shadowOnly bool false Return only the shadow.

Each pixel looks towards the light for the nearest occluder within length and takes the shadow of what it finds, with the attributes of that distance. W = the display width in px at this proxy level, p = the pixel centre. L = length·W; N = min(ceil(L), 4096) steps (one per pixel), t_i = L·i/N for i = 0 … N (N = 0: t = 0 only). Towards the light: directional d = −(cos angle, sin angle) (angle = where the shadow falls, degrees clockwise from +x, as in dropShadow); point d = (C − p)/|C − p| with C = center (the light; [-1, -1] = display centre), steps with t_i > |C − p| are skipped (nothing casts from behind the light; |C − p| < 1e-6 gives no shadow). u_i = i/N (0 when N = 0), w_i = u_i > 0 ? exp2(curve·log2(u_i)) : 0. σ_i = mix(softness, softnessEnd, w_i)·W, σmax = max(softness, softnessEnd)·W; level ℓ = σmax > 0 ? 3·σ_i/σmax : 0. Coverage a_i = the alpha at p + d·t_i (bilinear, transparent outside the data window) of the level images: level 0 = in, level k = soft<k>, which must hold in blurred (Gaussian sigma) by k/3·σmax — castShadow builds them; an unconnected soft<k> reads in. Between levels: k0 = min(floor(ℓ), 2), a = mix(a_k0, a_k0+1, ℓ − k0), clamped to 0..1; inner: a = 1 − a. Colour c_i = mix(color, colorEnd, w_i) (premultiplied), v_i = a·mix(opacity, opacityEnd, w_i)·c_i.a. Running maximum, nearest first: v_i > S → rgb += (v_i − S)·c_i.rgb / c_i.a, S = v_i. Shadow = (rgb, S): the nearest occluder decides where the shadow starts, a farther one only adds where it is darker. inner: the shadow is cut by the alpha of in at p (a shadow inside the shape, cast by its outside). Composite: shadowOnly → shadow; otherwise in over the shadow (inner: the shadow over in). Output window (RoiFn of lamino-nodes): inner → the window of in; directional → the union of the input windows and that union moved by L along the shadow, grown by 1 px; point → the union grown by ceil(L) + 1 px. Input regions = the output region grown by ceil(L) + 1 px.

Examples:

// Long shadow of a title, fading out
const long = shadowRay(title, { angle: 45, length: 0.2, softnessEnd: 0 });

glow

Multi-scale glow with a power-law falloff: a bright core and a long soft tail.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
threshold float 0.6 0 or more yes Level above which pixels glow (scene-linear brightness of the straight colour, or alpha for basedOn: "alpha").
knee float 0.5 0 to 1 yes Softness of the threshold: 0 = hard, 1 = the glow starts from black.
radius float 0.05 0 or more width units yes Radius of the widest layer in width units (its sigma is radius / 2).
falloff float 2 0 to 4 yes Exponent of the falloff with distance: 2 = inverse square; larger = tighter, smaller = wider.
layers int 6 1 to 14 Number of stacked Gaussians, each half the size of the one before (1 = a single soft glow).
intensity float 1 0 or more yes Multiplier on the glow.
aspect float 1 0.05 to 20 yes > 1: the vertical radius is divided by it (horizontal streak); < 1: the horizontal radius is multiplied by it.
chromatic float 0 -1 to 1 yes Colour fringe of the rim: > 0 red outside, < 0 blue outside.
tint vec3 [1, 1, 1] yes Colour of the glow (working space rgb multiplier).
outerTint vec3 [1, 1, 1] yes Extra colour of the widest layer, fading to none at the innermost.
basedOn enum "color" What glows: the bright colours, or the matte. Values: color alpha
operation enum "add" How the glow is put back on the input. Values: add screen
glowOnly bool false Return the glow alone instead of the composite.

What lies above a soft threshold is blurred at a ladder of scales and summed with weights that follow d^−falloff, the shape of real glare (a narrow core plus long tails; Spencer et al., "Physically-Based Glare Effects for Digital Images", SIGGRAPH 1995), then put back on the picture. One Gaussian (layers: 1) is the classic soft glow; the default stack is what makes a light look hot: tight and bright near the source, faint and wide far from it. Bright part b: kn = threshold·knee + 1e-5, resp(v) = max(0.25/kn · clamp(v − (threshold − kn), 0, 2·kn)², v − threshold) (a quadratic knee: knee 0 = hard threshold, 1 = the response starts at 0). basedOn: color: m = max(r, g, b); v = m / max(a, 1e-6) (the brightness of the straight colour); all four channels are scaled by resp(v)/v, so the hue is kept and light without coverage (alpha 0) passes whole. basedOn: alpha: resp(alpha) in all four channels (white light in the shape of the matte, whatever the colour). Stack: layers Gaussians of sigma σ_m = (radius·W/2)·2^−m px (W = display width at this proxy level; the widest has sigma = radius/2, so most of its light falls within radius), layer m weighted 2^(−(2 − falloff)·m), the weights divided by their sum: falloff 2 gives every octave the same energy (inverse-square profile between the innermost and the outermost layer), larger pulls the light towards the source, smaller towards the rim. Intensity 1 spreads exactly the light the threshold takes. rgb is multiplied by intensity · tint · mix(outerTint, 1, m/(layers − 1)) (the widest layer takes outerTint: a white-hot core with a coloured rim); alpha is the same stack of the bright part's alpha, without colour or intensity. chromatic c shrinks the radius per channel (c > 0: green ×(1 − c/2), blue ×(1 − c), a red rim; c < 0: red ×(1 + c), green ×(1 + c/2), a blue rim). aspect > 1 divides the vertical radius by it (a horizontal, anamorphic glow), < 1 multiplies the horizontal radius by it; the long axis keeps radius. Blur ladder (normative): the à-trous cascade of the cubic B-spline, h = [1, 4, 6, 4, 1]/16 per axis with taps 2^j px apart for level j; k levels are the B-spline of knot spacing 2^k (variance (4^k − 1)/3 px² per axis, reach 2·(2^k − 1) px, about 3.5 sigmas): 10 taps per level whatever the radius, nothing decimated, so nothing shimmers. With σ = radius·W/2 px: K = the smallest k in 1…14 with (4^k − 1)/3 ≥ σ² (no blur at all for σ < 0.25 px); the top level (j = K − 1) has its taps top px apart instead, the spacing in (0, 2^(K−1)] at which the ladder has exactly the variance σ² (so it is never wider than asked, and the picture moves continuously with radius). A tap between two pixels is their linear interpolation (the variance that adds is counted). A layer's weight is split between the two levels that enclose its variance (variance-preserving; below level 1 the lower one is the unblurred bright part), which keeps the result the same at every proxy level. The short axis of aspect uses the tap spacing times min(aspect, 1/aspect). Composite (operation): add = (in.rgb + glow.rgb, max(in.a, glow.a)); screen = the HDR-safe screen of merge on all four channels; glowOnly returns the glow alone, premultiplied and with its own alpha, for your own merge: bg.add(glow, { alpha: "max" }) adds the light and keeps the larger coverage (a plain add sums the alphas, above 1 on an opaque background), bg.over(glow) lets the glow's alpha cover the background. Output window = the input's grown by the ROI padding = 2·radius width units (the reach of the ladder, at most 4 sigmas); the cascade's intermediates cover the output window grown by the same padding, so a very large radius (above about half the width) can exceed the buffer budget: lower radius.

Examples:

// Title glow
const lit = glow(title, { threshold: 0.5, radius: 0.08, intensity: 1.5, tint: [1.0, 0.8, 0.5] });

// Glow from the matte
const halo = logo.glow({ basedOn: "alpha", threshold: 0.2, radius: 0.05 });

// Anamorphic, hot core with a blue rim
const neon = glow(sign, { radius: 0.2, aspect: 3, falloff: 2.4, outerTint: [0.4, 0.6, 1.0], chromatic: -0.3 });

// Glow as its own element
const light = glow(fx, { threshold: 1, radius: 0.1, glowOnly: true });
const comp = bg.add(light, { alpha: "max" });

lensBlur

Lens blur (bokeh): every point becomes the shape of the iris, with blades, cat's eye, rim and highlight boost.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
  • Input map (image, optional): Blur map: scales the radius per pixel (optional).
Parameter Type Default Range Unit Keys Description
radius float 0.01 0 or more width units yes Radius of the bokeh in width units.
blades int 0 0 to 16 Number of iris blades (sides of the bokeh); below 3 = a circle.
roundness float 0 0 to 1 yes 0 = straight blades (a polygon), 1 = a circle.
rotation float 0 degrees yes Rotation of the iris in degrees (a vertex points along it).
aspect float 1 0.1 to 10 yes > 1: the vertical radius is divided by it; < 1: the horizontal radius is multiplied by it (anamorphic ovals: 0.5).
catEye float 0 0 to 1 yes Optical vignetting: how much the bokeh narrows towards the corners of the frame.
rim float 0 -1 to 8 yes Brightness of the outer 20 % of the bokeh relative to its inside: > 0 a bright rim, < 0 a soft edge.
highlightGain float 0 0 or more yes Extra gain on what lies above highlightThreshold, before the blur.
highlightThreshold float 1 0 or more yes Scene-linear brightness above which the highlight gain acts.
edge enum "transparent" Outside the input's data window: transparent black (transparent, the borders of a plate darken) or the nearest edge pixel (clamp). Values: transparent clamp
mapChannel enum "luma" Channel of the blur map that scales the radius. Values: luma r g b a
focus float 0 yes Map value that stays sharp; the radius grows with the distance of the map from it.
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights (default AP1 / ACEScg).

An out-of-focus lens turns every point of light into a flat, hard-edged image of its iris. This is that blur, exact for any convex iris and safe for scene-linear highlights (every weight is positive, so there is no ringing however bright the light), at a cost that grows with the radius, not with its square. Method: rows of the iris are integrated with prefix sums built by recursive doubling (Hensley et al., "Fast Summed-Area Table Generation and its Applications", Eurographics 2005; Crow 1984), restarted every B pixels so that f32 keeps its precision next to very bright pixels. Iris (lamino_nodes::aperture, in units of its radius): the points u with |u| ≤ 1 and n_i·u ≤ apothem for i in 0..blades, n_i = (cos φ_i, sin φ_i), φ_i = rotation + (i + 0.5)·360°/blades, apothem = c + roundness·(1 − c), c = cos(180°/blades): roundness 0 = a polygon with a vertex at the angle rotation (from +x towards +y, clockwise on screen), 1 = a circle, between them a polygon with circular corners; blades below 3 = a circle. A point of light becomes this shape, not its mirror image. aspect > 1 divides the vertical radius by it, < 1 multiplies the horizontal radius by it (anamorphic ovals: aspect 0.5). catEye k cuts the shape with a second unit circle centred at k·v, v = (pixel centre − display centre) / (half the display diagonal): optical vignetting, the bokeh narrows towards the corners along the radial direction (the swirl of fast lenses). rim r weights the ring between the shape and the same shape scaled by 0.8 with 1 + r (r > 0: a bright rim, the soap-bubble look; r < 0, down to −1: a soft edge). Source s(q): the input at q (outside its data window: transparent black, or with edge: clamp the nearest pixel of the window), then the highlight boost: m = max(r, g, b); for m > 0, v = m / max(a, 1e-6) and rgb is multiplied by 1 + highlightGain·max(v − highlightThreshold, 0) (alpha stays; it makes the lights pop the way an overexposed sensor does, and it adds light, by design). Normative arithmetic (both backends, operation for operation). pad = the ROI padding in px = ceil(radius·W); B = the smallest power of two ≥ 2·pad + 4; n = log2(B). Prefix pass, repeated n times, step d = 2^it: P(x, y) ← P(x, y) + ((x & (B − 1)) ≥ d ? P(x − d, y) : 0), starting from P = s; afterwards P(x, y) is the sum of s over the row from the start of x's block (x & ~(B − 1)) to x (reads outside the work window are 0). Row integral to a real position t = x + o (pixel j covers [j − 0.5, j + 0.5); t is kept as the output column x and the offset o, so the fraction is as precise at the right of the frame as at the left): j = x + floor(o + 0.5), f = (o + 0.5) − floor(o + 0.5), lo = 0 if j is a block start else P(j − 1, y), I(t, y) = lo + (P(j, y) − lo)·f. Span integral S(tl, tr, y): with jl, jr the pixels of tl and tr, I(tr) − I(tl) when both lie in one block, else P(last pixel of jl's block, y) − I(tl) + I(tr). Gather at pixel (x, y): R = radius·W·size, size = 1 without map, else clamp(|m − focus|, 0, 1) with m the mapChannel of the map at (x, y) (luma = dot(luma, rgb); stored values; 0 outside the map's window); R < 0.001 → the output is s(x, y). Rx = R, Ry = R/aspect for aspect ≥ 1, else Rx = R·aspect, Ry = R. [y0, y1] = the lowest and highest y of the iris (host-computed). For dy from −ceil(Ry) to ceil(Ry), top to bottom: the interval [(dy − 0.5)/Ry, (dy + 0.5)/Ry] ∩ [y0, y1]; empty → next row; wy = its length·Ry, yc = its centre; [xl, xr] = the row of the iris at yc (aperture::span), cut by the cat's-eye circle (h² = 1 − (yc − k·v.y)²; h² ≤ 0 → next; xl = max(xl, k·v.x − h), xr = min(xr, k·v.x + h)); xl ≥ xr → next; acc += wy·S(x − xr·Rx, x − xl·Rx, y − dy); area += wy·(xr − xl)·Rx. Result acc/area. With rim ≠ 0 the same sums (acc2, area2) are taken with R·0.8 and the result is ((1 + rim)·acc − rim·acc2) / ((1 + rim)·area − rim·area2). A zero denominator gives s(x, y). Every output pixel is normalised by its own iris, so where the iris changes across the frame (catEye, a map) the light of a point is spread, not conserved exactly. map (optional second input) scales the radius per output pixel (a depth or focus matte): this is a gather, the way After Effects' Camera Lens Blur uses a blur map, so a sharp foreground edge does not spread over a blurred background behind it; for depth of field with correct occlusion, blur the layers separately and merge them. Premultiplied in, premultiplied out, all four channels alike. Output window = the input's grown by the ROI padding = radius width units (edge: clamp: the input's window). Two passes (prefix ×n, gather); the prefix covers the work window (the output window grown by the padding).

Examples:

// Defocus a background plate
const soft = plate.lensBlur({ radius: 0.012, blades: 7, roundness: 0.4, edge: "clamp" });

// Night lights with a bright rim and cat's eyes
const bokeh = lensBlur(city, { radius: 0.03, highlightGain: 4, highlightThreshold: 0.8, rim: 0.6, catEye: 0.5 });

// Rack focus from a depth matte
const dof = lensBlur(beauty, depthMatte, { radius: 0.02, focus: t((f) => remap(f, 1, 48, 0.2, 0.8)) });

mosaic

Pixelate: the picture in blocks of one colour each.

Module lamino/fx, category Filters, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
blocks vec2 [32, 18] 0.0001 or more yes Number of blocks [across the width, down the height] of the display.

The display window is divided into blocks = [across, down] blocks (block width = 1 / across, block height = (H/W) / down width units; the grid starts at the display's top-left corner and continues outside it). Every pixel of a block gets the block's colour: the mean of a 16×16 grid of bilinear samples of the premultiplied input spread evenly over the block (sample (i, j) at the block origin + ((i + 0.5)/16, (j + 0.5)/16) of the block size; transparent black outside the data window), summed row by row; border blocks of a picture without overscan darken slightly, their outermost samples reaching into the transparent black outside the data window. blocks must be positive (E_IR_PARAM_INVALID otherwise). Because the samples are placed in width units, every proxy level shows the same blocks. Output window = the input window grown to whole blocks; input region of an output box = the blocks it touches, plus one pixel.

Examples:

// Hide a face (with a mask)
const hidden = merge(mosaic(plate, { blocks: [48, 27] }), plate, { op: "copy", mask: faceMatte });

Mattes

screenKey

Colour-difference keyer (IBK style) for green / blue screens: pulls a matte and removes the screen colour.

Module lamino/fx, category Mattes, output image, pointwise (fused with its neighbours)

  • Input in (image): The plate.
  • Input cleanPlate (image, optional): Optional screen without the foreground (same framing, same colour state): gives S per pixel so an unevenly lit screen keys evenly.
Parameter Type Default Range Unit Keys Description
screen enum "green" Screen channel. Values: green blue
screenColor vec3 none yes Straight scene-linear screen colour probed from the plate (lamino probe on a clean patch of screen).
balance float 0.5 0 to 1 yes Weight of red in the limit of the other two channels (the rest goes to blue for green, to green for blue).
gain float 1 0 or more yes Scales the screen share before the matte (> 1 keys more).
clipBlack float 0 0 to 1 yes Raw matte at or below this becomes 0.
clipWhite float 1 0 to 1 yes Raw matte at or above this becomes 1 (must be > clipBlack).
subtract bool true Remove the screen colour from the rgb (true) or keep the plate colour premultiplied by the matte (false).
output enum "image" The keyed image, or the matte in all four channels. Values: image matte

Works on the values it gets: give it a scene-linear plate (convert a log or display-referred plate with colorspace() first) and screenColor probed from the same plate. Screen channel p and other channels o1, o2: green → (g; r, b), blue → (b; r, g). Colour difference D(x) = x_p − (balance·x_o1 + (1 − balance)·x_o2) (balance 0.5 is despill's average limit). Per pixel, with c the premultiplied input and a its alpha: S = the screen colour at the pixel (the clean plate unpremultiplied where it is connected, its alpha > 0 and D(S) > 1e-6; screenColor everywhere else); ρ = max(D(c.rgb) / D(S), 0) (the screen's share of the pixel, premultiplied); raw matte m0 = 1 − gain·ρ/a; matte m = clamp((m0 − clipBlack) / (clipWhite − clipBlack), 0, 1). subtract: true (default) removes the screen: u = max(c.rgb − ρ·S, 0) per channel and out.rgb = u·m/m0 where m0 > 0, else 0; with the default levels that is exactly u, so a pixel that is a mix α·F + (1 − α)·S with D(F) <= 0 comes out as α·F at alpha α (hair, motion blur and smoke keep their own colour), a pure or brighter screen pixel comes out as 0, and what remains has D(rgb) <= 0: the subtraction is also the spill suppression (despill with the average method after it changes nothing at balance 0.5). Levels rescale the reconstructed foreground u/m0 by the final matte, so a pixel clipBlack removes is fully transparent black and one clipWhite makes solid gets the foreground colour, not the plate. subtract: false keeps the plate colour: out.rgb = m·c.rgb (follow it with despill for spill). out.a = m·a. output: "matte" returns the matte in all four channels (m·a) for viewing; any image connects to a mask port through its alpha, so the keyed image itself is already the matte for merge's mask or withAlpha. gain divides the reference screen: the plate is read as a mix of the foreground and S / gain, so gain > 1 keys darker parts of an uneven screen fully (and brightens the reconstructed edge colour accordingly); a clean plate is the exact fix for an uneven screen. Pixels with input alpha 0 get the a → 0 limit: where gain > 0 and D(rgb) > 0 the pixel becomes 0; elsewhere the matte is 1, so rgb becomes max(rgb − ρ·S, 0) with subtract (rgb itself, negative channels set to 0, where D(rgb) <= 0) and stays rgb without; alpha stays 0. Garbage and holdout mattes are ordinary merges: outside(keyed, garbage) removes, merge(plate, keyed, { mask: core }) restores the opaque plate inside a core matte. Errors (E_IR_PARAM_RANGE, both backends): D(screenColor) <= 1e-6 (not a screen of the chosen colour, often a blue screen with screen: "green"), clipWhite <= clipBlack.

Examples:

// Green screen plate
import { screenKey } from "lamino/fx";
const keyed = plate.screenKey({ screenColor: [0.12, 0.42, 0.15], clipBlack: 0.05, clipWhite: 0.9 });
const shot = bg.over(keyed);

// Uneven screen with a clean plate, garbage matte
import { outside } from "lamino";
const keyed = outside(screenKey(plate, cleanPlate, { screenColor: [0.12, 0.42, 0.15] }), garbage);

// Check the matte
const m = plate.screenKey({ screenColor: [0.1, 0.2, 0.55], screen: "blue", output: "matte" });

wipe

Reveal or hide a picture with a moving edge: linear, radial (clock) or blinds.

Module lamino/fx, category Mattes, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
type enum "linear" Shape of the wipe. Values: linear radial blinds
completion float 0.5 0 to 1 yes 0 = picture whole, 1 = removed.
angle float 0 degrees yes Direction of travel (linear, blinds) or starting direction (radial), degrees clockwise from +x.
feather float 0 0 or more width units yes Width of the soft edge in width units.
width float 0.05 0.0001 or more width units yes Blinds: width of one strip in width units.
center vec2 [-1, -1] width units yes Centre of the radial wipe and origin of the blinds, [x, y] in width units; [-1,-1] = display centre.

Multiplies all four channels by a matte m in 0..1 (the image stays premultiplied); completion 0 leaves the picture whole, 1 removes it. dir = (cos angle, sin angle), computed on the host; s = dot(q − c, dir) for the pixel centre q and c = center; feather is the width of the soft edge in width units (0 = hard, one pixel wide in effect). linear: the edge travels along dir across the display window: with [s0, s1] the range of s over the display's corners, e = s0 − feather/2 + completion·(s1 − s0 + feather), m = clamp((s − e)/feather + 0.5, 0, 1) (for feather 0: s ≥ e). blinds: strips of width along dir, each wiped like the linear one within itself: with x = fract(s / width)·width, m = clamp((x − completion·(width + feather) + feather/2)/feather + 0.5, 0, 1). radial: a clock hand about c starting at angle and turning clockwise: θ = the angle of q − c from dir, in 0..2π (0 at q = c; a polynomial arctangent shared by both backends, error below 1e-6 rad), r = |q − c|; m = clamp((θ − completion·2π)·r/feather + 0.5, 0, 1), and m = 1 for completion ≤ 0, 0 for completion ≥ 1 (the starting edge at θ = 0 stays hard). With feather 0 the three are the comparisons s ≥ e, x ≥ completion·width and θ ≥ completion·2π. The matte is a function of the position only, so overscan outside the display window is wiped by the same rule (at completion 0 or 1 a linear wipe can still cut or keep pixels beyond the display's own range of s).

Examples:

// Wipe on from the left over 12 frames
const on = wipe(title, { completion: keys([[1, 1], [13, 0]]), angle: 180, feather: 0.02 });

matteOp

Combine two mattes (or prepare one): union, intersect, subtract, …, from alpha or luma, inverted or not.

Module lamino/fx, category Mattes, output image, pointwise (fused with its neighbours)

  • Input A (mask): First matte (an image's alpha, or a mask).
  • Input B (mask, optional): Second matte.
Parameter Type Default Range Unit Keys Description
op enum "union" How A and B are combined. Values: union intersect subtract difference max min
sourceA enum "alpha" What of input A is the matte. Values: alpha luma r g b
sourceB enum "alpha" What of input B is the matte. Values: alpha luma r g b
invertA bool false Use 1 − a.
invertB bool false Use 1 − b.
invert bool false Invert the result.
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights (default AP1 / ACEScg).

a = the sourceA of input A (alpha; luma = dot(luma, rgb) of the stored, premultiplied rgb; or one channel), 1 − a with invertA; b likewise from input B. op: union = a + b − a·b; intersect = a·b; subtract = a·(1 − b); difference = |a − b|; max; min. Without input B the result is a. invert gives 1 − result. Output: the matte in all four channels (r = g = b = a = m), an image that connects to image and mask ports alike: use it as a merge mask, or cut a picture with it (img.inside(m)). Nothing is clamped. Output window: the union of the inputs' windows (outside its window an input reads 0, so with invertA / invert the result is 1 only inside that union).

Examples:

// Garbage matte minus a hole
const m = matteOp(outer, hole, { op: "subtract" });

// Luma matte of a plate, inverted
const dark = matteOp(plate, { sourceA: "luma", invert: true });

Colour

colorMatrix

4×4 colour matrix plus offset (channel mixer, black and white, sepia, luma to alpha).

Module lamino/fx, category Colour, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
r vec4 [1, 0, 0, 0] yes Row of the output red: weights of [r, g, b, a].
g vec4 [0, 1, 0, 0] yes Row of the output green.
b vec4 [0, 0, 1, 0] yes Row of the output blue.
a vec4 [0, 0, 0, 1] yes Row of the output alpha.
offset vec4 [0, 0, 0, 0] yes Added after the matrix, [r, g, b, a].
unpremult bool true Work on straight colour: unpremultiply before and re-premultiply after.

With v = (r, g, b, a) straight (see unpremult): out.r = dot(r, v) + offset.r, likewise out.g, out.b and out.a from the rows g, b, a. The defaults are the identity. The colour rows' 4th component adds alpha to a colour channel; the a row builds the output alpha from the colour (a luma matte: a: [0.27, 0.67, 0.05, 0]). Nothing is clamped. Alpha == 0 pixels (with unpremult): rgb = the 3×3 colour part applied to rgb (the linear part; the alpha column and the offset vanish in the limit) and alpha stays 0, also when the a row or offset.a would give it a value. Script sugar: matrix: [[…], […], […]] (3×3 or 4×4, rows) fills the rows.

Examples:

// Swap red and blue
const swapped = colorMatrix(img, { r: [0, 0, 1, 0], b: [1, 0, 0, 0] });

// Luma into alpha
const lumaMatte = plate.colorMatrix({ a: [0.2722, 0.6741, 0.0537, 0] });

curves

Tone curves through control points: one master curve and one per channel.

Module lamino/fx, category Colour, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
master json [[0, 0], [1, 1]] Curve applied to r, g and b before their own curves: [[x, y], …].
r json [[0, 0], [1, 1]] Red curve.
g json [[0, 0], [1, 1]] Green curve.
b json [[0, 0], [1, 1]] Blue curve.
a json [[0, 0], [1, 1]] Alpha curve.
unpremult bool true Work on straight colour: unpremultiply before and re-premultiply after.

Each curve is a list of 2 to 16 points [[x, y], …] with strictly increasing x (anything else is E_IR_PARAM_INVALID). Between points it is a monotone cubic (Fritsch–Carlson tangents: no overshoot between points; the end tangents are the one-sided secants of the first and the last segment, limited like the others; all computed once on the host); outside the first and the last point it continues in a straight line with the tangent at that end, so values above 1 are not flattened. A curve left at its default [[0, 0], [1, 1]] is skipped (exactly the identity). Straight rgb (see unpremult): out.c = curve_c(master(c)) for c in r, g, b; alpha: out.a = a(alpha). Alpha == 0 pixels: each stored channel value is multiplied by the master's end slope on the side of its sign, then by the channel curve's end slope on the side of the sign of that result (the a → 0 limit of the straight continuations past the last point, or past the first for a negative value); alpha = a(0); nothing is re-multiplied.

Examples:

// S-curve contrast
const punchy = curves(plate, { master: [[0, 0], [0.25, 0.18], [0.75, 0.85], [1, 1]] });

hueSat

Rotate the hue, scale the saturation and the lightness, optionally for one hue range only.

Module lamino/fx, category Colour, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
hue float 0 degrees yes Hue rotation in degrees.
saturation float 1 0 or more yes Saturation factor (1 = unchanged, 0 = grey).
lightness float 0 -1 or more yes Lightness as a gain offset: rgb·(1 + lightness).
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights (default AP1 / ACEScg).
rangeCenter float 0 degrees yes Centre of the hue range in degrees (0 red, 120 green, 240 blue).
rangeWidth float 360 0 to 360 yes Width of the hue range in degrees; 360 = every hue (no range).
rangeSoftness float 30 0 to 180 yes Falloff beyond the range on each side, in degrees.

Works in the working space on linear values, about the luma axis (HDR-safe; the numbers do not match After Effects, which works on gamma-encoded HSL). Y = dot(luma, rgb). (1) hue: rgb is rotated about the grey axis (1, 1, 1) by hue degrees (red → green for positive angles: 120 turns red into green), then shifted along the grey axis by (Y − Y′)/Σluma per channel so that Y is what it was (no shift when Σluma = 0). (2) saturation: Y + (rgb − Y)·saturation. (3) lightness: rgb·(1 + lightness) (a gain: −1 is black, 1 doubles). The three steps are one 3×3 matrix, computed on the host (hue 0, saturation 1 and lightness 0 skip the node: exactly the input). The operation is homogeneous, so it is applied to the premultiplied rgb as stored, alpha is untouched, and alpha == 0 pixels get it like every other pixel. Range (rangeWidth < 360): the pixel's hue angle θ = atan2(dot(c, e2), dot(c, e1)) in degrees, with c = rgb − mean(rgb), e1 = (2, −1, −1)/√6, e2 = (0, 1, −1)/√2 (red 0°, green 120°, blue 240°; the same arithmetic arctangent on both backends, lamino_nodes::pointwise::hue_sat::atan2, error below 1e-6 rad); d = the angular distance from rangeCenter; w = 1 − smoothstep(rangeWidth/2, rangeWidth/2 + rangeSoftness, d); out = rgb + (adjusted − rgb)·w. A pixel without chroma (|c| ≤ 1e-6·max|rgb|) has no hue and gets w = 0.

Examples:

// Desaturate a little, shift towards green
const cooler = hueSat(plate, { hue: 8, saturation: 0.85 });

// Only the reds
const lessRed = plate.hueSat({ saturation: 0.3, rangeCenter: 0, rangeWidth: 60 });

colorCorrect

Saturation, contrast, gamma, gain and offset for the whole picture and per tonal range (shadows / midtones / highlights).

Module lamino/fx, category Colour, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
saturation float 1 0 or more yes Saturation of the whole picture.
contrast color [1, 1, 1, 1] 0 or more yes Contrast of the whole picture about 0.18.
gamma color [1, 1, 1, 1] 0.001 or more yes Gamma of the whole picture.
gain color [1, 1, 1, 1] yes Gain of the whole picture.
offset color [0, 0, 0, 0] yes Offset of the whole picture.
shadowsSaturation float 1 0 or more yes Saturation of the shadows.
shadowsContrast color [1, 1, 1, 1] 0 or more yes Contrast of the shadows about 0.18.
shadowsGamma color [1, 1, 1, 1] 0.001 or more yes Gamma of the shadows.
shadowsGain color [1, 1, 1, 1] yes Gain of the shadows.
shadowsOffset color [0, 0, 0, 0] yes Offset of the shadows.
midtonesSaturation float 1 0 or more yes Saturation of the midtones.
midtonesContrast color [1, 1, 1, 1] 0 or more yes Contrast of the midtones about 0.18.
midtonesGamma color [1, 1, 1, 1] 0.001 or more yes Gamma of the midtones.
midtonesGain color [1, 1, 1, 1] yes Gain of the midtones.
midtonesOffset color [0, 0, 0, 0] yes Offset of the midtones.
highlightsSaturation float 1 0 or more yes Saturation of the highlights.
highlightsContrast color [1, 1, 1, 1] 0 or more yes Contrast of the highlights about 0.18.
highlightsGamma color [1, 1, 1, 1] 0.001 or more yes Gamma of the highlights.
highlightsGain color [1, 1, 1, 1] yes Gain of the highlights.
highlightsOffset color [0, 0, 0, 0] yes Offset of the highlights.
ranges vec4 [0, 0.09, 0.5, 1] [s0, s1, h0, h1]: the shadows weight falls from 1 to 0 between s0 and s1, the highlights weight rises from 0 to 1 between h0 and h1 (luma).
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights (default AP1 / ACEScg).
unpremult bool true Work on straight colour: unpremultiply before and re-premultiply after.

Straight rgb (see unpremult), Y = dot(luma, rgb) of the input. Range weights from ranges = [s0, s1, h0, h1]: ws = 1 − smoothstep(s0, s1, Y), wh = smoothstep(h0, h1, Y), wm = 1 − ws − wh. Each control P has a master value and one per range; the value used at a pixel is P_master · (P_midtones + ws·(P_shadows − P_midtones) + wh·(P_highlights − P_midtones)) (= P_master · (ws·P_shadows + wm·P_midtones + wh·P_highlights), written so that equal range values give exactly that value) for saturation, contrast, gamma and gain, and P_master + ws·P_shadows + wm·P_midtones + wh·P_highlights for offset. Applied in this order: saturation (Y + (rgb − Y)·saturation), contrast (0.18·(c / 0.18)^contrast for c > 0, c unchanged otherwise), gamma (c^(1/gamma) for c > 0), gain (c·gain), offset (c + offset); a saturation, contrast or gamma of exactly 1 is not applied. Nothing is clamped. Parameter names: the master ones are saturation, contrast, gamma, gain, offset; the ranges prefix them (shadowsGain, midtonesContrast, highlightsSaturation, …). Colours take a scalar or [r, g, b]. Alpha is untouched. Alpha == 0 pixels: the a → 0 limit sends Y to the highlights, so rgb gets the saturation and the gain of master · highlights only; contrast, gamma and offset are not applied (no limit / constant term). Script sugar: shadows: { gain: 1.2 } sets shadowsGain.

Examples:

// Lift the shadows, cool the highlights
const cc = colorCorrect(plate, { shadows: { gain: 1.3 }, highlights: { gain: [0.95, 1.0, 1.08] } });

gradientMap

Map a channel (or the luma) through a colour gradient: tint, tritone, false colour, colour cycling.

Module lamino/fx, category Colour, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
stops json [{"color": [0, 0, 0, 1], "offset": 0}, {"color": [1, 1, 1, 1], "offset": 1}] Gradient stops [{ offset, color }, …], 2 to 8.
source enum "luma" What is looked up in the gradient. Values: luma r g b a
luma vec3 [0.2722287, 0.6740818, 0.0536895] Luma weights (default AP1 / ACEScg).
cycles float 1 yes Repetitions of the gradient over 0..1 of the source.
phase float 0 yes Shift of the lookup; 1.0 = one whole gradient.
wrap enum "clamp" Outside 0..1: hold the end colours, or start over. Values: clamp repeat
amount float 1 0 to 1 yes Blend with the original (1 = the gradient only).
unpremult bool true Work on straight colour: unpremultiply before and re-premultiply after.

t = the source of the straight pixel (see unpremult): luma = dot(luma, rgb), or one channel. u = t·cycles + phase; wrap: clamp uses clamp(u, 0, 1), wrap: repeat uses fract(u) (colour cycling: animate phase). The gradient is stops: 2 to 8 entries { offset, color } with non-decreasing offsets in 0..1 (anything else is E_IR_PARAM_INVALID), colours as every Color parameter ([r, g, b], [r, g, b, a], a number, "#hex" or { srgb: [r, g, b, a] }; premultiplied), interpolated linearly, premultiplied, between stops and constant before the first / after the last (of two stops at one offset the later one wins there). With G = gradient(u) and Gs = G.rgb / G.a where G.a > 0 (G.rgb otherwise): out rgb = rgb + (Gs − rgb)·amount (straight), out alpha = alpha·(1 + (G.a − 1)·amount), re-premultiplied by the output alpha. Alpha == 0 pixels pass through unchanged (the a → 0 limit of a lookup is not their colour).

Examples:

// Duotone
const duo = gradientMap(plate, { stops: [{ offset: 0, color: "#1b1f4b" }, { offset: 1, color: "#ffd9a0" }] });

posterize

Reduce each colour channel to a number of levels.

Module lamino/fx, category Colour, output image, pointwise (fused with its neighbours)

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
levels int 8 2 to 256 yes Levels per channel between 0 and 1 (2 = black and white per channel).
gamma float 2.2 0.1 to 10 Curve applied before the steps and undone after.
unpremult bool true Work on straight colour: unpremultiply before and re-premultiply after.

Straight rgb (see unpremult). For c ≥ 0: e = c^(1/gamma), q = floor(e·(levels − 1) + 0.5) / (levels − 1), out = q^gamma. The steps are taken on a gamma-encoded value (2.2 by default) so that they look evenly spaced; with gamma 1 they are even in linear light. Values above 1 keep stepping at the same spacing (nothing is clamped); negative values pass through. Alpha is untouched. Alpha == 0 pixels pass through unchanged (a step function has no a → 0 limit).

Examples:

// Six tones
const poster = posterize(plate, { levels: 6 });

Transforms

waveWarp

Displace the picture along a travelling wave: sine, triangle, square, sawtooth or smooth noise.

Module lamino/fx, category Transforms, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
type enum "sine" Wave shape. Values: sine triangle square sawtooth noise
height float 0.01 width units yes Largest displacement in width units.
wavelength float 0.1 0.0001 or more width units yes Length of one wave in width units.
direction float 0 degrees yes Direction the wave travels, degrees clockwise from +x (pixels move across it).
phase float 0 yes Position of the wave; 1.0 = one wavelength.
pinEdges bool false Keep the frame's border in place.
seed int 0 Seed of the noise wave.

dir = (cos direction, sin direction) (the way the wave travels), n = (−dir.y, dir.x) (the way pixels move), both computed on the host. For the pixel centre q (width units, relative to the display centre): x = dot(q, dir) / wavelength − phase; d = height·wave(x); out(p) = in(q − d·n), bilinear, transparent black outside the data window. wave(x), period 1, range −1..1: sine = sin(2π·x); triangle = 1 − 4·|fract(x + 0.25) − 0.5|; square = 1 for fract(x) < 0.5 else −1; sawtooth = 2·fract(x) − 1; noise = smooth value noise, one lamino_hash(i, seed, 0x77617665) value per unit i of x, smoothstep-interpolated, mapped to −1..1 (fract(x) = x − floor(x) throughout). phase moves the wave along dir (1.0 = one wavelength; animate it: the node never reads the frame). pinEdges: d is multiplied by clamp(e / (2·|height|), 0, 1) with e the distance from q to the nearest edge of the display window, so the frame's border stays put. Output window = the input window grown by ceil(|height|·W) px.

Examples:

// Flag ripple
const flag = waveWarp(cloth, { height: 0.008, wavelength: 0.15, phase: t((f) => f / 24) });

lensDistort

Radial lens distortion from two coefficients: add it to a CG element or remove it from a plate (when there is no ST map).

Module lamino/fx, category Transforms, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
k1 float 0 yes Second-order radial coefficient.
k2 float 0 yes Fourth-order radial coefficient.
center vec2 [-1, -1] width units yes Distortion centre [x, y] in width units; [-1,-1] = display centre.
squeeze float 1 0.1 to 10 Anamorphic squeeze: horizontal distances are multiplied by it before the radius is taken.
direction enum "undistort" Remove the distortion from a plate, or add it to an element. Values: undistort distort
scaleToFit bool false Scale so that no empty border shows.
filter enum "bilinear" Resampling filter. Values: bilinear bicubic

The simple model for when no ST map exists (with one, use uvMap). Normalised coordinates about c = center: v = ((q − c).x·squeeze, (q − c).y) / 0.5 (so |v| = 1 at half the width from the centre, squeeze being the anamorphic factor), r = |v|. The model maps a distorted position to the undistorted one: v_u = v_d·(1 + k1·r_d² + k2·r_d⁴) (k1 > 0: a barrel plate, whose periphery is imaged too close to the centre: undistorting pushes the picture outward. k1 < 0: pincushion: undistorting pulls it inward and leaves an empty border unless scaleToFit). direction: undistort removes the distortion from a plate: the output is the undistorted picture, out(v_u) = in(v_d), and v_d is found from v_u by 8 Newton steps on r (the same count on both backends, starting from r_u; the derivative is floored at 1e-6 and each step clamped to 0..1e4, so where the model folds and no r_d exists the result is undefined but finite). direction: distort adds it: out(v_d) = in(v_u), directly from the formula. scaleToFit scales the result about c by one factor S ≥ 1 so that the display window stays covered: S = the largest 1 / h over the four corners and four edge midpoints of the display window, h being how far the model moves that point along its ray (r_out / r_in), computed on the host; it never shrinks a result that already covers the frame. filter: bilinear or bicubic (Catmull-Rom); transparent black outside the data window. Output window = the display window united with the input window; the whole input is requested. The pixel aspect ratio is not used.

Examples:

// Straighten a plate, comp, put the distortion back
const flat = lensDistort(plate, { k1: -0.04 });
const out = lensDistort(comped, { k1: -0.04, direction: "distort" });

warp

Twirl, bulge or polar-coordinate warp about a centre.

Module lamino/fx, category Transforms, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
type enum "twirl" Kind of warp. Values: twirl bulge rectToPolar polarToRect
amount float 1 yes Twirl: degrees at the centre. Bulge: −1..1. Polar: 0..1 blend.
radius float 0.25 0.0001 or more width units yes Radius of the effect in width units.
center vec2 [-1, -1] width units yes Centre [x, y] in width units; [-1,-1] = display centre.

c = center, d = q − c for the pixel centre q, r = |d| (width units), R = radius; bilinear, transparent black outside the data window. twirl: inside R the picture is turned by amount degrees at the centre, falling to 0 at R: φ = radians(amount)·(1 − r/R)² for r < R; out(q) = in(c + rotate(d, −φ)) (clockwise positive). bulge: inside R the picture is magnified at the centre (amount in −1..1; negative pinches): out(q) = in(c + d·(1 − amount·(1 − r/R)²)) for r < R. Outside R both leave the picture as it is. rectToPolar (After Effects' Polar Coordinates, rect to polar): the output pixel at angle θ (clockwise from straight up, 0..1 of a turn) and radius r reads the input at x = θ (0..1 of the display width), y = (r / R)·(H/W) from the top; beyond R it reads below the picture's bottom edge (transparent unless the input has overscan there). polarToRect is the inverse: the output pixel (x, y) reads the input at c + R·(y / (H/W))·(sin 2πx, −cos 2πx). For the polar types amount (0..1) blends the read position between the pixel's own position and the warped one. amount 0 is a copy for every type. Output window = the input window united with the display window; the whole input is requested.

Examples:

// Twirl
const swirl = warp(plate, { type: "twirl", amount: 120, radius: 0.3 });

// Tiny planet
const planet = warp(pano, { type: "rectToPolar", radius: 0.28 });

cornerPin

Pin the four corners of the frame to four points (perspective / projective transform).

Module lamino/fx, category Transforms, output image

  • Input in (image): Source.
Parameter Type Default Range Unit Keys Description
tl vec2 [-1, -1] width units yes Where the top-left corner of the display window goes, [x, y] in width units; [-1,-1] = it stays.
tr vec2 [-1, -1] width units yes Where the top-right corner of the display window goes, [x, y] in width units; [-1,-1] = it stays.
br vec2 [-1, -1] width units yes Where the bottom-right corner of the display window goes, [x, y] in width units; [-1,-1] = it stays.
bl vec2 [-1, -1] width units yes Where the bottom-left corner of the display window goes, [x, y] in width units; [-1,-1] = it stays.
filter enum "bilinear" Resampling filter. Values: bilinear bicubic

The projective map (homography) that takes the display window's corners (0, 0), (1, 0), (1, H/W), (0, H/W) to tl, tr, br, bl. The 3×3 matrix and its inverse are computed on the host in f64 and handed to both backends as f32; each output pixel is mapped back through the inverse and the input is resampled there (filter: bilinear or bicubic = Catmull-Rom; transparent black outside the data window; a pixel whose inverse lies behind the projection, w ≤ 0, is transparent). The picture's overscan is mapped with it. Four corners that do not span a quadrilateral (three on a line, or coinciding) are E_IR_PARAM_INVALID when the frame is evaluated (concave and crossed quadrilaterals are valid). No filter widens when the pin shrinks the picture (as transform): blur first for a strong reduction. Output window = the bounding box of the mapped input window (E_RESOURCE_LIMIT beyond 16× the display area), or the display window united with the input window when a corner of it maps behind the projection; the whole input is requested.

Examples:

// Screen replacement
const onScreen = cornerPin(ui, { tl: [0.31, 0.12], tr: [0.62, 0.15], br: [0.61, 0.33], bl: [0.30, 0.31] });