5
\$\begingroup\$

I'm working on generating terrain on already generated landmass. The landmass and ocean around it consist of hexagons. Hexagons aren't really a concern for me, because I can always interpolate the values algorithms generates with the vertices on the grid. As you can see on the image below, blue is ocean, brown is land.

enter image description here

Problem is, I need the shore to have 0 height, can it even be done with diamond square algorithm?

\$\endgroup\$
  • 5
    \$\begingroup\$ By "the shore" you mean only the hexagons directly touching the sea? That's quite relevant for the problem at hand. Because if your answer to that is a yes, then my suggestion would be: why not only detect the land hexagons that touch the the blue ones? \$\endgroup\$ – MAnd Nov 27 '15 at 21:44
  • 1
    \$\begingroup\$ What's a diamond square algorithm? Do you mean a hex grid? Where is their height defined? \$\endgroup\$ – Anko Nov 27 '15 at 23:36
  • 1
    \$\begingroup\$ Shore are indeed the brown hexagons that are touching the blue ones. I can define height of every such vertex as 0. Question is, how do I generate heightmap with some variation of diamon square algorithm for the rest of the vertices? \$\endgroup\$ – user1617735 Nov 28 '15 at 13:28
  • 1
    \$\begingroup\$ I'm sure one can make a modified version of diamond-square that works for hexagonal instead of square tiles, but that seems irrelevant to this question as you have noticed yourself ("[not] really a concern for me"). The problem seems to be you want to use a heightmap generation algorithm while predefining the height for specific vertices. I have to ask: Why the requirement of needing to work on a predefined landmass? Why can't you derive land and ocean cells after heightmap generation? \$\endgroup\$ – Eric Nov 30 '15 at 16:37
  • 1
    \$\begingroup\$ @Anko Wikipedia has a decent overview of the Diamond-square algorithm. \$\endgroup\$ – Roflo Nov 30 '15 at 17:30
1
\$\begingroup\$

Diamond square algorithm works with random height add-on.

One thing you could do is to make a map that will give limits to these random numbers for each part of the map.

This map will have very low to null values in the sea region and on the shore. This map will allow higher values in other parts of the map.

You will then preserve the random generation and have realistic shores.

If you let low values in the sea side, you'll even be able to generate little random private islands ;)

\$\endgroup\$
0
\$\begingroup\$

Diamond Square doesn't work well with hexagons, but you did say you have a way around that with interpolation. You can seed the shore line with 0 and default the other heights to something else. During the process, don't generate the heights that are already 0.

Would that work?

\$\endgroup\$
  • \$\begingroup\$ As far as I understand how the algorithm works, it can cause problems. The algorithm starts with 4 seeded values at corners. I can ofcourse seed some points inside, but when I reach those points during one of algorithm's steps, the calculated value there may differ vastly, causing weird peaks. I may be wrong though, hope I am :) \$\endgroup\$ – user1617735 Nov 29 '15 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.