Shadow mapping question

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

It’s hard to tell, but probably your shadowCoord is not calculated correctly. At least the code you’ve pasted here looks correct.

This would imply that you can see the edges of the light/shadow frustum inside the camera frustum. Is this correct?
Verify you are not using CLAMP_TO_EDGE wrap S/T wrap mode on your shadow texture. That might explain it. Essentially this would “smear” the casting object infinitely out away from the boundaries of the shadow map.

Do I need to make my light frustum large enough to encompass all the objects?

At least big enough to encompass all the casters.