Color Interpolation

I want to change the color of some Cylinders dynamicly.

To do this, I'm thinking of using a color map, such that red corresponds to 0.0 and green corresponds to 1.0 (and hopefully a few other colors between). But moving through color space is moving through 3 dimensions (R-G-B), so a transfer function/interpolation is beyond me.

To reiterate, I need a function that will output RGB based on a float between 0 and 1.

The context of this might be something like a health-meter.

Anyone have any thoughts on how to accomplish this?

Well to be honest I would usually take the easy way and knock something up in an image editor. Get the colour blending looking how I want it and save it as a very thin texture. Then you can either use the texture directly (perhaps use scaling and an offeset if you only want part) or get colour values from it (just x=xsize*interpolation, y=0).



Alternatively just do a really simple function like

r = (255 * interpolation);

g = 255 - (255 * interpolation);

b = 0;

color = new ColorRGBA(r, g, b, 1.0f);



Depends how you want it blended really - I use the texture approach cos you don't have to think about it.

For a simple 2 color change you could just use sin and cos, and I think you could use 'ranges' combined with that to create a bigger paletteā€¦