Do assignment 3
[opengl.git] / normalfrag.glsl
diff --git a/normalfrag.glsl b/normalfrag.glsl
new file mode 100644 (file)
index 0000000..1683592
--- /dev/null
@@ -0,0 +1,24 @@
+#version 330
+in vec3 normal;
+in vec3 normalEye;
+in vec3 fragPos;
+uniform vec3 lightPos;
+uniform vec3 viewPos;
+uniform vec4 lightColor;
+out vec4 FragColor;
+
+void main() {
+       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 * vec4(normalEye, 1);
+}
+