vidmake v0.2.1
Download

Docs/StylePage 33 / 45

Masks and blend modes

Track mattes with mask and maskMode (alpha, inverted, luma), video through text, animated wipes and reveals, and every blendMode.

View .md Ask Claude Ask ChatGPT

A mask (a track matte, in After Effects terms) shows a layer only where another shape is. A blend mode changes how a layer's colors combine with what's behind it. Both are per-layer fields and work on every layer type, including groups.

#Masks

mask takes a complete layer definition. That layer is never drawn; instead, the masked layer is visible only where the mask layer would be opaque:

json
{ "id": "clip", "type": "video", "src": "assets/clip.mp4", "width": "100%", "height": "100%", "muted": true,  "mask": { "type": "text", "text": "VIDMAKE", "font": "Schibsted Grotesk", "fontWeight": 900, "fontSize": 220 } }
00:00.0 · f 000
Video through text: a text layer used as the alpha matte of a videoDownload
masks-text-video.jsonjson
{  "fonts": [{ "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }],  "compositions": [{    "id": "through", "description": "Video through text: a text layer used as the alpha matte of a video",    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",    "layers": [      { "id": "outline", "type": "text", "text": "VIDMAKE", "font": "Schibsted Grotesk", "fontWeight": 900, "fontSize": 220, "letterSpacing": -9,        "fill": null, "stroke": "#d8d1c1", "strokeWidth": 3 },      { "id": "clip", "type": "video", "src": "assets/clip.mp4", "muted": true, "width": "100%", "height": "100%", "saturation": 0.75,        "mask": { "type": "text", "text": "VIDMAKE", "font": "Schibsted Grotesk", "fontWeight": 900, "fontSize": 220, "letterSpacing": -9,                  "enter": { "type": "wipeRight", "duration": "1.2s", "ease": "easeInOutCubic" }, "exit": "fade" } }    ]  }]}

The mask can be any layer type: text, a shape, an image with transparency, a video, a gradient, a path, even a group of several shapes. It can have its own animation, presets and effects. In that demo the text mask has a wipeRight entrance, so the video is revealed letter by letter, and a dim outline text (a normal layer) shows where the letters will be.

#Where a mask sits

The mask layer is placed and timed as if it were a sibling of the masked layer:

  • its x, y, width, height and percentages are in the masked layer's parent coordinates, not relative to the masked layer;
  • its start and its animation times are relative to the parent too, not to the masked layer's start;
  • it defaults to the center of the parent, like any layer.

So if the masked layer moves, the mask stays where it is: the layer slides "behind" a fixed window. To move a layer and its mask together, wrap the layer in a group, define the mask inside the group, and move the group. The same goes for repeat: copies of a masked layer share one mask, so repeat a group that contains the masked layer instead.

Warning

If the masked layer has "start": "2s", its mask still starts at 0. That rarely matters for a still mask, but an animated one (a wipe, a growing circle) has finished before the layer appears. Give the mask the same start, or put both in a group that starts at 2 s.

#Mask modes

maskMode chooses what part of the mask counts:

maskModethe layer shows where the mask is...
alpha (default)opaque. Soft or semi-transparent edges give partial visibility
alphaInverted (aliases invert, inverted)transparent: a cut-out
lumabright: white shows the layer fully, black and transparent hide it, grays in between
lumaInverteddark: black (and transparent) areas show the layer, white hides it
00:00.0 · f 000
maskMode: alpha and alphaInverted use the matte's opacity, luma and lumaInverted its brightnessDownload
masks-modes.jsonjson
{  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],  "compositions": [{    "id": "modes", "description": "maskMode: alpha and alphaInverted use the matte's opacity, luma and lumaInverted its brightness",    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",    "layers": [      { "id": "alpha", "type": "rect", "x": 200, "width": 240, "height": 300, "cornerRadius": 2,        "fill": { "type": "linear", "angle": 160, "stops": ["#4a4640", "#161412"] },        "mask": { "type": "star", "x": 200, "width": "=200 + 30 * sin(t * pi)", "height": "=200 + 30 * sin(t * pi)", "rotation": "=t * 30" } },      { "id": "alphaInverted", "type": "rect", "x": 493, "width": 240, "height": 300, "cornerRadius": 2, "maskMode": "alphaInverted",        "fill": { "type": "linear", "angle": 160, "stops": ["#4a4640", "#161412"] },        "mask": { "type": "star", "x": 493, "width": "=200 + 30 * sin(t * pi)", "height": "=200 + 30 * sin(t * pi)", "rotation": "=t * 30" } },      { "id": "luma", "type": "rect", "x": 786, "width": 240, "height": 300, "cornerRadius": 2, "maskMode": "luma",        "fill": { "type": "linear", "angle": 160, "stops": ["#1f5fb0", "#161412"] },        "mask": { "type": "rect", "x": 786, "width": 240, "height": 300,                  "fill": { "type": "linear", "angle": { "from": 0, "to": 360, "duration": "4s", "ease": "linear" }, "stops": ["#fff", "#000"] } } },      { "id": "lumaInverted", "type": "rect", "x": 1080, "width": 240, "height": 300, "cornerRadius": 2, "maskMode": "lumaInverted",        "fill": { "type": "linear", "angle": 160, "stops": ["#1f5fb0", "#161412"] },        "mask": { "type": "rect", "x": 1080, "width": 240, "height": 300,                  "fill": { "type": "linear", "angle": { "from": 0, "to": 360, "duration": "4s", "ease": "linear" }, "stops": ["#fff", "#000"] } } },      { "id": "label", "type": "text", "text": "${pick(i, ['alpha', 'alphaInverted', 'luma', 'lumaInverted'])}", "font": "JetBrains Mono",        "fontSize": 18, "letterSpacing": 1.6, "fill": "#8a857a", "x": 640, "y": 560, "repeat": { "count": 4, "layout": "row", "spacing": 293 } }    ]  }]}

Each tile in that demo has its own mask with an x that matches the tile's x, because masks are positioned in the parent's coordinates. The alpha tiles use a star; the luma tiles use a white-to-black gradient whose angle turns, so the visible part sweeps around.

maskMode without mask is a validation error.

#Wipes and reveals

Animate the mask to reveal a layer or a whole scene. An iris wipe is a circle mask that scales up:

00:00.0 · f 000
An iris wipe: the second scene is masked by a circle that grows from the centerDownload
masks-wipe.jsonjson
{  "fonts": [    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk-Italic.ttf" }  ],  "compositions": [{    "id": "iris", "description": "An iris wipe: the second scene is masked by a circle that grows from the center",    "width": 1280, "height": 720, "fps": 30, "duration": "4s",    "layers": [      { "id": "before", "type": "group", "children": [        { "id": "before-bg", "type": "rect", "fill": "#f4f1ea" },        { "id": "before-t", "type": "text", "text": "before", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 170, "letterSpacing": -7, "fill": "#161412" } ] },      { "id": "after", "type": "group",        "mask": { "type": "ellipse", "width": 100, "scale": [[0, 0], ["0.8s", 0], ["2s", 15, "easeInOutCubic"], ["2.8s", 15], ["3.8s", 0, "easeInOutCubic"]] },        "children": [          { "id": "after-bg", "type": "rect", "fill": "#161412" },          { "id": "after-t", "type": "text", "text": "after", "font": "Schibsted Grotesk", "italic": true, "fontWeight": 400, "fontSize": 190, "letterSpacing": -6, "fill": "#f4f1ea" } ] }    ]  }]}
json
"mask": { "type": "ellipse", "width": 100,          "scale": [[0, 0], ["0.8s", 0], ["2s", 15, "easeInOutCubic"], ["2.8s", 15], ["3.8s", 0, "easeInOutCubic"]] }

The demo animates scale rather than width: an ellipse with only width set is made square from its frame-0 value (see which fields animate).

Other reveals use the same idea:

revealmask
linear wipea rect whose width grows from 0 with "anchor": "left", or the wipe* presets on the mask
diagonal wipea large rect with rotation: 30 sliding across with x keyframes
soft wipeany of the above with "blur": 40 on the mask, for a feathered edge
text reveala text mask with a typewriter or stagger entrance
spotlightan ellipse mask with blur following an expression path
shape morpha star mask animating innerRadius

For simple directional reveals on a single layer, the wipeLeft|Right|Up|Down presets are shorter; reach for a mask when the reveal has a custom shape or must cover several layers at once (put the mask on a group).

Tip

blur on the mask layer feathers the matte: "mask": { "type": "rect", ..., "blur": 30 } gives a soft edge. Blur, opacity and other effects on the mask all change the matte.

#Blend modes

blendMode sets how the layer's colors mix with the pixels beneath it:

blendModeeffect
normaldefault: paints over what's below
multiplydarkens; white disappears. Good for shadows, paper textures, ink
screenlightens; black disappears. Good for light leaks, glows, flares on black
overlaymultiply on dark areas and screen on light ones: adds contrast
darkenkeeps the darker of the two colors per channel
lightenkeeps the lighter of the two colors per channel
color-dodge (alias colorDodge)brightens the backdrop strongly, for hot highlights
color-burn (alias colorBurn)darkens the backdrop strongly, with saturated shadows
hard-light (alias hardLight)like overlay, keyed on the layer instead of the backdrop
soft-light (alias softLight)a gentle version of hard-light
differencethe absolute difference: inverts where the layer is bright
exclusionlike difference, lower contrast
add (alias plus)adds the colors together, clipping at white
00:00.0 · f 000
Every blendMode: the same red disc composited over the same backdropDownload
json
{ "id": "leak", "type": "image", "src": "light-leak.jpg", "width": "100%", "height": "100%", "blendMode": "screen", "opacity": 0.7 }

blendMode can't be animated; fade a blended layer's opacity instead.

#Blending inside groups

A layer blends with whatever has already been drawn into the same buffer. Most of the time that's the frame below it. But a group that needs its own buffer (because it has an effect, opacity below 1, clip, a mask or a blendMode of its own; components clip by default) composites its children first: inside it, children blend only with their siblings, and the group's result is then composited normally.

That's why each cell in the demo above contains its own backdrop: every cell is a clipped component, so a disc blended against the page background behind it would see nothing. To blend a group's content with the scene behind it, give the group the blendMode.

For agents

Masks and blend modes don't change a layer's reported box: inspect still shows the full layer. Check them with vidmake still or vidmake storyboard, and remember the mask is positioned in the parent's coordinates when the result looks shifted.