Sign in to follow this  

Simple occlusion test?

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

I'm wondering what would be the easiest/quickest way to check whether a particular point is begin occluded in the viewport? This is for rendering a lens flare. Should I render a pass into a single pixel FBO and check whether it was written to somehow, or is there a smarter way? Thanks.

Share this post


Link to post
Share on other sites
if u want a gpu version (ie not casting a ray or cylinder yourself through your scenegraph)
then
#ifndef GL_ARB_occlusion_query
is what u want

Share this post


Link to post
Share on other sites
you can use occlusion query to check how many pixels passed.
render lens billboard and get how many pixel are visible, use this result to do fade in/out effect.

Share this post


Link to post
Share on other sites
Occlusion query isn't core GL2.0 functionality is it? If not, I'm not allowed to use it, unfortunately (it's for a course at uni for which we're only allowed to use 2.0 core stuff)... Which means I guess I can't use an FBO for RTT either, but anyway.

Share this post


Link to post
Share on other sites
If you want to do this type of test on the GPU without occlusion querys, then I can offer a different approach. However, this approach is going to cost you (in performance that is), so let me know if you are interested before I go into this.

Share this post


Link to post
Share on other sites
If it's not too complex to implement then I'd very much like to hear it, performance isn't much of an issue as the scene is quite simple in terms of geometry.

Share this post


Link to post
Share on other sites
Ok then. What you can do is change the viewports to include only the pixels you want to check. Then you create a render target with the same pixels size and clear it to black. After that you render the whole scene without lights and other effects. During that render pass, you color all objects that are potential occluders in black and the object you check for occlusion (in your case a billboard if I am not mistaken) in white (flat shades – normals and other calculations that result in gradient colors should be avoided).
The result of this operation is a target with white pixels where the object you checked was not occluded. At this point I assume you want the result back in the CPU (this is the part that reduces performance), so you have to lock the target, go over all the pixels and check how many of them are white.
Since you asked for the simple version, this implementation is not optimized at all. If you implement this approach and want to optimize it, contact me again.

Whoo, that was a long one :)

Share this post


Link to post
Share on other sites
occlusion query became part of the core opengl with version 1.5 so u can use it

Share this post


Link to post
Share on other sites
Hmm, seems occlusion queries are indeed core features, I guess I didn't look hard enough before (I just skimmed through the spec). Thanks for the heads up zedz.

Thanks doronf, sounds good (quite similar, although somewhat more complex than my initial plan), although since occlusion queries are core features I'll be using them instead.

Share this post


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