#version 330 core

layout(location=0) out vec4 fragColor;

in vec3 worldNormal;
in vec3 Normal;
in vec2 texCoord;
in vec3 FragPos;

uniform sampler2D color_texture;
uniform vec3 lightPos;
uniform vec3 viewPos;

void main()
{
	vec3 lightColor = vec3(1.0f,1.0f,1.0f).rgb;

	vec3 norm = normalize(Normal);
	vec3 lightDir = normalize(lightPos - FragPos);

	float diff = max(dot(norm,lightDir),0.0);
	vec3 diffuse = diff*lightColor;

	float specularStrength = 0.5f;
	vec3 viewDir = normalize(viewPos-FragPos);
	vec3 reflectDir = reflect(-lightDir, norm);

	float spec = pow(max(dot(viewDir, reflectDir),0.0),32);
	vec3 specular = specularStrength*spec*lightColor;

	float ambient = 0.3f;
	vec3 objectColor=  texture(color_texture, texCoord).rgb;
	vec3 result =(ambient+diffuse+specular)*objectColor;
	fragColor = vec4(result, 1.0f);
}