Shadow WIP stage 2

- fix cel-shading
This commit is contained in:
Ayumiwii
2016-02-10 11:48:44 +01:00
parent ecd823cb9f
commit 6af167675d
3 changed files with 57 additions and 45 deletions
+19 -13
View File
@@ -124,7 +124,8 @@ vec2 poissonDisk[4] = vec2[](
float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture)
{
float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005);
float bias = 0.005;
//float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005);
// perform perspective divide
vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w;
// Transform to [0,1] range
@@ -136,21 +137,26 @@ float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampl
//float currentDepth = positionLightSpace.z;
float currentDepth = projCoords.z;
// Check whether current frag pos is in shadow
//float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
// float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
//float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
float shadow = 0.0;
//soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results:
vec2 texelSize = 1.0 / textureSize(depthTexture, 0);
for(int x = -1; x <= 1; ++x)
//float shadow = 0.0;
////soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results:
//vec2 texelSize = 1.0 / textureSize(depthTexture, 0);
//for(int x = -1; x <= 1; ++x)
//{
// for(int y = -1; y <= 1; ++y)
// {
// float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r;
// shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
// }
//}
//shadow /= 9.0;
//
if(projCoords.z > 0.9)
{
for(int y = -1; y <= 1; ++y)
{
float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
}
shadow = 1.0;
}
shadow /= 9.0;
return shadow;