Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Camera+depth of field

  • Camera+depth of field

    Posted by Paolomart on March 4, 2008 at 7:53 pm

    Hi everybody.
    I have a question on using expressions for depth of field and camera.

    I often use the expression “length” in order to link the depth of field to the position of the camera and the position of the object I want to be on focus.

    As for example>

    length (thisComp.layer(“Layer Name”).transform.position, transform.position)

    where the first transform.position is referred to the layer I want to be on focus and the second to camera position.

    What I-d like to know is if it-s possibile to change the focus on a different layer through expression in order to have a change of focus,
    Let-s say you have a layer on focus in the front and you want to change the focus on a layer on the back, so that the one in the front will be then out of focus.
    And besides I-d like to know if there-s a way to set the velocity of this change in focus.

    Hope I am clear enough 🙂

    Thank you.
    Paolo

    Paolomart replied 18 years, 2 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    March 4, 2008 at 11:27 pm

    You could use something like this (not tested, so there might be typos):

    strtFocusChg = 4; // start at 4 seconds
    focusChgDur = 2; // focus change duration
    d1 = length (thisComp.layer(“Layer 1”).transform.position, transform.position);
    d2 = length (thisComp.layer(“Layer 2”).transform.position, transform.position);
    ease(time,strtFocusChg, strtFocusChg + focusChgDur, d1,d2)

    Dan

  • Paolomart

    March 5, 2008 at 2:22 pm

    Thanks Dan.
    I’ll try as soon as I can.

    Paolo

  • Darby Edelen

    March 5, 2008 at 8:51 pm

    I just did something like this. In my case I only had 2 layers I was changing focus between so I created a Null (“Focus Control”) with 2 layer control effects applied and 1 slider control applied (it’s important that they be created in that order for this expression). The goal was to focus on the first layer control layer when the slider was at 0 and the second when the slider was at 1. Here’s the code I applied to the focus property:


    m = 300; //minimum focus distance
    a = thisComp.layer("Focus Control").effect(3)("Slider"); //The slider that determines which layer is in focus

    l1 = thisComp.layer("Focus Control").effect(1)("Layer"); //The first layer to focus on
    l2 = thisComp.layer("Focus Control").effect(2)("Layer"); //The second layer to focus on

    c = toWorld([0,0,0]); //The camera's position
    p1 = l1.toWorld(l1.anchorPoint); //The first layer's position
    p2 = l2.toWorld(l2.anchorPoint); //The second layer's position
    p = linear(a, 0, 1, p1, p2); //When the slider on the Focus Control layer is at 0 or below use the first layer's position, when it is at 1 or above use the second layer's position

    v1 = p - c; //The v1 vector is the vector between the layer's position and the camera's position
    v2 = toWorldVec([0,0,1]); //The v2 vector is a vector pointing down the camera's z axis
    v = dot(v1, v2); //Project the v1 vector onto the v2 vector (thanks Dan!)
    Math.max(m, v); //Return the larger of either 'm' or 'v'

    Since the camera began far behind the layers to focus on, in my case, I needed a minimum value for the focus. So I created the ‘m’ value to contain a minimum value, you could put a value that works better for you in there.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Paolomart

    March 5, 2008 at 10:07 pm

    This is pretty nice.
    I wonder if could be applied to 3 or more layers like to have a handheld camera effects.

    Paolo

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy