uniform sampler2D texture;
uniform sampler2D mask;

uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
uniform sampler2D tex4;

void main()
{
    vec4 textureColor = texture2D(texture, gl_TexCoord[0].st);
	vec4 maskColor = texture2D(mask, gl_TexCoord[0].st);
	
	vec4 tex1Color = texture2D(tex1, gl_TexCoord[1].st);
	vec4 tex2Color = texture2D(tex2, gl_TexCoord[1].st);
	vec4 tex3Color = texture2D(tex3, gl_TexCoord[1].st);
	vec4 tex4Color = texture2D(tex4, gl_TexCoord[1].st);
	
	//gl_FragColor = detailColor*textureColor;//*gl_Color;//*vec4(1,0,0,0.5);
	//gl_FragColor = detailColor*textureColor+(gl_Color/140+vec4(0,0,0,1));
	/*
	vec4 finalColor;
	finalColor = mix(finalColor,tex1Color,maskColor.r*maskColor.a);
	finalColor = mix(finalColor,tex2Color,maskColor.g*maskColor.a);
	finalColor = mix(finalColor,tex3Color,maskColor.b*maskColor.a);
	finalColor = mix(finalColor,tex4Color,1-maskColor.a);*/
		
	float gamma = 1.5;
	float ambient = 0.1;
	float texIntensity = 0.225;
	gl_FragColor = (((tex1Color*maskColor.r + tex2Color*maskColor.g + tex3Color*maskColor.b)*maskColor.a + tex4Color*(1-maskColor.a)+vec4(0,0,0,1)+ambient)*(gl_Color+0.08)+textureColor*texIntensity)*gamma; 
	//gl_FragColor = ((tex1Color*maskColor.r + tex2Color*maskColor.g + tex3Color*maskColor.b)*maskColor.a + tex4Color*(1-maskColor.a))*gl_Color*1.5; 
}