protot/data/shaders/fs_default.glsl

33 lines
780 B
Plaintext
Raw Normal View History

#version 150 core
uniform vec4 uColor;
uniform vec3 uLightDirection;
2018-03-11 14:16:23 +01:00
uniform vec3 uViewPosition;
smooth in vec4 ioFragColor;
in vec3 ioNormal;
2018-03-11 14:16:23 +01:00
in vec3 ioFragPosition;
out vec4 outColor;
void main() {
2018-03-11 14:16:23 +01:00
// ambient lighting
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);
vec3 light_dir = normalize(uLightDirection);
2018-03-11 17:30:56 +01:00
float diff = max(dot(normal_dir, light_dir), 0.0);
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;
}