Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Checking to see which ‘side’ of a layer the camera’s seeing…

  • Checking to see which ‘side’ of a layer the camera’s seeing…

    Posted by Waldemar Werbel on January 15, 2007 at 12:27 am

    Hi all.

    I know that there are plenty of work-arounds to this – parenting with a 1 pixel seperation in the z axis etc, but (for the sake of expanding my knowledge regarding expressions) humour me, if you will…

    Imagine I have a comp containing 2 layers running the length of the entire precomp – for the sake of argument let’s say that they’re a ‘front_face’ and a parented ‘back_face’ of a playing card. If the ‘front-face’s opacity is at 100, then the ‘back-face’s is automatically set to 0 with the expression:

    if(thisComp.layer(“front_face”).opacity == 0) 100 else 0

    applied to the opacity parameter of the ‘back-face’.

    Here’s the tricky part – getting the opacity of the ‘front_face’ to pop to 0 when it has ‘turned away’ from the camera and thereby triggering the opacity of the ‘back_face’ to pop to 100 and take over. Okay, if we assume that the layer only rotates once in the Y axis, and that it’s sitting directly in front of the camera (and that the camera isn’t rotated off axis in any way) then it’d be fairly straight forward – I guess you’d use the expression:

    if(rotationY < 90) 100 else if(rotationY > 270) 100 else 0

    on the opacity parameter of the ‘front_face’ (no doubt there’s a better way of expressing this, but for all intents and purposes I’m pretty much an expression newbie…)

    As we all know, things aren’t always as straighforward as layers rotaing just the once in only one axis, and once you’ve added a moving camera into the mix it gets ever more complicated – so here’s the crux of my question – is there an expression that looks something like layerFront=visible or do we need to get into complicated formulae testing for a layers orientation relative to the camera?

    Apologies for the long-winded nature of this post, and yes, I understand that using an expression to tackle this sort of elementary problem is a bit sledgehammer/nut, but I thought it’d be interesting to see how it’s done.

    Ahem. At the risk of looking foolish when Dan comes back with a solve-all one line piece of code…

    Warmest regards.

    Waldemar Werbel replied 19 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Mike Clasby

    January 15, 2007 at 1:07 am

    Make the layers 3D, but leave them with the same exact position numbers, parent 2 to 1, and add these Opacity expressions to make the layer invisible when the camera is on it’s backside.

    To layer 1.

    a = toWorldVec([0,0,1]);
    b = thisComp.layer(“Camera 1”).position – toWorld(anchor_point);
    c = dot(a,b)/length(b);
    if (c > 0) 0 else 100

    Then this expression on the second layer down:

    a = toWorldVec([0,0,1]);
    b = thisComp.layer(“Camera 1”).position – toWorld(anchor_point);
    c = dot(a,b)/length(b);
    if (c < 0) 0 else 100 The only difference between the two is the direction of the > (or) < These are Dan expressions from earlier posts.

  • Waldemar Werbel

    January 15, 2007 at 8:41 am

    Thanks Yikes.

    I did search for a while, but my terms must’ve been off mark. Just found the ‘solve-all one line piece of code’ –

    if (toCompVec([0, 0, 1])[2] > 0 ) value else 100

    Once again (after my ramble) I’m amazed at how succinct the expression is. Amazing.

    Thanks again.

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