summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-11-25 00:35:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-25 00:36:19 +0000
commit7c5a6166d8f48c7cb6848a103a4d7de7e21dcf75 (patch)
tree1c87abb08629e986a08a713e09c24ffa6535d056 /gfx/gl
parentTransform obj to ILT was a static mat4 (diff)
downloadilt-7c5a6166d8f48c7cb6848a103a4d7de7e21dcf75.tar.bz2
ilt-7c5a6166d8f48c7cb6848a103a4d7de7e21dcf75.tar.xz
ilt-7c5a6166d8f48c7cb6848a103a4d7de7e21dcf75.zip
Add slope colouring to terrain shader
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/shaders/landmassShader.fs48
1 files changed, 39 insertions, 9 deletions
diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs
index 09e4565..ee943d7 100644
--- a/gfx/gl/shaders/landmassShader.fs
+++ b/gfx/gl/shaders/landmassShader.fs
@@ -10,6 +10,8 @@ uniform vec3 lightColor;
uniform vec3 ambientColor;
const vec3 grass = vec3(.1, .4, .05);
+const vec3 slope = vec3(.6, .6, .4);
+const vec3 rock = vec3(.2, .2, .1);
const vec3 sand = vec3(.76, .7, .5);
const vec3 snow = vec3(.97, .97, .99);
@@ -17,21 +19,49 @@ const float beachline = .5;
const float snowline_low = 28;
const float snowline_high = 30;
+const float slope_min = .99;
+const float slope_mid = .95;
+const float slope_max = .90;
+
+vec3
+mixBetween(vec3 colA, vec3 colB, float blend, float low, float high)
+{
+ return mix(colA, colB, (blend - low) / (high - low));
+}
+
void
main()
{
- gl_FragColor = texture(sampler, texCoord0);
+ vec4 tex = texture(sampler, texCoord0);
+ gl_FragColor = tex;
gl_FragColor.rgb *= clamp(ambientColor + (dot(-lightDirection, normal0) * lightColor), 0.0, 1.0);
- if (height < beachline) {
+
+ if (height < beachline) { // Sandy beach
gl_FragColor.rgb *= sand;
}
- else if (height > snowline_high) {
- gl_FragColor.rgb *= snow;
- }
- else if (height > snowline_low) {
- gl_FragColor.rgb *= mix(grass, snow, (height - snowline_low) / (snowline_high - snowline_low));
+ else if (normal0.z < slope_max) { // Dark rocky face
+ gl_FragColor.rgb *= rock;
}
- else {
- gl_FragColor.rgb *= grass;
+ else { // Colour by lesser slope
+ if (normal0.z < slope_mid) {
+ gl_FragColor.rgb *= mixBetween(rock, slope, normal0.z, slope_max, slope_mid);
+ }
+ else if (normal0.z < slope_min) {
+ gl_FragColor.rgb *= mixBetween(slope, grass, normal0.z, slope_mid, slope_min);
+ }
+ else {
+ gl_FragColor.rgb *= grass;
+ }
+
+ // Add a snow covering
+ if (height > snowline_low) {
+ vec3 tsnow = tex.rgb * snow;
+ if (height > snowline_high) {
+ gl_FragColor.rgb = tsnow;
+ }
+ else {
+ gl_FragColor.rgb = mixBetween(gl_FragColor.rgb, tsnow, height, snowline_low, snowline_high);
+ }
+ }
}
}