Monday 28 January 2013

Reduce Saturation Away From Camera


Reduce Saturation Away From Camera

Let’s change gears a little. You want to create an expression
that reduces a layer’s saturation as it moves away from the
camera in a 3D scene. In addition, you want this expression
to work even if the target layer and the camera happen
to be children of other layers. You can accomplish this by
applying the Color Balance (HLS) effect to the target layer
and applying this expression to the Saturation parameter:
minDist = 900;
maxDist = 2000;
C = thisComp.activeCamera.toWorld([0,0,0]);
dist = length(toWorld(transform.anchorPoint), C);
ease(dist, minDist, maxDist, 0, -100)
The fi rst two lines defi ne variables that will be used to set
the boundaries of this effect. If the target layer’s distance
from the camera is less than minDist, you’ll leave the
Saturation setting unchanged at 0. If the distance is greater
than maxDist you want to completely desaturate the layer
with a setting of -100.
The third line of the expression creates variable C, which
represents the position of the comp’s currently active
camera in world space. It’s important to note that cameras
and lights don’t have anchor points, so you have to convert

a specifi c location in the camera’s layer space. It turns out
that, in its own layer space, a camera’s location is represented
by the array [0,0,0] (that is, the X, Y, and Z coordinates
are all 0).
The next line creates another variable, dist, which represents
the distance between the camera and the anchor
point of the target layer. You do this with the help of
length(), which takes two parameters and calculates the
distance between them. The fi rst parameter is the world
location of the target layer and the second parameter is the
world location of the camera, calculated previously.
All that’s left to do is calculate the actual Saturation value
based on the layer’s current distance from the camera. You
do this with the help of ease(), one of the expression language’s
amazingly useful interpolation methods. What this
line basically says is “as the value of dist varies from minDist
to maxDist, vary the output of ease() from 0 to –100.”



No comments:

Post a Comment