ALL About Expressions PLUS Animated Counter Tutorial / Davinci Resolve / Fusion

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my name is William justice today we're gonna talk about one of the most frequent questions I get all about expressions in DaVinci Resolve fusion it's a simple concept but it does seem a bit magical what's really going on once you understand him the trick is really knowing when to use them and why honestly I didn't want to make an expression video until I thought I had something really interesting to do so I think I've come up with it hopefully you enjoyed the video ok I want to be clear I'm not an expression expert I'm just trying to learn and get better we're gonna go over the basics of how to use expressions to modify properties then we're gonna use an expression script to set up this animated counter a lot of you based on your questions seem to be really interested expressions hopefully you'll enjoy this video if you do like the video and if you haven't already done so please subscribe to my channel I really appreciate your feedback so comment below and I'll definitely get back to you let me know what you use expressions for I've also set up a real quick expression cheat sheet and I'm gonna be growing this over time if you go to build justice comm resources you'll be able to see some real quick things that you can use in expressions we're infusion with a blank composition let's make some expressions we're gonna start with two rectangles what can we do with expressions we can modify a property with a number or formula we can use values from other nodes and properties we can animate properties over time we can use built-in functions such as date add scripting and coding logic and a bunch of other things that I really can't even think of right now all right we have our two rectangles set up we're gonna use each of these rectangles to demonstrate how the expressions can work we have rectangle one right here which is the blue rectangle and the rectangle on the right is the green rectangle we have a background node for each with a rectangle mask that's creating the shape and that's going into a transform node and we're gonna use these transform nodes to adjust properties of expressions to demonstrate what you can do with them how do you add an expression to a property we're gonna click transform to and go over to the inspector most of these properties can have an expression set up on them all you need to do is right click on the property and choose expression from the pop-up menu let's right click on size and choose expression we get an input box down here which is where we can enter our expression value and it defaults to the current value of the property with the expression enabled the edit control is no longer work you need to edit it down in the box below to remove an expression you just right-click on the property and choose remove expression the simplest expression that we can set up is just entering a number value in this box the size goes from 0 to 1 that's the scale so let's enter point 3 and the size of the box is scaled down we can add a little math we'll say point 3 times 2 and the box is scaled up to point 6 now we're going to connect the size of the green rectangle to the size of the blue rectangle we just need to enter the node name and the property we want to use we're going to enter transform 1 dot size transform 1 this is the name down here of the node and size is the property now both rectangles are the same size if we go to transform 1 and adjust the size they both adjust let's go back to transform 2 we can add a quick formula and multiply times 0.5 and that's going to set transform 2 to be half the size of transform 1 what if you don't know the name of the node or the property you want to use let's click transform 1 hold ctrl and click transform 2 then we're going to click the little pin icons up here and that's going to put both transform 1 and transform 2 in the inspector transform 1 is on the bottom and transform 2 is on top let's set the blue rectangle to have an angle of 45 so we'll go down to the inspector where under transform 1 set the angle to 45 so let's get the green rectangle to match we can right-click the angle property choose expression we could type in transform 1 here transform one angle and it's going to use that angle property the other thing we could do is click this little plus icon and it's going to have this line you draw the line to the property that you want to use so we're gonna draw it down to angle and what that does is it puts the name of that property of how it's referenced in to the expression field you can do this with anything if we space over we can hit the plus again and we can drag it down to say pivot and we got transform wound up pivot so it's just a quick shortcut to help you know what to put into the expression field so now the angle for both is connected if we want to make the green rectangle spend a bit faster than the blue rectangle we can go to the expression and multiply the angle times 4 or really any number and now the green rectangle is going to rotate quicker than the blue rectangle if we wanted to rotate in Reverse we just have to multiply it by say negative 2 and the green rectangle is going to spin in the opposite direction of the blue rectangle just a quick note if we select a node and rename it with f2 once we rename it all the expressions will be updated with the new name for the node so how can we use expressions to adjust the position of the rectangles let's adjust the position of the green rectangle we'll go to the sinner property in the transform - node we'll right-click on it and choose expression and what this put in here was a point and the point is the exposition with a comma followed by the Y position to move it we can simply change this and we'll say it's point 8 and it's gonna shift over a little bit let's set the green rectangle position to be the same as the blue rectangle for the x value so we're gonna get rid of that we're gonna go we're gonna type in transform 1 dot center dot X what that did was it set the point or the position for the sinner to match the position of the blue rectangle so if we move the blue rectangle the green rectangle is going to move along with it now you notice that we didn't do anything with the Y position so if we move the rectangle up and down the X position changes but the Y position of the green rectangle stays the same and we can add a little math in here we could say the center X plus 0.3 and that's going to make it point three to the right of the blue rectangle how do we animate something over time we're going to use the time variable so let's add a text node and we'll go to the text node inspector we'll right click on style text and choose expression and we're going to enter in this value time and bring it up to the top so that we can see it so basically what time is it's a variable that changes throughout your animation that matches the current frame you're on so if we go to frame 40 the time is on frame 40 it just changes as we go through the animation how can we use this time variable to animate a property the quickest thing we can do is to set the value of the angle to match the current frame we'll go to transform one so our blue rectangle it's right down here and you can see the the angle goes from zero and it just keeps on going up let's reset it to zero we're gonna right click on the angle choose expression and our expression is going to be time so whatever the value of time is that's going to be our angle so as we play the animation the angle of the rectangles are changing based on the time so if we're on I'm 45 the angle of the blue rectangle is 45 to make the animation go a little faster we just multiply the time times let's say 3 and it's going to be rotating it three times the frame rate so when we're on frame 30 the angle is now 90 we do the same thing if we want to slow it down we just divide it so we can divide the time by 3 and the angle is going to change slower than the frames are changing ok this is pretty interesting but you'll notice a lot of these properties they don't have really big values like the time they're going from zero to one and point five and things like that what can we do to use the time for those properties the best way to think about it is to think about time as a percentage to demonstrate time as a percentage I've set up this formula up at the top and and put it into this text note so we can see it we have the time the current time which is the current frame divided by 80 so we're gonna animate and do a time interval over 80 frames so right now this is the current value we're on frame zero divide that by 80 we're at 0% let's you'll notice that when we move forward in the animation let's say 10 frames in it's 10 divided by 80 which is 0.125 which is 12.5% and we'll keep playing along and by the time we get to frame 80 well go ahead there we're at 1 so what we've effectively done is we've created by using time divided by 80 we've created an expression that goes from 0 to 1 and you can change the time interval if you want this time to be longer or slower you can so for example if you wanted it to be 5 seconds you would put 20 this is at 24 frames per second in a video this is a 24 frames per second video so you could do 24 times 5 that would give you 5 seconds where the time interval going from 0 to 1 so let's use this technique in our blue rectangle angle ok transition one and you see right there we had time divided by 3 let's get rid of that and let's do this a different way let's say we want it to spin 360 degrees in 80 frames so this is our time divided by 80 so we are 360° times time divided by 80 now you'll notice when we're on the very first frame the angle is 0 that's because the time divided by 80 is 0 by the time we get to frame 80 the time is 1 and the angle is three six what we've done is we've set the blue rectangle to animate 360 degrees over 80 frames but now you'll notice that it keeps animating and this is because now we're over a 1 there so it's going to keep increasing the angle so to get the animation to stop at 360 degrees we're gonna use a built in expression function let's adjust the expression we're gonna type in min with a parenthesis and this is going to return the minimum value I'm gonna add a 360 and close it so we have the min of our expression here which is 360 times our time comma 360 what this function does it returns whichever is the lower value the first one or the second one so now when we do this when we get to frame 80 it's gonna stop right there so we can actually have it stop it so we could really have it stopped at any angle let's put in there 160 as the animation is running and it gets to an angle of 160 it's going to stop because it's returning the lower of these two values and obviously 160 is lower than what this is computing to right now now that we know how to use time as a percentage let's create a really quick progress bar just takes a few seconds well add a merge node I'll put a background on the merge so let's click on the rectangle mask for our progress bar you'll notice that the width goes from 0 to 1 and we just learned how to do that so let's put in a quick expression we're gonna right click on the width choose expression we're gonna say time divided by 20 and what this means is it's gonna take 20 frames to go from 0 to 1 based on their percentage so right there within 20 frames it was a full width progress bar but usually you want the you want the progress bars to automatically go to the length of the animation well there's a convenient variable that we can add called comp render end and comp out render end is the last frame so in this case let's let's go back up to our expression up here and we're gonna put time dot dot with this face two more dots this is how we build the string in here right now we're on frame 19 and the last frame is 119 if we go to the very end so let's go back to our rectangle and we have time / comp out render end that means that it's going to take the full length of the animation to go from 0% to 100% another fun thing we can do to get a repeating animation is to use the sine function it's a it's a trigonometry math function where you pass it an angle and it returns alternating values between negative 1 and 1 so we're going to assign a time as our expression it starts bouncing back and forth it disappears because it actually goes negative so we're not seeing the width to fix that we do the ABS function which is absolute value and that's always going to return a positive number so if you pass it a negative it's going to give you a positive next thing is we just need to slow it down just like we did before you multiply to speed things up divide to slow it down so we're going to divide it by 5 and we got a balancing progress bar all right so we've been using the time so let's say let's make a root super quick countdown timer let me show you how that works we're gonna click on text 1 go to our expression and we're just gonna start write a narrowing time now this video is in 24 frames per second so if we divide the time by 24 that's going to show the number of seconds that the video has been playing so if we go to 24 frames we should be at 1 second 48 frames is 2 seconds okay so you see we're getting all these decimal places let's remove those we can use a built-in function called floor that's going to take whatever your fractionate or whatever your decimal number is and round it down to the very lowest whole number so we're gonna type in floor with a parenthesis and put our time divided by 24 in that and we got 2 so now we're counting up let's say we wanted to count down from 3 all we need to do is go 3 - whatever we're counting up from and we're gonna have the number start at 3 go to 2 1 count down and then it goes negative so to get rid of the negative we can use the max function type in Max what our current expression is comma 0 and close that out and that means it's going to return the larger of the two values either the first part of the second part and since the first part is currently negative we see 0 next I'm going to show you how to enter a super easy dynamic date let's go to our text field right here get rid of this expression and we're gonna type in OS dot date and there we have it this is the current date and time when I'm making this video and when you play it you'll see that the time update now one thing is a lot of sometimes these frames will get cached so when you're replaying you may not see exactly where you're gonna see when you make the final video what ends up happening is when you render the video it's gonna be the current date and time of when the video is being rendered all right let's edit our date and put in some percent variables we have % a percent B % D so what those are are those date our date format variables I mean I have a reference on my website bill justice comm and I'm gonna pop up a little window here to see show you all the different options that you can use with the date that's a very basic overview of just a few of the things you can do with expressions obviously you won't be using these techniques all the time but hopefully understanding how they work will help you see where they might be useful now it's time for the animated counter the first thing we're going to do is create a basic number and then we're gonna replicate that to build columns and we're gonna animate each of these columns there's some different ways to do this without creating as many numbers but this was gonna be a little bit easier to demonstrate how the expression works because they only need to put them in one place as opposed to having to put them in multiple nodes so we're gonna create a background node and we're gonna put a mask on it and this is what we're gonna put our number on so let's set the background to white and go to the rectangle now the height that needs to be a fixed height for this animation because we're gonna animate it by this fixed height so we're gonna set the height to 0.25 and bring the width in the width does not matter as much we're gonna add a little bit of corner radius to give it a rounded look and then we're gonna add a shadow let's add our first number we're gonna add a merge node connect the shadow into the merge node so for our numbers we're gonna add a text node and we're gonna put that into the merge we're gonna start out with number 0 set the color to black and let's increase the size so that's our first number so what we're going to do is we're going to build a column of numbers going up and down and then use the expression to animate the y position to get the rotations first up to building this is to create merges for each of the nodes so I'm gonna cut I'm going to create a merge node and I'm just gonna make 10 of these then I'm going to take this shadow that we have so this is basically the background and I'm going to put that into the background for each of the merges next we're gonna we're gonna create instances of this text node so that we can customize the style really easily so with text one selected hit ctrl C to copy it and we're going to hit control V 10 time to make our instances so now that we have each of the text instances we just need to drag the output of the text and merge it in on top of the number background so we can move the shadow up on top and we're going to take all these text nodes and move them off to the other side here so this is the beginning of our column now what we need to do is for each of these text nodes we need to D in stencil text and change the number so the first one is going to be 0 so the next one needs to be 1 so we're going to click on it right click on style text choose D instance and set it to 1 now I'm just going to go ahead and do this for all the rest of the nodes ok our column is almost getting there we have all the numbers but right now they're sitting on top of each other so we're going to take the lower one and merge it onto the one that's right above it and we're just going to do that for each of these and we'll hit two on the last merge there so now what you see is when we come to this its merge four we can adjust the y position and there's our number 1 so we just need to space these out so since each of these is 0.25 hi I'm going to space them out by 0.28 and just keep that consistent so I'm going to go through each of these and add point to 8 to it to get a column of numbers we have our column set up so what we're gonna do is we're going to use some transform nodes to move the columns around so let's create 3 transforms for column 1 column 2 and column 3 we're gonna take this 1 column we created and put it into each of these transforms so transform 1 is going to be the ones column transform 2 is going to be the tens column and transform 3 is going to be the hundreds so let's tricks take transfer let's take transform 1 and the X position and slide it over let's merge these together real quick so we can see what we're doing it's about to transform 1 shift it over just a bit transform 2 is going to stay in the center for that column and transform 3 let's move it over to the left ok there we go we've got our three columns we're gonna add some more transform nodes in here to adjust why position of the columns with transform one selected let's add a transform in between same for transform two and transform three so we're going to put our expressions in these transforms and I'm going to rename them to ones tens and hundreds so to show you this works we'll hit on the ones column and we can adjust the Y position and you'll see that we have the whole column and we can move movement move it up and down so we're going to use an expression that's going to adjust the Y position for us based on time the expression is a bit long but it seems to work pretty good I wish it performed a little bit better it doesn't seem like it's overly complex it slows fusion down just a bit what I'm gonna do is plug these in real quick show you how it's working finish the setup after that stick around and I'm gonna break down the expression a little bit and show you exactly how it's working so we'll go to our ones transform right-click on the center position hit expression and I'm gonna get rid of that and paste in my expression so it looks like we're missing a number there so I have to go back and fix that okay I think I fixed that problem one of the numbers was just off a bit now though one other thing we need to do is we need to add a nine on top of here alright let's add in our expression for the ones column so we're gonna hit the one to transform node make this a little bit bigger so we can cut see what's going on we're going to right click on center position choose expression get rid of that point and we're gonna paste in the expression I came up with what this is rotating every half second so it goes a little bit faster one of the things I did is I put a mask on this so that we can only see the middle number so let's take the output of all three columns and merge it into a background and we're gonna mask that and let's take a look at that merge well go with the mask and adjust the soft edge just a touch and bring it down so the the numbers kind of are fading out as they rotate I'm going to go ahead and do the tens and hundreds so we'll go with tens and we're going to right-click on sinner choose expression paste in the expression and the tens column one rotate and same thing with the hundreds will click the hundreds transform right click on center property expression and will paste it in and now we have a fully working counter that once it once it gets past 100 it's just gonna keep on going okay so that's the basic setup it's once you have the column set up it's really easy the expression was not super difficult to come up with it just took a little bit of playing with the numbers to get it to work the way I wanted what we're gonna do is we're gonna take these numbers and stick them down on the side and I'm gonna put out the expression there so you can kind of see how it's working okay let me paste in the expression I've added a text node and you'll see it's way too long I can size this down to get it to fit but it's gonna be pretty small to go over okay so it's time to tackle this big bad expression here let's say let me break it down and show you exactly what I did the top line up here this is what I this is what we entered into the expression field it's a little bit hard to see and hard to break it down so what I did is took the line broke it down and put each of the statements on its own line so we can kind of see how they're working somebody walk you through what I did so the first line is frames equals 12 and there's a colon in front of it I think what the colon does is it tells the expression that you're going to be adding script or multiple statements in there frames is 12 meaning I want to rotate a new number every 12 frames we could set that to 24 and would rotate every second but I wanted it to go I wanted it to go a little bit faster TM is our time so we're gonna do the time plus 12 we're just doing that to kind of jumpstart the animation so it's not starting out at 0 H is a height that we're gonna move a column for each number so we have the height of each number at 0.25 the spacing at 0.28 I'm gonna adjust the Y position of the column by 0.28 count okay so count this is basically the count the number that we're trying to show so we're trying to show 142 here you can see 142 as we play the animation you'll see the count go up and the counter goes along with this count here so we'll just skip ahead so at this point we're trying to show number 128 so we're dividing the time by the number of frames and that gets us our count and it's just gonna keep going up this is the expression for the ones column so we want to get the digit in the ones column so we're going to take the count and use this percent operation by 10 and this is called a mod operation and basically what it's doing is it's taking our current count which is 128 dividing it by 10 and it returns the remainder so if we divide 128 by 10 we have a remainder of 8 so we know that this column we're gonna try to show digit 8 right now deep frames is the number of frames since we just switched to a new number so we're going to take the time divide it by the frame and do the same mod operation by the number of frames and when this is 0 that's when we just detected a new number so D frames is 11 we're gonna go for one frame and we're gonna be now we want to show number 128 so D frames is 0 and as we skip ahead it's going to go to 2 3 4 and I'm using D frames to animate this column right here and once it gets past 7 the animation stops ok the next line this is where our logic happens it's an IIF which is an if statement the way this works is you put in a bit of logic here in this case D frames greater than 7 so it's gonna be a true or false if it's greater than 7 it's gonna return this first part after the comma if this is false meaning it's less than 7 it's gonna return the second part over here when we're greater than 7 we return whatever the digit is in this case 8 times our height and we're going to use that when we return a point at the bottom so that's setting the position based off the height as the digit gets higher we're going to be offsetting the height by more the last part here is if the D frames is less than 7 this is what we're going to do our animation we're gonna take the previous digit and get what its height should be then we're going to add our height which is 0.28 times a fraction here and this is going to be our d frame so if D frames is 0 we're gonna be adding nothing to the height once it gets to 2/3 we're gonna add be adding a little bit more a little bit more and once it gets to 7 we're going to be adding the full height because D frames divided by 7 is 1 I know there's a lot of math in there I hope you could kind of understand it and follow along and that's basically how it works this is the expression for the ones column the expressions for the tens and hundreds columns are almost identical the only difference is here for the frames we're going to multiply this by 10 or by 100 and down here in this frames we're going to multiply this the frames times 10 or and that's gonna get us the correct digit and it works just the same now I also have this other script I think I'm probably not going to include it because this video is getting pretty long but what we can do is we can remove this column we can remove this expression here and click on these settings and in the frame render scripts we can go into this area and put in a slightly different script that does exactly the same thing we can put in some Lua code to set the position just like the expression does thanks so much for watching I hope you learned a little bit about expressions and maybe got a few ideas of some things that you can do with them like this video and subscribe to my channel for more videos about the vintage resolve filmmaking and maybe some interesting ideas comment below and let me know what you think thanks for watching [Music]
Info
Channel: William Justice
Views: 14,744
Rating: undefined out of 5
Keywords: Video Effects, Davinci, Davinci Resolve, Davinci Resolve 16, Fusion, Davinci Fusion, Tutorial, Filmmaking, Effects, tips, tricks, davinci resovle tips, william justice, Expressions, countdown timer, progress bar, animated counter, fusion script, date, time
Id: 2PjaZWwoxX0
Channel Id: undefined
Length: 25min 13sec (1513 seconds)
Published: Fri May 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.