Blurs the image according to a depth map channel. This allows you to simulate depth-of-field (DOF) blurring.
In order to defocus the image, ZDefocus splits the image up into layers, each of which is assigned the same depth value everywhere and processed with a single blur size. After ZDefocus has processed all the layers, it blends them together from the back to the front of the image, with each new layer going over the top of the previous ones. This allows it to preserve the ordering of objects in the image.
Connection Type |
Connection Name |
Function |
Input |
filter |
This image is used as the blur kernel. It represents the shape and size of the camera aperture used to shoot the input footage. As the clip in the image input is blurred, any out-of-focus highlights (’bokeh’) in the clip assume the shape of the filter image. You can create a filter image using the Roto node (Draw > Roto) or the Flare node (Draw > Flare), for example. The filter image can also be a color image. For example, if you want to add color fringing to your out-of-focus highlights to simulate chromatic aberration, you can use the Flare node to easily create a suitable filter image. You don’t necessarily need to crop the filter image to a smaller size, as Fast Fourier Transforms are used to speed up convolutions with large filter images. |
image |
The image sequence to receive the blur effect. This should also contain the depth map channel. |
|
mask |
An optional image to use as a mask. By default, the blur is limited to the non-black areas of the mask. At first, the mask input appears as triangle on the right side of the node, but when you drag it, it turns into an arrow labeled mask. If you cannot see the mask input, ensure that the mask control is disabled or set to none. |
Control (UI) |
Knob (Scripting) |
Default Value |
Function |
ZDefocus Tab |
|||
channels |
channels |
all |
The effect is only applied to these channels. If you set this to something other than all or none, you can use the checkboxes on the right to select individual channels. |
Local GPU |
gpuName |
N/A |
Displays the GPU used for rendering when Use GPU if available is enabled. Local GPU displays Not available when: • Use CPU is selected as the GPU Device in the Preferences. • no suitable GPU was found on your system. • it was not possible to create a context for processing on the selected GPU, such as when there is not enough free memory available on the GPU. You can select a different GPU Device, if available, by navigating to the Preferences and selecting an alternative from the GPU Device dropdown. NOTE: Selecting a different GPU requires you to restart Nuke before the change takes effect. |
Use GPU if available |
useGPUIfAvailable |
enabled |
When enabled, rendering occurs on the Local GPU specified, if available, rather than the CPU. The output between the GPU and CPU is identical, but using the GPU can significantly improve processing performance. NOTE: Enabling this option with no local GPU allows the script to run on the GPU whenever the script is opened on a machine which does have a GPU available. The GPU processing also requires certain NVIDIA GPUs and CUDA drivers. For more information on the minimum requirements, please refer to the Nuke Release Notes available in Help > Release Notes. |
depth channel |
z_channel |
depth.Z |
Specifies the input channel containing the depth map information. NOTE: The depth map should not be anti-aliased. If it is, pixels along an edge between two objects can be assigned a depth that is in-between the depth of the front and back objects. This looks wrong, as it suggests that those edge pixels are floating somewhere between the objects. |
math |
math |
depth |
Specifies how the depthchannel is used to calculate the distance between the camera and an object. For example, some programs use higher values to denote further away, while in others they mean closer to the camera: • direct - The Z value in the depth channel directly controls blur. For example, if Z is 0.5, then the blur size will be 0.5 times the value of the size control (unless this is bigger than maximum, in which case it will be clamped to maximum). • depth - The Z value in the depth channel is the distance between the camera and whatever is in the image at that pixel. • far = 0 - The Z value in the depth channel is equal to 1/distance. The values are expected to decrease from large positive values close to the camera to zero at infinity. This is compatible with depth maps generated by Nuke and RenderMan. • far = 1 - Near plane = 0, far plane = 1. This is compatible with depth maps generated by OpenGL. • -direct - As with the direct mode, the Z value in the depth channel directly controls blur. In other words, each layer is blurred by the same amount as in the direct mode. However, in this mode, the layers are interpreted as being in the opposite order, so a higher depth value places a layer in front of another rather than behind it. • -depth - The Z value in the depth channel is -distance in front of the camera. This is the same as depth, but the distances are negative to start with. • far = -0 - The Z value in the depth channel is equal to -1/distance. The values are expected to increase from large negative values close to the camera to zero at infinity. This is compatible with depth maps generated by Maya. • far = -1 - Near plane = 0, far plane = -1. |
output |
output |
result |
Sets the output type: • result - displays the input image and the result of the blur controls. • focal plane setup - displays depth-of-field (DOF) information in the rgb channels: • red - Less than DOF (in front of the area that’s in focus). • green - Inside DOF (in focus). Note that if depth of field is set to 0, nothing is displayed in green. • blue - Greater than DOF (behind the area that’s in focus). • layer setup - like focal plane setup, but displays depth-of-field (DOF) information after the depth has been divided into layers. Pixels assigned to the same layer have the same amount of blur applied to them. • filter shape setup - displays the filter shape in rbg, allowing you to adjust the filter more accurately. |
show image |
show_image |
enabled |
When output is set to focal plane setup, enabling this shows the depth-of-field (DOF) information overlaid upon the input image. |
fill foreground |
fill_foreground |
enabled |
When enabled, Nuke attempts to compensate for missing information by filling regions in the foreground which are revealed when the foreground goes out of focus. You can try enabling this control if you see sharp edge artefacts in blurred objects in front of the focal point (nearer to the camera). However, because the true image information isn't available in these regions, enabling fill foreground can sometimes introduce undesirable artefacts by adding things which aren't there. If you see blurry artefacts in the foreground, rather than sharp edge artefacts, try disabling this control. |
focus plane (C) |
center |
0 |
Sets the Z depth of areas in the image that are entirely in focus. |
focal point xy |
focal_point |
200, 200 |
Controls the position of the focal point widget in the Viewer. Adjusting the Viewer widget updates the focusplane and focalpoint fields automatically. |
depth of field |
dof |
0 |
Sets a depth slice around the focus plane that is entirely in focus. NOTE: True theoretical depth of field would set this to zero. |
blur inside |
blur_dof |
enabled |
When enabled, a small amount of blur is applied to the in-focus region. This gives a smoother transition between the in-focus region and the out-of-focus regions around it. |
size |
size |
25 |
Sets the size of the blur at infinite depth. Blur nearer the camera than the focus plane may be larger. If you have set math to direct, the size is multiplied by the depth to give the blur size at that depth. Setting size to 1 allows you to use the values in the depth map as the blur size directly. |
maximum |
max_size |
50 |
The filter size is clipped at this maximum value. No blurring greater than this value is generated no matter where the object is in relation to the camera. Set this value as low as possible for maximum processing speed. |
automatic layer spacing |
autoLayerSpacing |
enabled |
When enabled, ZDefocus automatically works out how many depth layers to use, based on the maximum blur size (maximum). In this mode, the layers are closer together near to the focal plane, where a small change in the blur amount is more obvious, and increasingly more widely-spaced further away. When disabled, you can control the depth layers and their spacing manually using depth layers and layer curve. |
depth layers |
nLayers |
20 |
The number of depth layers to use for the blur. Use a small number of layers for maximum speed. The maximum number of blur sizes that are used between 0 and maximum is 256. This means you can have up to 256 layers behind the focal plane, and up to 256 in front of it as well. |
layer curve |
layerCurve |
1 |
The curve to apply to the layer spacing. A value of 0 gives evenly spaced layers. Positive values concentrate the layers closer to the in-focus region. Negative values mean the layers are concentrated far from the focal plane, towards the maximum blur size. |
filter type |
filter_type |
disc |
Sets the blur filter applied to the image: • disc - applies a round disc filter to the image. • bladed - applies a bladed filter to the image (simulates the iris blades that can make up a camera's diaphragm). • image - uses the image in the filter input as the blur kernel. |
The following controls, up to and including aspect ratio, are only available when filter type is set to disc. |
|||
filter shape |
shape |
0 |
Dissolves the filter shape between Gaussian at 0 and disc at 1. |
aspect ratio |
aspect |
1 |
Sets the filter aspect ratio, which is 1:1 by default. Values less than 1 squeeze the filter on the x axis, and values larger than 1 squeeze it on the y axis. This allows you to simulate the cat's eye effect, caused by vignetting inherent within some lens designs. |
The following controls, up to and including catadioptric, are only available when filter type is set to bladed. |
|||
aspect ratio |
aspect |
1 |
Sets the filter aspect ratio, which is 1:1 by default. Values less than 1 squeeze the filter on the x axis, and values larger than 1 squeeze it on the y axis. This allows you to simulate the cat's eye effect, caused by vignetting inherent within some lens designs. |
blades |
blades |
5 |
Sets the number of iris blades that make up the camera's diaphragm. A value of 3 produces a triangle, 4 a square, 5 a pentagon, 6 a hexagon, and so on. NOTE: This field only accepts integers larger than 1. |
roundness |
roundness |
0.2 |
Controls the rounding of the filter polygon’s sides, where zero is equal to no rounding. |
rotation |
rotation |
0 |
Controls filter rotation in degrees. Positive values produce counter-clockwise rotation and vice-versa. |
inner size |
inner_size |
0.8 |
Controls the size of the inner polygon, as a percentage of the outer polygon. |
inner feather |
inner_feather |
1 |
Adds outward or inward feathering around the inner polygon. With values larger than 0.5, your feather effect is outward and, respectively, if your values are smaller than 0.5, the feather effect is inward. A value of 0.5 produces no feathering. |
inner brightness |
inner_brightness |
0.8 |
Controls the brightness of the inner polygon, where 0 is equal to black and 1 to white. |
catadioptric size |
catadioptric_size |
0.3 |
When catadioptric is enabled, controls the size of the catadioptric hole in the filter. |
catadioptric |
catadioptric |
disabled |
When enabled, ZDefocus simulates catadioptric lenses. This means the defocused areas of the image are annular, producing donut-shaped bokeh. You can use the catadioptric size to control the hole in the center of the filter. |
The following controls, up to and including clamp image filter, are only available when filter type is set to image. |
|||
legacy resize mode |
legacy_resize_mode |
N/A |
Loading scripts from pre-Nuke 8.0v7 enables the legacy resize mode checkbox automatically, for backward compatibilty, and uses the filter bounds dropdown to determine how images used in filtering are resized. Adding new ZDefocus nodes hides the legacy resize mode checkbox and allows you to use the image filter dropdown to give you more flexibility when calculating blur. |
filter channel |
filter_channel |
rgba.alpha |
The channel to use as the convolution matrix from the filter input. This control is only available if use input channels is disabled. |
use input channels |
use_input_channels |
disabled |
When enabled, the same channels are used for both the filter and image inputs. |
filter bounds |
filter_bounds |
shape |
Sets what to use as the filter bounds when legacy resize mode is enabled: • shape - The filter input’s bounding box. In this case, ZDefocus only uses the bounding box area, and the center of the filter is the center of the bounding box. This is the default value, and you may want to use it if your filter input is a roto shape with a small bounding box that doesn’t fill the entire format area, for example. • format - The filter input’s format. In this case, ZDefocus uses the entire format area, allowing you to offset the filter image within the format. NOTE: This control is only available when legacy resize mode is enabled. |
image filter | image_filter | Cubic |
Sets which of Nuke's filtering algorithms to use when remapping pixels from their original positions to new positions, when legacy resize mode is disabled: • Impulse - remapped pixels carry their original values. • Cubic - remapped pixels receive some smoothing. • Keys - remapped pixels receive some smoothing, plus minor sharpening (as shown by the negative -y portions of the curve). • Simon - remapped pixels receive some smoothing, plus medium sharpening (as shown by the negative -y portions of the curve). • Rifman - remapped pixels receive some smoothing, plus significant sharpening (as shown by the negative -y portions of the curve). • Mitchell - remapped pixels receive some smoothing, plus blurring to hide pixelation. • Parzen - remapped pixels receive the greatest smoothing of all filters. • Notch - remapped pixels receive flat smoothing (which tends to hide moire patterns). • Lanczos4, Lanczos6, and Sinc4 - remapped pixels receive sharpening which can be useful for scaling down. Lanczos4 provides the least sharpening and Sinc4 the most NOTE: This control is only available when legacy resize mode is disabled. |
clamp image filter | clamp_image_filter | disabled |
When using filters that employ sharpening, such as Rifman and Lanczos, you may see a haloing effect. If necessary, check clamp image filter to correct this problem. NOTE: This control is only available when legacy resize mode is disabled. |
gamma correction |
bloom_gamma |
disabled |
When enabled, a gamma curve of 2.2 is applied before blurring and then reversed for the final output. This is useful for making bokeh lens shape effects warmer and more visible. |
bloom |
bloom |
disabled |
When enabled, highlights over the bloom threshold are boosted to make lens shape effects more visible. |
bloom threshold |
bloom_threshold |
0.8 |
When bloom is enabled, highlights above this value are multiplied by the bloom gain value to make lens shape effects more visible. |
bloom gain |
bloom_gain |
2 |
When bloom is enabled, highlights above the bloom threshold are multiplied by this value. |
mask |
N/A |
disabled |
Enable the associated mask channel to the right. Disabling this checkbox is the same as setting the channel to none. |
maskChannelInput |
none |
The channel to use as a mask. By default, the blur is limited to the non-black areas of this channel. |
|
inject |
inject |
disabled |
Copies the mask input to the predefined mask.a channel. Injecting the mask allows you to use the same mask further downstream. |
invert |
invert_mask |
disabled |
Inverts the use of the mask channel, so that the blur is limited to the non-white areas of the mask. |
fringe |
fringe |
disabled |
Blurs the edges of the mask. |
mix |
mix |
1 |
Dissolves between the original image at 0 and the full effect at 1. |
Nuke 7.0 - ZDefocus from The Foundry on Vimeo.
Nuke 7.0 - Bokeh in ZDefocus from The Foundry on Vimeo.
This is Steve Wright for The Foundry, with a tutorial on the ZDefocus node’s bokeh effects. In the previous ZDefocus node tutorial, we took a quick look at the bokeh settings. In this tutorial, we will dive in for a much closer look to see the amazing amount of control you have to dial in the look of a lens bokeh. I will be using this city lights picture that has this depth.Z channel already built in. To get my ZDefocus node, I will use my Tab and search. Because the image has a depth channel, I already get a default defocus.
We will be looking at all three of these filter types, starting with the disc filter. The first parameter, filter type, determines whether the bokeh is a hard circle or a soft fuzzy blob. So as you move towards 0, it becomes just a Gaussian curve, back to 1, a sharp disc. The aspect ratio will squeeze it vertically or stretch it horizontally, so you are covered whether you are working on anamorphic plates or you are working flat and going out anamorphic.
Next, the bladed filter type. This refers to the bladed iris. Again, we have the aspect ratio as before, and here is the number of blades settings. By default, we have five blades, but we can set it to any number we want. Now, the roundness is how straight the edges are. If I go 100% roundness, it becomes almost a circle, and if I go in the opposite direction, the shape becomes concave. We will put that back to default, which is just a bit of roundness. The rotation, of course, allows you to rotate the filter, so that you can get any orientation you like. The inner size and inner feather will show up better if I take the inner brightness down to something like this. See this dark center, that’s what we're talking about. So I can change the inner size to make it as small or large as I wish, and the inner feather is how soft it is. Here’s an interesting toggle right here: the catadioptric feature. Catadioptric lenses use a combination of both mirrors and lenses, which produce a unique bokeh with a hole in the center. You can also adjust the size of the hole by adjusting the catadioptric size.
Next up, the image filter type. Before I select that, I will show you the images I have. I have this star filter here, and the important thing about this is, there are two boxes to be aware of. The outer box out here is what we will call the format, and the inner box is the bounding box of the shape. Note the shape is off center from the format: it’s on the lower left-hand corner. You will see why this is important in a minute. So I am going to take the filter input of the ZDefocus node at hook it up to my star filter, then switch back to my ZDefocus node, and zoom in. Now we will switch the filter type to image and there you go. Of course, we can change the size of it by adjusting the size and maximum values. So why was I going on about the format or the bounding box for the shape? That’s for right here: filter bounds. If you say shape, you are telling it the shape is inside the bounding box. However, if you select format, it means you want the large outer box and you can see now that the star bokeh has shifted down lower left and has kind of a lens treatment.
The next thing I want to show you is very cool: chromatic aberration. Let me show you my Chromatic_Aberration node (not supplied with Nuke). I hooked up a little 3-channel filter here that allows me to offset the RGB values like so. These offset channels will cause an offset in the bokeh of the image, so let’s check it out. First, we will hook up the filter to our Chromatic_Aberration, and switch the Viewer back to the ZDefocus node, and we get an error message. The error message covers right here (use input channels) by default. It’s looking for the alpha channel to contain the filter input. That’s not what we have here; we have a 3-channel image. So we need to use this use input channels. This means use the same 3 channels in that filter input as we are in the image, which is RGB. So we turn that on, and much better. Let’s zoom in, and see what it looks like. So, you can see all my bokehs now have a chromatic aberration. Red in the upper left, blue in the lower right. If I open my Chromatic_Aberration node again, I can dial the Offset up and down to increase and decrease the amount of chromatic aberration. I will turn it off and toggle if for you so you can really see the effect. OK, I am done with that, so I will close it and go back to the ZDefocus node.
Next, let’s take a quick review of the gamma correction and bloom. Toggle the gamma correction on, and the bokeh gets a lot brighter. You have no control over this because it’s doing a gamma 2.2 change to the bokeh relative to the image. If you want to dial in your own control, use bloom. With the bloom feature turned on, these two parameters wake up. The bloom gain allows you to make it brighter or darker. As you lower the bloom threshold, darker and darker pixels get bloomed.
With these powerful new bokeh features, the ZDefocus node can match the most obscure lenses for visual effects shots, or if you are doing animation, you have complete flexibility to generate your own creative looks.