Download

Draping algorithm for procedural road generation

I’ve been running into walls for the past week or so on my toy project in UE4. My goal is to draw procedural roads on a procedural landscape (eventually getting to intersections and buildings). The landscape is generated with libnoise and the roads are generated with a slightly modified version of the algorithm found here.

But I’m having issues draping the roads on the landscape and I can’t find any straightforward algorithmic way of doing it. You can see my problem below: the geometry of the road intersects the geometry of the landscape.

In short, given:

  • The landscape index buffer
  • The landscape vertex buffer
  • Every road segment’s X,Y,Z coordinate

How do I modify the underlying vertex/index buffer so that the landscape “wraps around” the roads?

For more context, here’s another screenshot of the problem:

I’ve tried a number of solution, including lowering all vertices in the neighborhood of the road (makes the terrain flat and the road float but placing road back flush to the ground causes the same problem):

“Cutting” all triangles within a distance of the road and trying to re-stitch the mesh:

I’ve run into issues with all these solutions but I know this is a solved problem as literally dozens of games do this. It would be great if anyone could point me into the right direction or at least give me some pseudocode to work with.

Thanks!

Might be of some interest to you: https://forums.unrealengine.com/showthread.php?120610-Terra-Nova-Dynamic-in-game-environment-builder

Hey, Davvv, you emailed me but I am going to answer here so other people can benefit.
The way I achieved that effect in the Terra Nova project is quite straightforward.
First I quickly checked which tiles had a road in them (by using points on the spline and a simple rectangle/circle intersection formula.
After I had all the tiles, I looped through the vertices on that tile and used their distance from the road spline to figure out of they were near the road.
After that, I used a simple fall off formula to create the curved banks you see in my project.
In your case, you might want to tesselate the chunks around the road a bit more, or it will be super tricky to create proper non-intersecting Geo.
Hope that helps, if you have any more questions, let me know.

Hey! Thanks a lot for your reply. I was running into some issues regarding getting bank vertices, but I resolved it last night (vertices on mesh section edges were an edge case I didn’t account for), so now I (at least) have a subset of the verticies of a “road hull”.

I like your solution, but, unfortunately, I can’t tesselate my terrain mesh further as it would degrade FPS. I think my only recourse is triangulating the road hull (Delaunay Triangulation comes to mind), but I was hoping to avoid that kind of complexity. Does anyone know if UE4 supports triangulation out of the box?

You could model the road mesh in a oval shape, like in real life, roads are not flat, they’re a little round, so model the road like and model a piece of terrain around the road as well, like a mound, so the road itself will be elevated from the landscape preventing clipping.