47 lines
895 B
GLSL
47 lines
895 B
GLSL
#version 440
|
|
|
|
in vec3 f_color;
|
|
out vec4 FragColors;
|
|
|
|
uniform vec3 Kd;
|
|
uniform vec3 Ka;
|
|
uniform vec3 Ks;
|
|
uniform float Shininess;
|
|
|
|
struct LightInfo {
|
|
vec4 Position;
|
|
vec3 Intensity;
|
|
};
|
|
|
|
uniform LightInfo Light[64];
|
|
uniform int LightCount;
|
|
|
|
|
|
in vec3 fNormal;
|
|
in vec3 pos;
|
|
|
|
void main()
|
|
{
|
|
|
|
vec3 finalColor;
|
|
vec3 diffuse_sum;
|
|
vec3 specular_sum;
|
|
vec3 ambient;
|
|
|
|
ambient = Ka * Light[0].Intensity;
|
|
for (int i=0; i<LightCount; i++)
|
|
{
|
|
vec3 L = normalize(Light[i].Position.xyz - pos);
|
|
vec3 N = fNormal;
|
|
vec3 V = normalize(-pos);
|
|
//vec3 R = normalize(reflect(-L, N));
|
|
vec3 H = normalize(V + L);
|
|
|
|
vec3 diffuse = Kd * Light[i].Intensity * max(dot(L, N), 0.0);
|
|
vec3 specular = Ks * Light[i].Intensity * pow(max(dot(H, N), 0.0), Shininess);
|
|
diffuse_sum += diffuse;
|
|
specular_sum += specular;
|
|
}
|
|
|
|
FragColors = (vec4(diffuse_sum + ambient, 1) + vec4(specular_sum, 1.0));
|
|
} |