X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=fragment.glsl;h=cffd8a01a0abcd4d11f2a708a2820e10b440209b;hp=edc4f63358b73b6d46799ab01e18f31ffbca038b;hb=5a4d005b668b98d44ef20391ecddaf6bfc2ee70f;hpb=1dcbad027a4537b550766e9053a4418e8256c81c diff --git a/fragment.glsl b/fragment.glsl index edc4f63..cffd8a0 100644 --- a/fragment.glsl +++ b/fragment.glsl @@ -1,7 +1,23 @@ #version 330 in vec4 color; +in vec3 normal; +in vec3 fragPos; +uniform vec3 lightPos; +uniform vec3 viewPos; +uniform vec4 lightColor; out vec4 FragColor; void main() { - FragColor = color; + float ambient = 0.1; + float specularStrength = 0.5; + vec3 lightDir = normalize(fragPos - lightPos); + float diffuse = max(0, dot(-normal, lightDir)); + + vec3 viewDir = normalize(fragPos - viewPos); + vec3 reflectDir = reflect(-lightDir, normal); + float specular = pow(max(0, dot(viewDir, reflectDir)), 128); + + vec4 lighting = (ambient + diffuse + specular) * lightColor; + + FragColor = lighting * color; }