#version 330 core

in VS_OUT {
	vec3 fragmentPosition;
	vec2 textureCoordinate;
	vec3 normal;
} fs_in;

!include types.glsl
!include constants.glsl

layout(std140) uniform LightInfo {
	Light lights[MAX_LIGHTS];
};

uniform int numPointLights;
uniform int numDirectionalLights;
uniform int numSpotLights;

uniform Material material;

uniform vec3 cameraPos;

out vec4 color;

const float gamma = 2.2;

!include lightcalc.glsl

void main() {
	vec3 normal = normalize(fs_in.normal);
	vec3 viewDir = normalize(cameraPos - fs_in.fragmentPosition);

	vec3 result = vec3(0.0);

	for(int i = 0; i < numPointLights; i++) {
		result += calcPointLight(lights[i], normal, fs_in.fragmentPosition, viewDir, fs_in.textureCoordinate, 0.0);
	}

	for(int i = 0; i < numDirectionalLights; i++) {
		result += calcDirectionalLight(lights[numPointLights + i], normal, viewDir, fs_in.textureCoordinate, 0.0);
	}

	for(int i = 0; i < numSpotLights; i++) {
		result += calcSpotLight(lights[numPointLights + numDirectionalLights + i], normal, fs_in.fragmentPosition, viewDir, fs_in.textureCoordinate, 0.0);
	}

	color = vec4(pow(result, vec3(1.0 / gamma)), 1.0);
}
