facerFX :: tutorials

 

sideNav
July 10, 2008
Z-Depth and Fog In One

This tutorial will show you how to get Z-Depth and fog in compositing out of the same render pass. It will also show you how to tweak your fog without having to go back and re-render from your 3d package. The tutorial is aimed at beginner to intermediate level compositors. The technique for getting Z-Depth and fog from the same render pass is not recommended for all situations but is definitely helpful if you have limited resources and cannot afford to render passes for both.

I will be using 3ds Max 2008 and After Effects CS3 for this tutorial although the techniques can be applied to any software packages.

Click here to download the Max file I am using for this tutorial.

We'll start off by just rendering a beauty pass of our scene.

beautyPass

Next we will render off our Z-Depth/fog pass. For now we will do this through Max's render elements. Open your render scene dialog and go to the "Render Elements" tab. Click the "Add ..." button and add a Z-Depth render element.

There are a few things you will need to do here in order to get the result we want. For many of the render elements filtering is enabled by default, but for some reason it is not for Z-Depth. Make sure the "Enable Filtering" button is checked otherwise we will possibly get rough edges around our geometry's edges.

You will also notice at the bottom of the rollout, with our Z-Depth render element selected, two spinners asking for a "Z-Min" and "Z-Max" value. These values are where our Z-Depth map begins and ends in Z-space, relative to the camera. I find the best method for getting these values is to select the camera we are going to be using and in the modify panel choose to show the camera's environment ranges. We then get a perfect visual representation of these ranges and the values to just copy over.

So play around with the environment ranges until you find values that you feel will work well for you and then copy them over to the Z-Min and Z-Max values in the render elements rollout.

Now if we click render, and we render from the proper camera, after the render finishes our Z-Depth pass will pop up. Save the image as PNG with alpha and open up After Effects.

depthPass

Start a new file, import footage for both our beauty pass and depth pass. When asked how to interpret the depthPass, choose to "Ignore" alpha (we're just not going to use it in this example). When your footage has been brought in, create a new comp using both pieces of footage.

Put your beautyPass on the layer above your depthPass. Right click on the beautyPass and go to "Effect/Blur & Sharpen" and add a Lens Blur. Your scene should now look similar to this.

In the top left you will see our Lens Blur effect controls. Click next to "Depth Map Layer" where it says "None". You have an option between beautyPass.png and depthPass.png here, choose depthPass. The only thing to note here is that the choices only consist of layers that exist in your current comp, if you removed depthPass.png from your comp you would not be able to choose it.

As soon as you choose depthPass.png you will notice the blurring on your image change as your depthPass is now determining how your image is blurred. This is probably not the result we are looking for though, so the next settings we are going to tweak is the "Blur Focal Distance" and "Iris Radius".

The blur focal distance is what determines what area of your image is going to be in focus, not hard to figure out. Without knowing how it works though you will probably just play around with the value and guess at it until you are happy with what your image looks like, but if you know how it is being used by the program you can get pin-point accuracy with your depth blur.

If you ramp the blur focal distance value up as far as it can go you will notice it stops at 255. If you know about color values, each the of the red, green, and blue channels range from 0 to 255 and when all 3 are equal to the same number you get a shade of gray. Our Z-Depth pass is a grayscale image ranging from black to white. The blur focal distance is really just telling After Effects what area of your image should be in focus according to the gray value in your depthPass.

Choose an area of your image that you would like to be in focus. Click the eyeball icon to the left of your beautyPass layer in order to hide it and see the depthPass underneith. Move your mouse cursor to hover overtop of the area you chose to be in focus and take note of the "Info" window in the top right of your screen. The info window will give you the color value of the pixel your mouse is currently hovering over. All three values for R, G, and B should be the same. Type this value in for your blur focal distance and unhide your beautyPass. Your image should now be focused on the correct spot.

Now adjust the "Iris Radius", no special tricks to this one, to the value you see fit. It is basically just the blur amount. Here is how the image should look now, notice the subtle blur.

Now we are going to create our fog. We are going to do a few steps before we begin. Select your beautyPass layer and go to the "Layer" menu in the top menu bar and select "Pre-Compose", way down at the bottom. A window will pop up and prompt you. Enter "beautyWithFog" as your "New composition name", choose "Leave all attributes in 'beautyPass'", and check the box for "Open New Composition".

The reason we are creating a new composition for our beautyPass is that when we put the fog overtop of our footage we want our fog to be blurred by the Z-Depth as well. Choosing "Leave all attributes in 'beautyPass'" means that although we are moving our selected layers to a new composition any existing effects on our selection will remain in this composition and be applied to the new comp that is taking the place of our current selection.

Now that we have our new comp created and open you will notice the blur is no longer there, that is okay. Go to your project bin and drag the depthPass footage into the current comp, placing it on top of your beautyPass layer. Change the blending mode from "Normal" to "Screen" (This might be currently hidden. Right click the bar above your footage, go to columns, and make sure "Modes" has a checkmark beside it.).

You will now notice that the fog is actually at the front of your image, to fix this we will simply add an invert effect to our footage. You can find invert in the channel category of your effects. Your image should now look like this.

Now we are going to fine tune our fog to how we want it. Believe it or not, but we have almost all the same control over it in After Effects as we do with Max's built in fog render effect, and even a little extra in some areas. All we need for this is a "Levels" effect to be added to our depthPass layer, so do that now. You can find levels in the color correction category.

The image above is showing control commonalities; 3ds Max on the left, After Effects on the right. If you play with these values in both software packages you will see that they give the exact same results, you even get more control over the exponential falloff by having three control points as opposed to one checkbox.

Other parameters in Max, such as color, environment color map, environment opacity map, and the entire layered fog type, are not as easily accessible in After Effects but are still attainable, you just need to get creative! For example, you can change the color by adding a "Hue/Saturation" effect to your depthPass layer and checking the "Colorize" option. You can get the same effect as the environment opacity map and layered fog by playing around with masks.

Anyways, tweak your fog settings until you find something you are happy with. I went with values of 32 for Input Black, 255 for Input White, and 0.70 for Gamma, all of which relate to the exponential falloff in Max, and then a value of 18 for Output Black (Near %) and 153 for Output White (Far %).

Go back to your main comp and you will see that we now have fog and Z-Depth from the same pass and they are working in unicen. Here is what your final image should look like.

Well, that's all! I hope you have found this tutorial helpful.


Bottom Nav
SideNav contact links resume tools tutorials technical portfolio news news portfolio technical tutorials scripts resume links contact