   Shadow Mapping Problems
  Okay, so I'm trying to implement shadow mapping into a 3d engine/demo that i'm writing. At this stage, i'm just trying to render the shadow map from the light's persective. Seemed simple enough, but I was wrong. I am outputting the shadow map texture that i'm rendering as a sprite just so that I can see what is going on. I'm using vertex and pixel shaders to do this stuff. My problem is that no matter what i do, i always get a depth value of 1.0 (or a value greater that is being clamped to 1.0) from transforming the vertex passed to the shader by the light's view and projection matrix. The depth is what is supposed to be written to the map, but all i get is one, making it useless. If I clear the map to 1, the display shows a completely white texture after rendering, and if i clear it to black, i can see the models from the persective that I'm supposed to be seeing them from, except everything that was rendered is white, giving no definition to the image. It looks like ambient lighting... kind of. You get the idea. I am completely stumped now. My code seems to be almost identical to two other shadow map sources that work fine. Any help that you guys could give me would be greatly appreciated. Here's some of the relevant code. Let me know if you need anything else.Shader code for shadow map:struct PS_OUTPUT{float4 Colour: COLOR;};struct VS_INPUT_SHADOW{float4 Pos: POSITION;};struct VS_OUTPUT_SHADOW{float4 Pos: POSITION;float Depth: TEXCOORD0;};VS_OUTPUT_SHADOW VS_Shadow_Dir(VS_INPUT_SHADOW input){VS_OUTPUT_SHADOW Out = (VS_OUTPUT_SHADOW) 0;Out.Pos = mul(input.Pos, matLightViewProj);Out.Depth = Out.Pos.z;return Out;}PS_OUTPUT PS_Shadow_Dir(VS_OUTPUT_SHADOW input){PS_OUTPUT Out = (PS_OUTPUT) 0;Out.Colour = input.Depth;return Out;}Texture creation:// Create Shadow map texture and surfacesif (FAILED(g_pDevice->CreateTexture(SHADOWMAP_SIZE, SHADOWMAP_SIZE, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R32F,D3DPOOL_DEFAULT, &m_pShadowMap, NULL))){Report_Error("Could not create shadow map texture.");return false;}if (FAILED(m_pShadowMap->GetSurfaceLevel(0, &m_pShadowMapSurf))){Report_Error("Could not fetch shadow map texture surface.");return false;}if (FAILED(g_pDevice->CreateDepthStencilSurface(SHADOWMAP_SIZE, SHADOWMAP_SIZE, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0,TRUE, &m_pShadowMapZ, NULL))){Report_Error("Could not create depth stencil surface for shadow map.");return false;}(I've also tried it with the texture using the D3DFMT_A8R8G8B8 format)Actual Rendering code:   // Create Shadow Map// Save other surfaces and set new ones for mapg_pDevice->GetRenderTarget(0, &pOldBackBuffer);g_pDevice->GetDepthStencilSurface(&pOldZBuffer);g_pDevice->SetRenderTarget(0, m_pShadowMapSurf);g_pDevice->SetDepthStencilSurface(m_pShadowMapZ);m_pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);switch (ls->Type)// use the pass for the right type of light{case DIR:effect->BeginPass(SHADOW_PASS_DIR);break;default:effect->BeginPass(SHADOW_PASS_DIR);break;}// Do render stuff here for map// view and projection matrix for the light sourceD3DXMATRIX mView, mProj;D3DXVECTOR3 Lookat = D3DXVECTOR3(0,0,0);//ls->Position + ls->Direction;D3DXVECTOR3 UpVec    = D3DXVECTOR3(0.0f, 1.0f, 0.0f);D3DXMatrixLookAtLH(&mView, &ls->Position, &Lookat, &UpVec);D3DXMatrixPerspectiveFovLH(&mProj, 0.5f, 1.0f, 1.0f, 1000.0f);D3DXMATRIX lightVP = mView * mProj;effect->SetMatrix("matLightViewProj", &lightVP);StaticBuffer *tempBuf;for (UINT i = 0; i < m_pVCMan->GetNumSB(); i++){tempBuf = m_pVCMan->GetSB(i);effect->CommitChanges();RenderStaticBuffer(tempBuf);}effect->EndPass();// Restore previous surfacesg_pDevice->SetRenderTarget(0, pOldBackBuffer);g_pDevice->SetDepthStencilSurface(pOldZBuffer);pOldBackBuffer->Release();pOldZBuffer->Release();ls is a light struct containing information about the light, and the staticbuffer is the models that are being rendered.Thanks in advance.   