Activity › Forums › Adobe After Effects Expressions › opacity: distance from camera
-
opacity: distance from camera
-
Jeremy Allen
February 18, 2008 at 7:23 pmHey all.. first of all, I’m pretty new to expressions so please bare with me. I understand the concept and it’s alot like actionscripting in Flash, which i have a pretty good grasp on, but there are minor differences that I haven’t quie figured out yet. Anyway, on to the question…
I have a line of 3D pictures in a comp, z-space distributed evenly. This comp is nested into a “MASTER” comp. I would like the pictures to fade opacity as they get further away from the camera in the master comp. So when you first see the pictures, the closest one is opaque, and the furthest one is pretty much transparent. As the line of pictures moves towards the camera, I would like each picture to become more opaque as it gets closer to the camera.
I found this thread which deals with pretty much the same issue: https://forums.creativecow.net/thread/227/8737#8737
I applied this expression to each image’s opacity:
C = comp(“MASTER”).activeCamera;
startFade = thisComp.layer(“opacity controller”).effect(“start”)(“Slider”);
endFade = thisComp.layer(“opacity controller”).effect(“end”)(“Slider”);
d = length(toWorld(anchorPoint),C.toWorld([0,0,0]));
linear(d,startFade,endFade,100,0)The only thing I changed from the other thread was to link the startFade and endFade parameters to a slider, so i would only have to adjust that once.
Now, when I initially set this up, it seemed to work perfectly..
But as I scrub through the timeline, the opacity values don’t seem to update as the image positions change..
So where’s the catch? What am I missing to make this work right? I’m thinking it has something to do with nesting a 3d comp and trying to set the values based on the distance from the camera in the outer comp. I’m not real familiar with the whole “length” and “toWorld” stuff either, so maybe I need to tweak that too, not really sure..
Any ideas from the expression masters out there?
-
Darby Edelen
February 18, 2008 at 10:56 pm[Jeremy Allen] “So where’s the catch? What am I missing to make this work right? I’m thinking it has something to do with nesting a 3d comp and trying to set the values based on the distance from the camera in the outer comp. I’m not real familiar with the whole “length” and “toWorld” stuff either, so maybe I need to tweak that too, not really sure.. “
When you use the toWorld(anchorPoint) function it will return the location of the layer’s anchor point in the local composition’s world space. So if you’re animating the pre-comp with transformations collapsed in the final composition then the positions of the layers never change relative to their position in the ‘world’ of the pre-comp.
One solution would be to animate the layers inside of the pre-comp instead of animating the pre-comp inside of your final composition.
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Jeremy Allen
February 18, 2008 at 11:09 pmAlso, is there a way to delete expressions from several layers at once? I know you can copy an expression, select several layers, hit paste and the expression will be applied to all selected layers. But can you delete expressions from several layers just as easily? If so, I haven’t figured out how yet..
-
Jeremy Allen
February 18, 2008 at 11:16 pmThanks for the help Darby. It seems like that is exactly what is happening. It makes more sense now.. The initial values are assigned and it never updates because they aren’t actually moving in the local comp. Thanks for clearing that up for me.
However, the reason I was using the nested comp was so that I could move all the images easily instead of animating each one individually. Maybe I could parent all the pics to a null and move that inside the “pics” comp. But then I’d have to go back and forth between comps to make sure the positioning was correct.
Is there anyway to modify the expression to work with the setup I have now, or is that just the way it is?
-
Darby Edelen
February 19, 2008 at 12:47 amThe best I can offer for this problem is that ‘ee’ reveals all properties with an expression applied to a layer.
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Darby Edelen
February 19, 2008 at 12:54 am[Jeremy Allen] “Is there anyway to modify the expression to work with the setup I have now, or is that just the way it is?”
I can’t test this right now because I’m rendering, but this may work. You need to add in the offset of the pre-comp’s position in the final composition to the anchor point value:
C = comp("MASTER").activeCamera;
offset = comp("MASTER").layer(thisComp.name).position - comp("MASTER").layer(thisComp.name).anchorPoint;
startFade = thisComp.layer("opacity controller").effect("start")("Slider");
endFade = thisComp.layer("opacity controller").effect("end")("Slider");
d = length(toWorld(anchorPoint + offset),C.toWorld([0,0,0]));
linear(d,startFade,endFade,100,0)
I’m not sure that this code will work (I know it won’t if your pre-comp is parented to any layers in the MASTER comp, so unparent it first if it is), but its the right idea.
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Dan Ebberts
February 19, 2008 at 12:57 amLayer space transforms with nested 3D comps are always tricky (to me at least).
Try this:
startFade = thisComp.layer(“opacity controller”).effect(“start”)(“Slider”);
endFade = thisComp.layer(“opacity controller”).effect(“end”)(“Slider”);
C = comp(“MASTER”).activeCamera;
CL = comp(“MASTER”).layer(thisComp.name);
CL.toWorld(toWorld(anchorPoint));
d = length(CL.toWorld(toWorld(anchorPoint)),C.toWorld([0,0,0]));
linear(d,startFade,endFade,100,0)Dan
-
Darby Edelen
February 19, 2008 at 1:05 am[Dan Ebberts] “CL = comp(“MASTER”).layer(thisComp.name);
CL.toWorld(toWorld(anchorPoint)); “I hadn’t even thought to check and see if it would convert one world space to another… Dan, you rock my world (space)!
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Colin Braley
February 19, 2008 at 1:50 am[Dan Ebberts] “Layer space transforms with nested 3D comps are always tricky (to me at least).”
Dan, if they are always tricky for you they are definitely always tricky for the rest of us.
~Colin Braley
http://www.colinbraley.com -
Jeremy Allen
February 19, 2008 at 5:20 pmFirst up, thanks to both of you for your time and patience. I really do appreciate your help. However…
I tried both of the new solutions and strange enough they both seem to do exactly the same thing. They both seem to work at first, but then as I scrub through the timeline, the opacity values only change 3% from far to near. So the furthest pic starts out at 12% and only goes up to 15% at it’s closest point to the camera. So at least the values are changing but not as much as they should be.
Am I trying to do something impossible here? The code makes sense to me and it seems like it should work, but something just isn’t right. Should I just put a camera in the pics comp and do it that way? I get the feeling that this won’t work at all if I parent the pics to a null for easy animation.
Reply to this Discussion! Login or Sign Up
Log in to reply.