uniform sampler2D materialtex;
uniform sampler2D normaltex;
uniform sampler2D colortex;

uniform float backfaces;

varying vec3 gposition;
varying vec3 gnormal;

varying vec3 normal;
varying vec4 color;

void main()
{
	vec3 nnormal=normalize(normal);

	vec2 lightmap_coords=nnormal.xy*0.497+vec2(0.5, 0.5);
	lightmap_coords.y*=-1.0;
	gl_FragColor=texture2D(materialtex, lightmap_coords);
//	gl_FragColor+=color;
	gl_FragColor*=color;

//	if(nnormal.z>0.07) // backfacing
//		gl_FragColor=vec4(0.1, 0.1, 0.1, 1);
	if(backfaces>0.5 && nnormal.z>0.07) // backfacing
	{
		float c=(gl_FragColor.x+gl_FragColor.y+gl_FragColor.z)*0.1;
		gl_FragColor=vec4(c, c, c, 1);
	}
}

