#The *Over* operation of a cg object using a mask

Make sure the cg render has a transparent background.

[![enter image description here][1]][1]  
[Sorry the labeling is switched, right is *Internal* and left is *cycles.*]

The render preview will show a checkered background, indicating **transparency**.

[![enter image description here][2]][2]

The **mask** (created in the image editor) can also by viewed, by connecting its output to a viewer node in the compositor.

[![enter image description here][3]][3]

For the easiest *over* operation, our mask is the "wrong way around". This means, we'll have to *invert* it. Add a [*Color >] **Invert*** node after the mask.

[![mask invert nodes][4]][4]


___

###Method to be used with any number of masks.

If you want to use multiple mask nodes, you are not going to be able to use the above node setup.

For that, **unpremultiply** image, alter the alpha (subtraction, max, cojoint-over, etc), **premultiply** it. This method is far more superior but also much more complex. Read up on [premultiplication][5]!

[![enter image description here][6]][6]

___

Premultiplication related: [Popcorn question][7], [Green screen question][8], [Alpha nodes assumes alpha (so smart, wow)][9], [when to convert to premultiplied][10], [Worst answer ever][11], 


  [1]: https://i.sstatic.net/rVyKf.png
  [2]: https://i.sstatic.net/A7diq.png
  [3]: https://i.sstatic.net/Xtd1t.png
  [4]: https://i.sstatic.net/BuQgg.png
  [5]: http://www.spherevfx.com/written-training/miscellaneous-written-training/understanding-premultiplied-images/
  [6]: https://i.sstatic.net/8NPVd.png
  [7]: https://blender.stackexchange.com/a/64322/30849
  [8]: https://blender.stackexchange.com/q/45877/30849
  [9]: https://blender.stackexchange.com/q/46151/30849
  [10]: https://blender.stackexchange.com/q/38459/30849
  [11]: https://blender.stackexchange.com/q/40594/30849