summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/simple.frag57
-rw-r--r--data/simple.vert33
2 files changed, 90 insertions, 0 deletions
diff --git a/data/simple.frag b/data/simple.frag
new file mode 100644
index 0000000..89480f7
--- /dev/null
+++ b/data/simple.frag
@@ -0,0 +1,57 @@
+#version 130
+#extension GL_ARB_explicit_attrib_location: require
+
+#define DO_LIGHTING 0
+
+/* Debug mode. This will cause the value supplied as 'normal_cs' to be
+ * written as the output color. The normal will be remapped from the usual
+ * [-1,1] range to [0,1].
+ */
+#define SHOW_NORMALS 0
+
+/* Approximate (u,v) at the current fragment. Passed from the vertex shader,
+ * this is used to determine the base color of the fragment.
+ */
+in vec2 frag_uv;
+
+// Direction of the normal in camera-space.
+in vec3 normal_cs;
+
+// Direction to the light in camera-space.
+uniform vec3 light_dir_cs = normalize(vec3(0., 1., 0.));
+
+layout(location = 0) out vec4 color;
+
+void main(void)
+{
+ /* Partition the surface into a checkerboard of 10x10 tiles that
+ * alternate colors.
+ */
+ ivec2 tile = ivec2(floor(frag_uv * 10.));
+
+ vec3 base_color = bool((tile.x ^ tile.y) & 1)
+ ? vec3(0.00784313679, 0.470588207, 0.996078372)
+ : vec3(0.00784313679, 0.992156804, 0.00784313679);
+
+ /* Renormalize the normal to account for interpolation errors.
+ */
+ vec3 n_cs = normalize(normal_cs);
+
+ /* If the polygon is back-facing, change the color and invert the
+ * normal. This causes back-facing polygons to have different colors
+ * and be correctly lit.
+ */
+ if (! gl_FrontFacing) {
+ n_cs = -n_cs;
+ base_color = base_color.zxy;
+ }
+
+#if DO_LIGHTING
+ float diff = min(max(.2, dot(n_cs, light_dir_cs)), 1.);
+ color = vec4(base_color * diff, 1.);
+#elif SHOW_NORMALS
+ color = vec4(normal_cs * .5 + .5, 1.);
+#else
+ color = vec4(base_color, 1.);
+#endif
+}
diff --git a/data/simple.vert b/data/simple.vert
new file mode 100644
index 0000000..1850a67
--- /dev/null
+++ b/data/simple.vert
@@ -0,0 +1,33 @@
+#version 130
+#extension GL_ARB_explicit_attrib_location: require
+
+uniform mat4 mvp;
+uniform mat3 mv_normal;
+
+layout(location = 0) in vec2 uv;
+
+out vec4 color;
+out vec2 frag_uv;
+
+// Direction of the normal in camera-space.
+out vec3 normal_cs;
+
+void main(void)
+{
+ /* Center the region at the origin. Assume that it's 7 units by 7
+ * units.
+ */
+ vec2 bias_uv = uv - 0.5;
+ vec4 position = vec4(bias_uv.x * 7.,
+ 0.0,
+ bias_uv.y * 7.,
+ 1.0);
+ gl_Position = mvp * position;
+
+ /* Transform the normal by the inverse-transpose of the model-view
+ * matrix.
+ */
+ normal_cs = mv_normal * vec3(0., 1., 0.);
+
+ frag_uv = uv;
+}