diff --git a/Shader/bump.fs b/Shader/bump.fs index 75f1fe4..03a0e35 100644 --- a/Shader/bump.fs +++ b/Shader/bump.fs @@ -53,7 +53,7 @@ vec2 get_parallax_offset_uv(vec2 uv, vec3 view_direction) { current_layer_depth += refinement_layer_depth; } - // Referse the UV operation again and return the result + // Reverse the UV operation again and return the result current_uv += uv_refine_shift_per_layer; return current_uv; @@ -78,17 +78,19 @@ float get_shadow(vec4 fragPosLightSpace, vec3 normal) { // get closest depth value from light's perspective (using [0,1] range fragPosLight as coords) mediump float closestDepth = moments.r; + mediump float depth_squared = moments.g; // get depth of current fragment from light's perspective mediump float currentDepth = projCoords.z; // check whether current frag pos is in shadow - float p = step(projCoords.z, moments.x); + float p = step(currentDepth, closestDepth); // We divide by this later, so make sure it's not exactly 0 // It seems like it should always be 0.0, but due to interpolation it's not -- it increases with the deviation! // A larger second parameter to max() means more blur (but also more light bleeding) - float variance = max(moments.y - moments.x * moments.x, (-0.01 + (currentDepth - closestDepth) * 0.7) * 0.1); + float variance = max(depth_squared - closestDepth * closestDepth, (-0.01 + (currentDepth - closestDepth) * 0.7) * 0.1); - float d = projCoords.z - moments.x * 1.0; + float d = currentDepth - closestDepth; + // Use linear_step to prevent light bleeding float p_max = linear_step(0.2, 1.0, variance / (variance + d * d));