Page 1 of 1

expression connecting brightness/cont to camera position(z)

Posted: January 9th, 2008, 4:07 pm
by jasonmorice
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.........

Posted: January 10th, 2008, 4:28 am
by Mylenium
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

Posted: January 10th, 2008, 8:10 pm
by jasonmorice
Cheers buddy, that really did the trick...

Re: expression connecting brightness/cont to camera position(z)

Posted: July 29th, 2008, 5:12 am
by Cptzap
Hi!

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

-Cptzap

Re: expression connecting brightness/cont to camera position(z)

Posted: July 29th, 2008, 5:50 am
by Atomic
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!

Re: expression connecting brightness/cont to camera position(z)

Posted: July 29th, 2008, 6:58 am
by Cptzap
Ah! Superb! This is really a handy expression..:)

Thanx!

- Cptzap

Re: expression connecting brightness/cont to camera position(z)

Posted: August 3rd, 2008, 2:56 am
by rolita
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

Re: expression connecting brightness/cont to camera position(z)

Posted: August 3rd, 2008, 6:00 am
by Atomic
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

Re: expression connecting brightness/cont to camera position(z)

Posted: August 3rd, 2008, 9:39 am
by rolita
UUAUU!! so fast answer, thanks a lot, i'm gonna try right now!!
thanks again :D

rolita