From 5abc7bf3af097682592321acbcb96db83db575c9 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 4 Dec 2014 14:53:07 +0100 Subject: [PATCH] Implemented poisson sampling. --- Shader/phong.fsh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 74564e1..5574051 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -26,6 +26,25 @@ uniform float fogEnd; uniform vec4 fogColor; uniform vec3 cameraCenter; +vec2 poissonDisk[16] = vec2[]( + vec2( -0.94201624, -0.39906216 ), + vec2( 0.94558609, -0.76890725 ), + vec2( -0.094184101, -0.92938870 ), + vec2( 0.34495938, 0.29387760 ), + vec2( -0.91588581, 0.45771432 ), + vec2( -0.81544232, -0.87912464 ), + vec2( -0.38277543, 0.27676845 ), + vec2( 0.97484398, 0.75648379 ), + vec2( 0.44323325, -0.97511554 ), + vec2( 0.53742981, -0.47373420 ), + vec2( -0.26496911, -0.41893023 ), + vec2( 0.79197514, 0.19090188 ), + vec2( -0.24188840, 0.99706507 ), + vec2( -0.81409955, 0.91437590 ), + vec2( 0.19984126, 0.78641367 ), + vec2( 0.14383161, -0.14100790 ) +); + void main() { vec3 ambientColor = ambientFactor * ambientColor; @@ -61,15 +80,12 @@ void main() // shadows float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0))); bias = clamp(bias, 0.0, 0.01); - vec3 biasedShadowCoord = vec3(shadowCoord); - biasedShadowCoord.z = shadowCoord.z - bias; float visibility = 1.0; if (shadowCoord.x > 0.0 && shadowCoord.x < 1.0) { if (shadowCoord.y > 0.0 && shadowCoord.y < 1.0) { - visibility = texture(shadowMap, biasedShadowCoord); - //if (texture(shadowMap, vec3(shadowCoord), bias) < shadowCoord.z) { - //visibility = 0.5; - //} + for (int i=0; i<16; i++) { + visibility -= 0.0625*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/700.0, (shadowCoord.z - bias)/shadowCoord.w))); + } } }