Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Tint layer based on distance to camera, How to make it based on Z only?

  • Tint layer based on distance to camera, How to make it based on Z only?

  • Saxon Rix

    July 31, 2015 at 4:32 pm

    Hi Guys, I’m using this expression on the tint effect in order to desaturate layers when further away from the camera. However it is also desaturating the layers when they are moved further from the camera in X & Y space. Is there any way for the expression to only desaturate the layers when moved away from the camera in Z space?

    Thanks!

    mCam=thisComp.layer("Camera 1").transform.position;
    mPos=thisLayer.transform.position;
    minDist=7150;
    maxDist=8200;
    fDist=length(mCam,mPos);
    fOpa=linear(fDist,minDist,maxDist,0,100);

  • Xavier Gomez

    July 31, 2015 at 4:51 pm

    Try change the line:

    fDist=length(mCam,mPos);

    with:

    fDist=Math.abs(mCam[2],mPos[2]);

    Xavier.

  • Dan Ebberts

    July 31, 2015 at 5:38 pm

    This might be what you’re looking for:

    C = thisComp.layer(“Camera 1”);
    mCam=C.transform.position;
    mPos=thisLayer.transform.position;
    minDist=7150;
    maxDist=8200;
    v = mPos-mCam;
    zDist = dot(v,C.toWorldVec([0,0,1]));
    fOpa=linear(zDist,minDist,maxDist,0,100);

    Dan

  • Saxon Rix

    August 2, 2015 at 10:16 am

    Dan, That is perfect thank you!

  • Rich Birket

    January 5, 2018 at 5:03 pm

    I thought I would respond to this thread than begin another as I think my question relates. I am a relative newcomer to AE and am fumbling my way through. Expressions and scripts are quite new to me. I have a scene of a lot of cutouts of people (numerous 3d layers at different ‘z’ distances to the camera). This is how it looks at the moment:-

    At the moment, all my people are tinted the same, but I would like to be able to desaturate and lighten the people out the further they are from my camera. This is basically what I am trying to achieve:-

    Could anyone explain exactly how I should do this please?

    Kind Regards,
    Rich

Viewing 1 - 5 of 5 posts

Log in to reply.

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