uniform sampler2D spcTex1;
uniform samplerCube spcTex2;
uniform sampler2D spcTex3;
uniform sampler2D spcTex4;
varying vec3 eyeVec;

varying vec3 tangent;
varying vec3 biNormal;
varying vec3 normal;

varying vec3 lightVec;
void main(void)
{
	
	vec3 normalN = normalize(normal);
    vec3 viewVec = normalize(eyeVec);
	vec2 newTCoord=vec2(gl_TexCoord[0]);
	vec4 value = texture2D(spcTex1,vec2(newTCoord.x,newTCoord.y));
	vec4 valueDirt = texture2D(spcTex4,vec2(newTCoord.x,newTCoord.y));
	
	vec4 nmap = texture2D(spcTex3,newTCoord.xy);
	
	
	vec3 lightVecz = normalize(vec3(0.0,-0.6,0.1));
	lightVecz=normalize(lightVec);
	
	vec3 nLight;
	//normalN.x = dot(tangent,nmap.xyz);
	//normalN.y = dot(biNormal,nmap.xyz);
	//normalN.z = dot(normal,nmap.xyz);
	float lightFactor = min(1.0,dot(nmap.xyz,lightVecz));
	vec4 value2= textureCube(spcTex2,reflect(-viewVec,nmap.xyz))*0.4;
	//lightFactor = min(0.1,dot(normalize(normal),lightVecz));
	lightFactor = clamp(lightFactor,0.0,1.0);
	//value.r=1.0;
	float spec = lightFactor;
	
	spec = pow(spec,12.0);
	spec=0.4;
	vec4 tangCol=vec4(tangent*0.5+vec3(0.5,0.5,0.5),1.0);//
	//value.xyz=vec3(1.0,1.0,1.0);
	gl_FragColor =(value+value2+valueDirt*0.4)*(lightFactor+spec);
}

