30

I should say paths, not roads as I'm thinking more medieval-like. Also, not looking for realism. The answer I'm looking for will be to fit into the mold I describe rather than realism.

I am looking for a method to generate procedural roads/rivers in a curvy sort of fashion, but I'm wanting to do so for a infinite terrain type system. Just like how perlin noise generates blobs, I'm wanting to generate random length line segments (possibly infinite length).

I'm aware of strategies like the suggested answer found here, however it relies on a specified start and end point to work, I don't have a specified start and end point. I'd like to be able to simply call a function using arbitrary coordinates and have it return whether the specific coordinates are part of the river/road.

I am not wanting to require terrain to be generated in advance. That includes a heightmap (like used for rainfall simulations or similar). I would also not want to require a start/end point.

Is there such an algorithm or tweak to a noise algorithm someone might know of to accomplish what I'm trying to explain?

The closest I've came to so far is multi-ridged fractals, if I'm using the name properly. I'm just taking the absolute value of value noise (assuming it is scaled to -1 to +1) and setting a threshold. My primary issue with this is the lines overlap way too often, are mostly circular, sometimes converge to form large lakes which is neat but undesired, and often times the thickness of the lines vary too much.

Here's a picture of what I have so far in 2D, but at a very high frequency to show more detail:

enter image description here

Mythics
  • 1,496
  • 2
  • 20
  • 32
  • since rivers "flow" it could be easy to determine rivers by simply using noise to determine the point of origin, after that simply use your raw heightmap data to determine path. – War Jul 17 '13 at 18:16
  • roads could be a bit more challenging though, I considered building roads based on use, if a player / all players regularly walked over some terrain it would become path. – War Jul 17 '13 at 18:17
  • I believe the problems with the links and method explained is that they require pregenerating some amount of data. The difference I'm referring to is similar to comparing perlin noise and midpoint displacement. Perlin noise, you use an algorithm where you can pick any point and get a value. Midpoint displacement, you have to have a predetermined grid size to use it at all (or merge multiple 'grids' together to get contiguity). – Mythics Jul 17 '13 at 18:23
  • Those strategies work on an incremental basis too. – House Jul 17 '13 at 19:33
  • I may be missing something obvious, so please forgive me if I am, but the possible duplicate as an example already has a starting point and end point they are wanting to displace the line between them. I am wanting something that doesn't require a start/end point or already generating a portion of the heightmap to then simulate rainfall. Similar to how perlin noise generates near-infinite random 'blobs', I want to generate near-infinite random 'squiggles'. Not seeking realism here. – Mythics Jul 17 '13 at 21:57
  • @Byte56 Sorry for the double comment, but I didn't tag you in the first and only just now added a description to the OP of what I have, a picture of it, and a description of what I dislike about it. – Mythics Jul 17 '13 at 22:59
  • Not sure if this may help, but I think this sample uses random generated number and interpolates them with catmull rom. The result is nice: http://www.mvps.org/directx/articles/catmull/ – Gustavo Maciel Jul 17 '13 at 23:05
  • 1
    @user19142 OK, not a duplicate then. You may find some use from this question/answer as well: http://gamedev.stackexchange.com/questions/53400/cave-generation-with-perlin-worms And I'll include the previous links again as "related" http://gamedev.stackexchange.com/questions/45403/algorithms-for-rainfall-river-creation-in-procedurally-generated-terrain?rq=1 http://gamedev.stackexchange.com/questions/29044/how-can-i-generate-random-lakes-and-rivers-in-my-game?lq=1 http://gamedev.stackexchange.com/questions/31263/road-river-generation-on-2d-grid-map – House Jul 17 '13 at 23:32
  • 4
    I think roads will not be very believable if generated with noise. Roads are created by intelligence instead of by physics and time. While they may resemble each other at times, they're different enough that you likely couldn't use the same algorithm for both. – House Jul 17 '13 at 23:39
  • My vision may be quite flawed, but if multiridged noise worked out, I would 'flatten' the terrain's height nearer the threshold value while generating purposeful structures on or near the roads (more like paths than road really). I doubt I can use the same algorithm too, but for rivers I could probably just use the algorithm I have with some slight modifications. Either way, I'm having quite a bit of fun just playing with it and would probably learn my lesson best if I implement something first hand and see that it sucks :P – Mythics Jul 17 '13 at 23:56
  • http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/ <-- you can use filtered perlin noise to generate land vs ocean and then use a variation of this, maybe. – Sean Middleditch Jul 18 '13 at 00:43
  • 1
    The roads in that project were contour lines that followed specific heights, so you could possibly generate them locally. It worked there but the height maps not generated with Perlin noise. – amitp Jul 18 '13 at 01:15
  • I really don't have much to contribute, but if I get this straight:
    1. You know how to do it with a start and end point, but you don't want it to be like that since you don't know them? How about you make the terrain with a start and end point and once the player reaches a certain place on the map you create a new piece of random terrain with the same principle? I realize this might not solve your problem, but if you are short on time it might be the way to go.
    – Bloodcount Jul 24 '13 at 06:14

4 Answers4

12

Just my idea to archive this what you want without (much) precomputation and the possibility for an infinite world.

The first pice of the algorithm is the usage of Voronoi-Diagramms. You divide your world into grids, each grid does have an adress in the form (xgrid, ygrid). For each cell in which you need to create roads you put the xgrid and ygrid variables into a hash function which returns a number CellSeed. You use CellSeed as the seed for a random number generator which generates the coordinates of the points for the Voronoi Diagramm.

Now you need to search the edges of the diagram and the nodes where multiple edges collide. You can also store the information into a graph for more easy access.

After this step you can search paths through the network which are valid.

For valid paths you can now create the roads (they do have sharph edges).

Note: You also need to generate the coordinates of the Voronio diagram for all neightbor cells so you don't have borders on the edges of the cell.

If you don't want sharph edges you can calculate the middlepoint of each connection and use the direction as a tangent for a bezier interpolation between two edges in the graph.

About the usage of Voronoi-Diagramms

To archive city like road structures the points from the pseudo random function can be aligned on a grid, so the ways are rectangle shaped.

For more county like roads the points have to be more unordered.

diagramm from wikipedia

About the Pseudo Random function to generate the positions of the points for the Voronoi-Diagramms

It can be a normal random function or a Hammersley set for a more uniform non-clumpy distribution of the points.

Quonux
  • 1,235
  • 1
  • 12
  • 19
  • Do you have any examples of hash function? I've got the same goal (infinite world which uses voronoi for roads) but I can't seem to get a handle on how this should be done. Every voronoi lib I can find expects coordinates of a bounding box which immediately defeats the purpose. – BotskoNet Oct 01 '16 at 01:53
  • No, the hash function is just for assigning a startseed to the cell. Can be something as trivial as x * prime1 + y * prime2 + z * prime3. Where the primes are unequal to each other and ideally large, you should calculate here with 64bit integers/unsigned. Its not a problem if the lib uses a bounding box, because for each cell you just have to consier all points in the cell plus all points of the neighborhood cells (which are 8 neighborhood cells). – Quonux Oct 01 '16 at 19:39
  • You will propably run into precision issues with single precision if the lib uses single precision or if you use single precsion. To bypass the problem if the lib just uses single precision and you don't do as follows: Before converting the positions to single precision subtract the global position of the center cell from them, then put this as floats into the lib, then transform the results back. – Quonux Oct 01 '16 at 19:43
  • I actually never implemented this algorithm but the hash function can be indeed an trivial one. – Quonux Oct 01 '16 at 19:44
8

For road (and city) creation, the best paper I found is this one :

Procedural Modeling of Cities by Y Parish and P Müller

This uses L-System and it can generate US and EU road patterns. If you don't want to generate roads for a whole city, you can just generate the main roads. It can take a height map, a water map and a population density map in input.

Rak
  • 106
  • 2
  • +1 just because I liked the paper. Really didn't fit in with how I'm wanting to attempt to generate the roads/paths/rivers WHILE dynamically generating the terrain. – Mythics Jul 23 '13 at 01:00
6

http://vterrain.org/Culture/Roads/ section "Generating 3D Roads" has some information on road generation.

The problem with roads is that they connect landmarks (although they often follow the terrain instead of going straight from A to B).

Personally, I'd generate the terrain, then place rivers (maybe using erosion, see http://vterrain.org/Water/ section "hydrogeology"), then place cities in places where it makes sense (e.g. near a river or other source of water, or in a place where water could be transported to using aqueducts or water towers and pipes) and finally generate roads between cities.

To make this more easy to use in a procedural world, you could create intermediate points on the terrain where roads would be most likely to go when generated in that place, then connect the intermediate points if a road is actually created in that place.

Exilyth
  • 1,438
  • 10
  • 18
4

First, rivers and roads are very different. Roads tend to follow isolines (same/similar elevation) - the reason being it is much easier to travel on roads that don't rise or fall much. Rivers, on the other hand, travel perpendicular to isolines/isoclines (downhill). Rivers form in basins (collections of mountains that all flow downwards to a given valley) and tend to form tree-like structures. Additionally, roads often travel perpendicular to rivers, in order to form logical bridges. Best idea is to first generate rivers, and then create logical roads (i.e. roads between cities). I don't have time to go into more detail unfortunately but hopefully this will get you on the right track.

It might seem obvious, but look at Google maps at various types of terrain and roads; you will get a better sense of how they should look.

Gavan Woolery
  • 1,990
  • 1
  • 13
  • 12
  • 1
    I modified the question again to make it more understood that I am not interested in realism anywhere near as much as I am in the way the algorithm would need to work. I do appreciate the answer nonetheless though mostly for some of the terms used. Try to think of my desire more like infinite random length squiggles able to be generated with minimal data needed (like height map). – Mythics Jul 24 '13 at 03:26