diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-20 00:17:58 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-20 00:17:58 +0000 |
commit | 2bc4bcebc93e7211dfb84303888635f888ba8018 (patch) | |
tree | 3a349beadc079c544001f3a65ac0e26fe494f8e5 /gfx/gl/shaders/landmassShader.fs | |
parent | Create smoother terrain (diff) | |
download | ilt-2bc4bcebc93e7211dfb84303888635f888ba8018.tar.bz2 ilt-2bc4bcebc93e7211dfb84303888635f888ba8018.tar.xz ilt-2bc4bcebc93e7211dfb84303888635f888ba8018.zip |
Custom land and water shaders
Create sandy beaches, snow topped mountains and grassy hills with a single texture, coloured
according to land height by a custom shader.
Also use the land mass mesh with a new water texture and a custom shader to create rather nice
looking water effect with depth, waves and motion.
Diffstat (limited to 'gfx/gl/shaders/landmassShader.fs')
-rw-r--r-- | gfx/gl/shaders/landmassShader.fs | 41 |
1 files changed, 41 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;
+ }
+}
|