# Layer basics

> The fields every layer shares — id, timing, position, anchor, size, transforms, paint, shadow, filters, blend modes, 3D tilt and presets — and how percentages and draw order work.

A composition is a stack of layers. Every layer is a JSON object with a `type` and, ideally, an `id`;
everything else is optional and has a sensible default. This page covers the fields that every layer
type shares. The pages that follow cover what each type adds.

```json title="the smallest useful layers"
{ "id": "bg",    "type": "rect", "fill": "#f4f1ea" }
{ "id": "title", "type": "text", "text": "Hello", "fontSize": 96 }
```

With no position, both land in the center of their parent. With no size, the rect fills its parent
and the text is measured from its content. With no timing, both last as long as their parent.

## Layer types

| `type` | what it draws | page |
|---|---|---|
| `rect`, `ellipse`, `polygon`, `star`, `arc` | built-in shapes | [Shapes](https://vidmake.app/docs/shapes.md) |
| `path`, `line` | SVG path data or a polyline, with draw-on trimming | [Paths](https://vidmake.app/docs/paths.md) |
| `text` | a text block: fonts, wrapping, rich spans, stagger | [Text](https://vidmake.app/docs/text.md) |
| `image` | png, jpg, webp, bmp, gif (first frame) or svg | [Images](https://vidmake.app/docs/images.md) |
| `video` | any file ffmpeg can read, with its sound | [Video](https://vidmake.app/docs/video.md) |
| `audio` | sound only, nothing on screen | [Audio](https://vidmake.app/docs/audio.md) |
| `group` | other layers in their own coordinate space | [Groups](https://vidmake.app/docs/groups.md) |
| `use` | another composition, with props (a component) | [Components](https://vidmake.app/docs/components.md) |
| `captions` | subtitles from srt/vtt/json or inline items | [Captions](https://vidmake.app/docs/captions.md) |
| `waveform` | a spectrum or oscilloscope of an audio track | [Waveform](https://vidmake.app/docs/waveform.md) |
| `particles` | a deterministic particle emitter | [Particles](https://vidmake.app/docs/particles.md) |

A field that does not apply to a type is an error, not a silent no-op, and a misspelled field gets a
suggestion:

```output
✗ main: layer `box` (main > layers[0]): field(s) fontSize do not apply to `rect` layers
✗ main: composition `main`: unknown field `fontsize` — did you mean `fontSize`?
```

## Identity and bookkeeping

| field | default | notes |
|---|---|---|
| `id` | `type#index` | Every CLI command addresses layers by id (`inspect -l`, `trace -l`, `set title.fontSize`). Give every layer one. |
| `type` | required | One of the types above. |
| `visible` | `true` | `false` removes the layer completely: it is not drawn, takes no space in a [layout](https://vidmake.app/docs/groups.md#layout), and its sound is not mixed. Handy for switching variants on and off. |
| `comment` | | Free text for humans and agents. Ignored by the renderer. |
| `lint` | | `false`, or `{ "ignore": ["offCanvas", "invisible"] }`, silences [validate warnings](https://vidmake.app/docs/lint.md) for this layer and its children. |
| `motionBlur` | `true` | `false` renders this layer at the exact frame when the composition has [motion blur](https://vidmake.app/docs/compositions.md). |

Auto-generated ids (`rect#0`, `text#3`) change whenever layers are reordered, so they are fine for a
quick look but not something to script against.

## Timing

| field | default | notes |
|---|---|---|
| `start` | `0` | When the layer appears, relative to its parent's start. |
| `duration` | rest of the parent | How long it stays. Media layers default to their media length. |
| `end` | | Alternative to `duration`: the time it disappears, on the same clock as `start`. `duration` wins if both are set. |

Numbers are frames; strings can be seconds (`"1.5s"`), milliseconds (`"500ms"`), frames (`"45f"`) or
`m:ss` (`"1:02.5"`). Every animation time inside a layer is local to that layer, so a keyframe at `0`
fires when the layer appears, not when the video starts. [Time values](https://vidmake.app/docs/time.md) covers this in depth,
and [series](https://vidmake.app/docs/series.md) plays layers one after another without adding up start times by hand.

## Position and size

| field | default | notes |
|---|---|---|
| `x`, `y` | `"50%"` (center of the parent) | Where the layer's **anchor point** sits, in parent coordinates. |
| `width`, `height` | depends on the type | See the table below. |
| `anchor` | `[0.5, 0.5]` | Which point of the layer's own box is placed at `x`/`y`. |

Coordinates are pixels with `0,0` at the parent's top-left corner, `y` growing downward. At the top
level the parent is the composition; inside a [group](https://vidmake.app/docs/groups.md) or [component](https://vidmake.app/docs/components.md) it
is that layer's box.

### Default sizes

| type | size when `width`/`height` are not set |
|---|---|
| `rect` | the full parent size. If only one of the two is set, the other is `100`. |
| `ellipse`, `polygon`, `star`, `arc` | 100×100. One of `width`/`height` makes it square. |
| `text`, `captions` | measured from the content, plus `padding` (captions are 80% of the parent wide) |
| `image`, `video` | the media's native size. One of `width`/`height` keeps the aspect ratio. |
| `path`, `line` | the bounds of the points, from `0,0` to the largest x and y |
| `group` | the parent size |
| `use` | the referenced composition's size |
| `waveform` | 80% of the parent width × 200 |
| `particles` | a point (1×1): the area particles are born in |
| `audio` | no box at all |

### Anchor

The anchor is a fraction of the layer's own box: `[0, 0]` is its top-left corner, `[1, 1]` the
bottom-right, `[0.5, 0.5]` (the default) the center. Rotation and scale happen around it too.
Names work as well: `center`, `top-left`, `top`, `top-right`, `left`, `right`, `bottom-left`, `bottom`,
`bottom-right` (camelCase like `topLeft` is accepted). Values outside `0..1` are allowed and put the
pivot outside the box, which is useful with [attach](https://vidmake.app/docs/attach.md).

*(An interactive anchor widget is shown here on the HTML page.)*

The anchor is the easiest way to align things without arithmetic. To pin a watermark to the top-right
corner 40 px from the edges, anchor its top-right corner and place that:

```json
{ "id": "mark", "type": "text", "text": "vidmake", "anchor": "top-right", "x": "=w - 40", "y": 40 }
```

Left-aligned blocks (lower thirds, bullet lists) usually want `"anchor": "left"` and an explicit `x`.

**Demo: The same rotation around three different anchor points** (rendered video: https://vidmake.app/media/layers-anchor.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "anchor", "description": "The same rotation around three different anchor points",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "guide", "type": "rect", "y": 330, "width": 1100, "height": 1, "fill": "#8a857a" },
      { "id": "card-tl", "type": "rect", "x": 260, "y": 330, "width": 180, "height": 110, "cornerRadius": 4,
        "anchor": "top-left", "fill": "#161412", "rotation": "=t * 90" },
      { "id": "card-c", "type": "rect", "x": 640, "y": 330, "width": 180, "height": 110, "cornerRadius": 4,
        "fill": "#161412", "rotation": "=t * 90" },
      { "id": "card-br", "type": "rect", "x": 1020, "y": 330, "width": 180, "height": 110, "cornerRadius": 4,
        "anchor": "bottom-right", "fill": "#161412", "rotation": "=t * 90" },
      { "id": "pin", "type": "ellipse", "width": 22, "y": 330, "fill": "#c92a26", "stroke": "#f4f1ea", "strokeWidth": 4,
        "x": "=pick(i, [260, 640, 1020])", "repeat": 3 },
      { "id": "label", "type": "text", "y": 630, "font": "JetBrains Mono", "fontSize": 22, "fill": "#8a857a",
        "text": "${pick(i, ['\"top-left\"', '\"center\"', '\"bottom-right\"'])}", "x": "=pick(i, [260, 640, 1020])", "repeat": 3 }
    ]
  }]
}
```

### Percentages

Any numeric field accepts a percentage string. What it is a percentage *of* depends on the field:

| field | `"50%"` means |
|---|---|
| `x`, `width`, `maxWidth` | half the parent's width |
| `y`, `height` | half the parent's height |
| `fontSize` | half the parent's height |
| `cornerRadius` | half the shorter side of the layer (so `"50%"` is a pill or a circle) |

Inside a group, the parent is the group's box, so `"width": "100%"` on a child fills the group, not the
canvas. In [expressions](https://vidmake.app/docs/expressions.md), `w`/`h` are the composition size and `pw`/`ph` the parent
size: `"x": "=pw - 40"` hugs the right edge of whatever contains the layer.

## Transforms

| field | default | notes |
|---|---|---|
| `rotation` | `0` | Degrees, clockwise, around the anchor. |
| `skewX`, `skewY` | `0` | Shear in degrees around the anchor, animatable. `skewX: -12` leans the top to the right, like italic type. |
| `scale` | `1` | Uniform scale around the anchor. Multiplies `scaleX`/`scaleY`. |
| `scaleX`, `scaleY` | `1` | Per-axis scale. Negative values mirror. |
| `opacity` | `1` | `0..1`, multiplied with every ancestor's opacity. |
| `rotateX`, `rotateY` | `0` | 3D tilt in degrees around the anchor: positive `rotateX` tips the top edge away, positive `rotateY` the right edge. |
| `perspective` | `1000` | Camera distance in px for the tilt. Smaller is more dramatic. |

The layer is placed in this order: move the anchor to `x`/`y`, rotate, skew, scale, then draw the box offset
by the anchor. Transforms never change the layer's measured `width`/`height` (what [layouts](https://vidmake.app/docs/groups.md#layout)
use); they only change where pixels land, which `vidmake inspect` reports as the `BBOX` column.

```console
$ vidmake inspect layers-anchor.json -t 1s -l card-tl
Frame 30 (1.00s) of `anchor` (1280x720), 1 visible layer(s), drawn bottom→top:

ID                       TYPE            X        Y       W       H    ROT  SCALE  OPAC  BBOX [x0,y0,x1,y1]          NOTES
card-tl                  rect        260.0    330.0   180.0   110.0   90.0   1.00  1.00  [150,330,260,510]
```

`rotateX`/`rotateY` render the finished layer flat, then project it in perspective, so they work on any
layer, including a whole group:

**Demo: rotateX and rotateY tilt a flat card in perspective** (rendered video: https://vidmake.app/media/layers-tilt.mp4)

```json
{
  "fonts": [
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }
  ],
  "compositions": [{
    "id": "tilt", "description": "rotateX and rotateY tilt a flat card in perspective",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s",
    "background": { "type": "radial", "center": [0.5, 0.45], "radius": 0.8, "stops": ["#f4f1ea", "#e9e4d8"] },
    "layers": [
      { "id": "card", "type": "group", "width": 520, "height": 320, "perspective": 900,
        "rotateY": "=28 * sin(t * pi / 2)", "rotateX": "=12 * cos(t * pi / 2)",
        "shadow": { "color": "#16141244", "blur": 30, "y": 24 },
        "children": [
          { "id": "face", "type": "rect", "cornerRadius": 6, "fill": { "type": "linear", "angle": 135, "stops": ["#4a4640", "#161412"] } },
          { "id": "title", "type": "text", "text": "Perspective", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 72,
            "letterSpacing": -3, "fill": "#f4f1ea", "y": "44%" },
          { "id": "sub", "type": "text", "text": "rotateX · rotateY", "font": "JetBrains Mono", "fontSize": 20, "letterSpacing": 2.4,
            "uppercase": true, "fill": "#8a857a", "y": "68%" }
        ] }
    ]
  }]
}
```

## Fill and stroke

| field | default | notes |
|---|---|---|
| `fill` | white | A color or gradient ([paints](https://vidmake.app/docs/colors.md)). `null` turns it off. |
| `stroke` | none | Outline paint. On text the outline is drawn behind the fill. |
| `strokeWidth` | `2` (`8` for `line` and open `arc`) | In px, animatable. The stroke is centered on the outline, so half of it lies outside the box. |
| `dash` | solid | Dash pattern in px, e.g. `[20, 10]`. |
| `lineCap` | `round` | `round`, `butt` or `square`: the ends of open strokes and dashes. |
| `cornerRadius` | `0` | Rounds `rect`, `image`, `video`, a text `background` and waveform bars. |

Shapes, text and particles get a white fill when you set neither `fill` nor `stroke`. A `line` and an
open `arc` are strokes by nature: if you give them only a `fill`, that paint becomes the stroke.
Gradient coordinates are relative to the layer's box, so a gradient follows the layer as it moves.

## Shadow and filters

| field | default | notes |
|---|---|---|
| `shadow` | none | `{ "color": "#0008", "blur": 20, "x": 0, "y": 8 }`. Defaults: color `rgba(0,0,0,0.5)`, blur `10`, x `0`, y `4`. Every part is animatable. |
| `blur` | `0` | Gaussian blur radius in px. |
| `brightness` | `1` | Multiplies the color: `0.5` darkens, `1.3` brightens. |
| `saturation` | `1` | `0` is grayscale, above `1` boosts color. |
| `blendMode` | `normal` | How the layer combines with what is under it, see below. |

The shadow is cast by the layer's actual pixels (text glyphs, a star's points, the visible part of an
image), not by its box. Filters apply to the finished layer, so blurring a group blurs everything in it.

**Demo: Stroke and dash, shadow, saturation and blur on four layers** (rendered video: https://vidmake.app/media/layers-style.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "style", "description": "Stroke and dash, shadow, saturation and blur on four layers",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "dashed", "type": "rect", "x": 200, "y": 330, "width": 200, "height": 200, "cornerRadius": 6, "fill": null,
        "stroke": "#161412", "strokeWidth": 6, "dash": [26, 14], "lineCap": "butt", "rotation": "=t * 22.5" },
      { "id": "lifted", "type": "rect", "x": 493, "y": "=330 - 14 * sin(t * pi / 2)", "width": 200, "height": 200,
        "cornerRadius": 6, "fill": "#fbf9f4", "stroke": "#d8d1c1", "strokeWidth": 1.5,
        "shadow": { "color": "#16141255", "blur": "=12 + 18 * max(0, sin(t * pi / 2))", "y": "=8 + 22 * max(0, sin(t * pi / 2))" } },
      { "id": "logo", "type": "image", "src": "assets/logo.svg", "x": 786, "y": 330, "width": 220,
        "saturation": [[0, 0], ["2s", 1.4, "easeInOutSine"], ["4s", 0, "easeInOutSine"]] },
      { "id": "blurred", "type": "star", "x": 1080, "y": 330, "width": 200, "fill": "#161412",
        "blur": [[0, 0], ["2s", 14, "easeInOutSine"], ["4s", 0, "easeInOutSine"]] },
      { "id": "label", "type": "text", "y": 520, "font": "JetBrains Mono", "fontSize": 20, "letterSpacing": 2.4, "uppercase": true,
        "fill": "#8a857a", "x": "=pick(i, [200, 493, 786, 1080])", "repeat": 4,
        "text": "${pick(i, ['dash', 'shadow', 'saturation', 'blur'])}" }
    ]
  }]
}
```

`blendMode` takes `normal`, `multiply`, `screen`, `overlay`, `darken`, `lighten`, `color-dodge`,
`color-burn`, `hard-light`, `soft-light`, `difference`, `exclusion` and `add` (camelCase spellings and
`plus` are accepted too). `screen` and `add` are the usual choices for light leaks and glows over video;
`multiply` for shadows and paper textures.

Glow, film grain, chromatic aberration and masks are covered in [Effects](https://vidmake.app/docs/effects.md) and
[Masks](https://vidmake.app/docs/masks.md).

## Presets and transitions

| field | notes |
|---|---|
| `enter` | Animation played when the layer appears: `"fadeUp"`, `"pop"`, `{ "type": "wipeRight", "duration": "0.4s" }`... |
| `exit` | Animation played as the layer ends. |
| `transition` | Only on children of a `series` group: how this child hands over to the next one. |

Presets combine with your own animation, so a layer can `pop` in while its `y` also floats. See
[Presets](https://vidmake.app/docs/presets.md) and [Series and transitions](https://vidmake.app/docs/series.md). Two more fields reshape a layer
rather than style it: [`repeat`](https://vidmake.app/docs/repeat.md) stamps out copies, and [`attach`](https://vidmake.app/docs/attach.md) pins a
layer to a path's tip or after a text's last character.

## Animating any field

Every numeric field on this page (and every color) accepts a constant, keyframes, a tween, a spring or an
expression:

```json
"x": [[0, 100], ["1s", 500, "easeOutCubic"]],
"opacity": { "from": 0, "to": 1, "duration": "0.5s" },
"rotation": "=t * 90",
"fill": [[0, "#c92a26"], ["2s", "#1f5fb0"]]
```

See [Animation](https://vidmake.app/docs/animation.md) for the forms and [Expressions](https://vidmake.app/docs/expressions.md) for the `=` language.
A few fields are plain values that cannot animate: `dash`, `lineCap`, `blendMode`, `anchor`, `visible`,
and type-specific switches like `sides`, `lineHeight` or `playbackRate`; each page says which.

## Draw order

Layers draw in array order: the first one is at the bottom, the last one on top. There is no
`zIndex`; to bring a layer forward, move it later in the array (`vidmake add --index n` inserts at a
position). A group draws all of its children at the group's place in its parent's order, so
everything inside a group sits above the layers before the group and below the layers after it.

`vidmake inspect` lists visible layers bottom to top, indented by depth, which makes the stacking easy to
check:

```console
$ vidmake inspect groups-card.json -t 2s
Frame 60 (2.00s) of `card` (1280x720), 6 visible layer(s), drawn bottom→top:

ID                       TYPE            X        Y       W       H    ROT  SCALE  OPAC  BBOX [x0,y0,x1,y1]          NOTES
card                     group       640.0    360.0   560.0   300.0    0.0   1.00  1.00  [360,210,920,510]           
  bg                     rect        280.0    150.0   560.0   300.0    0.0   1.00  1.00  [360,210,920,510]           
  dot                    ellipse      64.0     64.0    40.0    40.0    0.0   1.00  1.00  [404,254,444,294]           
  title                  text         48.0    150.0   285.9   115.2    0.0   1.00  1.00  [408,302,694,418]           "Group"
  sub                    text         50.0    228.0   265.8    28.8    0.0   1.00  1.00  [410,424,676,452]           "0,0 is the card's top-left"
  shine                  rect        645.1    150.0    90.0   600.0   20.0   1.00  0.06  [860,63,1150,657]
```

> [!AGENT]
> When something is missing from a frame, run `vidmake inspect project.json -t <time>` before changing
> anything: a layer that is not listed is outside its time window (or `visible: false`), a layer with
> `OPAC` near 0 is faded out, and a `BBOX` outside `0..width`/`0..height` is off-canvas. `vidmake validate`
> flags the last two as `invisible` and `offCanvas`.
