Sign in to follow this  

DirectX shadow mapping

Recommended Posts


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

Anyone any Id how i can resolve them

[code]float CalcShadowFactor(float4 projTexC)
// Complete projection by doing division by w. /= 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
When rendering the shadow map:

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this