summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r--gfx/gl/shaders/landmassShader.fs41
-rw-r--r--gfx/gl/shaders/landmassShader.vs21
-rw-r--r--gfx/gl/shaders/waterShader.fs13
-rw-r--r--gfx/gl/shaders/waterShader.vs23
4 files changed, 98 insertions, 0 deletions
diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs
new file mode 100644
index 0000000..36cc971
--- /dev/null
+++ b/gfx/gl/shaders/landmassShader.fs
@@ -0,0 +1,41 @@
+#version 130
+
+in vec2 texCoord0;
+in vec3 normal0;
+in float height;
+
+uniform sampler2D sampler;
+uniform vec3 lightDirection;
+uniform vec3 lightColor;
+uniform vec3 ambientColor;
+
+const vec3 grass = vec3(.1, .4, .05);
+const vec3 sand = vec3(.76, .7, .5);
+const vec3 snow = vec3(.97, .97, .99);
+
+vec2
+grad_between(float x, float lower, float upper)
+{
+ float off = (x - lower) / (upper - lower);
+ return vec2(off, 1 - off);
+}
+
+void
+main()
+{
+ gl_FragColor = texture(sampler, texCoord0);
+ gl_FragColor.xyz *= clamp(ambientColor + (dot(-lightDirection, normal0) * lightColor), 0.0, 1.0);
+ if (height < 0.5) {
+ gl_FragColor.rgb *= sand;
+ }
+ else if (height > 30) {
+ gl_FragColor.rgb *= snow;
+ }
+ else if (height > 28) {
+ vec2 grad = grad_between(height, 28, 30);
+ gl_FragColor.rgb *= grass + (snow - grass) * grad.x;
+ }
+ else {
+ gl_FragColor.rgb *= grass;
+ }
+}
diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs
new file mode 100644
index 0000000..72c9060
--- /dev/null
+++ b/gfx/gl/shaders/landmassShader.vs
@@ -0,0 +1,21 @@
+#version 130
+
+in vec3 position;
+in vec2 texCoord;
+in vec3 normal;
+
+out vec2 texCoord0;
+out vec3 normal0;
+out float height;
+
+uniform mat4 viewProjection;
+uniform mat4 model;
+uniform vec3 waves;
+
+void main()
+{
+ gl_Position = viewProjection * model * vec4(position, 1.0);
+ texCoord0 = texCoord;
+ normal0 = normal;
+ height = position.y;
+}
diff --git a/gfx/gl/shaders/waterShader.fs b/gfx/gl/shaders/waterShader.fs
new file mode 100644
index 0000000..bdfbc33
--- /dev/null
+++ b/gfx/gl/shaders/waterShader.fs
@@ -0,0 +1,13 @@
+#version 130
+
+in vec2 texCoord0;
+in float depth;
+
+uniform sampler2D sampler;
+uniform vec3 waves;
+
+void main()
+{
+ gl_FragColor = texture(sampler, texCoord0);
+ gl_FragColor.a *= clamp(-depth * .7, .1, 1.0);
+}
diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs
new file mode 100644
index 0000000..55a0fb8
--- /dev/null
+++ b/gfx/gl/shaders/waterShader.vs
@@ -0,0 +1,23 @@
+#version 130
+
+in vec3 position;
+in vec2 texCoord;
+in vec3 normal;
+
+out vec2 texCoord0;
+out float depth;
+
+uniform mat4 viewProjection;
+uniform mat4 model;
+uniform vec3 waves;
+
+void main()
+{
+ vec3 wpos = vec3(
+ position.x + cos(waves.x),
+ cos(waves.x + position.x + (position.z / 7)) * .3,
+ position.z + cos(waves.x * waves.z));
+ gl_Position = viewProjection * model * vec4(wpos, 1.0);
+ texCoord0 = texCoord;
+ depth = position.y;
+}