float interpolate (float z, float lowerBound, float maxRGB){
float scaled = z - lowerBound;
float interval = 63.75;
return (scaled*maxRGB)/interval;
}
void main(){
//Transformation of the object space coordinate to projection space
//coordinates.
//- gl_Position is the standard GLSL variable holding projection space
//position. It must be filled in the vertex shader
//- To convert position we multiply the worldViewProjectionMatrix by
//by the position vector.
//The multiplication must be done in this order.
position = g_WorldMatrix * vec4(inPosition, 0.0);
vec4 pos = vec4(inPosition, 1.0);
gl_Position = g_WorldViewProjectionMatrix * pos;
//________________________________________________________________________
vec4 diffuseColor;
float i;
float alpha = 1;
float interval = 255/4;
int maxRGB_1 = 1;
int maxRGB_255 = 255;
if(position.y < interval){ // blue to cyan
i = interpolate (position.y, 0, maxRGB_1);
diffuseColor = vec4(0, i, maxRGB_255, alpha);
}
else if(position.y < interval*2){ // cyan to yellow
i = interpolate (position.y, interval*1, maxRGB_1);
diffuseColor = vec4(i, maxRGB_255, 1-i, alpha);
}
else if(position.y < interval*3){ // yellow to red
i = interpolate (position.y, interval*2, maxRGB_1);
diffuseColor = vec4(maxRGB_255, 1-i, 0, alpha);
}
else{ // red to dark red
i = interpolate (position.y, interval*3, 0.5);
diffuseColor = vec4(1-i, 0, 0, alpha);
}
gl_FrontColor = diffuseColor;
//________________________________________________________________________