diff options
author | x2048 <codeforsmile@gmail.com> | 2021-07-11 17:15:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-11 08:15:19 -0700 |
commit | f5706d444b02ccc1fcd854968087172d50cfcca2 (patch) | |
tree | 073af762f7981cf49b0be4fdbd203ecc341df811 /client/shaders/nodes_shader | |
parent | 1d25d1f7ad35f739e8a64c2bdb44105998aed19b (diff) | |
download | minetest-f5706d444b02ccc1fcd854968087172d50cfcca2.tar.gz minetest-f5706d444b02ccc1fcd854968087172d50cfcca2.tar.bz2 minetest-f5706d444b02ccc1fcd854968087172d50cfcca2.zip |
Improve shadow rendering with non-default camera FOV (#11385)
* Adjust minimum filter radius for perspective
* Expand shadow frustum when camera FOV changes, reuse FOV distance adjustment from numeric.cpp
* Read shadow_soft_radius setting as float
* Use adaptive filter radius to accomodate for PSM distortion
* Adjust filter radius for texture resolution
Diffstat (limited to 'client/shaders/nodes_shader')
-rw-r--r-- | client/shaders/nodes_shader/opengl_fragment.glsl | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 43a8b1f25..9f8a21d09 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -181,9 +181,14 @@ float getDeltaPerspectiveFactor(float l) float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) { + float baseLength = getBaseLength(smTexCoord); + float perspectiveFactor; + // Return fast if sharp shadows are requested - if (SOFTSHADOWRADIUS <= 1.0) - return SOFTSHADOWRADIUS; + if (SOFTSHADOWRADIUS <= 1.0) { + perspectiveFactor = getDeltaPerspectiveFactor(baseLength); + return max(2 * length(smTexCoord.xy) * 2048 / f_textureresolution / pow(perspectiveFactor, 3), SOFTSHADOWRADIUS); + } vec2 clampedpos; float texture_size = 1.0 / (2048 /*f_textureresolution*/ * 0.5); @@ -192,8 +197,6 @@ float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDist float pointDepth; float maxRadius = SOFTSHADOWRADIUS * 5.0 * multiplier; - float baseLength = getBaseLength(smTexCoord); - float perspectiveFactor; float bound = clamp(PCFBOUND * (1 - baseLength), 0.5, PCFBOUND); int n = 0; @@ -211,9 +214,10 @@ float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDist } depth = depth / n; - depth = pow(clamp(depth, 0.0, 1000.0), 1.6) / 0.001; - return max(0.5, depth * maxRadius); + + perspectiveFactor = getDeltaPerspectiveFactor(baseLength); + return max(length(smTexCoord.xy) * 2 * 2048 / f_textureresolution / pow(perspectiveFactor, 3), depth * maxRadius); } #ifdef POISSON_FILTER |