Home · Lessons

Merge over and premult

Why edges go dark or glow, and the real fix

Lesson 01 · Free · ~6 min · Unit: Edges and alpha

1 The idea

Every time you lay one image over another, Nuke uses one formula: A over B = A + B·(1−αA). The part of B that is covered fades by alpha, then A is simply added on top.

The formula assumes A is already premultiplied (its colour already multiplied by alpha). If A is not premultiplied, the edge gets too bright (a glowing rim). If it was premultiplied twice, the edge goes dark. Switch the modes below and watch the edge graph.

out = A + B·(1 − αA), A = C·α

2 Try it

Switch the plate to "Bright" and pick premult twice: the dark rim is easiest to see

Viewer1 · Lesson 01rgba · 1001

3 Deep dive

Over = plus + stencil

Over splits into two steps: cut a hole in B by (1 − a), which is stencil, then add A straight on, which is plus. The result is identical, pixel for pixel.

Seen this way, every edge bug makes sense: no alpha leaves only the plus; unpremultiplied colour adds too much; a double premult cuts the same hole but fills it with too little.

  1. 1B (plate)
  2. 2Stencil by A’s alpha
  3. 3Plus A
  4. 4Result

What happens to alpha

Alpha follows the same formula: a + b·(1 − a). The numbers below were measured in Nuke with A = 0.3 (alpha 0.5) and B = 0.4 (alpha 0.8).

opFormulargbalpha
overA + B(1−a)0.50.9
underB + A(1−b)0.460.9
plusA + B0.71.3
maskB·a0.20.4
stencilB(1−a)0.20.4

Plus can push alpha above 1; never use it to combine mattes

Over’s relatives

Under puts A behind B without swapping pipes. Mask keeps B only inside A’s shape; stencil cuts it out. Both scale rgb and alpha together, so the image stays correctly premultiplied.

The matte operation is premult and over in one: A·a + B·(1 − a). Use it when A is not premultiplied yet, such as a keyed plate that already has its alpha.

Checking edges in a real shot

Put your element over a white Constant, then over black. A dark rim shows on white, a glowing rim on black. Then push the Viewer gain up and down to check again. F2 shows how to hunt down the node that premultiplies twice.

If A is bigger than the frame, such as smoke spilling past the edges, set the Merge bbox to B so the processing area does not grow for nothing.

4 In real work

In Nuke

  1. Merge (over): A = premultiplied element, B = plate
  2. Element not premultiplied (a key): Premult before the Merge, or use operation matte
  3. A behind B without rewiring: operation under
  4. Cut a hole only: stencil · keep only inside: mask
  5. Merge bbox: B when A spills past the frame

Common mistakes → the fix

  • ✗ Merging a keyed, unpremultiplied plate straight over✓ Colour outside the alpha gets added to the plate. Premult first, or use matte.
  • ✗ Stencilling the background and then merging over to put something behind✓ This often leaves a thin dark line. Use under instead.
  • ✗ Combining two mattes with plus✓ Alpha goes above 1 and over starts subtracting the background. Use max or screen (recap of F1).
  • ✗ Fixing a dark rim by eroding the alpha✓ If the cause is a double premult, eroding only hides it. Find the extra Premult and remove it.

Before you send the shot

  • A is premultiplied exactly once before the over
  • B is the plate, A is the element
  • No wrong rims over white and over black
  • Alpha after the merge stays at or below 1

5 Check yourself

One question to check yourself

Your CG has a thin dark rim when it sits over a bright sky. What is the most likely cause?

What you learned

🔒 Answer the question above and this card opens

More questions

1. A = 0.3 (alpha 0.5, premultiplied) over B = 0.4 gives what rgb?

2. A keyed plate is not premultiplied but has its alpha. Which Merge operation gets it right in one node?

Where the numbers come from: The merge formulas were checked in Nuke 17.0v2. The pictures here are a simplified in-browser calculation; values above 1 are clipped for display.