summaryrefslogtreecommitdiff
path: root/shaders
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-04-09 20:22:13 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-04-09 20:22:13 +0200
commit3817acdb49d775edb23fafbed70095be8f648ed6 (patch)
tree088d94ebd9f767e84263e1400db336930a7324cd /shaders
parente19c3838a4d89fb0640ed563ffdf58cd125cde7f (diff)
Terrain multitexturing.
Diffstat (limited to 'shaders')
-rw-r--r--shaders/terrain_fragment.glsl22
-rw-r--r--shaders/terrain_vertex.glsl15
2 files changed, 37 insertions, 0 deletions
diff --git a/shaders/terrain_fragment.glsl b/shaders/terrain_fragment.glsl
new file mode 100644
index 0000000..78417af
--- /dev/null
+++ b/shaders/terrain_fragment.glsl
@@ -0,0 +1,22 @@
+#version 120
+
+varying vec3 normal, light_pos;
+varying float y;
+
+uniform sampler2D tex[3];
+
+void main() {
+ vec3 n = normalize(normal);
+ float diffuse = max(dot(n, light_pos), 0.0);
+
+ float f1 = clamp((y-15.0) / 3.0, 0.0, 1.0);
+ float f2 = clamp((y-2) / 3.0, 0.0, 1.0);
+
+ vec4 t0 = texture2D(tex[0], gl_TexCoord[0].st);
+ vec4 t1 = texture2D(tex[1], gl_TexCoord[0].st);
+ vec4 t2 = texture2D(tex[2], gl_TexCoord[0].st);
+
+ gl_FragColor = mix(mix(t2, t0, f2), t1, f1) * diffuse;
+}
+
+/* vim: set syn=glsl: */
diff --git a/shaders/terrain_vertex.glsl b/shaders/terrain_vertex.glsl
new file mode 100644
index 0000000..e53c432
--- /dev/null
+++ b/shaders/terrain_vertex.glsl
@@ -0,0 +1,15 @@
+#version 120
+
+varying vec3 normal, light_pos;
+varying float y;
+
+void main() {
+ normal = gl_Normal;
+ light_pos = vec3(0, 1, 0);
+ y = gl_Vertex.y;
+
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
+
+/* vim: set syn=glsl: */