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

Depth buffer reading

Started by lacika Apr 10, 2005 at 2:49 PM 1 replies 1.1k views
Original Post
lacika
lacika
Hi all, I'm trying to do some post processing effect in D3D without using programmable shaders. I'm almost finished, and now I need to read depth buffer data. I'm trying with it for a while now and I'm out of ideas. I can make a d3d device with the D3DFMT_D16_LOCKABLE depth buffer surface, and I can get a lock on it (or at least the LockRect function succeed). I cast the buffer pointers pData member to unsigned short pointer. And I take exactly the same values for all the pixels in the buffer. If I copy the bits to the backbuffer, then I've got a plain green surface. Can anyone show me some WORKING code for reading from the depth buffer? And it is important, that I don't use any programmable shaders. Thx all.
Trip99
Trip99
You cannot read from the depth buffer - it is not allowed. If you think about it , it would require a read back from the graphic card which would be painful. You may be able to use the ztest states to do what you want?
------------------------See my games programming site at: www.toymaker.info
superpig
superpig
You can read from the depth buffer, but you really don't want to. Using a lockable depth buffer prevents the card from applying things like compression (because it needs to keep everything in a D16 format for you to read). Simply having it will slow your app down; locking it, pulling the contents back across the AGP bus, editing them, and sending them back again, is going to be downright painful. If you're planning on doing this in realtime I think you're SOL...

The only way of doing arbitrary depth work that I know of is to use a pixel shader and a floating point texture as a secondary render target. You just copy the pixel's depth value into that float texture as a secondary output. Then you can read from it without any issues (such as the hardware treating it as a shadow map).

Like Trip99 says, though, you may be able to use standard Z testing to achieve effects. What precisely are you trying to do?
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Topic Locked

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

Sign in to reply to this topic.