Home · Lab · Roto & Masks

R2 Grading inside a shape (Keymix)

Switch between graded and original by a mask

Roto & Masks · ~5 min · Free

1 The idea

Want just one hill brighter? Make a graded version (A) and Keymix it with the original (B) through a shape mask: A inside the mask, B outside, a soft mix along the feather.

Keymix differs from Merge over: it ignores A’s alpha and uses only the mask, which suits area grades.

Keymix: out = A · m + B · (1 − m)

2 Hands-on in the mini compositor

SkyVFX mini compositor · R2640×360 · float · 1001

3 Deep dive

Keymix, pixel by pixel

Keymix works like this: out = A·m + B·(1 − m), where m is the mask alpha times mix. Inside the mask (m = 1) you get A, outside (m = 0) you get B, and in the feather band a blend.

Example: a pixel reads 0.2. A Grade with white 1.6 makes it 0.32. Here is what each mask level gives.

Mask (m)MathsResult
0 (outside)0.32·0 + 0.2·10.20
0.5 (mid feather)0.32·0.5 + 0.2·0.50.26
1 (inside)0.32·1 + 0.2·00.32

Why not a Merge over?

Merge over decides with A’s alpha. Most plates have an alpha of 1 across the whole frame, so putting the graded plate over the original gives a fully graded frame. The shape does nothing.

Keymix ignores A’s alpha completely and listens only to the mask. That makes it the tool for any “change only this area” job: grades, despill, other fixes.

  1. 1Plate → B
  2. 2Plate → Grade → A
  3. 3Roto → mask
  4. 4Keymix

Building it from Merges, and the seam

Keymix equals three Merges: a stencil keeps the plate outside the roto, a mask keeps the graded image inside it, and a plus adds the two pieces. (Merge stencil keeps B where A’s alpha isn’t; Merge mask keeps B only where A’s alpha is. Here A is the roto. Both are covered fully in R3.) Use over instead of plus for the last step and a dark seam appears along the feather.

Why: the graded piece (the over’s A input) already has an alpha of m, so over multiplies B by (1 − m) a second time. At mid feather in the example above you get 0.16 + 0.05 = 0.21 instead of 0.26, so the feather band goes dark.

Pieces cut by matching masks go back together with plus, not over

In a real shot

Lifting one hill, bringing a face up a little, combining two despills (strong at the edge, gentle in the core), joining several keys region by region: all of these are a Keymix with a soft mask.

The mask must follow what you are fixing for the whole shot. If the camera moves, track the roto. A mask that drifts off the object shows up as a patch of light sliding around.

4 In real work

In Nuke

  1. Plate into B, the Grade branch into A, the Roto into the Keymix mask input.
  2. Use the Keymix mix to scale the whole change instead of re-tuning the Grade.
  3. For a single node you can plug the Roto straight into the Grade’s own mask input. Keymix is clearer when the change is a whole branch of nodes.
  4. A large or out-of-frame roto in a Merge’s A input can bloat the bbox; set that Merge’s bbox to B.
  5. Check with a Merge (difference) against the original plate: outside the mask must be pure black.

Common mistakes → the fix

  • ✗ Merging the graded plate over the original✓ The plate alpha is 1 everywhere, so the whole frame gets graded. Use a Keymix with a mask.
  • ✗ Rejoining stencil and mask pieces with an over✓ Over applies (1 − m) twice and leaves a dark seam on the feather. Use plus, or just use Keymix.
  • ✗ A hard-edged mask round the graded area✓ An area grade has no real edge in the plate, unlike the object edges in R1, so give it a wide feather until the seam disappears.
  • ✗ The camera moves but the mask stays put✓ Track it and let the roto follow, or the grade slides across the picture.

Before you send the shot

  • Outside the mask every pixel equals the original (difference = black)
  • No visible seam along the feather
  • The mask follows the object for the whole shot
  • The bbox isn’t bloated by the roto

5 Check yourself

One question to check yourself

What does Keymix use to choose between the images?

What you learned

🔒 Answer the question above and this card opens

More questions

1. Mask = 0.5, A = 0.32, B = 0.2. What does Keymix output?

2. You stencil the plate with a roto, mask the graded image with the same roto, then join them with an over. What happens?

Where the numbers come from: Computed in your browser. Saturation, Multiply, Clamp, Invert, Keymix, Copy and Grade match Nuke 17.0v2 (checked). Blur, Defocus, Glow, Sharpen, ChromaticAberration, Vignette, LensDistort, Grain, Erode, Toe, the Keyer and Despill are teaching versions, not identical to Nuke’s nodes. Transform here is also a teaching version: bilinear filtering, no concatenation, cropped at the frame edge. Images are our own Blender renders (the green screen is fully code-built; the desert scene uses Gaea 2.3 hills, a Poly Haven CC0 HDRI sky, Poly Haven CC0 rocks and grass, Quixel sand and cliff textures and a Mixamo rig for the robot, with Quixel and Mixamo used in the renders only).