0:00 You want to learn shader nodes? I know 0:01 shader nodes. In this video, I'm going 0:02 to teach you what I know. It's going to 0:04 be fast, so if you can't hang, slow it 0:05 down, but we're going from nothing to 0:06 everything. Here we go. This video is 0:08 sponsored by Skillshare, and we're going 0:09 to talk about that in a bit. So, in 0:10 Blender, when you're doing shading, you 0:12 go to, surprise surprise, the shading 0:13 workspace, and this is where we do our 0:14 work. An object inherits a material, and 0:17 what we do in the material is reflected 0:18 in the object. So, if I get rid of 0:20 everything and maybe put down plane, I 0:21 can give this a new material, where I'm 0:23 going to call this teaching you, and 0:24 then anything we do here is reflected on 0:26 that object. And of course, if I add 0:27 another object and inherit the same 0:29 context of material, and then this 0:31 changes both of them, okay? So, objects 0:32 inherit a material. For most of this 0:34 course, we're just going to be using a 0:36 grid, cuz it's easy to visualize, so 0:37 make sure you're either in look dev or 0:38 rendered mode. I'm mainly going to be in 0:40 look dev, and we're going to look from 0:41 the top view. And let's kind of expand 0:42 this so you can see what we're doing the 0:43 whole time. So, as you can see, we have 0:45 a default node setup with this weird 0:46 node called the principled BSDF, but 0:48 what matters is that that is piping into 0:49 the surface of the material output. If I 0:51 get rid of this, it's going to be black 0:53 cuz nothing is piping into it. If I do 0:54 this, now we're going to have something 0:56 piping into it. I can create a different 0:57 node, maybe this one's going to be red, 0:58 and now we can switch between the two. 1:00 So, without knowing what this means, all 1:01 you need to know is that a link sends 1:02 information into the surface of the 1:04 material output. We'll talk about volume 1:06 and displacement. The simplest thing we 1:07 can plug into the surface is just a 1:09 number. So, shift A to add nodes. I'm 1:11 going to type in value. You're going to 1:12 learn the names of these as we go. 1:13 Connect this to this. By the way, if 1:14 you're wondering how I do all these like 1:16 quick things, there's an add-on called 1:17 Node Wrangler. So, in add-ons, type Node 1:19 Wrangler and enable it. There's a lot to 1:20 learn with it, but basically, you hold 1:22 down alt and right-click drag to do 1:23 surface, control and right-click drag to 1:25 cut, and then there's a few more. So, we 1:26 connect the value to the surface, and 1:27 you can see as I change this, it is 1:29 going to change the brightness of the 1:30 thing. A value is just a number, where 1:32 zero means black and one means white, 1:34 and then 0.5 is gray in between. And it 1:36 turns out you can actually go above one. 1:38 So, if I make it 10, you can see it's 1:39 actually noticeably brighter. And it 1:40 turns out you can also go negative, but 1:42 that's still going to look like black 1:43 cuz anything below zero is going to look 1:44 black, but it is actually storing this 1:46 number, where we can add in a math node, 1:48 which we'll talk about in a second. I 1:49 can multiply by -1, and we get white 1:51 back, because -1 * -1 is equal to 1, 1:54 which means this must be storing the 1:55 value. By the way, I like using snapping 1:57 here to make sure that everything I do 1:58 is in this like nice grid, where 1:59 everything everything's organized. As 2:01 you might expect, we can take values and 2:02 add them together. So, we can have 2:03 different nodes with different values. 2:05 Our next most important node is the math 2:06 node, and this is how we combine them. 2:08 So, I've added these two values. If I 2:09 make them both zero, it's black. If I 2:11 increase one, you know, either one is 2:12 going to get brighter. And if I do 0.5 2:14 on both, this is going to equal one cuz 2:15 it's 0.5 * 2. And if I compare this to a 2:17 value of one, it's going to look the 2:19 same cuz they're both a value of one. 2:20 There's a whole list of operations here. 2:22 Most of them you know, like add, 2:23 subtract, multiply, whatever, but 2:24 there's probably some you don't know. 2:25 We're not going to use most of these, 2:26 but one important one is sign. So, we 2:28 have signs and cosines, where as you 2:30 increase this, it's going to go from 2:30 black to white to black to white. So, 2:31 this is a good way to kind of have 2:33 repetition, where we're using the sine 2:34 wave, right? Where we have bright areas 2:36 repeating, and then dark areas 2:37 repeating. If we have a single number, 2:38 you might wonder, can we have multiple 2:40 numbers? The answer is yes. A simple way 2:41 to think about this is you can actually 2:43 bring in a color. So, instead of value, 2:44 you have a node called RGB, that's red, 2:46 green, blue. You view it, and basically, 2:47 it, you know, represents the color of 2:49 whatever you pick here. Pretty simple. 2:50 Now, the reason I call this multiple 2:51 numbers is you can see it says red, 2:52 green, blue. This is actually three 2:54 numbers, where if I open this, you can 2:55 see if we go to RGB, there's a literally 2:57 three numbers. So, if I set the first 2:58 number to one, it's going to be red. If 3:00 I set the second number to one, it's 3:01 going to be red plus green, which is 3:02 kind of this yellowish. And if I have 3:04 one on all, it's going to be white. And 3:05 if all these are zero, it's going to be 3:06 black. So, these are three numbers 3:07 representing a color. And really, what 3:09 this is is it's something called a 3:10 vector. A vector is basically a list of 3:12 numbers that, you know, generally has 3:13 more than one. In this case, we have an 3:15 XYZ or red, green, blue. Instead of a 3:17 color, we can also just use a straight 3:18 up vector. These are basically the same 3:20 thing, but we just think about them a 3:21 little differently. Where again, we have 3:22 red, green, blue, essentially. If I set 3:24 X to one, it's red. If I set Y to one, 3:25 it's kind of the yellowish. It's the 3:26 exact same thing. The difference with 3:28 this node versus the RGB node is you're 3:30 going to see that this one has 3:31 connections, which means we can vary 3:33 what's going on. So, for example, in the 3:35 X component, and you can just drag and 3:36 write something in, I'm going to have 3:37 the sign of some value, okay? So, now 3:39 it's going black to red to black to red. 3:41 And then let's also do one on the Z, so 3:42 this is going to be blue. And for the 3:44 value, I can connect the same number to 3:45 both of these. So, this is our most 3:46 complicated network yet. The way you 3:48 want to read this is we have a number 3:49 that is going through two sine 3:50 functions, and one's going to X, and one 3:52 is going to Z. We can see it's going 3:53 black to purple, black to purple, or 3:55 kind of the magenta. And you might 3:56 wonder, if these are the same, why don't 3:57 I just use a single one of these? That 3:58 is right, it's going to give the same 3:59 thing. But the reason we might want to 4:00 separate these is I want to do different 4:02 things for red and blue. For example, I 4:04 can add an offset of, let's say, pi 4:06 here. So, now these sine waves, instead 4:08 of being like in sync, one is like this, 4:10 and then the other is perfectly out of 4:11 sync. In fact, it's actually a cosine 4:12 wave. Where now you can see there's more 4:14 going on. It's going red to blue to red 4:15 to blue. And by the way, just a tip, if 4:17 you don't want to keyframe or animate 4:18 this, you can click this, type hashtag, 4:20 which basically means I'm going to make 4:21 an expression, type in frame, and this 4:23 is literally going to give the frame 4:24 number. So, I'm on frame 25, which means 4:26 that this is going to be 25. And as I go 4:27 down, it's going to do that. 4:28 Additionally, I can take this and divide 4:30 it by something like 10. This is going 4:32 to take the frame number. It's going to 4:33 divide it by 10, which means it's going 4:34 to be smaller, which means it's going to 4:35 move slower. And now we have the same 4:37 thing, but it's a slow evolution. 4:39 Remember, I can apply this material to 4:40 any object. So, this has the same 4:42 material, and now they are both 4:43 flashing. Just like we can add numbers 4:45 or values together, so too can we add 4:47 vectors. So, here I have two vectors. 4:48 This is a vector math node. So, instead 4:50 of a math node, there's something called 4:51 a vector math node. Each one of these 4:52 can inherit a custom vector, or if you 4:54 don't need this control, you can just 4:55 type it in right here. So, red plus blue 4:57 is equal to purple. Or I can add even 4:59 more red, and it's going to be brighter, 5:00 maybe some green. If all of these are 5:02 -1, which does represent a negative 5:03 thing, but it's going to show up as 5:04 black. I add a value of two, it's going 5:06 to be white, because -1 on each 5:07 component plus two on each component is 5:09 equal to one on each component. These 5:10 are a bit more confusing, you might not 5:12 know them, but some of them are 5:13 familiar. Add, subtract, multiply, 5:14 divide. If I have zero times any vector, 5:16 and we multiply it, um, nothing's going 5:18 to change cuz it's always going to equal 5:19 zero. But if I set this equal to one, 5:20 basically, only the second vector is 5:22 going to represent cuz we multiplied by 5:23 one, which means it doesn't change. Now, 5:24 so far, we've outputted a vector or a 5:26 single number to this whole surface, 5:28 right? Anything we do is reflected on 5:29 the entire surface, but what if I want 5:31 one area to be black, one area to be 5:32 white, and maybe a gradient going 5:34 between them? Well, this is where we 5:35 introduce coordinates. And since we are 5:37 together learning about Blender shader 5:39 nodes, you need to know about the best 5:40 place to learn things online, which of 5:42 course, is Skillshare. Skillshare is the 5:44 best place to learn things online, 5:45 whether that be digital skills, life 5:47 skills, it's got it all. There's all 5:48 kinds of categories. So, you could do 5:50 film and video, that seems relevant to 5:51 us as like Blender people, graphic 5:52 design even more so, animation, and we 5:54 could even get specific. Let's do 5:56 Blender 3D, and you can see all kinds of 5:58 courses, some of which are very like 6:00 recent, like the Dune stuff. All kinds 6:02 of people that actually seem quite 6:03 familiar. We also have learning paths. 6:04 What these are is they're basically like 6:06 a curated sequence of a bunch of like 6:08 courses, one after another after 6:09 another, that's tied together, so you go 6:11 from zero to hero. So, recently, I've 6:13 been making a weird like website where 6:15 you can like type things in, and it's a 6:16 fun text editor with sound and all this, 6:18 fully dependent on HTML, which I don't 6:20 know much of. So, let's say we type in 6:22 HTML. Here you have HTML and CSS for 6:24 beginners, code your first website. It's 6:25 basically the idea of how do you make a 6:27 webpage without really knowing what that 6:28 is, made by Rich Armstrong. This is a 6:30 course that is super helpful if you 6:32 don't know the idea of tagging, what are 6:33 divs, and all of these things. It is 6:35 summer time. I don't know if you've 6:36 looked outside, but that means is that 6:37 you have a lot of time to learn 6:39 something online and finally do that 6:40 thing you'd said you'd do, whether 6:41 that's like making a website or learn 3D 6:43 animation or whatever it might be. So, 6:45 you guys can check out Skillshare, and 6:46 if you use my link in the description, 6:48 the first 500 people to do so will get a 6:50 one-month free trial of Skillshare, 6:51 which is plenty of time to watch a lot 6:52 of stuff. There is a coordinates node. 6:54 It's called texture coordinates, and 6:55 you're going to see all these things 6:56 that look confusing. Generated, normal, 6:57 UV, object, camera, windowed 6:59 coordinates, which is interesting cuz it 7:00 actually depends on where it is on your 7:02 screen. And if we use one of these 7:03 simple coordinate systems, like the UV 7:05 coordinates, you're going to see that we 7:06 basically have a graph going on here, 7:08 where in the bottom left corner, it's 7:09 completely black, so this is a value of 7:10 zero down here. And then as we progress 7:12 this way, you can see it gets redder and 7:13 redder and redder. This actually 7:14 represents the X axis, which is also 7:16 represented by red, and this means we're 7:18 increasing on X until we get an S equal 7:20 to one. Conversely, if we go up this 7:22 dimension, right? It gets greener and 7:23 greener and greener, just like the Y 7:25 axis is green, until we get a value of 7:27 one. And then if we go diagonal, we're 7:29 increasing both X and Y at the same kind 7:31 of rate. So, up here, we expect a vector 7:32 of 1, 1. This is a two-dimensional 7:35 vector, but actually, it is a 7:36 three-dimensional vector in a way, 7:37 because we have a Z coordinate that is 7:39 suppressed. So, instead of 1, 1, this is 7:40 one for the X, one for the Y, and then 7:42 zero for the Z is what's actually going 7:44 on here. Which means if I take these UV 7:46 coordinates, and this is a vector, 7:47 right? You can see this kind of purple 7:48 output. I can do a vector math, right? 7:49 So, nothing changes, but if I add a bit 7:51 of a Z component, you can see it's 7:52 getting a bit more blue, because we can 7:53 add a kind of tertiary component, the Z 7:55 component. You're going to notice that 7:56 this one is called UV, and that is no 7:58 accident. We can actually go to our UV 8:00 editor, and whatever we do with these 8:01 UVs translates, right? So, this is kind 8:03 of the bottom left black corner. And if 8:05 we shift it, you can see, now the kind 8:06 of center point is in the middle, cuz 8:07 this is the area on the bottom left. 8:09 Like I said, there's an X increasing, 8:10 and there is a Y increasing. Can we look 8:12 at one at a time? Yes. Because if we can 8:14 take a vector and write it as a 8:16 combination of XYZ, right? So too can we 8:18 separate a vector. So, I'm going to 8:20 separate XYZ, and now instead of this 8:21 two-dimensional, actually 8:22 three-dimensional coordinate system, I 8:23 can see the X component increasing. 8:25 Remember, black means zero, so this is 8:27 an X component of zero. And as we 8:28 increase, we get brighter equal to one. 8:30 Same thing with the Y axis. And you bet 8:31 that we can do all kinds of operations, 8:33 like addition, right? So, now you can 8:34 see that has more of a visual effect. Or 8:36 I can take X and Y and include both of 8:38 them, where we now add their components. 8:40 This is going to be equal to zero cuz X 8:41 is zero and Y is zero, we add them, it's 8:42 equal to zero. And then up here, you can 8:44 expect a value equal to two, cuz X is 8:45 equal to one and Y is equal to one, and 8:47 we added that. Let's multiply them 8:48 together. Now we get a more interesting 8:50 result, where we have X * Y. And you can 8:52 almost see this kind of like, I forget 8:54 the name. There there's a name for this 8:55 curve. I don't know if it's hyperbola or 8:56 whatever, but it's no coincidence that 8:58 you can actually see this curve, which 8:59 is kind of the equation you're used to 9:00 graphing. In fact, I can take this and 9:02 look at where this value is equal to 9:04 something. So, I can use the compare 9:06 function. So, this is a new one. You can 9:07 see there's actually three inputs. What 9:08 we do is we compare input one to input 9:10 two, and we use this epsilon value to 9:12 say, where are they almost equal to each 9:14 other, right? So, as I decrease this, 9:15 you're going to see it kind of gets 9:16 thinner, because our threshold for where 9:17 these are equal are kind of kind of 9:19 getting slimmer. So, let's see where X * 9:21 Y is equal to 0.5 with an epsilon of 9:24 something very tiny. Well, what you can 9:25 see is that this generates a curve that 9:27 I can actually sweep, right? This is 9:29 literally the equation. Let's do 0.25. 9:31 What I'm doing is I'm checking where X * 9:33 Y is equal to 0.25 with a bit of a plus 9:35 or minus with this epsilon. You can make 9:37 it really tiny, so it almost generates 9:38 the exact curve. And if you rearrange 9:39 this equation, we have Y is equal to 9:41 0.25 / X, which you might recognize as 9:44 the equation for whatever this thing's 9:46 called. Can we graph other things? We 9:47 sure can. Let's actually take X and take 9:49 the sine wave of it. And what I'm going 9:50 to do is I'm going to compare where the 9:51 sine of X is nearly equal to Y, okay? 9:54 And you can see it kind of gives this 9:55 gentle curve, but we don't actually see 9:56 our sine wave, and this is because again 9:58 X is going from zero to one, so we can 10:00 only go from sine of zero to sine of 10:02 one. And remember a sine wave has a 10:04 period of 2 pi. It takes 2 pi of input 10:06 to get from, you know, one place to the 10:07 other, which means if I take our X 10:09 component now and multiply it, you can 10:11 actually just write 2 * pi pi and we get 10:13 a kind of a sine wave. You can see we 10:14 have the top part, but why do we not see 10:16 the bottom part here? Let's think about 10:17 it. Well, remember our Y goes from zero 10:19 to one, whereas sine can get negative, 10:21 which means it's down here, which means 10:22 we can't see us. If I actually take this 10:24 sine wave and let's say we take kind of 10:25 the inverse, I'm going to multiply by 10:27 -1, now we get the other section cuz we 10:29 flipped it around. Additionally, I can 10:30 take something like a absolute value and 10:32 now we get this hump because the sine 10:33 wave was like this. This is the negative 10:34 component and I'm saying make it 10:35 positive. But what if I wanted to 10:37 capture the full sine wave also this 10:38 negative? Well, in that case I need to 10:40 remap our Y zero to one to something 10:42 like it should be able to go down here 10:43 -1 to 1 cuz that is the codomain of the 10:46 sine function. Well, there's actually a 10:47 node for that. It's called map range. 10:49 The range is basically how far this this 10:51 go. Again, Y goes zero to one, but I 10:52 want to increase the range to go from -1 10:54 to 1. What you can do is we said we're 10:56 looking at the Y component, we're going 10:57 from zero to one and I want to remap 10:58 that to -1 to 1 and now we get our sine 11:00 wave where I can multiply and guess let 11:02 me make this a bit thicker so we can see 11:04 where we can get kind of multiple period 11:05 of the sine wave. And one thing to note 11:07 about what we're doing here is it has 11:09 infinite resolution. No matter how much 11:10 I zoom in there won't be pixelation 11:11 because this is a mathematically perfect 11:13 equation. By the way, remember all of 11:15 this is ultimately dependent on our UV 11:16 coordinates, which means I can basically 11:18 I guess I can basically stretch it 11:19 because if I stretch it our UV 11:21 coordinates don't change, so it's forced 11:22 to still use this whole area, so it 11:23 stretches, but I can do something more 11:25 complicated like let's say I do a torus. 11:26 It inherit this material. Well, now you 11:28 can see it's doing something very weird 11:29 and it's not making a sine wave from 11:31 like the top perspective because our 11:32 torus has its own UV map. If I go to the 11:34 UV editor, you can see our torus has 11:36 this map and I can move it around. So 11:37 too can I take this UV coordinate and 11:39 sample different S sections of this. By 11:40 the way, if you're noticing that there's 11:41 this very weird kind of like section 11:43 over here, that's because our map range 11:44 strictly goes between -1 and 1 without 11:46 any kind of leeway for going above one, 11:48 right? Like when we go to 1.1 to it 11:50 doesn't like that and same with the 11:51 negative. You can change that by hitting 11:52 this clamp where we're no longer 11:54 clamping, we're no longer saying this is 11:55 a limit on with this thing. By the way, 11:57 clamping you're going to see is an 11:58 option in all these math nodes. It's 11:59 basically saying if we have the negative 12:00 value, so I'll say we have our timeline, 12:02 here is zero, here is one and here is 12:04 negative one. We're saying this whole 12:05 section, all the negative should just 12:06 become zero when we clamp and you can 12:08 see that over here. It kind of becomes a 12:09 flat line. Now, what if we want to make 12:11 a more complicated shape like let's say 12:12 we want to make a circle. Well, if we 12:14 want to make a circle, we kind of need 12:15 to know the equation for that. Well, a 12:16 circle is basically the set of points 12:18 that are equidistant from the center. So 12:19 if this is the center, you're going to 12:20 see every point in the circle is the 12:21 same distance of the radius away from 12:23 that. If you'll remember the radius, 12:25 which is basically a distance is 12:26 calculated by the Pythagorean theorem. X 12:28 squared plus Y squared is equal to kind 12:29 of like Z squared, but we take a square 12:31 root and now this is a distance 12:32 basically. So, if I want to calculate 12:33 the circle at .5, so we go halfway on 12:36 the X, halfway on the Y, what I need to 12:37 do is kind of do this calculation. So, 12:39 I'm going to take the UV coordinates and 12:40 I'm going to separate them, so we have X 12:41 and Y and I want to know kind of the 12:43 distance from this center, which we can 12:45 calculate by subtracting 12:46 .5. So you can see now it's kind of 12:47 moved to the center. By the way, this is 12:48 going to be negative values, which you 12:50 can correct for by just taking a 12:51 absolute value. Ultimately doesn't 12:53 matter cuz we're going to square it. So, 12:54 we have X squared compared to .5, so 12:56 let's take a power of two. So this is 12:58 squared and then we're going to take Y 12:59 squared and we are going to add these 13:01 together. I'm just doing the equation 13:02 and now you can see we kind of the 13:03 outline of a circle. And finally, we are 13:05 going to take a square root and we want 13:07 to check where this is like equal to one 13:08 for example and we know how to do that 13:10 already. I can compare this kind of 13:11 alpha to the number let's say .5 with a 13:13 epsilon that is very tiny, 13:15 .25 and now we have the equation for a 13:16 circle. We can pick a different radius 13:18 for. But notice before we did our 13:20 compare, we had something called a 13:21 field. A field is basically saying each 13:23 point on the surface has a different 13:25 like value we're evaluating at every 13:26 shading point where the center is quite 13:27 black as the distance from the center to 13:29 the shading point is very tiny and then 13:31 as we go further away, it gets bigger, 13:32 which means we can do all kinds of 13:33 things with this. We don't need to say 13:34 where this is less than or greater than 13:36 or equal to something. I can actually 13:37 take this and let's get weird. I can 13:38 take the sine wave of this and we don't 13:40 see it right yet cuz again we need more 13:41 periodicity, so I'm going to multiply 13:43 this by a bigger number and now you can 13:44 see we actually have something more 13:45 complicated. So, originally we basically 13:47 had a function that tells us the 13:48 distance from the center and along this 13:50 I'm calculating a sine wave. So now if I 13:52 take this and do some kind of 13:53 comparison, so I'm going to compare here 13:54 to like .25, you can see we get 13:56 something more complicated. Let me lower 13:57 this epsilon by like that. You can also 14:00 kind of offset over time. So we changed 14:02 our periodicity, I can also add to 14:04 change the phase and this is something 14:05 we can do over time. So I'm going to 14:06 write hash frame. You're not going to 14:07 see it as it moves quite quickly, so I'm 14:08 going to do the frame number divided by 14:10 10 just like before and now you can see 14:11 this kind of ring. I can also take our 14:13 distance function, which by the way, if 14:15 you want to put all this in one like 14:16 category, you can either take this and 14:17 hit shift E to put it in a frame or 14:19 panel P for panel or even better take it 14:21 control G and now it's in something 14:22 called a group. So I'm just going to 14:24 make this so we have a single output 14:25 instead of like one, two outputs. So 14:27 this is shift click right drag. I'm 14:28 going to take this control G. This is a 14:30 node group and I'm going to call this 14:31 distance. So this is our distance 14:33 evaluator and then I'm running all kinds 14:34 of math to do something like that. But I 14:35 can take this distance field and do 14:37 other things. So let's do a map range. 14:38 So again, this distance basically goes 14:40 from zero and then it increases to one 14:42 to two and it keeps going. Well, I can 14:43 take this range and invert it zero to 14:45 one to one to zero or I guess I want to 14:46 make this tinier. Now we kind of have 14:48 this soft circle because we're limiting 14:50 it from one to zero and I can take our 14:51 kind of sonar thing and then multiply it 14:53 by this and you can see now we have the 14:55 same thing, but it's kind of limited. 14:57 And if we think of this as a sonar, it 14:58 should probably be green, so I can 15:00 combine XYZ. Remember this is a vector 15:02 with three numbers. If I want my sonar 15:03 to be green, we need to increase the Y 15:05 or the green component. So I'm going to 15:07 put this here. I'm going to view it and 15:08 now we have a green sonar where we can 15:10 increase the epsilon to kind of get this 15:12 more visible sonar or multiply the 15:14 periodicity to get a more dense sonar. 15:15 By the way, if you don't want this 15:16 shrinking to the middle, but instead 15:18 expanding outwards, all I need to do is 15:19 take this and invert it. So you can take 15:21 the frame number, take the negative 15:22 frame number and now it's going outward 15:24 or simply you can just take this output 15:25 and multiply it by -1. Okay, so we have 15:27 our sonar, but we need something to be 15:29 detected by the sonar. So let's say we 15:30 have kind of like a target over here. So 15:32 in other words, we have a circle that 15:33 should be showing up on the sonar. Well, 15:34 remember we actually already know how to 15:36 do this. This is basically the circle. I 15:37 can take our UV coordinate, calculate 15:39 the distance, but now I don't want the 15:40 distance from the center, I want the 15:42 distance from something like over here. 15:43 Well, one way to do that is I can either 15:45 take our UV coordinate and kind of 15:46 offset them, which also kind of does the 15:48 right thing. Say I don't want to mess 15:49 with my UV coordinates, I just want to 15:50 mess with our distance. Well, remember 15:51 we're calculating the distance from the 15:53 center, so hit tab to go inside of here. 15:54 We're calculating the distance from X 15:56 value .5. So by the way, what if I want 15:58 one distance function to calculate from 15:59 the center and another from here? So you 16:01 want to duplicate and these do different 16:02 things. Well, the issue is so these are 16:04 the same right now. The issue is if I 16:05 change one of them, it changes the 16:06 other. These are the same now. So I want 16:07 these to basically be independent and I 16:09 want to control the X and Y without 16:10 going in here. Well, if I go in here and 16:12 take the X component and do this, so I'm 16:14 adding it to the group input. These are 16:15 now inputs. I can change the X and Y 16:17 where you can see we have numbers that 16:18 are exposed and these will give us 16:19 different results because one is looking 16:21 for the center from like .2 to .5. The 16:23 other one is using .5 to .5. So by the 16:25 way, if you don't want these called 16:26 value, but you actually want to remember 16:27 what they are, go into the node, hit N 16:28 for the panel and you're going to see 16:29 all these options where we can actually 16:31 take this value, rename it to X, take 16:32 this, rename it to Y. So you can see 16:34 that updated here and then for the 16:35 output we can call it distance and then 16:36 for the coordinates we can call it 16:37 coordinates instead of vectors. So now 16:38 we know exactly what to do with this. 16:39 Okay, so we have our sonar, but we also 16:41 want a target. We know how to do this. I 16:42 use the distance, I use the map range 16:44 from before and now we have kind of this 16:45 like circle that I can move and if I 16:47 want to take before it becomes green, 16:48 but if I want to take our sonar map and 16:50 then include or add this, how do I 16:52 combine them? Well, I just said it. We 16:53 add, we combine their influence, right? 16:55 So I can take this whole thing and I can 16:56 add it to our circle. So now both are 16:58 included. In fact, I can kind of make 17:00 this sharper if I don't want it to be 17:01 the soft circle by saying, so here we 17:02 have our distance map that was inverted. 17:04 I want to make it a sharp circle, so I 17:06 can just say take this field and tell me 17:07 where it's greater than or less than 17:08 some numbers. If I use greater than, now 17:10 you can see we have this and we include 17:12 this into our green and now we have a 17:14 sonar. You're going to notice by the way 17:15 that this overlapping section a bit 17:17 brighter. If you want that, good. If you 17:18 don't, that's an issue. The reason it's 17:19 happening is we have contribution from 17:21 this where it's equal to one and also 17:22 this where it's equal to one, which 17:23 means where they overlap it's equal to 17:25 two. We don't want that. Well, similarly 17:27 to how we clamped the last, I can also 17:28 clamp the white values. So we can't go 17:30 below zero or above one. Another way to 17:32 do it is instead of adding, I can say we 17:34 want to add them, but only keep the 17:35 bigger of the two and don't like 17:36 literally just add them to become two. 17:37 Well, if we're keeping the bigger of the 17:38 two, that is called a maximum. This is 17:39 another way to do it. Another way to do 17:41 it is a minimum, which will give us kind 17:42 of the inverse. You can think of that as 17:43 a intersection. I want this to also fade 17:46 our dots. So all I need to do is kind of 17:47 change the order of operations where I 17:49 have this output and this output. I'm 17:51 taking the maximum, so it combines them 17:52 and then for this, so I'm going to 17:54 multiply by our like soft mask. So now 17:56 we get something like this. A little 17:57 hard to tell, but if I move it towards 17:58 the edge, you can see it kind of gets 17:59 fainter and we make that green. Cool 18:01 thing about this by the way is we can 18:02 just repeat this. So remember we have 18:04 our distance, which we can modify for 18:06 each one, so maybe this one will be a 18:08 bit to the left. We put it through the 18:09 same nodes. By the way, if you just want 18:10 to keep it simple, this which goes from 18:12 our distance to a sharp circle can also 18:13 be a node group control G. So I'm going 18:15 to call this circle maker. Here I can 18:17 have our distance go into a circle 18:18 maker, but it's using a different 18:19 distance input from the other one. Just 18:21 like before, we have our sine wave, we 18:23 have our circle and we took the maximum 18:25 between the two. I want to also include 18:27 our other circle, so I can take this and 18:29 then take another maximum, right? By the 18:31 way, alt S to kind of shift these, 18:33 although in this case it doesn't matter. 18:34 And now we have both circles that we 18:35 multiplied by our soft map that we make 18:37 green. So this is our sonar and you can 18:39 also have these targets move over time 18:41 by saying we take the X component, so 18:42 let's actually do this explicitly. I can 18:44 take the X component that's 18:45 .33 and then we can add or subtract some 18:47 value over time so that it's moving. I'm 18:49 just going to use a driver hash frame 18:50 divided by 10, which will go a bit too 18:52 fast, so I'm going to divide by 100 and 18:54 now it's slowly moving across the 18:55 screen. We can make it even slower. 18:57 Whereas this, I can also write hash 18:59 frame divided by 100 here. But this one 19:01 I also add .52, so you can make your 19:02 expression more wild. But a sonar 19:04 usually has this kind of like rotating 19:06 thing that basically like scans as it 19:08 updates. It rotates. Well, to do that, I 19:10 basically need a new function that takes 19:12 our coordinate system and from the 19:13 center kind of gives us the angle. Well, 19:15 class you'll recognize this as the polar 19:16 coordinates where instead of Cartesian 19:18 coordinates, right? We go from X going 19:19 from zero to one and Y going to zero to 19:21 one and a point here is basically its X 19:22 component and then its Y component. A 19:24 polar coordinate system is instead given 19:26 by instead of like X and Y, it's given 19:28 by an angle and a radius, right? So this 19:29 point right here is basically defined by 19:31 the angle theta from the X axis and then 19:33 the radius from the center. Or a point 19:35 like this can be an even larger angle 19:37 with a smaller radius. So we're just 19:39 kind of converting. Well, we already 19:40 know how to calculate radius from the 19:41 center. That's just our distance 19:43 function. Going to put that here. We're 19:44 calculating the distance from the center 19:46 .5. This is our radius, which I can just 19:48 rename to radius, but we also need to 19:50 calculate the angle of every point. 19:52 Well, this is kind of a special trick 19:53 where let's say we have an angle equal 19:55 to beta. This angle is still defined by 19:57 X and Y, right? So, we go some 19:59 components. So, let's say we have this. 20:01 We have some components on the X and 20:02 some component from the Y. And remember 20:04 we want to calculate this angle over 20:05 here. And if you remember so ka toa, 20:07 sine cosine tangent, you're going to see 20:09 that this is the opposite, right? The 20:10 opposite over the adjacent, right? So, 20:12 tangent, let's write this down. Tangent 20:14 of beta of beta is equal to opposite, 20:16 which in this case is going to be the Y 20:17 component. So, opposite divided by 20:19 adjacent, which is the X component. 20:20 Which means if I take a inverse tangent, 20:22 right? On both sides, we're going to 20:23 find that beta is equal to the inverse 20:25 tangent of inverse tangent of Y divided 20:28 by X. In other words, we have a 20:29 complicated equation for the angle. If I 20:31 want to Y divided by X, we have our UV 20:32 coordinates, which are two-dimensional, 20:34 actually three. I'm going to connect 20:35 this here so we get the X and the Y 20:36 component. And instead of doing this 20:37 division and inverse tangent, there's 20:39 already a function for us. It's called 20:40 arc tan two. Tan two does the division 20:43 for you and some other thing where I can 20:44 say this is Y divided by X. And now this 20:47 is going to give an angle. So, it's hard 20:48 to tell, but it's going to give an angle 20:49 from the center, which is actually over 20:51 here because we didn't shift it yet. So, 20:52 remember our UV coordinates are equal to 20:53 0 0 down here. We just didn't shift 20:55 them. But this gives an angle where I 20:56 can do a greater than to see it gives an 20:58 angle that sweeps. But if I want to 20:59 calculate the angle from the middle, all 21:01 I want to do is take our UV coordinates 21:02 and shift them this way, which means 21:03 like we know you can take the vector 21:05 math and to do a I guess a subtraction 21:07 or adding a negative. So, subtract by 21:08 0.5 0.5, right? You might think that you 21:10 want to add 0.5 0.5 to get here, but 21:12 it's actually the inverse because if 21:13 this is equal to 0.5 0.5, when we 21:15 subtract 0.5 0.5, it becomes zero. 21:16 You're going to see it looks a bit 21:17 weird. Uh the way this is working, by 21:18 the way, is you can see it sweeps like 21:20 this, but then it kind of stops. And it 21:21 stops at not just a random number, but a 21:23 very specific number. Uh this number you 21:24 might recognize as pi. But you can also 21:26 go the other way, right? So, the thing 21:27 is this output a value 0 to pi uh for an 21:30 angle, but then it's 0 to negative pi 21:31 over here. But what if I wanted to go 21:33 from 0 to 2 pi like normally? Well, this 21:35 section's fine. This is the section I 21:36 want to uh invert. Well, if I want to 21:38 invert the bottom section, all I need to 21:40 do is isolate it and then multiply by 21:41 -1. Well, how do I isolate the section? 21:43 This is where the Y component, the Y, 21:45 the height, the vertical is less than 21:47 0.5, right? The bottom section. In other 21:48 words, I can take this Y component that 21:50 we had from before. I'm going to see 21:52 where it is less than Oh, no, we already 21:53 did our shift here. Remember we did 21:55 this. So, what I can do is either do it 21:56 with a separate UV coordinate or let's 21:58 just do it with a separate UV coordinate 21:59 to keep it simple. So, again, I'm going 22:00 to separate my UV coordinates. I want to 22:01 know where our Y component is less than 22:02 0.5, right? This is the bottom section. 22:04 For this, I want to take the arc tangent 22:05 and multiply by -1. So, the issue here 22:08 is if I take this and then like multiply 22:09 by this and then like multiply by -1, it 22:11 all kind of gets a little weird. So, 22:13 what I want to do is I want to say for 22:14 this top section, do nothing, and for 22:15 the bottom section, multiply by -1. 22:17 Well, here is another important note. 22:18 It's called the mix node. What the mix 22:20 node does is allows you to have two 22:21 numbers like 0 and 1, and then you can 22:22 switch in between them with this factor. 22:24 So, when this is equal to 1, it's going 22:25 to use the B, and when this is equal to 22:26 0, it's going to use the A. I can just 22:28 have arc tangent, and then for B, I can 22:30 take the arc tangent, and like we said, 22:31 multiply by -1. So, something like that. 22:33 So, we have arc tangent, and then this 22:35 multiply by -1, which you can see kind 22:36 of inverse it. And the difference 22:37 between using A and B should be this 22:39 kind of mask here. So, we do this, and 22:41 now you can see we have This isn't This 22:42 is actually not exactly what we want, 22:44 but you can see now we have our full 22:45 spectrum where if I do a greater than, 22:46 it's actually going to give something a 22:47 different. It's going to give this pi 22:48 wedge, kind of like a Pac-Man eating it, 22:50 which is actually pretty interesting. 22:51 This is because we go from 0 to pi, but 22:52 then in this section we're also going 0 22:54 to pi. So, multiplying by -1 was kind of 22:56 the right idea, but really what I want 22:57 is we had this 0 to negative pi. This 23:00 should be remapped to pi to 2 pi, kind 23:02 of kind of confusing, but we know how to 23:03 do this. We have our arc tan two, and we 23:05 know I just want to remap the range from 23:07 Remember, it's going from You could do 23:08 it either way. Let's say we're going 23:09 from pi to Oh, sorry, negative pi to 0. 23:11 We go from negative pi to 0, and that 23:13 should become So, right now it's going 0 23:15 to 1. This should become pi to 2 pi, 23:17 right? I'm just redefining this. And 23:19 then this is what I want to have as our 23:20 B component. So, now we have 0 to pi, 23:22 and then for the bottom section, pi to 2 23:23 pi, and now we have the full sweep. 23:25 Okay? Very complicated, but kind of the 23:26 takeaway here is now I can do kind of a 23:28 compare function where I can say where 23:30 is this equal to let's say pi, right? 23:32 Which should be this direction with an 23:33 epsilon of 0.05. And as I sweep this, 23:35 it's going to give a circle. By the way, 23:37 another issue, uh when we go from 0, 23:38 it's good. We increase, we increase, we 23:39 increase, and then we're at 2 pi, and 23:41 then it goes away. Why is that? This is 23:42 because our angle goes from 0 to 2 pi, 23:43 but then we don't increase, right? And 23:45 then go to like 3 pi and 4 pi. It just 23:46 goes from 0 to 2 pi. Which means this 23:48 compare is going to operate at a at 23:50 certain section. So, if I want to sweep, 23:51 I somehow need to say go from 0 to 2 pi 23:53 and then go back to 0 and 2 pi and all 23:55 this. In other words, the range 0 to 2 23:57 pi is totally weird as to ever is 23:59 totally fine, but then as we go from 2 24:01 pi to 4 pi, um it should again become 0 24:03 to pi, same with a 4 pi to 6 pi. 24:05 Basically, we always need to bring it 24:06 back. In this case, it would work by 24:07 just subtracting 2 pi. 2 pi would become 24:09 0, 4 pi would become 2 pi, etc. So, 24:11 let's actually just, you know, take a 24:12 crack at this. So, uh what I can do is I 24:14 can just Oh, well, let's actually do it 24:15 as a value to keep it simple. So, here 24:16 we have a value. I'm going to take the 24:18 frame number. Remember, frame 0 it's 24:19 black, and then it gets wider. We 24:20 actually start on frame one, it's white, 24:22 and then it gets even more white. Uh 24:23 this is something that should always 24:25 remap 0 to 2 pi. Uh let's take this and 24:27 first of all divide by 10 so that it 24:29 grows much slower. And then I want to 24:31 know when this has exceeded 2 pi. So, I 24:33 can take this and say when are you 24:35 greater than, let's say, 2 pi, right? 24:37 So, in the beginning it's going to be 24:38 black, and then as we play, eventually 24:39 it's going to become white. Well, in 24:41 that case, what I want to do is then 24:42 remap it to the beginning. And there is 24:44 a math node for that. It turns out it is 24:45 called fraction. What fraction does is 24:47 let's say we have a timeline that 24:48 increases from, let's say, 0 to 1 to 2. 24:50 What it does is it takes each one of 24:52 these sections that's above 0 to 1, and 24:54 it remaps it to the beginning. The way 24:55 it does this, and the reason it's called 24:56 fraction, is let's say we have a number 24:58 here like 1.3. What it does is it 24:59 basically truncates. It gets rid of this 25:01 one, which makes it equal to 0.3, which 25:03 means it's remapped back here. So, too, 25:04 if we have 2.3, it will just get rid of 25:06 the integer component and then remap to 25:08 0.3. And it does this over and over and 25:09 over again. Uh this with the fraction is 25:11 going to be kind of blackish and white, 25:12 and then it repeats because it keeps 25:13 going from 0 to 1 over and over again. 25:15 But if I wanted to go from 0 to 1 to 0 25:16 to 2 pi, I just multiply this by 2 pi, 25:19 connect this here, and let's see what we 25:20 got. We have our circle, and it goes on 25:21 forever because we keep going 0 to 2 pi. 25:23 To make this slower, I'm going to divide 25:24 by 100. So, what I am going to do is I'm 25:27 going to take this whole nonsense over 25:28 here and just keep it simple where I'm 25:30 going to control G uh to make this a 25:31 node group so now we're a bit cleaner 25:32 here. By the way, take a node control H 25:34 to hide every socket we're not using. 25:35 This is going to be our angle. Have our 25:37 angle actually inside of here. I'm going 25:39 to bring back our compare nodes. I want 25:41 to compare this to, let's say, 0 with 25:42 epsilon of something a bit bigger. Okay, 25:44 actually we did that wrong. We have our 25:46 angle, and then we compare to this light 25:47 changing value with an epsilon of 25:48 something tiny. I want to take this and 25:50 add it to our sonars. Remember, we had 25:52 our sonar, we added a dot, we added 25:53 another dot, and then we multiplied by 25:55 our feed. Just like before, we add one 25:56 more maximum including our angle. And 25:58 now we have all these components that we 25:59 dampen and we make uh green. No reason 26:02 you can't take this and make it blue, 26:03 right? Using the Z component. In fact, 26:04 here's a way you can think about it. We 26:05 can take a vector math, which again is a 26:07 three-dimensional thing. You could think 26:08 of it as a color or vector. Let's say I 26:10 pick the color red. I can take this and 26:11 I can multiply it by this map right 26:13 here, which is 0 to 1. So, I'm going to 26:14 multiply. By the way, if you put a 26:15 number inside a vector, so let's say 26:17 this is equal to 0.1, what it does is 26:18 it's not 0.1 0 0. It makes it equal to 26:20 0.1 on X, Y, and Z. It just treats it as 26:22 a vector. Works the same everywhere. Now 26:24 we have red, and we can kind of change 26:26 this nice and dynamically and pick a 26:28 nice color. I'm going to go for green. 26:30 And again, everything we have here, 26:31 beauty of the nodes, completely uh 26:33 controllable. So, I can bring down the 26:35 periodicity, and now we have a sparser 26:36 sonar, denser sonar. Okay, let's move on 26:39 to a different section. We talked about 26:40 numbers, vectors, and coordinates, and 26:41 now let's talk about three-dimensional 26:43 things, right? We've been stuck on two 26:44 dimensions. Okay, so for part two, I'm 26:46 thinking we change what kind of 26:47 coordinate system we're using. We're 26:48 mainly going to talk about normal 26:50 coordinates. And now our goal is to do 26:51 more vector math and create more 26:53 interesting materials like moss or 26:54 grunge or dirt or whatever. So, this 26:56 time we're going to use not a flat 26:58 plane, but very intentionally I'm using 26:59 a mesh with kind of like curvature and 27:01 different faces. And in the shading 27:02 workspace, I'm going to apply a new 27:04 material, and just like we've been 27:05 doing, I'm going to bring in a 27:06 coordinate system. Specifically, normal 27:08 coordinates. Now, what normal 27:09 coordinates describe is not like the 27:10 thing we're used to where we have kind 27:11 of like an X, a Y, a Z axis, and we know 27:13 like how far along we are. No, a normal 27:15 coordinate basically tells us what 27:16 direction is facing outwards from the 27:18 mesh. So, here it's this direction, here 27:20 is this direction. You're going to 27:21 notice this is actually going to change 27:23 with the geometry. So, as I increase 27:24 this and maybe give it a bit of 27:25 rotation, you can see that color is 27:27 changing because now the direction that 27:28 is going outward is changing. 27:30 Additionally, if I shade smooth, it's 27:31 going to smooth the coordinates unless, 27:33 of course, we don't want that where we 27:34 can use this geometry node. Don't worry 27:36 about it where we have a normal 27:37 coordinates and a true normal, which 27:38 don't change under uh shade smooth. So, 27:40 we actually wanted to. So, why is 27:41 something like this useful? Well, it's 27:42 useful to know which direction is 27:44 outwards because then we can define more 27:46 complicated surfaces. So, instead of 27:47 saying, "Oh, only extract the top 27:49 section If I wanted something like moss 27:51 or dirt or whatever that will accumulate 27:53 on the top and not on this like overhang 27:54 over here, uh this is where normal 27:56 coordinates come in. So, for example, 27:57 let's say that again I want to drape 27:58 something over the surface. In other 28:00 words, I want it here, I want it here, I 28:02 want it here, but I don't want it in 28:04 this direction cuz it's facing kind of 28:05 downward. Well, how do I describe that 28:07 selection in three dimensions? Well, 28:08 here is a new operation that you might 28:10 have not heard of. It is called the dot 28:11 product in vector math, and what it 28:13 tells us is something about the angle. 28:14 In particular, if I have a vector going 28:16 upwards, again, a vector's a 28:17 three-dimensional quantity. In this 28:18 case, it is zero on the X, zero on the 28:20 Y, and one on the Z. In other words, 28:22 this is the direction that's going 28:23 straight up. Let's say I have this 28:24 vector and then also the surface normal. 28:26 You're going to see in this case the 28:27 angle between them is actually quite 28:29 tiny, which means they're almost 28:30 aligned. Whereas somewhere like here, we 28:32 have our upward Z vector, and we have a 28:34 surface normal, and this angle is huge. 28:36 In other words, if we can extract this 28:37 angle, we know what is kind of facing 28:39 upwards. And this is what dot product 28:40 does. So, I'm going to plug in the 28:41 normals, and for the second vector I'm 28:42 comparing, I'm going to use the Z up 28:44 direction. When I view this, you're 28:45 going to see it gives this kind of 28:46 interesting output that indeed kind of 28:48 isolates the top of the mesh. But more 28:49 particularly, it kind of gets rid of 28:51 these overhangs. And this is very 28:52 sensitive uh to mesh deformation. So, 28:54 you can see, let me actually rotate it 28:55 uh the other way. You can see we're 28:57 actually starting to re-expose sections 28:58 of it as it's like pointing upwards. 29:00 Now, the dot product doesn't actually 29:02 give you an angle. What it does is it 29:03 compares the two vectors and then gives 29:05 you a value between -1 and 1, very 29:07 similar to sine and cosine. It turns 29:09 out, though, that you can take this and 29:10 convert it into an angle using this 29:12 special formula. The dot product of two 29:14 vectors, the first one's going to be 29:15 called V, the second one's going to be 29:16 called W cuz I say so. This is basically 29:18 equal to something related to the angle, 29:20 but really it is the cosine of the 29:22 angle, which tells us we're going to 29:23 need to take a inverse cosine to extract 29:25 this. And then I believe it also cares 29:26 about the magnitude of the vectors, like 29:28 how big or long are they. So, it might 29:29 not exactly be this, but I think it's 29:30 the magnitude of V times the magnitude 29:32 of W. But if we can make sure that these 29:34 are both equal to one, then we don't 29:35 actually care about that. And to make 29:36 sure that our vectors are of distance 29:38 one, that's also called normalized, what 29:39 we can do, and they actually are 29:41 already, but you can bring in a vector 29:42 math, and there's an operation for this. 29:43 It's called normalize. What it does is 29:45 it makes sure that if you have a vector 29:46 pointing in this direction, it maintains 29:48 that vector, but it makes sure that it 29:49 has a magnitude of one. So, this is a 29:51 vector, this is the normalized vector. 29:52 Just make sure it has a length one. But, 29:54 as you can see, 001 obviously has a 29:56 height of one cuz it's only on the Z 29:57 axis. So, if we take this and then take 30:00 a inverse cosine, which is going to give 30:01 us something kind of similar, it's 30:02 called arc cosine, but this is going to 30:04 give us the angle. This is exactly going 30:06 to be black wherever that this is kind 30:08 of pointing directly upward, which we 30:09 can actually isolate uh just like that. 30:11 So, this is a good way to find where 30:12 there's water cuz it always kind of goes 30:14 the level to a thing. Uh but that that's 30:16 that's what you got. Now, it turns out 30:17 we don't actually care about this cuz we 30:18 can still use this -1 to 1 to define 30:20 something, but let's kind of stick with 30:21 that. So, let's say that we have kind of 30:23 like moss on the top and not moss on the 30:24 bottom. Remember, we do have this kind 30:26 of like mix node we've been talking 30:28 about where we can make this the factor. 30:29 So, I can make one of these one, the 30:31 other one 0.5, and it will basically 30:32 choose as we let me like decrease the 30:34 value. It'll basically choose what gets 30:36 like what value depending on what is 30:37 black and what is white. But, it turns 30:39 out there's not just a mix node, but 30:40 there's a mix color, which works exactly 30:42 the same, right? So, I can have one of 30:43 these be red, one of these be blue, and 30:44 now you can see we're kind of shifting 30:46 between them where in between we have 30:47 this purple. Because this is not exactly 30:49 black or white, there's some gray in 30:50 between just like real life. But, we 30:51 could get rid of that if I say where is 30:52 this greater than let's say 0.5, and now 30:54 we have kind of like a sharp color if 30:55 you want that. And like I said, colors 30:57 and vectors basically the same thing. 30:58 They're a three-dimensional vector, 30:59 which means if we have a mix color, so 31:01 too can we use a mix vector where let's 31:02 say one is red and one is blue. So, I'm 31:04 just writing it explicitly, and it gives 31:06 us the same thing, right? I want this to 31:07 be grass or moss or at least it should 31:09 be kind of like a dark green up here, 31:11 and then on the bottom it can be kind of 31:12 like a dirt color, so kind of like a 31:14 brown. And this is kind of like our 31:15 basic uh moss setup that is responsive 31:18 uh to the environment. In fact, if I add 31:20 something with harsher edges, you can 31:21 see it's only on the top face, but as I 31:22 bevel, it will kind of fade off as the 31:24 vector aligns less and less with the uh 31:26 Z up. Additionally, we can get fancy, 31:28 and we'll come back to the moss where 31:29 instead of having this kind of like up 31:31 direction, which by the way, you can 31:32 totally change. So, we can say what is 31:33 facing the X direction, and now it's 31:35 pointing this way. Or you can do that 31:36 plus Y. Instead of something like that, 31:37 we can use the dot product to create 31:38 something interesting. Where let's say 31:40 that we have a camera that is facing our 31:42 geometry. So, I'm just going to camera 31:43 to view to face our geo from the 31:45 perspective of this camera, I want to 31:47 isolate the outline or roughly the 31:49 outline of this object, which is not 31:51 information we actually get inherently 31:52 with every style or something like this. 31:54 So, how do we do that? Well, in a case 31:55 like this, we know something is vaguely 31:57 on the outline if it is facing away from 31:59 us. So, this part of the sphere is 32:00 facing this way, whereas whereas the 32:02 camera is kind of facing this way to the 32:04 shading points. In other words, these 32:05 two basically make a right angle, and 32:07 they're not facing each other at all. On 32:08 the other hand, if we have a surface 32:10 point like this one right here that 32:11 we're facing exactly. Uh a little hard 32:13 to see with the three-dimensional, but 32:14 uh these two vectors basically align. 32:16 They're they're kind of inverses. But, 32:17 in a case like this, we know what is and 32:18 isn't facing us. Well, how do we get 32:20 this vector from the camera to the 32:21 surface? Well, there is kind of a node 32:23 for this, but let's do it explicitly. 32:24 The way we get one vector from here to 32:25 here is first of all, we need to know 32:27 the position of the camera, and second 32:28 of all, we need to know the position of 32:29 the surface point. For the camera, I'm 32:31 going to do this explicitly for now, so 32:32 I'm going to combine XYZ. And how do we 32:34 know the position of the camera? Well, 32:35 it is written right here, okay? So, I 32:37 can copy this X value, paste it in here, 32:39 same thing with the uh Y component, and 32:40 then finally the Z component. So, this 32:42 vector basically represents where the 32:44 camera is. It's not going to change no 32:45 matter uh what direction we look at it 32:47 from. And additionally, it's not going 32:48 to change when we move our camera 32:49 because then the location is changing, 32:51 and we haven't updated to that. Now, the 32:52 second thing we needed is the shading 32:53 point where we're looking on the 32:54 surface, right? So, we need the position 32:56 of points on the surface. Uh it turns 32:57 out we don't have that in our 32:58 coordinates, although it is in a way a 32:59 coordinate system. You have to use that 33:01 geometry node I was just talking about 33:02 where uh we have all kinds of things 33:04 like position that tells us the position 33:05 of this, which will change, right? Uh 33:07 depending on where the vertex positions 33:08 are. And to get the vector from the 33:09 camera to the position, all we have to 33:11 do is subtract the two. The reason for 33:13 this is if we have a world origin where 33:14 this is 000, the position represents the 33:17 vector to get to the shading point. So, 33:18 this is position. The camera vector that 33:20 we wrote out explicitly, so this is C, 33:22 goes from the origin to the camera. And 33:24 if we take the position and subtract 33:25 this camera, in other words, we're going 33:27 negative, so we go up the position and 33:28 then this way for the camera, it's a 33:30 little out of sight. Well, this minus 33:31 this is basically going to give us uh 33:33 this direction, which is parallel to 33:35 this one. So, in other words, what I 33:36 want to do is I want to take the 33:37 position. We are going to then subtract 33:39 away this camera vector. So, this is 33:40 basically going to give us the direction 33:42 facing this. But, remember for the dot 33:43 product, we want to always normalize cuz 33:45 that will make the equation nicer. And 33:47 now, for each point on the shading 33:48 surface, we know what direction the 33:49 camera's facing to get there, and we 33:51 also know the normal of the surface. So, 33:53 let's actually take the dot product. 33:54 Let's compare how close these are to 33:55 each other. So, I'm going to use a dot 33:57 product right here, connect these, and 33:59 let's see what that gives us. Well, it 34:00 gives us basically something that is 34:01 facing the camera. Okay, so it's a 34:02 little hard to tell, but the outline of 34:04 this is pretty much black. We can make 34:05 that more visible by let's say this is a 34:07 thing between -1 and 1. So, let's see 34:09 where this is greater than some number, 34:10 and you can see we've essentially 34:11 extracted out the outline, right? It 34:13 turns out that there is a name for this. 34:14 This is called Fresnel, which is 34:15 basically the angle of where we're 34:17 looking from compared to the surface 34:18 normal. So, here is what Fresnel looks 34:20 like. So, it looks something like this. 34:21 You can see it's dependent on the angle. 34:22 So, this is a custom Fresnel node where 34:24 just like before, we can use this as a 34:26 mixing to kind of blend dirt and moss 34:28 together if you wanted to. Well, you're 34:29 seeing that this is working, but it's 34:31 kind of very boring, and there's a lot 34:33 of fading going on over here, right? 34:34 There's no explicit moss and then no 34:36 moss. And we basically want to take this 34:37 black and white and kind of compress 34:38 them, increase the contrast. Well, 34:40 here's a super useful node to kind of do 34:41 this visually. So, we can take a color 34:43 ramp node. What this does is it takes a 34:45 input, and one of them is going to be 34:46 black, one of them's going to be white, 34:47 and you're going to see as I shift this, 34:49 it basically kind of recolors our thing. 34:51 We can actually invert this if we take 34:52 both handles and flip them. And most 34:53 importantly for us is we can take these 34:55 two and bring them very close together 34:57 to get kind of like a harsher falloff. 34:59 Additionally, you can kind of use this 35:00 as a fancy mix node where the white can 35:02 be mapped to kind of this dark green 35:03 that we had before, and the black can be 35:05 kind of like a dirt color. And just so 35:06 you know, there's a lot of ways to do 35:07 this. So, let me just add RGB curves. 35:09 There's a lot of ways to define this. 35:10 Only kind of prerequisite is it's got to 35:11 go from 0 to 1. That's just what RGB 35:13 curves like. So, I'm going to take map 35:15 range. We're going to go from -1 to 1 to 35:16 0 to 1, right? We remap the range. I'm 35:18 going to connect this to the color. So, 35:19 you're going to see we get something 35:20 like that, not much different than what 35:21 we had before. But now, we can kind of 35:23 sculpt out to the look of this and get 35:25 more uh custom kind of repetition kinds 35:27 of things. Just like we could have done 35:28 before and we did with the sonar. Like 35:30 you can take a sign and do kind of like 35:32 fancy things along this. So, let me 35:33 multiply or a kind of more frequency 35:35 thing. Okay, let's get back to our moss. 35:36 So, we have this, and we know how to 35:38 isolate it thanks to the dot product, 35:39 but it's kind of very harsh, right? 35:41 There's no kind of like noise or any 35:43 kind of organicness to that. only way we 35:45 could do this is if we modeled it 35:47 ourselves. So, we have some up, we have 35:48 some down, and it creates kind of this 35:49 distorted thing, which I want. But, what 35:50 if I don't want to model, and I just 35:52 want that detail in the material? Well, 35:53 this is where noises come in. So, if you 35:55 hit Shift A to add a node, you're going 35:56 to notice that there's this whole 35:57 section called texture where we have 35:59 noise texture, magic texture, all these. 36:01 You click one, and basically what it 36:02 shows you is a pattern that are dictated 36:04 by different rules that have this kind 36:05 of organic look to them. So, we have 36:07 noise texture. You kind of learn what 36:08 these are about. There's a wave texture. 36:09 Wave just means repeat just like we did 36:11 with the sine wave. And just like we use 36:13 this as a factor for our mixing, so too 36:15 can we use the noise texture, which will 36:16 now kind of fade between these. Notice 36:18 that the noise texture has this socket 36:20 right here, this vector socket, which 36:21 means it relies on a coordinate system 36:23 just like everything else does. By 36:24 default, it uses something called 36:25 generated coordinates. We haven't talked 36:27 about that, but we have talked about UV 36:28 coordinates, which are of course 36:29 dependent on the UVs of our mesh. Either 36:32 way, we're for now going to use this 36:33 default generated coordinate system. 36:34 Just for your information, we know 36:35 normal represents the direction out of 36:37 the surface. We know UV is the UV 36:39 texture. What generated coordinates do 36:41 is they basically take our mesh and make 36:42 a bounding box. They make the tiniest 36:44 possible box that kind of Well, let me 36:46 do this in three dimensions. They make 36:47 the tiniest possible box that contains 36:48 this mesh. And then for this cube, not a 36:50 grid, but a cube, it imposes a X 36:52 direction just like our UV. It imposes a 36:55 Y direction, but it also imposes a Z 36:57 direction. So, all of these are 36:58 three-dimensional, but this one's really 36:59 three-dimensional, right? It cares about 37:00 our X, Y, and Z, which of course we can 37:02 visualize by separating out the 37:03 spectrum. So, here is the X going from 37:05 left to right along the X axis. You can 37:07 see that here. Here is the Y that goes 37:09 this way. And then finally, we have the 37:10 Z that goes vertically. Either way, I 37:11 can take our dot product and kind of add 37:13 influence from this by just multiplying 37:15 them together. So, some sections get 37:16 multiplied by a number close to zero, so 37:18 they get darker. Uh let's do it like 37:20 this. And now, we have what we had 37:21 before, but with a bit uh with a bit of 37:24 kind of detail. So, now when we view 37:25 this, our moss looks a tiny bit better. 37:27 Again, we can kind of change the color 37:28 ramp here, but we still have kind of 37:30 this super weird look where this brown 37:32 is a single color, and this green is 37:34 essentially single color, and there's no 37:35 kind of detail going on here. But, 37:37 remember our noise texture has this 37:39 black and white going everywhere, which 37:40 means we can incorporate that not only 37:41 into our mask of where there's moss, but 37:43 also into the color of the moss. And 37:45 this is where we get into color math. 37:46 So, remember, we have value math. A 37:48 value is just a number, and you can take 37:49 two of these and multiply, add, 37:51 whatever. And then with vectors, we have 37:52 vector math. In the color world, you 37:54 could also use vector math like we 37:55 talked about, but in the color world, we 37:56 use mix color, which I showed you. 37:58 There's all these operations, which you 37:59 might be used to from Photoshop. This is 38:00 all like image editing, photoshoppy type 38:02 things. Some of these make a lot of 38:03 sense, right? We know what multiply 38:05 means. It's just multiply these two 38:06 color vectors. Add means add their 38:07 components, but there's all kinds of uh 38:09 weird ones. What I'm going to do is in 38:10 this mix color, for one of them, I'm 38:12 going to use our kind of green-brown 38:14 thing. And right now, just like our 38:15 normal mix, you can choose between 38:17 selection A and selection B. So, 38:18 selection B can be red, and we can go 38:20 between them. What I want to do is 38:21 instead of saying use one or the other 38:22 and average them with mixing, I want to 38:24 say explicitly multiply. So, when we 38:26 multiply this, and this factor now 38:27 represents how strong the multiplication 38:29 is. If I use one, it's really just 38:30 taking this and multiplying it by red. 38:32 What that is going to give us is just 38:33 the kind of darkish, noisy red. Let's 38:36 think about why that is. Well, we had 38:37 all this color that kind of takes up the 38:38 full color spectrum of our 38:40 three-dimensional vector space, we'll 38:41 call it red, green, blue. But, when we 38:43 multiplied it by red, we essentially 38:45 multiplied it by the vector one for red, 38:47 zero for green, zero for blue. We 38:48 multiply these, we get the red, but then 38:50 both of these over here are basically 38:52 canceled out cuz green is multiplied by 38:53 zero, and so is blue. So, we don't want 38:55 to do that. We want to multiply in a way 38:56 that doesn't isolate them. And 38:57 specifically, we want to use this noise 38:59 texture. So, let's just drag this here, 39:00 and you can see we now took what we had, 39:02 and we multiplied it with the noise 39:03 texture, which we can make softer or 39:04 harder. Our noise texture, you might 39:06 have noticed, has all these numbers, 39:07 scale, detail, roughness, whatever. As 39:09 kind of like a rule, you can think of 39:10 scale as basically kind of how densely 39:12 packed is this pattern. So, while scale 39:14 increases, you can see like the parts 39:16 kind of get smaller, so it's the inverse 39:17 of what you think. Think of it as 39:18 density. Let me bring that back down. 39:19 Detail is basically how detailed, I 39:21 guess, is this. So, this is before and 39:22 after. Just adds a bit more. Roughness 39:24 is basically kind of how spread out is 39:25 this pattern. And by the way, all of 39:27 this is easier to see if we use a color 39:28 ramp, not a mix color, but a color ramp. 39:30 So, now if I increase the detail, you 39:31 can really see it increasing the detail. 39:33 And you can really see it increasing the 39:34 roughness. And if I now substitute out 39:36 all our like noises with this new 39:38 high-contrast, detailed noise, you're 39:39 going to see we get what we got before, 39:40 but with more detail. So, I'm going to 39:42 increase the roughness just so it's a 39:43 bit more distributed, and I'm going to 39:45 make the black less intense by bringing 39:47 these kind of further apart. So, 39:48 something like that. It's actually 39:49 looking quite similar to a Minecraft 39:50 block because this is a way to kind of 39:52 make that material. And ultimately, all 39:54 of this is dependent on our nodes that 39:56 we can change at any time. Remember, a 39:57 dot product tells us what direction 39:59 we're kind of comparing to. So, if I 40:00 make this X, now we have grass that 40:01 grows sideways, which is pretty cool in 40:02 its own right. Let's do the Y component. 40:04 Now, it's going this way. And while we 40:05 have this material totally procedural, 40:07 so let's actually apply it to a 40:08 different object and make kind of like a 40:09 Minecraft block. So, we use a cube, we 40:11 apply this material, and now we get 40:12 something like this. Now, remember, the 40:13 reason that this is only on the top face 40:15 is this the only one that even remotely 40:17 faces up. All of them are basically 40:18 perpendicular as a test. But, the rest 40:20 of it totally applies, right? We had our 40:21 high-contrast noise texture, and 40:23 everything kind of maps the way we 40:24 wanted to. If you wanted to bleed off 40:25 the edges, a quick way to do that is we 40:27 just add a bit of a bevel, and now it 40:29 kind of bleeds a bit further down cuz 40:30 our surface normals are aligned, and 40:32 then a little less aligned, and then 40:33 barely aligned, and then not at all. And 40:35 you could get fancy where you can model, 40:36 you know, as you go. You can see it kind 40:38 of updates where the dirt should and 40:39 shouldn't be. I can inset remember, the 40:41 way generated coordinates were is they 40:42 create a bounding box for 41:04 our mesh in three dimensions, but if one 41:06 of these axes is super long like this Y 41:08 axis, our bounding box which always goes 41:10 from zero to one on each axis has Y go 41:12 from zero to one over a very big 41:14 distance, which creates that stretching. 41:15 One easy solution to this is like 41:17 generated coordinates, there's something 41:18 called object coordinates. They're 41:19 actually very similar, although instead 41:21 of using a bounding box, all it really 41:22 cares about is kind of the origin of our 41:25 mesh and then how far away each point 41:26 is, which means we can substitute this 41:28 in as object coordinates and view it, 41:30 and now we don't have any stretching no 41:31 matter how we modify the geometry. While 41:34 object coordinates doesn't care about 41:35 edit mode, which is quite nice, you can 41:36 see it kind of like changes with our 41:37 mesh. It does actually care about object 41:39 transforms. So, if I scale it this way, 41:41 you can see it still does our 41:42 stretching, which we don't want. You can 41:43 see right here we have this uh scaling 41:44 of eight that is fixed by applying this 41:46 uh scale. So, control A, apply scale, 41:48 and now we're all good. So, now we've 41:49 talked about different coordinate 41:50 systems and how to make something more 41:51 complicated. Okay, we're back with part 41:53 three. This time we're going to be 41:54 talking about BSDF, which is actually 41:56 how you use this thing in Eevee and 41:58 Cycles. So, let's get to it. So, what is 41:59 a BSDF? Well, it kind of stands for like 42:01 bidirectional surface direct It It 42:03 doesn't really matter what it means, but 42:05 what it is is it's basically a material, 42:07 it's basically a shader that responds to 42:09 lighting. Remember, if I go to the 42:10 shading workspace and just kind of view 42:12 our render and I get rid of this BSDF 42:14 and just do the kind of things we've 42:15 been doing, so let's make this white, it 42:17 doesn't actually respond to light 42:18 because why would it? It's just a value 42:20 of one, it doesn't care about the 42:21 context of the scene. But, there's this 42:22 whole class of nodes called shaders, and 42:24 most of these are blah blah blah BSDF, 42:26 and these are basically nodes somebody 42:27 else made that responds to light. 42:29 There's all kinds, usually the simplest 42:30 is considered diffuse BSDF. It's pretty 42:32 simple, you pick the color, which we 42:34 know is a three-dimensional vector, you 42:35 pick the roughness, which is basically 42:37 how shiny it is. So, let's switch over 42:39 to Cycles. It's kind of subtle, but 42:40 you'll see the difference as we increase 42:42 the roughness, right? It doesn't reflect 42:43 the light as much, and it is more green 42:44 than it was before. But, just so we 42:46 understand what's going on, let's make a 42:47 BSDF ourselves. So, let's make the same 42:50 kind of thing. So, we know RGB lets us 42:52 pick a three-dimensional vector. So, 42:53 here we have green, but of course, this 42:55 doesn't respond to lighting, it's kind 42:56 of like emissive. Uh the shadows don't 42:58 count, we only care about what's on the 42:59 surface. Well, to actually shade this, 43:01 what do we know about lights? If the 43:02 surface is kind of pointing towards the 43:04 light source, and of course, we're 43:05 talking about surface uh normals in this 43:07 context like we talked about, if it is 43:08 facing the light, it should be brighter 43:10 than something like over here that is 43:12 not facing the light and is kind of 43:13 obscured, which of course, we know how 43:14 to do as a dot product. So, the first 43:17 thing we need is we are going to 43:18 execute, we're not going to kill though, 43:19 we're going to execute a dot product, 43:21 the first of which of course is our 43:22 normal coordinates. We talked about 43:24 this, this gives us the vector at every, 43:25 you know, surface point, every face that 43:27 tells us which way it is facing. And the 43:29 other thing we care about is the 43:30 direction from surface point to the 43:32 light. We basically calculated this 43:34 before when we were treating this as a 43:35 camera, so let's do it again. We care 43:37 about the position of the shading point, 43:38 so here we have the position. And second 43:40 of all, we care about the location of 43:41 the light. And this is something we 43:43 subtract one from the other. In this 43:44 case, I want a vector that points 43:46 towards the light, so we're actually 43:47 going to have position be the second 43:49 socket, and then for the first socket, 43:50 we care about the position of the light. 43:51 For now, we are just going to copy it 43:53 manually, but then I'll show you how we 43:54 can like avoid this. And this is our Z 43:56 component that again gives us a vector 43:58 that is position dependent, but as we 44:00 know, we want to uh normalize this 44:01 vector before it goes into the dot 44:03 product just so we get good cosine of 44:04 beta properties and the length is one, 44:06 so I'm going to normalize. And of 44:07 course, you can also normalize your 44:09 normal coordinates, but they're actually 44:10 already normalized. It's in the name. 44:12 So, I'm going to take the dot product of 44:13 these, and let's view it. And you can 44:14 see this gives us pretty much exactly 44:16 what we want. This face that is not 44:17 facing the light is in darkness, and the 44:19 faces that are facing the light, you 44:21 know, are doing what they're supposed 44:22 to. When we rotate this object, you're 44:23 going to see the lighting doesn't update 44:24 because it actually cares about the 44:26 position of every vertex. That doesn't 44:27 technically change when you do an object 44:29 uh transform. So, if I go to edit mode 44:30 and now rotate, you're going to see the 44:31 lighting updates the way you would 44:33 expect it to, nice and in shadow. Uh 44:35 let's say we move our light around, it 44:36 doesn't do anything except for the uh 44:38 shadow, which we can actually get rid of 44:39 this plane so we can see what's going on 44:40 here. We want this to actually know 44:42 where the light is as it's updating, 44:43 which means we can't just have a static 44:45 vector. Instead, I can look at this X 44:47 component and see how it's updating by 44:49 right clicking, we say copy as a new 44:50 driver, and then in the material for the 44:52 X component, all you have to do is paste 44:54 the driver. So, what you're going to see 44:56 is right now it's 2.4, but as I move the 44:58 light around, there's now something 44:59 happening. Now, it's 1.6, it only 45:01 updates the X component. So, as you 45:02 expect, we right click, copy as a new 45:04 driver. What a driver basically means is 45:06 it references one piece of data to 45:08 update another piece of data. And now, 45:09 we've actually done everything we need. 45:11 Of course, it looks a little janky, but 45:12 we've done everything we need uh 45:14 technically to make a lighting setup. Of 45:16 course, this only works with a single 45:17 light, you'd have to add multiple light 45:18 sources, uh but it's not too bad. So, 45:20 you can think of this as in full 45:22 exposure until we darken and use our 45:23 lighting and everything. So, I'm going 45:25 to mix color, I'm going to multiply our 45:27 dot product. So, full strength, we are 45:29 going to multiply, and now you can see 45:30 it's the same thing as before, uh but it 45:32 darkens. And technically, you might see 45:34 here, if you kind of look, it actually 45:35 has kind of a hotspot that gets kind of 45:37 weaker radially as it goes outwards. 45:39 This of course makes sense because this 45:40 whole face does have the same surface 45:42 normal at every shading point. However, 45:44 the direction to the light basically 45:46 changes depending where we are, which 45:48 means that the dot product effectively 45:50 changes, so we get that for free. Now, 45:51 another thing you're going to notice is 45:52 if I keep this kind of in the same 45:54 direction, let's just do it upwards, 45:55 you're going to notice that yes, it has 45:57 the hotspot and everything, but the 45:58 lights the lighting basically doesn't 46:00 get weaker. I can bring this infinitely 46:01 high, and it's always going to be 46:03 basically exposed. What we know is as 46:05 this distance between the surface point 46:07 or the shading point and the light 46:08 grows, right? So, now it's bigger, it 46:10 should get dimmer, and that is 46:11 proportional to an inverse square. So, 46:13 you can think of the light or the 46:14 strength of the light to be a function 46:16 of one over the distance between the two 46:18 squared. What that basically means is if 46:20 we have a height here, it has some 46:22 strength, but if I now double this, so 46:23 now it's uh two times as tall, it's not 46:25 going to get half as weak, it's actually 46:26 going to get four times as weak cuz we 46:28 have that inverse square. This is 46:29 because light basically emits in 46:31 spheres, the surface area of which is a 46:32 function of a square, doesn't really 46:34 matter. But, what does matter is I care 46:35 about the distance between these. And 46:36 we've already actually calculated 46:38 distance, remember, we had the square 46:39 root of X squared plus Y squared and all 46:41 this, which is the way to do it, but now 46:43 we know what's going on, so I'm going to 46:44 give you a bit of a uh secret. In the 46:45 vector math all along, there is a 46:47 distance function that does this for 46:49 you. two vectors, it'll tell you the 46:50 distance. Sorry for not telling you. So, 46:51 our first input is the position. This is 46:54 uh what I care about, and our uh second 46:56 input is going to be this updated 46:57 position of the light, and this will 46:58 give us the distance. However, you're 47:00 going to see that we wrote this vector 47:01 in here, so we can't really bring it 47:03 over here, like we didn't uh outsource 47:04 it. Bit of an oversight, but if you 47:06 think about it, the distance between 47:08 these is the same as saying look at the 47:10 vector that points from one to another, 47:11 and then give me the magnitude. How long 47:13 is that vector? What that means is 47:15 instead of the distance function, which 47:16 totally works, I can take this vector 47:18 that is not normalized, it actually has 47:20 a length that isn't one necessarily, and 47:22 I now calculate the length of the 47:23 vector. So, these are kind of related 47:24 ideas. So, if I view this, what you're 47:26 going to see is as I bring the light, 47:27 it's going to get darker, and you know, 47:29 vice versa. But, this is a inverse 47:31 square relationship. In other words, it 47:32 should get dimmer as I go further away, 47:34 not the opposite. So, I'm going to take 47:36 the reciprocal. You can do that by 47:38 dividing one over. Either way, you're 47:39 going to see it's pretty bright here, 47:41 and as I move it away, it gets pretty 47:42 dim, but it does that in some way like 47:44 inverse linearly. So, we take a power of 47:47 two. And now, it's an inverse square, 47:49 and you're going to see the darkening. 47:50 This actually looks like what you're 47:51 kind of used to. This basically distance 47:53 function doesn't account for what's uh 47:55 faces are facing away from the light. 47:56 So, uh things can be exposed that aren't 47:58 supposed to be. As you might expect, all 48:00 I need is both of these pieces of 48:01 information, so I multiply them 48:02 together. And now, we don't only have 48:04 this nice uh strength of lighting, but 48:06 also kind of the uh faces that are 48:08 obscured. This is what we pipe into our 48:10 green mixer. And now, we have something 48:12 like this, and you might be thinking, 48:13 how do I make this light stronger? 48:15 Because if I increase the power or 48:16 decrease it, it actually doesn't do 48:18 anything because we made our own BSDF in 48:20 a way that doesn't actually look at that 48:21 data. So, if you think about it, all we 48:23 have to do is take this light intensity 48:24 or kind of this inverse uh distance, and 48:26 we take it, and we multiply it by some 48:28 number. If I multiply it by 10, it's 48:30 going to be 10 times as strong. Just 48:31 like before, if you want the actual 48:33 settings for this, we can take the power 48:35 and create a driver. So, now it's at a 48:37 value of 1,000. I'm going to paste this 48:39 into our multiplication. Of course, this 48:40 is going to be super bright cuz it's 48:41 taking values like 1,000, you have to 48:43 get pretty far away to see what's going 48:44 on. So, because we're wanting this to be 48:45 like somewhere between 1 and 10, you can 48:47 take this driver, and let's go to edit 48:49 mode. You can actually do a division or 48:51 an expression by saying, let's do it 48:53 scripted expression. So, right now it's 48:54 taking the energy of the light, which it 48:56 knows what that is. I'm going to take it 48:57 and divide it by let's say 100. So, it's 48:59 still dependent on this, right? You can 49:00 see it's updating, but um it's not as 49:02 intense. Another way to think about this 49:04 is let's actually make the power super 49:05 low. Let's set it equal to one, and then 49:07 for this edit driver, we no longer need 49:09 this expression, it can just be the 49:10 energy. And this is kind of a more 49:12 sensical way to do it anyhow because our 49:13 numbers are going to be small anyway. 49:15 So, let's try it on a sphere. Let's make 49:17 that a bit bigger. Now, you can see we 49:18 have a bit of a smoother situation, and 49:20 you're actually seeing this the setting 49:22 where you can see every single face, and 49:23 that is of course because our normals 49:25 that are, you know, used to calculate 49:27 the uh dot product, uh those are kind of 49:28 quantized where we can shade smooth, and 49:30 now they're no longer quantized. In the 49:32 worst-case scenario, this unlit section 49:34 is basically black, no light is reaching 49:35 it, which of course isn't realistic when 49:37 we have this gray world. It would be 49:39 realistic if I kind of darkened the 49:40 background, right? Like this is what 49:42 you'd see in something like space. Let 49:43 me actually save this bad boy. It is 49:45 what you would see in space, but our 49:46 background is gray, so there should be 49:47 some ambient light. So, this is the 49:49 concept when you have diffuse, you have 49:51 directional lighting, which of course we 49:52 have right here, but you should also 49:53 have ambient lighting. We just added 49:55 this. And of course, if I'm saying that 49:57 we are to add a bit, we can do that. So, 49:59 I guess what we can do is after the stop 50:00 product, I don't know if this is 50:01 precise, but after it we multiply and 50:03 all this, I can just add a tiny bit of a 50:05 boost. So, you can see in here we're 50:06 increasing our ambient lighting. Let's 50:08 set that to point two. And now, yes, um 50:10 there's a bit of a background thing, but 50:11 we can actually, you know, I don't know. 50:13 We we we can see what's going on here. 50:14 Uh we do have all of this and it does 50:16 seem to have lighting and everything 50:17 we'd expect, but it's still a little 50:19 hard to see the form of this. It 50:20 actually looks like a flat uh circle in 50:23 this case, which might be accurate with 50:24 the lighting, but I just want to see a 50:25 bit of a rim light. And remember, we did 50:27 make a function that will exactly tell 50:29 us the outline or what we call the 50:31 Fresnel. This time, because I don't want 50:32 to do it again with the camera and all 50:33 this, remember how we did it with the 50:34 dot product? We basically swap this out 50:36 for a camera and then use inverse 50:37 square. Uh we are now free, I'm 50:39 claiming, to use the Fresnel node, okay? 50:40 We've done it already, it's good enough. 50:42 And I'm going to have this like Fresnel 50:43 outline be brighter on the edges, which 50:46 it is. So, you can either do this 50:47 additive or as a multiplication. I am 50:50 going to do it I'm going to do it as a 50:51 addition. So, we have our ambient light 50:53 and then further, I'm going to add this 50:55 Fresnel. Uh which might be a bit 50:56 intense, we can uh change it later, but 50:57 now we can actually see the form of this 50:59 quite well. You might argue that this uh 51:01 Fresnel should also be a function of the 51:02 dot product. Let me think about this. If 51:04 we wanted it that, what we can do is 51:05 instead of adding after the fact, we can 51:07 take this Fresnel and add before the dot 51:09 product, so it's affected by it. I don't 51:10 know how I feel about that. It 51:12 definitely adds something, but for my 51:13 purposes, I'm not saying this is 51:14 physically accurate, but for my 51:15 purposes, I'm going to add it after. And 51:17 we can play with something called the 51:18 index of refraction. Basically, you can 51:20 think of it as the harshness of uh the 51:22 situation. There's a technical 51:23 definition of how much it bends light 51:24 and all this. And I'm going to make it a 51:26 little less intense by multiplying our 51:27 Fresnel by a tiny number like, let's 51:29 say, point three. Now, this technically 51:31 isn't enough logic to do every kind of 51:33 scenario. So, if I have a torus, I shade 51:35 it smooth. Uh you can totally tell it's 51:36 a torus. However, however, you're going 51:38 to notice something weird. If I put this 51:39 light over here, indeed this section is 51:41 in shadow cuz it's facing away from the 51:43 light, but let me do this kind of 51:44 perfectly, the perfect scenario, so this 51:46 uh section is lit. You're going to 51:47 notice that this section is also lit, 51:49 which if you think about it doesn't 51:50 really make sense because the light ray 51:52 shoots in this direction, it then hits 51:53 the shading point and makes it a certain 51:55 brightness. Uh but then, if this ray was 51:57 to continue and hit this shading point, 51:58 uh it's already been obstructed, right? 52:00 We have no information that says you've 52:02 already intersected uh the mesh 52:03 essentially. And this would this idea is 52:06 actually the idea of shadows, like light 52:08 intersecting surfaces, not just kind of 52:09 like this dot product looking thing, but 52:11 actual shadows. Uh we're going to need 52:13 to have kind of this collision system 52:14 that tells us did we intersect 52:16 something? Now, this is kind of hard to 52:18 do by itself because we don't have 52:19 information about intersection, right? I 52:21 can start at a point and go towards the 52:23 direction of the light, but how would I 52:24 even know if uh I even intersected at 52:26 any point? Well, it turns out there's 52:27 many ways to do this with SDF and 52:29 something called the ray marching, but 52:31 for the purposes of this uh tutorial, 52:32 we're not going to do it because the way 52:34 I know how to do it is with a ray 52:35 marching or ray tracing and that takes a 52:37 while to implement. So, for this plane, 52:38 I'm going to shift click control L link 52:40 materials. Now, both of these kind of 52:42 have the situation and our scene uh can 52:44 be properly lit, whereas we go further 52:45 away, it kind of gets darker. I think 52:47 our ambient light is definitely a bit 52:48 strong, so let me make it like five 52:50 times weaker. You could also make it a 52:51 function of this kind of like inverse 52:53 square with a strength and so you can 52:54 multiply like this. And now the Fresnel 52:56 is definitely there. You can tell that 52:57 there's a difference, but it does kind 52:59 of go away at a certain point. I think 53:00 this is more physically accurate in my 53:02 mind. So, we created a BSDF beautiful. 53:05 It isn't, you know, fully featured like 53:06 the diffuse BSDF is, right? Diffuse BSDF 53:09 has shadows or works with shadows. It 53:10 also has roughness and it has something 53:12 called normals, which we'll talk about. 53:14 By default, it actually uses the normal 53:16 coordinates that you're used to, so if I 53:17 type in coordinates, use normal, it 53:18 doesn't change anything, but the moment 53:20 I modify these uh coordinates like I 53:22 shift it like this, you can see it does 53:23 the lighting stuff. So, if we were to 53:24 affect the normals, it affects kind of 53:25 the uh shading. And this isn't 53:26 surprising because if we take our normal 53:28 coordinates here in our custom setup and 53:30 let's do a vector addition, we also kind 53:32 of get this weird effect. So, it turns 53:33 out if we modify our normals just a 53:36 little, we can get kind of cool shading 53:38 effects, but we'll go back to that. Now, 53:39 instead of this green, let's do 53:41 something more interesting. Remember we 53:42 talked about uh different kinds of 53:43 textures like a noise texture, for 53:45 example. Uh that has this uh 53:46 three-dimensionality to it, so let's 53:47 actually use object coordinates to 53:49 prevent stretching. Uh if you're seeing 53:50 that this is denser here than on the 53:52 grid, the density of the noise, we 53:54 talked about how this doesn't like 53:55 necessarily change with a scaling, so 53:57 control A apply scale and now it works. 53:59 I'm going to connect this instead of our 54:02 green and now we view it and we have 54:04 still our lighting set up, but with a 54:05 bit of noise. And let's, you know, let's 54:07 also make it green, so just like before, 54:09 I can multiply these two together, uh 54:11 set it to multiplication. I don't think 54:12 the order matters. And now we have a 54:14 green with a tiny bit of grunge that I 54:16 can make more detailed, maybe a bit 54:18 rougher. And now we have the impression 54:19 of maybe grass or something like that. 54:22 Uh before we wrap up here, let's 54:23 actually use some of this logic we made 54:26 to uh create a nice little BSDF node 54:28 dress. So, what I want control over is I 54:29 want to keep the normals over here. I 54:31 want to keep the color stuff over here, 54:33 I guess, so we can choose the color. And 54:35 lastly, we like our ambient lighting, 54:37 where we can uh choose that with a 54:38 single number uh with a value. That's 54:40 kind of the overall brightness of the 54:41 scene. This is also something I want to 54:42 control and everything else, yeah, the 54:44 rest we can throw into a group. So, 54:45 select all, control G, and now we've 54:47 reduced our whole setup to basically 54:49 three inputs. We can uh totally name 54:51 these, so hit N for the panel. Our uh 54:53 vector thing is really the normal. Our A 54:55 is basically the color. And then this, 54:57 you can think of as ambient light. This 54:59 outputs, not technically, but we'll call 55:01 it a BSDF. So, if at any point I was to 55:03 change the color, it does that. If I 55:05 change the ambient light, it does that. 55:07 And if I modify the normals, it will uh 55:10 modify the normals. I'm going to let's 55:11 just use No, no, no, let's keep it like 55:13 this. I'm just going to pack this into a 55:14 little section for our color. Take this, 55:16 shift P for panel, I think it stands 55:18 for, and connect that to the color. 55:20 Okay, I think we'll call it a wrap here. 55:22 I definitely think that's good enough 55:23 for this part. I'm uh happy with this. 55:25 By the way, little tip to wrap up here, 55:27 if you want different colors or whatever 55:29 for different objects, it turns out that 55:30 even with a single material, right? So, 55:32 I don't need to duplicate this material 55:33 and for this one make it red and all of 55:35 this. Uh it turns out with a single 55:36 material, it knows which object is which 55:38 by adding a maybe the geometry node has 55:41 this. So, remember we use geometry node 55:43 for the uh position here. Oh, by the 55:44 way, I got to make sure I didn't 55:45 duplicate this. So, now this should show 55:47 everywhere. Uh we have the position, but 55:48 it also has other things like the 55:49 normal, the tangent, but what we care 55:51 about is there's something called random 55:53 per island. Little hard to tell, but 55:54 you're going to see this one's gray, 55:56 whereas this one is white. And it turns 55:57 out that each island, so I'm just going 55:59 to kind of duplicate this here. Uh each 56:00 island, each uh separate piece of 56:02 geometry, it generates a random number 56:04 between zero and one uh to distinguish 56:06 them. Another way to do this, if you 56:07 don't want the uh island situation, 56:09 which doesn't necessarily work with 56:10 duplicating the same object cuz it 56:11 basically has the same island, there's 56:12 also a node called object info. Whereas 56:14 this gives us a per shading point thing 56:16 for different objects, object info just 56:18 cares about the objects themselves. So, 56:19 if I look at location, I can have one 56:21 object moving and it's the same for the 56:22 entire object. I can extract data like 56:24 the objects, not object and then index, 56:27 but I guess we'll just use random. And 56:28 this also gives us a random number, but 56:29 now it works with uh this, which is 56:31 actually preferable for us. And if I 56:32 want to generate different colors with 56:34 this, so now we're introducing new 56:35 nodes. We could either I mean, we could 56:37 just do something like combine XYZ, 56:39 where this is kind of the strength of 56:41 the red, so you can see these have 56:42 different amounts of red, but if I want 56:43 to actually randomize the color here, uh 56:45 we talked about different kinds of 56:46 noises, right? Or different kinds of 56:48 textures. We have noise texture, we have 56:49 wave texture. Here's an interesting one. 56:51 There's something called white noise. 56:52 White noise kind of looks like this. I 56:54 think by default it uses generated 56:56 coordinates. You're actually not going 56:57 to be able uh to tell. What this does is 56:59 it's basically like TV static. Every 57:00 shading point, even ones infinitesimally 57:02 close to each other, get a random number 57:04 between zero and one, which means no 57:05 matter how much you zoom in, it's 57:06 basically going to look gray cuz it 57:08 averages out visually, but it turns out 57:10 that you can also do this with color, so 57:12 you can get chroma noise. And to me, 57:14 this is important because instead of 57:15 using generated coordinates, we can use 57:17 a single vector, right? Or a single 57:19 number uh to determine this. Let's 57:20 actually use a single number. And you're 57:21 going to see as I change this number, 57:22 it's going to give the same color to 57:24 everything because our white noise is 57:25 evaluating at a single vector, only at 57:28 3.07 3.07 3.07. And because that's the 57:31 same everywhere, it's going to give the 57:32 same random number everywhere instead of 57:34 using something like uh I don't know, 57:35 position coordinates, where you can see 57:36 each shading point is different. Meaning 57:38 that if I have different random values, 57:40 I can use this as the vector uh to give 57:42 different, you know, luminances, but 57:44 more importantly, different colors, 57:45 okay? And this is going to vary for 57:47 every single object. And by the way, if 57:49 you want to alter this, all you need to 57:50 do is just offset your random a bit. And 57:52 each one's going to generate a a 57:53 different color. So, let's say instead 57:55 of our green, I connect this over here, 57:57 I view our BSDF, and now we have, I 57:59 don't know, this looks more like a old 58:01 school uh Toy Story scene to me. And all 58:03 which, by the way, uh in the end menu, 58:05 you can give it a name, so I'm going to 58:06 call it color and that shows up. This is 58:08 our uh kind of color thing. By the way, 58:10 probably should have closed these 58:11 windows. I guess you can make this 58:12 four-dimensional, which gives it a W 58:13 slider. Think of it as a randomization 58:15 slider. It's a four-dimensional noise, 58:16 kind of complicated. More simply, we can 58:18 just vary our input uh right here to 58:20 change the color. And this works with 58:21 various objects if I give them the same 58:23 materials. I'm going to put a sphere 58:25 here, maybe I'll put a cube over here. 58:27 Make sure to control L link the 58:29 materials. And now we have, I mean, it's 58:31 way more complicated than what we had 58:32 before. I'll say that. Okay, so in this 58:34 part, we created lights itself. I guess 58:36 let's do another part. Are we going to 58:38 keep going? I don't know. So, I'm pretty 58:39 sure this is going to be the last part. 58:40 We'll see if I'm inspired to do more. 58:41 So, we have our like fake BSDF and I 58:43 want to take it one step further and add 58:45 kind of like custom normal mapping. I'll 58:47 tell you what that means right now. So, 58:48 we have our custom BSDF, which is 58:50 starting to look pretty similar to the 58:52 diffuse BSDF. So, here you can see the 58:53 diffuse BSDF, it looks a lot nicer cuz 58:55 there's shadows and all this. But what I 58:56 want to emphasize is for color, uh we 58:58 have color. Uh we actually have ambient 59:00 lighting, which diffuse BSDF doesn't, 59:02 and we have a normal socket, which I 59:04 want to uh modify. We don't have 59:05 roughness, but we'll live with it. What 59:06 is special about this normal socket, 59:08 which is actually identical uh to the 59:10 one we made, is it inspires the idea of 59:12 using custom normals, not just the ones 59:14 you get. So, let me show you what that 59:15 means. Imagine that we use the same 59:17 color as before, so we have our like 59:19 same setup over here. I'm going to make 59:20 the light a bit stronger cuz it's using 59:21 the actual power. You're going to notice 59:23 that this looks pretty plain, right? 59:24 Like it has all this noise, but it's as 59:26 if it's a perfectly flat surface, but 59:28 there's no like texture or like detail 59:30 or grunge in the actual normal mapping. 59:32 What I mean by this is if I look at the 59:33 normal coordinate, it's just blue 59:35 because it is facing directly upwards. 59:37 So Z component is one, X and Y are 59:38 suppressed. Well, what I can do here is 59:41 use this kind of like noise texture from 59:42 before to actually create uh more normal 59:45 coordinates. I'm just going to use a 59:45 node we haven't talked about yet. We're 59:47 actually going to make this ourselves. 59:48 It's called the bump node. It converts 59:50 like value information into normal 59:52 information. And I'm just going to 59:53 connect this into the normal socket. And 59:54 you can see all of the sudden, all we 59:56 did is we changed the normals. You can 59:57 see that there's actually like texture 59:58 here. Let me make this even stronger. 1:00:00 There's actual like kind of like 1:00:01 textural something to this, right? So 1:00:03 this is without. It's just kind of like 1:00:04 perfectly flat. And then this is with. 1:00:07 Now, while our plane is in reality 1:00:09 perfectly flat, which means from the 1:00:10 side view, it basically looks like this 1:00:12 and has a normal direction this way, 1:00:13 what I want to kind of fake is let's say 1:00:15 that this surface is a tiny bit rocky, 1:00:17 like kind of microscopically uh 1:00:19 detailed. The difference in this case is 1:00:21 our normals are no longer just straight 1:00:23 up. In fact, in this section it's 1:00:24 straight up, in this section it's 1:00:25 pointed a little this way, pointed a 1:00:27 little this way, going a bit up. And as 1:00:29 we remember, we're using the dot product 1:00:31 as compared to the direction of the 1:00:33 light to judge kind of the darkness or 1:00:35 shading of every single point, which is 1:00:37 going to look different if we modify 1:00:39 kind of the height or the normals rather 1:00:41 than just using this flat surface. In 1:00:42 other words, if I have a height map that 1:00:44 basically defines how rocky I want the 1:00:46 surface to be, we need a converter that 1:00:47 goes from height information to normal 1:00:49 information, again extracting these uh 1:00:51 vectors that aren't really there. Well, 1:00:53 the theory of this is actually quite 1:00:54 simple, right? If I'm at the peak of 1:00:56 this, in other words, it's kind of flat, 1:00:57 the way I know it's flat is what I'm 1:00:59 doing in my brain is I'm imagining this 1:01:00 tangent line that's just tangent, it's 1:01:02 right on the surface. And if I take this 1:01:04 tangent kind of direction and rotate it 1:01:06 by 90°, we have the normal. Similarly, 1:01:08 if I have a point that's on a bit of a 1:01:09 slant, I imagine this kind of tangent 1:01:11 line, I you know, have this vector, I 1:01:13 rotate it by 90°, and then I have this. 1:01:15 In other words, to extract the normal 1:01:17 vector in a case, the two-dimensional 1:01:18 case, all I need to know is basically 1:01:20 kind of this tangent line, which will 1:01:22 give us the normal. Now, in three 1:01:23 dimensions it gets a bit more 1:01:24 complicated, right? So instead of like, 1:01:26 you know, a two-dimensional rocky 1:01:27 surface, it's kind of So here I'm trying 1:01:28 to draw a three-dimensional hill. It 1:01:30 doesn't really translate, but here the 1:01:31 surface is three-dimensional. So instead 1:01:32 of a tangent line, we have tangent 1:01:34 planes that are facing different 1:01:35 directions, each with their own uh 1:01:37 normal vector, which means instead of 1:01:39 getting kind of like a simple slope of a 1:01:41 line, we kind of need the slope in a 1:01:43 sense of the surface, which actually 1:01:44 generalizes quite nicely. In the 1:01:46 two-dimensional case, the way I actually 1:01:48 calculate or approximate this tangent is 1:01:50 if I have this kind of like height map, 1:01:52 like I know what this hill is, I know 1:01:53 the slope of this tangent by looking at 1:01:55 rise over run. You might remember that. 1:01:57 So we have Y, that's the rise, divided 1:01:59 by X is equal to the uh slope. At least 1:02:02 this is a approximation, because what we 1:02:04 need to do is have this rise over run 1:02:06 sampled at tinier and tinier intervals 1:02:08 closer to our point, right? Because if 1:02:10 we have a point like this that exists 1:02:11 somewhere on the X axis, so we have an X 1:02:14 value right here, I'm going to sample a 1:02:15 bit to the left and maybe a bit to the 1:02:16 right. So I give a bit of a nudge on the 1:02:18 X axis. So let's say we're now 1:02:20 evaluating right here. We look at the 1:02:22 rise, the difference in the height 1:02:23 between these points, and how much we 1:02:25 traversed on the X. So you can think of 1:02:26 this as X plus a tiny infinitesimal kind 1:02:29 of like delta. So this will give a 1:02:30 pretty good approximation instead of 1:02:32 like, let's say we did a big shift in X. 1:02:34 So this is X plus like a big delta. In 1:02:36 that case, I'm like evaluating over 1:02:38 here, and then the rise over the run 1:02:41 kind of represents a very like different 1:02:42 slope. So too, in a three dimensions, we 1:02:44 have a bit more leeway, so I can go in 1:02:46 this direction, I can go in this 1:02:47 direction, there's a lot of options. All 1:02:49 I need to do is sample the X and the Y 1:02:51 direction and kind of combine them. So I 1:02:53 go a bit on the X axis, and then I 1:02:55 sample, and I look at that 1:02:56 two-dimensional slope, rise over run, 1:02:58 and then I also sample, let's say the 1:03:00 orthogonal like uh in a different 1:03:01 dimension. I then say combine these to 1:03:03 create the three-dimensional slope or 1:03:05 the tangent uh plane that then defines a 1:03:07 normal. In other words, instead of a 1:03:09 extra evaluation, I have to do an extra 1:03:10 two evaluations. So for this, I'm 1:03:12 actually going to take my noise texture 1:03:13 nodes and just put them over here for 1:03:14 now. We're We're going to use the 1:03:15 original, but uh for now I just want 1:03:17 like to illustrate this more simply. 1:03:18 This noise texture, you can think of as 1:03:20 a height map. And you're thinking, how 1:03:21 is that height? It's just kind of the 1:03:22 splotchy thing. Well, if I make this 1:03:24 higher contrast, you'll be able to see. 1:03:25 You can think of black areas as being on 1:03:27 the surface, and the more white it is, 1:03:29 so like a white point over here 1:03:30 represents something that's higher up. 1:03:31 In other words, if I have a rocky 1:03:33 surface like this, this section right 1:03:35 here is going to be black with a value 1:03:36 of zero, this section right here is 1:03:37 going to be 0.5, and as we go higher and 1:03:39 more white, it eventually maxes out at a 1:03:40 height of one. So if I want to sample 1:03:43 this at two different spots, or I guess, 1:03:44 yeah, one on the X and one on the Y plus 1:03:46 the original, so three spots, all I need 1:03:47 to do is I take my coordinate system and 1:03:49 say nudge it a little, right? So instead 1:03:51 of our default coordinate system, I can 1:03:53 add a tiny bit on the X, right? Like 1:03:55 0.2. And you can see what this 1:03:56 effectively does is it like moves our 1:03:58 height map, which makes sense cuz I want 1:03:59 to sample just a bit to the sides, so I 1:04:01 need to know what that is. So let's say 1:04:02 I shift this by 0.1. So this is without, 1:04:04 and this is with, just a bit of a nudge. 1:04:06 If I want to know the rise over the run, 1:04:08 we can figure out what the rise is by 1:04:10 evaluating again. So this is our 1:04:11 original, this is our shifted. The rise 1:04:13 is the difference between the heights, 1:04:15 right? Like how high up did we go? So I 1:04:16 subtract these, and then the run is how 1:04:18 much I nudged it. Remember, our slope is 1:04:21 the change of height over the change of 1:04:22 how much we nudged it. In this case, we 1:04:24 nudged it by 0.1. So literally take this 1:04:26 and divide it by 0.1. And the this piece 1:04:29 of color that you're seeing here uh 1:04:30 basically represents how much the 1:04:31 surface is changing on the X axis. 1:04:33 Instead of going like 0.1, for example, 1:04:35 I want to explicitly say uh what do we 1:04:36 go? Like 0.1, 0.2, 0.05, whatever it is, 1:04:39 we divide by this number. So I'm going 1:04:41 to divide by two. So now this is going 1:04:42 to be a bit more accurate. Divide by 1:04:43 two, a bit more accurate. And you really 1:04:45 want this to be tiny. So saying 0.0001, 1:04:48 uh which is what is actually uh written 1:04:49 here even though you can't see it, is 1:04:50 better than 0.1. You're going to see 1:04:52 these look pretty similar, um but one 1:04:53 kind of has more accurate data. So too, 1:04:56 can we do this nudge on the Y axis? So 1:04:58 all I'm going to do By the way, this 1:05:00 might be responsible for the change. 1:05:02 Make sure you're using object 1:05:03 coordinates. Um not necessarily because 1:05:04 they're object coordinates, but because 1:05:05 we used them here. So if you use 1:05:07 generated, use generated for both and 1:05:08 vice versa. Actually, this looks a lot 1:05:10 more sensible. Looks a lot more sharp. 1:05:11 You can almost imagine the surface. 1:05:13 Next, I'm going to do the exact same 1:05:14 thing. So I'm going to take my object 1:05:15 coordinates, I'm going to offset them by 1:05:17 basically the same thing. So I have a 1:05:18 custom vector, uh but this time instead 1:05:20 of nudging on the X, I'm going to take 1:05:22 the same number. I want to nudge by the 1:05:24 same amount, so that they're um in terms 1:05:25 of ratio kind of like equal to each 1:05:27 other. Anyway, it doesn't matter. I'm 1:05:28 going to take this number, and this time 1:05:30 shove it on the Y axis, okay? So instead 1:05:32 of X, we're doing Y, which means we 1:05:34 again have our original sample and our 1:05:36 shifted Y sample. You can barely tell 1:05:37 the difference cuz they're barely uh 1:05:38 different. I'm going to subtract the 1:05:40 two, so we are comparing them. And then, 1:05:42 did we do everything correct over here? 1:05:43 I believe so. And we need to divide by 1:05:45 this very tiny number to kind of 1:05:47 normalize this. And now you can see we 1:05:48 kind of have this rough direction. Let's 1:05:50 actually view it from the top uh in this 1:05:51 Y. So you can almost see it's in this 1:05:52 axis, and then X is the other. Like I 1:05:54 said, if you combine these 1:05:55 contributions, so this is basically a uh 1:05:57 a change of X in terms of slope, and 1:05:59 this is a change of Y. We combine these 1:06:02 into a single vector. This is the X 1:06:03 component, this is the Y component to 1:06:05 get something that's kind of like a 1:06:06 normal map. Uh really, this is the 1:06:08 difference of what we had. Uh to get the 1:06:10 actual normals, you need to add the 1:06:12 original contribution. So it's pointing 1:06:14 up, and then we added a bit of 1:06:15 variation. So you set Z equal to one, 1:06:17 and this is the actual normal map. Let's 1:06:19 see if it's identical to the way um bump 1:06:21 node does it. So I plug this into the 1:06:22 height. You can see it looks basically 1:06:24 the same. If you do not want to add the 1:06:26 Z component, which by the way is 1:06:27 different depending on which way we 1:06:29 angle the surface, instead it would make 1:06:31 sense to use this difference and then 1:06:32 add our original uh normal. So we have 1:06:35 what it was before plus uh our 1:06:37 contribution, which updates depending on 1:06:39 the uh direction. Now, technically, we 1:06:41 do live in a three-dimensional world, 1:06:43 which means yes, we can kind of 1:06:45 approximate this uh normal using X and Y 1:06:47 and all of this, but that isn't accurate 1:06:49 in any case where like this isn't like 1:06:51 perfectly flat and we're doing a height, 1:06:53 right? If we have a sphere, some tangent 1:06:55 planes are pointing upwards, but some of 1:06:56 them are pointing downwards. So you kind 1:06:59 of have to account for all of these. So 1:07:00 there is a sense in which you also want 1:07:02 to do another evaluation. So now we're 1:07:04 doing four total evaluations, and we do 1:07:06 need to copy this noise texture each 1:07:07 time or whatever height map you had, you 1:07:09 can't just put it all in one vector. The 1:07:10 cost of doing a normal is just doing 1:07:11 extra evaluations. So this is going to 1:07:13 be our object coordinates, you know the 1:07:14 drill, plus an offset of this number on 1:07:16 the Z axis. I subtract our new 1:07:19 contribution minus the original. I take 1:07:22 this bad boy and I divide it by our tiny 1:07:25 number, which in the case of it pointing 1:07:27 straight up, you can expect is just 1:07:28 going to be I guess noise texture is 1:07:30 three-dimensional in a sense. So you 1:07:31 wouldn't really see this in like a 1:07:32 two-dimensional image, uh but in this 1:07:34 case there is a change of like Z 1:07:35 component, which uh will update 1:07:37 depending on the direction of the 1:07:38 surface. By the way, you can argue that 1:07:40 we want to like make sure these are all 1:07:41 in the same order. So for example, we do 1:07:43 a shift in X minus the original. In this 1:07:45 case, we want to do a shift in Y, which 1:07:47 is this one, so we need to flip it, 1:07:48 minus the original. And then in this 1:07:49 case, we have a shift of Z minus the 1:07:51 original. Basically, as long as you're 1:07:52 consistent, you'll be pretty good, plus 1:07:54 or minus a minus sign. So we have our X 1:07:55 component, we have our Y component, and 1:07:57 now we have our Z component that gives 1:07:59 us the total offset that again we can 1:08:01 just add our uh normal uh to. So make 1:08:04 sure we have our normal coordinates, and 1:08:06 this is basically uh what is going on 1:08:08 here. Uh this whole nonsense, we want to 1:08:11 use for the dot product, basically. So 1:08:13 because this is a monstrosity, we can 1:08:16 take this and actually put it in a 1:08:17 single node. Of course, we might change 1:08:19 the height map later, but whatever. So 1:08:21 I'm going to combine all of this 1:08:23 nonsense, all of it except for maybe 1:08:25 this like 0.001 that I guess I do want 1:08:27 to like uh change later. So I'm going to 1:08:29 take all of this plus this plus the 1:08:31 coordinates, control G, and all of that 1:08:32 nonsense reduces to something that is 1:08:35 actually manageable. The reason that 1:08:36 node, by the way, is called bump is we 1:08:37 are bumping, we are shifting the Sorry, 1:08:39 we are shifting the surface. And we 1:08:41 don't actually need our original normal 1:08:42 coordinates cuz we added them inside of 1:08:44 here. Okay, what is the point of all 1:08:45 this? The point is now we have our BSDF, 1:08:48 I told you we'd go back to this. It's 1:08:50 using normal normal coordinates, but 1:08:52 here I have a different one where I can 1:08:53 plug it in. And now you can tell it's a 1:08:55 bit intense, but it's actually 1:08:56 responding in a way that looks, you 1:08:58 know, accurate, right? So now the 1:08:59 question is, how do we take this and 1:09:01 make it less intense? Well, we always 1:09:02 want to have our original normal 1:09:04 coordinates plus our calculation, but 1:09:06 our calculation of adding in these fake 1:09:08 normals can be not as intense, less 1:09:10 contribution. In other words, you take 1:09:11 this and you multiply it by tiny number. 1:09:13 You can think of it as just multiplying 1:09:14 it, again you can use a value here by 1:09:16 0.1. So here you can see instead of one, 1:09:19 we use 0.1, and it's much softer. 1:09:20 Another way to do this, by the way, 1:09:21 that's more intuitive is you use scale. 1:09:23 This is identical to multiplying by 1:09:24 value, except this time the value is 1:09:26 explicitly here, and we now have the 1:09:28 luxury of making that a parameter, where 1:09:29 the first one is the distance of 1:09:31 sampling, and the second one is the 1:09:33 strength of the uh normals. Now, we 1:09:34 didn't do all this work just to have a 1:09:36 plane, right? We want to have the uh 1:09:37 three-dimensional case. So, let's bring 1:09:39 back our objects here. So, remember, we 1:09:41 had the setup where it picks the color 1:09:42 randomly, and because they're all using 1:09:44 the same material, they all have that 1:09:45 noise texture, and you can see, it's 1:09:47 looking much more realistic than before, 1:09:49 right? It's capturing like more uh 1:09:51 information in a sense. And this is kind 1:09:53 of how like rendering works or how BSDFs 1:09:55 work. We just made our own, and the name 1:09:57 of the game is basically swapping out 1:09:58 our height map, which right now we're 1:10:00 using this uh noise texture for whatever 1:10:02 it is we want, okay? Um because there 1:10:04 actually is a bump node that the 1:10:06 difference between these two, but we 1:10:07 want the real bump node. Actually, the 1:10:09 one we made is the real one, but uh the 1:10:10 reason we want this uh bump node is 1:10:12 instead of like putting in this noise 1:10:14 texture or whatever height map four 1:10:15 times, if I want to change it, I'd need 1:10:16 to change it four times. This bump uh 1:10:18 thing basically does that for us, okay? 1:10:20 So, I'm going to keep this off to the 1:10:21 side. It is useful, but I'm going to use 1:10:23 the standard now that we know how to 1:10:24 make it. like we've earned it. So, now I 1:10:26 plug this into the normal coordinates, 1:10:28 and right now it's just using the 1:10:29 normal. By default, it looks like this 1:10:30 isn't connected to anything, but it is 1:10:32 just using the normal coordinates. 1:10:33 Instead, I'm going to use this like 1:10:35 noise texture, for example, as the 1:10:37 height. It's literally called height cuz 1:10:38 it's a height map, and now we have 1:10:39 basically the same thing where we 1:10:40 control the strength. We we just made 1:10:41 this ourselves. Uh it happens. And I 1:10:43 guess in this case uh distance is kind 1:10:45 of inversely proportional to what we 1:10:46 did. Either way, we now have a bump, 1:10:48 which by the way, you can invert, so 1:10:49 instead of popping outwards, uh it goes 1:10:51 inwards, kind of like reversing the 1:10:52 vector for the dot product. Doesn't 1:10:54 really matter. By the way, I should 1:10:55 mention, ideally, we do like vectors 1:10:57 normalized to get them to work uh the 1:10:59 way we want to in terms of the uh dot 1:11:01 product. So, uh you do want to make 1:11:02 sure, I guess, at the end of this, you 1:11:03 have your normal plus the contribution, 1:11:04 just take it and normalize it, so it has 1:11:06 a magnitude of one. This is important 1:11:07 because our BSDF calculates a dot 1:11:10 product and doesn't do the normalization 1:11:12 uh in there. So, we'll do it in the 1:11:13 other one. Either way, we now have the 1:11:15 luxury of swapping our height map. So, 1:11:17 let's do something different, like a 1:11:18 wave texture that looks like this. You 1:11:20 plug in either the color or the factor. 1:11:21 I believe if you do the color, it will 1:11:22 just take the red or X component. I'm 1:11:24 going to plug this into the height. It 1:11:25 looks pretty much what you expect it to 1:11:26 look like, and now you can see, it's as 1:11:28 if we actually modeled the ridges into 1:11:30 our surface. That that is normal 1:11:31 mapping, which is kind of like the big 1:11:33 piece of uh kind of like realistic 1:11:35 rendering here. And in a way, you can 1:11:36 think of roughness or how shiny a 1:11:38 surface is, not technically, but kind of 1:11:40 as kind of like inversely proportional 1:11:42 uh to our strength. So, as the strength 1:11:44 is big, not very rough, or sorry, 1:11:45 extremely rough. Um like there's not 1:11:48 much reflectivity is what I meant. And 1:11:49 then as this goes down, you can think of 1:11:50 this is kind of more reflective. 1:11:52 Technically, when you have reflections, 1:11:53 you have a light ray hitting the 1:11:54 surface, it looks at the normal, and 1:11:56 then goes this way, and then goes this 1:11:57 way, and sees what it's actually uh 1:11:59 reflecting. So, like a mirror, it would 1:12:01 have a bit of red, a bit of whatever. Uh 1:12:02 we're not doing that in the same way 1:12:04 that we are not doing shadows. Here you 1:12:06 have your diffuse BSDF. If you get rid 1:12:08 of the shadows, there's actually not 1:12:09 much of a difference. So, for our 1:12:10 objects invisibility, I can actually 1:12:12 disable shadows, so that we get, you 1:12:14 know, pretty much what we have set up 1:12:16 over here. So, I'm getting rid of 1:12:17 shadows, and now you can see the diffuse 1:12:19 BSDF in action compared to our custom 1:12:21 BSDF, where I have to lower the uh 1:12:23 strength of this, which looks pretty 1:12:24 similar in my opinion. Again, the 1:12:26 difference is it has like reflectivity 1:12:28 kind of with the roughness, and it has 1:12:30 global illumination, where, you know, 1:12:31 this point in some sense affects this 1:12:33 point cuz light can bounce and do all 1:12:34 kinds of things. But that is our custom 1:12:36 BSDF. Okay, I decided we're doing 1:12:38 another one. This is the final part of 1:12:39 the series cuz I think I've taken you 1:12:41 from zero to hero, right? There's more 1:12:42 with image textures and all this, but 1:12:43 this is kind of the basics of how things 1:12:45 work. In this part, I I mentioned 1:12:46 reflectivity and kind of light bounces 1:12:48 and all that. We're not going to do 1:12:49 light bounces, but I am going to kind of 1:12:51 do reflectivity for you guys. So, at the 1:12:53 moment, our environment, or we call it 1:12:55 the uh world, is basically gray, right? 1:12:57 There's not much to reflect. And by the 1:12:59 way, uh we can totally change this 1:13:00 either in the uh world parameters. Of 1:13:02 course, this isn't going to affect 1:13:03 anything because uh we want this to 1:13:05 proportionally affect our like ambient 1:13:07 light, but whatever. Uh it turns out 1:13:08 that you can do more than just pick a 1:13:09 color, right? You can change it for all 1:13:11 kinds of things. What you want to do is 1:13:12 in the world settings, you can pick your 1:13:14 own uh HDRI, which is basically an image 1:13:16 that represents the spherical uh 1:13:18 environment. If you have Node Wrangler, 1:13:19 you can hit Ctrl T. It adds all these 1:13:21 nodes. We basically know what these do. 1:13:22 We know what generated coordinates are. 1:13:23 We know what a texture is. Although, 1:13:25 this time it's not noise or wave, we 1:13:26 just pick our own image from our 1:13:27 computer. And the mapping, we didn't 1:13:29 really talk about, but you can think of 1:13:30 this as kind of offsetting. So, for 1:13:32 location, uh which is really the only 1:13:34 one we talked about, it's the same as 1:13:35 just offsetting with a uh vector. So, uh 1:13:37 with a environment texture, what I can 1:13:38 do is I can load a HDRI that I 1:13:40 downloaded from the uh internet. This is 1:13:42 our environment. Again, it's not going 1:13:44 to be reflected, whether we have Eevee 1:13:45 or Cycles, like it's just not going to 1:13:47 show up. But for now, I don't want to 1:13:49 see that. We might turn it on later. I 1:13:50 want this to kind of affect what we see, 1:13:53 you know, over here. So, back into 1:13:55 object land, where we're dealing with 1:13:56 our material, we somehow need somehow 1:13:59 need So, like let's say we have a 1:14:00 reflection over here. We're viewing from 1:14:02 the camera, so we are looking in from 1:14:03 the camera. We have a ray from the 1:14:05 camera going here. It's going to reflect 1:14:06 kind of like infinitely into the 1:14:08 distance until it hits kind of like our 1:14:10 environment, our scene, and that tells 1:14:11 us what it should be reflecting. Well, 1:14:13 we need a way to kind of reflect things, 1:14:15 and we can totally do this ourselves, 1:14:16 right? We know how to calculate a vector 1:14:18 coming from the camera. We actually did 1:14:19 this ourselves, and it turns out there 1:14:20 actually is a node for this. It's called 1:14:22 uh incoming cuz this is the vector that 1:14:23 is incoming. It is coming towards the uh 1:14:25 camera. It changes based on uh 1:14:26 perspective. And you can totally reflect 1:14:29 by saying take the incoming vector, look 1:14:31 at the surface normal, and just kind of 1:14:32 reflect off that direction, like 1:14:33 bouncing off a wall. Uh we can totally 1:14:35 do that. Um I guess let me just show you 1:14:37 how you would do that. So, we have our 1:14:38 incoming, we have our normal, and just 1:14:39 like we had cool operations with our dot 1:14:41 product, so too can we take vector math 1:14:43 and look at our options, and we have 1:14:44 reflect, refract, face forwards. We care 1:14:46 about reflecting. So, if this is what I 1:14:48 think it is, we take the incoming 1:14:49 vector. We're looking at the surface and 1:14:51 then reflecting it off of the direction 1:14:53 of the surface, so off of the normal. 1:14:55 This is going to give us a coordinate 1:14:56 system that looks like this. Main 1:14:57 takeaway is that it is view dependent, 1:14:59 right? In this case, it's going to be 1:15:01 one color because we are, you know, 1:15:02 reflecting off of something that has a 1:15:04 consistent normal. Whereas, if I was to 1:15:06 kind of bevel this, you're going to see 1:15:07 it kind of changes, okay? In a way, 1:15:09 we've created what you can consider to 1:15:11 be a reflection coordinate system. It 1:15:12 just samples off into the distance. As 1:15:14 always, there is a pre-established thing 1:15:16 for this cuz this turns out to be quite 1:15:17 useful. So, if I look at my not normal, 1:15:19 not UV, not object, but reflection 1:15:21 coordinates, they're not necessarily 1:15:23 going to be exactly the same. You can 1:15:24 see it does kind of a similar thing. So, 1:15:26 this is our uh custom reflection. If 1:15:28 anything, it looks the same minus the uh 1:15:29 black here. I think the main difference 1:15:31 here is technically, so we know how to 1:15:33 make a ray going from the camera to the 1:15:34 surface. I said that there's something 1:15:35 called incoming. I think what it is 1:15:37 technically is it is that, but it is the 1:15:39 inverse, right? So, if I have a uh 1:15:40 camera here casting a ray onto the 1:15:42 surface, uh this is what we want, right? 1:15:44 This is what we want incoming to be, but 1:15:46 I think incoming technically does the 1:15:47 opposite. I think it goes from the 1:15:48 surface to the camera, which means I can 1:15:50 just multiply this by -1, and it will 1:15:51 give us what we want. So, I take 1:15:53 incoming, I vector math, you can either 1:15:54 multiply 1:15:55 or like we talked about, scale by -1. 1:15:57 Now, it's going to be, you know, the 1:15:58 opposite. I use this over here, and now, 1:16:01 is this the same thing? It might still 1:16:02 be a bit different. Let's see. Our 1:16:03 reflection coordinates versus or theirs 1:16:05 versus ours. Nope, it's the exact same 1:16:07 thing. So, uh we've calculated a 1:16:08 reflection coordinate system, and it 1:16:09 makes sense how we did that. At least it 1:16:11 makes sense to me. Hopefully, it makes 1:16:12 sense to you. Once we have this 1:16:13 coordinate system, we can say that the 1:16:15 world, our environment, had any kind of 1:16:17 texture that it's now sampling. So, kind 1:16:19 of an obvious example that we get for 1:16:20 free, like we talked about, is this uh 1:16:22 noise texture. So, unlike before, and 1:16:24 let's make this kind of higher contrast 1:16:25 over here, so we can see what we're 1:16:26 doing. Okay, yeah, that looks pretty 1:16:28 good. Uh unlike before, where it sticks 1:16:29 onto the surface, because this is view 1:16:31 dependent with the incoming, you can see 1:16:32 that this gives, you know, a reflection. 1:16:34 Definitely for this ground plane, it 1:16:35 looks like a mirror. Uh you could swap 1:16:37 this with anything. So, let's do a uh 1:16:39 wave texture. So, now we have waves 1:16:41 reflecting. It turns out that we can 1:16:43 actually, just like we put in our world 1:16:45 a uh custom environment texture. So, 1:16:46 this is called a environment texture. 1:16:48 It's not a normal texture. There is a 1:16:49 difference. Uh we could load one of 1:16:50 those in. So, with our reflection 1:16:52 coordinates, let's load in not an image 1:16:54 texture, but an environment texture. 1:16:56 You're going to notice the differences, 1:16:57 other than the name, of course. Uh the 1:16:58 most important thing is this thing that 1:17:00 says equirectangular. Uh this is 1:17:02 important. Let me show you because if 1:17:03 you look at an HDRI, it's a 360° image, 1:17:06 but it has to be represented in a 1:17:07 rectangle, and this weird distorted 1:17:09 thing where this section, Pac-Man, 1:17:11 teleports over here. Uh this is just 1:17:12 called equirectangular cuz it's a 1:17:14 rectangle, and it preserves area or 1:17:15 something, I'm not sure. This has 1:17:17 equirectangular, whereas this only has 1:17:18 other kinds of uh projections. So, in 1:17:20 the environment texture, I'm going to 1:17:21 choose this burn to warehouse, which uh 1:17:23 by default kind of gives this weird kind 1:17:25 of thing. Either way, this is now what 1:17:26 we want. We want the reflection 1:17:27 coordinate system, and now you can 1:17:28 imagine, right? Especially with this 1:17:30 sphere, this like a chrome ball, you can 1:17:31 see the environment reflected. We can 1:17:33 actually enable our uh scene again, and 1:17:35 this should give us what we need. So, in 1:17:37 the ceiling, we have wood planks plus 1:17:38 this uh sideways wood plank, and you can 1:17:40 see that reflected. There's a reason the 1:17:41 word is reflected. Uh we need it to be 1:17:43 in our kind of BSDF here, okay? So, we 1:17:46 know our BSDF has color that we then 1:17:48 like shade with our dot product. I want 1:17:50 to also include a hit of color from our 1:17:52 reflection. So, first of all, we have 1:17:55 our color that I want to contribute. So, 1:17:57 we have our mixing and everything. So, 1:17:58 our mixing just darkens it uh before our 1:18:00 multiplication. Before I do that, I want 1:18:01 to mix it with another color. I want to 1:18:04 tint it by a uh custom color. So, I'm 1:18:06 going to put a input over here. Instead 1:18:07 of color, I'm going to call this or or 1:18:09 maybe like world color or something like 1:18:11 that, and I can move that above, so that 1:18:12 the color and the world color are 1:18:13 together. I want to mix this with our uh 1:18:16 thing over here. So, not just the color 1:18:17 or not just the world, but the world 1:18:19 we're using our reflection coordinates. 1:18:20 So, I'm going to put this right here. 1:18:21 Let's view it. It's going to give us 1:18:22 what we had before, but now with some 1:18:24 reflectivity and still with our 1:18:26 darkness. So, it kind of just works, 1:18:28 right? Like now we have something much 1:18:29 more dynamic. Let me get rid of this. 1:18:30 But this isn't technically, probably, 1:18:33 the best way to do this. The reason for 1:18:34 it is it's mixing the uh color and the 1:18:37 reflection equally everywhere. It's the 1:18:38 same on the edge, it's the same here. Uh 1:18:40 and in reality, that's not how it works. 1:18:42 If you think about it, imagine you have, 1:18:44 here's another analogy, imagine you have 1:18:45 a puddle of water, okay? Or maybe a 1:18:47 lake. If I am the viewer, and I view the 1:18:49 lake from over here, so I'm kind of 1:18:50 standing on the beach, uh I'm looking at 1:18:52 the lake, and that is going to reflect 1:18:53 this way or like upwards, and it's going 1:18:55 to show maybe the sky or maybe some 1:18:56 trees in the distance. However, uh when 1:18:58 I look at it from the top, you might 1:19:00 notice that when you're on a boat and 1:19:01 you look directly down at the water, you 1:19:03 don't really see much of a reflection. 1:19:04 If anything, you kind of see into the 1:19:06 water. You see the depth as it goes 1:19:07 down, down, down, getting darker into 1:19:09 the surface. Whereas, if you look from a 1:19:11 different angle, you see the 1:19:11 reflectivity. So, it turns out that the 1:19:13 surface normal versus our incoming 1:19:15 vector, take a dot product, gives us, in 1:19:18 some sense, maybe an inverse of how 1:19:19 reflective it should be, right? So, dot 1:19:21 products are used everywhere, wherever 1:19:22 we have a surface normal. Remember, did 1:19:24 we end up using a Fresnel? Uh we have a 1:19:26 Fresnel that basically gives us exactly 1:19:27 that, right? So, in reality, if we look 1:19:29 directly into the surface, like this 1:19:31 part of the sphere, it's going to be 1:19:32 blackish, which means that it's not 1:19:33 going to have much reflectivity. But, on 1:19:35 the edges, we get much more reflection. 1:19:36 And we can control that. Beautiful. And 1:19:39 by the way, I should mention, now that 1:19:40 we have our custom normal coordinates, 1:19:42 you're going to notice that Fresnel, 1:19:43 just like anything else with a uh normal 1:19:45 socket, by default uses these 1:19:46 coordinates. You can add our fake 1:19:48 coordinate system, and in the Fresnel, 1:19:49 you're going to see it adds that fake 1:19:50 detail, as if it was contributing to the 1:19:52 view angle. So, that's just a thing. Uh 1:19:53 but, because we have our Fresnel, we can 1:19:55 uh mix in our reflectivity that we can 1:19:58 kind of say how intense is it uh also by 1:20:00 this Fresnel. So, I'm going to do that 1:20:01 here. It's going to be quite subtle, but 1:20:02 there is some reflection going on here. 1:20:04 There is some reflection. And you want 1:20:05 to make sure that the world color is in 1:20:07 the uh bottom socket. So, let's see. 1:20:09 This is without. It's just color, and 1:20:11 then this is with. And let's see if this 1:20:12 does what we want. So, if we look at 1:20:13 this kind of like a hardwood floor from 1:20:15 this angle, quite reflective, but as I 1:20:16 look up, no longer reflective. And we 1:20:18 can see that in the hue. We can have 1:20:19 this IOR, which remember is affecting 1:20:22 the uh reflectivity. It's also affecting 1:20:24 this kind of like addition we did over 1:20:26 here. Or was it a multiplication? I 1:20:27 don't know. We just added like a bit of 1:20:28 something. Uh we can make that a 1:20:30 parameter. So, now IOR is here. Uh IOR 1:20:32 is different for different surfaces. It 1:20:33 turns out water has 1.33, whereas glass 1:20:36 has 1.5, whereas other things much 1:20:38 higher. You can think of these as 1:20:39 metals. I'm going to keep that at 1.5. 1:20:41 We have our nice reflections with our 1:20:43 nice lighting. Kind of the last thing, 1:20:45 kind of the last piece of the recipe I 1:20:46 think we're missing is if you look at 1:20:47 the reflections in a diffuse BSDF, let's 1:20:50 actually Let's do a reflective one. What 1:20:52 what what's it called? Like a glossy? 1:20:53 So, glossy BSDF gives us the 1:20:55 reflections. You're going to see that it 1:20:56 kind of scatters or diffuses the 1:20:57 reflection, unless I set the roughness 1:20:59 to zero, where we have what we had 1:21:00 before, right? Nearly identical, except 1:21:02 for the uh reflections of the objects 1:21:04 themselves. But, the main thing we are 1:21:06 missing is kind of this uh roughness. 1:21:08 How much does the thing scatter? Well, 1:21:09 here, I'm going to show you a trick. So, 1:21:11 you can think of scattering of light, of 1:21:13 a texture, of whatever, as basically 1:21:14 blurring it approximately. I don't know 1:21:16 if that's true, but you can think of it 1:21:17 as blurring. Um so, if we can make a 1:21:19 blurring node, we can kind of fake 1:21:20 roughness here. So, I want you to 1:21:21 imagine, not an image texture, I want 1:21:23 you to imagine we have a very kind of 1:21:25 like very visual texture, like a Voronoi 1:21:26 texture, which has all these cells. If I 1:21:28 want to blur this, it should kind of 1:21:30 look like fuzzy uh on the edges, and in 1:21:32 fact, fuzzy everywhere. Now, the 1:21:33 question is, what is blurring? Well, if 1:21:35 I take this point on the edge, 1:21:37 ultimately should be kind of the average 1:21:38 of everything around it. The way that 1:21:39 works is for this point, it samples a 1:21:41 bit over here. And then it samples a bit 1:21:42 over here. And actually, it samples in 1:21:44 every direction. And for each one, it 1:21:46 says, "Oh, this is orange. This is 1:21:47 orange. This is cream." And for every 1:21:48 sample, it adds and uh averages them out 1:21:51 together. But, our blurring is more 1:21:52 effective the more kind of directions 1:21:54 that we sample. So, somehow, I want to 1:21:55 sample this in every direction and blur 1:21:57 it and all of this. There is a node that 1:21:59 we actually already talked about that 1:22:01 does this. What is it? Well, remember 1:22:02 that our, you know, whatever texture 1:22:04 usually by default uses generated 1:22:06 coordinates. What I want to do is we 1:22:07 already know how to sample, right? We 1:22:09 just shifted a bit to the side like we 1:22:10 did with our normals. I want to shift 1:22:11 it, but kind of like everywhere. Of 1:22:13 course, that's not possible because we 1:22:14 can only pick a single direction at a 1:22:16 time. But, if you look at this like 1:22:17 cluster of points that kind of 1:22:19 represents this one, every single point 1:22:20 inside of here kind of picks a different 1:22:22 one, and they're so close together, it 1:22:23 will look about right. Well, how do we 1:22:25 like pick random directions? How do we 1:22:26 know how to do that? Well, remember 1:22:27 Remember when we were randomizing, we 1:22:29 used this thing called the white noise 1:22:30 texture, which if we use generated 1:22:31 coordinates, gives us a number between 1:22:33 zero and one on every single point, no 1:22:34 matter how close together. But, so too 1:22:36 can we pick a random color, a 1:22:37 three-dimensional X, Y, and Z vector, 1:22:39 which we can think of as a direction. 1:22:41 This is a way to sample random 1:22:43 directions, right? It gives us random 1:22:44 things. So, if I sample this way, like I 1:22:46 do a bit of an offset, you're going to 1:22:47 see that it looks kind of ridiculous, 1:22:49 right? Because we have our generated 1:22:50 coordinates, and then I'm adding this 1:22:52 massive blur. Well, I can take this 1:22:53 contribution and basically make it less 1:22:56 intense the same way that we made our 1:22:57 normal custom normal contribution less 1:22:59 intense. So, as I scale this down, let 1:23:01 me set it to zero. We have this, and 1:23:02 then as I shift it, you're going to see 1:23:04 it blurs. But, you are going to see a 1:23:05 bit of an issue. You're going to see 1:23:05 yes, it blurs, but it also kind of goes 1:23:07 off to the side as if it's kind of being 1:23:09 uh pushed diagonally. So, it's being 1:23:10 pushed downwards and diagonally. Why is 1:23:12 that? It should be picking random 1:23:13 directions. On average, it should not 1:23:15 really move. If you think about it, if 1:23:16 we're picking a random direction, right? 1:23:18 That's not actually that. It's really 1:23:19 just a number between zero and one, but 1:23:21 on the X, Y, and Z. Like we have three 1:23:23 random number generators that go between 1:23:25 zero and one. That means that on 1:23:27 average, if you average them all out, 1:23:28 it's going to pick a number basically 1:23:30 that's 0.5 on average. This means that 1:23:32 on average, we are shifting our 1:23:34 coordinates by 0.5 on X, Y, and Z uh 1:23:37 multiplied by our scale. Of course, we 1:23:38 don't want this sampling from zero to 1:23:40 one, but instead, we want it centered. 1:23:41 So, you can think of it as instead of 1:23:42 zero to one, we can map range to -1 to 1:23:45 1. Did you know you can take a map 1:23:46 range, and instead of a float, you can 1:23:48 use a vector, which is basically the 1:23:49 same thing as a color. You take a input 1:23:51 interval, and you send it to an output 1:23:52 interval. So, it's going from zero to 1:23:54 one on X, Y, and Z, and we want to map 1:23:55 it to -1 to 1, just so it's centered. 1:23:58 And what you're going to see now is it's 1:23:59 blur or it's not blurred, and as we 1:24:00 increase it, it blurs quite intensely, 1:24:02 actually. But, uh it does it in a way 1:24:04 that's uniform and stays uh centered. 1:24:06 Now, the reason this blurs so incredibly 1:24:07 fast is the directions these are 1:24:09 sampling uh isn't just like this way, 1:24:11 but it's this way with a giant 1:24:12 magnitude, right? Trying to kind of 1:24:14 solve that by bringing down the scale, 1:24:15 but some of these can be pretty big. If 1:24:16 you just care about the direction, we 1:24:18 know we can normalize. So, this is 1:24:19 without. This is with. Going to be kind 1:24:20 of subtle, but it will uh kind of work 1:24:22 here. What was the point of this? Uh we 1:24:23 wanted it for uh blurring our reflection 1:24:25 uh texture. Uh so, for now, I'm just 1:24:27 going to add a empty thing. The reason 1:24:28 I'm doing that is I want to highlight 1:24:29 Ctrl G. You need to have an output for 1:24:31 this to actually, you know, come out 1:24:32 with this uh vector. Uh what I mean by 1:24:34 this is if I didn't have this here and I 1:24:35 Ctrl G, uh there would be no output. So, 1:24:37 Ctrl G, I'm going to call this like 1:24:39 blurring in some sense. And we don't 1:24:41 just want to blur necessarily the 1:24:42 generated coordinates, although often we 1:24:44 do. Uh I want to blur a custom 1:24:46 coordinate system. Okay? So, this is 1:24:47 going to be blurred coordinates, and 1:24:50 this is going to be our coordinates. So, 1:24:51 we input coordinates, we output uh 1:24:53 blurred coordinates. So, ultimately, we 1:24:56 have our reflection image. I'm going to 1:24:57 pass this uh reflected coordinate system 1:24:59 through our blurring. And is it perfect? 1:25:02 Uh but, we've uh essentially blurred, 1:25:04 and you can see these bokeh balls. Uh 1:25:05 let's add a parameter, of course, for 1:25:07 how strong this is. And instead of doing 1:25:08 this directly, where the numbers have to 1:25:10 be very small, uh let's divide it by 1:25:12 Let's see. If we have 0.03, let's divide 1:25:14 it by 10, for example, which means 0.03 1:25:17 effectively becomes 0.3. As we increase 1:25:20 it, it gets very diffuse. And as we 1:25:21 decrease it, it becomes quite sharp. And 1:25:23 you can use this blurring for all kinds 1:25:24 of things that we did before. But, 1:25:25 either way I view this now, we indeed 1:25:27 have our reflections, which I might want 1:25:29 to see more of or less of, but I can 1:25:32 also control effectively the uh 1:25:34 roughness of those reflections. So, 1:25:35 zero, one. It ain't perfect, but it's an 1:25:37 honest living. Um I guess kind of like a 1:25:39 final thing uh to note is we have 1:25:40 control over where the reflection 1:25:42 appears, how rough it is. Uh but, we 1:25:43 don't have like a general strength 1:25:45 slider, I guess. So, we are like using 1:25:47 the Fresnel here. But, what if I want to 1:25:49 take this Fresnel and kind of modify it? 1:25:50 Well, we can either modify it with a 1:25:52 multiplication. So, as I increase this, 1:25:55 it kind of gets more metallic. As I 1:25:56 decrease this, it kind of gets more 1:25:57 diffuse. Or you can think of it as a 1:25:59 addition, where it's uniform. I think 1:26:00 obviously multiplication makes more 1:26:02 sense. So, I'm going to call this 1:26:04 reflectivity, right? So, now our 1:26:06 reflectivity is at zero. We can increase 1:26:08 it, and now it's more reflective. If I 1:26:09 wanted it to be a nice metal, I'd pick 1:26:11 kind of like a darkish color with um 1:26:13 high reflectivity and maybe a low uh 1:26:16 blurring. And yeah, let us do just a bit 1:26:19 of experimenting. We don't need to have 1:26:20 this HDRI. We could have picked this 1:26:21 outdoor forest one that I actually want 1:26:23 to see. And let's actually also bring 1:26:25 down our reflectivity, so we can see all 1:26:27 of this. Maybe 0.5. Maybe let's bring 1:26:29 down the IOR and bring up the strength 1:26:31 of our normal coordinates. I mean, you 1:26:33 know, you can't get better than that. 1:26:34 So, what have we done in this tutorial 1:26:36 series? Just to recap, we can go 1:26:37 further, maybe. I don't think I want to 1:26:39 at the moment. We went from basically 1:26:41 going uh with a single value node. We 1:26:43 just talked about what is a number. What 1:26:45 does it do? How does it represent a uh 1:26:47 kind of surface output? We then talked 1:26:48 about vectors, colors, how to like 1:26:49 multiply, how to use dot product, and 1:26:51 use all these methodologies uh to 1:26:52 basically recreate the diffuse BSDF um 1:26:55 but fully custom with the drivers that 1:26:57 let us kind of pick our lighting uh 1:26:59 nicely. So, we created essentially what 1:27:01 we call a BSDF. Really, this is just a 1:27:03 shader that responds to lighting and 1:27:05 reflections and all this kind of stuff. 1:27:06 So, I hope you enjoyed this tutorial 1:27:08 series. Where do you want to take this 1:27:10 from here, you might be wondering. 1:27:11 Probably the next step is going over 1:27:13 other BSDFs and talking about 1:27:15 transparency and all this. But, what we 1:27:17 were building to is kind of recreating 1:27:18 the granddaddy of a BSDFs, which is the 1:27:21 principled, right? It has this metallic, 1:27:22 which you can think of as our 1:27:24 reflectivity, kind of makes it more 1:27:25 metallic. It has roughness, which you 1:27:27 can think of as our blurring. Um it has 1:27:30 IOR, color. We're kind of building 1:27:32 towards that. It has normals. But, what 1:27:33 it's missing is it doesn't have 1:27:34 emission. We don't have transmission. 1:27:36 So, hopefully you learned something. 1:27:37 That is what I know for kind of like a 1:27:39 level one. If you want a level two, 1:27:40 maybe beg, and maybe I will do it. The 1:27:42 man puts on his hood in mystery as he 1:27:44 creates the best tutorial of all time.