Height Map Coloring

Hi!

I’m having some problems writing an algorithm to give me the color of a certain vertex depending on its height.

The goal is to generate a landscape colored using a smooth gradient starting from blue and passing through other colors until red.

The problem is I dont get a smoth transition between color. Maybe this is a problem of normalization…

Does anybody knows an algorithm to do this?

Thanks a lot

are you using a smooth shading model

Yes, that’s working ok… the problem is how to assign the correct colors to vertices.

With two colors there is no much problem, because it is linear. But using more colors, the RGB values will vary depending on the height at the same time.

I was wondering if some of you have already been through this problem…
Is there any trick or something?

Thanks

The following is untested, so I didn’t test it, but it should work. You use this code for each heightvalue that means for each vertex. Then it shouldn’t be a problem to add further color levels.

#define MAXHEIGHT 255

if(heightvalue >= 0 && heightvalue =< 128) {
// interpolate between (1.0f, 0.0f, 0.0f) and (0.0f, 1.0f, 0.0f)
green = heightvalue / 128.0f;
red = 1.0f - green;
blue = 0.0f;

} else if(heightvalue > 128 && heightvalue <= 255) {
// interpolate between (0.0f, 1.0f, 0.0f) and (0.0f, 0.0f, 1.0f)
red = 0.0f;
blue = (heightvalue - 127) / 128.0f;
green = 1.0f - blue;
}

This is the perfect application for a 1D texture. The 1D texture defines the color gradient for your height map. This works very well…

yep, a 1d texture is perfect for this. the only thing though is you have to be very careful about choosing the colors for the texture. they have to blend into each other in a natural fashion. i have a decent 32-element 1d texture that goes from green to yellow to a red/brown to white. it looks nice when applied to terrain. i can email it to you if you want.

Thanks for your help, I’ll try both methods.

SThomas, I would like to see this texture. Thanks for offering.

My e-mail is noah_iv@zipmail.com