uniform sampler2D texture;
uniform bool useTexture;

varying vec4 vertex;
varying vec3 normal;

//show standard lighting
void main()
{	
	vec3 lightVec = vec3(0.5, 8, -5) - vertex.xyz;
	lightVec = normalize(lightVec);

	//gl_FragColor = vec4(0.0, 0.0, 1.0, 0.5);
	if(useTexture)
		gl_FragColor = texture2D(texture, gl_TexCoord[0].st);
	else
	{
		gl_FragColor = gl_FrontMaterial.diffuse; 

		gl_FragColor *= clamp(dot(normal, lightVec), 0.0, 1.0);

		vec3 R = normalize(reflect(-lightVec, normal));
		float cosTheta = max(0.0, dot(R, normalize(-vertex.xyz)));

		gl_FragColor += vec4(0.5)*pow(cosTheta, 6.0);
	}
}