About Masks |
Under Construction
Masking is closely related to Keying. We can consider keying as the process of pulling a matte, typically from a bluescreen. Masking can be thought of as applying a matte to a layer or operation. There is a special section on Keying - see About Keying.
There are two primary ways of considering masks in Shake - you can mask an effect, like a color correction, or you can mask a layer so that whatever is outside (or inside) the mask turns black. This section will discuss, using a tutorial-like example, both of these techniques. It will also discuss special cases like Filters. This is a good section to read because there are some basic optimizations that can be made to any script regarding concatenation.
You can find the example images in doc/pix/masks. Read in all four images.
During the process, we will be taking these:
bg.jpg | woman_pre.iff |
![]() |
![]() |
sign_mask2.iff | car_mask.iff |
![]() |
![]() |
and turning it into this:
Not that it's an amazing masterpiece that you'd hang up on your wall next to your black velvet Elvis portrait anything, but it does help us to talk about both ways of masking.
Masking an
Effect
You can use the side input of a node to mask off an effect. This will pass through all of the input image, only applying the effect of the node to where you applied a mask. In this example, we will make the basic spotlight effect by applying a Brightness node to the bg image. Bring the value down to .3, making the entire image darker. However, we only want the darkening to occur outside of the spotlight area, which we have to make, so we will use a mask. You can mask this with the side mask input with two ways:
OR
nuiAddMaskCommand("QuickShape","QuickShape();"); |
We need to put the circle in perspective, so insert a CornerPin onto the RGrad and adjust it a bit. You should end up with something like this:
![]() |
![]() |
We see that we need to invert the mask. This can be done with an Invert node, but even more easily by opening up the mask controls in the node you are masking. Hit the little plus sign by Mask in the Brightness node, and you can see the mask parameters. In our case, hit invertMask.
We should now have a dark background with a light spot:
When Not
to Use a Mask
These mask inputs are useful for color corrections and transforms. They should not be used for Layer nodes - the logic is completely opposite of what you would think it should be. Trust me. However, even with Color and Transform nodes, they should be used with caution. Here is an example.
We want to color correct the dark parts of the background by applying a Mult and tinting it blue. Since we only want to tint the dark part, we mask the Mult as well:
When you put in a deep blue color, you will get something like this:
However, there are several problems with this:
A better way to do this is to disconnect the masks and instead use KeyMix:
This will ameliorate all of the above problems. This illustration shows the difference between the two renders. Notice that there isn't a blue ring around the soft part of the mask area.
The next step is to mask off a Pan so that we get a feeling of depth between the street and the car hood. If I pan the RGrad, and mask it off, it will give me what I want:
:
Hey! This is just what I told you not to do - mask off otherwise concatenating nodes. I just broke the concatenation between CornerPin and Pan. So, here again, I would use a KeyMix - or if you are lazy, leave it alone. Oh well, laziness wins again...No, no, bad Compositor! Bad!
Now pan the RGrad up to the left by using the Pan node, and you should get something like this:
before | after |
![]() |
![]() |
The image you are using to mask doesn't need to have an alpha channel. For example, Cineon and jpgs don't carry alpha channels. If you plug one in as the mask, you will get no effect, since there is no mask and therefore has a value of 0. Instead, switch the mask channel to R, G, or B in the Mask subtree to select a different channel. If you want the luminance of the image, apply a LumaKey to your mask image and leave the channel at A, or a Monochrome and select R,G, or B. |
Masking a Layer
The other type of masking is using an image as a holdout matte to cut holes into an image. The typical functions to do this are Layer - Inside and Outside. Inside will put the first image only where you see white in the second image, and Outside will put the first image only where you see black.
For example, we don't want the sign to get the brightening effect since it is in the foreground. Therefore, I want to mask off the the brightening image with the sign_mask, meaning, I want to punch a hole into the light mask with the sign mask. We can do this with Outside, saying "The light mask is Outside of sign_mask":
Outside1 | KeyMix1 |
![]() |
![]() |
We could do the same with the woman by combining the sign_mask and the car_mask with an Over (or Max), but there is a slight problem:
If you look at the image, there is a matte line between the two masks:
Therefore, switch the Over to an IAdd by selecting Over1 in the Node View and Ctrl+clicking on Layer - IAdd. This should take care of the line:
Now, we could put the woman Outside of the new mask IAdd1, but we already did that sort of technique with the sign, so let's try a different approach. In this case, I am going to use Atop, which is similar to Over, except it only happens where there is an alpha channel on the background image. Therefore, I want to use SwitchMatte to copy the alpha channel from IAdd1 to KeyMix1, invert it (since Atop only will composite where there is white in the background alpha mask) and turn off matteMult, and put the woman Atop the SwitchMatte node:
If the image came out wrong, make sure that SwitchMatte1's matteMult is turned off and that invert is turned on.
Masking Filters
Filters have special masked versions of the node that will not only mask off an effect, but also change the amount of filtering based on the intensity of the second image. These take the same name as the normal Filter node preceded by an I, i.e., Blur and IBlur. This is much more convincing than using the mask input.
For example, create a Text node and scale the font up so that it fills the image. Now create a Ramp, and make sure your alpha1 parameter is set to 0. Attach a Blur node and crank it up to 200 pixels and mask it off with the Ramp. It should look bad, rather like this. You can see that the right side of the image merely mixes the completely blurred image with the non-blurred image:
![]() |
![]() |
Instead of this, switch the Blur with IBlur (select Blur1 in the Node View and Ctrl+click on IBlur) and take the Ramp from the mask input into IBlur1's second image input:
![]() |
![]() |
Now, the right side is blurred to 200 pixels, the middle is blurred to 100 pixels, and the left edge isn't blurred at all.