2020-02-16 22:28:24 -08:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
out vec4 FragColor;
|
|
|
|
|
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
in vec3 FragPosition;
|
|
|
|
in vec3 Normal ;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uniform vec3 ObjectColor;
|
|
|
|
|
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
uniform vec3 LightPosition;
|
2020-02-16 22:28:24 -08:00
|
|
|
uniform vec3 LightColor ;
|
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
uniform vec3 ViewPosition;
|
|
|
|
|
2020-02-16 22:28:24 -08:00
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2020-02-17 18:10:15 -08:00
|
|
|
float AmbientStrength = 0.1;
|
|
|
|
float SpecularStrength = 0.5;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
|
|
|
vec3 ambient = AmbientStrength * LightColor ;
|
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
vec3 Direction = normalize(Normal );
|
|
|
|
vec3 LightDirection = normalize(LightPosition - FragPosition);
|
|
|
|
|
|
|
|
float DiffuseStrength = max(dot(Normal, LightDirection), 0.0);
|
|
|
|
|
|
|
|
vec3 diffuse = DiffuseStrength * LightColor ;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
vec3 ViewDirection = normalize(ViewPosition - FragPosition);
|
|
|
|
|
|
|
|
vec3 ReflectionDirection = reflect(-LightDirection, Normal);
|
|
|
|
|
|
|
|
float Spec = pow(max(dot(ViewDirection, ReflectionDirection), 0.0), 32);
|
|
|
|
|
|
|
|
vec3 specular = SpecularStrength * Spec * LightColor;
|
|
|
|
|
|
|
|
vec3 result = (ambient + diffuse + specular) * ObjectColor;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
|
|
|
FragColor = vec4(result, 1.0);
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-16 22:28:24 -08:00
|
|
|
}
|