Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using the depth buffer as a texture

Started by Foxhound May 19, 2003 at 4:12 AM 4 replies 7.5k views
Original Post
Foxhound
Foxhound
Hi there, By using the SetRenderTarget in DX you are able to render anything to a texture created with the D3DUSAGE_RENDERTARGET usage. You can select another texture created with the D3DUSAGE_DEPTHSTENCIL to use as depth stencil buffer. I want to render this depth-stencil texture, but when i select this texture and render it to screen it is all white. I tried to select only the r, g, b and a colors with a pixel shader but all values seem to be 1.0f. Does anyone know if it is possible to use a D3DUSAGE_DEPTHSTENCIL texture and render the depth values to screen? thanx!
JovialPeon
JovialPeon
yes, it is possible to do what you want. some effects require the use of a depth buffer as a texture (such as field of view).

however, i believe you cannot write to the depth buffer (texture) while reading from it... or perhaps that''s only if you read from the same pixel you''re writing to. anyway, you should (as a general rule) not write to the surface you are reading from and visa versa. perhaps this might be a problem.

another possability is that your depth buffer was cleared to 1.0f and you have not written to it

that''s just what comes to mind. it may be something else. though it is possible to do what you want.



-tim
-tim
Foxhound
Foxhound
Well, I''ve read some things about field of view. All effects that use depth are rendering the depth to the alpha channel of the colorbuffer by using pixelshaders. I am now doing the same thing and that works ok for now.

I''ve read an article about using the depth buffer as texture and there they said that only the Radeon 9700 support that because it uses float buffer for texture storage or something.
I think that using the depthbuffer as texture is just another feature that will be supported in the near future.... (lets hope so )

Tamer_Malas
Tamer_Malas
Dear Foxhound

would you please be generes and write me a small code how to render a LPDIRECT3DTEXTURE9 using surface or any thing


pleeeeeeeeeeeeeeaaaaaaaaaaaaaseeeeeeeeee
Tmm
Foxhound
Foxhound
Ok, this is what you could do:

- Use CreateTexture to create a texture that the device can render the colors to:
pD3DDevice->CreateTexture(512, 512, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pColorTexture);

- Use CreateTexture to create a texture for the depth buffer (this can also be done with CreateDepthStencilSurface() )
pD3DDevice->CreateTexture(512, 512, 0, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D32, D3DPOOL_DEFAULT, &pDepthTexture);

- Retrieve the surface levels of the two texures (no mipmaps so use level 0)
pColorTexture->GetSurfaceLevel(0, &pColorSurface);
pDepthTexture->GetSurfaceLevel(0, &pDepthSurface);

- Use set render target to start rendering to the textures
gD3DDevice->SetRenderTarget(pColorSurface, pDepthSurface);

- Render as always

check out the DirectX SDK help for more details!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.