From 63db565fd7703b926d6fb185c1d6e833cd58aab0 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 9 Feb 2014 19:42:22 +0100 Subject: [PATCH] Shadow: Better bias. --- data/shaders/sunlightshadow.frag | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index db96b7855..418bfa59e 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -19,8 +19,6 @@ out vec4 Diff; out vec4 Spec; out vec4 SpecularMap; -const float tolerance_z = 0.001; - vec3 DecodeNormal(vec2 n) { float z = dot(n, n) * 2. - 1.; @@ -76,8 +74,11 @@ void main() { // shadowcoord.xy += vec2(dx, dy);*/ float shadowmapz = 2. * texture(shadowtex, shadowtexcoord).x - 1.; + float bias = 0.002 * tan(acos(NdotL)); // According to the slope + // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping + bias = clamp(bias, 0.001, 0.014); - if (shadowmapz > shadowcoord.z - tolerance_z) + if (shadowmapz > shadowcoord.z + bias) { Diff = vec4(NdotL * col, 1.); Spec = vec4(Specular * col, 1.); @@ -92,12 +93,6 @@ void main() { // float moved = (abs(dx) + abs(dy)) * 0.5; - - -// float bias = 0.002 * tan(acos(NdotL)); // According to the slope -// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping -// bias = clamp(bias, 0.001, 0.014); - // float avi = 0.002; // float abi = 0.0025;