# Refocus an image and add depth haze from a depth map

> Generate a depth map in Nodespell, then use ZDefocus and Depth Atmosphere in an Image Compositor to refocus a still and add distance haze.

Source: https://docs.nodespell.com/recipes/depth-refocus-and-atmosphere/ · Last updated: 2026-11-10

The Nodespell depth recipe turns a flat still into one with a chosen focus plane and distance haze. A depth model node creates a grayscale depth map of the image, then inside an Image Compositor, ZDefocus blurs everything off the focus plane and Depth Atmosphere adds fog, color, and bloom that grow with distance. Only the depth map uses credits; the compositor work runs in the editor and can be adjusted freely.

**What you need**

- A still image, as an Asset or a result on a node in your Project.
- Credits for one depth-map run.
- Familiarity with compositors helps. Depth maps here work like a Z pass in other compositing tools: one channel, near and far encoded as brightness.

**Graph at a glance:** Image → Depth Anything V3 Image (or Facet Depth V1) → Image Compositor { Compositor Input (image) + Compositor Input (depth) → ZDefocus → Depth Atmosphere → Compositor Output }

> **Where credits are spent:** The depth model node is the only paid step. On paid plans, the run button shows its estimate before you run. ZDefocus and Depth Atmosphere are image-processing nodes and do not use credits, so you can tune them as often as you like.

## Stage 1: Generate the depth map

1. Open the Project in **Graph** mode. If the image is not on the canvas, press `Tab`, add an **Asset** node, right-click it, choose **Load Asset**, and pick the image.
2. Press `Tab` and add a depth model node, for example **Depth Anything V3 Image** or **Facet Depth V1**.
3. Connect the image to the depth node's **Image** input.
4. Select the depth node and press `Cmd/Ctrl+Shift+R`.

Both nodes output a grayscale map with near surfaces in white and distant surfaces in black. Depth is relative, not a distance in meters.

| Depth node              | Useful settings                                                                                                                    | Outputs                                                                                       |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| Depth Anything V3 Image | **Output format**: keep **PNG** to avoid lossy compression.                                                                        | One grayscale depth image.                                                                    |
| Facet Depth V1          | **Ignore transparent objects** (**Standard** or **See-through**), **Processing resolution** (**1K**, **1.5K**, **2K**), **Scale**. | **Depth map (PNG)**, plus **Depth (EXR)** and **Raw depth (NPY)** with floating-point values. |

See [Depth and defocus](https://docs.nodespell.com/edit/depth-and-defocus/) for the full list of depth tools.

## Stage 2: Bring image and depth into a compositor

1. Press `Tab` and add **Image Compositor**.
2. Connect the image to the Image Compositor **Images** input first, then connect the depth map. The first connection is index 0, the second is index 1.
3. Select the Image Compositor and press `Enter` (or right-click and choose **Enter Node**).
4. Leave the existing **Compositor Input** on **Index** `0`; this is the image.
5. Press `Tab`, add a second **Compositor Input**, and set **Index** to `1`; this is the depth map.

ZDefocus works only inside a compositor. See [Compositing](https://docs.nodespell.com/edit/compositing/).

## Stage 3: Refocus with ZDefocus

1. Press `Tab` and add **ZDefocus**.
2. Connect the image Compositor Input to the ZDefocus image input and the depth Compositor Input to its depth input.
3. Check **Depth Encoding** is **White Near**, which matches both depth nodes. Use **Black Near** only for maps where near is dark.
4. Set **Output** to **False Colour Focus** to see which areas are in focus.
5. Adjust **Focus Depth** (the normalized depth that stays sharp) until your subject is in focus, and **Focus Range** to widen or narrow the sharp zone.
6. Set **Near Blur** and **Far Blur** for the strength in front of and behind the focus plane, and **Max Radius** for the largest bokeh in pixels.
7. Choose an **Aperture**: **Disc**, **Blades**, **Heart**, **Star**, **Ring**, or **Image** (uses a picture connected to **Kernel**). Raise **Highlight Gain** to make bright points bloom into bokeh shapes.
8. Set **Output** back to **Result**. Switch **Quality** to **High quality** for the final frame.

Other **Output** views help you debug: **Depth View** shows the depth as read, **Blur View** shows blur amount, **Kernel** shows the aperture shape, and **Layer Setup** shows how depth is split into layers.

## Stage 4: Add distance haze with Depth Atmosphere

1. Press `Tab` and add **Depth Atmosphere**.
2. Connect the ZDefocus output to **Image** and the depth Compositor Input to **Depth**.
3. Set **Start** and **End**, the normalized distances where atmosphere begins and reaches full strength.
4. Set **Air Density** for how thick the fog is, **Maximum Opacity** to cap the haze, and **Air Colour** to tint it.
5. Choose **Falloff**: **Exponential**, **Linear**, or **Custom** to draw your own **Falloff Curve**.
6. Optionally, in the grade and diffusion controls, use **Exposure**, **Contrast**, and **Saturation** to change distant tones, **Image Diffusion** to soften distant detail, and **Highlight Bloom** to spread light from bright areas.
7. Use **Output** views such as **Fog Mask**, **Distance Influence**, or **Atmosphere Only** to check coverage, then return to **Result**.

## Stage 5: Output and download

1. Connect the Depth Atmosphere output to **Compositor Output**, replacing the default connection.
2. Press `U` to return to the parent graph.
3. Select the Image Compositor to see the result in the Design panel, then right-click it and choose **Download**.

## Check the result

- Look at subject edges. ZDefocus spreads foreground blur past object edges; turn on **Edge Anti-aliasing** if edges look stepped.
- Set Depth Atmosphere **Output** to **Fog Mask** and check that coverage grows toward the distance and stays off the subject.
- Select the original image and the Image Compositor together to compare them as A and B in the Design panel.

## Variations

- **Video shots.** Use **Depth Anything V3 Video** to make a depth clip, and the **Compositor** (video) node instead of Image Compositor.
- **Haze without refocus.** Skip ZDefocus and connect the image straight to Depth Atmosphere. Depth Atmosphere also works outside a compositor.
- **Limit the effect to part of the frame.** Both nodes accept an optional mask; set **Mask Source** and **Invert Mask** as needed.
- **Generated stills.** Start from an [Image Generator](https://docs.nodespell.com/creative-tools/image-generator/) result and keep its take fixed before you build the depth chain.

## Frequently asked questions

### Why is the wrong part of the image blurred?

The depth encoding is probably inverted. Both Nodespell depth nodes put near surfaces in white, so ZDefocus and Depth Atmosphere should use **White Near**.

### Does changing ZDefocus or Depth Atmosphere use credits?

No. They are image-processing nodes. Only generating the depth map uses credits.

### Why can't I add ZDefocus in the main graph?

ZDefocus is available only inside a compositor. Enter an Image Compositor or Compositor first. Depth Atmosphere works in both places.

### Is the depth map a real distance?

No. Both depth nodes produce relative depth, not distances in meters. Use **Depth Min** and **Depth Max** on ZDefocus or Depth Atmosphere to remap the range you need.

## Related

- [Depth and defocus](https://docs.nodespell.com/edit/depth-and-defocus/) — every depth, defocus, and atmosphere control
- [Compositing](https://docs.nodespell.com/edit/compositing/) — compositor inputs and outputs
- [Viewers](https://docs.nodespell.com/edit/viewers/) — inspect channels and compare results
- [Composite and finish existing images](https://docs.nodespell.com/recipes/composite-and-finish/) — the compositor basics
