Sign in to follow this  
DeathCarrot

Simple occlusion test?

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
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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this