Jump to content
  • Advertisement
blackbeen

Concerning terrain heightmaps

Recommended Posts

Hello,

I'm curious as to how one calculates position coordinates for the terrain; specifically the height coordinates. My understanding of Terrain generation with height maps is iterating through the heightmap and retrieving pixel data. The pixel data, depending on its greyscale color (white or black), will determine its height. However, I'm unsure of the practical implementation of this, specifically the equation used to convert pixel data to new height coordinates. 

In addition to the Y coordinates, how do I determine the values in the X and Z plane. Do I just pick a range of values (ex. [-30, 30]) in X and Z?

Lastly, I'm sure indices will have to be used in order to make an efficient program. My prior experience with Index is manually entering values for simple geometric shapes (Cubes and triangles). This seems more involved than before. I was wondering if there exists an algorithm that handles indices when dealing with terrain.

Share this post


Link to post
Share on other sites
Advertisement

First, keep in mind that it's not required for the 'y' axis to be the vertical axis. It's fairly common in this sort of context to use 'z' as the vertical axis. This can be more intuitive because it makes the xy plane the ground plane. But this is entirely up to you of course (unless you're constrained for some reason, e.g. by the tools you're using).

Computing the height coordinates involves mapping values from one range (e.g. [0, 255] to another, which is fairly straightforward mathematically (conceptually it can be done by converting the original values to normalized values, and then using those normalized values to compute the final values in the desired range).

As for the ranges, that's up to you. The only thing I'd mention is numerical precision. For the ground plane especially, centered ranges (like the [-30, 30] example you posted) might be preferable to alternatives (such as all geometry in the positive quadrant) as precision is more evenly distributed over the environment, and smaller values might be preferable to larger ones for precision reasons as well. However, whether any of that would make any practical difference depends on the circumstances (it very well may not).

Quote

Lastly, I'm sure indices will have to be used in order to make an efficient program. My prior experience with Index is manually entering values for simple geometric shapes (Cubes and triangles). This seems more involved than before. I was wondering if there exists an algorithm that handles indices when dealing with terrain.

The indices can be generated procedurally. There are other ways, but a straightforward way to render a grid mesh would be using individual indexed triangles. The procedure for generating such indices is fairly straightforward.

Edited by Zakwayda

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!