Brendan Dawes
Analogue + Digital

Visually Setting the Depth of Field Focal Point in Houdini

When using Depth of Field in Houdini, I've always found it a little frustrating that you can't visually set a focal point for the camera, like you can in many other pieces of similar software.

Born out of my frustration, I searched the Houdini forums to see if anyone had found an elegant way to do this. Sure enough, a user called Tamte from Method Studios in New York posted a great solution on the Sidefx forum, which I wanted to make a note of here for future reference.

The technique involves creating a piece of geometry called focus_target, on the same level as the camera. This object, which you can visually move around the scene to where you want your focus to be, is then referenced using some Vex in the Sampling > Focus Distance parameter of the camera settings like this:

vlength(vtorigin(".", "../focus_target/");
Setting the focus distance with Vex
Using Vex to set the focus distance
Moving the focal point
Moving the focal point

This magic bit of code measures the distance of the focus_target object to the camera and uses that to set where the camera is focussing when you have Depth of Field turned on in the render settings. It works perfectly as you can see from the two images below. This first has the focus set near the camera, the second set in the distance. The lower the f-stop, the more shallow the Depth of Field.

Focus set to near the camera
Focus set nearer the camera
Focus set to further from the camera
Focus set further from the camera