Blender Tutorial: Noise Advection with Geometry Nodes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome this is manuel with antagoma and i'm here with a new geometry nodes tutorial for blender today i want to talk about noise election i want to elect some points through a noise field that is a quite handy operation because it allows for visualizing a noise field and on the other hand it creates some beautiful graphics so it is handy in this regard too the big problem with coming up with an algorithm for this is the geometry nodes unfortunately does not support loops yet and it does not support simulation as you will see in a second we will need some sort of looping to move our points through the noise field but we will find a workaround although it might be a little cumbersome but now let's dive into blender and follow me implementing noise advection inside of geometry nodes so to start let's get rid of the camera we won't need it for now and the light we can add them in later and split the view to create a geometry nodes viewport and let's select this cube it really doesn't matter which geometry to choose we will overwrite the geometry anyways and let's create a new geometry nodes tree let me get rid of the end panel and here we have the group input and the output first let's cut this connection making the geometry disappear now we want to start with a line and i want to use a curved line because a curved line allows me to later on define how many points the line is composed of so let's start with this curved line if we connect it here you see we get a line in the viewport and now let's create a resample curve node and this node allows us to specify how many points are used for this curve so now we have 10 points we want to move these points through a noise field and that means we need a noise field first so let's create a noise texture this creates a noise field and it outputs either just a float value or a vector in form of a color so what we could do now is we could just lay down a set position node set position and if we connect it here we can now move the points around using this offset as you can see and if we just connect this color to this offset we are effectively moving the points using the vectors from the noise field so now every point samples a vector at the position where it is in the noise field and then this vector is used to move the points but we have some problems here first all the points are moved to the first quadrant and that is because this noise texture spits out values between 0 and 1 only because it is colors so first we have to transform these values to be centered around the origin and to do this let's use a map range node so let's lay down a map range node but before we continue let's switch this over to vector because we are intending to remap vectors connect the color here and now let's remap the ranges from 0 to 1 to -1 to 1. now we are centering the value range around the origin if we are using these values you can see that we now centered the deformation effect around the origin but still this is not what we are after at the moment i am transforming every point with a vector at the location where the point started what i want to do instead is i want to start with the very first point and then travel through the noise field so the very first point should stay at zero then we want to read the value of the vector at this location and move the next point to this location then we want to sample the position here and move the second point to this location and so on and so forth moving the point of the curve through the noise field but that means we have to accumulate the vectors so the first point samples the first vector and then the second point is moved to this location and all the other points too and then they are moved from this location to the next location and so on and so forth so this approach does not get us anywhere so let's cut this connection instead we want to move them successively first we want to put all the points just at the origin to start so let's go into this curved line and move all the points to zero we are still having 10 points but they are all crammed into the origin and now we want to sample the first vector position for all the points at this location but we only want to set them to all the points but the very first one so we have to use this selection of the set position node to tell the set position node to only set the values for all the points but the very first one we can use a compare node so let's lay down a compare and we want to compare integers because we want to compare indices for this i need a index node spitting out the indices of the points and i connect it here and i can tell this node to only output true if the index of the point that is currently processed is greater than zero and that is true for all the points but the very first one so now if i connect this here and connect now my vector from the noise texture to the offset you see that all the points are moved a little bit but the very first one now from here we can sample the next noise vector and then move all the points further through the noise field to do this because we do not have loops unfortunately we have to replicate this set position setup by hand so let's select these two nodes and duplicate them so after the first set position let's create a second set position like so and we want to again move the points around but this time we want to move all the points but point zero and one so the first two points should stay in place or the others should move to the next location so let's put in one here all the points greater than one are now moved now before we continue with this process because we have to add more and more of this set position nodes for all the points that we have on the curve let's first change the settings on our texture because the noise texture at the moment has a scale of five and that means we have a lot of detail in here let's go down to one with a scale and maybe we want the opportunity to move the noise field through space so let's create a vector mass node and set it to add and now let's create an explicit position node because if you do not connect anything to this vector port it implicitly connects a invisible position node to this vector we want to do this explicitly so let's create a position node and connect this to this add here and that allows us to specify a second vector to move this noise field around and you can see it is working now the first two points are moving through the noise field one at a time now to make the entire spline move through the noise field we can continue with this process now let's select both of these setups and duplicate them and let's connect them here after the first two set positions like so and now we have to connect all the vectors to the offsets like here and here and we have to connect all the indices to the a ports of the compares and we have to of course change the numbers because now with this third set position we want to set all the points but zero one and two so let's put two in here and with this one we put three in here and you can see now the points are successfully moving through the noise field that is what i am after the problem is that the vectors that this purlin noise outputs are not necessarily always of the same length so let's make them the same length because we want to decide the step size through the noise field so let's take all of this business and move it to the left and maybe let's introduce a new reroute to make it easier for us and now let's lay down another vector math and switch this to normalize normalize will make all the vectors that come out of this map range a length of 1. and now that we have vectors that have always a length of 1 we can just duplicate this node set it to multiply and decide how long the vectors will be by multiplying them it is convenient to create a value node value and connect it here such that we can set all the three components of the vector here with just one value and maybe we want to rename this node to make sure that we remember what this is for and call it step length because this value decides on how large a step will be now with this in place we can connect this here and with zero we don't get any result but if we increase this value you see you can decide how long a step through the texture field will be let's say 0.1 for now now we have a little spline here crawling through the vector field and to make it longer remember that we have 10 points we need to add another six iterations by hand until geometry nodes finally implements loops so let's copy all of these and move them over here and connect them in and don't forget to connect all the vectors that is why this reroute is handy i can temporarily move it over here and easily connect all these offsets like so and then we want to connect all the indices to the comparison nodes one two three and four like so and we want to dial in the numbers so we ended at three so this will be four and this will be five and this will be six like so and this will be a seven and now our spline got longer because we now take eight steps through the vector field let's move the vector field around to see what happens and you can see i can move the vector field around and the little curve just advect through the vector field so two points left because we have ten points with the curve so we have to create two more iterations by hand by duplicating these and now connect them in and connect everything up first the offsets here and here and then the indices i will temporarily move my index node down there for easy connection like so connect connect and put in the numbers 8 and 9. and now we have 10 points moving through our vector field so that is the basics of what we wanted to achieve we can now make the vector field move and the points on the spline are advected through the field that is great but what if we want to use more points in this case we would have to create even more iterations and that is cumbersome so why don't we just turn these 10 iterations into a group that can be reused easily that is what i wanted to do next but to do this i have to make sure that the numbers are not hard coded instead i want to come up with a logic for these numbers and this logic is not hard to create because it is just adding up one to each number so let's move these connections out of the way and instead of putting in these numbers by hand let's create a math note to do it like so let's assume we have a start value of zero and now we want to add to this value of zero one like so and put this here this gives one so this is now a one and now we can duplicate this add and just add one to the result of this and use it here and let's continue the process add another one and use it here and another one and use it here and now we can copy all four nodes move them over and again wire this into there and that into here and this into here like so this goes there and this goes there and one more so duplicate add one and put it here now we procedurally created all of these numbers now that we have that we can in theory create a group out of all of this business and reuse the group so to do this let's introduce another reroute just to make sure that we only get one input port on our group select everything and make sure to select these two reroutes too and then go to node and make group this puts all of this business into a group if we leave the group you'll see now we have a nice group node i will call this node ent for entegma underscore advac that is what the node does and then 10 to indicate that this is doing 10 advection steps and now we have a very clean setup again because we only have this one note if we go inside we have three automatically created input values geometry offset and a let's deal with this by bringing on the n panel and if we go to group we can rename the ports so offset is okay and a is just index so i will call it index and we will need the start value because at the moment the start value is zero that is nice but if i want to make more iterations i probably want to start at 10 or something so we need another port here so let's drag from this port to this value and let's call this newly created value start value or start index is probably even better start index and let's make it an integer like so now we can leave the node and we see we have this start index here and that means that we now in theory can create more points on the curve and then use many of these advect nodes in a row to make 10 advections at a time this way we can fake iterations although we don't have them inside of geometry nodes so first let's increase the count of the points of the line so let's go to the line and let's say we want to do 20 points so increase this to 20. and now that we have 20 nothing happens because we are only advecting 10 we can duplicate this note and connect it here then make sure that it has the noise field and the index and now we can go with the start index to 10. and now the entire spline advects through the noise field so if i change this value here to move the noise field around you can see we are happily advecting 20 points through the field so why don't we do even more because then the spline gets longer and that is a good thing to have so let's go to 50 points and let's just duplicate our iteration three more times like so effectively creating 50 iterations for 50 points connect everything up and before it will start to work we have to first give every node the noise field like so and every node needs the index index and index and now we want to start at 20 at 30 and at 40. and now we have a spline traveling through the noise field with 50 points so we faked an iteration of 50 points and you see if you move around the noise field the spline advects through the noise field so basically the spline goes through the noise field and follows the vectors of the vector field and shows you the path through the noise field to make it more even let's go down with the detail to zero like so and let's probably go down with the step length to 0.05 like so not too long and now you can see i can move my noise around and the line will adject through the noise field very nice but to actually see the noise field we cannot just use one spline we need more splines so why not creating a field of splines and advect all of them to create a field of splines it is probably a good idea to use a grid so instead of just using one blind let's first lay down a grid a grid and this grid should get 10 points and now let me use instancing to put this curve on all of the points so lay down an instance on points node and we want to use the grid points as targets and the curves as instances before i connect this up let's quickly look at what we got so far so if i connect this here you see that you see nothing and that is because remember the curved line creates all the points at the origin but if you temporarily create a one here you see we are getting a field of curves so back to zero the curves are still there it's just that they are all moved to zero and then before we want to use our advection with all of these splines we have to make sure to prepare them accordingly first after the instance on points the curves are instances and the points of instances cannot be altered so let's put down a realized instance node creating geometry out of the instances by the way you can watch this process if you go to the spreadsheet here you see we have a hundred instances at the moment and as soon as i introduce this real-life instance node i don't have any instances anymore instead i get real splines with points control points many control points 5000 okay now we have a lot of points but the problem is that the indices now are all over the place they are just counting that means we have indices with very high numbers but our setup relies on indices between 0 and 50. so we have to make sure that our indices are between 0 and 50. so let's introduce a new math operation to turn our indices between 0 and 50. and this mass operation you guessed it is called modulo modulo gives you the remainder of a division so if we divide the index number by 50 but then just keep the remainder we will effectively get indices that go from 0 to 49 and then again back to zero and that is exactly what we want for advection so let's put down a math operation mass and set this to modulo and make sure to put the same value in here that you used for the count and now we can create another reroute and put the modulo here now we will make sure that all our indices are going through this modulo effectively turning them in ranges between 0 and 49 and then again they ran 49 and then again 0 and 49. that means that this loop here will work for all the points at the same time because they get the same indices now that i have that i can just take the spline bundle here and connect it here to our output and don't forget to connect this to the group output again and you see beautiful now all 10 splines are being advected through the noise field this starts to look quite interesting immediately so let's see what happens if i move the noise field around and you can see now the splines are advecting through the noise field creating a visualization of the noise field and looking pretty at the same time so that is nice but what if we would turn this grid into a cube into a volume of points then the visualization would be even more precise so why don't we do that doing this is quite easy it's just that we don't want to use the grid itself alone instead we want to create a mesh line a mesh line and this mesh line should be set to end points and the first end point should be minus 0.5 in z and the next endpoint 0.5 in z creating a line of length 1 centered around the origin now i can use this mesh and another instance on points node to instance our grid to this mesh line creating 10 grids let me visualize this for you to better see what we are doing here you see now we get 10 and again we will need a realize instances node because we want to use the points of these grids so put in a realized instance node and now let's connect this to the points here and move the output back to the very end of our graph and you see now you get quite some advection because we are starting with a grid of points a cubic grid of points and all of these points get advected and that looks quite nice that we move through the noise field you see how pretty this is how intricate the structures are that are emerging from this operation really funny okay but all the splines are just black that is not that pretty so why don't we first turn all these curves into real geometry let me move the spreadsheet out of the way let's create a little more room here because we want to work with the spline themselves so let's at the very end create a curve to mesh curve to mesh node which will sweep another curve along these curves and this other curve for now is just a circle so a curved circle we don't need a resolution of 32 let's use eight and make the radius quite a bit smaller say 0.01 and now connect this here and now this creates mesh curves look at this look how funny this looks with all these curves being injected through the noise field now this is great but i would like to not only create geometry but at the same time color how could i color this well we started with colors in the first place remember we use the colors from the noise to be vectors that are used to move stuff around in space but we can at the same time use them as colors so let's set up point colors for this i first need a color output port so let's for now create a color node color let's create some pinkish color and connect it here to this color port now we want to set this attribute to the geometry for the shader being able to read the attribute to do this we have to go to the modifier and under output attributes we now have this color output port and we have to decide how to name the attribute that is being written to the geometry i will call it cd because that is what i am used to from houdini color diffuse that is my color attribute now we want to create a shade that can use this attribute so let's quickly switch to the shader editor and create a new shader we already have one so let's create a new attribute node attribute and let's put in cd that is the attribute we want to use and connect it to the base color and make sure to switch over to viewport shading otherwise we won't see the colors well at the moment this is not working yet because we did not apply the material to the geometry remember inside of geometry nodes materials are no longer applied to the object because we are replacing the geometry of the object this is not working so we need a set material node to tell the newly created geometry to accept the material so lay down a set material node material put it at the very end and now if we go in here we can select our created material and now this connection is working because now the geometry is using the material called material by the way let's call it visualize cd that's a more descriptive name and the attribute gets written to the geometry the shader is reading the attribute the shader is applied to the geometry and thus we can specify the color from here but i wanted to sample the colors from the noise instead of just using one color here so in theory i could just go in and drag the color output of the noise all the way over to this port here but this creates a strange noise pattern and that is not what i want i don't want to sample the noise after the fact so all the points of these mesh lines should not sample the noise and that is what's happening here and that is why you get these splotches of color instead i want to sample the noise at the origin of each line so the original points should sample the noise and then color the entire line with this color to do this we need a node that tells geometry nodes where to execute this color field here at the moment it is executed in this context so the geometry port on the group output determines the context that the connected field in our case this noise texture is executed in and because we have all the points here the noise field is executed for all the points we want to execute the noise field for all the points before we put the curves on them so for the original points of these cloned grids here and we can tell geometry nodes to execute this in this context by using the capture attribute node it is there for this purpose so if you connect it here it will allow you to sample the noise field here and then pass on the values to the created meshes so let's switch this over to be a color of the main point and now let's connect this color here now this node here tells the noise texture to sample only where these points are that are in this geometry input port and that is the original point and now this attribute is stored on these points and if we connect this to the very output at the end you can see that this changes the behavior quite a bit because now it only captures the value at the origin point of each spline and then copy this value to the entire curve giving the curve one solid color now this is pretty much it but the colors are very very light i think so why don't we use just another map range node to make the colors a little bit more vibrant duplicate this the lightness of the color the low saturation of the colors originates from the fact that the values of the noise texture originally are not only between 0 and 1 but usually they are in a range between 0.25 and 0.7 or something so that is why they are also light so let's put this color into this map range and of course you can put a color into a vector map range because the color is just a vector and let's say we want to output values between 0 and 1 because this is now meant to be colors but the input values should be something like say 0.35 and 0.7 or so to actively compress the value range and if we now connect this output to our color you can see that we get more vibrant colors and if you ask me this looks a lot nicer so look what we created a very very pretty vector field that picks up the color colors everything with this color and advects the spline through the noise field and by changing this ad here you can move through the noise field and display different parts of the noise field with color and look what interesting the shapes are that you can generate with this method but not only that being interesting at the same time this gives you a very nice indication about how the noise field the vector field actually looks like that you are working with so if you don't want to use this to create some pretty graphics why don't you just use this for debugging your other setups that may use noise fields okay now to finish this up let's quickly go to the shader again and finally to rendering and now let's introduce first a black background a black background is well viewed for this now we want to introduce light so light point light give this a little more wattage thousand like so and move this out of the way why don't we just go with a hdr let me quickly switch to the asset browser where i have some environments loaded and i will take this old industrial hall environment that i downloaded from sibl you can see now this is pretty and maybe let's return to the shader editor now go into the object shader i have to select the object and maybe we want to switch this to christensen burleigh turn up subsurface a little and connect this color to the subsurface too always gives a nice effect to have a little subsurface with evie so let's see what this gives and this already looks quite nice and now maybe let's create a seamless background by just introducing plane and scaling it a little bigger let's go into edit mode and just extrude this back side here move it up and if i now bevel this like so let me introduce a few more subdivisions make it a nice bevel like say so that looks nice let's shade this smooth and move all of this business down a little and maybe we want to scale it even further let's see how this looks now this looks really interesting if you ask me now we can put in a camera and let's look through the camera by pressing 0 on the numpad make the camera viewport bigger and now lock camera to view to find a nice camera angle like so and now you can return to the geometry nodes editor and to animate this we can just move the noise field around as you can see and of course we could keyframe this value but i prefer to do it procedurally so why don't we just lay down time node scene time and let's use as a seconds here if i connect this it's probably not a good idea because now everything is very quick but we can of course use a combine xyz to manually create the vector that we want to use and let's use the seconds only on the x now it moves from front to back better to easier on the y like so now this is nice still too fast for my liking so let's put down a math note and let's just multiply this down 0.5 maybe this is nice and because this is all procedural i can go in and maybe just create less blinds to make it evaluate faster we could of course change these vertices of the grid but then we have to change this count too so why don't we just lay down another integer node and connect it here and here and here such that we can set all these values at the same time and let's go down to five creating a cube made out of five sample points in each direction okay that's great last but not least let's go in and let's go to node and let's call this count because that is what it is and now you have a pretty animation of your vector field traveling through your sample grid so the vector field is traveling through the grid and the splines are advected through the grid and this gives this interesting animation and let's see what happens if we go up to 20 with count that gives quite some splines but look how pretty this is and if you move around in time you are sampling different portions of the vector field of the noise field and this of course gives different interesting results with different interesting colors and this is really a nice procedural playground to come up with interesting abstracted forms of course you can go in and change the other parameters of the procedural setup that we just created so you can of course change the step length make it longer say 0.1 again and the splines will be adjected longer through the noise or you can go smaller 0.03 and it won't be as long so that concludes how you create noise advection with curves inside of geometry nodes inside of blender i hope you like the tutorial and i hope you find this setup useful for one of your projects thanks for listening and it is cheers and goodbye if you like what we are doing please consider becoming a patreon not only for supporting and tagma but for access to in-depth courses on topics such as particles vellum geometry nodes and so on and so forth and at this point let me say thank you so much to all our existing patrons without you this channel would not be possible thank you
Info
Channel: Entagma
Views: 47,177
Rating: undefined out of 5
Keywords:
Id: JfKQ8m3ZfJM
Channel Id: undefined
Length: 30min 54sec (1854 seconds)
Published: Mon Jul 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.