60 lines
1.1 KiB
GLSL
60 lines
1.1 KiB
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;
|
|
|
|
in vec2 texCoord;
|
|
uniform int TexCount;
|
|
uniform sampler2D tex[32];
|
|
|
|
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 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;
|
|
}
|
|
|
|
vec4 texColor = texture(tex[0], texCoord);
|
|
|
|
for (int i=1; i < TexCount; i++)
|
|
{
|
|
vec4 new_tex = texture(tex[i], texCoord);
|
|
texColor = mix(new_tex, texColor, new_tex.a);
|
|
}
|
|
|
|
FragColors = (vec4(diffuse_sum + ambient, 1) * texColor + vec4(specular_sum, 1.0));
|
|
|
|
}
|