Tutorial 3.1: Using the Z Channel, Pixel Analyzer, and Color Correction |
This tutorial discusses manipulation of the Z channel and also dips into a small discussion of premultiplication during color correction.
A Z channel is the distance of a pixel from the image plane (the camera). This information usually comes from a 3D render, and can precisely indicate a pixel's distance from the 3D camera. Pixels with higher Z values are further away from the camera than pixels with lower Z values.
Most composite nodes depend on the RGB and alpha channels to calculate the final composite. Depth compositing uses a fifth channel, the Z channel, that orders pixels according to a certain depth from the pixel plane. Generally, Z channels are generated with a 3D renderer. Z channels are simple to generate, since every pixel has a certain distance from the camera. Z compositing takes the pixel with the lower Z value when it compares two images. Z channels can be rendered into the same file as the RGBA, or saved into a separate file and later loaded with a Copy node using z as your channel. In this tutorial, use both techniques to composite 3D-rendered blimps into a (really bad) scan of New York City. First, read in a 3D-rendered file of the blimps, and then combine the New York City image with a hand-painted Z image (of the New York City image).
The RGB images:
![]() |
![]() |
The depth images:
![]() |
![]() |
The blimp mask and final composite:
![]() |
![]() |
Why use ZCompose? With nearly 100 ships in the air, you
have to recreate the cityscape in 3D and create a 3D mask in the render. The
most practical solution is to move the camera, however, since the background
plate in this example is static, fake the Z with a hand-painted mask of the
New York City image. By using Z, the dirigibles appear in front and behind
the buildings, as shown in following close-up image.
To start the Z composite, read in the tutorial images using one of the following:
Start Shake, and create a FileIn. In the Load image or
sequence browser, navigate to doc/pix/nyc. Shift-click
dir.iff , nyc.jpg, and nyc_grey.jpg, and click
OK.
Note: Shift-click allows you to select
multiple files within the same directory. You can also drag-select.
First, a bit of image framing:
In the Node View, click the left side of the dir node to View the dir image.
"Fitting" the image to the Viewer may result in a non-integer zoom, and causing visual artifacts.
Press Home to reset the image to a 1:1 view ratio. Any visual artifacts caused by the non-integer zoom are removed.
Press+ / - (by the Backspace key) to zoom the image. The location of the cursor determines the point of zoom.
Shift+F ensures that the Viewer title bar is visible. The Viewer title
bar displays information about the image. For example, the dir image
is a BWAZ (black-and-white image, with alpha and Z channels) 8-bit image.
Now you are probably thinking, "Great, I just press Z and see the Z channel." Well, that would be dandy, and obvious, but it sadly isn't so. Shake does not know what to show you that accurately displays your image sequence, as your Z values may zoom toward or away from the camera over the course of the sequence. For example, a plane could be flying towards the camera, so Z values would change every frame.
The Z values for your image are determined and displayed. This is an old Alias-rendered image, so the actual Z values go from 0 to around 270.
To see the numerical Z values, Right-click the
button and select the Load Viewer Script Controls into Parameter2 Tab.
In the Parameters2 tab, set the floatZinA parameter to Original. This places the real Z values into the Alpha channel for analysis purposes. Scrub the cursor on the Viewer to print the distance on the top of the Viewer, except it's in the Alpha channel position. Wasn't that easy? How do say "Hack" in your language?
Use the Pixel Analyzer when the Z View Script is applied to get the min/max values. In the Pixel Analyzer tab, set Mode to Image and click Maximum.
Not the most elegant method, but it works. Here, Original and Distance return the same value. However, if you use a 3ds max or a Maya-rendered image, you get negative values and -1/distance values, respectively, which are not intuitive. Setting the Z View ViewerScript to Distance returns the actual distance from the camera.
A note about the Z View: It is non-intuitive in that it displays low values (objects close to the camera) as white. Objects which have greater Z values (objects far from the camera) are given darker values. This is the opposite of how you associate high numbers and image values, but it allows Shake to display distant objects as fading into the infinite distance properly.
Does the Z View sound like it's cobbled together with electrical tape? You're right, it is!
You must prepare the false (hand-painted) Z channel for the New York City image to be copied over as a proper Z channel. Whereas the dirigible element has a specific Z channel with ranges from 0 to approximately 262, in this case you must copy the painted black-and-white image as the simulated Z channel. The only difference is that the values of this channel, since it is 8-bit, range from 0 to 1.
In the Node View, select the nyc_grey node.
Attach a Color - Invert node.
Attach a Color - Reorder node.
Use the Reorder node to copy the red channel of the painted image into the Z channel.
In the Reorder Parameters1 tab, enter rgbar in the channels text field. This string specifies that red goes to the red channel, green to the green channel, and so on. The the fifth value, Z also takes the red channel.
The city Z image fades to black because there are low values in the distance. You must invert either the nyc_grey image or the dir image. You cannot flip the blimps (dir image) because its Z range goes beyond 1, and Invert only properly inverts the Z channel if it is normalized (between 0 and 1). Therefore, the Invert node is placed on the city Z image (nyc_grey). Yup, this is confusing.
You have now created a snazzy Z channel. Next, use a Layer - Copy node to copy the Z channel to the NYC image.
In the Node View, select the NYCnode.
Attach a Layer - Copy node.
Connect Reorder1 to the second input of Copy1.
In the Copy1 parameters, enter z into the channels
text field. This copies the Z channel from the Reorder1 node to NYC
One last step, small and easily forgotten.ZCompose needs alpha channels in the images, and the NYC image doesn't have an alpha channel.
Note: As an alternative, you can also attach a Color
- SetAlpha after the NYC FileIn.
Since the Z channels are in place, you can now create the Z composite with a ZCompose node. The ZCompose function takes two images, and promotes the RGBA pixels by comparing which image has the lower Z value. Therefore, order does not matter with a ZCompose.
In the Node View, select the dir node.
Attach a Layer - ZCompose node.
Connect Copy1 to the second input of ZCompose1.
And... Nothing happens!
OK, after all of that buildup, you are crushed and manically disappointed to see that the composite is only of the cityno airships in sight. Great. What a fine tutorial.
If you recall, the dirigible (dir image) Z values range from 0 to approximately 262, as shown earlier with the Pixel Analyzer. The NYC range is from 0 to 1. That pretty much guarantees that the NYC image is always going to be in front of the blimps, since 1 is less than, say, 130. You must therefore multiply the Z value of the city to scale it to match the Z range of the blimps.
In the Node View,select Copy1.
Attach a Color - Mult node (not MMult).
The Mult node has a parameter called depth. It is used to multiply, um, the depth. In the Mult parameters, there are three ways to modify the depth parameter:
Drag the depth slider up. Although the slider stops at 3, you can enter higher values (such as 50) manually in the depth text field.
Note: In Tremor-style, the virtual sliders are always on.
Place the cursor over the depth text field. Hold down Shift and press the Right Arrow key. The value advances by increments of 10 (10 times the normal increment). Press Ctrl for increments of 1. Press Alt for increments of .1.
Things start to look mighty keen once you get past 70, and triumphantly swell
around 190.
You may have noticed that, gee, the blimps are black and white in the middle of a fine smoggy red sunset. Blend them into the scene with a Compress node. This is a good node for fog effects, and for matching color ranges.
In the Node View, select dir .
Insert a Color - Compress node.
The Compress node squeezes the blacks and whites into a colored range.
In the the Compress node parameters, click the Low Color Picker. The Color Picker opens and displays the ColorWheel.
Click Min above the ColorWheel to select the darkest colors on the NYC image.
In the Viewer, scrub along the dark windows of the buildings.
Hey! Everything goes bright! This tutorial blows!
The entire image is brightened because you are color correcting a premultiplied image. By raising the black levels, the entire image, including the space between the blimps, is raised. As discussed in the Intermediate tutorial, use the following solution:
In the Node View, select the dir node.
Insert a Color - MDiv node.
Select Compress1 in the Node View.
Insert a Color - MMult (not Mult) node.
The color correction appears only on the blimps.
Next, set the higher colors.
Load the Compress1 parameters.
Click the High Color picker.
In the Color Picker tab, click Max.
Scrub along the sky to sample the brightest orange color.
The blimps blend with the New York City image.
|
Without Fog | With Fog |
![]() |
![]() |
In this section, add depth cueing by color correcting the blimps in the foreground differently than the blimps in the background. There are about 300 ways to do this, but here, pull a depth-based key from the dir image and use it as a mask for the Compress1 node.
In the Node View, select dir.
Shift-click on Key - DepthKey. A new branch is created with the DepthKey node.
Connect DepthKey1 as the mask to the side of the Compress1
node.
As an alternative, connect MMult1 to a Layer -
KeyMix node. The DepthKey is the third image input, and whatever
else you want (a colored Ramp, a differently color-corrected blimp,
etc.) is the second input in the KeyMix node.