skein/frag_lit.glsl

31 lines
776 B
GLSL

#version 330 core
in vec3 Normal;
in vec3 FragPos;
in mat4x4 ModelViewProjection;
out vec4 FragColor;
void main()
{
vec3 objectColor = vec3(1.0, 0.5, 0.2);
vec3 result;
// Ambient lighting
vec3 ambientLightColor = vec3(1.0, 1.0, 1.0);
float ambientStrength = 0.1;
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;
vec3 normal = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * directionalLightColor;
result = (ambient + diffuse) * objectColor;
FragColor = vec4(result, 1.0);
}