#ifdef GL_ES
precision mediump float;
#endif
uniform vec3 u_LightPos;
uniform sampler2D u_tex0;
//uniform vec3 u_AmbientMat;
//uniform vec3 u_Spec;
//uniform float u_Shininess;

varying vec3 v_normal; // mediump
varying vec4 v_colour; // lowp
varying vec3 v_vertex;
varying vec2 v_texture;

void main()
	{
		
	vec3 u_AmbientMat = vec3(0.1,0.1,0.1);
	vec3 u_Spec = vec3(1.0,1.0,1.0);
	float u_Shininess = 60.0;

	vec3 N = normalize(v_normal);
	vec3 L = normalize(u_LightPos - v_vertex);
	vec3 E = vec3(0, 0, 1);
	vec3 H = normalize(L + E);
	float df = max(0.0, dot(N, L));
	float sf = max(0.0, dot(N, H));
	sf = pow(sf, u_Shininess);

	/*if(df < 0.1) df = 0.0;
	else if(df < 0.3) df = 0.3;
	else if(df < 0.6) df = 0.6;
	else df = 1.0;

	sf = step(0.5, sf);*/

	//vec3 colour = texture2D(u_tex0, v_texture).rgb * v_colour.rgb;
	//colour = colour * df + sf * u_Spec;
	vec3 colour = u_AmbientMat + df * v_colour.rgb + sf * u_Spec;
	gl_FragColor = vec4(texture2D(u_tex0, v_texture).rgb * colour, v_colour.a);
	//gl_FragColor = vec4(colour, v_colour.a);
	}