Original Post
Hi So I planned on having simple shadowmapping in my learning app, and I looked on NVIDIA's VSM sample and copy-pasted the code to make the shadowmap texture. Everything seemed fine and I got the linear depth rendered nicely onto my shadowmap texture. But when I tried to apply the texture to a simple vertical quad (just simple basic texturing), the texture got rendered wrong. It looks correct when viewed close, but when I move the camera farther away from the quad, it darkens. This can't be my shader's fault because its a simple float4 color = SMtexture.Sample( samLinear, input.Tex ); return color; I've tried replacing the texture with a loaded bitmap, and this WEIRD DARKENING effect didn't happen. It only happens when I apply that shadowmap texture. So I think the shadowmap somehow screws up texture sampling or something? Resources : ID3D10RenderTargetView* pSMRTV; ID3D10DepthStencilView* pSMDSV; ID3D10Texture2D* pSMZ; ID3D10Texture2D* pSMRT; ID3D10ShaderResourceView* pSMSRV; ID3D10ShaderResourceView* pSMDepthSRV; In OnD3D10CreateDevice() : UINT SMSize = 1024; //NULL out resources pSMZ = NULL; pSMRT = NULL; pSMDSV = NULL; pSMSRV = NULL; //Create our textures D3D10_TEXTURE2D_DESC Desc; Desc.ArraySize = 1; Desc.CPUAccessFlags = 0; Desc.Format = DXGI_FORMAT_R32G32_TYPELESS; Desc.Width = SMSize; Desc.Height = SMSize; Desc.MipLevels = 0; //Full mip-chain Desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS; Desc.SampleDesc.Count = 1; Desc.SampleDesc.Quality = 0; Desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET; Desc.Usage = D3D10_USAGE_DEFAULT; //Create our renderable 2-component texture array pd3dDevice->CreateTexture2D( &Desc, NULL, &pSMRT); _ASSERT( pSMRT ); pSMRT->GetDesc( &Desc ); iMipLevels = Desc.MipLevels; Desc.Width = SMSize; Desc.Height = SMSize; Desc.CPUAccessFlags = 0; Desc.Usage = D3D10_USAGE_DEFAULT; Desc.Format = DXGI_FORMAT_R32_TYPELESS; Desc.BindFlags = D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE; Desc.MipLevels = 1; Desc.ArraySize = 1; Desc.MiscFlags = 0; //Create our MSAA depth buffer pd3dDevice->CreateTexture2D( &Desc, NULL, &pSMZ ); D3D10_DEPTH_STENCIL_VIEW_DESC DSVDesc; DSVDesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; DSVDesc.Format = DXGI_FORMAT_D32_FLOAT; DSVDesc.Texture2D.MipSlice = 0; //Create our depth stencil view pd3dDevice->CreateDepthStencilView( pSMZ, &DSVDesc, &pSMDSV ); D3D10_RENDER_TARGET_VIEW_DESC RTVDesc; RTVDesc.Format = DXGI_FORMAT_R32G32_FLOAT; RTVDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; RTVDesc.Texture2D.MipSlice = 0; //Create our render target view pd3dDevice->CreateRenderTargetView( pSMRT, &RTVDesc, &pSMRTV ); D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc; SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; SRVDesc.Format = DXGI_FORMAT_R32G32_FLOAT; SRVDesc.Texture2D.MipLevels = iMipLevels; SRVDesc.Texture2D.MostDetailedMip = 0; //Create our shader resource view pd3dDevice->CreateShaderResourceView( pSMRT, &SRVDesc, &pSMSRV ); _ASSERT( pSMSRV ); SRVDesc.Format = DXGI_FORMAT_R32_FLOAT; SRVDesc.Texture2D.MipLevels = 1; pd3dDevice->CreateShaderResourceView( pSMZ, &SRVDesc, &pSMDepthSRV ); _ASSERT( pSMDepthSRV ); ZeroMemory( &ShadowMapVP, sizeof( D3D10_VIEWPORT ) ); ShadowMapVP.Height = SMSize; ShadowMapVP.Width = SMSize; ShadowMapVP.MaxDepth = 1.0f; As I said before, this was copy-pasted from NVIDIA's VSM source code. Is there anything wrong with the texture? Also, I can't seem to change the texture's format. If I change it to anything else than R32G32 it returns an error. Please help I'm a n00b.