4. Rendering model

A sampled Node is resolved in hd into a display program: flat drawing operations in frame pixels, plus offscreen scopes where a shader needs them. The display program is plain data, compared to skip repeated frames and checked in tests without a GPU. hd then plans the GPU work for it (chapter 5).

Layout and paint

rect, circle, text, number, path, stroke and the chart and code constructors provide content. row and column lay children out with gap and alignment; stack aligns; canvas(width, height, children) keeps child coordinates and draw order. .pad, .background, .center_in, .translate, .scale, .opacity and .id compose normally. Paint transforms never reflow siblings. Shaders, masks and clips change paint, never the layout box.

The core operations

Everything visual is built from these. The bundled pkg.looks and a project's own looks use exactly the same ones.

Operation What it does
path(outline, paint) Fills an outline: moves, lines, quadratic and cubic curves, any number of contours, nonzero or even-odd. Paints are solid colors and linear and radial gradients
stroke(outline, style, paint) Strokes an outline: width, caps, joins, miter limit, dashes
text, image Shaped glyph runs and pictures
.opacity(a), group A layer at an opacity
.blend(mode) The node as one layer, combined with what's under it: multiply, screen, overlay, darken, lighten, dodge, burn, hard and soft light, difference, add
.clip_path(outline) Cuts the node to any outline
.mask(shape, invert) Keeps the node where shape is opaque, or where it isn't
shader(wgsl, inputs, params, extent) Pixels computed by WGSL from other nodes' pixels: the one pixel operation
geometry(wgsl, data, stride, count, bounds) Triangles placed and colored by WGSL vertex and fragment shaders over per-instance data: particles, sprites, later meshes

All but shader and geometry are vector operations that Vello draws within the frame's own render. Those two draw offscreen and come back as an image.

Outline holds segments and a fill rule; .and(other) joins outlines into one path, .with_even_odd() switches the rule. StrokeStyle { width, cap, join, miter, dashes, dash_offset } defaults to round caps and joins.

Shaders

shader(wgsl, inputs=[a, b], params=[...], extent=.FromInputs(reach))
node.shade(wgsl, params, reach)        # Node::shader(wgsl, [node], ...)

A shader runs wgsl once for every pixel of its region, reading the pixels of its inputs. Each input is drawn offscreen, aligned to the region. The WGSL defines fn kernel(p: vec2<f32>) -> vec4<f32>, returning the premultiplied color at pixel center p (from the region's top left). It may call:

and read SIZE (the region in pixels), SCALE (pixels per unit), REGION (x y width height in units) and INPUTS (how many). Names starting nippo are reserved. A shader takes at most 4 inputs and 16 parameters.

Region. .FromInputs(reach) covers where the inputs paint, grown by reach units on every side, for shaders that spread pixels outward like blurs. .Fixed(width, height) is a box from (0, 0), for shaders that make pixels from nothing, like noise. A shader with no inputs needs a fixed extent.

Units. Inputs are drawn in the shader node's own units at the pixel density of its final transform, and the result is drawn back under that transform. So a blur radius is measured in the node's units, and scaling a finished glow scales its halo.

Fusion. Single-input shaders written one over another fuse into one scope: the innermost input is drawn once, then each shader runs in order over the previous one's output (source), without drawing back between them. Their reaches add up.

Errors. A shader that fails to compile stops the render with the WGSL compiler's message verbatim, so the agent that wrote it can fix it. The interface above is versioned: changing it breaks every project's looks.

Compositing laws

The looks library

A Look is fn(Node) -> Node, applied with node.look(look) or clip.look(look). pkg.looks is ordinary hd and WGSL to read, copy and change. Each look declares its source kinds, defaults and units, bounds, alpha handling, time dependence, seeds, endpoint behavior and cost.

Look Contract
blur(radius) Separable gaussian, two shaders; grows the region by 1.5 radii
glow(radius, strength, color?) A bounded halo under the source; without a color the halo takes the source's colors
shadow(offset, radius, color) A soft shadow behind the source
light_sweep(progress, strength, width=0.16) One alpha-respecting band; identity at 0 and 1; width is a fraction of the source's width
card_flip(progress, from) Invisible at 0, the exact source at 1; the layout box doesn't change
light_rays(center, strength, length=0.45, threshold=0, spread=420) The source's own light streaming away from center (40 taps toward it, fading); identity at 0
chromatic(amount) Red and blue pulled apart from the middle, amount units at the corners; identity at 0
ink_reveal(progress, seed), liquid_reveal(progress, seed) Hidden at 0, exact at 1; a stable seeded edge
wipe(progress, from, feather) A feathered straight-edge reveal; hidden at 0, exact at 1
luma_mask(shape, invert) The source kept where shape is bright
film_finish(preset, seed) Contrast, saturation, vignette and grain; alpha kept; grain steps on a 24 Hz grid from the frame
Background::aurora(size, palette, seed) Opaque coverage of size, a direct seeded function of time
Title::neon(text, size, max_width, max_lines, color) Pinned bold face, stable wrapping, bounded glow; too many lines is a preflight error

pkg.transitions holds the transitions, each a Transition.With exact at 0 and 1:

Recipe Contract
smear(dx, dy) A directional box blur along a vector in units, as two passes: about 2√L samples for a streak L pixels long; identity at zero; grows paint by half the vector
whip_pan(toward, distance, streak) Both samples translate together, eased; smear peaks at the middle
film_burn(seed, x, y) One two-input shader: a seeded fbm front from (x, y), warm overexposure ahead, a hot rim
prism(amount, angle), prism_transition(amount, angle) Eight hue-weighted taps along a segment, normalized per channel; alpha is the taps' maximum
page_curl(radius, angle) The outgoing sample rolled on a cylinder sweeping corner to corner; the back shows as paper; a soft shadow on the incoming sample

Looks that need two copies of their source (glow, shadow) draw it twice; identical scopes in a frame share one result, so the copy costs only vector drawing. Library versions, defaults and seeds are part of render identity.

Quality and cost

Video.effect_scale(scale) draws every effect scope and geometry layer at scale of full resolution. GPU cost falls by about scale²; vector drawing outside the scopes stays sharp. nippo render --draft (and still, sheet) uses 0.5. Kernels see the scale as SCALE and keep their sizes in units, so a draft keeps the final layout.

The costs project has one variant per recipe over the same 1080p frame (COSTS names them). The table below comes from nippo render costs --variant N: 120 frames, x264 veryfast, best of three, on an M3 Max under load. The bare frame is encoder-bound at 260–290 fps, so a recipe within that range costs less than the run-to-run noise.

Tier Recipes Final Draft
Below noise on a card-sized subject blur, glow, shadow, light sweep, card flip, ink and liquid reveals, wipe, smear, prism, echo ×4, motion blur ×8 210–270 fps same
One full-frame pass glass panel, aurora, film finish, prism and page-curl transitions 205–225 fps 170–250 fps
Two full frames streaked whip pan, film burn 155–200 fps 200–230 fps

Measure on the target machine before relying on a tier. Readback is double-buffered, so the report's GPU wait shows only the GPU time the CPU couldn't hide. Per-pass GPU time would need timestamp queries.

A coherent effect library

Family Initial usable results Reusable operations
Titles/captions Word rise, emphasis, neon, lower third, karaoke Semantic selection, stagger, paint, glow
Reveals/transitions Ink, liquid, luma, whip, prism, film burn Masks, displacement, two-input mixing, exact endpoints
Light/atmosphere Sweeps, glints, rays, dust, sparks, confetti Threshold/blur, overlays, finite emission, lifetime curves
Textures/finishing Grain, duotone, halftone, paper/print, film/analog Procedural/image maps, grade, compositing
Surface/deformation Glass cards, lenses, ripple, heat haze, fold/curl Explicit backdrop, spatial maps, deformation
Temporal Speed ramps, stutter, echoes, trails, selective blur Source-time requests and bounded accumulation
Patterns Logo walls, cascading cards, radial/path repetition Stable distributions plus indexed motion
Optional depth Extruded title and model/product shots Bounded prepared geometry and shot recipes

Particle assembly

Prepare a stable point set from a source fill or edge and keep the exact source appearance. Scattered positions come from the same point IDs; trajectories and lifetime appearance are evaluated per sample, then the particles crossfade to the exact source over the last 200 ms. Too-short durations are diagnosed.

assembly := prepare_particle_assembly!(source=prepared_title, count=2400, scatter_radius=220.0, seed=41)?
art := assembly.sample(start=ms(200), duration=ms(1100), color=hex("#67e8f9"), radius=1.4)
    .look(glow(12.0, 0.35))

Preparation lays the source out, turns its fills and glyphs into outlines (glyph outlines come from the shaper), and keeps seeded points inside them by the outlines' fill rules. Each point records which shape it landed in. Preparation therefore needs the Shaper; a project's build has it in its Preparing row.

The recipe behind sample is ordinary hd over dots, so a variation such as per-word stagger stays local to the project. Particles are geometry: their data crosses the native boundary in one buffer, never per particle.

Liquid text, glass and depth

A liquid neon reveal composes shaped words, staggered progress, an organic mask, a bright boundary rim, glow and settling motion. Changing selection, mask or treatment should produce a new look without another native effect implementation. These are image/motion recipes, not promises of fluid simulation.

Looks at rest are the node itself. A reveal or flip at 0 or 1 returns the node (or nothing) instead of resampling it, so finished text stays sharp and costs no pass.

Glass (built): glass(backdrop, shape: Outline, frost, refraction, bevel, shine, sheen, tint, light_x, light_y) in pkg.surface. It clips the backdrop to the panel's bounds grown by 1.5 × frost + refraction, blurs that, and bends it along the slope of the panel's softened edge. The rim catches light from one side and shades on the other. Draw the backdrop, then the glass, then the label (surfaces).

Patterns (built): pkg.patterns has grid, ring and along(outline), which place item(i) copies. Items take any requirement row, so they can animate. scatter(count, w, h, gap, seed) gives stable seeded points; spread(points, origin) gives distance fractions for outward cascades. Outline.point_at(fraction) gives position and heading by length.

Audio-reactive drivers (built): reactive(analysis, attack, release) in pkg.reactive smooths the loudness envelope in preparation and scales it to a peak of 1. level(t), beats(t) (onsets so far) and pulse(t, decay) are pure functions of time.

Clips bound paint: a subtree under clip_path paints only inside the clip's bounds. A scope's region honors this, so clipping a large input before an expensive shader shrinks the work.

A glass panel takes an explicit same-time background value and region. Reuse the same backdrop branch in the scene, then composite the panel label afterward to keep it sharp. Reject cycles; never read whichever pixels happened to be drawn earlier. The supplied prism/page-curl examples are references for these kinds of treatments. Prism demo source, deformation source.

Solids and shot packs (built): pkg.solid is library code over geometry with depth.

Product shots remain ordinary timed visuals that can be captioned, masked and retimed.

Geometry

geometry(wgsl, data, stride, count, bounds, vertices=6, params=[], depth=false, smooth=false)

Geometry draws count instances of vertices corners each. The WGSL defines:

and may call datum(instance, k) (float k of the instance, from data[instance * stride + k]), param(i) and quad(vertex) (corner vertex % 6 of a two-triangle square from -1 to 1), and read SCALE. vertex may set DEPTH (0 near, 1 far) and W: the corner's clip position is (position, DEPTH) × W, so setting W to the view distance interpolates the corner values in perspective. Without depth, instances draw in order, each over the ones before; with it, the nearest triangle wins at each pixel. smooth draws 4× multisampled, for antialiased edges. bounds, in the node's units, is where it may paint and its layout box: the GPU places the triangles, so hd can't measure them.

Like a shader, geometry is drawn at the pixel density of its final transform and drawn back under it. Its data crosses to the GPU once a frame, as one buffer.

pkg.particles is library code over geometry: dots (round, antialiased), confetti pieces turned and flipped in the vertex shader, and the sparks, confetti and dust emitters, which compute each particle's state analytically from time and a seeded hash. pkg.solid draws meshes with the same node, depth and smooth set.

This page’s source on GitHub