summaryrefslogtreecommitdiff
path: root/client/shaders/nodes_shader/opengl_vertex.glsl
diff options
context:
space:
mode:
authorx2048 <codeforsmile@gmail.com>2022-03-26 16:58:26 +0100
committerGitHub <noreply@github.com>2022-03-26 16:58:26 +0100
commit0f25fa7af655b98fa401176a523f269c843d1943 (patch)
tree1fa8762f53941d6c1250c0c3a7dc6b8557995a40 /client/shaders/nodes_shader/opengl_vertex.glsl
parent8d55702d139db739f8bf43eaa600f41446b29a16 (diff)
downloadminetest-0f25fa7af655b98fa401176a523f269c843d1943.tar.gz
minetest-0f25fa7af655b98fa401176a523f269c843d1943.tar.bz2
minetest-0f25fa7af655b98fa401176a523f269c843d1943.zip
Add API to control shadow intensity from the game/mod (#11944)
* Also Disable shadows when sun/moon is hidden. Fixes #11972.
Diffstat (limited to 'client/shaders/nodes_shader/opengl_vertex.glsl')
-rw-r--r--client/shaders/nodes_shader/opengl_vertex.glsl57
1 files changed, 29 insertions, 28 deletions
diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl
index 95cd138a8..5e77ac719 100644
--- a/client/shaders/nodes_shader/opengl_vertex.glsl
+++ b/client/shaders/nodes_shader/opengl_vertex.glsl
@@ -195,34 +195,35 @@ void main(void)
varColor = clamp(color, 0.0, 1.0);
#ifdef ENABLE_DYNAMIC_SHADOWS
- vec3 nNormal = normalize(vNormal);
- cosLight = dot(nNormal, -v_LightDirection);
-
- // Calculate normal offset scale based on the texel size adjusted for
- // curvature of the SM texture. This code must be change together with
- // getPerspectiveFactor or any light-space transformation.
- vec3 eyeToVertex = worldPosition - eyePosition + cameraOffset;
- // Distance from the vertex to the player
- float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar;
- // perspective factor estimation according to the
- float perspectiveFactor = distanceToPlayer * bias0 + bias1;
- float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor /
- (f_textureresolution * bias1 - perspectiveFactor * bias0);
- float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0);
- normalOffsetScale = texelSize * slopeScale;
-
- if (f_timeofday < 0.2) {
- adj_shadow_strength = f_shadow_strength * 0.5 *
- (1.0 - mtsmoothstep(0.18, 0.2, f_timeofday));
- } else if (f_timeofday >= 0.8) {
- adj_shadow_strength = f_shadow_strength * 0.5 *
- mtsmoothstep(0.8, 0.83, f_timeofday);
- } else {
- adj_shadow_strength = f_shadow_strength *
- mtsmoothstep(0.20, 0.25, f_timeofday) *
- (1.0 - mtsmoothstep(0.7, 0.8, f_timeofday));
+ if (f_shadow_strength > 0.0) {
+ vec3 nNormal = normalize(vNormal);
+ cosLight = dot(nNormal, -v_LightDirection);
+
+ // Calculate normal offset scale based on the texel size adjusted for
+ // curvature of the SM texture. This code must be change together with
+ // getPerspectiveFactor or any light-space transformation.
+ vec3 eyeToVertex = worldPosition - eyePosition + cameraOffset;
+ // Distance from the vertex to the player
+ float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar;
+ // perspective factor estimation according to the
+ float perspectiveFactor = distanceToPlayer * bias0 + bias1;
+ float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor /
+ (f_textureresolution * bias1 - perspectiveFactor * bias0);
+ float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0);
+ normalOffsetScale = texelSize * slopeScale;
+
+ if (f_timeofday < 0.2) {
+ adj_shadow_strength = f_shadow_strength * 0.5 *
+ (1.0 - mtsmoothstep(0.18, 0.2, f_timeofday));
+ } else if (f_timeofday >= 0.8) {
+ adj_shadow_strength = f_shadow_strength * 0.5 *
+ mtsmoothstep(0.8, 0.83, f_timeofday);
+ } else {
+ adj_shadow_strength = f_shadow_strength *
+ mtsmoothstep(0.20, 0.25, f_timeofday) *
+ (1.0 - mtsmoothstep(0.7, 0.8, f_timeofday));
+ }
+ f_normal_length = length(vNormal);
}
- f_normal_length = length(vNormal);
#endif
-
}