Website powered by

Procedural Cities For Games Part 3: Arch Bridges in Houdini and Unity

General / 06 December 2019

In the course of my work building out the world for Frameshift, we needed the roads to be able to span various large gaps in the terrain, like rivers and canyons. The causeway bridge generator in the previous post is good for things like overpasses and small bridges, but we needed another solution for large bridges. This is where the Arch Bridge tool comes in.


The Arch Bridge SOP is packaged up as an asset for use on the geometry level inside Houdini, and it is placed inside the Road Mesh Generator tool that was outlined in the last post. As input, it takes a curve that it should build the bridge along and the terrain that the bridge will sit on. It has various parameters to control the look of the bridge:


The first thing I do with the input curve is separate out the ends of the bridge. If you look at references for arch bridges, you'll notice most of them have short curved sections at the beginning and end so that the arch portion of the bridge can be a straight shot. That is what I'm doing here.


Next I start on making the curves for the arches. First I delete the ends (since the arches are only on the straight portion of the bridge), then resample the curve using the number of segments (arches) I would like.


Carve it to get a primitve for each section, and resample so each section has two segments (3 points). The middle point will be used as the apex of the arch.


Next, ray the non-apex points to the terrain that the bridge will sit on. I also make two copies by using Peak to move the arch to the side of the bridge, and another Peak to move it to the opposite side, then merging them back together.


Then resample the segments using "Subdivision Curves" to get the final arch curves.


I resample again using my "pillar frequency" control to get points that I will instance pillars to.


Now that I have all the points and curves that I need, I can start working on the geometry. The roadbed is just a line swept along the original curve, using my roadbed width parameter to control the length of the line.


Using my original resampled curve where I created the arch "segments", I instance large supports that will be at the base of each arch. The vex code below makes sure the bottom of each pillar is aligned to its lowest point (after a ray dropping it to the terrain) so that the bottoms don't stick up above the terrain but remain rectangular.


To create the arch geometry, I sweep a square along the arch curves. My parameter for support thickness controls the size of the square.


I then create small support pillars that go from the arches to the roadbed and between the two arches. This is just standard instancing to points, but I use the roadbed extruded in the negative Y as a bounding box to create a group of points below the roadbed. This group has pillars extending up to meet the roadbed, whereas the "above" group has pillars extending down to meet the roadbed. There aren't any pillars above in this case, but with the control parameters, the arch can be extended above the roadbed as you can see in the animation above. The pillar geometry is also boolean subtracted with the roadbed to cut it off at the proper height.


Here is a shot of a bridge with more pillars to give you a better idea of what is happening:


Next we add railings, using standard copy to points and sweeps. The highlighted vex node is grouping every 10th point (that isn't an end point) into a group called "large" that we will instance slightly larger railings to add some variation.


Next we add supports under the curved start/end sections. This is done by instancing to points, but if the support pillar will be too close to the terrain, it is removed (seen in the vex code below).


Finally we merge it all together for the final output!


Here are some bridges that appear in various locations in-game:




  I even brought one bridge back into Houdini and did an RBD fracture sim to create a broken bridge!


Procedural Cities For Games Part 2: Street and Bridge Meshes in Houdini and Unity

General / 19 November 2019

In the last post I covered how to procedurally generate a city street network, but the result of that was just a bunch of curves in Houdini. Now I'll cover how to generate the road geometry for each of the curves to create meshes for use in Unity. Here are the results from the last post, now in Unity:


First I need to cover how I exchange data back and forth between Houdini and Unity. For the roads, I write a series of points, the road width, and road surface preset to a JSON file. I have created editor tools in Unity to manually edit the roads using Bezier curves, if needed:


There are many tutorials covering how to create a Bezier curve editor in Unity if you google it. Then to bring the data back to Houdini I use a Python node to read the JSON file:

You can see the result of our city street network creation from the previous post, but this time it is being read from a JSON file because it is now coming from Unity, with manual edits already made if needed.

I also import terrains from Unity by reading their raw data. This could probably be done natively inside the HDA now that Houdini Engine has better support for Unity terrains, but I did this before that was added.

Next we create intersections. The main work here is done by the Intersection Stitch SOP but I also use some VEX to extend the roads a bit in case they weren't fully overlapping and I remove short ends to make sure "T" intersections come out correctly.


Next, I create the intersection group using falloff from the intersection point, where the falloff distance is equal to the widest road in the intersection. I then expand that edge group in cases where the angle between two of the roads is less than 45 degrees, to ensure there is enough space between the two intersection ends to create a road mesh of the desired width:

The math in the VEX node is solving for the hypotenuse of a right triangle (we can assume that any individual piece of the intersection is made up of two right triangles) like this:

Since we know the width apart we want the intersection group roads to be ("A" above), and we know the angle "a", we can solve for C to find out the distance we need to expand the intersection group in order to get them the desired width apart.

Next we create bridge groups by separating out sections of road that are more than a certain distance above the ground by using a Ray SOP with "point intersection distance" enabled and "transform points" disabled. Then to create our final curves for sweeping geometry, we Polycut out the intersection and bridge groups so only regular road areas remain.


Finally we start actually creating meshes. The subnetwork that creates the intersection meshes is a modified version of the awesome Solving Intersections tutorial by Dokai. The subnetwork that creates the road geo just sweeps a line and creates UVs. There is a great tutorial for this also, by HoudiniSimon. He covers how to UV a closed curve sweep, but the first part of his tutorial can be applied to open curves as well.

Then I just create some groups to apply materials to using the roadPreset attribute that came in from my curves from Unity. 


Next we create the bridge geometry. The network below basically iterates over all the bridge groups that were created earlier, and based on how high above the ground and how long and curvy it is, it either inserts a causeway bridge or an arch bridge. I'll cover arch bridge creation in a later tutorial, but the causeway bridge uses the cool Gamedev Sweep Geometry SOP with start and end groups enabled to sweep pre-made bridge geometry along the bridge curve.

The result:

These bridge meshes are comprised of hand modeled start/end/middle sections and are deformed and duplicated along the curves using the Gamedev Sweep Geometry SOP as mentioned above. This is what the hand modeled geometry and groups look like:

The center group is highlighted and the ends are in groups "bridgeStart" and "bridgeEnd" that are used by the sweep geometry node.

We wrap it up by doing a little extrude to create a roadbed that will have a gravel texture on it, and we do a few booleans to certain road types where they overlap. For example if a dirt road intersects a highway it is clipped off.


Finally we save all of our geometry out for use in Unity and additional Houdini tools. We split the road meshes into smaller chunks and export them as FBX, and we save out .bgeo files for some other stuff so we can use the data later.


And in Unity:

I hope you enjoyed this overview of the process of creating road geometry in Houdini. In the next post I'll cover creating the road markings (paint) and flattening the terrain to conform to the roads. This is for the game Frameshift, check it out and sign up to alpha test if you want!

Procedural Cities For Games Part 1: Street Networks in Houdini and Unity

General / 05 November 2019

For my work on the post apocalyptic survival game Frameshift, I need to populate a very large open world with diverse cities. We only have a team of 3 people so I'm using the procedural power of Houdini, of course! 

Before I discovered Houdini, I even wrote some procedural mesh generation tools in Unity using C#. It was very slow to add features and once I discovered that Houdini was tailor made for this kind of task, I made the switch. I have experimented with a few different methods for generating cities and streets, and over the course of this series of posts, I'll outline the methods I ended up using for the final product.

First off, I created a tool to generate a street network like one that would be used in a city. My approach is based on the concepts shown here and the paper it is based on (linked on that page). There is a lot of talk about tensor fields and eigen vectors and it all gets very technical - but the gist of it is: for my case (generating a road network on terrain), I needed to generate terrain contour lines, and their perpendicular counterparts.

I start off with a terrain, and with a little help from an example from Houdini Gubbins, I generate vectors on each terrain point that point toward the contour and the gradient lines using VEX:


The yellow vectors visualize the contour lines.

Next we need to create a city street grid and mix the vectors from that with the vectors that follow the natural curves of the terrain. This will create a city street grid-like area that mixes nicely with the surrounding terrain. Here we're placing a grid onto the terrain, then polyframing it to get normals along the grid lines, adding a falloff to blend nicely, and finally setting a new contour vector that is a mix of the two:


Above you can see that inside the bounds of the rectangle, the contour lines now run in a more grid-like fashion. I also do a similar process to optionally add influence from existing hand-placed roads that are already in the game. I also expose a slider in the Unity HDA so that the influence can be tweaked for more naturally flowing streets, or more grid-like streets within the bounds of the city.

Next I convert the vector fields to VDBs so they can be sampled from to create the final roads:

 You can get a cool visualization using the volume trail SOP:

Here it is a lot easier to see what the final roads will do. And with the perpendicular vectors visualized too:

It's starting to look like a grid of streets! A bit too close together, but the general shapes are there. Next we do a lot of sampling from the velocity VDBs, and a lot of vex to create the final road lines. The vex code basically properly spaces out the roads and ends them if they get too close to other roads or too long:

Then finally we do some post processing to smooth things out, delete small sections, extend close ends to make realistic intersections, and drop the roads to the terrain. The final result can be seen here:

There are still a few unrealistic areas, but a little manual clean-up in Unity is acceptable for the amount of time this saves laying out cities. In my next post, I'll give a breakdown of how I generate actual city street geometry from these lines. Hope you enjoyed reading! Alpha sign-ups are now open for Frameshift, have a look and sign up now!