]> git.localhorst.tv Git - tacos-assets.git/blobdiff - shader/floor.fragment.glsl
floor shader
[tacos-assets.git] / shader / floor.fragment.glsl
diff --git a/shader/floor.fragment.glsl b/shader/floor.fragment.glsl
new file mode 100644 (file)
index 0000000..46f611c
--- /dev/null
@@ -0,0 +1,34 @@
+#version 330 core
+
+in vec3 view_position;
+in vec3 view_normal;
+
+struct DirectionalLight {
+       // direction in view space
+       vec3 direction;
+       vec3 ambient;
+       vec3 diffuse;
+       vec3 specular;
+};
+uniform DirectionalLight global_light = DirectionalLight(
+       vec3(0.57735026918962576451),
+       vec3(0.1),
+       vec3(1.0),
+       vec3(1.0)
+);
+
+
+void main() {
+       // TODO: pull from texture (or some other source)
+       const vec3 material_color = vec3(1.0);
+
+       vec3 normal = normalize(view_normal);
+       float cos_theta = dot(normal, global_light.direction);
+       float cos_alpha = dot(-normalize(view_position), reflect(-global_light.direction, normal));
+
+       vec3 ambient = global_light.ambient * material_color;
+       vec3 diffuse = global_light.diffuse * material_color * max(0.0, cos_theta);
+       vec3 specular = global_light.specular * pow(max(0.0, cos_alpha), 5);
+
+       gl_FragColor = vec4(ambient + diffuse + specular, 1.0);
+}