Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Opacity of a layer in relation to the camera

  • Opacity of a layer in relation to the camera

    Posted by Hamish Gilbert on August 28, 2010 at 3:03 am

    Hi. I understand how expressions work but I am not very familiar with the syntax or how you integrate variables from different objects into one expression. Hopefully there is an answer to this:

    I want to create a movie in which the camera flies straight ahead through a cluster of images and videos all randomly positioned in z-space. I want each video to fade to transparent as the camera approaches within a certain distance so you can alway see what is behind it.

    I can fade out the opacity manually but it’s proving to be very time consuming, especially if I re-position all my images and videos in z-space.

    Is there an expression which can determine the distance between the camera and an object, then adjust the opacity of the object so that when the camera is within say, 100 pixels of it and approaching 0, it fades the object’s opacity from 100% to 0% accordingly…..?

    I would probably eventually want to be able to adjust the distance at which the object starts to fade so if you could further explain this I’d be pretty grateful.

    I hope I’m making sense!

    Thanks in advance.

    H

    Dan Ebberts replied 10 years, 3 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    August 28, 2010 at 4:40 am

    Try this:

    startFade = 100;
    endFade = 50;
    C = thisComp.activeCamera;
    d = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
    linear(d,endFade,startFade,0,100)

    It should starting fading the layer when it gets within 100 pixels of the camera and be completely faded by the time it gets within 50;

    Dan

  • Hamish Gilbert

    August 28, 2010 at 6:11 am

    Thanks Dan, it worked perfectly. I just have one another question. I now want to fade the images in slowly when they are in the distance, hold them at 100% opacity until they are within 1000 pixels to the camera and then fade them out again. I can work out how to fade them in or out and adjust the point at which the transition starts and ends, but I can’t get both expressions to work when both applied to the object. One seems to cancel the other out. Is there a way to integrate both expressions into one?

    Thanks!!

    H

  • Dan Ebberts

    August 28, 2010 at 5:58 pm

    Try this:


    fadeInStart = 5000;
    fadeInEnd = 3000;
    fadeOutStart = 1000;
    fadeOutEnd = 50;

    C = thisComp.activeCamera;
    d = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
    if (d > fadeInEnd)
    linear(d,fadeInEnd,fadeInStart,100,0)
    else if (d > fadeOutStart)
    100
    else
    linear(d,fadeOutEnd,fadeOutStart,0,100);

    Dan

  • Hamish Gilbert

    August 29, 2010 at 7:46 am

    Aha, thanks Dan, it looks like it makes sense, will try it now. Thanks very much for the help

    HG

  • Nelson Rayner

    January 27, 2016 at 4:16 pm

    Hi guys,

    I have a composition with a camera panning around several pre-comped images (in Z position) which (with the help of this script) get more transparent the further they are away from the camera.
    I have to zoom in on specific images within the pre comps, some of which are at the outer areas of the pre comps. Unfortunately this script uses the distance between the anchor point of the pre-comp and the camera, so when panning out towards the edge of a comp onto an image, the pre-comp becomes more transparent due to the distance becoming greater.

    Is there any work around for this??

    Any help would be greatly appreciated.

    Thanks 🙂

  • Dan Ebberts

    January 27, 2016 at 7:38 pm

    Try it this way:

    fadeInStart = 5000;
    fadeInEnd = 3000;
    fadeOutStart = 1000;
    fadeOutEnd = 50;

    C = thisComp.activeCamera;
    v1 = toWorld(anchorPoint) – C.toWorld([0,0,0]);
    v2 = C.toWorldVec([0,0,1]);
    d = dot(v1,v2);

    if (d > fadeInEnd)
    linear(d,fadeInEnd,fadeInStart,100,0)
    else if (d > fadeOutStart)
    100
    else
    linear(d,fadeOutEnd,fadeOutStart,0,100);

    Dan

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