AE tip. fade object with camera distance.
- At April 24, 2007
- By ken
- In design / tech
I’m building a piece at the moment that requires some 30-40 layers to be positioned in 3d space. I want them to fade in to view as they approach the camera. Sure, you can do this by hand, but that would be tedious, and what if you want to change it as the composition progresses? Enter expressions. Found this article on the AE site.
I modified it slightly, mapping the startFade and endFade parameters to a null with slider expression control so I can easily control the distances on a global scale. The final expression:
startFade = thisComp.layer("control").effect("close")("Slider"); // Start fade 500 pixels from camera.
endFade = thisComp.layer("control").effect("far")("Slider"); // End fade 1500 pixels from camera.
try{ // Check whether there's a camera.
C = thisComp.activeCamera.toWorld([0,0,0]);
}catch(err){ // No camera, so assume 50mm.
w = thisComp.width * thisComp.pixelAspect;
z = (w/2)/Math.tan(degreesToRadians(19.799));
C = [0,0,-z];
}
P = toWorld(anchorPoint);
d = length(C,P);
linear(d,startFade,endFade,100,0)