# SM Depth Test : Always Shadowed?

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

## Recommended Posts

I'm running into an issue that I haven't seen before and have no idea what's causing it: I have a simple scene with a single light position, a single object, and some ground. My SM is a 2048x2048 R32F texture, along with a D24_S8 depth surface to go along with it. When i do my SM test in the pixel shader, the ground under the object is correctly shadowed, but any terrain BETWEEN the light and the casting object ALSO fails the shadow test. below is the pixel shader line i use to compute if a pixel is shadowed: return (tex2Dproj(sm0Sampler,projCoord0)<(projCoord0.z) / (projCoord0.w); where sm0Sampler is the shadowTexture, projCoord0 = mul(vertex.position,SM_WVPMatrix), SM_WVPMatrix is the world*view*projection of the camera when the scene is rendered from the light's viewpoint, multiplied by the texture biasing matrix. The only solution that I have right now, is given to me when i render out the differences between the shadowmap depth, and PC0.z / PC0.w depth. which shows that the SMD is significantly smaller than the PCD, so that when i render out their differences (SMD-PCD) i get black pixels everwhere that the projected shadow map has depth values associated with it (ie, if there was no pixel written into that xy in the shadow map, the final test passes, and the final pixel is lit) This above points to the possibility that somehow my projection numbers are incorrect when testing against the SMD ? I've messed with moving the near/far planes, as well as the overall position, relative to the object, and nothing seems to get the SMD and PCD in a close enough range to give correct SM results. Has anyone ever rand into this problem that can perhaps point me in a correct direction? FROG!

##### Share on other sites
I'm having a little bit of a hard time understanding the situation (a screenshot or two would really help).

Anyways, first guess is that you're not clearing the shadow map texture. In my experience, when I was not rendering every single object to the SM, I found I had to clear the texture to get it to work.

##### Share on other sites
hmm.. i was assuming that this was a standard problem that has been run into enough that some would recognize it.

I'm unable to post any pic's until later, but i will when i can.

Yes, i'm clearing the entire RT for the shadow map every frame.

FROG!

##### Share on other sites
return (tex2Dproj(sm0Sampler,projCoord0)<(projCoord0.z) / (projCoord0.w);

whats the use of the division there? you divide the result of the comparison by w.. bool / w

shouldn't the division be elswhere in the equation?

thats all i can spot by my eyes right now. else, screenies would be cool, yes

##### Share on other sites
Quote:
 Original post by davepermenreturn (tex2Dproj(sm0Sampler,projCoord0)<(projCoord0.z) / (projCoord0.w);whats the use of the division there? you divide the result of the comparison by w.. bool / wshouldn't the division be elswhere in the equation?thats all i can spot by my eyes right now. else, screenies would be cool, yes

I thought that the / operator took precedence over >? If that isn't the case, then I'd say that's the problem. Also, it seems like you're missing a bracket closing off the tex2DProj function.

##### Share on other sites
I found the problem, and post it here for anyone else to run into.

Turns out D3D Has a different need for it's texutre biasing matrix

//standard texture bias matrix:0.5  0.0  0.0  0.00.0  0.5  0.0  0.00.0  0.0  0.5  0.00.5  0.5  0.5  1.0//D3D texture biasing matrix:0.5  0.0  0.0  0.00.0  0.5  0.0  0.00.0  0.0  1.0  0.00.5  0.5  0.0  1.0

anyhow, thanks for the help everyone.
FROG!

##### Share on other sites
Quote:
Original post by Cypher19
Quote:
 Original post by davepermenreturn (tex2Dproj(sm0Sampler,projCoord0)<(projCoord0.z) / (projCoord0.w);whats the use of the division there? you divide the result of the comparison by w.. bool / wshouldn't the division be elswhere in the equation?thats all i can spot by my eyes right now. else, screenies would be cool, yes

I thought that the / operator took precedence over >? If that isn't the case, then I'd say that's the problem. Also, it seems like you're missing a bracket closing off the tex2DProj function.

depends on where the missing bracket is :D and no, i thought > takes precedence :D

but anyways, it got solved.. :D

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634103
• Total Posts
3015539
×