47 lines
894 B
GLSL
47 lines
894 B
GLSL
#version 440
|
|
|
|
in vec3 f_color;
|
|
out vec4 FragColors;
|
|
|
|
struct Light {
|
|
vec3 Position;
|
|
vec3 Color;
|
|
};
|
|
|
|
uniform Light lights[64];
|
|
uniform int NLights;
|
|
|
|
in vec3 fNormal;
|
|
in vec3 pos;
|
|
|
|
in vec2 texCoord;
|
|
uniform sampler2D tex;
|
|
|
|
uniform vec3 view_pos;
|
|
|
|
void main()
|
|
{
|
|
vec3 finalColor;
|
|
vec3 diffuse_sum;
|
|
vec3 specular_sum;
|
|
vec3 ambient;
|
|
|
|
vec4 texColor = texture(tex, texCoord);
|
|
//Hardcoded ambient
|
|
ambient = texColor.rgb * 0.1;
|
|
for (int i = 0; i < NLights; i++)
|
|
{
|
|
vec3 L = normalize(lights[i].Position.xyz - pos);
|
|
vec3 N = fNormal;
|
|
vec3 V = normalize(view_pos - pos);
|
|
vec3 H = normalize(V + L);
|
|
|
|
vec3 diffuse = lights[i].Color * texColor.rgb * max(dot(L, N), 0.0);
|
|
vec3 specular = lights[i].Color * pow(max(dot(H, N), 0.0), 16.0) * 0.5;
|
|
diffuse_sum += diffuse;
|
|
specular_sum += specular;
|
|
}
|
|
|
|
FragColors = (vec4(ambient + diffuse_sum + specular_sum, 1));
|
|
}
|