2023-04-10 00:21:49 +02:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
out vec4 FragColor;
|
|
|
|
|
2023-07-19 12:42:45 +02:00
|
|
|
in vec3 TexCoord;
|
|
|
|
in vec3 Normal;
|
2023-04-10 00:21:49 +02:00
|
|
|
in vec3 FragPos;
|
|
|
|
|
|
|
|
vec3 lightColor = vec3(1.0);
|
|
|
|
vec3 lightDir = -normalize(vec3(0.0, 100.0, 0.0) - vec3(32.0));
|
|
|
|
|
2023-07-19 12:42:45 +02:00
|
|
|
float ambientStrength = 0.1;
|
|
|
|
float diffuseStrength = 0.8;
|
|
|
|
float specularStrength = 0.1;
|
2023-04-10 00:21:49 +02:00
|
|
|
|
|
|
|
uniform vec3 viewPos;
|
|
|
|
uniform float u_time;
|
|
|
|
uniform sampler2DArray textureArray;
|
|
|
|
|
2023-07-19 13:06:01 +02:00
|
|
|
float gamma = 2.2;
|
|
|
|
|
2023-04-10 00:21:49 +02:00
|
|
|
void main(){
|
2023-07-19 12:42:45 +02:00
|
|
|
// Load the texture
|
|
|
|
// anti-gamma-correction of the texture. Without this it would be gamma corrected twice!
|
2023-07-19 13:06:01 +02:00
|
|
|
vec3 vColor = pow(texture(textureArray, TexCoord).rgb, vec3(gamma));
|
2023-04-10 00:21:49 +02:00
|
|
|
|
2023-07-19 12:42:45 +02:00
|
|
|
vec3 normal = normalize(Normal);
|
2023-04-10 00:21:49 +02:00
|
|
|
|
2023-07-19 12:42:45 +02:00
|
|
|
/* Start of Blinn-Phong lighting */
|
2023-04-10 00:21:49 +02:00
|
|
|
// Ambient
|
|
|
|
vec3 ambient = lightColor*vColor;
|
|
|
|
|
|
|
|
// Diffuse
|
|
|
|
float diff = max(dot(normal, lightDir), 0.0);
|
|
|
|
vec3 diffuse = vColor * diff;
|
|
|
|
|
|
|
|
// Blinn Specular
|
|
|
|
vec3 viewDir = normalize(viewPos - FragPos);
|
|
|
|
vec3 halfwayDir = normalize(lightDir + viewDir);
|
|
|
|
float spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0);
|
|
|
|
vec3 specular = lightColor * vColor * spec;
|
|
|
|
|
|
|
|
// Final color
|
|
|
|
vec3 color = ambient * ambientStrength + diffuse * diffuseStrength + specular * specularStrength;
|
2023-07-19 13:06:01 +02:00
|
|
|
FragColor.rgb = pow(color, vec3(1.0/gamma));
|
2023-04-10 00:21:49 +02:00
|
|
|
}
|