distance from camera expression issues...

Moderators: Disciple, zlovatt

Post Reply
chris dC
Posts: 3
Joined: July 25th, 2007, 11:14 am

July 25th, 2007, 12:17 pm

i posted this originaly on creative cow.

i'm trying to measure z space distance between the camera and an object layer, converting that distance into a percentage, then applying that percentage to an effect.

first method i used was toWorld and linear;

C = thisComp.activeCamera.toWorld([0,0,0]); // Cam position
x = thisComp.activeCamera.position[0]; // Cam x position
y = thisComp.activeCamera.position[1]; // Cam y position
z = position[2]; // Object z position
P = toWorld([x,y,z]); // Object relative position on the z-axis from Cam
d = length(C,P); // Distance Calculation

linear(d,startFade,endFade,1,Q.effect("Levels (Individual Controls)")("Input White"))

problem is that for some reason scale effects this inversely, i.e. scaling down increases the effect, scaling up the effect decreases. i'm assuming that it's toWorld that's taking scale into effect.

so next i tried using position.value;

c = thisComp.activeCamera.position.value[2];
P = position.value[2];
d = length(c,P);
easeOut(d,startFade,endFade,Q.effect("Levels (Individual Controls)")("Output Black"),0)

great it works,
except for parented layers.
parented layers take on the position relative to the parent layer. the postition.value[2] is not absolute to the world.
no good, can't animate without parenting.

so is there some other position interpolation method or some way to stabilize scale to not effect toWorld?

driving me crazy,
hope you can help,

chris d-_-b
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

July 25th, 2007, 1:11 pm

It doesn't look like you posted the entire expression, but give this a try:

Code: Select all

d = Math.abs(thisComp.activeCamera.toWorld([0,0,0])[2] - toWorld(anchorPoint)[2]);
easeOut(d,startFade,endFade,Q.effect("Levels (Individual Controls)")("Output Black"),0) 
Dan
chris dC
Posts: 3
Joined: July 25th, 2007, 11:14 am

July 25th, 2007, 1:52 pm

Okay, it looks like it's working. wow. thank you.

here's the code

Q=thisComp.layer("atmopheric master control");
startFade = Q.effect("Start Close Up")("Slider");
endFade = Q.effect("End Close Up")("Slider");
d = Math.abs(thisComp.activeCamera.toWorld([0,0,0])[2] - toWorld(anchorPoint)[2]);
easeOut(d,startFade,endFade,Q.effect("Levels (Individual Controls)")("Output White"),1)

Q is a control null with all my FX settings
i'm using a combination of color balance, levels and hue/sat to have objects fade off in the distance and turn black in the foreground.

i'm still wondering why scale effects toWorld.
and what does Math.abs exactly do? the AE scripting help is a little vague.

thanks again,

chris d-_-b
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

July 25th, 2007, 2:30 pm

I think scaling should only affect the results if it causes the Anchor Point to move. What are seeing exactly?

Math.abs() just takes the absolute value and gives you a posative number, like length() does.

Dan
chris dC
Posts: 3
Joined: July 25th, 2007, 11:14 am

July 25th, 2007, 3:02 pm

in the original expression (the one using toWorld) the effect was inversed against the scale of the object.

as in if i increased the scale (grow) of the object it would cause the same effect if i had moved the object further back in z-space away from the camera.
if i decreased the scale (shrink) the object it would cause the same effect if i had moved it closer to the camera.

i originally was usinig the full position [x,y,z] for the effect but it would measure from the anchorpoint and having some offset anchorpoint animated obejcts messed with the effect. so i isolated the [z] but then the nasty scale effect came into play. using just the position was no good for parented objects. as you can guess by now there was alot of kinectic animation and moving camera.

what's with toWorld?

d-_-b
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

July 25th, 2007, 3:20 pm

toWorld() does one specific thing, and that is to convert coordinates from a layer's layer space (where the upper left corner is [0,0,0]) to world space.

So the only thing you would want to feed toWorld() would be coordinates represented in layer space. This is why you always see anchorPoint used instead of position (because a layer's anchor point is always expressed in its layer space).

Feeding it world coordinates (which is what it appears you're doing in your original expression) will lead to unpredictable results.

Dan
rogozyk
Posts: 2
Joined: October 25th, 2004, 3:01 pm
Contact:

September 28th, 2007, 6:31 pm

sorry to be such a newbie with expressions but where do you paste it?
ritka
Posts: 10
Joined: March 25th, 2010, 10:30 am

January 25th, 2013, 10:00 am

How can i reduce the light intensity with distance from camera, if both of the camera and the light is parented to a Null layer?
Dan Ebberts
Posts: 319
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

January 25th, 2013, 5:00 pm

I think lights have included falloff since CS5.5, but if you have an earlier version, you could try something like this:

Code: Select all

decay = .005;
noFalloff = 200;
 
L = thisComp.layer("target");
p1 = L.toWorld(L.anchorPoint);
p2 = toWorld([0,0,0]);
d = length(p1,p2);
if (d < noFalloff){
  value;
}else{
  value/Math.exp((d - noFalloff)*decay);
}
Doing it this way though affects the amount of light from Light 1 falling on other layers as well.

Dan
ritka
Posts: 10
Joined: March 25th, 2010, 10:30 am

January 25th, 2013, 6:07 pm

Unfortunately i have CS4. But this works. :)
Thank you Dan!
Post Reply