skein/frag_lit.glsl

31 lines
776 B
Plaintext
Raw Permalink Normal View History

#version 330 core
2023-08-03 10:26:01 +02:00
in vec3 Normal;
in vec3 FragPos;
in mat4x4 ModelViewProjection;
2023-08-03 10:26:01 +02:00
out vec4 FragColor;
void main()
{
2023-08-03 08:43:34 +02:00
vec3 objectColor = vec3(1.0, 0.5, 0.2);
2023-08-03 10:26:01 +02:00
vec3 result;
// Ambient lighting
vec3 ambientLightColor = vec3(1.0, 1.0, 1.0);
2023-08-03 08:43:34 +02:00
float ambientStrength = 0.1;
2023-08-03 10:26:01 +02:00
vec3 ambient = ambientStrength * ambientLightColor;
// Directional lighting
vec3 directionalLightColor = vec3(1.0, 1.0, 1.0);
vec3 lightPos = (ModelViewProjection * vec4(6.0, -7.0, 8.0, 1.0)).xyz;
2023-08-03 10:26:01 +02:00
vec3 normal = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * directionalLightColor;
2023-08-03 08:43:34 +02:00
2023-08-03 10:26:01 +02:00
result = (ambient + diffuse) * objectColor;
2023-08-03 08:43:34 +02:00
2023-08-03 10:26:01 +02:00
FragColor = vec4(result, 1.0);
}