 Hey everyone, I'm Dalai here. I want to try to do another codewive episode And the idea today is to see how far it can get and I have a lot of time It's gonna be slightly more than one hour, maybe two top to try to get a visualization for the different flows in geometry node In a geometry node 3 usually you have the main flow of the geometry and then we have also the secondary flow of the function which are the fields and things which are evaluated There's a blog post on codewive blender.org that explains it a little bit better We have a task for this which we created those days and some detail that we have a reference commit I've also talked to some developers about How do how to implement that? So I have some flows But the main idea is just to be able to navigate the code and then talk out loud about the process of doing so Not so much about getting to the solution which No idea if you're gonna get it Let's start as always by having a nice simple file I have one already that That illustrated the problem This is a simple file you follow using fields. I think that's not master just yet Let's make this nice and big here is a little node 3 to basically Based on the position Based on the position of the vertices of the cube To translate them in a direction That's what I'm doing if I hide this Basically, I'm taking the cube and then having a position and I'm adding a value to it But I want to do this only for part of the node and the interesting thing here is that We have one main flow here Which is a so-called data flow so the jump to the pass through Then we have another flow here And have a secondary flow, which is the function flow The data here is only evaluated In the node once we get that geometry so the node gets a geometry and then it goes back and reads Everything that's been passed to it And we're here as well for the selection So what we're aiming with this Project is to have those lines here dashed That's simple We can tell in a glance for zooming out you can tell oh, this is my main data flow. This is my function flow can also tell then Can also tell them by their socket type This is using a branch already Basically a patch that Jack Luke is Been working on I think I'm already gonna help a little bit. I can already tell a little bit then apart But it is to enhance this to the next level Let's get started Basically, I know that What do I know? I did in the past. I contribute some of the dashed line shader. So for me, it's not that much alien But basically we have some Make this bigger There we go. We have already like some shaders In Blender to handle dashed lines Which is simply doing these in the fragment shader. So this for example Well, there's a fragmented itself and Basically discarding it Anyone not familiar with open gel and gel a cell basically have a program that draw the points and then For each pixel in the scene In what you just draw you can apply something on top of it. In our case are literally Just discarding dashed line just so you can see If I have a let's do it differently. If I have a parent camera It's probably gonna be hard to see in the video. I cannot really see maybe here Is it a dashed line? Let's save this as And if I say and tell this never to be discarded ideally They should make it disappear. We're not really using the shader. So there's more an example It did not work so it's probably using one of the other dashed line Shaders we have. Oh, of course the 3d line. Oh, I got a fragment shader for a 3d line Very interesting. I don't see it here. Oh dashed reform in screen space I have a feeling That the dashed line in this case Complete even outside the days, but let's go to another part of blender that has already dashed line like the Outliner if this is the parent of this one shift parent Here you see the dashed lines and with the new build you should not see the dashed lines So let's open the file again. Oh, that was a different black file if this is out of this one. I See I still see the dashed lines This is about right As you can see I'm not only With rusty Idea they did read compile Did I run the right planner? You ever got saved this one, but that's why I'm just still working here even though we discard we stopped And from discarding them and compile it fine, right? Yep. No idea Which is fine because I'm not really using these as a base Man this so not working, but let me explain a little bit what I learned so far from the code on what we're looking at basically blender has a bunch since we migrated from OpenGL to OpenGL We're doing 2.80. We had to make sure that everything We do uses the latest greatest OpenGL technology, which means you're using Vertex and fragment shader for pretty much everything we draw. Oh, that's a good link So in this case we have a line. So how do we do the? overall line the dashed lines You basically we know for each of the pixels of the drawing how far we are into the line What do you see here? And based on that we know whether or not to dash the line Again, I hate it that you cannot really see it in my little test But that's okay now for the node links. You also have a pair of nodes which are used here Then there's a bit annoying that regard because if you want to know when we're using those You actually need to look for That's the kind of straight the problem. It's as up versus all together. Sure. I think you're using a macro for those things So Blender first Blender has a way to convert those codes to C code And you save them as this Here I have instance and other one think that's the main one Basically, you need to go here and any place in the code that's calling this is probably using the it's using this shader Which in our case is here and here back draw for the node link functions this one That's a draw link bezier. Let's Just hack them around so just to see if you if you if you hide this one If this function no longer runs, what do you get me or the UI change it didn't get saved, you know Have some things. Oh Yeah, I cannot see my lines because we basically Made this function to not run. It was good. So we found at least the function that is calling The drawings the drone itself was talking to play mom and he said that the way this works at the moment That we are basically drawing every single The program is we draw every single point and then we shuffle them to make the line Inside the shader node. It's basically here There's creating the batch builder We actually passing the handle I need to look at it. Also spoiler alert a really very noob when it comes to curve code sorry The curve code so the whole base your calculations can be beyond me But that's okay Let's focus on let's take a look at the let's take a look at the shader that's exactly drawing those lines if anything maybe helps us to help to Illustrate the problem node link and Fragment shader and this one is doing almost nothing Just for fun Let's for instance say that If it's funny, you're gonna say it now actually. Oh, there you go. Yeah, beautiful. That's where you are if instead we do But this is how we do Kind of an aliasing, but let's instead try to just discard and of course this is gonna I Hope the shader optimize itself, but basically is gonna make sure the whole thing doesn't drop Because we're discarding every Every single pixel and then just so we take a quickly look at the code I'm curious to understand where How are you using the base is Hope is 0, P1, P2 That's fascinating Not pretending I'm fully understand what's happening here But kind of aligns to what the clean mom was telling me. Oh, so I have teeth teeth. How far so that's the T, right? T, T1, T, T, T2, T2 Times 3 3 basically is how far you're into the curve Let's try to also we have the UV already here I think you probably need what I have to do is to Calculate the UV so basically how far we are into the curve On the jump on the vertex shader but for now, let's try something interesting which is to basically take the UV and Have these affecting the Shader node, so I want to use the UV as a color over there I just go and try to use it here To don't work because you need to expose these in the as a totally calling this as an out in and out as the But I think I probably let's Let's see if you can you'll be forgot that the In out, but let's do a new out. I call UV dash It simply is gonna be That's before and I know that makes this whole thing chaotic just show what happens if I don't pass the UV there I'm gonna be fine. The problem is always when running it because those shaders are compiled In runtime and I cannot we're just about fix that And I think the problem that UV itself adjusts it. It's a it's linear technically if you change That can be interesting. Oh, sorry. I'm gonna find a variable UV. Oh, you did that. Sorry. They forgot to remove No, they're probably all zero zero. I forgot to initialize it. So what's happening there? It's very simple You did that she's zero because it didn't set any value So we get the same red color we got before out then the color is the one zero zero let's Do this but what I'm trying to think is I would say it's probably like out there trying to do it as far as just having the The lines when they are not curved to work And then let them all have fun doing the curved lines. Oh, that's so beautiful. Oh my god That is so beautiful Honestly, I think that's all we need. Oh, wow. That is so beautiful You see that? We already have does it change if it's I Think even Yeah, there's only do if you act technically not even UV is a float Let's call you're gonna call t-dash How does I find a better name very soon? But Well, no, let's let's keep to do. Let's keep to the old name who cares of course is a float Already want to change the name. Let's call it Line I think it's t the name for that how far you are into the line But let's give it a more let's quite you know, let's call it Sometimes name is the hardest line Only the least effect on G to be that Just because my I just a theory kind of thing. This is gonna get us the same Give me that and then I'm gonna try to invert it Like you like you But I do remember in the same result as before and I'm pretty sure you should do the why I'm pretty sure this isn't no Let's find out. We're happy with the previous value. We also need to know. Okay, that's very interesting. Oh That's so interesting We also need to know how large how big is my entire curve Entire segment so I can know given the line you Given the line you We know how far How many real units when you're skipping it? This I think I was just gonna cheat for now and but in the future be nice to calculate ideally once for the whole curve But I can just do it. We want to do it once for the whole curve But we can do it once per vertex. It's it's fine. But the results gonna be the same It should be easy to calculate with those Blah blah blah. I'm gonna try to find a formula and then to calculate that I can ask Hans He's probably know it Let's pretend this is I was thinking about like some arbitrary number, but let me check something here Actually want all those values as well. I'm gonna copy those in a bit Just interest on what's the unit here? Shoulda matter, right? Let's pretend is one One what let's call this what they are parameters Line line length and it calculates still Honestly, you need to do it section here back to our other shader Right, and then the other values for now. I'm not gonna pass it. I don't even I'm not even I don't remember The long perspective means it doesn't get a thing interpolated You can quickly check this It's not what it wants. What we use it all because the fact is in 2d so I'm pointing like all these Maybe I need to spend some time understanding these But I won't what we need now. I want this to be more than one. I want this to be like five Because First we get a let's first calculate This is a bit interesting that we're gonna be a bit boring because there's not so much about the blender It's more about now the shader as a whole, but I hope it's still interesting and You want to know? How do you do that? Have the overall thing Let's start copying some code around so I understand what the normalize distance I just did T. We just want T to be divided by X amount of okay. That's a dash read it. So let's get dash read it as a Define Later we can replace it as a uniform Fract is a fraction part of the equation JL cell and a fraction apart So X minus 4 This post this is supposed to be the easy part Let's start simple So if and that's really bad coding, but if line you oh I need to know the line you in absolute terms. So let's even do that. Just You can normalize everything gonna do the other way around so line you Gonna call it absolute go line length times Line you I wonder you'd be I don't I don't use this for now. So Be around but what I want to do for a quick test is this if blah blah blah This card also cares about So I'm gonna do something gonna save my default file. So it's always Beautiful so beautiful and doesn't matter if it's curved or not I love Working on a visual call is so much fun. Oh, it's so much fun Well, first know what what I want to do instead is to actually use the absolute number Here's about the what we use elsewhere. Okay, so that's very We change that though. Oh Also because the I'm not using the real distance calculation, right? Using five so it's not even proportional That's now Let's do Let's do a first really cheap. That's line if it's bigger That is out you put on the cringe Are you how we don't have a plank format playing blender? We have playing format for forming the code which means basically if I If I for instance not following the blender style added plenty plenty of space here and I save oh My computer is not running Plank format, so never mind, but it should out from it. I can order Small intermediate Mission compile why we think so here we want to set up Can I do that? Yeah, that's the whole point of this right? to Show how developers work does this to exist? Whatever do I go over the blender? plank format documentation how to That's what we want. No, I'm obvious code. Sorry. Here you have it already Let's let's try it. Thank you very much. Sometimes I get so lost at the Running manually that's so bad. Check this out. Come on people All the claim format Let's do some information something interesting. I'm gonna commit something. I should just ignore it and continue But I won't master make sure you have the latest I was just basically gonna do a small commit to fix Just running plain format in the whole master as you see some developers like myself And I can even tell who it is but They're not running Plank format on their computer, and it's pretty much most of it is harmless But I think you don't run plank format for the GLS files yet continue for five Nasty, but it's beautiful. I think I got I'm gonna share this with the team just to get their reaction compile is gonna take a bit longer now because we are We updated Blender pretty much Shouldn't shouldn't have it Now let's let me think for you meanwhile. Oh to do get a real extension Get a little line absolute and the formula is really days. It's really let's get a dashed and now we want to normalize What is actually doing here is? A trick to not use if and else I'm pretty sure Just an optimization trick So every time you don't if elf if else it can create branching code in the which for shaders really bad Because the you know when it comes to GPU coding One of the benefits of you know something like fragment shader that can run in parallel All the pixels can be calculated at the same time and if you start branching out we have Pixels running in different speed different programs That's as technical as I can get but it's not so good So I think this is just so we wait for them to have a color for every pixel weather Is that you're not I think or for Fading out once you calculate and Find Look at this So beautiful want to do this our complete line. I'm gonna share this already But won't be much harder than that. I believe to Blender Chats just let me double check to see if everything's fine Yeah Do you have a formula to get the busier length But let's go back to the video. Let's share the code just for fun Beautiful beautiful. Let's go back here. Of course. We don't want to do these But but it's correct I was trying to think if it's the Principles correct and it is and it's stretching because we don't get a real the real line line length How hard should it be? I'll do a knock. I'll do something like a little hack I'll do Calculate these just based on the distance between The First point and the last point remember this function distance. Is it built in? Can I call? That back to you so this mbt-2 back to is gonna be oh, sorry p3 Right clearly Not good. How do I know what is the data that we're getting here have no idea to know Let's multiply by a value. I don't want to adjust the my our manual actually Actually, I'm curious if you ever if these ever get dashed. So if Use the distance Well, maybe can just check the values we're passing right No pain No game remembered or deal to find who is using those let's go back there arrow size the other one that the one we Print those points before Announced me so much that the client form is not running You did split this so nicely already function Really wanted to running Did I disable it? By accident expression No, he doesn't expect expression. Oh, it does expect something. I'm getting wrong Hopefully have print have exposed in this file Pretty sure we do Are we do I'm used to Python more than signal days And it's so consummary in Python to added those leading commas So when you did well, let's not try to think at the same time recently syntax error Wasn't this the one that's ours one of those things which I forgot to know the other things called I got it This is the thing that's called being called instead can just do it here. It's fine Here and I might still fix my clank format before the end of these because it's so annoying to me I want this to get a value to understand what's in what yeah, this files a bit too big for that I know this already because But that does give us Sense of wow of the scale those are the units. So for instance, let's Let's say go Blender has a way it still has to Okay, let's show that to the bug math visualization and math piece But I don't think it's enabled by default if you think This is my what do you want just here Be zero sick of Man, it's been so long Vector never stick at least or as it works. Yeah You won't be able to see it. Let me try to make this better There you go. So that's P1 over there. So that's a Blender has It's an interesting way to help people to debug visual Mathematical Coding that's P1 Now P2 It's a nice way to check the order Okay, getting to the meat of this video P2. Yep, and then before P3 and then I found the distance between I was right in the order, but basically is the distance gonna be We have a built-in Distance now it's P3 minus P0 That's a vector and the length of the vector 124 Going back to where we were I was saying five I Really it's more like a hundred. What was the example? 124 For one of them, I don't even know which one was it When we give us a measure of the scale, so if it is a hundred twenty five Even okay, so if that's we actually taking the distance Now we're talking about five times 20 times what we had before this shouldn't matter either way. Oh, yeah, because they line absolute So if this is a hundred let's say is every 10 you better Then and then 20 and 30 40 and 50 60 and other or to see you go, but let's close this Just and that's when you just want to the scale. Otherwise, it's Ha and now even if you change it's working Each again, it's not calculating the real distance. Of course, it's Not creamy and loop or anything It's pretty cool. It's actually So nice The big question of course is it is really if this really going to work and I think it will Think it will That's it hands replied. Otherwise, I'm gonna find it in the internet the formula no closed form solution for calculating The length of a basic curve adding up the length There's no formula for that No Must be but for now, it's fine. Honestly, maybe even for the final shader. This is fine might not not not Not this menu, but overall Approximate length Because like who cares why bother just cleaning up a little bit. No, let's get the So that also means the dash with it in this example was 10, right? Now let's use this all the way to the end and Then we pass this as a parameter. Let's copy this over and try to understand what I what is this line doing This is a long line is what we're calling this Let's rename There we go. I Got a normalized distance and Then oh we have the dash with it and then the dash factor Which is this well, and then I have to guess and I don't so I want for now I'm gonna have the This I'm practical to think if I'm talking about the distance along the line Let's use a let's make it visual. Let me close these otherwise Let's make it a visual So I have my line here and the distance along the line is 0 1 0.5 here By divide the distance along the line with the dash unit. Oh this along the line is actually What it did like was that 200? 120 right 60 We divide one this by the line dish. So it's gonna be 0. He's gonna be 6. He's gonna be 12 He's gonna be 3 9 here that is the Divided and then the fraction why do you care about the fraction sir, but the fraction is how far We are too. I'm not very happy with this formula Maybe because I'm not following it following so much. Oh, we need to be because I don't have no idea What's the because it because the dex factor that factors calculated factors calculated layer Technically is if if the factor is more than one Why are we using F the GLS? shader We can't forbidden If it's one we want it Else if thing we don't know yet things changing the color according to that code and otherwise we discard it Give me the dash factor No, it is once for the whole thing Get anything that's more than one is is is just to indicate that hey, we do it Because the line is not dashed like here But can be point five You fully didn't grasp what a hack but let's and this is gonna be how we draw the different How we're gonna draw the different lines because for the data flow just gonna have the dash factor as one to do here and Then by the way dash factor You don't buy these but let's Let's see. That's all so nice So like I should stop it here and share it It's caring. I'm looking at one of the questions. We had in the drumming to know this weather it's to what we call Las Vegas UI it's flickering and changing For instance, if I move my node You're gonna see the this changes a little bit, right? I confess it gets a little bit distracting because if the if the curves are Are not curved For instance, if they're straight line We don't see it so much right here's There's something wrong with the algorithm because in this case one thing at a time The dashes are decreasing over time It's not good. You can see here The spacing is big and here the space is very small of very small But and I assumed it since my curvature is zero The the distance function should be quite accurate and Regardless, it's because from base year the real first points not a real point. This I can also leave her for pet review Honestly, I'm happy with this already Visually, I don't like that Maybe I do like the dash lines the code itself. Let's comment the code a little bit and share it again And this is honestly, I don't worry about Leave the compiler to optimize this even change this to something different just to see how it looks I'm recording something. They're welcome to join. I'm recording a video of me trying to do but We got points But you can see as well how something is not right Yeah, we need to investigate this Maybe it's part of the whole Honestly, that's good enough why I And it's off. Sorry about that. I'm just a second pass on the patch itself just to share That's simple damn. It's beautiful. Copy this again. Let's interact a bit Someone's explaining here. Why about this quishing? Let's Pull the chat a little bit. I Think I will stop this recording right now. This is as far as wanted to go with anyways, I Think I'm rather happy with the solution. I think you're gonna send this as a patch for a prototype That's actually we built and as a proof of concept test Yeah, I really don't like how I think there's something specifically unpleasant about it. I Think I'll send as a pet just to start a conversation on how we do it properly Was the most like one hour so stop it here. Thank you so much for tuning in Have any suggestions or anything you want to add and questions. I know I'm gonna be replying to the third view for some time Bye-bye