Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Opacity based on distance to camera redux

  • Opacity based on distance to camera redux

    Posted by Navarro Parker on April 11, 2013 at 4:08 am

    There’s this standard opacity expression. It’s great for getting things to fade off into the distance.

    But what if I wanted it to also fade as layers moves toward the camera also? So there’s this sweet spot zone of where layers are at full opacity — the things behind are fading into the distance, the things in front fade off too, but have a more rapid falloff

    startFade = 500; // Start fade 500 pixels from camera.
    endFade = 1500; // 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)

    Dan Ebberts replied 13 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    April 11, 2013 at 5:37 am

    This should work:

    startInnerFade = 100;
    endInnerFade = 50;
    startOuterFade = 500;
    endOuterFade = 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 > (startInnerFade+startOuterFade)/2)
    linear(d,startOuterFade,endOuterFade,100,0)
    else
    linear(d,endInnerFade,startInnerFade,0,100)

    BTW there was an error (probably mine) in the expression you posted, which I have corrected here.

    Dan

  • Navarro Parker

    April 11, 2013 at 5:27 pm

    Brilliant as always! Thank you! …and you might want to check your email 😉

  • Dan Ebberts

    April 11, 2013 at 6:06 pm

    Thank you–I appreciate it!

    Dan

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