 Howdy guys, Andy Pixel here, and in this video we are going to take a look specifically at how we produce bridges. All right, so we've kind of covered roads a little bit. Most notably the guardrails with the curvature video. This time what we're going to do is we're going to look at how to produce the proper curves to produce bridges here all procedurally. So if I were to go and move this curve around, you can see that my entire environment here is actually updating. So all the guardrails are updating, but the bridge is also updating as I move the curve around to accommodate the terrain at that level. So what we're going to do is learn how to produce the proper data to produce a bridge from curves. All right, so let's get started. Okay, so let's get started by building our terrain and bridges here. So we're going to start with the terrain, but I'm just going to put this all inside a one geo container here. So I'm going to drop down a height field, and I'm going to change the size here to 200 by 200. Just make it small. We don't need a large terrain for this. And then I'm going to go and drop down a height field noise node like so. And I'm going to pick a noise that I like. So I went with something around 600 for the amplitude and about 129 for the element size. And you can play around with the roughness a little bit. Really depends on what you're looking for. That's going to be good. And then let's go and create a height field clip node. And for this one, I want to kind of set where the bottom of the terrain is. And so I'm just going to use a min clip for this. So this allows me to actually clip the terrain off. So this is basically going to be where all the water is for this particular landscape. And then I want to do another clip. And we need to make sure that we get the height field clip node. There we go. And I want to clip off the tops here. So you can also hit the compute range and then just kind of move your way down from there. I really just want to create these kind of flat toes like so. And then what I like to do is go back to the noise here and actually pick a location. For this guy, I used a negative 77 and negative 89 for the location of the noise, which gives me a nice place to put a bridge. That's really what I was looking for there. And we can bring this down even more. I really want kind of a flat top, something like that. Looks pretty good. You can also play around with these clip strengths here and the soft clip strength and we get a deeper channel going there. Looks pretty good. All right. Then I'm going to do a mask clear. I don't need that mask anymore. And then I want to go and do a height field distort. So let's get a distort node. Stort by noise. There we go. And I just want to go and just kind of rough it up a little bit. Make it look more interesting. More terrain like looks pretty good. All right. And then I'm going to do a visualize. And I'm not going to get all fancy with the visualization in this particular video here. Just want to get something. So I'm just going to do a compute range. And I'm going to get rid of all these color knots here just by clicking and dragging them. And I'm going to make this more of like a darker mud type color. And then we're just going to come over here and do kind of a nice terrain green. And I'm going to go and plant these guys here. So we get a harsher transition. Looks pretty good. All right. So I'm going to select all these guys, hold down a on the keyboard and then left click and drag upwards to organize those guys. I'm going to drop down a new grid. And this grid now needs to match the size of this particular guy. So I'm just going to copy this parameter, go down to the grid here, paste that into the size option here. So now we have a grid that's the same size. And this is going to act as my water plane. So I'm just going to drop down a color node and we're going to go and give it a nice water type color. And then let's just merge the two guys together here by selecting both hold down alt left click and drag off of the not there for the output. See that one more time. There we go. And now I've got a pretty nice setup there for terrain that we can use. And the color here doesn't seem to be coming through all that great. It's picking up a little bit of the terrain colors there. Let's just go and drop down an attribute create node. And what I'm going to do is call this alpha. I'm going to give the water a little bit of transparency. I'm going to put it at 0.5. We go. That will work for our terrain. So I'm going to go and drop down an all node. We'll call this out terrain. All right. So with that done, let's put a net box around this stuff here. So I'm just going to select all the nodes, do a shift O. And we're going to call this step one. Call this create terrain and give it a color by hitting C on the keyboard and selecting the black swatch there or whatever color you want. Now we are ready to go and create our bridges. One thing we can do is make this a little higher res. So let's go up to our height field node up here. And in the grid spacing, let's do something like 0.75. There we go. So now we've got much higher res terrain there. All right. So let's take a look at calculating the bridges from a single user curve. So let's drop down a curve node here and this guy is going to be our user curve. So if you're building an HDA, this will be exposed to the actual HDA. So it can be edited in like the Houdini engine or outside of this particular geo node. And then I'm going to go down and hold down my alt control and left click and that will template this. And then I can draw on top of my terrain. So if I hit space bar two and hit enter on the keyboard in the scene view here and we'll just draw some sort of like road like thing. Something like that looks pretty cool. All right. I want my curve here to actually sit on top of the terrain so I can cast right down and snap this to the terrain. And so to do that, I like to go and drop down a transform node just in case the user curve comes in with values that are in Y. And I just put the scale to 0 in Y and that flattens it out. And then we can use a match size node. So let's drop down a match size node and let's feed in an object for the second input here. So I'm going to drop down an object merge node. And this is going to be called get terrain. And I'm just going to feed in my terrain here. So let's just drop this guy down here like so. And yeah, let's pipe this guy into here. Very cool. You can see the match size node will actually take into account the second inputs geometry bounding box size. So we can then use the justify and set this to max so that the curve is sitting right on top of the terrain there. All right. So at this point, I'm going to resample the curve and I'm going to start out with a high value. So I'm going to do something like a four for this. And then I want to make sure I turn on my subdivision curves. You can see here if I turn on my point display, we have a good resampling for this particular road here. And I'm going to start with larger values just because we're going to work our way down to smaller values as we get more detail going here. All right. So then we want to go and snap this to the terrain. So I'm going to call this guy snap to terrain. And for the second input here, I'm going to feed it the terrain there. And for this, I'm going to utilize the volume sampling trick that I showed you guys in a video a little bit ago. And so this is the code right here. So you can copy that. I just saved it as a preset. So that way I don't have to type it over and over and over again. All right. So now we're snapped to the terrain perfectly. You can see that it missed the water because this particular technique here is only looking for volumes in our height fields, our volumes. What we need to do now is we need to go and figure out how we get the curve to be above the terrain here. Right. And so to do that, we're going to be doing some blurring. And so I need to go and drop down a group by range node here and just group the ends. You can also do it with becks as well. But I'm going to do it with a group by range node this time. Let's go to points and we'll set our start and end to one and one and we'll invert it. And that will go group just the end points there, which is perfect for us. All right. So at this point, I need to go and drop down a polyframe node. And this time I'm going to type in a capital N for the tangent. You can also save a preset for that. So you can see I have a couple here. All right. And that will create for us our flow normal. And then finally we want to go and get our slope here. So I'm going to call this get slope because what I want to do is I want to find the areas that have really high slopes in here. And what that will allow us to do is it'll allow us then to blur those areas, which will actually lift this portion of the curve up. These areas over here don't have a high slope. And so they won't generate any sort of bridges or anything like that. So let's do this in order to do this. If you haven't seen the path slope reduction video, I highly recommend watching it. I'm going to call this a new vector of flat norm and it's going to be equal to the current normal, which is our flow normal. And then for that flat norm, I'm going to set its y component to zero. And then we're going to normalize it just so we have a unit length of one. So we're going to say normalize. And we're going to say flat norm. And then to get the actual slope in degrees, I'm going to create a new attribute called slope by typing in F at attributes stands for a float type of attribute. And we're going to say degrees. And we're going to get the art cosine of the dot product of the current normal and our flat norm. That will give us our slope in degrees there. And then you type in dot for this guy. I missed one. There we go. Beautiful. All right. So now we have our slope. Now one way you can actually visualize this is you can utilize the visualizers here. You've probably seen that I've used the visualize node over here by just creating a node or you can also select node and hit X on the keyboard. All right. Or you can come over here and you can right click on this little guy. And you can say I want to create a new visualizer by hitting this plus button right here. And I want to create a new marker. And for this, I want to go and look at that slope value. So I set the class to points because it's on the point class. And I just want to set it as a marker. So now we have really quick access to our visualizer. So you can see that we have all of our slope values here. And you could see the area where there should be a bridge, we have some pretty high slopes. So it's a pretty good way to find all this stuff. Now if you want to turn off the visualizer, just right click this and just turn off the little check mark. So a little bit faster than using the visualize node. All right. So now we've got the slope going there. I want to go and find the maximum slope that we have. So let's go and do an attribute promote. So I'm just going to go and type this in here. We're going to do max slope. And we want to go from point because currently our slope attribute is on the point class. Let's go from point to detail. We want to take the slope. And we want to get the maximum value. Let's change that new name. Let's call this max slope. And let's make sure not to delete the original there. All right. So with that done, let's go and drop down attribute remap node. And this remap node is going to remap our slope into a value of zero and one. All right. So let's go and select the remap node there. And our original is going to be slope. Our destination or new name is going to be slope as well. So we're just going to override it. And then what I want to do is I want to get the maximum value from this attribute promote. So to do that, we're going to type in detail zero for the first input and the remap node only has one input. So that'll work. And we want to get the max slope. And we want to get the first index of that because it's just a single flow value. So now we've got that maximum value. And if I were to go and look at the slope now, so let's turn on our marker that we made, you can see that we have a value that goes from zero to one, depending on our max slope values. All right. So we can use that now. Let's go and blur this. And let's actually, let me show you really quickly. Let's un-template our terrain here. Let's go back to our marker by right clicking on it. And then we can go and edit the marker now by hitting the little pencil icon right here. Let's actually change it to a color. And let's close this guy out and turn off our point displays. So now you can see where our slope is the most intense, which is right around where the bridge should be, which is great. So we're going to then blur that value. So I'm going to say blur slope. And we are then going to type in slope for the attribute to blur. We're going to turn off pin border points. And you can see now, as I move this guy, that the visualizer will update. So you can see, it's kind of hard to see, but there you go. So I'm going to set this up to something like, oh, I don't know, 200. Actually, let's do 50. 200 is probably going to be a bit much. I'm going to set the step size to one. So that just gives us a really nice gradient. All right. Very cool. What we can do with that value is we can drop down another attribute blur node and we can then blur the position. So I'm going to use that slope value as a weight attribute. So let's type that into the weight attribute. So what's going to happen in the blur node is it's going to use that zero to one value, our slope value, and it's going to blur it more intensely where our slope is more intense. All right. So let's go and do that. I'm going to set this one up to about 200. And we are going to turn off our pin border points. And we also want to make sure you can see that when I move this slider, it's actually moving our end point. So I want to say not ends up here or exclamation mark ends that will pin our end points to where they were originally located. So now I'm just going to set this to something like 200. All right. So if you can see now, if I were to template my original curve, you can see that the greatest changes in the curve appear right around where the bridge should be. And these other guys would be tunnels basically, based off of some sort of height threshold. All right. So cool. Now we've got our curve that we want to use. So I'm going to drop down our wrangled node. And this one is going to be to set the y pause. I really am just interested in the y position of this curve. And I want the x and z positions of this curve. All right. So that's what we're going to do here. So to do that, we're just going to create a new vector called other pause. And we're going to make that equal to a point expression or point function that is looking at the second input, it's going to get its p attribute. And we're going to look it up by its point number. Because both these curves are the exact same point numbers, that'll work. All right. So at this point, let's resample this now. Let's go down to a lower sampling rate. This time I'm going to do something like one. This will just give us more detail to work with. And let's also make sure we turn on our subdivision curves. The other thing I forgot to do, let's actually set the p dot y up here to our other pause dot y. There we go. So now you can see we retain the x and z position, but use the y position from this curve that was, that has been blurred out. So now we need to go and find out the height from the terrain that a certain part of the curve is at. All right. So to do that, I'm going to go and grab my terrain. I'm going to drop down a another object merge node. You could always come up here and just copy this guy and drag it down here. So do an all left click drag. So now I have my terrain over here. And let's template it by holding down control and left clicking the template flag. We'll take a look at our curve here. All right. So I need to go and sample the terrain and figure out the heights from each point to our particular curve there. All right. So to do this, I always turn to my trusty vex. All right. So we're going to say find height and for this, just like what we did up here for the snapping to the terrain, we're going to do a volume sampling because you can see that we're returning the height. So we basically want to just copy this same set of code here for the vex. And we want to paste it into there. But this time, I don't want to actually set the height to the curve. I want to keep this particular portion of the curve. This time, what I want to do is I want to say f at disk to create a new distance attribute that lives on each point. And I want to then go and subtract the current points position from our height that we just sampled. And then you make sure this is a period there. We're going to negate that. And then finally, I'm going to colorize this just so we can visualize this particular distance value. So I'm going to say at dist. So if at this is less than negative one, let's just start there. So three feet, then we want to basically give it a color of red. So let's do one, zero, zero for red. Else, we want to just color green. That'll just be a road area. So I'm just going to go and pump that in there. Go and voila, we now know if I were to template my terrain again, turn off my point display, you can see everywhere where a bridge will be considered. Right. So you might have a little tiny bridge there. You might have a little tiny bridge there. You can always get rid of those guys and only take the really long ones. All right. So now we know where all that stuff is. All right. So we know what bridge is going to go right here. And this has a potential for being a bridge. At this point, then what we need to do now is break off these sections of the curves from the green area. So we want to get just the curve that are all red and just the curves that are all green. All the green curves will be the roads and all the red curves will be the bridges. So to do that, I'm going to use a convert line and we're going to convert all of these into individual segments or primitives here. Perfect. So I don't need to keep the wrestling. So I just turn that off and I'm going to then go and promote my color value. So I'm going to do attribute promote. We're going to promote this from points to our primitive because we now have individual primitives per segment. You can see it creates a nice clean value, but it is actually producing like a yellow value. So I do want to go and get just the first match. So now we have a very clear cut between those two guys. So at this point, I'm just going to drop down a split node and we're going to use a little expression. We're going to say at cd.r is greater than zero. And that'll leave us with just the bridge curves. Just for good measure, let's set this to primitives. And now what we can do is drop down a null node and we can say out bridge curves and then left quick and drag with Alt held down and say out road curves like so. I'm just going to drag these guys down because we're not done yet. Remember all these particular curves here are still broken up in individual segments. So I don't want that. And so all we need to do is just drop down a fuse node and a polypass node. And that will turn them back into single primitives per curve there. And then finally, we're going to need a value for these so we can loop through each one of these guys. And currently we have this prim number that identifies each bridge segment by itself. But I need to actually create a ID value for this. So primitive, all I'm going to do is just go and write a little tiny back here. I'm going to say I at ID is equal to at prim them. This will help us when we drop down a couple for each loop nodes and start working on the individual segments. So different bridges here, because you could end up having different types of bridges for the overall distance that it's actually traveling like this one would be a really big bridge. And this one would be a really small bridge because remember it's based off of its distance value. All right, and let's just do the same thing for the roads. And there we go. So now we've got our bridge curves, and we've got our road curves. Last step here is just to select all the nodes, do a shift, oh, and we will then go and call this step to find a bridge curves, and then give it a little color. Tend to go for the black, very nice. All right, so now we've got all that data. You're pretty much good to go. All we need to do is drop down a couple sweep nodes and then build our bridges. And we'll have some roads and bridges. And so after a couple of hours, this is what I came up with. So I literally just started with these bits of data and the terrain. So I did just a couple of things, you know, for the terrain, for the water. In order to get this nice cut out, I just used a Boolean. So I just took the original terrain and an extruded version of the water and then just Booleaned it out and then just remeshed it to get a nice mesh out of that. And then moving on. This was the final terrain right here. So nothing awesome to look at there. It's just really basic. And then for the road. So in this case, I took both curves, the road curve and the bridge curve. I also made sure to put an attribute blur onto the actual bridge. So that way it's nice and flat. I also went up here and removed all the small bridges. So to do that, you would just drop down a measure node and find the perimeter and then go and delete all the small bridges. And then you could do something else with them after that. Maybe they're just like a retaining wall type of structure. So yeah, then I ended up with the roads. And then we got my final bridges, which I didn't really spend a ton of time on. This is just really basic version of the bridge. Added some foliage, just like so. I'll just using a scatter node. Nothing really complex or anything like that. I'll make a walk through the nodes here. So I brought in the terrain, just added some point normals, created a really basic mask, used a mask from geometry node to mask out where the path was. And then scattered it on using that mask value as my density for the scatter points. And then just copied some stuff to it, some really basic low poly models. And then I created the foam. So for the foam, I use the ab seam. So if you come over to the Boolean node over here, I output the ab seams and then that allows me then to go and extract those particular curves with the edge group to curve node. So you get those guys and then I just peeked it out and then create two more lines there and then just do the sweep with a random p scale on it. And then you gave me something nice and stylized there, which I was going for. Then finally the guard rails, which we saw a couple videos ago in the Procedure Modeling Tips video series. And then that is that. Ended up with this guy. Turned up pretty cool. I like it. And then I also went and set up a basic karma render here for this. Nothing crazy either. All materials are all just principle trainers. And there we go. So this file is available to all the patrons on the Unipixel Patreon page. If you're interested, definitely go check it out. And so yeah, that is how we do bridges. There's at least one way to do bridges. You know, with Udini, there's a hundred different ways, thousands of different ways to do things. So hopefully you guys like that technique. And thanks much.