Jump to content
  • Advertisement
Sign in to follow this  
Ethanph

about using depth buffer

This topic is 4228 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

Hi, I'd like to ask one easy question, because i am just a learner I want to copy the data from texture to depth buffer, then draw a quad with a specific depth to select the right elements in the depth buffer. My code looks like this: Device->CreateDepthStencilSurface(8,8,D3DFMT_D16,D3DMULTISAMPLE_NONE, 0, true, &pDepthSurface, NULL ); Device->UpdateSurface(pTexSurface, 0, pDepthSurface, 0);//pTexSurface with the format DFMT_A4R4G4B4的texture Device->SetDepthStencilSurface(pDepthSurface); Device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); Device->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESS ); //then draw a blank why there is nothing in the screen? I'd like to know if my method is right? Thanks!!!

Share this post


Link to post
Share on other sites
Advertisement
From The Documentation:
Quote:

Remarks
This method is similar to CopyRects in DirectX 8.
This function has the following restrictions.
[snip]
  • The surface format cannot be a depth stencil format.
  • I.e. you can't use UpdateSurface to copy to/from a depth buffer. You should really be using the debug runtimes (see the Forum FAQ) and checking your return values. Either of those would show you that UpdateSurface() is failing (Probably with D3DERR_INVALIDCALL).

    Generally, touching the depth buffer in any way is A Bad Thing. Video cards are free to use whatever format they feel like for the depth buffer, including compressing it if they wish.

    What exactly are you trying to do? I mean, why do you want to alter the depth buffer?

    Share this post


    Link to post
    Share on other sites
    Actually, I am following my advisor to do some research about GPGPU(General Purpose GPU).we try to simulate some database operations using GPU. We have implemented sorting. Now I try to compare between an attribute and a constant.

    The method is like this:
    First the attribut values should be stored in depth buffer, then render a screen filling quadrilateral with depth "d".So the hardware will use the comparison function for testing each attributes value stored in the depth buffer against "d"

    If anyone also is interested in this subject, I could share more.
    I am just a newbie about DirectX programming. So I hope you would give me some help. I really appreciate.

    Thanks!

    Share this post


    Link to post
    Share on other sites
    You might be able to store contents in the depth buffer by using a pixel shader. Pass in a screen-aligned texture with the appropriate data in and then use the pixel shader to write out a depth value. Although, as Steve pointed out - messing with the depth buffer isn't usually a good idea if you want full performance.

    You might be able to simulate the same thing quicker using the clip()/texkill instruction or fixed-function alpha testing.

    But I'd personally dig into the stencil buffer for comparison operations - you can put the reference value in very quickly using Clear() and then just render a screen-aligned quad with your real data in and perform the test. Putting your per-pixel data in a texture is much easier [smile]

    hth
    Jack

    Share this post


    Link to post
    Share on other sites
    Thanks for your suggestions.But unfortunately, i have had a talk with my advisor, I still have to copy the data into the depth buffer, because we have a series of operations based on it.


    So dear jollyjeffers, I didn't understand your method very well.So in which pass actually I copy the data from texture to the depth buffer?

    Thanks!

    Share this post


    Link to post
    Share on other sites
    Regarding Jack's (jollyjeffers') first method, define a DEPTH output for your pixel shader, and write the texture value there.

    But I'd suggest going with clip(), as Jack suggested. There's no real reason to use the depth for this, in particular since you don't want to use it normally. A floating point texture could be more straightforward and more accurate. You can do the comparison inside the pixel shader and clip().

    I'd go even further than that, and suggest that you don't use a 3D API at all. ATI has CTM (works for the X1x00 family), NVIDIA has CUDA (for the 8800 family), and both are likely to provide better results, since they're geared towards GPGPU work and not graphics, and can expose the underlying hardware much better.

    Share this post


    Link to post
    Share on other sites
    Hi ET3D

    Your suggestion is very useful, actually we have contacted nVidia, and got the CUDA, but my advisors should spend a period to decide if we will use it. Recently we just follow one paper from Naga.

    Maybe I will talk to my advisors again and make a decision

    Share this post


    Link to post
    Share on other sites
    Dear All:

    Thanks for your suggestions. I have used pixel shader to solve this problem. Then, unfortunately, next I need to read the data from depth buffer, I still meet trouble. Should I first do it like this?

    device->GetDepthStencilSurface(pSurface);

    Then next step how could I see the data in this surface? It seem unlockable...

    BTW, can I just create an empty surface? then copy the data to the empty surface using updatesurface. But I don't know how to create an empty surface...

    Share this post


    Link to post
    Share on other sites
    If your card supports a lockable depth buffer, you can define that at device creation time. However, IIRC you'd be limited to 16 bit Z with current cards.

    I'd suggest outputting the Z to a render target (not the Z buffer) and reading that, since you create the Z manually anyway.

    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!