Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
3 replies to this topic

#1 gchewood   Members   -  Reputation: 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:
http://www.gamedev.n...ng-shadow-maps/

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:

problem.jpg

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);
			lightViewMatrix = Matrix.CreateLookAt(shadowCamPos, sphere.Center, Vector3.Up);
			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
	 	   float ShadowMapSize = 1024.0f;
			Vector3 shadowOrigin = Vector3.Transform(Vector3.Zero, lightViewProjectionMatrix);
			shadowOrigin *= (ShadowMapSize / 2.0f);
			Vector2 roundedOrigin =new Vector2((float)Math.Round(shadowOrigin.X), (float)Math.Round(shadowOrigin.Y));
			Vector2 rounding = roundedOrigin - new Vector2(shadowOrigin.X, shadowOrigin.Y); ;
			rounding /= (ShadowMapSize / 2.0f);
			Matrix roundMatrix = Matrix.CreateTranslation(rounding.X, rounding.Y, 0.0f);
			lightViewProjectionMatrix *= roundMatrix;
		}


Sponsor:

#2 Steve_Segreto   Crossbones+   -  Reputation: 1511

Like
0Likes
Like

Posted 20 November 2012 - 12:39 PM

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

#3 gchewood   Members   -  Reputation: 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.


#4 gchewood   Members   -  Reputation: 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.

Any advice is welcome!




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.



PARTNERS