2018-03-11 11:58:50 +01:00
|
|
|
#version 150 core
|
|
|
|
|
|
|
|
uniform vec4 uColor;
|
|
|
|
uniform vec3 uLightDirection;
|
2018-03-11 14:16:23 +01:00
|
|
|
uniform vec3 uViewPosition;
|
2018-03-11 11:58:50 +01:00
|
|
|
|
|
|
|
smooth in vec4 ioFragColor;
|
|
|
|
in vec3 ioNormal;
|
2018-03-11 14:16:23 +01:00
|
|
|
in vec3 ioFragPosition;
|
2018-03-11 11:58:50 +01:00
|
|
|
|
|
|
|
out vec4 outColor;
|
|
|
|
|
|
|
|
void main() {
|
2018-03-11 14:16:23 +01:00
|
|
|
// ambient lighting
|
2018-03-11 11:58:50 +01:00
|
|
|
float ambient_strength = 0.1;
|
|
|
|
vec4 ambient = ambient_strength * ioFragColor;
|
|
|
|
|
2018-03-11 14:16:23 +01:00
|
|
|
// diffuse lighting
|
2018-03-11 17:30:56 +01:00
|
|
|
vec3 normal_dir = normalize(ioNormal);
|
2018-03-11 11:58:50 +01:00
|
|
|
vec3 light_dir = normalize(uLightDirection);
|
2018-03-11 17:30:56 +01:00
|
|
|
float diff = max(dot(normal_dir, light_dir), 0.0);
|
2018-03-11 11:58:50 +01:00
|
|
|
vec4 diffuse = diff * ioFragColor;
|
|
|
|
|
2018-03-11 14:16:23 +01:00
|
|
|
// specular lighting
|
|
|
|
vec3 view_dir = normalize(uViewPosition - ioFragPosition);
|
2018-03-11 17:30:56 +01:00
|
|
|
vec3 halfway_dir = normalize(light_dir + view_dir);
|
2018-03-11 14:16:23 +01:00
|
|
|
|
2018-03-11 17:30:56 +01:00
|
|
|
float spec = pow(max(dot(normal_dir, halfway_dir), 0.0), 32);
|
|
|
|
vec4 specular = spec * vec4(0.5);
|
2018-03-11 14:16:23 +01:00
|
|
|
|
|
|
|
outColor = ambient + diffuse + specular;
|
2018-03-11 11:58:50 +01:00
|
|
|
}
|