In my previous entry I talked about the Blur and Defocus nodes. Now let's step it up and take a look at the ZDefocus node. This is the node you want to use with elements that come with a depth pass, like CG renders.  

A typical depth pass. Pixels are brighter the farther they are from the camera.

A depth pass contains the values that represent the distance of each pixel in relationship to the render camera. In most cases the depth starts at 0 which is the location of the camera and gets brighter as it gets farther away. In this case we can see that the tail of the aircraft is the brightest part of the pass because it's the furthest thing away from the camera. 


In some rare cases the depth pass might be inverted go from white to black instead of black to white.  

The first step is to select our depth Channel. In this case it's the default depth.Z but that might not be the case in other situations. The second important part is the math. This will depend on which render engine the CG elements were rendered. In my case it was Vray so I need to set it to depth. If it was rendered in Nuke or RenderMan you'd leave it at far=0  

Now let's set our focal point in the viewer. I'm going to push size and maximum to a higher value to accentuate the effect of depth of field. Don’t go to high as it will slow things down drastically.  

Unpremultiplied on the left. Premultiplied on the right.

It seems to depend on the situation and the rendering engine but at least in this case I need to unpremult the depth pass by the alpha to avoid nasty edges. I'll cover premultiplication in details in a future video. 

As you move the focal_point around in the viewer you'll see that different selected areas will be in focus and the rest of the element will get out of focus just like it would with a real lens. You can also see the focus plane and focal point values change in the settings as you move the focal_point selector around. Focal point is the position of the selector while focus plane is the depth value of that point. You can change the value manually to change what part of the element is in focus. 

You probably guessed it by now, the size slider changes how blurry things get. Now what the maximum setting does is clipping the blur value. In some cases, this is useful and can help you make things render slightly faster and prevent extreme blur between the camera and the focus plane but this is beyond the scope of this blog and video. In 99% of the case I just leave it at the same value than the size slider and I don't worry about it unless I really need to. 

The main drawback of the ZDefocus node compared to better Defocus plugins likge pgBokeh is that it's using arbitrary values for its blur instead of real lens aperture which I like better. But it gives pretty good results and it's pretty fast if you render it with the GPU. 

Focal plane setup helps you visualize which parts are in focus, and which parts aren't.

Now that we've seen the basic settings of the node, let's look at the details. In the output dropdown menu, select focal plane setup. What you're seeing here is the part in focus in green, this is what is referred as the focus plane. In blue is everything between the camera and the focus plane. In red is everything beyond the focus plane. 

In a real setting the focus plane is extremely narrow even when using a small aperture in the lens such as f22 or above, only a small part is really in perfect focus it just ramps to out-of-focus very slowly. In nuke we get to cheat that by adjusting the depth of field slider bring it up slightly and the green part will get broader. It might be hard to see a difference if you switch back to the final output unless you push the size of the blur up quite a bit. That's why focal plane setup can be useful.  

Layer setup shows you "slices" of defocus.

Next in the menu is the layer setup. Here you can see that the red and blue areas have a gradient. The more blue or red, the more out of focus things are, in black you're pretty much in focus. You can see that the gradient reacts to the values entered in the size slider as they're showing you "how" out of focus things are. This can be very useful to dial in your depth of field without having to render the final result each time you change something. 

If you unselect "automatic layer spacing" and bring the values down you can see banding in the gradients. I pretty much always leave it on. It allows you to change how many level of blur you want to have. Set it to a low number like 2 and look at the result with a high blur value and you should be able to see a hard line. A high number will give you more steps of blur and will result in a smooth result. Again, just leave it on automatic, it does the job perfectly. 

Now on to filter type. This is where you get to play with the Bokeh of your Defocus. If you observe out of focus footage, especially cities at night, each light will look like a disk shape, sometimes with smooths edges and sometimes not so much. This is due mainly to the shape of the aperture in the lens. 

By default, it's set to disc. A basic circle with hard edges. Filter shape will give change the sharpness of the bokeh shape and aspect ratio will let you change its shape. Set it to 0.5 and you get a nice anamorphic lens bokeh. You can set the output drop down menu to filter shape setup and see the shape of the bokeh. 

Final image on the left and the bokeh shape on the right.!

Bladed will give you more options. Such as the number of blades the aperture of the lens has, and other settings that will help you match your bokeh to those of a live action plate or make them pretty. Last but not least, you can plug in an image. These tend to be hard to find online but I've definitely been given some to use in production. They will have small details that can make you bokeh really pretty or you can get creative and plug in pretty much anything. 

Make your bokehs pop using bloom.

The last thing we have in this node, is gamma correction which can help make the bokeh pop out more but lacks any kind of control. Bloom is a better options:  values above the threshold will be affected by the bloom and the bloom gain set's by how much. This can help you match a plate or make things pretty.


That's it for the Zdefocus node !