// Fragment Shader for normal mapping experiments – file "texture_norm.frag"

#version 150 core

uniform sampler2D in_texture;
uniform sampler2D normal_Map;

in vec2 fragment_texcoord;
in vec3 texture_Light;
in vec3 texture_Eye;

out vec4 out_color;

void main(void)
{
	float diffuse_intensity;
	float specular_intensity;

	vec3 light;
	vec3 normal;
	vec3 eye;
	vec3 reflection;

	light = normalize(texture_Light);

	normal = normalize(texture(normal_Map, fragment_texcoord).xyz * 2.0 - 1.0);
	normal.y = -normal.y;	//Left handed to right handed space - 
	//because most normal maps are generated for direct x - difference between direct x and opengl
	eye = normalize(texture_Eye);

	//diffuse part of the surface
	diffuse_intensity = clamp(max(dot(normal, light), 0.0), 0.0, 1.0);
	//reflective part of the surface
	reflection = normalize(reflect(-light, normal));
	//specular part of the surface
	specular_intensity = pow(clamp(max(dot(reflection, eye), 0.0), 0.0, 1.0), 0.0);

	//get the out_color
	out_color = vec4(0.0, 0.0, 0.0, 1.0) + vec4(0.0, 0.0, 0.0, 1.0) + 
		texture(in_texture, fragment_texcoord) * diffuse_intensity +
		vec4(0.0, 0.0, 0.0, 1.0) * specular_intensity;


}
