2020-02-16 22:28:24 -08:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
out vec4 FragColor;
|
|
|
|
|
2020-02-18 11:37:17 -08:00
|
|
|
in vec3 FragPosition ;
|
|
|
|
in vec3 Normal ;
|
|
|
|
in vec3 LightViewPosition;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
uniform vec3 ObjectColor ;
|
2020-02-18 11:37:17 -08:00
|
|
|
uniform vec3 LightColor ;
|
2020-02-20 22:18:07 -08:00
|
|
|
|
|
|
|
uniform float AmbientStrength ;
|
|
|
|
uniform float DiffuseStrength ;
|
|
|
|
uniform float SpecularStrength;
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-16 22:28:24 -08:00
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2020-02-18 11:37:17 -08:00
|
|
|
// Ambient
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
vec3 ambient = AmbientStrength * LightColor ;
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-18 11:37:17 -08:00
|
|
|
// Diffuse
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-20 14:18:08 -08:00
|
|
|
vec3 direction = normalize(Normal );
|
2020-02-18 11:37:17 -08:00
|
|
|
vec3 lightDirection = normalize(LightViewPosition - FragPosition);
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
float diffuseMagnitude = max(dot(direction, lightDirection), 0.0);
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
vec3 diffuse = DiffuseStrength * diffuseMagnitude * LightColor;
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
// Specular
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 14:18:08 -08:00
|
|
|
vec3 viewDirection = normalize(-FragPosition);
|
2020-02-18 11:37:17 -08:00
|
|
|
|
|
|
|
vec3 reflectionDirection = reflect(-lightDirection, direction);
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-18 11:37:17 -08:00
|
|
|
float spec = pow(max(dot(viewDirection, reflectionDirection), 0.0), 32);
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
vec3 specular = SpecularStrength * spec * LightColor;
|
2020-02-18 11:37:17 -08:00
|
|
|
|
|
|
|
// Combining
|
|
|
|
|
2020-02-18 14:19:55 -08:00
|
|
|
vec3 result = (ambient + diffuse + specular) * ObjectColor;
|
2020-02-18 11:37:17 -08:00
|
|
|
|
|
|
|
FragColor = vec4(result, 1.0);
|
2020-02-16 22:28:24 -08:00
|
|
|
}
|