diff options
Diffstat (limited to 'client/shaders')
-rw-r--r-- | client/shaders/object_shader/opengl_vertex.glsl | 10 |
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; |