Skip navigation
Currently Being Moderated

Decreasing Layer Opacity with Distance from Camera

Sep 17, 2012 12:55 AM

Is there a way to automatically decrease layer opacity as a layer moves away from a camera?

  • Currently Being Moderated
    Sep 17, 2012 1:05 AM   in reply to 420jammer

    Sure, a simple expression will do:














    Adjust values as needed...



    Mark as:
  • Currently Being Moderated
    Sep 19, 2012 10:56 PM   in reply to 420jammer

    Not sure what you are saying. If you get specific warnings, post them. Otherwise adjusting the values should do.



    Mark as:
  • Currently Being Moderated
    Sep 21, 2012 2:03 AM   in reply to Mylenium

    Let's break down the thought process for the expression and see if we can get it to work for you.


    First you need to measure the distance between the camera and the layer. The After Effects Expression Language Menu has a method we can use under vector math that measures the distance between two points. Use the camera for one point and the layer's position for the other and we have the first number.


    Now we need to decide what we want the opacity to do in relation to the distance. When the layer is the same distance from the camera as the zoom value it will be at the equivalent of 100% scale. This may be a good place to have the layer be fully visible. That distance is easily set by assigning the fully visible distance to the Active Camera's zoom value. Next we need to decide how far away the layer should be when it's fully invisible (opacity = 0). Personally, I think the easiest way to do this is to use a multiplier for the zoom value. 4X with most lens settings is a pleasing distance.


    To set up the relationship between distance and maximum opacity you can use one of the Interpolation methods from the Expression Language Menu. We'll use the method with maximum and minimum values.


    Let's put that together in an expression. The two methods to use are


    length(point1, point2)

    linear(t, tMin, tMax, value1, value2)


    Define some variables for each of the values and we're done:


    point1 = thisComp.activeCamera.position;
    point2 = position;
    tMin = thisComp.activeCamera.zoom;
    tMax = tMin * 4;
    value1 = 100;
    value2 = 0;
    t = length(point1, point2);
    easeIn(t, tMin, tMax, value1, value2)


    If you really want to get fancy then you can add a layer space transformation to the camera and to the layer so that the expression would work the same with or without parent layers for the camera and/or the layer. The toWorld modification looks like this:


    point1 = thisComp.activeCamera.toWorld([0,0,0]);
    point2 = thisLayer.toWorld(anchorPoint);


    By the way, I usually use more descriptive and shorter names for the variables but thought this would make it easier to understand what was going on in the expression. I also usually use Active Camera for my expressions rather than thisComp.layer("Camera 1") because it works no matter what you've named your active camera.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points