-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightingShader.frag
36 lines (28 loc) · 1006 Bytes
/
lightingShader.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#version 460 core
in vec4 Normal;
in vec3 FragPos;
in vec2 TexCoords;
out vec4 FragColor;
struct material {
sampler2D diffuse;
sampler2D specular;
float reflectivity;
};
uniform material Material;
uniform vec3 lightSourceColor;
uniform vec3 lightAmbientColor;
uniform vec3 lightPos;
uniform vec3 viewPos;
void main() {
vec3 ambient = lightAmbientColor * vec3(texture(Material.diffuse, TexCoords));
vec3 norm = normalize(vec3(Normal));
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = lightSourceColor * diff * vec3(texture(Material.diffuse, TexCoords));
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), Material.reflectivity);
vec3 specular = lightSourceColor * spec * vec3(texture(Material.specular, TexCoords));
vec3 result = (ambient + diffuse + specular);
FragColor = vec4(result, 1.0);
}