• Create Account

## Problem with stable shadow mapping.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1gchewood  Members

236
Like
0Likes
Like

Posted 20 November 2012 - 12:14 PM

I'm using a basic orthographic projection to create shadow mapping for a direction light in XNA.

I ran into the (I assume common) problem of the shimmering edges of the shadows as is described in this post:

I implemented the solution described in the post and it works great. HOWEVER, It seems to cut some of the shadows off. I've attached an image showing the problem:

The code I'm using to calculate the matrices can be found below. Playing with a few of the variables, it seems that this gap in the shadow is down to the ExtraBackup variable being too high. If I reduce it from 20 to 0, the shadows are nearly back to normal. However, this obviously creates different problems as not all onscreen models will be caught in the bounding sphere. Someone help!!!!

public void UpdateShadows(Vector3 lightDir, Matrix viewProjection)
{

BoundingFrustum frustum = new BoundingFrustum(viewProjection);

BoundingSphere sphere = BoundingSphere.CreateFromFrustum(frustum);
const float ExtraBackup = 20.0f;
const float NearClip = 1.0f;
float backupDist = ExtraBackup + NearClip + sphere.Radius;
Vector3 shadowCamPos = sphere.Center - (lightDir * backupDist);
float bounds = sphere.Radius * 2.0f;
float farClip = backupDist + sphere.Radius;
lightProjectionMatrix = Matrix.CreateOrthographic(bounds, bounds, NearClip, farClip);
lightViewProjectionMatrix = lightViewMatrix * lightProjectionMatrix;

//Make shadows stable under camera translation
Matrix roundMatrix = Matrix.CreateTranslation(rounding.X, rounding.Y, 0.0f);
lightViewProjectionMatrix *= roundMatrix;
}


### #2Steve_Segreto  Members

2007
Like
0Likes
Like

Posted 20 November 2012 - 12:39 PM

http://msdn.microsoft.com/en-us/library/windows/desktop/ee416324(v=vs.85).aspx

### #3gchewood  Members

236
Like
0Likes
Like

Posted 20 November 2012 - 12:53 PM

Peter Panning eh? Thanks I'll see if I can figure it out.

Edited by gchewood, 20 November 2012 - 12:54 PM.

### #4gchewood  Members

236
Like
0Likes
Like

Posted 20 November 2012 - 02:38 PM

Ok well I've tried playing with the near and far planes, and I've tried altering the depth bias. No luck so far.