37 lines
966 B
GLSL
37 lines
966 B
GLSL
#version 410 core
|
|
in vec3 FragPos;
|
|
in vec3 Normal;
|
|
in vec3 Color;
|
|
|
|
out vec4 FragColor;
|
|
|
|
uniform vec3 uLightPos;
|
|
uniform vec3 uViewPos;
|
|
uniform vec3 uLightColor;
|
|
uniform float uAmbientStrength;
|
|
uniform float uSpecularStrength;
|
|
uniform float uShininess;
|
|
|
|
void main() {
|
|
// Normalize the normal vector
|
|
vec3 norm = normalize(Normal);
|
|
|
|
// Ambient lighting
|
|
vec3 ambient = uAmbientStrength * uLightColor;
|
|
|
|
// Diffuse lighting
|
|
vec3 lightDir = normalize(uLightPos - FragPos);
|
|
float diff = max(dot(norm, lightDir), 0.0);
|
|
vec3 diffuse = diff * uLightColor;
|
|
|
|
// Specular lighting
|
|
vec3 viewDir = normalize(uViewPos - FragPos);
|
|
vec3 reflectDir = reflect(-lightDir, norm);
|
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), uShininess);
|
|
vec3 specular = uSpecularStrength * spec * uLightColor;
|
|
|
|
// Combine results
|
|
vec3 result = (ambient + diffuse + specular) * Color;
|
|
FragColor = vec4(result, 1.0);
|
|
}
|