Simple occlusion test?

Started by
7 comments, last by DeathCarrot 16 years, 3 months ago
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.
Advertisement
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
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.
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.
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.
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.
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 :)
occlusion query became part of the core opengl with version 1.5 so u can use it
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.

This topic is closed to new replies.

Advertisement