2
votes

I have a program where I need to represent height as an RGBT (in float) value. That is:

[R, G, B, T (Transperancy)] -> [0.0f-1.0f, 0.0f-1.0f, 0.0f-1.0f, 0.0f-1.0f]

Conceptually I know that you can encode via basic height between max and min height. I even have some code for greyScale height encoding:

double Heightmin=0;
double Heightmax=23;

osg::Vec4 getColourFromHeight(double height, double alpha=1.0) {

    double r=(height-Heightmin)/Heightmax;
    double b=(height-Heightmin)/Heightmax;
    double g=(height-Heightmin)/Heightmax;
    return osg::Vec4(r, g, b, 1.0);
}

What I would like to know, is if there is an algorithm that's more complex then just using R and G like this:

double r=(height-Heightmin)/Heightmax;
double b=0.0f;
double g=(Heightmax- height + Heightmin)/Heightmax;

(That is, the G is the inverted form of R, so at low values it will appear more green and at high values it will appear more red.

I would like to be able to utilise R G and B to give realistic looking hieght encoded landscapes:

enter image description here

This is an image of a 72dpi RGB height encoded topographic map. I would like to be able to achive something similar to this. Is there a simple algorithm to create an RGB value based on a minimum and maximum hieght?

Thaks for your help.

Ben

1
You just need to come up with a suitable colour gradient that you like, and then put it in a lookup table (or similar).Oliver Charlesworth
That sounds like a good idea but would it be suitable when considering the max and min height will be changing in the final code?Fantastic Mr Fox
Are you sure that that image is only height encoded? Seems to me like it's a combination of geographical and topographical data.Robert Mason
That isn't an image of my work, I was hoping to clarify the question by showing what sort of thing i wanted. You are correct though, water is shown as blue etc.Fantastic Mr Fox

1 Answers

2
votes

You just need to come up with a suitable colour gradient that you like, and then put it in a lookup table (or similar).

Then all you need is something that will map a value in the range min_height -> max_height into the range 0 -> 255 (for example).

Of course, it's possible that you will find a colour gradient that can be expressed as mathematical functions, but that's less general.