ZDefocus

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.

Inputs and Controls

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 default blink 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, if available, by navigating to the Preferences and selecting an alternative from the default blink 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.

Note:  Enabling this option with no local GPU allows the script to run on the GPU whenever the script is opened on a machine that does have a GPU available.
You should also select this if you wish to render from the command line with the --gpu option.

See Nuke 15 Release Notes for more information on the GPUs Nuke supports.

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

When enabled, only apply the effect to the edge of the mask.

When disabled, the effect is applied to the entire mask.

mix

mix

1

Dissolves between the original image at 0 and the full effect at 1.

       

Step-by-Step Guides

Simulating Depth-of-Field Blurring

Video Tutorials