From 955eee5a602a4697ae5429b71bdea40f7927cf10 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 19 Jan 2015 00:40:28 +0100 Subject: [PATCH] Linearization of depth buffer. Didn't change graphics in any way. --- Shader/phong.fsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 77cb8d6..aae9127 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -51,11 +51,12 @@ vec2 poissonDisk[16] = vec2[]( ); float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) { + float nearPlane = 0.1; float visibility = 1.0; float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0))); bias = clamp(bias, 0.0, 0.01); - for (int i=0; i<4; i++) { - visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/700.0, (shadowCoord.z - bias)/shadowCoord.w))); + /*for (int i=0; i<4; i++) { + visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/700.0, (2.0 * nearPlane)/(farPlane+ nearPlane - shadowCoord.z * (farPlane - nearPlane))- bias))); } if (visibility == 1.0-(directionalIntensity/16)*4) { @@ -63,10 +64,11 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) { } else if (visibility != 1.0) { for (int i=0; i<12; i++) { - visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/700.0, (shadowCoord.z - bias)/shadowCoord.w))); + visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/700.0, (2.0 * nearPlane)/(farPlane+ nearPlane - shadowCoord.z * (farPlane - nearPlane))- bias))); } - } - return visibility; + }*/ + visibility = texture(shadowMap, vec3(shadowCoord.xy, (shadowCoord.z - bias)/shadowCoord.w)); + return (2.0 * nearPlane) / (farPlane + nearPlane - visibility * (farPlane - nearPlane)); } float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {