Skip to content

Commit 6476a0a

Browse files
committed
pcf
1 parent 81a83df commit 6476a0a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Shaders/ShadowMapping/PCF.glsl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
float ShadowPCF(vec4 sc, uint cascadeIndex)
1+
float ShadowPCF(vec4 shadowCoord, uint cascadeIndex)
22
{
33
ivec2 texDim = textureSize(shadowMap, 0).xy;
44
float scale = shadowUBO.pcfScale;
55
float dx = scale * 1.0 / float(texDim.x);
66
float dy = scale * 1.0 / float(texDim.y);
77

88
vec3 N = normalize(normal);
9-
vec3 lightDir = normalize(shadowUBO.lightPosition.xyz - worldPos);
10-
float bias = max(shadowUBO.shadowMaxBias * (1.0 - dot(N, lightDir)), shadowUBO.shadowMinBias);
9+
vec3 L = normalize(shadowUBO.lightPosition.xyz - worldPos);
10+
float NoL = dot(N, L);
11+
float bias = max(shadowUBO.shadowMaxBias * (1.0 - NoL), shadowUBO.shadowMinBias);
1112

1213
// TODO Find out a better blurring technique concerning multiple shadow maps
1314
const int range = 1;
@@ -18,8 +19,8 @@ float ShadowPCF(vec4 sc, uint cascadeIndex)
1819
for (int y = -range; y <= range; y++)
1920
{
2021
vec2 off = vec2(dx * x, dy * y);
21-
float dist = texture(shadowMap, vec3(sc.st + off, cascadeIndex)).r;
22-
shadow += (sc.z - bias) > dist ? 0.1 : 1.0;
22+
float dist = texture(shadowMap, vec3(shadowCoord.st + off, cascadeIndex)).r;
23+
shadow += (shadowCoord.z - bias) > dist ? 0.1 : 1.0;
2324
count++;
2425
}
2526
}

0 commit comments

Comments
 (0)