Fine tune height generation for hex grids

I am currently working on a small project to have some fun. This is a C ++ WinAPI application using OpenGL.

I hope this turns into an RTS game played on a grid with a hexagon, and when I get the main game engine, I have plans for further expansion.

Currently, my application consists of VBO, which contains information about vertices and heights. A height map is created using the midpoint shift algorithm (diamond square).

To implement a hexagonal grid, I went with the idea described here here . It shifts the odd rows of the normal grid to provide relatively easy visualization of the hexagons without any additional complications (hopefully).

After a few days, it starts to come together, and I added a mouse pick, which is implemented by rendering each hex in the grid in a unique color, and then fetching that mouse position in this FBO to identify the identifier of the selected cell (displayed in the upper right corner of the screen shot below) .

enter image description here

In the next phase of my project, I would like to look at creating more “reproducible” landscapes. For me, this means that the shape of each hexagon should be more regular than the shape shown in the image above.

So, finally, having come to the conclusion, is there:

  • A way to smooth or adjust the vertices in my current method, which would bring the whole point of the hexagon to one plane (coplanar).

EDIT: For anyone looking for information on how to make coplanar points, this is a great explanation .

  • The best approach to procedural landscape generation, which would allow for better control over such things.
  • The way I present information about my top is different, which allows it.

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

here )

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

I hope to get something similar to what I have (relatively beautiful hilly hills and terrain), but with more controlled plateaus. This gives me the flexibility of adding areas (non-playable tiles) later, where I can add more detailed grids if necessary.

Any feedback is welcome, I use this as a training exercise, so please, all comments are welcome!

+4
source share
1 answer

It depends on what you really want and what you mean by “more controlled”.

You want to say: "There will be a mountain at coordinates [11, -127] with a radius of 20"? The complexity of this depends on how far you want to go. If you only need mountains, then enough radial gradients (just add the gradient values ​​to the noise values). But if you need more complex shapes, you can try.

I study this idea at great depths in the project (please think that the published version is just a prototype that is currently undergoing redesign, it is quite possible to use a map generator, though).

Another way to make the generation process more procedural is to simply indicate the sequence of mathematical functions that you apply on the ground. Even a simple transformation of values ​​can lead you very far.

All of these methods should work fine for the hexadecimal grid. If artifacts occur due to an odd line shift, you can interpolate the odd lines instead (just calculate the height value for the vertex from the two vertices between which it is located with a simple linear interpolation formula).

Consider a function that maps a purple line to a blue curve - it emphasizes a lower height as well as a height height, but makes the transition between them steeper (this example is just a cosine function, which makes the curve less smooth makes the transformation more noticeable).

Cosine value transform

You can also use only the lower half of the curve, making the peaks sharper and lower local areas flatter (thereby more reproducible).

Cosine value transform II

The “sharpness” of the curve is easily modulated by power (which makes the effect more dramatic) or square root (reducing the effect).

enter image description here

The implementation of this is actually extremely simple (especially if you use the cosine function) - just apply the function to each pixel on the map. If the function is not so mathematically trivial, lookup tables work very well (with cubic interpolation between table values, linear interpolation creates artifacts).

In this article, you can find several simpler methods of "gamification" of a random noise landscape: " Real-time synthesis of the decomposed fractal surface for use in computer games ."

Good luck with your project.

+3
source

All Articles