#version 400 core

uniform sampler2D Texture;

in vec4 FogParam;
in vec3 InterpNormal;
in vec2 InterpTexCoord;
in vec3 InterpViewDir;
in vec3 InterpLightDir;

out vec4 Color;

void main(void)
{
    
    vec4 color = texture( Texture, InterpTexCoord );
    
    // discard fragments with small alpha (alpha testing for leaf texture)
    if (color.a < 0.5) discard;

    // Normalize and calculate vectors needed for light computation
    vec3 Normal = normalize(InterpNormal);
    vec3 ViewDir = normalize(InterpViewDir);
    vec3 LightDir = normalize(InterpLightDir);
    vec3 Reflection = reflect(LightDir, Normal);

	//Calculate basic phong lighting
	float Diffuse = clamp(dot(Normal, LightDir), 0.0, 1.0);
	float Specular = pow(clamp(dot(Reflection, ViewDir), 0.0, 1.0), 4);
	
  	Color = mix( color * ( 0.5 + Diffuse + Specular ), FogParam, FogParam.w );
}
