• Advertisement
Sign in to follow this  

Height Values to Colour RGB

This topic is 4250 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

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement