

#version 450 core


/**
Bind points for different SSBOs
*/
#define DIRECT_LIGHT_SSBO_BIND_POINT 3

/**
transparency
*/
#define SMALL_EPSILON 0.001

/**
The direct global light
*/
struct DirectLight {
    vec3 direction;
    vec3 color;
};


out vec4 FragColor;

layout(std430, binding = DIRECT_LIGHT_SSBO_BIND_POINT) restrict buffer dirLightSSBO {
    DirectLight directLight;
};

struct Material {
    sampler2D diffuse;
    sampler2D specular;
    float shininess;
}; 


in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoord;
in vec4 FragPosLightSpace;

uniform vec3 viewPos;
uniform Material material;

//texture stuff
// uniform sampler2D ourTexture;
uniform int hasTransparency;
// uniform sampler2D specularTexture;

//light depth map
uniform sampler2D shadowMap;

// function prototypes
float calcLightIntensityTotal(vec3 normal);


void main(){
    if(hasTransparency == 1){
        if(texture(material.diffuse, TexCoord).a < 0.1){
            discard;
        }
    }
    vec4 textureColor = texture(material.diffuse, TexCoord);

    //grab light intensity
    vec3 norm = normalize(Normal);
    vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));

    //calculate final color
    vec3 finalColor = textureColor.rgb * lightIntensity;
    FragColor = vec4(finalColor, textureColor.a);
}

float calcLightIntensityAmbient(){
    //calculate average of ambient light
    float avg = (directLight.color.x + directLight.color.y + directLight.color.z)/3.0;
    return avg;
}

//
float calcLightIntensityTotal(vec3 normal){
    //ambient intensity
    float ambientLightIntensity = calcLightIntensityAmbient();

    //sum
    float total = ambientLightIntensity;
    return total;
}