Shadow WIP stage 2
- fix cel-shading
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user