#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 viewPos;

//material information
uniform vec3 ambientFactor;
uniform vec3 diffuseFactor;
uniform vec3 specularFactor;
uniform float shininess;

//light information
uniform vec3 lightPos;
uniform vec3 ambientColor;
uniform vec3 diffuseColor;
uniform vec3 specularColor;

void main()

{
	//vec3 lightColor = vec3(1.0f,1.0f,1.0f).rgb;
	
	//ambient 
	vec3 ambient = ambientColor* ambientFactor;

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

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

	//specular
	vec3 viewDir = normalize(viewPos-FragPos);
	vec3 reflectDir = reflect(-lightDir, norm);

	float spec = pow(max(dot(viewDir, reflectDir),0.0),shininess);
	vec3 specular = specularColor*(spec*specularFactor);

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

}