Sign in to follow this  

Generating HeightMaps

This topic is 3456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently I have a Fractal Terrain generation routine written in OpenGL using glut, but I'm having some trouble figuring out the heightmap concept. I'm testing my terrain with a small 16 element array that will index through it, randomly select a value and randomly scale it within an upper and lower bounds. This works and you get a nice grid filled with peaks and valleys - depending on how I set the scaling values it'll control how steep the peaks get. I've also added away to do the same thing but generate it from a heightmap (or a 2^n sized texture that I pass in - really it doesn't have to be 2^n, but my code will truncate to the closest 2^n value or to a set value by either dropping or reusing the data depending on if your over or under the required value.) So anyways. All of this works and it generates, but the problem is that the texture I pass in, I'm unsure as to how to pull the RGB values out and convert them to useable data. I'm using devIL and while I've tried using uint, float, int - no matter what I do the values just dont seem to scale like they should. So my question is really two fold. One: When you generate a heightmap using a texture (jpeg/gif images ... I'm going to move on to mathematically generated after I get this to work) do you just open up photoshop or something else and just start building something using a gradient and use that as a heightmap or is there some other technique? Two: Once you have your heightmap, whats a good way to parse and scale the values? The terrain fields I'm generating are pretty much any given size, constrained by the heightmap usually, so far I've been doing 128x128 grids with 6 subdivisons per quad. Thanks for any replies/help.

Share this post


Link to post
Share on other sites
I'd use a grey-scale image and save it as 8-bit.

Or just use one color channel, i.e. the red one.

A third solution could be to convert the color information into grey scale, using the following commonly used formula: grey scale = red * 0.3 + green * 0.59 + blue * 0.11.

Share this post


Link to post
Share on other sites
Thanks for the replies, I have just noticed that the data I'm feeding into my buffer are either really big and negative or really small depending on how I tell devIL to convert it. I think I'm going to have to just pass everything around as bytes and just collect every 3 Like Lord_Evil suggested and just use that as a heightmap. Cross your fingers.

Share this post


Link to post
Share on other sites
Much luck.

Another possibility is to use the entire 24 or 32-bit information of the pixel to get smoother heightmaps (more than 255 distinct heights). The problem with this is, that creating heightmaps in a image editor is not easy but if you used a special editor you could save up to 4294967296 distinct heights per hightmap.

Share this post


Link to post
Share on other sites
Basically you'd read them as int or uint and just define the height of each pixel as h = i * scaling (e.g. height = 4500 * 0.1 (m) = 450.0 (m) -> the pixel would have value 4500 which is 17 green and 148 blue in a argb layout).

Share this post


Link to post
Share on other sites
Thanks for the info Evil. I've gotten it to load right and its working as it should I guess. I know its not stellar work, but I'm moderately content that its just working - even though I wish I could figure out how to make real nice LOD Terrain I guess you have to start somewhere - also my texturing skills are, well, non-existent, at any rate this is what the thing looks like.
Basically the algorithm is taking the data from the image, storing it off and referencing it, applying random scaling to allow you to see it generated differently everytime you change how many times each grid splits. I'm just applying the heightmap as a repeating texture just to get a rough idea as to how
its laying down.

4 Splits:

Terrain-Lvl4

5 Splits:
Photobucket

6 Splits:
Terrain-Lvl6

Like I said, its a start I guess...

Share this post


Link to post
Share on other sites
I do have one gripe, that someone can probably help me with,
since I'm using devIL to load the thing I'm having the strangest issue with
ilCopyPixels. In my Terrain class, I'm saving off the heightmap as an
array of ints so I simply have a pointer that's dynamically allocated at runtime. Whenever I try to use ilCopyPixels requesting anything thats not of
type IL_BYTE, i get an memory access exception. It doesnt matter how I convert
or if I do at all, if I don't use byte I get an exception.
The shots above are actually from me casting the raw data to an int after doing the byte conversion, which actually puts out RGB values like I would expect, but I can't get ilCopyPixels to do the same.

To Illustrate:

ilConvert(IL_RGB,IL_BYTE)
...
...
ilCopyPixels(0,0,0,width,height,1,IL_BYTE,data) <---- Works!!!
ilCopyPixels(0,0,0,width,height,1,IL_(ANYTHING),data) <---- Doesn't Work, even if I change the Convert from BYTE to match what I want in the Copy.

Share this post


Link to post
Share on other sites

This topic is 3456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this