Height Values to Colour RGB

Started by
5 comments, last by jack_bauer_24 17 years, 9 months ago
Hi Does anybody know of a good algorithm for converting height map values to a series RGB values so that high height values are a darker brown colour and lower values are represented as a lighter green and those in the middle represent a transition between the two i've had a small ammount of success but the problem is i end up with a few areas of really stark colours such as pink or bright blue any help or discussion anybody could offer on this would be greatly appreciated. Thanks
Advertisement
It sounds like those stark colours are the right transistions between the colors,.
GBS
Maybe you should calculate colors in a HSV color space, and do a linear interpolation (according to height) of only the H value. That will avoid the bright (stark) colors.
If your interpolation is good, you should get a smooth transition between green and brown - no pinks and blues allowed.

As long as you interpolate each of the R, G and B components separately, this should be fine.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
The more common problem is that the intermediate colors end up too dark. This is easily fixed by introducing gamma correction. If you are getting bright colors in between, you are doing something very very wrong.
Sounds like the weird colors are because you're flooding some bits or something.

The easy way to interpolate between two colors (linearly) is basically

(psuedo code)
blendedRed = red1 * (1 - height/range) + red2 * (height/range);
// repeat for green and blue

where blendedRed is the resultant color for a represented height, red1 is the red source of the color for height=0, height is the current height, range is the maximum height ( 0 to height... maybe 255? ) red2 is the red part of the source color (green?) for the max height (height=range)

since your heights are probably integer heights, you'd be smart to just create a palette type lookup.

e.g.
you have an array of the colors for the representative heights. Iterate through possible height values (0 through 255, for example) filling in the color using the code above. Now the color for a particular height may be easily referenced with something like arrayColor[height]

(blah blah blah blah blah)

-Michael g.

p.s.
By the way, stay away from colors which claim to have 0 red, green or blue. Zero does funny things when applying lighting.
Most "black" objects we encounter in life actually *do* have a diffuse component > 0 since they seem to get brighter when light shines on them (think laser-pointer)
Thanks that explanation helped a lot thats just the sort of thing i was looking for thanks.

This topic is closed to new replies.

Advertisement