LIBRARY: Tutorials Reviews Interviews Editorials Features Business Authors RSS Feed

noise()

noise() – After Effects hidden gem of the week

CreativeCOW.net Adobe After Effects Tutorial


noise() – After Effects hidden gem of the week
Dan Ebberts Dan Ebberts
Sacramento, California, USA

©2004 by Dan Ebberts and CreativeCow.net. All rights are reserved.

Article Focus:
The After Effects expression language has a seldom-used random number generator that is really quite a gem. Dan Ebberts says “seldom-used” because he doesn't believe he's ever seen it used in a single expression he's seen posted on the internet. It’s not the easiest command to understand and the documentation is pretty sparse but once you get past that it’s very cool.

Download Movie

the objective


Before we get into how to use it, let’s set up a scenario where we might want to use it (if we only knew that it existed). Suppose you had a grid of dots and you wanted to generate an undualting 3D motion like the dots were attached to a flag waving in the wind or were floating on water. One way to do this would be to set up a grid of dots and then have a comp-sized layer of Fractal Noise below and have each dot’s z position related to the luminace of the Fractal Noise patten directly below the dot. Let’s say we want brighter areas of the noise to move the dots closer to the camera and the darker areas to move the corresponding dots away from the camera. As we animate the “Evolution” parameter of the Fractal Noise we would expect the dots to undulate as the underlying luminance vlaues change. Note that what we’re looking for is not independent random motion for each dot. We want it to appear as if the dots are connected to an undulating surface. That means that the position of each dot is related to that of its neighbor.


best laid plans


OK this sounds like a cool project – let’s get started. There’s just one problem. As you may have discovered, there’s no way (without the help of a plugin) to access pixel luminance values from an expression. There are some nifty plugins that will let you do this “Anarchy Toolbox” from Digital Anarchy has “Color Sampler”, “Expression Effects” from Bresnev Shu has “Color Analysis Node”, and Useful Things from Profound Effects also gives you access to the pixel color and luminance values. Each of these wonderful plugins provides you a way to solve our design problem (and much, much more). But in this very specialized, particular case (where we want to use fractal noise to generate an undulating motion) we’re going to be able to pull this off with the tools provided within AE’s expression language.


noise() to the rescue


The trick to all this is the “noise()” function. What this lets us do is create our own Perlin noise space (if you’re interested in the math, use Google to look up “Perlin noise” which is the basis of many fractal noise patterns). It gives us access to a 3D noise structure that extends in all directions. We can simulate moving through it in any direction. We won’t be able to see it like you can with Fractal Noise, but we’ll be able to see the affect it has on our dots. Picture it as a gigantic wispy fog bank that you can wander around in and take sample fog density readings wherever you are.

The noise() function accepts a single parameter that can have one, two, or three dimensions. It’s useful to visualize these as offsets in x, y, and z directions. If you supply a one-dimensional parameter the results of varying that parameter would be like moving along a straight line in our fractal noise environment. A two-dimensional parameter would be like moving around in a single plane of the noise space, and a three-dimensional parameter gives you access to the whole 3D space. The output is a number between 0 and 1 that is somewhat random, but has correlation to nearby points.

OK – so here’s the plan. We’ll set our dots up in a grid (actually, we’ll apply an expression that will allow our dots to position themselves in a grid - much less work). We’ll use each dot’s x and y position as the first two inputs to the noise() function. We’ll use the result of the noise() functin to calculate each dot’s z displacement based on the value of the noise field at that x/y location. We’ll use time as the third dimension of the input to noise() that will effectively move our plane throught the 3D fractal noise space. The result should be undulating dots.

So our position expression for each dot will be a combination of grid-positioning for x and y and a noise() component for z. Let’s tackle the grid part first. We’re going to set up a 10 x 10 grid of dots.


creating the grid




Start by creating a 640 x 480 comp several seconds in length. Then add a 30x30 solid layer. Make it 3D and set the quality to best. Make it a circle/dot by double clicking on the circular mask tool. Add this expression to the Position Property:

numRows = 10;
numCols = 10;

row = Math.floor((index - 1)/numCols);
col = (index - 1)%numCols;
x = col*width + width/2;
y = row*height + height/2;
xOffset = (this_comp.width - numCols*width)/2;
yOffset = (this_comp.height - numRows*height)/2;

[x,y,position[2]] + [xOffset,yOffset,0]

Now duplicate the “dot” layer 99 times. I do this by selecting the layer, hitting Ctrl+d 9 times, select all the dots and hit Ctrl+d nine more times. The dots should spread themselves out to fill in a 10x10 grid. Note that you can create any grid size you want by changing the “numRows” and “numCols” parameters and making the appropriate number of duplicates. If you want smaller dots, just start with a smaller solid – the expression will adjust.

At this point you might want to create a camera and position it so that you can see the grid on an angle so you’ll be able to clearly see motion in the z direction. I added a light for dramatic effect. Note – put the camera and light on the bottom of the layer stack, otherwise it will mess up the grid calculation, which relies on the layer index and expects layer 1 to be the first dot.


adding the undulations




Now that we’ve demonstrated that we can, in fact, generate a self-populating 10x10 grid of dots without too much trouble, we’re ready to add in the undulating part of the expression. Delete 99 of the dot layers so we’ll only have to modify one expression – then we’ll recreate the duplicates.

Here’ the modified expression:

numRows = 10;
numCols = 10;
xyCompress = 200;
speedCompress = 1;
amplitude = 100;

row = Math.floor((index - 1)/numCols);
col = (index - 1)%numCols;
x = col*width + width/2;
y = row*height + height/2;
xOffset = (this_comp.width - numCols*width)/2;
yOffset = (this_comp.height - numRows*height)/2;

z = amplitude*noise([x/xyCompress,y/xyCompress,time/speedCompress]);

[x,y,z] + [xOffset,yOffset,0]

Let’s take a look at what’s different. You’ll notice that we’ve added three new parameters at the top of the expression. The first one, “xyCompress” that will define how closely correlated the z position of adjacent dots will be. The larger this number is, the more related adjacent positons will be. In other words, larger values of “xyCompress” will give you a smoother undulation, smaller values will give you more chaotic undulation. The next new parameter is “speedCompress”. This will determine how fast we move through our fractal noise field. In practical terms, the larger the value of “speedCompress” the slower the undulation. The last new parameter is “amplitude”. This simply scales the output of the noise() function (which is normally between 0 and 1) to the range of z movement (in pixels) that we want in our undulation. In this case, we’ll get values between 0 and 100 pixels.

Finally, the lst new line of code – where all the action takes place – is the call to noise(). We feed it the x and y position of our dot (scaled by “xyCompress”) and the current comp time (scaled by “speedCompress”) and get a z offset that we multiply by “amplitude”. Then all we have to do is replace “position[2]” from our first expression with “z” and we’re done.

Create the 99 duplicates again and preview. If you did everything correctly, you should be rewarded with a nice 10x10 grid of undulating dots.


wrapping up


Once you get your brain wrapped around noise(), you start to see where it can come in handy to have access to a 3D noise field within the environment of After Effects expressions. Think about it. Natural effects like wind flowing through a field of grass or lilypads on a pond. The possibilities are endless. That’s my hidden gem of the week. 8^>

##Dan Ebberts

Feel Free to discuss this technique in the After Effects forum here at CreativeCOW.





Please visit our forums and view other articles at CreativeCOW.net if you found this page from a direct link.




Comments

Re: noise()
by Michael Sigmon
AMC Theaters uses an undulating wave as a background, if you've been to one of their theaters you'll see this before the trailers start. Then the undulating wave is disrupted like the wake left behind by a boat zipping through a body of water. I understand the concept, you'd modify the amplitude by the result of some other formula. I can kind of picture what the formula needs to do, but I'm sort of stuck trying to express that in script. Anybody have a hint?
Re: noise()
by Michael Sigmon
put the expression in an external file, have your solid's position read the external file and you can tweak the variables without deleting 99 layers, tweaking, and copying again.
-2


Related Articles / Tutorials:
Adobe After Effects
Adobe After Effects Reverse Stabilization

Adobe After Effects Reverse Stabilization

You're going to be blown away by how you can power up your After Effects workflow with reverse stabilizing your footage! By separating your tracking from your compositing, you can focus on each step, and in addition, overcome the render order complexities when match moving elements and effects on a moving shot.


Roei Tzoref
Adobe After Effects
After Effects Content Aware Fill: When It Doesn't  Work

After Effects Content Aware Fill: When It Doesn't Work

There’s a new artificial intelligence-powered feature in Adobe After Effects called Content-Aware Fill that allows you to remove anything from your shots fairly easily! It's powerful, but if you’ve tried it you know that it doesn’t always work perfectly. So what do you do when it doesn’t work as well as you'd hoped? Filmmaker Cody Pyper is here to show what to try next!


Cody Pyper
Adobe After Effects
VFX in Adobe After Effects: An Artists Panel (NAB)

VFX in Adobe After Effects: An Artists Panel (NAB)

Join panelists Andrew Kramer of Video Copilot, Jayse Hansen, and Mary Poplin of Boris FX, along with moderator, Victoria Nece of Adobe, as they discuss the world of visual effects from an artist’s perspective.


Adobe Creative Cloud
Adobe After Effects
Scars, Tattoos & Digital Makeup: After Effects & Mocha Pro

Scars, Tattoos & Digital Makeup: After Effects & Mocha Pro

How do you add SCARS, TATTOOS or DIGITAL MAKEUP to a person's face? Learn how to use Mocha Pro's planar tracker and the Mesh Warp tool to insert a flat image/video on a (non flat) human face! Join VFX guru Tobias G from Surfaced Studio for a closer look!


Tobias G
Adobe After Effects
Compositing Secrets Everyone Can Use, Pt 5: Brightness

Compositing Secrets Everyone Can Use, Pt 5: Brightness

The first challenge to understanding the nature of brightness in compositing starts with remembering that we're not actually seeing color at all, but rather something of an illusion that appears to us as color! Join longtime VFX artist, editor, software developer, and business owner Simon Ubsdell for Part 5 of the best look behind the technology of compositing that you've ever seen, as he takes a look at the math behind brightness, and how to apply that to the compositing toolsets in your favorite editing, compositing, and color grading applications.

Tutorial
Simon Ubsdell
Adobe After Effects
60 Second Tutorial: Alien Invasion in Adobe After Effects

60 Second Tutorial: Alien Invasion in Adobe After Effects

Here's a fast, fun one! Sixty seconds to create and animate an alien using the 3D and Track Camera tools to animate your character in Adobe After Effects. Use the included files, or bring your own!

Tutorial
Adobe Creative Cloud
Adobe After Effects
What Are Adobe Motion Graphics Templates?

What Are Adobe Motion Graphics Templates?

A Motion Graphics Template, referred to as a MOGRT, is an animated sequence that is self-contained and can be used in Adobe Premiere Pro, Adobe Premiere Rush and Adobe After Effects, combining graphics, text, audio and video files, as well as vector or still images (including logos), to create a still or animation that can then be customized by the MOGRT user. The result is a dynamic creative tool that provides design freedom and is consistent to its users across apps and devices. Reuse, share, and even sell them!


Rod Harlan
Adobe After Effects
Compositing Secrets Everyone Can Use Pt. 4 - Advanced Alphas

Compositing Secrets Everyone Can Use Pt. 4 - Advanced Alphas

When most people hear the words "alpha channels", they think "transparency", but that's not exactly accurate. The truth is more complex, and a quite bit more interesting! Join longtime VFX artist, editor, software developer, and business owner Simon Ubsdell for Part 4 of the best look behind the technology of compositing that you've ever seen, packed with practical advice for applying the secrets of alpha channels that's simply not possible before understanding these underlying principles. No matter which applications you're using for editing, compositing, or visual effects, this one is a must-see!

Tutorial
Simon Ubsdell
Adobe After Effects
Compositing Secrets Everyone Can Use: Pt. 3 - Alpha Channels

Compositing Secrets Everyone Can Use: Pt. 3 - Alpha Channels

When most people hear the words "alpha channels", they think "transparency", but that's not exactly accurate. The truth is more complex, and a quite bit more interesting! Join longtime VFX artist, editor, software developer, and business owner Simon Ubsdell for Part 3 of the best look behind the technology of compositing that you've ever seen, packed with practical advice for applying the secrets of alpha channels that's simply not possible before understanding these underlying principles. No matter which applications you're using for editing, compositing, or visual effects, this one is a must-see!

Tutorial
Simon Ubsdell
Adobe After Effects
Compositing Secrets Everyone Can Use 2: Advanced Blend Modes

Compositing Secrets Everyone Can Use 2: Advanced Blend Modes

Whether you're a full-time compositor and VFX artist, an editor working in one of the many NLEs that supports Blend Modes (including Adobe Premiere, Apple FCP and FCPX, Avid Media Composer, DaVinci Rsolve, and VEGAS Pro), or whether you just want the additional graphics power that comes with insight into the secret world of pixels, this is the tutorial for you! Join longtime VFX artist, editor, software developer, and business owner Simon Ubsdell for Part 2 of the best look behind the technology of blend modes that you've ever seen, with some practical steps you can start taking today to make your work look better than ever.

Tutorial
Simon Ubsdell
MORE
© 2019 CreativeCOW.net All Rights Reserved
[TOP]