Hello all,
I’m developing a shader to render a graphic so I’m trying to make specific heigths (position.y) of specific colors.
I’ve ran into a problem, the heights go from 0 to 255 and I’ve devided this into 4 groups of height that are a gradient between different colors. Example: values between 0 and 63.75 have colores between (0, 0, 255) and (0, 255, 255).
I have very abrupt transformations between strips:
[ATTACH=CONFIG]193[/ATTACH]
The Vertex shader (the part about diffuse color):
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;
//________________________________________________________________________
In the Fragment Shader I just have:
vec4 diffuseColor = gl_Color;