FORUMS: list search recent posts

Hide layer if not seen by camera

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chad Specter
Hide layer if not seen by camera
on Aug 31, 2017 at 7:50:39 pm

Hi all. I would like to hide all layers that are not seen by the camera. I'm currently using the following expression from Dan Ebberts to hide layers behind the camera.

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

This works fine, but it still leaves a lot of layers visible in my comp. I'd like to hide layers that are long the camera's vector but not seen by the actual camera viewport if possible.


Return to posts index

Chad Specter
Re: Hide layer if not seen by camera
on Aug 31, 2017 at 9:49:35 pm

Solved my own problem. For those who are interested you you will need to use toComp(). This converts the layer coordinates to the camera space coordinates. Then, given any z depth, the viewport position matches the pixel dimensions in your comp size. So, for example, if you are using a 1920x1080 comp, the x value of the left edge of the screen is always 0 and the y value of the right is always 1920, no matter what the z value is. I added a variable in my code to allow for objects with an anchor point slightly out of the viewport to still be visible.


ext = .2;
width = thisComp.width;
height = thisComp.height;
minWidth = 0 - (width * .2);
maxWidth = width + (width * .2);
minHeight = 0 - (height * .2);
maxHeight = height + (height * .2);
z = Math.ceil(Math.abs(toComp([1,1,1])[2]));
x = Math.ceil(toComp([1,1,1])[0]);
y = Math.ceil(toComp([1,1,1])[1]);
isInViewport = (x > minWidth && x < maxWidth) && (y > minHeight && y < maxHeight);

isInFrontOfCamera = toCompVec([0, 0, 1])[2] > 0;

if (isInFrontOfCamera && isInViewport ) {
this.opacity = 100;
} else {
this.opacity = 0
}


Return to posts index

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