expression connecting brightness/cont to camera position(z)

Moderators: Disciple, zlovatt

Post Reply
jasonmorice
Posts: 6
Joined: January 8th, 2008, 6:10 pm

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.........
Mylenium
Posts: 139
Joined: July 20th, 2005, 12:07 am

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
[Pour Mylène, ange sur terre]
jasonmorice
Posts: 6
Joined: January 8th, 2008, 6:10 pm

Cheers buddy, that really did the trick...
Cptzap
Posts: 5
Joined: July 15th, 2008, 5:25 am
Location: Bergen, Norway

Hi!

Where and how to you apply this expression to get that effect?

-Cptzap
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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.

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); 
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!
"Up And Atom

No...No

Up And At Them!"
Cptzap
Posts: 5
Joined: July 15th, 2008, 5:25 am
Location: Bergen, Norway

Ah! Superb! This is really a handy expression..:)

Thanx!

- Cptzap
rolita
Posts: 2
Joined: December 5th, 2006, 6:27 am

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 :D

thanks


rolita
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

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.

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); 
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
"Up And Atom

No...No

Up And At Them!"
rolita
Posts: 2
Joined: December 5th, 2006, 6:27 am

UUAUU!! so fast answer, thanks a lot, i'm gonna try right now!!
thanks again :D

rolita
Post Reply