protot/data/shaders/fs_default.glsl

34 lines
827 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
vec3 norm = normalize(ioNormal);
vec3 light_dir = normalize(uLightDirection);
float diff = max(dot(norm, light_dir), 0.0);
vec4 diffuse = diff * ioFragColor;
2018-03-11 14:16:23 +01:00
// specular lighting
vec3 view_dir = normalize(uViewPosition - ioFragPosition);
vec3 reflect_dir = reflect(-light_dir, norm);
float specular_strength = 0.5;
float spec = pow(max(dot(view_dir, reflect_dir), 0.0), 32);
vec4 specular = specular_strength * spec * vec4(1.0, 1.0, 1.0, 1.0);
outColor = ambient + diffuse + specular;
}