Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions calculate angle between camera and light

  • calculate angle between camera and light

    Posted by Barend Onneweer on April 11, 2008 at 12:47 pm

    Hi all,

    I’m trying to do the following:

    I have a camera and a light in a scene. I’ve added a lensflare (Knoll Light Factory) to the light (converting 3D position data to 2D coordinates).

    Now I want to link the brightness of the flare to the angle of the light in relationship to the position of the camera:

    If the light points into the camera the flare should be 100. And when the light turns away from the camera the brightness should fade to zero.

    I think it should work something like this: if the camera is on or close to the ‘line of sight’ of the light, the outcoming value should be 100. And if there’s a bigger angle between the ‘line of sight’ of the light, the outcoming value should decrease.

    But my combination of math and scripting skills prevent me from cracking this. Anyone?

    Thanks in advance for any help.

    Bar3nd

    Raamw3rk – digital storytelling and visual effects

    Barend Onneweer replied 18 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Filip Vandueren

    April 11, 2008 at 1:15 pm

    Dag Barend,

    this should work:


    l=thisComp.layer("Light 1");
    c=thisComp.activeCamera;
    vec1=normalize(l.transform.position - c.position);
    vec2=l.toWorld([0,0,-1]) - l.position;

    dotProduct = dot(vec2, vec1);

    linear(dotProduct,-.25,1,0,1) * value;

    the dot-product will return a value between 1: pointing directly in the camera to -1 pointing exactly away.

    You should tweak the values in the linear function:
    if you change to -.25 to a zero: the flare will disappear when the light shines 90° to the focal plane, Depending on the kind of light ‘enclosure’ you’re simulation, you could try other values.

  • Barend Onneweer

    April 11, 2008 at 2:37 pm

    That is so cool!

    Works great, thank you so much!

    Bar3nd

    Raamw3rk – digital storytelling and visual effects

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy