Shadow: tweak bias to remove acnee

This commit is contained in:
vlj
2014-04-24 18:33:05 +02:00
parent ef07b25202
commit 85e720a58f
2 changed files with 6 additions and 6 deletions

View File

@@ -53,7 +53,7 @@ float getShadowFactor(vec3 pos, float bias, int index)
float sum = 0.;
for (int i = 0; i < 4; i++)
{
sum += texture(shadowtex, vec4(shadowtexcoord + shadowoffset[i] / 2048., float(index), 0.5 * (shadowcoord.z - bias * 0.01) + 0.5));
sum += texture(shadowtex, vec4(shadowtexcoord + shadowoffset[i] / 2048., float(index), 0.5 * shadowcoord.z + 0.5 + bias));
}
return sum / 4.;
}
@@ -88,8 +88,8 @@ void main() {
// }
// Shadows
float bias = 0.002 * tan(acos(NdotL)); // According to the slope
bias = clamp(bias, 0.001, 0.014);
float bias = 0.005 * tan(acos(NdotL)); // According to the slope
bias = clamp(bias, 0., 0.01);
float factor;
if (xpos.z < 5.)
factor = getShadowFactor(xpos.xyz, bias, 0);

View File

@@ -37,7 +37,7 @@ vec3 getShadowFactor(vec3 pos, float bias)
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
if (shadowtexcoord.x < 0. || shadowtexcoord.x > 1. || shadowtexcoord.y < 0. || shadowtexcoord.y > 1.)
continue;
return cascadeColor[i] * texture(shadowtex, vec4(shadowtexcoord, float(i), 0.5 * (shadowcoord.z + bias * 0.001) + 0.5));
return cascadeColor[i] * texture(shadowtex, vec4(shadowtexcoord, float(i), 0.5 * shadowcoord.z + 0.5 + bias));
}
return vec3(1.);
}
@@ -61,8 +61,8 @@ void main() {
vec3 outcol = NdotL * col;
// Shadows
float bias = 0.002 * tan(acos(NdotL)); // According to the slope
bias = clamp(bias, 0.001, 0.014);
float bias = 0.005 * tan(acos(NdotL)); // According to the slope
bias = clamp(bias, 0., 0.01);
vec3 factor = getShadowFactor(xpos.xyz, bias);
Diff = vec4(factor * NdotL * col, 1.);
Spec = vec4(factor * Specular, 1.);