Jump to content
  • Advertisement
Sign in to follow this  
Leo_E_49

OpenGL [Urgent] Depth buffer based occlusion queries?

This topic is 4821 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 go about doing depth buffer based occlusion queries? Is it possible to determine whether one or more pixels of a mesh has passed the depth test? If so, how do you go about doing this? Can such a method be implemented in both OpenGL and Direct3D? My basic understanding is that you would render a value of e.g. 1.0f to a stencil buffer based on depth pass. Then you would tally the number of pixels which passed the depth check and if greater than 0, the object is not occluded. My problem is the tallying part. How would you go about adding up the pixels in the stencil buffer to check whether they are greater than 0?

Share this post


Link to post
Share on other sites
Advertisement
Occlusion queries do exactly this. They will report how many pixels have passed the depth test in a given render. THey're usable in both OGL and D3D -- the only draw back is that their results tend to be delayed.

Share this post


Link to post
Share on other sites
So there's an inbuilt framework for these tests in both OpenGL and Direct3D? Could you provide a link or some functions/interfaces I could look up for how to use them?

Is there any way I can access the stencil buffer manually (perhaps in a pixel shader?). I would like to know in case I want to port this technique to a non-OpenGL or DirectX API, e.g. SPS2.

Share this post


Link to post
Share on other sites
As far as I know the stencil buffer isn't used for occlusion queries in OpenGL (I assume D3D is the same). Look up the ARB_occlusion_query extension. You can't access stencil buffers manually in pixel shaders as far as I know (in fact you can't access any of the output buffers - all the output is fixed function). Accessing stencil buffers and doing occlusion querys are both API specific so there isn't really any general method you can use.

Share this post


Link to post
Share on other sites
In Direct3D, you call Direct3DDevice::CreateQuery to create the query object, use Query::Issue to signal the beginning of the query, render your geometry, issue the 'end' signal, then call Query::GetData to see when the results are ready (and retrieve them if they are).

Share this post


Link to post
Share on other sites
Oohh, I just had a brain-wave! [grin] What if I do a render to texture of the full scene, with the stencil buffer checking for depth pass? Then I lock the texture and count the number of pixels which passed the test! In theory this could even work accurately with alpha blended sprites.

Do you think this is a viable strategy?

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
No.


As hilariously rude as that was, he's right. Locking textures and manually counting pixels is the fastest way to get the slowest renderer.

[Edited by - Cypher19 on August 30, 2005 12:43:01 PM]

Share this post


Link to post
Share on other sites
What if I do it on a low resolution texture, say 1/4 the screen size, it would still give good results if done that way. Although, I'm sure it would be a lot slower than the hardware test, could it work real time? Would it be possible to tally the pixels with a pixel shader somehow? I wonder if you know any way to implement it on the PS2?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!