Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

PoC of mountain ridges, hex map

This is one of few approaches I've tried to make good-looking mountains for hexagonal terrain map. If you are interested in others, please, let me know. Any comments/requests/suggestions are welcome.

Brief
The whole approach is based on Ridges. Ridge is fancy name for undirected graph. If we have group of N "mountain" hexes we can choose N points from each of them. Then we can create M (M < N) ridges by connecting N points in some order. Some trivial order will be presented below

Single tile
r1-r2 is just a line elevated at some point along Z axis. We want to make 3D shape from a line and flat hexagon. Let's calculate height of every point inside hexagon as linear interpolation from border level (assume it 0 in this post) and r1-r2 level (assume it Ridge level). R is radius of excircle, r - radius of incircle

Top view

Side and top views:

Side and top views

Let's render this idea. First picture does not include perlin noise, second - does include. Black line is ridge. Size of triangle in mesh is R/28.
 

Two tiles

Nothing really interesting, same concept. "No Perlin noise" version is below. There are 3 points in ridge, middle point is slightly displaced.

With noise:

We need more tiles

Let's look at group of tiles:

If we look at "border" tiles - all except C5, C6 - it's easy to calculate distance from every point inside of them to nearest border: there is formula of distance between line and point. If we look e.g. at point X, we can't calculate distance to border using tile C6 itself. We use information from neighbours: 

  1. Find nearest corner point of neighbours. Let's call it A
  2. distance_to_border(X) = distance(A, X) + distance_to_border(A)

So, for every point now we know distance to nearest border and distance to nearest ridge point (ridges are set by us). How can we arrange tiles in groups? By using Disjoint set union

Next question, how we can decide which tile will be water tile, which - hill and which - mountain, etc? By using any algorithm which may be used to generate terrain: e.g. diamond square or Perlin noise. We calculate max and min of all heights and set thresholds. First, lets call amplitude = max - min. Next, let's assign water threshold = [0.0, 0.1] of amplitude, mountain - [0.9, 1.0] of amplitude. If we increase 0.1 -> 0.2 there will be more water tiles, if we decrease 0.9 -> 0.8 there will be more mountain tiles.

Finally, recall that we "know all ridges coordinates". But how? Surely, there is a lot of approaches how to set them. First I tried DLA algorithm but with no success. I'll show trivial made up algorithm. Let me remind, that at this point we know everything except positions of ridges. Algorithm is the following:

  1. Sort mountain tiles: less neighbours first, more - last. E.g. C0 has 2 while C6 - 6 neighbours.
  2. Basically, it's kind of "two pointers" solution. Set "left" pointer to first element of sorted array, right - to last element
  3. Make move from "left" tile to "right" tile and each iteration choosing randomly between not visited neighbours.
  4. Move "left" to next element, "right" to previous element until "left" != "right".

Let me show short illustration.

Concluding remark

We used Perlin noise to make shape more realistic. By using different set of parameters it's possible to make unnatural - but still pretty shapes. Compare pics below:

Final results:


Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.