uniform sampler2D spcTex1;
uniform sampler2D spcTex2;
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 rockSample = texture2D(spcTex1,cords);
 vec4 resCol = vec4(rockSample);
 vec4 skyShadowSample = texture2D(spcTex2,gl_TexCoord[1].xy);
 
 vec3 sunPos = vec3(cos(timeOfDay)*0.5+0.5,sin(timeOfDay)*0.5+0.8,-0.5);
 sunPos = normalize(sunPos);
 float lit = max(0.3,dot(-norm,sunPos));
 //lit = pow(lit,13.0);
 
 //resCol+=skyShadowSample;
 resCol.r-=0.2*clamp(timeOfDay,0.0,1.0);
 resCol.g-=0.3*clamp(timeOfDay,0.0,1.0);
 resCol.b-=0.3*clamp(timeOfDay,0.0,1.0);
 
 resCol.r=lit*rockSample.r;
 resCol.g=lit*rockSample.g;
 resCol.b=lit*rockSample.b;
 gl_FragColor = resCol;
}