Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

RGB value encoded from height

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

Upvotes: 2

Views: 2576

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272507

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.

Upvotes: 2

Related Questions