voxel-engine/shaders/shader-texture.fs

48 lines
1.3 KiB
Forth
Raw Permalink Normal View History

#version 330 core
out vec4 FragColor;
in vec3 TexCoord;
in vec3 Normal;
in vec3 FragPos;
vec3 lightColor = vec3(1.0);
vec3 lightDir = -normalize(vec3(0.0, 100.0, 0.0) - vec3(32.0));
float ambientStrength = 0.1;
float diffuseStrength = 0.8;
float specularStrength = 0.1;
uniform vec3 viewPos;
uniform float u_time;
uniform sampler2DArray textureArray;
2023-07-19 13:06:01 +02:00
float gamma = 2.2;
void main(){
// 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-07-28 16:39:24 +02:00
if(TexCoord.z == 4) vColor = vColor * normalize(vec3(10, 250, 10));
vec3 normal = normalize(Normal);
/* Start of Blinn-Phong lighting */
// 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));
}