# ZDefocus

> Depth of field from a depth channel — the image is cut into depth layers, each blurred by its distance from the focus plane and laid back over the others from the back to the front.

Depth of field from a depth channel — the image is cut into depth layers, each blurred by its distance from the focus plane and laid back over the others from the back to the front. Drag the focal point in the Viewer to focus on what is under it. Disc, bladed (iris) or image bokeh; focal plane / layer / filter shape setup views. fill foreground keeps the background continuous behind a blurred front layer, so its edge does not leave a step. Layer spacing is automatic unless you turn it off.

| Node | ZDefocus |
|---|---|
| Menu | Filter › ZDefocus |
| **Names in each format** | |
| .oink comp (JSON) | `"type": "OC_N_zdefocus"` |
| .nk script | `ZDefocus2`, also imports `ZDefocus` ([how .nk import works](/docs/nuke-users/nk-import)) |
| Python | `nuke.createNode("ZDefocus2")` |
| Assistant (MCP) | `create_node(type="ZDefocus")` |
| Tab search | `zdefocus`, or its initials `zd` |

![ZDefocus properties](/shots/nodes/zdefocus@2x.webp)

## Inputs and outputs

| Port | Name | Type |
|---|---|---|
| input 0 | Image | image |
| input 1 | filter | image |
| input 2 | mask | image |
| output 0 | Image | image |

## Knobs

Panel tab **ZDefocus**, in panel order.

| Knob | Label | Type | Default | Range / values | .nk knob | Description |
|---|---|---|---|---|---|---|
| `channels` | channels | menu | `all` | rgba, rgb, alpha, all, none |  | Layer the op applies to: rgb, rgba, alpha, all, none, <layer> or <layer>.<ch> |
| `useGPUIfAvailable` | Use GPU if available | bool | `true` |  | `useGPUIfAvailable` |  |
| `z_channel` | depth channel | text | `depth.Z` |  | `z_channel` |  |
| `math` | math | menu | `depth` | direct, depth, far0 (far = 0), far1 (far = 1), ndirect (-direct), ndepth (-depth), nfar0 (far = -0), nfar1 (far = -1) | `math` |  |
| `output` | output | menu | `result` | result, focal_plane_setup (focal plane setup), layer_setup (layer setup), filter_shape_setup (filter shape setup) | `output` |  |
| `show_image` | show image | bool | `true` |  | `show_image` |  |
| `fill_foreground` | fill foreground | bool | `true` |  | `fill_foreground` |  |
| `center` | focus plane (C) | float | `0` | -100 to 100 | `center` |  |
| `focal_point` | focal point | vector ×2 | `200, 200` | -10000 to 10000 | `focal_point` |  |
| `dof` | depth of field | float | `0` | 0 to 100 | `dof` |  |
| `blur_dof` | blur inside | bool | `true` |  | `blur_dof` |  |
| `size` | size | float | `25` | 0 to 100 | `size` |  |
| `max_size` | maximum | float | `50` | 0 to 200 | `max_size` |  |
| `autoLayerSpacing` | automatic layer spacing | bool | `true` |  | `autoLayerSpacing` |  |
| `nLayers` | depth layers | float | `20` | 1 to 256 (integer) | `nLayers` |  |
| `layerCurve` | layer curve | float | `1` | -5 to 5 | `layerCurve` |  |
| `filter_type` | filter type | menu | `disc` | disc, bladed, image | `filter_type` |  |
| `shape` | filter shape | float | `1` | 0 to 1 | `shape` |  |
| `aspect` | aspect ratio | float | `1` | 0 to 2 | `aspect` |  |
| `blades` | blades | float | `5` | 2 to 16 (integer) | `blades` |  |
| `roundness` | roundness | float | `0.2` | -1 to 1 | `roundness` |  |
| `rotation` | rotation | float | `0` | -180 to 180 | `rotation` |  |
| `inner_size` | inner size | float | `0.8` | 0 to 1 | `inner_size` |  |
| `inner_feather` | inner feather | float | `1` | 0 to 1 | `inner_feather` |  |
| `inner_brightness` | inner brightness | float | `0.8` | 0 to 1 | `inner_brightness` |  |
| `catadioptric_size` | catadioptric size | float | `0.3` | 0 to 1 | `catadioptric_size` |  |
| `catadioptric` | catadioptric | bool | `false` |  | `catadioptric` |  |
| `filter_channel` | filter channel | text | `rgba.alpha` |  | `filter_channel` |  |
| `use_input_channels` | use input channels | bool | `false` |  | `use_input_channels` |  |
| `filter_bounds` | filter bounds | menu | `shape` | shape, format | `filter_bounds` |  |
| `image_filter` | image filter | menu | `CUBIC` | IMPULSE (Impulse), CUBIC (Cubic), KEYS (Keys), SIMON (Simon), RIFMAN (Rifman), MITCHELL (Mitchell), PARZEN (Parzen), NOTCH (Notch), LANCZOS4 (Lanczos4), LANCZOS6 (Lanczos6), SINC4 (Sinc4) | `image_filter` |  |
| `clamp_image_filter` | clamp image filter | bool | `false` |  | `clamp_image_filter` |  |
| `bloom_gamma` | gamma correction | bool | `false` |  | `bloom_gamma` |  |
| `bloom` | bloom | bool | `false` |  | `bloom` |  |
| `bloom_threshold` | bloom threshold | float | `0.8` | 0 to 10 | `bloom_threshold` |  |
| `bloom_gain` | bloom gain | float | `2` | 0 to 10 | `bloom_gain` |  |
| `mask_channel` | mask | menu | `none` | none, rgba.alpha, rgba.red, rgba.green, rgba.blue |  | Mask channel, e.g. rgba.alpha (none = no mask) |
| `inject` | inject | bool | `false` |  |  | Copy the mask into mask.a for nodes downstream |
| `invert_mask` | invert | bool | `false` |  | `invert_mask` |  |
| `fringe` | fringe | bool | `false` |  |  | Only apply the effect at the edges of the mask |
| `mix` | mix | float | `1` | 0 to 1 | `mix` |  |

### Other knobs (Python, .nk and the assistant; not on the panel)

| Knob | Label | Type | Default | Range / values | .nk knob | Description |
|---|---|---|---|---|---|---|
| `gl_color` | Viewer Controls Color | float ×3 | `0, 0, 0` | 0 to 1 |  |  |
| `postage_stamp_frame` | Static Frame | int | `1` | -2147483648 to 2147483647 |  |  |
| `lifetimeStart` | Lifetime Start | int | `0` | -2147483648 to 2147483647 |  |  |
| `lifetimeEnd` | Lifetime End | int | `100` | -2147483648 to 2147483647 |  |  |
| `useLifetime` | Use Lifetime | boolean | `false` |  |  |  |
| `cached` | Cached | boolean | `false` |  |  |  |
| `bookmark` | Bookmark | boolean | `false` |  |  |  |
| `dope_sheet` | Dope Sheet | boolean | `false` |  |  |  |
| `clone_group` | Clone Group | string |  |  |  |  |
| `link_source` | Link Source | string |  |  |  |  |
| `link_overrides` | Link Overrides | string |  |  |  |  |
| `split_views` | Split Views | string |  |  |  |  |
| `unpremult` | (Un)premult by | enum | `none` | none, rgba.alpha |  |  |
| `invert_unpremult` | invert | boolean | `false` |  |  | (Un)premultiply by 1 - alpha |
| `legacy_resize_mode` | legacy resize mode | boolean | `false` |  | `legacy_resize_mode` |  |


---
Sources: opencomp_core/nodes/filter/zdefocus.py, opencomp_electron/src/components/properties/knobSchema.ts, opencomp_core/nodes/help/zdefocus.md, opencomp_core/nk/mapping.py
