// learnopengl.com
#version 330 core

layout(location=0) out vec4 fragColor;

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


uniform vec3 viewPos;

//material information
uniform sampler2D color_texture; // diffuse map
uniform sampler2D specularMap;
uniform float shininess;

//zu löschen spaeter anfang
uniform vec3 ambientFactor;
uniform vec3 diffuseFactor;
uniform vec3 specularFactor;
//zu loeschen spaeter ende

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

void main()
{
    // Ambient
    vec3 ambient = ambientColor * vec3(texture(color_texture, texCoord));
  	
    // Diffuse 
    vec3 norm = normalize(Normal);
    vec3 lightDir = normalize(lightPos - FragPos);

    float diff = max(dot(norm, lightDir), 0.0);
    vec3 diffuse = diffuseColor * diff * vec3(texture(color_texture, texCoord));  
    
    // 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 * vec3(texture(specularMap, texCoord));
        

    fragColor = vec4(ambient + diffuse + specular, 1.0f);  
} 