header image of the blog on using After Effects Expressions with Lights

The Ultimate Guide to Using After Effects Expressions with Lights

Published on 16 February 2025

Introduction

Adobe After Effects offers make-a-living kinda tool sets to many graphic artists and motion designers.

One of the most powerful yet underutilized features is After Effects expressions. But, in this site, we have discussed quite a few techniques covering the expressions for Random patterns and Java Script Math Operators in separate pieces.

Expressions are snippets of JavaScript code that can be used to automate and control properties, saving time and adding complexity to your animations. In this article, we’ll explore how to apply After Effects expressions to lights, with some use cases.

I’ll avoid inserting GIF animations which I extensively used before, since they’re heavy and do take longer to load.

Lights in After Effects is a bit tricky to handle. A lot time the beginners find it difficult to handle. I’ll point the things to remember and follow while using the After Effects Expressions with Lights in the following segments.

So let’s jump in.

1. Flickering Light with Math.Sin & Math.Pi added to the Intensity

A few things to remember while using the After Effects Lights.

  • Turn the layers into 3D before creating a Light
  • Use 2-Viewer workspace to check whether your background, objects or Lights are placed correctly

I am sharing a screenshot to show how to set your scene/ composition before using the After Effects Expressions with Lights.

Now, add the following expression to the Intensity of the Point Light you have added to your composition.

flickerFrequency = 5 // Controls how often the light flickers
flickerAmount = 50;    // Controls the intensity variation
baseIntensity = 200;   // Base intensity of the light
baseIntensity + flickerAmount * Math.sin(time * flickerFrequency * Math.PI * 2)

Here is another variation with a Spot light.

freq = 10; // frequency of flicker
amp = 50;  // intensity of flicker
intensity + amp * Math.sin(freq * time * 2 * Math.PI)

2. Light Following a Null Layer – Use After Effects Expression with Light

I have created a Null layer, but parented a Box to the Null show its movement, since a null layer is not visible. And finally add the following expression to the position property of the Light.

target = thisComp.layer("Null 1");
target.toWorld(target.anchorPoint)

So there you are having a decent movement using After Effects Expressions with lights.

3. Color Cycling of a Light – After Effects Expressions with Lights

Pretty simple this one. I have added the following code to the Color property of the point light.

wiggle (4, time)

4. Light Intensity Linked to Audio Amplitude – After Effects Expressions with Lights

Before writing the code, one thing I would like to mention. You have to convert audio into Keyframes by right clicking on the audio layer > Key frame Assistant > Convert Audio to Key Frame

Then add the following code to the Intensity property of Light.

audioLayer = thisComp.layer("Audio Amplitude"); // Replace with your audio layer name
   amplitude = audioLayer.effect("Both Channels")("Slider");
   minIntensity = 50; // Minimum intensity
   maxIntensity = 800; // Maximum intensity
   linear(amplitude, 0, 100, minIntensity, maxIntensity);

5. Light Cone Angle Linked to Audio Amplitude – Use Linear After Effects Expressions with Lights

This instance shows another variation of mapping light intensity to the audio amplitude with linear expression.

The same old set up. A background, a Box and a spot light. One audio layer added and don’t forget ti right click on the audio layer > Key frame Assistant > Convert Audio to Key Frame.

Now add the following expression to the Cone Angle property of the Light.

audioLayer = thisComp.layer("Audio Amplitude"); // Replace with your audio layer name
amplitude = audioLayer.effect("Both Channels")("Slider");
minAngle = 30; // Minimum cone angle
maxAngle = 90; // Maximum cone angle
linear(amplitude, 0, 100, minAngle, maxAngle);

Download the Project File

6. Random Light Movement with Math.sin & Math.cos – After Effects Expressions with Lights

Add the following code to the position property of the Light.

xRange = 500; // Horizontal movement range
yRange = 200; // Vertical movement range
speed = 10;    // Speed of movement
x = Math.sin(time * speed) * xRange;
y = Math.cos(time * speed) * yRange;
[x + thisComp.width / 2, y + thisComp.height / 2]

Adjust the range and the speed as you wish.

7. Light Oscillation in a Sine wave with Math.sin & Math.PI – After Effects Expressions with Lights

I used a spot light in the scene and reduced the cone angle to 35 degree. Finally, I have added the code below to its intensity property.

amplitude = 50;
frequency = 1;
intensity + amplitude * Math.sin(frequency * time * 2 * Math.PI)

Sine function works between -1 and 1. There a regular ups and downs of light intensity might be attained using this expression. Change the amplitude and the frequency to see the effect.

8. Pulse Light Intensity over Time with Math.sin & Ease Expression – After Effects Expressions with Lights

This expression is a variation of the last one with ease expression added.

Like a rotating light house or the beam of a pulsar, this gives much more regular a light pulse. Add the following code to the Light intensity.

pulseSpeed = 5; // Speed of pulse
maxIntensity = 200;
minIntensity = 10;
ease(Math.sin(time * pulseSpeed) + 1, -1, 1, minIntensity, maxIntensity)

Again, play around with the speed, max and min range to see the change.

9. Shadow of an object following the Source by using After Effects Expressions with Lights

In this, I have added one Bulb with transparency and parented its position to the Point Light added. Also, I have created a path or trajectory of the light around the Red Box.

Then I have added Drop Shadow effect to the Box layer. Now the scene is perfectly set for adding the expressions in quite a few properties of the Drop Shadow and map them to the trajectory of the Light/ Bulb.

The idea is to create a shadow that follows the movement of light that casts the shadow of the object. Let’s now add the following piece of codes one after another.

  1. Add the following to the Direction property of Drop Shadow.
light = thisComp.layer("Point Light 1").position;
obj = thisLayer.position;
angle = radiansToDegrees(Math.atan2(obj[0] - light[0], light[1] - obj[1]));
angle; 

2. Add the following expression to the Distance property.

light = thisComp.layer("Point Light 1").position;
obj = thisLayer.position;
maxDist = 500; // Maximum shadow length
dist = length(light, obj);
linear(dist, 0, 500, 10, maxDist);

3. Add the following to the Softness

light = thisComp.layer("Point Light 1").position;
obj = thisLayer.position;
maxSoft = 100; // Maximum blur
dist = length(light, obj);
linear(dist, 0, 500, 5, maxSoft);

10. Changing Color of a Light with its Movement – After Effects Expressions

image for showing the after effects expressions with lights that helps change color with the position of a layer

This is the scene before adding the lighting and working on expressions. I downloaded this from freepik.

After adding a point light I have added a Bulb too to make its movement evident. The idea is to move the light from one position to another and during that period, the color will keep changing. Let’s first see the video, what has come out. And then we’ll discuss.

Actually , I added two lights and made them move from the opposite direction. I have added the following code to the color of the Light. Not to mention, Lights’ position has only three key frames, left to right and then coming back to the starting position.

But I used loopOut() to continue with the motion throughout the length of the composition.

xNorm = linear(position[0], 0, thisComp.width, 0, 1); // Normalize X position
yNorm = linear(position[1], 0, thisComp.height, 0, 1); // Normalize Y position
r = linear(xNorm, 0, 1, 0, 255); // Map X to Red
g = linear(yNorm, 0, 1, 0, 255); // Map Y to Green
b = 255 - (r + g) / 2; // Complementary Blue
[r, g, b, 255] / 255; // Normalize to RGB

Download the Project File

Conclusion

Using After Effects Expression with Lights open up a huge repertoire of possibilities for animation. These expressions help you get a firm control and whirl the power to make the best use of it.

Whether you’re simulating natural lighting, syncing lights to audio, or creating abstract effects, expressions can save time and add depth to your animations.

Start with the examples provided, experiment with your own ideas, and soon you’ll be harnessing the full power of After Effects expressions in your projects.

When it comes to lights, expressions can be used to create dynamic, responsive, and realistic lighting effects that would be tedious or impossible to achieve manually.

In this guide, I have explored a few use cases on the After Effects Expressions with lights and saw how they look like. I’ll keep adding more such in the days to come.

Leave a Reply

Your email address will not be published. Required fields are marked *