DirectX shadow mapping

Started by
2 comments, last by Hodgman 13 years ago
Hi,

I'm using the book Wordware Introduction to 3D Game Programming with DirectX 10. And i'm trying to implement shadow mapping.
But when i render it i get these triangles colored black
prob1.jpg

Anyone any Id how i can resolve them

float CalcShadowFactor(float4 projTexC)
{
// Complete projection by doing division by w.
projTexC.xyz /= projTexC.w;

// Points outside the light volume are in shadow.
if( projTexC.x < -1.0f || projTexC.x > 1.0f ||
projTexC.y < -1.0f || projTexC.y > 1.0f ||
projTexC.z < 0.0f )
return 0.0f;

// Transform from NDC space to texture space.
projTexC.x = +0.5f*projTexC.x + 0.5f;
projTexC.y = -0.5f*projTexC.y + 0.5f;

// Depth in NDC space.
float depth = projTexC.z;

//gShadowMap.SampleCmpLevelZero( ShadowSampler, pIn.projTexC.xy, pIn.projTexC.z); //

// Sample shadow map to get nearest depth to light.
float s0 = gShadowMap.Sample(gShadowSam, projTexC.xy).r;
float s1 = gShadowMap.Sample(gShadowSam, projTexC.xy + float2(SMAP_DX, 0)).r;
float s2 = gShadowMap.Sample(gShadowSam, projTexC.xy + float2(0, SMAP_DX)).r;
float s3 = gShadowMap.Sample(gShadowSam, projTexC.xy + float2(SMAP_DX, SMAP_DX)).r;

// Is the pixel depth <= shadow map value?
float result0 = depth <= s0 + SHADOW_EPSILON;
float result1 = depth <= s1 + SHADOW_EPSILON;
float result2 = depth <= s2 + SHADOW_EPSILON;
float result3 = depth <= s3 + SHADOW_EPSILON;

// Transform to texel space.
float2 texelPos = SMAP_SIZE*projTexC.xy;

// Determine the interpolation amounts.
float2 t = frac( texelPos );

// Interpolate results.
return lerp( lerp(result0, result1, t.x),
lerp(result2, result3, t.x), t.y);
}


this i the line of code in the shader to calculate the shadowfactor i think here is my error.
Advertisement
Looks like regular shadow acne artefacts. Try tweaking the depth/slope bias state values when rendering the depth view.
Ty for this fast reply.

I supose u mean my SHADOW_EPSILON with bias?
When rendering the shadow map:
http://msdn.microsof...8(v=vs.85).aspx
http://msdn.microsof...8(v=vs.85).aspx

This topic is closed to new replies.

Advertisement