   Shadow mapping - working weird on different PC
  Hello DirectX gurus. I'll start with the question and then explain it a bit more. So:QUESTION:I've currently added shadow map shadows to my application and it works as supposed. But when I try it on second computer, the shadows are displayed very incorrectly.What can possibly be the source of this behaviour? Where should I focus my attention?EXPLANATION OF THE PROBLEM:The application displays a rather small outdoor square scene surrounded by walls, lit by one directional light, which is casting the shadows.The scene is static and one object moves on it. Scene is not just a flat ground, so it casts also shadows on itself and also the moving object casts shadows.On the second PC, it seems as if it was using light shining from a different pitch then it really is. As some point of the scene, all shadows are ok. When moving from this point "further" from the light, shadows are like growing up unnaturally and on the other direction, shadows are "sinking" below the ground so for example only top branches of a tree are casting shadows like if only they were above the ground and most of the tree below the ground (but the tree is rendered correctly in fact).Rendering sequence:Render from a camera watching the scene from the light's direction and from such height to get the whole scene in the output, using ORTHO projection and near and far planes set as close as possible. Depth information is passed from vertex shader as texcoordoutDepth.xy = outPos.zw;and then written in pixel shader to the textureoutColor = Depth.x / Depth.y;(Idea taken from shadow map example from the SDK)Shadow map is D3DFMT_R32F, 2048x2048.When rendering the objects, vertex shader does this:vPos = mul(iPos, g_worldView);oPos = mul(vPos, g_projection);vPosLight = mul(vPos, g_viewToLightProj); // vPosLight are float4 texcoordsAnd pixel shader compares the depth:float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5, 0.5 );ShadowTexC.y = 1.0f - ShadowTexC.y;float lightAmount = (tex2D(texShadowSampler, ShadowTexC) < vPosLight.z / vPosLight.w) ? 0.0f : 1.0f;  Using PIX for Windows, I found that the shadow map texture is rendered probably correctly. So the problem must be somewhere in the second step.Both computers have the same OS (WinXP) and DX SDK version (August 2006), the application is of course EXACTLY THE SAME.The computers differ in HW (the first one has GF7800GT and the second one, the "wrong one", has GF8600GT), also the second one has the latest nVidia drivers while the first one doesn't.As I said, this alghoritm (taken partly from SDK example) works on one PC and doesn't on the another one. What's the problem? It doesn't give any sence to me :DThx a lot in advance for any hints. If you need more code, please ask for it.   
  I'm not seeing anything obviously wrong...if you can, I would try running with the debug runtimes on the second PC to see if any of your D3D calls are failing or producing otherwise weird results.  You may also want to try running with the reference rasterizer, in case this is a driver-related issue.  It's very possible that one of the drivers is more tolerant of something than the other, and REF device will tell you which one is producing the correct behavior.  Aside from that...I would check your view and projection matrices for the shadow caster as well as the depth values in your shadow map.  Perhaps, if you can, try to set up an identical scene on each PC and see what values you get in your matrices and in a particular texel of the shadow map using PIX.Also on a side note, it's refreshing to see a question that's so nicely laid out.  [smile]   ;  Thx for answer MJP.Quote:Original post by MJPI'm not seeing anything obviously wrong...if you can, I would try running with the debug runtimes on the second PC to see if any of your D3D calls are failing or producing otherwise weird results.This came to my mind also, but it gave no errors or unusual warning.Quote:You may also want to try running with the reference rasterizer, in case this is a driver-related issue.  It's very possible that one of the drivers is more tolerant of something than the other, and REF device will tell you which one is producing the correct behavior.Aside from that...I would check your view and projection matrices for the shadow caster as well as the depth values in your shadow map.  Perhaps, if you can, try to set up an identical scene on each PC and see what values you get in your matrices and in a particular texel of the shadow map using PIX.OK, sounds like a plan :)Quote:Also on a side note, it's refreshing to see a question that's so nicely laid out.  [smile]LOL thx, I'm always trying to make the whole problem one-post to prevent as much of additional questions as possible.;  REF device on the first PC (the only one I can test now) brings the same problem as on the second PC (at least it seems so, it's hard to test it without any FPS).So it seems that the correctly working one is wrong and the badly working one is OK :DStill weird...And problem stays.   ;  I'm completely desperate :(First I thought I found the problem, thought it was in the up vector in view matrix which i had not perpendicular to camera direction.But when I tried top-down light with the following matrices, the problem is still here, working on one PC, not working on second PC :(t = D3DXVECTOR3(0, 0, 0);p = D3DXVECTOR3(0, 6, 0);u = D3DXVECTOR3(0, 0, 1);D3DXMatrixLookAtLH(&g_lightViewMatrix, &p, &t, &u);D3DXMatrixOrthoLH(&g_lightProjMatrix, 21, 21, 0, 7.5f);D3DXMatrixMultiply(&g_lightViewProjMatrix, &g_lightViewMatrix, &g_lightProjMatrix);It behaves completely the same - shadows are correct only at one distance from the light, which in this case means on one height on the terrain (when going uphill, shadows are sinking).It seems the heights stored to the shadow map are taken differently when writing them and when comparing them with a particual pixel to show shadows.How exactly is it with Z and W components and distance from camera (or the near clip plane) on ortho projection? Can there be any possible problem making different behaviour on different GC? Or can it be somewhere in D3DFMT_R32F texture?   ;  OK - for anyone with a similar problem in the future:Problem was in enabled alpha (ALPHABLENDENABLE = TRUE) during shadow map creation.;Quote:Original post by Tom KQTHow exactly is it with Z and W components and distance from camera (or the near clip plane) on ortho projection? Can there be any possible problem making different behaviour on different GC? Or can it be somewhere in D3DFMT_R32F texture?Looks like you solved everything but just for future reference...when you divide z by w (in the pixel shader) the result is eye-space depth that has been scaled to the range between the near and far clip planes of your orthographic projection.