Blender Tutorial: Connect The Dots with Geometry Nodes, The "Plexus" Effect

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello this is Manuel with intagma and I'm here with the new blender tutorial today I want to connect the dots I want to create an effect that is known as the plexus effect I think because of an After Effects plugin that is called plexus that creates this effect inside of After Effects I want to take a point cloud and then I want to examine the distances between the points and if these distances fall below the threshold I want to connect the dots with a line and by the way this is the very first effect that I created as an Houdini tutorial on this channel I think four years ago and today it's time to create the same thing inside of blender using geometry notes so let's start by selecting everything and get rid of everything instead I want to create a mesh monkey let's subdivide this monkey like so and then apply the modifier and that will be the volume that I want to use to distribute some points in to make this invisible now let's create a new plane that's just a placeholder object and let's call it GN for geometry nodes and then connect the dots like so let's create a geometry nodes viewport and let's get rid of the side panel and create a new tree and call it TN underscore connect the dots like so let's cut this connection and let's bring in our Suzanne whenever you bring in another object you have to decide if you want to use original or relative I want to use relative because I want to use the global coordinates of the Susan points inside of the coordinate space of my object here now let's connect this and this creates our original geometry now in this coordinate space now I want to distribute some points but not on the surface but inside of a volume and to do this I think you have to use the blender 3.4 version that I'm using here currently so if you don't find some of the nodes please update to the very latest beta version so I want to first turn our Suzanne into a volume using the mesh to volume node this gives a volumetric representation of Suzanne and now with this volume in place I can use distribute points in volume and that creates some points inside of the volume I can up the density and that creates more and more points filling the volume with points to develop the effect let's go down to 10 with the density or even lower say five because as long as we have only few points it's easier to understand what we will be doing now this is our Point cloud and now comes the algorithm to make this visually clear I want to create a reroute here and now let's invoke the end panel for a second select the reroute and call it in there is a point where the point Cloud enters my setup great let's cut this connection and let's put the re-routine before we start let's think about what we are about to create so if I have some points that are scattered in space I want to start with the very first point let me create a new layer with a different color so this point here should be the first point and that has an index of zero and and now I want to examine all the distances to all the other points so I can calculate the distance to this point and the distance to this point and the distance to this point and so on and so forth or the distances and as soon as I have the distance as I can decide if the distance is short enough to be drawn as a line now once I have this I have to do the same thing for the next Point Let's create different colors so this say here is one now I have to do the same thing and have to examine this connection and this connection and this connection and so on this connection and then the same thing for the next Point dark blue say that is 0.2 and we want to examine the connection to this point and to this point and to this point and to this point and to this point and so on and so forth so as you can see to find all the connections between the points we first have to run over all the points so we want to examine point zero and then 0.1 and then 0.2 and then 0.3 and so on and 4.0 we want to look at all the other points so 4.0 we want to look at the connection between 0 and 1 and 0 and 2 and 0 and 3 and so on and 4.1 we want to look at the connection between 1 and 0 1 and 1 1 and 2 1 and 3 and so on and for two the same and for three the same so we have a lot of examination to do and if you look at this closely we want to look at all the points for every Point how can we do this without Loops inside of geometry nodes well actually we do have loops inside of geometry nodes but these Loops are not directly usable instead we can Loop over geometry only so we have to create geometry to create this Loop and unfortunately we cannot do nested Loops that is what I intended to do I want first to Loop over all these points and then for every point I want to Loop over all the points that is not possible either so what could we do well we can come up with a serialization we could think about how to turn this into a linear Loop and if you think about it we could do the following we could look at point zero and then we could pair it with point zero and then we can look at point zero again and examine the connection to point one and then 0 again connection to two and zero again connection to three and so on and so forth let's assume that we only have four point at the moment now after we did this We examined all the connections of point zero now it's time to check the connections of point one so now we could look at point one ones to examine the connection to point zero then at point one again to examine the connection with point one and then again connection to two and again connection to three and after that we can start with two so let's look at point two once to examine connection to point zero and then with one and you get the idea so if we do this we look at every Point not once but as often as necessary to go over all the points and interesting pattern is emerging here if you look at this this is an indices of the currently processed point and this is this is of the target point that we want to examine the connection to so we get an index pattern here that is zero zero zero zero and then one one one one and then two two two two and then 333 if we have four points and here we have a pattern that goes zero one two three and then starts over at zero one two three and if we have these two index patterns we can match every point with every other point and by doing so we can circumvent a shortcoming of geometry nodes that it does not have nested oops so let's get rid of the annotations and do this so first we want to create some stand-in geometry that serves as a basis for our looping so we want to add some points for this we can use the point node that allows you to create points by count and how many points do we want to create well we want to create as many points as R in the point Cloud squared because for every point in the point Cloud we want to create as many points as we have in the point Cloud before we continue let's quickly create another viewport up here and switch this to be the geometry spreadsheet that makes it easier to debug things and let's connect this here quickly and you'll see at the moment we have 21 points so what we need in total is 21 squared points so first we want to find out how many points are in the point cloud and we can do this by creating a domain size node this gives us the point count that's connected here and let's switch it to point cloud and tells us that we have 21 points in the point cloud and now let's Square this using a math note mass and go to power here and we want to use an exponent of two so let's Square this number and now let's create some points by connecting this to the count let's see now here we have 441 points that is 21 squared let me check if I put 21 times 21 we get 4401 what's up 21 squared is 441 okay but these points do not have any location we want to put the location of the point regarding their indices as an attribute on these points to calculate with these attributes instead of the real Point positions remember this is just a stand in Geometry it's just there to make geometry nodes run over 441 points and we will just write the positions onto these points but before we do this we want to Tinker with the indices so let's create an index node index and for debugging it's a good idea to use a viewer node so let's create one if you create a viewer node and you connect some geometry here let me create some space here and make it visible the attribute spreadsheet immediately switches to display the output of the viewer node and now I can connect for example the index here and if I now go to the points we have a new field here called viewer and here we see the index value and the index value of course is the same as this index value here now remember the pattern that we wanted to create first we want to create 21 zeros and 21 ones and so on so forth to do this we can do the following let's duplicate this power node we just need a math node and set it to divide what if we take the index and divide it by the point count then what that gives is a number 0.00.048 and so on and so forth that c and with Point 20 which is the 21st point we get 0 9 5 2 and then we get a one so this looks suspiciously as if it is the right thing to do but we are only interested in the integer part of this not in the decimals how can we just keep the integer part we can duplicate the mass knot once again and set it to floor the floor function will do just that it will get rid of all the decimals and now we have zero zero zero 21 times and then the first point in the next punch is now chord one and then with Point 42 we get a 2 here and that is exactly what we need so we now have an index number the first 21 points are meant to represent point zero now we need the second index for the Target points how can we calculate this one well we just use another Mass node and take the index but this time we set this to modulo modulo the modular operator gives us the remainder of an integer division so if I now create the modulo with the point count let's see what this gives and now we get 0 1 2 3 and so on so forth until we reach 20 with 0.20 and then it starts over at 0 1 2 3 and that means now we have exactly the two index pattern that we need to match every point with every other point to remember what we did here what I like to do is to go to layout and create a frame an empty frame I use these as tags as text tags so the first pattern that we created is zero zero zero one one two two if I assume I have three points this is a pattern that I would create three times the first index three times the second index and so on now let's duplicate this one and this modulo creates a pattern that reads differently it reads 0 1 2 0 1 2 0 1 2 that is what the modulo does now these two indices correlate every point with every other point in all linear Loop exactly what we wanted to do now let's start to compare the positions for this we need the positions but we do not have any positions on these temporary points so we have to fetch the positions from the original points to do this there is a node called sample index it's samples of value by using an index and we have two indices here so let's switch this to Vector because we intend to sample the position and let's create a position node to tell this node which value to sample connect the position here and now we want to connect the original geometry the in Geometry to this geometry because we want to read values from this geometry at the index that we provide now connect this index to the index this gives us our source position because remember this is always the same point if there's a source position now let's do the same thing but for the Target position we connect everything similarly in Geometry here but this time we use the second index now we get values for the salt position and for the Target position and that means we can compare the lengths between these two positions by using a vector math so create a vector Math mode and set it to distance and connect the two values here this now calculates the distances of all the connections between the point and that means we now can compare if these distances are shorter than a certain threshold by using a compare node so compare and we want to compare this float value it's a distance so it's a float and what we now want to do is we want to delete a point if the connection to its Target point is longer than the distance that we specified so let's keep this to greater than and for now let's put in something like 0.3 here so whenever the distance between these two positions is larger than 0.3 we get it true and with this true we can do something we can now create a delete geometry node so let's feed in our temporary points let's move this stuff out of the way let's feed everything through this delete geometry node and let's connect this here and if I switch back to evaluated you see we are left with 25 points if I go directly here to the output we have 441 points but obviously only 21 coins have connections that are shorter than 0.3 that is nice but we have a second problem to solve and that problem is that we have probably double connections because if we have this pattern remember we have zero zero zero one one if we have three points and then 0 1 2 0 1 2 we will compare for example the connection between 0 and 1 and the connection between one and zero but that is of course geometrically speaking the same connection so we only want to have this connection once and that is why I do a second test and this test is I want to test the indices and I only want to keep the connection if the first index is smaller than the second one that makes sure that only use every connection once and I want to test something else because it does not make sense to compare points against themselves this will always be a distance of zero and it will be drawn although the points are at the same position so I want to get rid of these connections how can we achieve this while we do a second test duplicate this testing node and now we compare the indices let's compare the two indices by wiring them here and now switches from greater than to greater than or equal because if both indices are equal I want to discard this so now we have a second test we have two boole values both can be two or four so we have to combine them and to combine them we want to use Boolean math and we want to switch it to or so this port will be 2 if either this one or this one is true so both can delete geometry let's connect this here and then the output of this to our selection and we are left with just two connections but if we now make the threshold higher 0.5 for example we have 14 connections it seems to work because everything that resembles the connection that does not meet our test is deleted now the problem is that we have points that resemble connections but we do not have the actual positions these points are just temporary geometry they are all residing at the origin so we have to provide the actual positions the point positions as attributes so let's do this we already sampled the positions and now we have to write them to this geometry stream as named attributes because the delete geometry node will Tinker with the actual indices so with the indices of blender sees and that means we cannot use these values directly it will not work we have to write them to the geometry we could use a capture attribute instead if you prefer you can use that but I think it's clearer to store named attributes so let's create a store named attribute node and let's switch this to be a vector and call the attribute my pause for my position and let's put it here before we do the delete geometry and then we need a second stored attribute and that will be the target position Target position because remember every Point here resembles one connection so a connection has two points at starting point my position and end point Tire position and the starting position will be this one here the first one that we sample with these indices and the second one will be this one that we sample with these indices and now we have a lot of data here on our points as he might pause the entire Paws and they are different not always but they are different most of the time and now this data is persistent after the delete geometry because it is attributes are stored on the geometry so even if the indices change these values will be there so we now can use them after the delete to create some lines and position the lines correctly to create some lines we just want to use instances so let's create an instant some point node and I want to create some lines so let me create a curved line and let's put the curved line onto these points if I do so I get 15 instances because we are left with 15 connections now let's turn these instances into real geometry because then we have lines with the starting point and an end point and we can use these points to connect the dots so let's first use a realize instances here which now gives us curves 15 splines with 30 control points and that is exactly what we need and the good thing is because of the way that the instance on point works every line has alternating points so the first two points are from the first line and the second two point from the next line and that means that you can tell if you are dealing with starting points or end points by the index if the index is even we have a starting point and if the index is odd we have an endpoint and we can use this fact to set the right values so let's first put down a set position node set position and let's connect it here and now to set the position correctly we need to switch note because it now depends on if the point is even or odd if we want to use the my path that is stored on the point or the tripod that is stored on the point so let's create a switch and this switch uses a Boolean value to switch between these two ports and let's make this a vector and now we want to read the stored attributes named attribute and this one is my post and then let's duplicate this one and that one will be terpos connect both here and now we need this switching value to decide which one to use and that can easily be calculated by using the index the remaining points and deciding if it is even or odd by just using a math operation again that we set to modulo 2 because modulo 2 will be zero if it's even and one if it's 4 and 0 and 1 is exactly what we need to switch between these two ports so if we connect this here and now connect this here to position the setup is finished and should work but we don't see any draw between the view port and that is because of the viewer node that is still active remember we left this active so if we just delete it now we should get some output in the viewport and it is working here you can see all the connections that we created if we go to our test and up this value here more and more connections are drawn between the points that we have let's go down to 0.5 again we only get few connections because everything that is longer than 0.5 will get deleted but now we can go to the very beginning and up the density on our Point Cloud to say 20 and you see you get a lot of connections because now we have more points and thus we have more connections that meet the requirements and that is exactly what we wanted to do now let's create some geometry for these connections to make them visible for this I create a curved to mesh node curve to mesh to create geometry out of these lines I need a second curve a circle here for this note to work so create a curved Circle and connect to the profile if it is far too large Showdown to 0.01 and you see now it draws the connections but I don't want to have the connections only I want to have the original points too so let's go back to the beginning of our setup and let's create another instance on points let's just wire in the point Cloud itself to this instant from points and let's put spheres on the sphere icosphere will do here let's make this smaller 0.01 for now this is a point and back here we have the lights time to join them let's create a join geometry node let's move this stuff over here and let's wire in the points and the lines merge both and now with both merge we can connect the output to the geometry and we get both the thing is we don't see anything because the lines are still too thick so let's go down to 0.005 Here and Now you see you get little fears at the point and you get connections now we have a network pretty time to deal with the color I would love to set some colors on the points and then make the connections interpolate the color the Devils we first have to set up color on the points so let's go back to the points and let's move everything before the in out of the way and let's use some noise to drive the color so let's lay down a noise texture noise texture I don't want to use the color of the noise directly instead I want to use the factor and then drive it through a color ramp for this to work let's first lay down a map range as always when working with noise because the noise values usually are not evenly spaced at between zero and one let's go to 0.4 and 0.6 here and now let's use the color ramp color ramp that will take these values and give them color and I will use a dark blue here and then on the other side red and to make it more interesting create two more knots and the one in the middle will be yellow like so and this one probably green maybe like this give it a little bit more fresh green here this is too dull too though this might look okay so this is our color ramp now we want to set this color to our points to make it available in the shading context and for this we use stored attribute again so store named attribute and I call it CD that is a habit from Houdini where the color on Geometry is always called CD for color diffuse the switch is to be a color and let's connect the color here and there's one more thing I want to do I want to create a position field because I love to make the connection here at the beginning of the noise explicit now a noise value is created for every point and this sampled and some color is sampled and written to CD that means that we probably can give some shading to these points let's switch to the shading editor and let's create a new Shader and call it CD underscore instances because this will shade the instances instances and let's create an attribute node to read the CD attribute but be careful this instances these little three other instances so we have to switch this to instant search to read the writer attribute and put City here down there now it reads the correct attribute put it in the Shader and we'll apply the Shader to the point geometry so back to Geometry nodes and up here we can create a set material node set material like so and switch it to be the CD instances Shader now if we turn shading on you see that the points got color let me make the points a little bigger for you to see better what's happening here so let's go here and let's upgrade to 0.02 and you can see now we have color on the points nice but we want to take the same color for the connections and we want the connections to interpolate the color so if we have a Green Dot here and the yellow one here this should fade from green to Yellow so we have the color on the points how can we put it on our connections we will need a second Shader for this and we want to sample the information and put it on the points just like with the positions so here where we sample the position we now need two more sample index nodes to sample the color information let's duplicate them and set them up exactly like before so the original Point Cloud geometry goes into geometry here and there but this time we want to switch them to be a color we want to sample color so color and color the indices are the same so the first index goes into the first node and the second index goes into the second node because we want to sample the point color and the target color and now for the colors we want to read the named attribute because remember we set this here to the point and now we can read it here so create a named attribute node set it to color and read CD that is the color CD then it's a color on which now let's read the color and put it into these two ports now these nodes sample the color from the points time to put the color onto our standing points so we have to duplicate these two story named attribute nodes and do the same things which are from Vector to color this time we want to store colors and connect them here after that so that we have four of these nodes I want to call the first digital my color my call and the second one Tara color tar call Alexa and now let's connect the output of these sample nodes to the first and second node let's see what we get here if we go to the vertices we can now scroll over and see that I have my color and dark color and both have values now I have these color values on the points that I use to create the connections so I in theory could use them later to set the color to the point of the lines that we create from these connection points basically it's the same setup as with a position but after the position we want to set the color so let's move stuff out of the way here's our setup to set the position for the alternating point and now let's do the same thing with the color let's create another store named attribute because this time I want to store CD for the line points and this CD will depend on odd or an even point so I'll switch this to a point and do the same thing as here we wanted to duplicate this switch node this time again we want to set it to color and now we want to read my color and tar color so let's duplicate these two nodes and let's read my color my call and tar call the note understand that this is a color value and switch the type accordingly connect this here and there and then this goes into the CD value name it CD so now the point of the lines have a CT value too but they do not have a Shader assigned that is why you don't see the value so let's create a Shader because remember up here is instances and we created a Shader to read the attributes from the instances but this down here is geometry so we need a different Shader go to the Shader editor and click on this little two here to create a copy of the instance Shader and just call it CD like so and let's see where the network is here it is and the only change that we want to make is to switch to Geometry to read from geometry back to Geometry nodes and now the last thing that we have to do is to apply this material so let's use a set material node here and apply the CD Shader and you can see as soon as we do that we get color on our connections and this color should in theory interpolate between the color values but we forgot one thing we forgot to connect the modulo value here so it's not switching at the moment it's just setting my call but as soon as you connect our modulo value to the switch now it sets the correct values and starts to interpolate the color as you can beautifully see here with the blue dot now the color is just fading from Blue to Orange pretty now we are pretty much done the last thing that I want to do is move the original Point Cloud to make the effect more interesting I already got a noise there so let's take this noise and use it for moving the points that is easy here we have noise vectors coming out of this color Port we will need another map range node but this time we want to set it to vector and we want to connect this Vector here remap the values between 0.3 to say 0.6 two values between minus one and one because we want vectors that go in all the directions in euclidean space that are possible and we need one more node a vector Mass node Vector math to scale these vectors put it here switch it to multiply and for Simplicity I create a value because I intend to scale this uniformly connect it here 0.5 for now so now I have created noise vectors and I scaled them time to apply them so after the store named attribute we want to store the position we can do that with the set position node put it here and connect this to the offset and you see now everything is deformed by noise and we have this control down here to tell how strong the effect should be very nice let's go to the render settings and turn off viewport denoising for now now the last step is to make this move and to make it move I want to use a scene time node so create one scene time and and I want to use the second here to make the noise move for this I switch the noise to be 4D noise that gives me this W value and I can use this one to move the noise to the force Dimension actually changing the look of the noise in the remaining three dimensions but if I connect the seconds here directly and then press play Everything is quite fast so let's multiply the second down by using another math node edit here and set it to multiply and say 0.2 so now this will be slower let's test uh still a little fast let's go to 0.1 and now we got a very pretty particle animation of the points moving around driven by noise and the noise is shown as color now you can decide how many points you want to create say let's go up with the density to 50 and you get a very intricate Behavior here we have a lot of control as we now can decide how far the points are moved apart by the noise and you can tell which connections you want to draw and which you want to skip down here with the testing whereas our testing is our test value at the moment it's 0.5 but if we go higher we draw more connection and if we go lower we draw fewer collections so you see do you now get a lot of control to create this intricate connect the dots effect so the last step would be to turn everything that is back here after the end and create a node group out of this then you could store it in the asset manager and make it ready for reuse later in future patients other than that we are done we created a plexus effect inside of geometry nodes and colored it and made it move so I hope you learned something from this tutorial and as always it is cheers and goodbye if you like what we are doing please consider becoming a patreon not only for supporting antagma 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 patreons without you this channel would not be possible thank you
Info
Channel: Entagma
Views: 80,985
Rating: undefined out of 5
Keywords:
Id: tj6ZZYO5qPY
Channel Id: undefined
Length: 32min 30sec (1950 seconds)
Published: Mon Nov 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.