ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Saxon Rix
Tint layer based on distance to camera, How to make it based on Z only?
on Jul 31, 2015 at 4:32:22 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);


Return to posts index

Xavier Gomez
Re: Tint layer based on distance to camera, How to make it based on Z only?
on Jul 31, 2015 at 4:51:24 pm

Try change the line:

fDist=length(mCam,mPos);

with:

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


Xavier.


Return to posts index

Dan Ebberts
Re: Tint layer based on distance to camera, How to make it based on Z only?
on Jul 31, 2015 at 5:38:03 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



Return to posts index


Saxon Rix
Re: Tint layer based on distance to camera, How to make it based on Z only?
on Aug 2, 2015 at 10:16:55 am

Dan, That is perfect thank you!


Return to posts index

Rich Birket
Re: Tint layer based on distance to camera, How to make it based on Z only?
on Jan 5, 2018 at 5:03:06 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]