Original Post
Hey folks!
Currently I'm working on a shadow mapping implementation for my litte XNA game. Following the tutorial by Matt (aka MJP), I was able to convert his sourcecode to XNA 4.0 - but obviously I'm making some mistakes :-S
Although my depthMap and shadowMap are looking good, the occlusionMap does not. It's a bit hard to describe, so let the pictures speak ;-)

Matt is using CCW culling in his shaders (sample homepage), which gives the results from above. For me it would be a little more logical, if the depthMap and shadowMap would also show the plane beneath the cube. This could be achived by using CW culling order but still does not solve the issue.
I think there might be some kind of error in the occlusion shader, but the understanding of that is way beyond my knowledge.
My light view projection matrix is calculated as:
Any ideas?
Thanks a lot!
Currently I'm working on a shadow mapping implementation for my litte XNA game. Following the tutorial by Matt (aka MJP), I was able to convert his sourcecode to XNA 4.0 - but obviously I'm making some mistakes :-S
Although my depthMap and shadowMap are looking good, the occlusionMap does not. It's a bit hard to describe, so let the pictures speak ;-)

Matt is using CCW culling in his shaders (sample homepage), which gives the results from above. For me it would be a little more logical, if the depthMap and shadowMap would also show the plane beneath the cube. This could be achived by using CW culling order but still does not solve the issue.
I think there might be some kind of error in the occlusion shader, but the understanding of that is way beyond my knowledge.
My light view projection matrix is calculated as:
protected void CalculateFrustum(NiceLightDirectional light, NiceCameraAbstract camera)
{
// Shorten the view frustum according to the shadow view distance
Matrix cameraMatrix = camera.WorldMatrix;
// Find the centroid
Vector3 frustumCentroid = new Vector3(0, 0, 0);
for (int i = 0; i < 8; i++)
frustumCentroid += frustumCornersWS;
frustumCentroid /= 8;
// Position the shadow-caster camera so that it's looking at the centroid,
// and backed up in the direction of the sunlight
float distFromCentroid = MathHelper.Max((camera.FarPlane - camera.NearPlane), Vector3.Distance(frustumCornersVS[4], frustumCornersVS[5])) + 50.0f;
Matrix viewMatrix = Matrix.CreateLookAt(frustumCentroid - (light.Direction * distFromCentroid), frustumCentroid, new Vector3(0, 1, 0));
// Determine the position of the frustum corners in light space
Vector3.Transform(frustumCornersWS, ref viewMatrix, frustumCornersLS);
// Calculate an orthographic projection by sizing a bounding box
// to the frustum coordinates in light space
Vector3 mins = frustumCornersLS[0];
Vector3 maxes = frustumCornersLS[0];
for (int i = 0; i < 8; i++)
{
if (frustumCornersLS.X > maxes.X)
maxes.X = frustumCornersLS.X;
else if (frustumCornersLS.X < mins.X)
mins.X = frustumCornersLS.X;
if (frustumCornersLS.Y > maxes.Y)
maxes.Y = frustumCornersLS.Y;
else if (frustumCornersLS.Y < mins.Y)
mins.Y = frustumCornersLS.Y;
if (frustumCornersLS.Z > maxes.Z)
maxes.Z = frustumCornersLS.Z;
else if (frustumCornersLS.Z < mins.Z)
mins.Z = frustumCornersLS.Z;
}
// Create an orthographic camera for use as a shadow caster
const float nearClipOffset = 100.0f;
Matrix c_ProjectionMatrix;
Matrix.CreateOrthographicOffCenter(mins.X, maxes.X, mins.Y, maxes.Y, -maxes.Z - nearClipOffset, -mins.Z, out c_ProjectionMatrix);
Matrix.Multiply(ref viewMatrix, ref c_ProjectionMatrix, out lightCameraViewProjection);
}Any ideas?
Thanks a lot!