-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flat.fs
58 lines (46 loc) · 1.26 KB
/
flat.fs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#version 300 es
// Required for webgl
#ifdef GL_ES
precision highp float;
#endif
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};
struct DirLight {
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
out vec4 FragColor;
in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoord;
/* in vec4 FragPosLightSpace; */
uniform vec3 viewPos;
uniform Material material;
uniform DirLight dirLight;
uniform sampler2D tex;
void main()
{
// ambient
vec3 ambient = dirLight.ambient * material.ambient;
// diffuse
vec3 norm = normalize(Normal);
/* vec3 lightDir = normalize(light.position - FragPos); */ /* Calculate from position */
vec3 lightDir = normalize(dirLight.direction);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = dirLight.diffuse * (diff * material.diffuse);
// specular
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = dirLight.specular * (spec * material.specular);
vec3 result = ambient + diffuse + specular;
FragColor = vec4(result, 1.0);
/* TODO re-enable texture */
/* FragColor = texture(tex, TexCoord); */
}