- fix diagonal linear shadow map artifact

This commit is contained in:
Magnus Norddahl 2018-10-04 00:46:17 +02:00
parent 51dfc82153
commit 36946a47fe
2 changed files with 12 additions and 9 deletions

View file

@ -162,17 +162,19 @@ float shadowDirToU(vec2 dir)
{
if (abs(dir.x) > abs(dir.y))
{
float v = dir.y / dir.x * 0.125;
if (dir.x >= 0.0)
return dir.y / dir.x * 0.125 + (0.25 + 0.125);
return (0.25 + 0.125) - v;
else
return dir.y / dir.x * 0.125 + (0.75 + 0.125);
return (0.75 + 0.125) - v;
}
else
{
float v = dir.x / dir.y * 0.125;
if (dir.y >= 0.0)
return dir.x / dir.y * 0.125 + 0.125;
return 0.125 + v;
else
return dir.x / dir.y * 0.125 + (0.50 + 0.125);
return (0.50 + 0.125) + v;
}
}

View file

@ -140,12 +140,13 @@ void main()
if (radius > 0.0)
{
vec2 pixelpos;
switch (int(gl_FragCoord.x) / int(ShadowmapQuality/4.0))
float u = gl_FragCoord.x / ShadowmapQuality * 4.0;
switch (int(u))
{
case 0: pixelpos = vec2((gl_FragCoord.x - float(ShadowmapQuality/8.0)) / float(ShadowmapQuality/8.0), 1.0); break;
case 1: pixelpos = vec2(1.0, (gl_FragCoord.x - float(ShadowmapQuality/4.0 + ShadowmapQuality/8.0)) / float(ShadowmapQuality/8.0)); break;
case 2: pixelpos = vec2(-(gl_FragCoord.x - float(ShadowmapQuality/2.0 + ShadowmapQuality/8.0)) / float(ShadowmapQuality/8.0), -1.0); break;
case 3: pixelpos = vec2(-1.0, -(gl_FragCoord.x - float(ShadowmapQuality*3.0/4.0 + ShadowmapQuality/8.0)) / float(ShadowmapQuality/8.0)); break;
case 0: pixelpos = vec2(u * 2.0 - 1.0, 1.0); break;
case 1: pixelpos = vec2(1.0, 1.0 - (u - 1.0) * 2.0); break;
case 2: pixelpos = vec2(1.0 - (u - 2.0) * 2.0, -1.0); break;
case 3: pixelpos = vec2(-1.0, (u - 3.0) * 2.0 - 1.0); break;
}
pixelpos = lightpos + pixelpos * radius;