aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/shadow_shaders
diff options
context:
space:
mode:
authorx2048 <codeforsmile@gmail.com>2021-10-01 16:21:53 +0200
committerGitHub <noreply@github.com>2021-10-01 16:21:53 +0200
commit982e03f60dc95cb2605a4a1c6520b604f85dd1d0 (patch)
tree748a4763dea169f7e983a602a1fc7d2e031c9849 /client/shaders/shadow_shaders
parent21113ad4105dd3fb181b3d0638b907af94a352ab (diff)
downloadminetest-982e03f60dc95cb2605a4a1c6520b604f85dd1d0.tar.gz
minetest-982e03f60dc95cb2605a4a1c6520b604f85dd1d0.tar.bz2
minetest-982e03f60dc95cb2605a4a1c6520b604f85dd1d0.zip
Improvements to colored shadows (#11516)
Diffstat (limited to 'client/shaders/shadow_shaders')
-rw-r--r--client/shaders/shadow_shaders/pass1_trans_fragment.glsl7
-rw-r--r--client/shaders/shadow_shaders/pass1_trans_vertex.glsl7
2 files changed, 13 insertions, 1 deletions
diff --git a/client/shaders/shadow_shaders/pass1_trans_fragment.glsl b/client/shaders/shadow_shaders/pass1_trans_fragment.glsl
index 9f9e5be8c..032cd9379 100644
--- a/client/shaders/shadow_shaders/pass1_trans_fragment.glsl
+++ b/client/shaders/shadow_shaders/pass1_trans_fragment.glsl
@@ -2,6 +2,8 @@ uniform sampler2D ColorMapSampler;
varying vec4 tPos;
#ifdef COLORED_SHADOWS
+varying vec3 varColor;
+
// c_precision of 128 fits within 7 base-10 digits
const float c_precision = 128.0;
const float c_precisionp1 = c_precision + 1.0;
@@ -30,7 +32,10 @@ void main()
//col.rgb = col.a == 1.0 ? vec3(1.0) : col.rgb;
#ifdef COLORED_SHADOWS
- float packedColor = packColor(mix(col.rgb, black, col.a));
+ col.rgb *= varColor.rgb;
+ // alpha 0.0 results in all-white, 0.5 means full color, 1.0 means all black
+ // resulting color is used as a factor in the final shader
+ float packedColor = packColor(mix(mix(vec3(1.0), col.rgb, 2.0 * clamp(col.a, 0.0, 0.5)), black, 2.0 * clamp(col.a - 0.5, 0.0, 0.5)));
gl_FragColor = vec4(depth, packedColor, 0.0,1.0);
#else
gl_FragColor = vec4(depth, 0.0, 0.0, 1.0);
diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
index ca59f2796..0a9efe450 100644
--- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
+++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl
@@ -1,5 +1,8 @@
uniform mat4 LightMVP; // world matrix
varying vec4 tPos;
+#ifdef COLORED_SHADOWS
+varying vec3 varColor;
+#endif
const float bias0 = 0.9;
const float zPersFactor = 0.5;
@@ -23,4 +26,8 @@ void main()
gl_Position = vec4(tPos.xyz, 1.0);
gl_TexCoord[0].st = gl_MultiTexCoord0.st;
+
+#ifdef COLORED_SHADOWS
+ varColor = gl_Color.rgb;
+#endif
}