blob: 54bf7009a9d864f55e3198f87d70c0106907828a (
plain)
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
|
#version 330 core
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};
struct Light {
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 position;
};
in vec3 fragNormal;
in vec3 worldPosition;
uniform Material material;
uniform Light light;
uniform vec3 cameraPosition;
uniform vec3 lightColor;
uniform sampler2D smilingTexture;
uniform sampler2D containerTexture;
out vec4 FragColor;
void main() {
vec3 ambientLight = light.ambient * material.ambient;
// @note: Diffuse calculations
vec3 lightDir = normalize(light.position - worldPosition);
float diffuseStrength = max(dot(lightDir, fragNormal), 0.0);
vec3 diffuseLight = light.diffuse * (diffuseStrength * material.diffuse);
// @note: Specular calculations
vec3 viewDir = normalize(cameraPosition - worldPosition);
vec3 reflectDir = reflect(-lightDir, fragNormal);
float specularity = max(dot(viewDir, reflectDir), 0.0);
float shinePower = pow(specularity, material.shininess);
vec3 specularLight = light.specular * (shinePower * material.specular);
vec3 color = ambientLight + diffuseLight + specularLight;
FragColor = vec4(color, 1.0);
}
|