Tweaking Heightmap Generation For Hexagon Grids
Asked Answered
D

1

4

Currently I'm working on a little project just for a bit of fun. It is a C++, WinAPI application using OpenGL.

I hope it will turn into a RTS Game played on a hexagon grid and when I get the basic game engine done, I have plans to expand it further.

At the moment my application consists of a VBO that holds vertex and heightmap information. The heightmap is generated using a midpoint displacement algorithm (diamond-square).

In order to implement a hexagon grid I went with the idea explained here. It shifts down odd rows of a normal grid to allow relatively easy rendering of hexagons without too many further complications (I hope).

After a few days it is beginning to come together and I've added mouse picking, which is implemented by rendering each hex in the grid in a unique colour, and then sampling a given mouse position within this FBO to identify the ID of the selected cell (visible in the top right of the screenshot below).

enter image description here

In the next stage of my project I would like to look at generating more 'playable' terrains. To me this means that the shape of each hexagon should be more regular than those seen in the image above.

So finally coming to my point, is there:

  • A way of smoothing or adjusting the vertices in my current method that would bring all point of a hexagon onto one plane (coplanar).

EDIT: For anyone looking for information on how to make points coplanar here is a great explination.

  • A better approach to procedural terrain generation that would allow for better control of this sort of thing.
  • A way to represent my vertex information in a different way that allows for this.

To be clear, I am not trying to achieve a flat hex grid with raised edges or platforms (as seen below).

here)

I would like all the geometry to join and lead into the next bit.

I'm hope to achieve something similar to what I have now (relatively nice undulating hills & terrain) but with more controllable plateaus. This gives me the flexibility of cording off areas (unplayable tiles) later on, where I can add higher detail meshes if needed.

Any feedback is welcome, I'm using this as a learning exercise so please - all comments welcome!

Dryad answered 22/12, 2012 at 20:15 Comment(0)
U
3

It depends on what you actually want and what you mean by "more controlled".

Do you want to be able to say "there will be a mountain on coordinates [11, -127] with radius 20"? Complexity of this this depends on how far you want to go. If you want just mountains, then radial gradients are enough (just add the gradient values to the noise values). But if you want some more complex shapes, you are in for a treat.

I explore this idea to great depth in my project (please consider that the published version is just a prototype, which is currently undergoing major redesign, it is completely usable a map generator though).

Another way is to make the generation much more procedural - you just specify a sequence of mathematical functions, which you apply on the terrain. Even a simple value transformation can get you very far.

All of these methods should work just fine for hex grid. If artefacts occur because of the odd-row shift, then you could interpolate the odd rows instead (just calculate the height value for the vertex from the two vertices between which it is located with simple linear interpolation formula).

Consider a function, which maps the purple line into the blue curve - it emphasizes lower located heights as well as very high located heights, but makes the transition between them steeper (this example is just a cosine function, making the curve less smooth would make the transformation more prominent).

Cosine value transform

You could also only use bottom half of the curve, making peaks sharper and lower located areas flatter (thus more playable).

Cosine value transform II

"sharpness" of the curve can be easily modulated with power (making the effect much more dramatic) or square root (decreasing the effect).

enter image description here

Implementation of this is actually extremely simple (especially if you use the cosine function) - just apply the function on each pixel in the map. If the function isn't so mathematically trivial, lookup tables work just fine (with cubic interpolation between the table values, linear interpolation creates artefacts).

Several more simple methods of "gamification" of random noise terrain can be found in this paper: "Realtime Synthesis of Eroded Fractal Terrain for Use in Computer Games".

Good luck with your project

Underclassman answered 23/12, 2012 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.