Article
No items found.

Everything About Expressions You Didn't Know...Part Deux: Semicolon's Revenge

by
Zack Lovatt

Enhance your expression knowledge with a close look at the Light, Camera, and Text Expression Language menus

The Expression Language Menu holds a lot of little pieces for you to assemble. Where do you even start?! This series will walk you through each category and highlight a few unexpected items in each, leaving you better equipped to start expressing yourself via expressions.

mkt-3799-thumbnailArticle1.jpg

In Part 2 of our series, we're diving into some of the newer—or ignored—menus. Today, we're going to be looking at:

  • Light
  • Camera
  • and Text
Article 2 Menu.png

Check Out the Full Series!

Can't express yourself enough? Check out the rest of the series:

Part 1 - Property and Effects, Layer, Key, Marker Key

Part 3 - Javascript Math, Random Numbers, Path Properties

Part 4 - Global, Comp, Footage, Project

Part 5 - Interpolation, Vector Math, Color Conversion, Other Math

Light

expressions-part-2-1.jpg

While I'm sure somebody out there is using 3D Lights in After Effects, they're not very common! So the chance of someone using lights and expressions is pretty slim.  We came up with a few creative uses of these properties, though they're definitely not everyday tasks and are a little contrived.

We'll explore:

I have a good feeling that learning about the Light category will be just as illuminating for you as it was for me, so let's go!

MAKING LIGHTS FLICKER

We can use the intensity property to... see how intense the light is!

Let's say you've set up a flickering light, and you want a layer to glow more based on how intense the light is. We can do that!

On our glow effect's intensity, we can use this expression:

const lightIntensity = thisComp.layer("Light").intensity;
const multiplier = 1.5;


lightIntensity * multiplier;

Now, for every 1% of intensity, the glow will get 1.5x brighter!

MATCHING AE COLORS TO LIGHT COLORS

expressions-part-2-3.jpg

Looking at our scene, we have a light with a specific color casting onto our scene, coloring the ground plane.

In this case, though, the sun doesn't match the light color...so this looks a little weird.

To fix this, we don't need any fancy tricks; we'll just pickwhip from the shape layer fill color to the light color, and get this expression that leverages the light’s color property:

thisComp.layer("Light").color;

Now as we change the light's color, the sun color will change too!

Turning Out the Lights

Hopefully this small glimpse into the world of Light expression category has set off some cartoon lightbulbs above your head.

Camera

expressions-part-2-4.jpg

3D cameras in AE are a topic of much contention and argument, but nobody can deny that—just like with peanut butter—everything is made better with expressions.

To that end, here are some neat tricks that use expressions with Camera properties to great effect.

We'll look at:

  • Preserving layer scale during camera zooms
  • Ensuring your hero layer is always in focus

Without further ado: Lights! Action! Camera! ...or something.

HOW TO MAINTAIN LAYER SCALE DURING 3D CAMERA ZOOMS

expressions-part-2-5.jpg

It's a little weird to think about, but you can use the zoom value of a camera layer to control the scale of other layers—so no matter how much you zoom in or out, they'll appear the same size on screen!

Consider: the more you zoom in on something, the bigger it appears. But sometimes you don't want it to scale up. Maybe you want it to stay a fixed size. For example, having 2D labels attach to your objects that still respect the 3D environment of your comp.

const camera = thisComp.activeCamera;
const distance = length(sub(position, camera.position));
const scaleFactor = distance / camera.zoom;


value * scaleFactor;

By applying this to our layer scales, we can still tweak the individual scale of each layer but have it ignore the camera zoom altogether.

KEEPING 3D LAYERS IN FOCUS WITH 3D DEPTH OF FIELD

expressions-part-2-6.jpg

If you find yourself using 3D cameras in AE, there's an old trick to make sure that your camera's target is always in focus.

You can apply this expression to the Focus Distance property. It will look at the distance between the camera itself and its Point Of Interest, and use that distance as the focus distance. No matter how near or far they are, your interested layer is always sharp.

const cameraPosition = thisLayer.position;
const cameraPOI = thisLayer.pointOfInterest;


length(cameraPosition, cameraPOI);

aaaand cut!

These two tips can make working with Cameras in AE a little bit more accessible. As we all know, every little bit of speed and easiness adds up when on the clock.

Text

expressions-part-2-7.jpg

Text plays a HUGE role in AE animation, so of course we can work with so much of it via expressions too!

The most useful commands here are only available as of AE 17.0 (released in January 2020), but they're great and well worth the update:

This article will take a look at:

Without further ado let's stop reading Text and start expressing it.

SETTING FONT BY EXPRESSIONS

expressions-part-2-8.jpg

Within the main Text menu is the most unique button in alllll of Expressionland: a menu item that... doesn't give you any code! Instead, it lets you select a typeface (and weight), and it'll give you the internal name of it.

On its own, maybe not the most useful! But when paired with setFont(), you can actually change the font of your text layer itself right from an expression!

Here's this in use, on the Source Text property. Note that I selected 'Roboto Mono' and 'Medium' in the Font... menu:

const font = "RobotoMono-Medium";
const style = text.sourceText.createStyle();


style.setFont(font);

text 2.png

COPYING TEXT LAYER STYLING

expressions-part-2-9.jpg

We can use the text style property to get all of the font styling info from a text layer!

You can use this to get things such as the font, fill color, leading, font size, and so on from another layer— that's right, you can style one layer, and have it control the look of another layer.

This example will look at our layer 'Main Text' and inherit all formats of its style, just like that.

const otherLayer = thisComp.layer("Main Text");
const otherStyle = otherLayer.text.sourceText.style;


otherStyle;

Now, on the surface this is pretty straightforward, but I use this simple technique a ton with toolkit projects. The users can adjust the text style and formatting in one place, and have it propagate to every text layer in the rest of the project.

Still Tracking?

This category is a newer addition to the expression repertoire, and so uses and features are actively being explored!

Some of the other items here let you get (and set) other font features such as tracking, leading, kerning, font size, font fill and stroke colors, and so on. There's a lot more to explore, now that you've had a taste!

Expression Session

If you're ready to dive into some radioactive goop and gain a new superpower, don't do that! It sounds dangerous. Instead, check out Expression Session!

Expression Session will teach you how to approach, write and implement expressions in After Effects. Over the course of 12 weeks, you'll go from rookie to seasoned coder.

Success! Check your email (including spam folder) for your download link. If you haven't yet confirmed your email with us, you'll need to do that one time.
Oops! Something went wrong while submitting the form.
Featured
No items found.
No items found.