Matching Rack Focus In Nuke

A useful technique for matching the rack focus from the plate to your CG/elements… 

Matching Rack Focus In Nuke

A useful technique for matching the rack focus from the plate to your CG/elements… 

If you're struggling to accurately match the rack focus in a plate, here's a technique that usually helps: 

First, find the sharpest frame of the plate, and FrameHold it. By sharpest, I mean where the plate is in focus in the area (on the same focal plane) where you’ll be inserting your CG/element. 

For example, if the rack focus goes from focusing on the foreground to focusing on the background, and you'll be placing an object in the foreground, the sharpest frame means where the plate is fully focused on the foreground. 

Then, go to the most out-of-focus frame of the plate. Look for a bokeh or another feature that clearly displays the defocus in the area where you'll be inserting your object. This can for example be a light, a window, or some other distinct shape, which when defocused clearly blooms/smudges out to a different shape. 

Next, either set up two Viewers or A/B wipe between the frameheld sharp frame and the defocused frame. View the same bokeh/feature that you picked earlier, in both Viewers. 

💡
If there is a camera move, you may have to transform or reproject the sharp frame to line it up with the defocused frame. 

Now, add your defocus node of choice to the frameheld sharp frame. Increase the defocus value until the feature that you picked matches between this frame and the defocused frame. (If you're trying to match a bokeh, you'll need a matching bokeh kernel input for your ZDefocus, this tutorial shows how to extract one). 

💡
You can use the Viewer Sampler to measure the size of the bokeh in pixels to get an exact match. Press Ctrl/Cmd + Alt/Option + Shift and left-mouse-button drag out the red sample box around the bokeh. At the bottom of the Viewer it will say the dimensions of the box. 

Example of matching the bokeh size. 

Next, at this most defocused frame, set a keyframe on the defocus value. Then, go to the sharpest frame and keyframe the defocus value to 0 (or the minimum value). 

💡
Animate your defocus value in between and/or outside of these two keyframes as necessary. The rack focus may not be perfectly linear, so make sure to follow what the plate is doing. 

You can now detach your defocus node from the frameheld frame and attach it to your (sharp) CG render or element, and they should match up to the plate in terms of the rack focus. 

Note that if you’re using a ZDefocus or similar defocus node with depth information, you’ll also/instead need to animate the focus plane value so that the focus (focal plane) will move correctly across your object. On the sharpest frame, sample your CG/element’s depth using the focal_point sampler in the Viewer, and set a keyframe on the focus plane value. Then, on the most out-of-focus frame, sample or input the new focus plane value, and set another keyframe. Animate the value as needed in between/outside of these two keyframes.

💡
If you're using a ZDefocus node and the animated rack focus looks steppy, uncheck automatic layer spacing, and manually increase the number of depth layers. (Additionally, a layer curve value of 0 will evenly space out the depth layers. Positive values will concentrate the layers closer to the in-focus region, while negative values will concentrate the layers far from the focal plane, towards the maximum blur size. Adjust as needed). 

The great thing about using this technique is that you can often pretty easily get a perfect match. Because you are defocusing the same scene as the real lens did, and you already have a reference for what it should look like. 

Focus Breathing 

During a rack focus you may get (more or less subtle) focus breathing in the plate. 

Focus breathing, also known as lens breathing, refers to a change in the apparent focal length when adjusting the focus, causing the image to appear slightly zoomed in or out.

If your CG/element looks like it's sliding slightly over the plate during the rack focus, you may need to counter-animate the movement with a Transform node for it to stay aligned. 

You can achieve that by applying a Transform node to your CG/element, with the center point set to the centre of your image, and adjusting the scale value by a very small amount. 

Using Real Life Metadata 

A final tip:

If you have access to it, you can use the real life camera and shoot information to drive your rack focus. 

By linking a ZDefocus node to real camera values and metadata from the shoot (distance from the camera to the object in focus), the focus will be calculated for you automatically. 

Several tools have been built that can do this, such as PxF_ZDefocus, OpticalZDefocus or k_ZDefocus

💡
If you're lucky, you may even get focal plane metadata in your source plate which you can plug into the focus plane value of the ZDefocus node directly.

I hope you found this tutorial useful. For more Nuke tips & tricks, see Nuke.