Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions camera near/far fade

  • camera near/far fade

    Posted by Greg Brannen on August 28, 2008 at 8:43 pm
    startFade = 500; // Start fade 500 pixels from camera. 
      endFade = 1000;  // End fade 1500 pixels from camera. 
      try{ // Check whether there's a camera. 
          C = thisComp.activeCamera.toWorld([0,0,0]); 
      }catch(err){ // No camera, so assume 50mm. 
          w = thisComp.width * thisComp.pixelAspect; 
          z = (w/2)/Math.tan(degreesToRadians(19.799)); 
          C = [0,0,-z]; 
      } 
      P = toWorld(anchorPoint); 
      d = length(C,P); 
      linear(d,startFade,endFade,100,0)

    HI.

    I am trying to fade objects based on their distance to the camera.
    I found an expressions that fades as the object moves away from the camera but I need it to also fade as it gets near the camera.

    Thanks for any help.

    Michiel Wesselius replied 14 years, 2 months ago 4 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    August 28, 2008 at 11:55 pm

    This should do it:

    startFadeNear = 300;
    endFadeNear = 500;
    startFadeFar = 800;
    endFadeFar = 1500;
    try{ // Check whether there’s a camera.
    C = thisComp.activeCamera.toWorld([0,0,0]);
    }catch(err){ // No camera, so assume 50mm.
    w = thisComp.width * thisComp.pixelAspect;
    z = (w/2)/Math.tan(degreesToRadians(19.799));
    C = [thisComp.width/2,thisComp.height/2,-z];
    }
    P = toWorld(anchorPoint);
    d = length(C,P);
    if (d < endFadeNear){ linear(d,startFadeNear,endFadeNear,0,100) }else{ linear(d,startFadeFar,endFadeFar,100,0) } Dan

  • Greg Brannen

    August 29, 2008 at 12:51 am

    Wow! Great to have a community like this.
    Nice to have someone who knows what they are doing out there.

    Thanks for your help.

    I really appreciate it.

    Thanks again Dan,

    Greg

  • Danny Jenkins

    May 10, 2010 at 8:24 am

    Hi Dan, first of all thanks for all the time you put into helping us out on here!

    Now this one from above isn’t working for me in AE CS4:

    startFadeNear = 300;
    endFadeNear = 500;
    startFadeFar = 800;
    endFadeFar = 1500;
    try{ // Check whether there’s a camera.
    C = thisComp.activeCamera.toWorld([0,0,0]);
    }catch(err){ // No camera, so assume 50mm.
    w = thisComp.width * thisComp.pixelAspect;
    z = (w/2)/Math.tan(degreesToRadians(19.799));
    C = [thisComp.width/2,thisComp.height/2,-z];
    }
    P = toWorld(anchorPoint);
    d = length(C,P);
    if (d
    linear(d,startFadeNear,endFadeNear,0,100)
    }else{
    linear(d,startFadeFar,endFadeFar,100,0)
    }

    After Effects warning: Expected: )
    Expression disabled.
    Error occurred at line 15.

    Just need this expression to fade in AND out in relation to distance from camera! Thanks again for any help!

    Danny

  • Dan Ebberts

    May 10, 2010 at 1:58 pm

    It looks like the 14th line got chopped off when I posted the expression. Change it from this:

    if (d

    to this:

    if (d < startFadeFar){ Dan

  • Danny Jenkins

    May 10, 2010 at 11:17 pm

    Thanks Dan! Didn’t know how much luck I’d have digging this up from’08 haha.

    I found your expression site as well, hope to see you still working on it, it looks great!

    Danny

  • Michiel Wesselius

    March 19, 2012 at 3:02 pm

    the correction doesn’t appear to work in 5.5.
    Is this possible or am i missing somthing?

  • Dan Ebberts

    March 19, 2012 at 3:48 pm

    I can’t think of a reason it wouldn’t work in 5.5. Are you getting an error message? If not, is the expression doing anything?

    Dan

  • Michiel Wesselius

    March 19, 2012 at 4:06 pm

    Sorry, it appears my browser didn’t preview the correction properly, now it works correctly. Thanks1

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