Jump to content
  • Advertisement
Sign in to follow this  
Sharsnik

Reading from a depth buffer

This topic is 3407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do you set up a depth buffer to read from? I tried creating a texture, setting it to a D3DUSAGE_DEPTHSTENCIL and then setting the depthStencilSurface to it's surface. This worked for the render process (z Buffer functioned normally), but when I use tex2D look ups on the depth map, it returns garbage. So, I thought I'd try copying the depth buffer to a standard texture surface, but this proves troublesome as StretchRect requires similar formats. The first method seems like the way to go.. is there something special I need to do to be able to use tex2D on a depth buffer formatted surface?

Share this post


Link to post
Share on other sites
Advertisement
In D3D9 there's no standard way to read back the contents of a depth-stencil surface in a shader. This functionality was new for D3D10.

There are vendor-specific driver hacks for doing it, both aimed at shadow mapping.

Nvidia

ATI

Share this post


Link to post
Share on other sites
I see. Well.. that's balls.

Well, can I copy the depth buffer somewhere where it can be read?

I'm rendering to a normal/depth map for edge testing, but if I don't include the shadow data in that pass I'll have to render the entire screen geometry again. I could use a non-deferred shadow map, but that wouldn't allow me to use PCF to blend the shadows.

Any other ideas? :/

Edit: Is there any way render more than 4 floats in one pass? Ideally I'd like to be able to do all the deferred maps in one go. I know you can render to multiple targets, but I assume that's just a copy? Or can you specify color[n] to set it to a different target?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sharsnik
Well, can I copy the depth buffer somewhere where it can be read?


You can do that if you make it lockable, but that's going to be slooooooooow.


Quote:
Original post by Sharsnik
Edit: Is there any way render more than 4 floats in one pass? Ideally I'd like to be able to do all the deferred maps in one go. I know you can render to multiple targets, but I assume that's just a copy? Or can you specify color[n] to set it to a different target?


You can put whatever data you want in each target, by using color[n]. This is very common for deferred rendering where you'll write out depth, normals, diffuse material, specular material, etc. in one pass.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
You can put whatever data you want in each target, by using color[n]. This is very common for deferred rendering where you'll write out depth, normals, diffuse material, specular material, etc. in one pass.


Cool, yeah.. I'm checking this out now.

It seems that my render targets are sharing alpha values, however.

If color0.a == 1 then render target 2 gets color1, if not it blends in with the back buffer. This will be a problem for the decal pass, as decals are most certainly going to need alpha...

I'm really not sure what's going on with this method of rendering (Well, I get the theory but there's a lot of new semantics), so if you could direct me to a tutorial, or something, that'd help a lot.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!