uniform sampler2D spcTex1;
uniform float timeOfDay;
varying vec3 normal;
varying vec3 eye;
varying float height;
void main()
{
 //generate a slight texture distortion based on time of the day and 
 //horizon.
 
 //we messure horizon by shooting eye vector and 
 //the more angle it has, the less haze we apply.
 
 vec3 norm = normalize(normal);
 vec3 horLine=normalize(eye);
 float haze = 1.0-dot(norm,horLine);
 haze =  abs(height)/4998.0;
 haze=1.0-haze;
 haze = pow(haze,7.0);
 vec2 cords = gl_TexCoord[0].xy;
 cords.x+=sin(haze*2.4*cords.x)*0.002*timeOfDay;
 cords.y+=sin(haze*2.4*cords.y)*0.002*timeOfDay;
 vec4 skySample = texture2D(spcTex1,cords);
 vec4 resCol = vec4(skySample);
 resCol.r-=(0.4-haze*0.02)*clamp(timeOfDay,0.0,1.0);
 resCol.g-=0.4*clamp(timeOfDay,0.0,1.0);
 resCol.b-=0.4*clamp(timeOfDay,0.0,1.0);
 gl_FragColor = resCol;
}