# Effects

> Shadows, blur, glow, grain, chromatic aberration, brightness and saturation, 3D tilt with perspective, and composition-wide motion blur and film grain. All animatable, all usable on groups.

Effects are per-layer fields. Each one renders the layer to its own buffer, processes it, and
composites the result, so they work the same on a rectangle, a text, a video or a whole
[group](https://vidmake.app/docs/groups.md). Every effect value is [animatable](https://vidmake.app/docs/animation.md): keyframes, tweens, springs and
[expressions](https://vidmake.app/docs/expressions.md) (including [audio-reactive](https://vidmake.app/docs/audio-reactive.md) ones like
`"chromaticAberration": "=8 * beat"`).

| field | default | what it does |
|---|---|---|
| [`shadow`](#shadow) | none | a blurred, offset, colored copy of the layer's silhouette behind it |
| [`blur`](#blur) | 0 | gaussian-like blur, radius in px |
| [`glow`](#glow) | none | an additive blurred halo |
| [`brightness`](#brightness-and-saturation) | 1 | multiplies the colors: 0 is black, 1 unchanged |
| [`saturation`](#brightness-and-saturation) | 1 | 0 is grayscale, 1 unchanged, above 1 more vivid |
| [`chromaticAberration`](#chromatic-aberration) | 0 | RGB split in px |
| [`grain`](#grain) | 0 | film grain on the layer, 0..1 |
| [`rotateX`, `rotateY`, `perspective`](#3d-tilt) | 0, 0, 1000 | 3D tilt around the anchor |

On the composition: [`motionBlur`](#motion-blur) and [`grain`](#grain).

## Shadow

```json
"shadow": { "color": "#000a", "blur": 30, "x": 0, "y": 18 }
```

| field | default | notes |
|---|---|---|
| `color` | `rgba(0,0,0,0.5)` | any [color](https://vidmake.app/docs/colors.md); its alpha sets the shadow's strength |
| `blur` | 10 | softness, in px |
| `x`, `y` | 0, 4 | offset in px; positive `y` is down |

All four are animatable, so a card that lifts can cast a larger, softer, further shadow:

**Demo: shadow follows the card as it floats; glow halos a ring in its own color and a word in a chosen one** (rendered video: https://vidmake.app/media/effects-shadow-glow.mp4)

```json
{
  "fonts": [
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }
  ],
  "compositions": [{
    "id": "light", "description": "shadow follows the card as it floats; glow halos a ring in its own color and a word in a chosen one",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#1d1b18",
    "layers": [
      { "id": "card", "type": "rect", "x": 260, "width": 260, "height": 300, "cornerRadius": 4, "fill": "#efebe2",
        "y": "=350 - 18 * sin(t * pi)",
        "shadow": { "color": "#000", "blur": "=26 + 16 * sin(t * pi)", "x": 0, "y": "=20 + 18 * sin(t * pi)" } },
      { "id": "ring", "type": "arc", "x": 640, "y": 350, "width": 230, "strokeWidth": 12, "stroke": "#efebe2",
        "endAngle": 360, "glow": { "radius": 28, "strength": "=1.2 + 0.8 * sin(t * pi)" } },
      { "id": "word", "type": "text", "text": "glow", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 140, "letterSpacing": -6,
        "fill": "#efebe2", "x": 1020, "y": 340, "glow": { "radius": 30, "strength": 2, "color": "#f05a4e" } },
      { "id": "label", "type": "text", "text": "${pick(i, ['SHADOW', 'GLOW', 'GLOW + COLOR'])}", "font": "JetBrains Mono",
        "fontSize": 18, "letterSpacing": 2.2, "fill": "#8f8a7f", "x": 640, "y": 580, "repeat": { "count": 3, "layout": "row", "spacing": 380 } }
    ]
  }]
}
```

The shadow is the layer's own shape, not its box: text casts a text-shaped shadow, a PNG with
transparency casts the shape of its opaque pixels, and a group casts one shadow for all its children
together. The shadow takes the layer's `opacity` and `blendMode`.

## Blur

```json
"blur": 12
"blur": { "from": 30, "to": 0, "duration": "0.6s", "ease": "easeOutCubic" }
```

The radius is in composition pixels and scales with `--scale`, so a draft render looks the same as the
final. Blur is also what the [`blur` preset](https://vidmake.app/docs/presets.md) animates, and a blurred [mask](https://vidmake.app/docs/masks.md)
gives a feathered matte.

## Glow

A glow is a blurred copy of the layer added (with an additive blend) underneath it, so it brightens
whatever is behind and reads as light rather than shadow:

```json
"glow": 20
"glow": { "radius": 28, "strength": 2, "color": "#f05a4e" }
```

| field | default | notes |
|---|---|---|
| `radius` | 20 | blur radius of the halo, in px. A bare number is the radius |
| `strength` | 1 | brightness of the halo; values above 1 stack extra passes (2 is twice as bright) |
| `color` | the layer's own colors | tint the halo one color instead |

Glow works best on dark backgrounds, where the additive blend has room to brighten. On a light
background a `shadow` with a light `color` and `y: 0` gives a softer halo.

## Brightness and saturation

```json
"brightness": 0.6
"saturation": 0
```

`brightness` multiplies the red, green and blue channels: `0.6` darkens a background video behind
titles, `0` makes the layer black, and values above 1 brighten (clipping at white). `saturation` mixes
towards the luminance: `0` is grayscale, `1` unchanged, `1.5` more saturated. Both apply before the
other effects.

## Chromatic aberration

```json
"chromaticAberration": 10
"chromaticAberration": "=12 * beat"
```

Shifts the red channel left and the blue channel right by this many pixels (negative values swap the
directions), for a lens or glitch look. It's most visible on high-contrast edges.

## Grain

```json
"grain": 0.35
```

On a layer, `grain` adds animated noise (0..1) to that layer only. The pattern changes every frame and
differs between layers. On the composition, `"grain": 0.08` covers the whole finished frame, which is
the usual way to make clean vector motion feel filmic:

```json
{ "id": "main", "width": 1920, "height": 1080, "grain": 0.08, "layers": [] }
```

The demo below runs the same clip through each filter. The clip has sound, so every copy is `muted`:

**Demo: The same clip six times: original, blur, brightness, saturation, chromaticAberration and grain** (rendered video: https://vidmake.app/media/effects-filters.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "filters", "description": "The same clip six times: original, blur, brightness, saturation, chromaticAberration and grain",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "orig", "type": "video", "src": "assets/clip.mp4", "muted": true, "x": 240, "y": 210, "width": 340, "height": 191, "cornerRadius": 2 },
      { "id": "blur", "type": "video", "src": "assets/clip.mp4", "muted": true, "x": 640, "y": 210, "width": 340, "height": 191, "cornerRadius": 2,
        "blur": "=6 + 6 * sin(t * pi)" },
      { "id": "bright", "type": "video", "src": "assets/clip.mp4", "muted": true, "x": 1040, "y": 210, "width": 340, "height": 191, "cornerRadius": 2,
        "brightness": 0.45 },
      { "id": "sat", "type": "video", "src": "assets/clip.mp4", "muted": true, "x": 240, "y": 480, "width": 340, "height": 191, "cornerRadius": 2,
        "saturation": "=0.5 + 0.5 * cos(t * pi)" },
      { "id": "ca", "type": "video", "src": "assets/clip.mp4", "muted": true, "x": 640, "y": 480, "width": 340, "height": 191, "cornerRadius": 2,
        "chromaticAberration": 10 },
      { "id": "grain", "type": "video", "src": "assets/clip.mp4", "muted": true, "x": 1040, "y": 480, "width": 340, "height": 191, "cornerRadius": 2,
        "grain": 0.35 },
      { "id": "label", "type": "text", "font": "JetBrains Mono", "fontSize": 17, "letterSpacing": 1.4, "fill": "#8a857a", "x": 640, "y": 470,
        "text": "${pad(i + 1, 2)}  ${pick(i, ['original', 'blur', 'brightness 0.45', 'saturation', 'chromaticAberration 10', 'grain 0.35'])}",
        "repeat": { "count": 6, "layout": "grid", "cols": 3, "spacing": [400, 270] } }
    ]
  }]
}
```

## 3D tilt

`rotateX` and `rotateY` tilt the layer in 3D, around its [anchor](https://vidmake.app/docs/layers.md), seen through a camera
`perspective` pixels away:

| field | default | notes |
|---|---|---|
| `rotateX` | 0 | degrees around the horizontal axis; positive tips the **top** edge away |
| `rotateY` | 0 | degrees around the vertical axis; positive turns the **right** edge away |
| `perspective` | 1000 | camera distance in px; smaller is a stronger, wide-angle effect |

```json
"rotateX": { "from": 80, "to": 0, "duration": "1.2s", "ease": "easeOutBack" }
"rotateY": "=35 * sin(t * pi)"
```

**Demo: 3D tilt on groups: a flip-up entrance with rotateX, a swinging rotateY, and a closer camera** (rendered video: https://vidmake.app/media/effects-3d.mp4)

```json
{
  "fonts": [{ "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }],
  "compositions": [{
    "id": "tilt", "description": "3D tilt on groups: a flip-up entrance with rotateX, a swinging rotateY, and a closer camera",
    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",
    "layers": [
      { "id": "flip", "type": "group", "x": 240, "width": 300, "height": 380, "anchor": "bottom", "y": 550,
        "rotateX": { "from": 80, "to": 0, "duration": "1.2s", "ease": "easeOutBack" }, "opacity": { "from": 0, "to": 1, "duration": "0.4s" },
        "children": [
          { "id": "flip-bg", "type": "rect", "cornerRadius": 4, "fill": "#161412" },
          { "id": "flip-t", "type": "text", "text": "rotateX", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 42, "letterSpacing": -2, "fill": "#f4f1ea" } ] },
      { "id": "swing", "type": "group", "x": 640, "y": 360, "width": 300, "height": 380, "rotateY": "=35 * sin(t * pi)",
        "children": [
          { "id": "swing-bg", "type": "rect", "cornerRadius": 4, "fill": { "type": "linear", "angle": 180, "stops": ["#fbf9f4", "#e9e4d8"] }, "stroke": "#161412" },
          { "id": "swing-t", "type": "text", "text": "rotateY", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 42, "letterSpacing": -2, "fill": "#161412" } ] },
      { "id": "near", "type": "group", "x": 1040, "y": 360, "width": 300, "height": 380, "rotateY": "=35 * sin(t * pi)", "perspective": 400,
        "children": [
          { "id": "near-bg", "type": "rect", "cornerRadius": 4, "fill": { "type": "linear", "angle": 180, "stops": ["#fbf9f4", "#e9e4d8"] }, "stroke": "#161412" },
          { "id": "near-t", "type": "text", "text": "perspective\n400", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 42, "letterSpacing": -2, "lineHeight": 0.95, "fill": "#c92a26" } ] }
    ]
  }]
}
```

The tilt is applied to the rendered layer as a flat card: a [group](https://vidmake.app/docs/groups.md) tilts as one
plane with everything in it, which is the natural way to build card flips and "3D" UI shots. There is no
depth sorting between layers; layer order still decides what is on top. For a card that flips up from
its bottom edge, set `"anchor": "bottom"` as in the first card above.

## Motion blur

Fast motion looks choppy at 30 fps. A real camera smears it, and so can vidmake: set `motionBlur` on the
composition and every frame is rendered several times at sub-frame times and averaged.

```json
{ "id": "main", "width": 1280, "height": 720, "motionBlur": { "samples": 12, "shutter": 1 }, "layers": [] }
```

| field | default | notes |
|---|---|---|
| `samples` | 6 | sub-frames per frame. `1` turns motion blur off. Render time grows roughly in proportion |
| `shutter` | 0.5 | how long the virtual shutter stays open, in frames. The samples are spread from `shutter` frames before the frame up to the frame itself |

Set `"motionBlur": false` on a layer to render it at the exact frame time even when the composition
has motion blur. It applies to the layer's children too. Use it for things that must stay crisp:
UI, logos, small text that would smear, or a layer that already uses `blur`.

**Demo: Composition motion blur on fast motion; the bottom ball opts out with motionBlur: false** (rendered video: https://vidmake.app/media/effects-motion-blur.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "blur", "description": "Composition motion blur on fast motion; the bottom ball opts out with motionBlur: false",
    "width": 1280, "height": 720, "fps": 30, "duration": "3s", "background": "#f4f1ea",
    "motionBlur": { "samples": 12, "shutter": 1 },
    "layers": [
      { "id": "bar", "type": "rect", "x": 640, "y": 230, "width": 360, "height": 22, "cornerRadius": 2, "fill": "#161412",
        "rotation": { "from": 0, "to": 720, "duration": "3s", "ease": "easeInOutCubic" } },
      { "id": "blurred", "type": "ellipse", "width": 70, "y": 450, "fill": "#161412",
        "x": { "keys": [[0, 220], ["0.75s", 1060]], "ease": "easeInOutQuad", "repeat": "pingpong" } },
      { "id": "sharp", "type": "ellipse", "width": 70, "y": 570, "fill": "#c92a26", "motionBlur": false,
        "x": { "keys": [[0, 220], ["0.75s", 1060]], "ease": "easeInOutQuad", "repeat": "pingpong" } },
      { "id": "count", "type": "text", "text": "FRAME ${pad(f, 2)}", "font": "JetBrains Mono", "fontSize": 18, "letterSpacing": 2.2,
        "fill": "#8a857a", "x": 1180, "y": 60, "anchor": "right" }
    ]
  }]
}
```

The bar and the top ball are blurred along their motion; the bottom ball has `"motionBlur": false`.
Text written with `${...}` (the frame counter) is always evaluated at the whole frame, so it stays sharp.

> [!TIP]
> Motion blur multiplies render time. Iterate with `vidmake render --draft` (which skips motion blur and
> renders at half size) and keep the full-quality render for last. `inspect` and `trace` always report
> the exact frame, unaffected by the shutter.

## Effects on groups

Every effect works on a [group](https://vidmake.app/docs/groups.md), and then applies to the group's rendered result: blur a
whole scene for a transition, darken everything behind a title with `brightness`, put one shadow under a
card made of many layers, or tilt a whole layout. Wrapping layers in a group just to apply an effect is
normal and cheap to write:

```json
{ "id": "scene", "type": "group", "blur": { "from": 0, "to": 20, "start": "4s", "duration": "0.5s" },
  "brightness": { "from": 1, "to": 0.4, "start": "4s", "duration": "0.5s" }, "children": [] }
```

> [!NOTE]
> A group that needs its own buffer (any effect, `opacity` below 1, `clip`, a `mask` or a `blendMode`)
> composites its children together first. Their [blend modes](https://vidmake.app/docs/masks.md#blend-modes) then mix with each
> other inside the group, not with what is behind the group.

## Order of operations

For each layer, vidmake draws the content, then applies `brightness`/`saturation`, `blur`,
`chromaticAberration`, `grain` and the 3D tilt, in that order. The result is composited with its glow
underneath, then its shadow underneath that, both following the blurred and tilted shape. Opacity, any
`mask` and the `blendMode` apply when compositing.

> [!AGENT]
> Effects don't change a layer's box, so `inspect` bounding boxes ignore blur, glow and shadow. To
> judge them, look: `vidmake still project.json -t 2s -o f.png` renders one full-resolution frame,
> with motion blur, exactly as the final render will.
