   Just need to render depth buffer
  Hi,I just want to render a depth buffer I created.  I used CreateTexture with these params: D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8I get the surface from it and pass it to SetDepthStencilSurface() and draw some stuff.Now I'm trying to just render the depth texture but I'm confused on how to access the depth info in my pixel shader (tex2D(TextureSampler, In.TextureUV)??) and what my shader's output should be.Thanks   
  Most hardware will not let you read from the depth buffer directly.  One way to get around this would be to render the depth values to a render target instead.  You would still have your depth buffer but also render the same information to a normal render target.What are you trying to do?  Are you trying to visualize a shadow map or something?neneboricua   ;  Hi, Yes, I'm trying to look at my shadow map.I created my depth stencil just like any other texture like so,Quote:hr = m_pD3DDevice->CreateTexture(RenderParams.ShadowMapSizes[0][0], RenderParams.ShadowMapSizes[0][1], 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8, D3DPOOL_DEFAULT, &m_pShadowDepthSten, NULL);I actually do use another texture I use as a render target, and the depth buffer seems to be working properly.  I plan on (eventually) disabling writes to color buffer, and just use the depth texture (I'm following a Hardware Shadow Mapping tutorial by some Nvidia dudes).Thanks,Beny;Quote:Original post by UnfadableI actually do use another texture I use as a render target, and the depth buffer seems to be working properly.  I plan on (eventually) disabling writes to color buffer, and just use the depth texture (I'm following a Hardware Shadow Mapping tutorial by some Nvidia dudes).Remember, you can only do this on Nvidia hardware.  Cards from other manufacturers do not support this.  If you're targeting only Nvidia hardware, then that's fine.  But if you want your application to run on other cards, then take a look at the shadow mapping samples on ATI's developer site.  Those samples use general techniques that will work on any graphics card.To visualize your depth buffer, you will have to render the depth to a normal render target.  This is what you do.  You pass the position of a vertex from your vertex shader to your pixel shader in a texture coordinate register.  That will cause the position to be interpolated.  Then in your pixel shader you can determine how far away from the light source the particular pixel is because you have access to the light's position in a constant register set up by your main application.  Once you've got that distance, you can scale it by the light's maximum range and output it to all three color channels of the render target.To view this target, you don't even need to render it to the screen.  Just run a frame and use D3DXSaveTextureToFile and save the target as a .bmp.  It will be slow but this is just for debugging anyway so its no big deal.neneboricua   