1. Trang chủ
  2. » Công Nghệ Thông Tin

Adobe After Effects CS5 Visual Effects and Compositing STUDIO TECHNIQUES phần 7 doc

57 889 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 57
Dung lượng 1,46 MB

Nội dung

ptg 314 Music is math. —Michael Sandison and Marcus Eoin (Boards of Canada) Expressions E xpressions are cool. You can use them to create amaz- ing procedural effects that would otherwise be impossible (or at least impractical). You can also use them to create complex relationships between various parameters. Unfor- tunately, many After Effects users are afraid of expressions. Don’t be. The fact that you’re reading this chapter indicates that you are at least curious about expressions. That’s a good start. By the end of the chapter, you’ll see how expressions can open new doors for you, and, hopefully, you’ll have the confi dence to give them a try. The best way to learn about expressions is to examine working examples to fi gure out what makes them tick. The examples in this chapter focus on how you can use expres- sions to create or control effects. As you work through the examples (don’t be discouraged if you need a couple passes or more to understand it all), please keep in mind that I’m mainly a code guy—not a special effects or motion graphics artist. My examples may not be very visually impressive, but using these same tech- niques, you’ll be able to create your own dazzling effects. What Expressions Are The After Effects expression language is a powerful set of tools with which you can control the behavior of a layer’s properties. Expressions can range in complexity from ridiculously simple to mind-numbingly complicated. At the simple end of the spectrum, you can use expressions to link one property to another or to set a property to a static value. At the other extreme, you can create complex Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 315 II: E ects Compositing Essentials linkages, manipulate time, perform calculations in 3D space, set up tricky procedural animations, and more. Sometimes you’ll use expressions instead of keyframes (most properties that can be keyframed can be controlled by expressions). In other cases you’ll use expressions to augment the keyframed behavior. For example, you could use keyframes to move a layer along a specifi c path and then add an expression to add some randomness to the motion. Expressions Have Limitations Although the After Effects expression language presents you with an impressive arsenal of powerful tools, it’s important to understand the limitations of expressions so that you can avoid making assumptions that lead you astray. . An expression may generally be applied only to a property that can be keyframed, and it can affect only the value of that property. That is, an expres- sion can affect one and only one thing: the value of the property to which it is applied. This means there are no global variables. This also means that although an expression has access to many composition and layer attributes (layer width and height, for example) as well as the values of other properties, it can only read, not change, them. . Expressions can’t create objects. For example, an expression cannot spawn a new layer, add an effect, create a paint stroke, change a blend mode—the list goes on and on. Remember, if you can’t keyframe it, you can’t create an expression forit. . Expressions can’t access information about individual mask vertices. . Expressions can’t access text layer formatting attributes, such as font face, font size, leading, or even the height and width of the text itself. . Expressions cannot access values they created on previous frames, which means expressions have no memory. If you’ve had a little Flash programming experi- ence, you might expect to be able to increment a value at each frame. Nope. Even though you can access previous values of the property using valueAt- Time(), what you get is the pre-expression value (the static value of the property plus the effect of any keyframes). It’s as if the expression didn’t exist. There is no way for an expression to communicate with itself from one frame to the next. Note, however, just to make things more confusing, the postexpression value of a property is available to any other expression, just not the one applied to that property. In fact, the postexpression value is the only value available to expressions applied to other properties. To summarize: An expression has access only to the pre-expression value of the property to which it is applied, and it only has access to the postexpression values for other properties with expressions. It’s confusing at first, but it sinks in eventually. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 316 Chapter 10 Expressions Creating Expressions The easiest way to create an expression is to simply Alt-click (Opt-click) the stopwatch of the property where you want the expression to go. After Effects then creates a default expression, adds four new tool icons, changes the color of the property value to red (indicating that the value is determined by an expression), and leaves the expression text highlighted for editing (Figure 10.1). At this point you have a number of options. You can simply start typing, and your text will replace the default expression. Note that while you’re in edit mode, the Enter (Return) key moves you to a new line in the expression (this is how you can create multiline expressions) and leaves you in edit mode. Another option while the text is highlighted is to paste in the text of an expression that you have copied from a text editor. This is the method I generally use if I’m working on a multiline expression. Instead of replacing all the default text by typing or past- ing, you can click somewhere in the highlighted text to create an edit point for inserting additional text. Alternatively, you can drag the expression’s pick whip to another property or object (the target can even be in another composition), and After Effects will insert the appropriate text when you let go. Note that if an object or property can be referenced using the pick whip, a rounded rectangle appears around the name as you drag the pick whip over it. If this doesn’t happen, you won’t be able to pick whip it. Finally, you can also use the Expression Language menu to insert various language elements. Figure 10.1 When you create an expression, After Effects creates a default expression with the text high- lighted for editing, changes the color of the property value to red, and adds four new tool icons: an enable/disable toggle, a Graph Editor toggle, a pick whip, and an Expression Language menu fly-out. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 317 II: E ects Compositing Essentials After creating your expression, exit edit mode by clicking somewhere else in the timeline or pressing Enter on the numeric keypad. If your expression text contains an error, After Effects displays an error message, disables the expres- sion, and displays a little yellow warning icon (Figure 10.2). You can temporarily disable an expression by clicking on the enable/disable toggle. Working with existing expressions is as easy as creating them. Some common operations include . editing. Click in the expression text area to select the entire expression; you now have the same options as when creating a new expression. If your expression consists of multiple lines, you may need to expand the expression editing area to be able to see all (or at least more) of it by positioning the cursor over the line below the expression text until you see a double-ended arrow and then clicking and dragging. . deleting. Simply Alt-click (Opt-click) the property’s stopwatch, or you can delete all the text for the expres- sion and press Enter on the numeric keypad. . exposing. Select a layer in the Timeline and press EE to expose any expressions applied to that layer. . copying. In the Timeline panel, select a layer prop- erty containing an expression and choose Edit > Copy Expression Only to copy just the property’s expression. You now can select as many other layers as you’d like and Edit > Paste to paste the expression into the appro- priate property of the other layers. Figure 10.2 If your expression con- tains an error, After Effects disables the expression, changes the enable/ disable toggle to the disabled state, returns the Property value to its nor- mal color, displays an error icon, and displays an error message dialog box. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 318 Chapter 10 Expressions The Language of Expressions The After Effects expression language is based on a subset of JavaScript. JavaScript is a scripting language used largely for Web page design and includes many features specifi - cally aimed at that task. The JavaScript implementation for expressions includes the core features only. That means there’s a lot about JavaScript that you won’t need to know, but it also means that any JavaScript reference you pick up (and you’re going to need one if you really want to master expressions) is going to have a lot of content that will be of little or no use to you. The rest of the expression language consists of extensions that Adobe has added specifi cally for After Effects. This means that in addition to a good JavaScript reference, you’ll also be frequenting Adobe’s After Effects Expres- sion Element Reference. The most up-to-date version of this reference can be found at Adobe’s Help on the Web. The After Effects Help menu will take you there: Help > After Effects Help, or you can go to www.adobe.com/support/ aftereffects. This chapter focuses on working examples rather than the details of JavaScript. The book’s disc, however, contains an abbreviated JavaScript guide, and I recommend that you glance through it before you really dive into the sample expressions discussed here. In addition, I’ll point you to the appropriate sections of that guide as you encounter new JavaScript elements for the fi rst time. Linking an Effect Parameter to a Property Here’s the scenario: You want to link an effect to an audio track. Specifi cally, you want to link the Field of View (FOV) parameter of the Optics Compensation effect to the amplitude of an audio layer. Expressions can’t access audio levels directly, so fi rst you have to use a keyframe assis- tant (Animation > Keyframe Assistant > Convert Audio to Keyframes) to create a null layer named Audio Amplitude with Slider Controls keyframed for the audio levels of the Left, Right, and Both channels (for a stereo source). Next, Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 319 II: E ects Compositing Essentials you just Alt-click (Opt-click) the stopwatch for the FOV parameter of the Optics Compensation effect and drag the pick whip to the Both Channels Slider property of the Audio Amplitude layer (Figure 10.3). Doing so generates this expression: thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”) Take a closer look at its syntax: From JavaScript, the After Effects expression language inherits a left-to-right “dot” notation used to separate objects and attributes in a hierarchy. If your expression references a property in a different layer, you fi rst have to identify the composition. You can use thisComp if the other layer happens to be in the same composition (as in this example). Otherwise, you would use comp(“other comp name”), with the other composition name in quotes. Next you identify the layer using layer(“layer name”) and fi nally, the property, such as effect(“effect name”)(“property name”) or possibly transform.rotation. In addition to objects and properties, the dot notation hierarchy can include references to an object’s attributes and methods. An attribute is just what you would guess: a property of an object, such as a layer’s height or a composi- tion’s duration. In fact, in JavaScript documentation, attri- butes are actually referred to as properties, but in order to avoid confusion with the layer properties such as Position and Rotation (which existed long before expressions came along), in After Effects documentation (and here) they’re referred to as attributes. For example, each layer has a height attribute that can be referenced this way: comp(“Comp 1”).layer(“Layer 1”).height Figure 10.3 Select the Both Channels slider with the pick whip to replace the highlighted default expression text. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 320 Chapter 10 Expressions Methods are a little harder to grasp. Just think of them as actions or functions associated with an object. You can tell the difference between attributes and methods by the parentheses that follow a method. The parentheses may enclose some comma-separated parameters. It’s important to note that you don’t have to specify the full path in the dot notation hierarchy if you’re referencing attributes or properties of the layer where the expression resides. If you leave out the comp and layer references, After Effects assumes you mean the layer with the expres- sion. So, for example, if you specify only width, After Effects assumes you mean the width of the layer, not the width of the composition. Let’s forge ahead. You linked the amplitude of your audio layer to your effect parameter, but suppose you want to increase the effect that the audio level has on the param- eter. You can use a little JavaScript math to multiply the value by some amount, like this thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”) * 3 Toward the end of the chapter you’ll see a much more complicated and powerful way of linking an effect to audio. Using a Layer’s Index A layer’s index attribute can be used as a simple but power- ful tool that allows you to create expressions that behave differently depending on where the layer is situated in the layer stack. The index attribute corresponds exactly to the number assigned to the layer in the Timeline window. So, the index for the layer at the top of the stack is 1, and so on. Time Delay Based on Layer Index Suppose you keyframed an animation for one layer. Now you want to create a bunch of identical layers, but you want their animations to be delayed by an amount that increases as you move down the layer stack. You also want to rotate If you’re not familiar with JavaScript arithmetic operators (such as the * for multiplication used in this example), you might want to take a look at the “Operators” section of the JavaScript guide on the book’s disc. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 321 II: E ects Compositing Essentials each copy by an amount proportional to its position in the layer stack. To do so, you fi rst apply an expression like this to the top layer’s animated properties: delay = 0.15; valueAtTime(time - (index-1)*delay) Then you apply an expression like this to the Rotation property: offsetAngle = 3; value +(index-1)*offsetAngle Finally, duplicate the layer a bunch of times. The anima- tion of each layer will lag behind the layer above it by 0.15 seconds and the rotation of each layer will be 3 degrees more than the layer above (Figure 10.4). What’s going on here? In the fi rst expression, the fi rst line defi nes a JavaScript variable named delay and sets its value to 0.15 seconds. The second line is where all the action is, and it’s packed with new things. For example, notice the use of time. It represents the current composition time, in seconds. In other words, time represents the time at which the expression is currently being evaluated. You use valueAtTime() to access a property’s pre-expres- sion value at some time other than the current comp time (to access the pre-expression value at the current comp time, use value() instead, as in the Rotation expression). The parameter passed to valueAtTime() determines that time: time – (index-1)*delay Subtracting 1 from the layer’s index and multiplying that result by the value of the delay variable (0.15) gives the total delay (in seconds) for this layer. Subtracting 1 from index means that the delay will be 0 for the fi rst layer. So, for Layer 1, the total delay is 0, for Layer 2 it is 0.15, for Layer 3 it is 0.30, and so on. You then subtract the total delay from the current comp time. The result of this is that Layer 1’s animation runs as normal (not delayed). Layer 2’s animation lags behind Layer 1 by 0.15 seconds, and so on. If you’re not familiar with JavaScript variables, see the “Variables” sec- tion of the JavaScript guide on the accompanying disc. Figure 10.4 Notice how the blaster shot created by each layer lags that of the previous layer and is at a slightly different angle. Remember, if you don’t specify a comp and layer when referencing a property or attribute, After Effects assumes you mean the layer with the expression. When you refer- ence an attribute of the property housing the expression, After Effects makes a similar assumption, allowing you to specify only the attribute name (without the entire comp/layer/property path). One side benefit of not having to specify the entire path is that you can apply the same expression to any property, without having to modify it at all. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 322 Chapter 10 Expressions The Rotation expression is very similar except that it doesn’t reference time. The reason for this is that the fi rst expression is used to offset a keyframed animation in time, while the second expression simply creates a static (not animated) offset for the Rotation property. The fi rst line of the expression defi nes a variable named offsetAngle. This variable defi nes the rotation amount (in degrees) by which each layer will be offset from the layer above it. The second line tells After Effects to calculate the layer’s offset and add it to the pre-expression value of the property. You’ll see other ways to use index in later examples. Looping Keyframes The expression language provides two convenient ways to loop a sequence of keyframes: loopOut() and loopIn(). Suppose you keyframed a short animation and you want that sequence to repeat continuously. Simply add this expression to the keyframed property loopOut(“cycle”) and your animation will loop for the duration of the comp (Figure 10.5). There are three other variations of loopOut(), as well: . loopOut(“pingpong”) Runs your animation alternately forward, then backward. . loopOut(“continue”) Extrapolates the animation beyond the last keyframe, so the value of the prop- erty keeps moving at the same rate (and in the same direction, if you’re animating a spatial property such as A small glitch in the cycle ver- sion of loopOut() drops the first keyframe from each of the loops. If you want the frame with the first keyframe to be included, add a duplicate of the first keyframe one frame beyond the last keyframe. Figure 10.5 The solid line in the graph represents the keyframed bounce action. The dotted line represents the subsequent bounces created by loopOut(“cycle”). Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com ptg 323 II: E ects Compositing Essentials Position) as the last keyframe. This can be useful, for example, if you’re tracking an object that has moved offscreen and you want After Effects to extrapolate where it would be if it kept moving at the same speed and in the same direction. . loopOut(“offset”) Works similarly to “cycle” except that instead of returning to the value of the fi rst keyframe, each loop of the animation is offset by an amount equal to the value at the end of the previous loop. This produces a cumulative or stair-step effect. loopIn() operates the same way as loopOut(), except that the looping occurs before the fi rst keyframe instead of after the last keyframe. Both loopIn() and loopOut() will accept a second, optional parameter that specifi es how many keyframes to loop. Actually, it’s easier to think of it as how many keyframed segments to loop. For loopOut() the segments are counted from the last keyframe toward the layer’s In point. For loopIn() the segments are counted from the fi rst keyframe toward the layer’s Out point. If you leave this parameter out (or specify it as 0), all keyframes are looped. For example, this variation loops the segment bounded by the last and next-to-last keyframes: loopOut(“cycle”,1) Two variations on the expressions—loopOutDuration() and loopInDuration()—enable you to specify the time (in sec- onds) as the second parameter instead of the number of keyframed segments to be looped. For loopOutDuration(), the time is measured from the last keyframe toward the layer’s In point. For loopInDuration(), the time is mea- sured from the fi rst keyframe toward the layer’s Out point. For example, this expression loops the two-second interval prior to the last keyframe: loopOutDuration(“cycle”,2) If you leave out the second parameter (or specify it as 0), the entire interval between the layer’s In point and the last keyframe will be looped for loopOutDuration(). For loopInDuration(), the interval from the fi rst keyframe to the Out point will be looped. Download from WoweBook.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... answered and take a look at expressions contributed by others http://forums.creativecow.net/forum /adobe_ after_ effects_ expressions: A forum dedicated to expressions http://forums .adobe. com/community/aftereffects_ general_discussion/aftereffects_expressions: Adobe s own After Effects forum, which has a subforum on expressions www .adobe. com/support/aftereffects: The online version of After Effects. .. 0 .7 seconds The next line tells After Effects that you want the random number generator (random()) to generate the same random number on each frame More About random() There are several ways to use random() If you call it with no parameters, it will generate a random number between 0 and 1 If you provide a single parameter (as in the Random Time example), it will generate a random number between 0 and. .. 0 .7; seedRandom(index, true); time + random(maxOffset); The first thing to notice about this expression is the use of seedRandom() and random() and the relationship between these functions If you use random() by itself, you get a different random number at each frame, which is usually not what you want The solution is seedRandom(), which takes two parameters The first is the seed It controls which random... the path from the rich outer world of visual data to the images in your final output In this chapter, we’ll take a look at how higher bit depths, the built-in color management system of After Effects and 3D LUTs, and compositing in linear (1.0 gamma) color can enhance your work Dynamic Range: Bit Depth and Film It may still be the case that the majority of After Effects artists spend the majority of... WoweBook.com II: Effects Compositing Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Essentials After Effects skips to the end of the routine with the variable n still set to 0 You need to make this test because the next line attempts to access the nearest marker with the statement n = marker.nearestKey(time).index; If After Effects attempted to execute this statement and there were... comma, it will generate a random number between those two parameters It’s important to note that the parameters can be arrays instead of numbers For example, this expression will give you a random 2D position somewhere within the comp: random ([thisComp.width, thisComp.height]) In addition to random(), After Effects provides gaussRandom(), which operates in much the same way as random() except that the... note 330 Download from WoweBook.com II: Effects Compositing Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Essentials that seedRandom() doesn’t generate anything by itself It just defines the subsequent behavior of random() Here’s an example This Position expression randomly moves a layer to a new location in the comp on each frame: random([thisComp.width,thisComp.height])... gaussRandom(), sometimes the values may actually be slightly outside the specified range, which never happens with random() The last line of the expression calculates the final Time Remap value, which is just the sum of the current comp time plus a random offset between 0 and 0 .7 seconds Next, you would apply the Opacity and Audio Levels expressions from the wiggle() example so that each layer’s video and. .. stay in one random location: seedRandom(1,true); random([thisComp.width,thisComp.height]) This version is the same as the previous one, except that it generates a different, single random location because the value of the seed is different: seedRandom(2,true); random([thisComp.width,thisComp.height]) Let’s get back to the Time Remap expression The first line creates the variable maxOffset and sets it... one for Time Remap, one for Opacity, and one for Audio Levels First, you enable time remapping for the layer Then apply the three expressions and duplicate the layer as many times as necessary to create the look you want (Figure 10 .7) Figure 10 .7 The time-wiggling effect with multiple layers 328 Download from WoweBook.com II: Effects Compositing Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com . reference can be found at Adobe s Help on the Web. The After Effects Help menu will take you there: Help > After Effects Help, or you can go to www .adobe. com/support/ aftereffects. This chapter. property is maxOffset = 0 .7; seedRandom(index, true); time + random(maxOffset); The fi rst thing to notice about this expression is the use of seedRandom() and random() and the relationship between. of extensions that Adobe has added specifi cally for After Effects. This means that in addition to a good JavaScript reference, you’ll also be frequenting Adobe s After Effects Expres- sion

Ngày đăng: 12/08/2014, 15:21

TỪ KHÓA LIÊN QUAN