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?
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;
}
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.