ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Link Light intensity to Camera Position

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ben Mason
Link Light intensity to Camera Position
on Sep 7, 2018 at 3:10:10 pm

Hi,
I really hope someone can help me with this...

I'm trying to create lights attached to the surface of an earth model that will fade out when they are on the far side of the sphere (based on distance from camera).

So I have parented lights to 3D nulls generated in Element3D - these nulls are in turn parented to a single null that controls the earth's rotation.
The only way I can think of to 'hide' the lights when they are on the far side of the earth is to link their intensity to the distance from camera via an expression.

The lights are referenced by co-pilot's Optical Flares plugin, but the 'Foreground layer' workaround wouldn't work in this instance as the lights would be obscured when they are on either side of the earth, only when they are on the horizon would they be visible.

Hope that makes sense.
So looking for an expression that will dim a light when it gets to a certain distance from the camera, even if the light is parented to a null.

Thanks in advance

Ben Mason
motionographer
London
UK


Return to posts index

Dan Ebberts
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 7:54:58 pm

It's hard to picture exactly how you have things set up, but would it make sense to have the light dim when the angle formed by the camera, earth center null, and the light is greater than 90 degrees? Also, over what range should it dim (I mean, it doesn't just turn off as soon as it crosses the threshold, right?)


Dan



Return to posts index

Ben Mason
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 8:33:26 pm

Thanks for getting back to me Dan, much appreciated.
That sounds like a very clever solution - hadn't thought of that
re: set up
Here is a still

I plan to cut between multiple camera angles of the earth, which is why I am keen to have a solution that doesn't involve keyframing multiple lights on and off for each shot.

Set up is...
Element 3D sphere - linked to master null for rotation, position, scale
Parented to that master null are 20 city location nulls (positioned and aligned to the earth's surface)
Also parented to that master null are 20 lights, with same position data as each of the city nulls
Each light represents as a flare courtesy of Optical Flares
Problem is that lights on the far side of the planet show up on this side.
So I thought that if they reached the horizon line of the earth I could reduce the light's intensity and they would effectively fade out before they cross the horizon line.
I found an expression for reducing a layer's opacity based on distance from camera but this requires an anchor point for the layer and lights don't have one? It's in the box below


start = thisComp.layer("Control").effect("FadeStart")("Slider");

end = thisComp.layer("Control").effect("FadeEnd")("Slider");



CameraPos = thisComp.activeCamera.toWorld([0,0,0]);

LayerPos = toWorld(anchorPoint);

Difference = length(CameraPos, LayerPos);

linear(Difference, start, end,0,100);


Ben Mason
motionographer
London
UK


Return to posts index


Dan Ebberts
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 8:56:40 pm

For lights and cameras, just use [0,0,0] instead of anchorPoint.

Dan



Return to posts index

Dan Ebberts
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 10:03:20 pm

If you wanted to try the 90 degree angle thing, you could set it up like this:

thisComp.activeCamera.toWorld([0,0,0]);
LayerPos = toWorld([0,0,0]);
earthNull = thisComp.layer("Earth Null");
EarthPos = earthNull.toWorld(earthNull.anchorPoint);
v1 = CameraPos - EarthPos;
v2 = LayerPos - EarthPos;
angle = radiansToDegrees(Math.acos(dot(normalize(v1),normalize(v2))));
linear(angle,85,95,100,0)

(it assumes there's a layer named "Earth Null" at the center of the earth). Adjust the last line to change the angle range where the fade occurs.


Dan



Return to posts index

Dan Ebberts
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 10:04:56 pm

Ooops... I messed up the first line. Should be like this:

CameraPos = thisComp.activeCamera.toWorld([0,0,0]);
LayerPos = toWorld([0,0,0]);
earthNull = thisComp.layer("Earth Null");
EarthPos = earthNull.toWorld(earthNull.anchorPoint);
v1 = CameraPos - EarthPos;
v2 = LayerPos - EarthPos;
angle = radiansToDegrees(Math.acos(dot(normalize(v1),normalize(v2))));
linear(angle,85,95,100,0)


Dan



Return to posts index


Ben Mason
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 10:33:38 pm

Thank you Dan, looks great - really appreciate you looking at this!

Do you mind if I get back to you tomorrow afternoon if I have any queries?
Currently on another project deadline for tomorrow.

Ben Mason
motionographer
London
UK


Return to posts index

Dan Ebberts
Re: Link Light intensity to Camera Position
on Sep 7, 2018 at 10:53:11 pm

Not a problem. Fire away.

Dan



Return to posts index

Ben Mason
Re: Link Light intensity to Camera Position
on Sep 8, 2018 at 2:18:27 pm

Hi Dan,

So I've renamed the main null as 'Earth Null' and applied the expression to one of the lights - is that correct? do I need to do anything else?

I'm getting an odd error message


any thoughts?

Ben Mason
motionographer
London
UK


Return to posts index


Dan Ebberts
Re: Link Light intensity to Camera Position
on Sep 8, 2018 at 4:38:30 pm

Sometimes expressions will break because the active camera is undefined at times before zero. See if either of these help:


if (time >= 0){
CameraPos = thisComp.activeCamera.toWorld([0,0,0]);
LayerPos = toWorld([0,0,0]);
earthNull = thisComp.layer("Earth Null");
EarthPos = earthNull.toWorld(earthNull.anchorPoint);
v1 = CameraPos - EarthPos;
v2 = LayerPos - EarthPos;
angle = radiansToDegrees(Math.acos(dot(normalize(v1),normalize(v2))));
linear(angle,85,95,100,0);
}else{
value;
}



try{
CameraPos = thisComp.activeCamera.toWorld([0,0,0]);
LayerPos = toWorld([0,0,0]);
earthNull = thisComp.layer("Earth Null");
EarthPos = earthNull.toWorld(earthNull.anchorPoint);
v1 = CameraPos - EarthPos;
v2 = LayerPos - EarthPos;
angle = radiansToDegrees(Math.acos(dot(normalize(v1),normalize(v2))));
linear(angle,85,95,100,0);
}catch(e){
value;
}



Dan



Return to posts index

Kalleheikki Kannisto
Re: Link Light intensity to Camera Position
on Sep 11, 2018 at 2:37:27 pm

As an alternate solution you can use a lightmap on a (hidden) duplicate layer of the Element 3D sphere as the source for Optical Flares. The lightmap is a texture that has white dots where you want light sources and otherwise black. With recent AE versions you can use the result directly or in earlier version you need to precompose with a linked camera. Use "Luminance" as source type in Optical flares and select the lighmap E3D layer. No expressions required with this method.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

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