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-20 14:18:08 -08:00
|
|
|
in vec3 LightRawPos ;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
|
|
|
uniform vec3 ObjectColor;
|
2020-02-18 11:37:17 -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-18 11:37:17 -08:00
|
|
|
// Ambient
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-18 11:37:17 -08:00
|
|
|
float ambientStrength = 0.1;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-18 11:37:17 -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-18 11:37:17 -08:00
|
|
|
float diffuseStrength = max(dot(direction, lightDirection), 0.0);
|
|
|
|
vec3 diffuse = diffuseStrength * LightColor ;
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-18 11:37:17 -08:00
|
|
|
// Specular
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-18 11:37:17 -08:00
|
|
|
float specularStrength = 0.5;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 14:18:08 -08:00
|
|
|
// vec3 viewDirection = normalize(ViewPosition - FragPosition);
|
|
|
|
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);
|
|
|
|
|
|
|
|
vec3 specular = specularStrength * spec * LightColor;
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|