uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;

varying float interpf;
varying vec3 normal;
varying vec3 lightDir;
varying float dist;

void main ()
{
	// Kombiner teksturer
	float interpfc = min(interpf, 1.0);
	vec3 interptex = vec3(texture2D(texture4, gl_TexCoord[1].st));

	vec3 firstFrag = vec3(texture2D(texture1, gl_TexCoord[0].st));
	vec3 secondFrag = vec3(texture2D(texture2, gl_TexCoord[0].st));
	vec3 thirdFrag = vec3(texture2D(texture3, gl_TexCoord[0].st));

	float interpfa = 1.0 - interpfc;
	//vec3 combined = vec3((interpfa*firstFrag.r)+(interpfc*secondFrag.r), (interpfa*firstFrag.g)+(interpfc*secondFrag.g), (interpfa*firstFrag.b)+(interpfc*secondFrag.b));
	
	vec3 combined = vec3((firstFrag.r * interptex.r) + (secondFrag.r * interptex.g) + (thirdFrag.r * interptex.b),
			     (firstFrag.g * interptex.r) + (secondFrag.g * interptex.g) + (thirdFrag.g * interptex.b),
                             (firstFrag.b * interptex.r) + (secondFrag.b * interptex.g) + (thirdFrag.b * interptex.b));
	

	// Belysning. Vi dropper spekulærbelysning for terreng, det ser ikke naturlig ut.

	//float ambient = 0.5;
	//float diffuse = max(dot(vec3(0.33, -0.33, 0.33), normal), 0.0)*2.5;
	

	gl_FragColor = vec4(combined, 0.0);
	
	//gl_FragColor = vec4((combined.r * ambient) + (combined.r * diffuse), (combined.g * ambient) + (combined.g * diffuse), (combined.b * ambient) + (combined.b * diffuse), 0.0);
}