Hello,
I am trying to use shadow mapping in my game. I ported some sample code over and finally have it working for the most part. However, I am getting some bad artifacts whenever an object which casts a shadow leaves the view frustum of the light, I think. As the object crosses the edge of the frustum boundary, the shadow spills out across the entire terrain.
I read some tutorials which suggested checking to make sure shadowCoord.w is > 0, where shadowCoord is the coordinate used to access the shadowMap:
textureProj(shadowMap, shadowCoord);
But this is not working for me. Here is the code for my frag shader. The (version >= 140) stuff is to differentiate between Mac and iOS.
void main()
{
float shadow = 1.0;
#if VERSION >= 140
if (shadowCoord.w > 0.0)
shadow = textureProj(shadowMap, shadowCoord);
fragColor = vec4(colorVarying.xyz * ((1.0 - kShadowAmount) + kShadowAmount * shadow), colorVarying.w);
#else
if (shadowCoord.w > 0.0)
shadow = shadow2DProjEXT(shadowMap, shadowCoord);
gl_FragColor = vec4(colorVarying.xyz * ((1.0 - kShadowAmount) + kShadowAmount * shadow), colorVarying.w);
#endif
}
Anyone know how to fix it? Here are some pictures of what is happening. Do I need to make my light frustum large enough to encompass all the objects? Or is there a way to have it slide gracefully out of the frustum without bleeding the shadows all across the landscape? I don’t care that much if the faraway objects do not have shadows, but I can’t have the bleed artifacts.
[ATTACH=CONFIG]386[/ATTACH]
Thanks
Bob
Thanks
Bob