Procedurally Generated Road Networks and Intersections

So I’ve put in a few weeks of work into a procedurally generated world map. It was way, way harder than I expected and I ended up spending well over two weeks with little usable output (a major setback with my timeline). The environment that I’m trying to make is something like mount blade, or a sid meier’s pirates (only on land), so an environment with maybe 50 or so cities, towns and villages.

Part of the problem is that I’m trying to generate a realistic ‘feeling’ road network between these locations and a single large road mesh.

Generating a single road segment mesh against a spline is pretty simple, but road intersections and branches sort of have me stumped.

The easiest method (given the code that I’ve already worked out) would probably be running a constrained delaunay triangulation against the outline of the road, with branches represented by 5 points (one constraining the forked area, and 2 bordering the ‘pre fork’ road, one on either side of the fork constraint). So even using this method (the ‘easiest’) will actually be quite difficult.

Another method, perhaps, would be simply generating each road as a discrete segment against a spline then somehow merging them at the end. In this case I can simply use Unity - Scripting API: Mesh.CombineMeshes - the problem being that the textures will… intersect at intersections. So if my road has some kind of outline, it’ll look like a mess when roads connect…

Am I missing something? Is just generating a simple, rule bound triangulation for intersections achievable by someone with a limited math background?

Is this stuff really that specialized and difficult?

I bit the bullet and purchased superspline since it had special “spline junction” support… sadly, it just uses a shared point for multiple spline meshes, so texturing roads at intersections is just as much of a problem. EasyRoad3d seems to have actual support for junctions, but I’m concerned that it has limited api support (and is really intended to be used visually).

Is this stuff actual rocket science?

It’s surprisingly hard, but also fun. :slight_smile:

Here’s where I’m at with mine.

1 Like

I got a bunch of other stuff for the world generation logic… but here is where I currently am with the mesh generation for spline intersections.

I’ve got some number of splines that share a common key vector (in the attachment, all 4 splines share a common start/end). Then I generate a set of vertices for the intersection (currently a separate mesh) then I clip out the road vertices that fall within the intersection.

the uv mappings are super simple at the moment, but you can see that at least the texture for the individual road segments and the intersection blend properly - and you don’t have weird edges…

There’s still some work left with the uv map, and there are some bugs with the vertex removal logic, but it’s coming along I guess.

1571290--93090--$road_far.png
1571290--93091--$intersection.png

1 Like

Looks really good! Those nearly parallel intersections are a pain. I haven’t got to mesh generation yet but my roads are stored much like yours are, except I use a list of segments between endpoints instead of splines.

So I’m almost done with this. The UV map is a bit smarter.

I added y coords based on terrain height.

I copied a shader from easyroads because otherwise the mesh was bleeding into the terrain too much.

The result is pretty close to what I was looking for. But so far this has taken almost 4 days, way longer than I could afford :stuck_out_tongue_winking_eye:

1 Like

and finally, after a long, difficult labor … the uv’s are perfect. a dream realized.
…a dream… that took way too f’n long.

man, it sure would be nice if someone said, “hey wow thats awesome!”

2 Likes

That’s pretty cool, awesome work!

…What are you gonna do for streetlights?

Streetlights? Screw off!! :smile:

Anyway, so I spent a bit longer on this and I wrote my own shader (from scratch!). It was my very first shader!

Here is the AWESOME result!

1 Like

Everything is awesome!

Looks great! I’m still picking away at city street layout generation.

Don’t suppose there’s any chance you could put a demo project up? Currently struggling with a very similar problem!

Yeah, well done! Looks awesome!

Been 4 years now, but oh well. Like someone else requested, sharing a demo project would be amazing!

sorry man, that code is long gone.

It’s funny seeing this post from four years ago. Roads, roads, my life for good roads.