1D shadow maps are now working

This commit is contained in:
Magnus Norddahl 2017-03-04 09:14:01 +01:00
parent 0d1deddae5
commit 8515f9720a
3 changed files with 6 additions and 4 deletions

View file

@ -83,7 +83,7 @@ void FShadowMap::UploadLights()
ADynamicLight *light = it.Next();
if (!light) break;
mLightToShadowmap[light] = mLights.Size();
mLightToShadowmap[light] = mLights.Size() / 4;
mLights.Push(light->X());
mLights.Push(light->Y());

View file

@ -158,7 +158,9 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
else
u = dir.x / dir.y * 0.125 + (0.50 + 0.125);
}
return texture(ShadowMap, vec2(u, v)).x < dot(dir, dir) ? 1.0 : 0.0;
dir -= sign(dir); // margin, to remove wall acne
float dist2 = dot(dir, dir);
return texture(ShadowMap, vec2(u, v)).x > dist2 ? 1.0 : 0.0;
}
//===========================================================================

View file

@ -129,8 +129,8 @@ void main()
{
case 0: pixelpos = vec2((gl_FragCoord.x - 128.0) / 128.0, 1.0); break;
case 1: pixelpos = vec2(1.0, (gl_FragCoord.x - 384.0) / 128.0); break;
case 2: pixelpos = vec2((gl_FragCoord.x - 640.0) / 128.0, -1.0); break;
case 3: pixelpos = vec2(-1.0, (gl_FragCoord.x - 896.0) / 128.0); break;
case 2: pixelpos = vec2(-(gl_FragCoord.x - 640.0) / 128.0, -1.0); break;
case 3: pixelpos = vec2(-1.0, -(gl_FragCoord.x - 896.0) / 128.0); break;
}
pixelpos = lightpos + pixelpos * radius;