Fractals. But With ONLY NODES (Blender Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] so I hope you brought your helmet today because today I'm gonna make your brain explode I don't want you to get chunks everywhere we should have this nice and contained I'm gonna be showing you how to achieve stupid we just absurdly complex results using very few notes specifically I'm gonna be showing you how to make fractals without looping without coding just your good old procedural nodes that we have control over and I guess you know with with this intro I have you hooked in I guess we should just begin so specifically I want to make this kind of fractal which has a name I think it's called sierpinski gasket but it might be a different thing and I might have just maybe it's called the carpet I've no idea but it's this fractal that kind of takes the center square being this black square cuts it away and then it kind of repeats that for these eight neighbors and then again and again and again and you can see how this is like self-similar repeats and we can zoom in here and there's no coding done for this in fact what I did is I just created a single node group being this one copy did a bunch of times and that's what makes the fractal so if I get rid of all this you can see really what the node group does is it just punches away the middle square if you were to divide this into a three by three grid it punches that out and then I just kind of duplicate it and every time it adds another iteration so no we can't control the number of iterations without putting in all these extra node groups but it's not like you need that many like at this point I can't even see the additional detail unless I zoom in and one more thing before we begin and I show you how to do this since this is gonna be a bit mathematically intense if you're not used to it I just want to make sure that you're ready I don't want to you you know you got to be prepared okay so it's not that it's just punching away the center there's actually more going on here and these nodes here aren't doing any help they're not helping you see it so I'm just gonna get rid of them what's actually happening is I took my texture coordinates punched out the middle one just like I said but then also copied it for the other tiles which is what makes it self referential so generated coordinates looks like this we just made eight of those and punched out the middle one so that when you duplicate it it just makes more generated coordinates and then we did a bit of a trick so I guess I should show you how to do this and by the way I don't think I and by the way we get more control than you might think we gonna change where these squares are to kind of get a three-dimensional effect we can change the size of these squares to make a different kinds of fractals in fact you can make an infinite number of fractals and if people want I'll show you the three-dimensional version in a sequel but you have to beg I'm not doing it for free I will do it for free but you gotta beg what's let me just talk about how to do this without any more build up so default blender thing I say use 2.8 2 or above since we're gonna be using the compare node although if you're like a 2.7 hermit I don't care you you figure it out yourself 2.8 2 and above so cube get rid of it we're gonna be using a plane we're just gonna be putting the fractal on the surface of the plane shading workspace were ready halfway done we've already done all our modeling the rest of it is just nodes so the tutorial is now wrapping up we're gonna go to the top view works with Eevee works with cycles I recommend Divi because it's faster and it's nice that it works with Eevee so new material we're gonna call this for active for some mysterious reason and then we're just gonna be using our texture coordinates so right now we have a plane and we're viewing our texture coordinates which are you know it's a three dimensional thing it also has a z-axis but we don't really care about that because it's infinitesimally thin infinitely thin maybe that's what I'm trying to say so you could also use a UV coordinates if you want that just eliminate the Z components and in fact I think that's what I'm gonna do we'll save generated for the three dimensional version I'm gonna take this I'm going to separate it by X Y Z what does this do it takes a 3 dimensional quantity again you've YZ kind of two-dimensional kazi's constraint to zero but we can extract the x axis or the X component and the y component why does X go from black to white because this is the x axis left to right it's 0 all the way here and then it progresses to 1 as we get to the right and then same thing with Y but up to down so the origin is in the bottom left corner okay so the idea first of all is we want to take our UV coordinates and like I said punch out the middle because that's what's happening with each iteration of the fractal so how do we kind of isolate the middle well since we have to point a 2 it's actually very easy we just use a math node we set it to compare so right now we're just dealing with the X component information and then we're do the same thing for the Y component so we want to compare and what this does again if you don't know is it takes the first socket and the second socket compares these two values who are saying X compare this 2.5 with a threshold of the epsilon and let me just increase this so you can see what happens it kind of makes this a bar or stripe that goes vertically but expands horizontally what's happening here is we're saying blender make this white wherever X is within point 2 2 distance of 0.5 if we make this threshold this distance this radius bigger it's going to include more of it if we make it close to zero it's going to include less of it if we change this point 5 we're comparing to a different number which looks like sliding that's the idea so we don't want it to just be any thickness we want it to be exactly 1/3 of the plane and you might be thinking ok how do we know what it's supposed to be well think about it like this if you have a coordinate system where 0 0 is right here and you progress to 1 this way in this way right now we only care about the x-axis 1/3 goes from 0 up to 0.33 333 or 1/3 right that's what we want and this this section goes from 1/3 to 2/3 so how do we isolate it well we say we're comparing to 0.5 in the middle that's what we're comparing to so we want to take point 5 and then since we want this to be you know kind of like 1/3 across or I guess yeah 1/3 across what we do is we subtract 1/3 ok so now what we're doing is we're saying 0.5 0.5 in the middle and we want the overall thickness of this thing from left to right to be a third meaning you just subtract 1/3 this is what happens I think this is the same as the 1/6 so there you go now you've isolated this area and to do it with the y-axis what do you do you just duplicate it you just kind of reuse the ideas from before right so why plug this in here and now we're taking Y comparing it to 0.5 now we're treating this as kind of like a vertical thing so kind of like rotated by 90 degrees same thickness so 1/2 how do we kind of combine these ideas together to make it the square well we want to say blunder where's this stripe going horizontally and vertically at the same time because that would kind of give us the intersection this is the same thing as multiplication whereas addition gives us an or some multiplication gives us the square addition gives us the cross so we want multiplication so so far what have we done we've isolated the centerpiece that were eventually gonna cut out okay so how do we cut this out now that we've isolated this area well what we need to do is we need to take our UV coordinates the stuff and subtract kind of this mask that we made pretty obvious how do we do it I'm gonna use vector math because now we're not dealing with one dimensional quantities with these math nodes but in fact three dimensional vector quantities that's why these have purple sockets and again it is two dimensional UV coordinates forget about it we're gonna take UV coordinates and your first instinct might be okay we want to subtract away whatever's white and black kind of do nothing so you say okay subtract and then you plug this in and you say okay I've done it I've kind of cut out the middle chunk like what's the issue the the the issue with this is and the reason that doesn't work is this black area isn't actually set to zero it looks like it is but it's not in fact what's happening here is we have negative values which makes sense since we subtracted some positive quantity it's gonna go to the negative region at least somewhere and the fact is blender shows all this is black anything below zero is black so we don't actually know if it's negative or just zero everywhere but believe me it is so instead what we're gonna do to fix this issue and actually get rid of it and set everything in the middle to zero is instead of subtraction we are going to use multiplication so M for multiply which kind of gives us the inverse right now but the idea the idea is here right now this is the black region it's multiplying that area by zero so the vector in those areas actually gets multiplied to zero instead of going negative just gets sent immediately to zero now of course we want the inverse of this since we want I so at the middle not do whatever is happening here so to take the inverse you could either use a invert note which I wouldn't recommend because that's lame instead just use more math notes set it to subtract one minus the quantity inverts it right boom-boom-boom so you can see the inversion the reason this works is we're saying 1 minus of this area is 1 minus 1 is zero so that's why it's black and then this area you have black so you have 1 minus nothing zero so it's 1 it inverts it that's where you have to know okay cool so you might think we're done with this node group and we can start copying it since we I don't know why I'm trying to save since we punched out the middle but in fact this is not the case this is what happens when we try to do it so I'm going to group it ctrl G and what I did before is I just duplicated it over and over and you can see it's not actually doing anything it's as if we're adding no information every time we add an iteration the reason this is happening is because it's just mapping this image that we've made this kind of UV texture almost with the thing in the middle being black we're taking this and just mapping it on the UV coordinates again and again and again which isn't gonna change anything it's being mapped onto itself right what we need to do is we need to make tiles so we need to make our 3x3 grid with this thing in the middle gone so instead of feeding UV coordinates instead of feeding UV coordinates into this multiplication which is what gets rid of the center we need to feed in tiles so how do we make tiles that's a good question here's a super simple trick to do it vector math and I'm just gonna view what we're doing here what I'm gonna do is right now we have our UV coordinates not manipulated at all because we're adding zero and you could add some quantity to actually manipulate it right now we just have our UV coordinates we're gonna set this to scale which is gonna convey it's gonna multiply an XY and Z but you can think of it as a strength or intensity so you can kind of see what's happening here we're gonna use a strength of three so now instead of going from 0 to 1 on X on X&Y it's going from 0 to 3 0 to 3 because we've scaled it by 3 so now it's going three times further and now what we want to do is since we're going from 0 to 3 we just want to say blunder we have to come too much going on in the square instead of going from 0 to 3 go from 0 to 1 0 to 1 0 to 1 so we're breaking it up into 3 components to do this add another vector math node set this one to fraction to fraction and what's the view it and it does exactly that now we have our three by three grid again this works because here we have a zero to three UV square kind of and what fraction does is it takes the numbers and gets rid of all the integers in the beginning so one point three two becomes point three two pi 3.14159 dove gets mapped to zero to one that's the idea okay cool so we have this and then we want to do this multiplication so we feed it in here and now we have our tile you know our 3x3 tile UV grid - the thing in the center and again there's no reason you can't use generated coordinates which would be useful if you're doing the 3 dimensional version it's just that this has a Z component I think right now it's averaged to 0.5 so if you wanted to you could set this to subtract subtract not that but Z subtracts 0.25 I don't know subtract something and it will get rid of that blue whatever we don't care about that right now okay so now we have a completed node group which I need is set to UV again we have a completed node group we can take all this I'm highlighting it I'm hitting ctrl G for group or you could right-click a group somewhere yeah group ctrl G and now we have our UV coordinates feeding into this thing that takes UV coordinates and turns it into this well if we take this and duplicate of what's gonna happen well it's gonna generate this and now let's think about why this is the case because this might seem like black magic think about what this node group does what does it do takes in UV coordinates it looks like this and outputs this well this thing has UV coordinates in each of these tiles so it's going to perform the same thing just in a localized area again so it's almost as if we're just taking this and shrinking it down eight different times but not in the middle so it's just gonna do the same thing and now we still have you these stuff it's just smaller so we do it whoops not duplicate the plane although that would be an interesting way to do it but we do it again and again and again okay so now we've actually kind of created this thing there's like one technicality we want this to be black and white white wherever there isn't a square missing black where there is that square missing the trick I use for this it's not exact but it's a fairly good is what you do is you add in vector math at the very end of you in this case five iterations you could do more iterations and what I'm gonna do is I'm going to set this to length which is going to take our vectors an output B if you were to take a vector and compute the magnitude the length of it this is what it does so a zero zero zero vector you know the zero vector outputs a length of zero one zero zero vector puts a length of 1 and then etc etc it uses the Pythagorean theorem is the idea but the nice thing about length is this length is only going to be 0 exactly where there's these black squares because those are the 0 0 0 vectors so that has a length of 0 and at the very very corner of each of these squares so the origin of each of these is technically 0 0 0 but because we don't care about that one infinitesimal points it's as if the entire thing is white that's why this trick kind of works ok so we view this and you can see that right now it's almost doing what we want but it's again it's just outputting the length so you can see again in these corners we have something that's getting really really really close to 0 what I'm gonna do is I'm gonna use a math node and I'm gonna say take this and show me where it's greater than 0 so technically it's gonna give us white everywhere except for the very very corners and these squares that we eliminate it so it looks it looks perfect there's no reason this doesn't work and I guess one thing you already saw is we can make this a different number so it's kind of making circles here and this is a interesting effect in its own right but you know whatever I'm not going to be using this so again what did we do we use the UV trick again and again and again so now we have a very dense UV grid we said give me the length of this and we said tell me where that length is bigger than 0 which very very precisely approximates approximates what we need and at this point we can just pick the number of iterations so 1 2 3 4 etc okay so you might think this is pretty interesting we didn't really need to make that many nodes to give us something that really looks like a fractal even though it's not it has a limited number of iterations what can we do with this well you can render this but you can actually control much more because these node groups aren't just duplicates but they're instances of each other so you can see next to each of these node groups you see the number 5 if I add another should give us 6 and this is saying there's 6 instances being like it's more than duplicate if we manipulate one and manipulates the other they're carbon copies so since these are exactly the same I can change instructions in the first one and it will change instructions and all the others what kinds of instructions would we want to change well maybe this compare stuff right so we could change whatever this is it drifts it on the x-axis this drifts it on the y-axis again if we were to unlink this hit this so now this is independent from these five which are now duplicate so this is independent this is only going to affect the first iteration being the first Square and it doesn't affect anything else right so we've kind of isolated it if we were to do this again on like step three so now this is the one that's different from the others this is only going to move like the third largest square so it looks like this so you can just isolate component by component but that's not what's interesting the the thing that makes fractals interesting is that they are self-similar meaning the fractal itself exists within itself just smaller it's self referential right so we want to have all these linked to each other so I'm gonna keep all these what they're sixes or sevens or whatever it computes really fast because we're not actually doing that much math I'm gonna go into one of these instances and you could do any one of these because they're all duplicates of each other carbon copies and what I'm gonna do is instead of just manipulating one of these values or every we could do this one for the thickness of the square is I'm gonna use a value node to control two at the same time now you don't you could do them independently independently from each other which gives you rectangles rectangles instead of squares but I do like keeping at a square so I'm gonna use one value node here and this is just gonna be our kind of transition diagonally because it's controlling you x and Y and then I'm gonna make another value node and this is gonna be for our epsilon the thickness or the distance or the threshold or whatever you want to call it and this needs to be smaller than I think just point five to actually see something yeah there you go and you can see this thing kind of generating and then as these squares get really small and goes to white so we get this cool transition but really every step along the way is a fractal and its own right that we can transition so if I do this just right I can't remember what the numbers are supposed to be but that like the Legend of Zelda triangle thing we can almost generate that so you can kind of see how this looks the same just kind of turned a bit something like this now you can kind of see the Triforce it's kind of a wanted out version but you know it works and we can make it look a bit different so these fractals kind of exist within each other and in some sense a lot of these fractals that you know are all the same fractal but yeah we can do all this kind of stuff it looks three-dimensional whatever like I said you can make these independent from each other you don't need to have like x and y do the exact same thing if you don't want to and in fact you can generate many more fractals if you don't add that constraint but uh yeah there you go I think I taught you how to make fractals pretty easily and you could fix the number of iterations and I think I already said all this stuff we've reached the end of the show I hope you enjoyed this tutorial if you did actually before I say what I'm about to say if you want the three-dimensional version so volume metrics fractals using the same idea but a bit modified let me know I might make it I might not you know you gotta really convince me but if you enjoyed this free tutorial on youtube the best way to support this channel and get bonus content and keep me making those free tutorials is via patreon patreon not only lets you be a patron and donate to this channel directly but it gives you benefits you get behind-the-scenes content you get exclusive tutorials discord access trying to remember private not private exclusive blend files or project files sometimes I upload those depending on the thing sometimes I upload fragments of videos sometimes I upload them early but you can find out about that on the patreon I appreciate anybody who is willing to do that it really does help me obviously but you do get some stuff in return so you can think of it as a transaction up - either way I hope you enjoyed this free tutorial that fractals I'm the best in the procedural game nobody can
Info
Channel: Default Cube
Views: 25,863
Rating: undefined out of 5
Keywords: blender, tutorial, fractal, procedural, nodes, material, 2.83, 2.9, 3d, cg, vfx, cgi, animation, animated, texture coordinates, advanced, menger sponge
Id: ZV38FriNoYc
Channel Id: undefined
Length: 19min 17sec (1157 seconds)
Published: Sat Jun 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.