uniform sampler2D spcTex1;
uniform sampler2D spcTex2;
uniform sampler2D spcTex3;
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.2*cords.x)*0.01*timeOfDay;
 cords.y+=sin(haze*2.2*cords.y)*0.01*timeOfDay;
 vec4 groundSample = texture2D(spcTex1,cords);
 vec4 lmapSample = texture2D(spcTex2,gl_TexCoord[1].xy);
 vec4 skyShadowSample = texture2D(spcTex3,gl_TexCoord[2].xy);
 
 vec3 light=vec3(0.0,1.0,0.3);
 light = normalize(light);
 float lit = max(0.0,dot(light,norm));
 lit = pow(lit,12.0);
 //lmapSample*=lit;
 
 vec4 resCol = vec4(groundSample);
 resCol.r+=1.5*clamp(timeOfDay,0.0,1.0);
 lmapSample*=skyShadowSample*(4.0-timeOfDay);
 resCol.r *= lmapSample.r;
 resCol.g *= lmapSample.g;
 resCol.b *= lmapSample.b;
 gl_FragColor = resCol;
}