Add Phong lighting
[opengl.git] / fragment.glsl
index edc4f63358b73b6d46799ab01e18f31ffbca038b..e41a7f929083f43ba0ee3653e1cf37946eb9daf2 100644 (file)
@@ -1,7 +1,20 @@
 #version 330
 in vec4 color;
+in vec3 normal;
+in vec3 fragPos;
+uniform vec3 lightPos;
+uniform vec3 viewPos;
 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);
+
+       FragColor = (ambient + diffuse + specular) * color;
 }