   Shadow map stretch problem.
  Attempting to do shadow maps in DirectX with shaders.  The mini picture in the bottom right is the shadow depth map.  Everything is fine in this picture:http://morgar.dhs.org/shadow1.jpgHowever whenever the moving box gets to the edge of the shadowmap, it stretches the shadow across the rest of the geometry:http://morgar.dhs.org/shadow2.jpgThe sampler state for my shadow map texture is set to clamp, but in the examples that I have seen from the DirectX samples and other sites have it set to clamp as well.  Anyone have any idea what the issue is?  Sorry for the noobness of this question.   
  well, if you clamp the shadow map, and the box hits the edge of the map (so that the edge is in shadow), the shadow will extend into the "clamped" region.Traditionally, clamp works with shadow maps because only areas that are shadowed get lit by the light (that is, there's no place that the light shines that isn't also within the shadow map projection).  It looks like you're using a single shadow map for a point light, which is quite unusual.  You have a few options:#1: use a cube map for your shadow map (that way, the shadow map exists for all directions that the light shines in, which is a requirement of accurate shadowing)#2: convert your light into a spotlight (where the spotlight's projected area matches that of the shadowmap)#3: use "border" instead of "clamp", with a border color that corresponds to "totally in shadow".  This is probably what you are looking to do, but I don't think it's the best way (Because shadows of things will suddenly end at the border of the shadow map, which would look unusual).Hope that helps!   ;  Yeah actually it helped explain what was going on pretty good :).  I figured that I'd have to go to Cube maps anyways, but this has presented a new problem unfortunately.for (DWORD i=0;i<6;i++){D3DXVECTOR3 vLookatPt, vUpVec;D3DXMATRIX mView, mProj;D3DXMatrixIdentity(&mView);D3DXMatrixPerspectiveFovLH(&mProj, D3DX_PI/2, 1, fNear, fFar);switch(i){case D3DCUBEMAP_FACE_POSITIVE_X:vLookatPt = D3DXVECTOR3(fFar, 0.0f, 0.0f)+g_pLightList[0].m_vPos;vUpVec    = D3DXVECTOR3(0.0f, 1.0f, 0.0f);break;case D3DCUBEMAP_FACE_NEGATIVE_X:vLookatPt = D3DXVECTOR3(-fFar, 0.0f, 0.0f)+g_pLightList[0].m_vPos;vUpVec    = D3DXVECTOR3( 0.0f, 1.0f, 0.0f);break;case D3DCUBEMAP_FACE_POSITIVE_Y:vLookatPt = D3DXVECTOR3(0.0f, fFar, 0.0f)+g_pLightList[0].m_vPos;vUpVec    = D3DXVECTOR3(0.0f, 0.0f,-1.0f);break;case D3DCUBEMAP_FACE_NEGATIVE_Y:vLookatPt = D3DXVECTOR3(0.0f,-fFar, 0.0f)+g_pLightList[0].m_vPos;vUpVec    = D3DXVECTOR3(0.0f, 0.0f, 1.0f);break;case D3DCUBEMAP_FACE_POSITIVE_Z:vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, fFar)+g_pLightList[0].m_vPos;vUpVec    = D3DXVECTOR3( 0.0f, 1.0f, 0.0f);break;case D3DCUBEMAP_FACE_NEGATIVE_Z:vLookatPt = D3DXVECTOR3(0.0, 0.0f,-fFar)+g_pLightList[0].m_vPos;vUpVec    = D3DXVECTOR3(0.0f, 1.0f, 0.0f);break;}HRESULT hr=g_pCubeTexture->GetCubeMapSurface((D3DCUBEMAP_FACES)i, 0, &g_pCubeFaces);hr=g_pD3DDevice->SetRenderTarget (0,g_pCubeFaces); }VertexShader:texture CubeMap;samplerCUBE CubeMapSamp = sampler_state{    Texture = <CubeMap>;    MinFilter = LINEAR;    MagFilter = LINEAR;    AddressU = Clamp;    AddressV = Clamp;    AddressW = Clamp;    };Out.CubeMapUV=inPos - fLightPos[0];PixelShader:float ShadowMapF=texCUBE(CubeMapSamp, CubeMapUV);if ((Depth-ShadowMapF) > 0.0f){// darkness}Just basically posted the appropriate lines of code.  So basically the problem is that it only uses the negative Z portion of the cube map, no matter what I put in there.The depth maps themselves are accurate since I check them out by saving to file.I've tried a myriad of different things, but have not be able to solve the problem.So basically I must be doing something wrong with the accessing of the cube map, if anyone can help, or needs more info.   ;  I figured I would just continue this thread.  I changed my method to using quadratic distance instead of depth, which has helped alot.  However I believe there is something wrong with my code because I get results like this:http://morgar.dhs.org/cubeshadow1.jpgand from a different angle this:http://morgar.dhs.org/cubeshadow2.jpgMy shadow map pass uses the following relevant lines:Vertex Shader:float4 Position=mul(inPos,LightProj);Out.Pos=Position;Out.shadowdir=Out.Pos*(1/fFar);  Pixel Shader:return dot ( shadowdir, shadowdir);And for the normal render pass:Vertex Shader:Out.CubeMapUV=((inPos-fLightPos[0])* (1/fFar));Pixel Shader:float QuadDistance=dot(CubeMapUV,CubeMapUV);float ShadowMapF=texCUBE(CubeMapSamp, CubeMapUV);float ShadowTerm=(ShadowMapF > (QuadDistance - 0.0008f)) ? 1.0f : 0.0f;if (ShadowTerm==0.0f){  // darkness  Diff=float4(0,0,0,1);}else{   float3 varL=normalize(inPos.xyz-fLightPos[0]);   float Result=dot(varL,Normal);   if (Result>0)   { float temp=1.0-(len/fFar); float4 res=mul(vLightColor,Result); Diff+=mul(temp,res);   }}return tex2D(DiffuseSampler, Tex)*Diff;As you can see there is something off with the shadowmap itself, or the retrieval of the shadow information from the map.  Any help would be appreciated if anyone can see a problem thanks.   