]> git.localhorst.tv Git - tacos-assets.git/commitdiff
floor shader
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 7 Mar 2016 13:18:26 +0000 (14:18 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 7 Mar 2016 13:18:26 +0000 (14:18 +0100)
shader/floor.fragment.glsl [new file with mode: 0644]
shader/floor.vertex.glsl [new file with mode: 0644]

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);
+}
diff --git a/shader/floor.vertex.glsl b/shader/floor.vertex.glsl
new file mode 100644 (file)
index 0000000..b74d164
--- /dev/null
@@ -0,0 +1,16 @@
+#version 330 core
+
+layout(location = 0) in vec3 vert_position;
+layout(location = 1) in vec3 vert_normal;
+
+uniform mat4 MV;
+uniform mat4 MVP;
+
+out vec3 view_position;
+out vec3 view_normal;
+
+void main() {
+       gl_Position = MVP * vec4(vert_position, 1.0);
+       view_position = (MV * vec4(vert_position, 1.0)).xyz;
+       view_normal = mat3(MV) * vert_normal;
+}