• Advertisement
Sign in to follow this  

DirectX shadow mapping

This topic is 2479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement