Hey everyone,
I need an expression that will allow a layer to be brighter or darker in relation to the distance it is away from the camera ie. it will darken the further from the camera it gets and vice versa. It only needs to relate to the z position, x and y aren't relevant.
If anyone can help it would be much appreciated.
Regards, Jase.........
expression connecting brightness/cont to camera position(z)
camSource=thisComp.layer("Camera").position;
footSource=thisComp.layer("Footage").position;
minDist=0;
maxDist=500;
minBright=0;
maxBright=100;
distance=length(footSource,CamSource);
darken=linear(distance,minDist,maxDist,maxBright,minBright);
Tie to whatever parameter you need (opacity, brightness effect etc.)
Mylenium
footSource=thisComp.layer("Footage").position;
minDist=0;
maxDist=500;
minBright=0;
maxBright=100;
distance=length(footSource,CamSource);
darken=linear(distance,minDist,maxDist,maxBright,minBright);
Tie to whatever parameter you need (opacity, brightness effect etc.)
Mylenium
[Pour Mylène, ange sur terre]
-
- Posts: 6
- Joined: January 8th, 2008, 6:10 pm
Cheers buddy, that really did the trick...
I created a new comp and added a red solid and a camera.
I set the 3D checkbox on the red solid. (cube switch)
I selected the red solid and pressed the T-KEY to reveal the opacity value. for the red solid.
I ALT-Clicked on the stop watch.
I pasted this code into the expression box.
I pressed the numberpad enter key to lock the expression into place.
NOTE:If your red solid is named something other than "Red Solid 2" you will get an expression error message, simply correct the name of the solid and or camera as needed to match your comp.
Use the camera Track-Z tool to zoom the camera in and out. The red solid will fade in and out as the camera distance changes.
Because this expression returns a number between minBright and maxBright (in this case 0-100 i.e. a percentage) you can use this expression on any animatable parameter that requres a percentage range. Transition complete comes to mind, but I'm sure there are others as well.
Thanks for the code Mylenium!
I set the 3D checkbox on the red solid. (cube switch)
I selected the red solid and pressed the T-KEY to reveal the opacity value. for the red solid.
I ALT-Clicked on the stop watch.
I pasted this code into the expression box.
Code: Select all
camSource=thisComp.layer("Camera 1").position;
footSource=thisComp.layer("Red Solid 2").position;
minDist=1000;
maxDist=2500;
minBright=0;
maxBright=100;
distance=length(footSource,camSource);
darken=linear(distance,minDist,maxDist,maxBright,minBright);
NOTE:If your red solid is named something other than "Red Solid 2" you will get an expression error message, simply correct the name of the solid and or camera as needed to match your comp.
Use the camera Track-Z tool to zoom the camera in and out. The red solid will fade in and out as the camera distance changes.
Because this expression returns a number between minBright and maxBright (in this case 0-100 i.e. a percentage) you can use this expression on any animatable parameter that requres a percentage range. Transition complete comes to mind, but I'm sure there are others as well.
Thanks for the code Mylenium!
"Up And Atom
No...No
Up And At Them!"
No...No
Up And At Them!"
Hi Atomic,
I tried to use this expression with filter, for example BLUR or any other filter, just for test, but i could not find the expression, because filter are not percentage , could you help me a bit for use a filter and connect with this expression
thanks
rolita
I tried to use this expression with filter, for example BLUR or any other filter, just for test, but i could not find the expression, because filter are not percentage , could you help me a bit for use a filter and connect with this expression

thanks
rolita
rolita,
I applied the Lens Bur effect to a layer. I decided to control the parameter Blur Focal Distance. I scrubbed the parameter and discovered that is has a range of 0-255. I set minBright to 0 and maxBright to 255. I played around with different value for minDist and maxDist. You will have to do the same to tune the expression to your needs.
With the above expression applied, as I dolly my camera in z-space, my layer blurs and un-blurs as the camera approaches.
There are also other interpolation methods you can use instead of the linear function.
http://livedocs.adobe.com/en_US/AfterEf ... -7a06.html
I applied the Lens Bur effect to a layer. I decided to control the parameter Blur Focal Distance. I scrubbed the parameter and discovered that is has a range of 0-255. I set minBright to 0 and maxBright to 255. I played around with different value for minDist and maxDist. You will have to do the same to tune the expression to your needs.
Code: Select all
camSource=thisComp.layer("Camera 1").position;
footSource=thisComp.layer("Red Solid 2").position;
minDist=500;
maxDist=750;
minBright=0;
maxBright=255;
distance=length(footSource,camSource);
darken=linear(distance,minDist,maxDist,maxBright,minBright);
There are also other interpolation methods you can use instead of the linear function.
http://livedocs.adobe.com/en_US/AfterEf ... -7a06.html
"Up And Atom
No...No
Up And At Them!"
No...No
Up And At Them!"