varying vec4 TexCoord;
varying float fogFactor; 


uniform sampler2D colormap;
uniform sampler2D shadow;
uniform sampler2D color;

uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
uniform sampler2D tex4;
uniform sampler2D tex4_height;
uniform sampler2D tex4_normal;
//uniform sampler2D tex5;


varying vec3 lightDir;
varying vec3 halfVector;

uniform float Strength;
uniform float nighta;



void main(void)
{
  vec2 TexCoord0 = vec2(TexCoord[0],TexCoord[1]);
  vec2 TexCoord1 = vec2(TexCoord[2],TexCoord[3]);

  // vec2 TexCoord0 = vec2(TexCoord[0],TexCoord[1]);
  // vec2 TexCoord1 = vec2(TexCoord[2],TexCoord[3]);
   vec4 a1 = texture2D(colormap, TexCoord1.st).rgba; // szinterkep
   vec3 sd = texture2D(shadow, TexCoord1.st).rgb; // arnyek
   vec4 ct = texture2D(color, TexCoord1.st).rgba; // color
   vec3 d1 = texture2D(tex1, TexCoord0.st).rgb;
   vec3 d2 = texture2D(tex2, TexCoord0.st).rgb;
   vec3 d3 = texture2D(tex3, TexCoord0.st).rgb;
   vec3 d4 = texture2D(tex4, TexCoord0.st).rgb;
   vec3 h4 = texture2D(tex4_height, TexCoord0.st).rgb;
   vec3 n4 = texture2D(tex4_normal, TexCoord0.st).rgb;

   
   
   
   
   
   
   
   // BumpMapping ======================================================
   /*
   vec3 h = normalize(halfVector);
    
   float height = texture2D(tex4_height, TexCoord0.st).r;
   height = height * -0.03 + 0.04;
   vec2 newTexCoord = TexCoord0.st + (height * h.xy);
  
  
   vec3 n = normalize(texture2D(tex4_normal, newTexCoord).rgb * 2.0 - 1.0);
   vec3 l = normalize(lightDir);
    
   float nDotL = max(0.0, dot(n, l));
   float nDotH = max(0.0, dot(n, h));
   float power = (nDotL == 0.0) ? 0.0 : pow(nDotH, gl_FrontMaterial.shininess);
    
   vec4 ambient = gl_FrontLightProduct[0].ambient;
   vec4 diffuse = gl_FrontLightProduct[0].diffuse * nDotL;
   vec4 specular = gl_FrontLightProduct[0].specular * power;
   vec4 cc = gl_FrontLightModelProduct.sceneColor + ambient + diffuse + specular;
    
   gl_FragColor =  texture2D(tex4, newTexCoord);*/
   
  
   
   
   
  
   
   
   
   
   //gl_FragColor.rgb = d1;

   vec3 finalColor = ((d1*a1.r + d2*a1.g + d3*a1.b)*a1.a + d4*(1-a1.a))*(sd*2*(nighta+0.3))*(ct);
   
   gl_FragColor.rgb = mix(gl_Fog.color, finalColor, fogFactor );
   
   //gl_FragColor.rgb = (((d1*a1.r + d2*a1.g + d3*a1.b)*a1.a + d4*(1-a1.a))*(sd*2)) * gl_Fog.color.rgb;
   
   //gl_FragColor.rgb = vec3(1,0,0);
   //gl_FragColor.rgb = 
   //              ((d1 * a1.r * (1.0 - a1.g) * (1.0 - a1.b) + d2 * a1.g * (1.0 - a1.b) + d3 * a1.b + d4 ) /
   //              (a1.r + a1.g + a1.b - a1.r * a1.g - a1.r * a1.b - a1.g * a1.b + a1.r * a1.g * a1.b) *a1.a)*(sd*3);
 
}

