Lighten layers based on distance from camera. Fog?

What type of scripts do you need?

Moderator: byronnash

Post Reply
Posts: 10
Joined: February 25th, 2009, 1:34 pm

So what I'm hoping to achieve here is a simple way to automatically lighten background 3d layers based on their distance from the 3D after effects camera. My goal is to have a way to mimic something like this photo.


Hoping to achieve an atmospheric effect in which subjects far from the camera/eye are gradually lightened - perhaps even desaturated a bit. I'm sure there's a better way to describe this but the picture above should help. I can obviously do this by hand, but with 30-50 3d layers in my comp I'm hoping to apply an expression that automates this a bit more. I think using the hue/saturation effect or maybe just a levels effect will get me the results I'm looking for on a per/layer level.

I think it would be pretty amazing to have this included with a 3D camera in much the same way that depth of field works. It would be incredibly useful to just have a checkbox for this. In Maya I suppose this would be a volumetric effect or a way to add distance based fog.

Any suggestions? Thank you!!!
Posts: 13
Joined: March 2nd, 2012, 10:10 am

Sounds like you need an expression that calculates the distance in 3d space from the camera to the layer in question. Hopefully this equation helps you:
Define your two points. Point 1 at (x1, y1, z1) and Point 2 at (x2, y2, z2).
xd = x2-x1
yd = y2-y1
zd = z2-z1
Distance = SquareRoot(xd*xd + yd*yd + zd*zd)
Once you have that you can just paste whatever effect you want to use for the lighting and add the expression to alter its value as a function of distance. You'd need some way of setting your min and max distance values, kind of like setting a focal length for depth of field. Lastly when using coordinates to calculate distance make sure to use their world position, otherwise things like parenting will throw it off. Here's a link for how to get those values in expressions:

P.S. One you have figured out your effect and expression, there's nothing stopping you from applying it to all selected layers via a script. Best of luck!
Posts: 10
Joined: February 25th, 2009, 1:34 pm

Thanks so much for the info/advice and the expression. I'm going to take a crack at integrating this into my comp soon. Since a pesky deadline was forcing my hand, I just created two semi-transparent white 3D layers separated in z space to do a quick and dirty fog. Works for now, but I can see how this could be used for many things in the future. Thanks so much!
Post Reply