Implemented poisson sampling.

This commit is contained in:
Faerbit 2014-12-04 14:53:07 +01:00
parent b38e24c3db
commit e005c97439

View File

@ -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)));
}
}
}