Skip to main content
Known Participant
May 15, 2015
Question

Using an expression to change focus distance three times in one composition (rack focus effect)

  • May 15, 2015
  • 2 replies
  • 759 views

Hello all,

I'm running AE CC 2014. I know next to nothing about expressions, but I've been experimenting with them to try and find a way to create a rack focus effect on a photo that I cut up into several layers using Photoshop.

I'm working in 3D, and I'm changing my camera's positioning to zoom in and pan around the image. As I zoom from layer to layer, I want to create a rack focus effect by changing the value of the camera's focus distance.

I found an expression that allows me to keep the focus distance locked onto one layer, and then I found another expression that builds on the first one and allows for one rack focus between two layers after a few seconds:

target1 = thisComp.layer("people left/painting cutup.psd");

target2 = thisComp.layer("Middle man 1/painting cutup.psd");

tStart = 6;

tEnd = 7;

d1 = length(thisComp.layer("people left/painting cutup.psd").transform.position[2],transform.position[2]);

d2 = length(thisComp.layer("middle man 3/painting cutup.psd").transform.position[2],transform.position[2]);

ease(time,tStart,tEnd,d1,d2,)

My problem is that I don't know how to build on that expression and add a second rack focus to a third layer. I really don't even know where to start - does anyone have any advice?

Many thanks.

This topic has been closed for replies.

2 replies

Mathias Moehl
Community Expert
Community Expert
May 16, 2015

If you don't want to write your own expressions code, you can also use the Autofocus on Layers iExpression as you can see in this tutorial

(the part about Autofocus on Layers starts at 5:35)

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Dan Ebberts
Community Expert
Community Expert
May 15, 2015

I haven't tested this code, but it should look something like this:

tStart1 = 6;

tEnd1 = 7;

tStart2 = 10;

tEnd2 = 11;

d1 = length(thisComp.layer("people left/painting cutup.psd").transform.position[2],transform.position[2]);

d2 = length(thisComp.layer("middle man 3/painting cutup.psd").transform.position[2],transform.position[2]);

d3 = length(thisComp.layer("xxxxx/painting cutup.psd").transform.position[2],transform.position[2]);

if (time < tEnd1)

ease(time,tStart1,tEnd1,d1,d2)

else

ease(time,tStart2,tEnd2,d2,d3)

Dan