Posts Tagged ‘after effects’

Expression-based motion trail in After Effects

Monday, January 7th, 2013

I was recently working on a motion graphics piece that involved numerous shape and text layers.  One of the effects I was going for was to have part of a logo flying around with a motion trail behind it.  Unfortunately, the Echo filter built into After Effects didn’t quite achieve the look I was going for: while it would duplicate the graphic element multiple times and fade off a little bit with adjustments to the decay rate, I was also wanting the motion trail to shrink in size.  It also introduced number of issues with 3D layer elements in After Effects, so suffice it to say that I needed another solution.  I’ve been dabbling with expressions in After Effects and after some tinkering around, I was able to use them to get the exact look I wanted as well as built in controls to adjust the effect very easily.

This tutorial has two sections: First, we’ll build the basic effect with the Echo filter, then we’ll build it again with the added functions and controls through expressions.

Start with a new, empty composition.  Draw out an ellipse at the center of the composition, then move it to the left.  Set a few animation keys to have it go from left to right, putting ease on both frames.  (Fig. A) To have this behavior mirror and repeat, we’re going use a very simple expression.  Alt+Click on the stop watch by the Position attribute and type in:


Fig. A

After entering this expression, the circle should move from left to right, then right to left, and repeat until the end of your composition (Fig. B).

Fig. B

Now to apply the echo filter, located in Effects -> Time -> Echo.  I’ve adjusted some of the settings to get some opacity falloff.  (Fig C)  These settings are pretty self explanatory, though one thing to keep in mind is to keep the Echo Time very very small and set to a negative; if you set it as a positive, it’ll look forward in the timeline for the position of the circle and draw a motion trail based on that (which could also be a useful look, depending on what you need).  However, you’ll notice that the repeated instances of the circle are very hard-edged.  Correct this by adding a Fast Blur effect and setting the amount as needed to get a smooth look.   (Fig. D)

Fig. C

Fig. D

At this point, we have the basic look: a soft motion trail that decays over time.  For some situations this may work just fine, but in addition to wanting the instances to decrease in scale, this may cause issues with 3D effects if elements are flying in and out of the composition.  While I’m not entirely sure what is happening, my best guess is that the Echo effect takes a 2D snapshot of the layer and applies the effect based on that.  Instead, let’s have the motion trail directly reference the layer transform data with expressions.

Delete the Echo effect on the circle layer.  Create a new null layer, move it to the very top, and rename it “trailControl”.  Apply three Slider Controls (Effect -> Expression Control -> Slider Control) to the layer and set them as shown in Figure E.  (Click on a slider control and hit Enter to rename it; the naming conventions have to match this tutorial exactly if you want to follow along.)  Right now this null object isn’t doing anything, but we’ve built in some controls so that it can later influence the look of the motion trail.

Fig. E

Next, duplicate the circle layer, then Alt+Click on the stopwatch by its Position attribute and then regular-click on the stopwatch again to delete all animation keys.  If you scrub the timeline, the circle on layer 2 will move but the one on layer 3 will remain stationary.  To make the third layer act as a motion trail, Alt+Click on the stopwatch a third time and enter in the following expression:

timeOffset = thisComp.layer(“trailControl”).effect(“trailPositionTimeOffset”)(“Slider”);


If your After Effects throws up an error, make sure the name of the circle layer matches what’s in the expression.  In my case, the layer was called ‘Circle’; yours may be different, so make sure they match.  Once everything is set up properly, when you click on the third layer and scrub through the timeline you’ll see that it’s ever-so-slightly behind the second layer.  (Fig. F) The effect will become more apparent if you duplicate the third layer multiple times. (Fig. G)  With the expression we made earlier, we’ve told After Effects to take the position of Circle (the circle we initially drew) at a fraction of a second earlier (as defined by the trailPositionTimeOffset slider on the trailControls layer) and apply that to the current layer.  This offset cascades downward (this is what the ‘index – 2’ is for; it uses the current layer’s number but subtracts the two layers above it from the calculation) as you duplicate the layer; in this case, each subsequent duplicate of this layer will be another 0.01 seconds behind.

Fig. F

Fig. G

Confused yet?  No?  Good, let’s move on, as we need to program in more expressions for opacity and scale.

Delete all layers in this comp except for the first three (the trailControl, Circle, and one of the duplicates [in my case Circle 2]).  Open up the Opacity for your duplicate circle, Alt+Click on the stopwatch, and apply the following expression:


Math.pow(opacityOffset,index – 2)*100

This expression uses exponential math (Math.pow) to determine the opacity of the layer.  First it references the number programmed into the trailOpacityOffset slider on the trailControl layer, then raises that to the power of the current layer number (minus two, to ignore the two layers above it in the calculation).  For this first duplicate, it’s 0.85 to the first power, which is 0.85.  Duplicate it once and the next copy’s opacity is 0.85 x 0.85, the next is 0.85 x 0.85 x 0.85, and so forth.  (Fig. H)

Fig. H

Lastly, we need to make a cascading expression for the trail’s scale.  Delete all layers except the control, the initial circle, and the duplicate of the initial circle.  Alt+Click on the scale attribute of the duplicate and enter this expression:


[Math.pow(scaleOffset,index - 2)*100,Math.pow(scaleOffset,index - 2)*100]

This one’s a little different because Scale consists of two values: X and Y.  This is why the second line of the expression is in brackets and has the same entry repeated with a comma between them: the first instance is applied to the X axis, the latter to the Y (ie: [x,y]).  Were we working on a 3D layer, we’d have to copy and paste the entry for a third time to account for Z (i.e. [x,y,z]).  Duplicate this layer multiple times and you should notice the subsequent duplicates becoming smaller.  (Fig. I)

Fig. I

From here, you can adjust the look of the motion trail in a number of ways with the trailControl layer.  You can adjust how far back in time the trail extends by increasing or decreasing the trailPositionTimeOffset, adjust how much the trail shrinks with the trailScaleOffset, and adjust how quickly it fades away with the trailOpacityOffset.  Note that you might also need to make or decrease the number of duplicate layers in the comp: if the opacity of the bottommost layer is extremely low you might not even see it, or if it’s too high then you need more duplicates as the trail may appear to simply stop instead of fade.  Either way, play with it until you get the look you want.

That’s the end of this tutorial.  There are many additional levels of control you can build into this motion trail rig once you get the hang of how the math and syntax work, so I highly recommend you read up on expressions as they’re extremely powerful and can simultaenously speed up and improve the quality of your work. Thanks for reading!

Click here to return to the blog
Click here to go to the front page

Tutorial – Light fog in After Effects – Part 2

Monday, November 12th, 2012

In part 1 of this tutorial, we went through rendering and setup of the composite for a scene with a light fog effect to be made in After Effects. Next we’ll take the 3D movement data from Maya and apply that to the CC Light Burst effect so that the light fog emanates from the right place.

For those of you who skipped the first part as you only want the tracking tutorial, the first thing you’ll need is a Maya scene. I’ll be working from the sample scene I provided in part 1 of this tutorial, but make sure your scene at least have the following:

• A camera with animation keys
• A locator snapped to the same position as the light source that emits the fog. (If you have multiple sources you want to track then have a locator for each one, but for the sake of this tutorial I’m only operating as if one is present.) If the light source moves, then be sure the locator moves with it (a point constraint works well for this).

Next, you’ll need to convert the camera and locator data into a format that After Effects can use:

• Rename your camera to ‘camera1’ and your null to ‘null1’
• Select your camera and locator, then go to Edit -> Keys -> Bake Simulation (use default options)
• With the camera and locator still selected, go to File -> Export Selection and export to an alternate version of this sequence. Be sure you set the format to ‘Maya ASCII’ (.ma).
• Open this .ma file to make sure everything appears right. Your scene should consist ONLY of the camera and locator. (If you use a camera with aim and such, the camera group and camera aim nodes are okay to have around; at this point they’re redundant, but they aren’t harming anything. Just make sure the camera itself is only receiving information from the animation keys after the simulation is baked.)

The next step is to bring this information into After Effects.

• Import the .ma file into After Effects. This should create a new composition with the name of the file you imported which contains a cameraShape1, a nullShape1, and any extraneous nodes (mine included a camera1_group node but I deleted it as it wasn’t doing anything).
• The camera and null1 will have animation keys for each and every frame. (Figure 7) Feel free to remove any keys that aren’t necessary. I’d leave the camera alone, but if your light source is completely stationary (ie: it’s the camera that moves, not the light or other tracked objects), there’s no sense in having After Effects process animation keys on the null1 node.
• Rename this composition to ‘tracking’

Fig. 7

Once you’re sure the composition works properly, it’s time to make it into something the After Effects tracker can use.

• Create a black solid that covers the entire composition. There should be no transparency present in the composition. Set it as the bottommost layer in this comp.
• Create a white solid and drop it into your scene. Hit your Toggle Switches / Modes button, make the layer 3D and set its anchor point to 0,0,0. Pick-whip the white solid layer so that it’s parented to follow your nullShape1 layer. Set its position to 0,0,0. (Figure 8 )
• By now the top-left corner of the white solid layer should be matched up with the top-left corner of nullShape1, however the white solid should look very large and, depending on your specific scene, be very blurry. This is because the nullShape1 is, by default, scaled way too large. Correct this by scaling it down to a very small number (my scene was set to around 0.1%). The end result should have the white solid look like a relatively small, crisp-edged square that will be easy to track. (Figure 9)

Fig. 8

Fig. 9

Now your composition should be set up such that the camera moves in 3D and the white solid appears to be a flat 2D plane facing “forward” (towards the camera, but at an angle depending on the camera’s position/rotation). Let’s use After Effects’ tracking tools to convert the position of the top-left corner of the solid (or more specifically, the position of the null1Shape node which matches the light source) into 2D information that can then be pumped into a 2D layer or effect.

• Drop your ‘tracking’ composition into ‘fogComp’. With the tracking layer selected, go to Animation -> Track Motion
• Drag the very center of your track point to the top-left corner of the white box. A square around the center point will show you a zoomed-in view to help ensure good placement.
• In the Tracker pane, click the forward button on Analyze to track the motion. Make sure you’re at the first frame of your composition (or where you would otherwise like the tracking to start). After Effects will move forward through the sequence and apply a keyframe to the tracker for each frame. (Figure 10)

Fig. 10

At this point you can hide the tracker layer. Now to link the Center of the CC Light Burst to this tracking data.

• Hit the drop-down menu on your adjustment layer, open the CC Light Burst effect, then hold the Alt key while hitting the stop watch next to the Center attribute
• Click the pick-whip on this expression menu and drag it to the Feature Center of your tracking layer’s Motion Tracker. (Figure 11)

Fig. 11

Now if you scrub through the timeline, you should notice that the Center attribute of your CC Light Burst effect is moving in place with the motion tracker. (Note that your computer may respond slowly; you can help improve performance by changing your Resolution to Half, Third, or even Quarter.) If you go back to your mainComp, this will map forward to the final composite. (Figure 12)

Again, this is a very specific application of this type of 3D -> 2D motion tracking, but there are tons of other uses for this. Want pop-up labels to move with the camera? Simulate sprites without dynamics? Fireflies in the background during a night scene? Go nuts!

I hope this was helpful. If you have any questions, please leave me a note in the comments section or shoot me an email at Thanks for reading!

Click here to return to the blog
Click here to go to the front page

Tutorial – Light fog in After Effects – Part 1

Thursday, November 1st, 2012

I’ve had a lot of fun tinkering around with various tricks in After Effects to see how I could integrate them into my 3D renders. One visual effect I was trying to work with recently was light fog: the idea was to have a stationary prop placed in front of a bright light, only visible by its silhouette, with light fog casing around its shape. I know how to do this in Maya, however I wanted to do it in post due as tweaking the effect in the 3D software to get the desired look can require a lot of guesswork and be slow to render. The basic look is easy enough to accomplish in post with the CC Light Burst effect, except that although the prop itself was stationary, the camera itself moves in the Maya sequence: the center point of the light burst would have to move in 3D space, and CC Light Burst is a 2D effect. I was eventually able to get this work by taking locator and camera data from Maya, tracking that locator data, and then transferring the 2D coordinates from the tracker to the CC Light Burst effect.

Confused yet? I’ll start from the beginning.

This tutorial is split into two parts: the first part will focus on rendering and compositing your Maya scene for the light fog effect described above, and the second part will walk through how to take the 3D placement data from your Maya scene and track it using After Effects.

First, you need a Maya scene. I’ve provided a very basic scene with a cube, a bright mental ray area light, a polygonal ground plane, and a camera with animation keys. (Figure 1). I’ve also set up the proper render layers for this tutorial, though to understand the workflow I’d recommend deleting the render layers and following along. This workflow should work with any scene, but be sure you have the following as they’ll be needed for tracking in After Effects:

• A camera with animation keys
• A locator point-constrained to the light source (the point constrain is only necessary if the light source itself moves.Otherwise, snap the locator so it’s placed in the exact same position as the light). If you have multiple light sources or objects you want to track, you’ll need a locator for each one.

Fig. 1

With the scene ready, it’s time to set this up for rendering. For the light fog effect, you’ll need these three render layers:

• A beauty pass
• An RGB matte pass with the cube and ground plane assigned to different colors
• An RGB shadow pass that will serve as a matte for the light fog effect. This will be used to luma mask the CC Light Burst effect so that it doesn’t show in front of the cube within its shadow.

The beauty pass is simple enough. For this scene, the default masterLayer will suffice.

For the RGB matte, select the poly cube and the ground plane and assign them to a new render layer called ‘rgb_matte’. Assign a pure red surface shader to the cube and a pure green surface shader to the ground plane. (Figure 2) We’ll use this to key the box out in After Effects.

Fig. 2

The RGB shadow pass layer is a little tricky. I’ve had difficulty using Maya’s and mental ray’s shadow pass systems, however Jeremy Birn has a very excellent tutorial on the setup and merits of making an RGB shadow pass. The best workflow I’ve found is to duplicate the light source (rename it to some variant of ‘shadow light’ to avoid confusion), hide the primary light, turn off any decay that may be present (this is why we duplicate the light; you can’t use layer overrides for decay rate), apply Jeremy Birn’s workflow for making a shadow pass, and set the value of its shadow color to a very high level (I used 100). (Figure 3) The result should have very strong contrast between black and whatever primary color you choose, though the look can be tweaked in After Effects with color correction effects when we key the background out.

Fig. 3

With everything ready, batch render the sequence and bring those renders into After Effects. Make sure the alpha settings are set properly: the RGB shadow pass will need to have its alpha ignored to be properly luma keyed later. Drop the beauty pass into its own composition and name this composition “mainComp”.

We’ll be building a separate composition specifically for the fog effect. To start this, drop in the beauty pass. (We’ll only be using it as a visual guide and this will be hidden at the very end.) Rename this comp to ‘fogComp’. Next, drop in a white solid, then drop in the rgb_matte render. We’ll need to apply a Set Matte effect to the rgb_matte layer and set its ‘Use For Matte’ to red channel. Next, select the white solid and set its track matte to alpha. At this point, your composition should look like the beauty pass with an additional white box covering the cube. (Figure 4) If everything looks lined up properly, you can hide the beauty pass layer in fogComp.

Fig. 4

Next, we need to build the light fog effect. First, create a new adjustment layer and also drag on the RGB shadow sequence, placing it above the adjustment layer. Apply a Set Channels effect to the RGB shadow layer and set all color sources to whatever color channel you set as the shadow color in Maya (in my case, green). Then, select the adjustment layer, set its track matte to Luma Inverted, and apply a CC Light Burst effect. Tweak the Intensity and Ray Length as desired. The result should have the white cube visible with light fog extending around its edges, except for where its shadow on the ground plane would be obstructing it. (Figure 5)

Fig. 5

Everything looks good so far, however the light fog should be going around the box; the box itself shouldn’t be lit. To fix this, drag on a black solid and the RGB matte. Re-apply the Set Matte effect to the RGB matte layer like we did a few minutes ago to isolate the red cube, then apply this as an alpha track matte to the black solid we just placed. There should now be a black ‘cutout’ where the box was, however there may be a thin white line going around the bottom edge of the box. To fix this, go down to the rgb matte layer that’s affecting the white solid layer and apply a Minimax effect, setting its operation to Minimum, its radius to 1, and the channel to Alpha. This should remove the thin white line. (Figure 6)

Fig. 6

From here you can tweak the look of the light fog. For starters, you can add a Levels effect to the RGB shadow layer to adjust the spread of the light fog onto the ground plane, or you can apply some Gaussian blur effects to the RGB matte layers to soften the edge of the fog.

Now to apply this light fog effect our mainComp. Go to mainComp and drop the fogComp on top of it, sending its blend mode to Screen. If you scrub through your timeline you should now have the silhouette of the cube with light fog being cast from its edges, however there’s no directionality to the light fog: it’s always being emitted from the very center of the composition. For stills or sequences with minimal camera movement you can move the Center attribute of the CC Light Burst effect and be done with it, but for complex sequences or animations where the camera moves a lot this may not be practical.

In the next part of the tutorial, we’ll go over how to take the animation data already in Maya and apply that to a 2D effect in After Effects. If you have any questions about this part of the workflow, shoot me an email at or leave a note in the comments section. Thanks for reading!

Click here to return to the blog
Click here to go to the front page