After Effects Opacity Expression - What It Is & How To Use It

The opacity expression in After Effects is a powerful tool that allows you to control the transparency of a layer. Read more on what Opacity expression is and how to use it

November 26, 2024
After Effects Opacity Expression - What It Is & How To Use It
Video Editing On Steroids!
ULTIMATE Tools for creating high-quality video content
15M+ Assets
for After Effects, Premiere Pro, FCPX & DaVinci!

Opacity Expression In After Effects

What is the Opacity Expression?

In the context of animation, video editing, or graphic design tools like Adobe After Effects, an Opacity Expression refers to a mathematical or scripting formula applied to the opacity property of an element to create dynamic or automated changes in transparency.. The opacity expression is essentially a way to generate random values for the property it's applied to. This might sound simple, but there are different variations of this expression in After Effects that offer unique ways of controlling randomness.

Opacity controls how visible an object is, with values typically ranging from 0% (completely invisible) to 100% (fully visible). Using expressions, you can programmatically control this property to achieve effects that would be tedious or impossible to create manually.

How to Use the Opacity Expression:

  1. Select the Layer: In After Effects, find the layer you want to adjust.
  2. Locate the Opacity Property: This can be found in the timeline panel. If it's not immediately visible, you might need to twirl down the properties of the layer.
  3. Activate Expressions: Hold down the 'Alt' key (or 'Option' on macOS) and click on the stopwatch icon next to the opacity property. This will activate the expressions option.
  4. Enter the Expression: In the field that appears, you can type or paste in the desired expression.

Types of Random Expressions:

  1. Basic Random: The most straightforward form is random();. For instance, random(50); will return random opacity values between 0 and 50 every frame.
  2. Range Random: You can define a range for the random values, like random(40,75);, which will generate random opacity values between 40 and 75.
  3. Gaussian Distribution: This is a more advanced form, gaussRandom();, which gives a natural randomness based on a bell curve, making some values more likely than others.

Common Uses of Opacity Expressions

  1. Fading Effects:
    • Gradually make an object appear or disappear over time.
  2. Interactive Transparency:
    • Link opacity to another property, such as the position of an object or user interaction.
  3. Random Flicker:
    • Create a blinking or flickering effect by randomizing opacity values.

Examples of Opacity Expressions in After Effects

Fading Over Time
Automatically fade out an element over 3 seconds:

  • linear(time, 0, 3, 100, 0)
    • At time = 0 seconds, opacity is 100%.
    • At time = 3 seconds, opacity decreases to 0%.

Random Flicker
Create a light flickering effect:

  • random(30, 100)
    • The opacity randomly fluctuates between 30% and 100%.

Link to Another Property
Link opacity to the vertical position (y) of an object:

  • linear(position[1], 0, 500, 0, 100)
    • The opacity randomly fluctuates between 30% and 100%.

Looping Fade
Make the opacity fade in and out repeatedly:

  • Math.abs(Math.sin(time * 2)) * 100;
    (This makes the opacity oscillate between 0% and 100% over time, creating a pulsating effect.)
    • The opacity oscillates between 0% and 100% over time

Basic Random

This expression will return random opacity values between 0 and the value you set.

random();

Range Random

This expression will generate random opacity values between the two values you set.

random(40,75);

Gaussian Distribution

This expression gives a natural randomness based on a bell curve.

gaussRandom();

Controlling the Randomness:

To have consistent random movements every playback, use the seedRandom method. This sets the "seed" value, dictating which random pattern After Effects should use. For instance, seedRandom(20, timeless = false); followed by gaussRandom(20,100); will give you controlled randomness.

Pro Tip: Instead of manually setting a seed value every time, you can use the layer's number as the seed. Simply use seedRandom(index, false); where "index" is the layer number.