summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorDmitry Kostenko <codeforsmile@gmail.com>2022-02-20 00:04:48 +0100
committerx2048 <codeforsmile@gmail.com>2022-03-07 23:45:26 +0100
commit4801bdf45aaaa9238bc52a157e1d25c9d477d81a (patch)
tree7d557eda80e935b62129f40ae683e7685b28bc8f /client
parent25c1974e0d734b6e80d128b325e8e6b506a7401b (diff)
downloadminetest-4801bdf45aaaa9238bc52a157e1d25c9d477d81a.tar.gz
minetest-4801bdf45aaaa9238bc52a157e1d25c9d477d81a.tar.bz2
minetest-4801bdf45aaaa9238bc52a157e1d25c9d477d81a.zip
Correct normal bias for entities
Remove use of magic constants. Apply cameraOffset Calculate distance projected on SM plane
Diffstat (limited to 'client')
-rw-r--r--client/shaders/object_shader/opengl_vertex.glsl10
1 files changed, 7 insertions, 3 deletions
diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl
index 12078f532..185551c58 100644
--- a/client/shaders/object_shader/opengl_vertex.glsl
+++ b/client/shaders/object_shader/opengl_vertex.glsl
@@ -3,6 +3,7 @@ uniform vec3 dayLight;
uniform vec3 eyePosition;
uniform float animationTimer;
uniform vec4 emissiveColor;
+uniform vec3 cameraOffset;
varying vec3 vNormal;
@@ -110,10 +111,13 @@ void main(void)
// 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.
- float distanceToPlayer = length((eyePosition - worldPosition).xyz) / f_shadowfar;
+ 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 = 1.0 / f_textureresolution;
- texelSize *= f_shadowfar * perspectiveFactor / (bias1 / perspectiveFactor - texelSize * bias0) * 0.15;
+ 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;