Occlusion query failing for fogged occluders

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
I don't know if this is just how it works or not, but it's annoying, and I'm curious if there's a fix, or a workaround.

Anyway, I use occlusion queries to fade out a "glare" around the sun in my game based on how many of the sun's pixels make it through the occlusion test. Works beautifully. You can see the sun smoothly fade out behind tree's leaves, or when a mountain blocks it, etc.

The trouble is, if the occluder is *fogged*, the occlusion query fails ( which is to say, the occludee isn't occluded by fogged fragments ). You can see the sun's glare *through* a tall mountain for example, if that part of the terrain is far enough away to be fogged. But when you move closer, as soon as the terrain goes from being fogged to being not fogged, the occlusion query starts working again.

Can anybody tell me what's happening and how to fix it? I'll post code if anybody's interested but it's pretty generic.
Quote this message in a reply
Moderator
Posts: 435
Joined: 2002.09
Post: #2
I have never used occlusion queries but this seems like an interesting problem so I've given it a few minutes thought.

Some clarification might be useful though. If you are trying for a lens-flare-like effect, the glare *should* be visible in front of the mountain. The issue is that the amount of glare should decrease as more of the sun is behind the mountain. Is that your problem?

If so, it's a bit mysterious to me how the sun can be drawn behind the mountain but the occlusion query say that it's not occluded.

Or are you are seeing the sun itself through the mountain as well? If so, then it makes sense that the occlusion test fails.

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #3
This may be a stupid question, but is the occlusion box for the sun behind the fogged portion? (distance wise) As long as it's solid geometry, and it's present, it *should* work, from what I've seen of occlusion queries.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
Here's a couple screenshots that may help to describe the problem:

Here's the glare drawing even though the sun is occluded by the fogged mountain fragments ( which is drawn over everything else in the scene, but is modulated by the number of fragments of the source -- the sun -- which passed the occlusion query )
[Image: Screenshots-2006-01-06-23.png]

Here, I've walked forward a little bit, so that the hills are no longer fogged. The occlusion query works as expected here, and the glare isn't drawn at all since none of the sun's fragments make it through

[Image: Screenshots-2006-01-06-26.png]

And finally, I've climbed on top of the mountain, and can see the sun in all its glory, and the glare can be seen drawing on top of my "character" for cheap fixed-function "bloom" effect

[Image: Screenshots-2006-01-06-27.png]
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #5
Actually, here's a very constrived example -- I made a flat level with just a conical mountain in the center.

Here I'm walking backward. The mountain's not 100% in fog yet, and occlusion query works as expected.
[Image: Screenshots-2006-01-06-29.png]

Now, I've backed up a little farther (BAM!):
[Image: Screenshots-2006-01-06-30.png]
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
This is on your gf5200, right?
Have you tried this out on a Radeon 9600 or newer?
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
Actually, no I've only got the one powerbook. My coworker has a g5 with 9600 but she's too busy to let me run this on it, I'll have to come in to work early on monday and give it a stab.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #8
Well, I just got back from the gym and my coworker's left, so I tried it out on her machine. Interestingly, occlusion queries *don't work at all* on her dual 2.0 with a 9600. Since my code uses a ray-intersection fallback when a card reports that it doesn't support occlusion queries, and since it wasn't using the ray fallback on her machine, that means it did *say* it had them, they just don't work.

I have to assume, then, that I'm doing something screwy.

That said, it hauls ass on her machine. I was getting 30fps at 1600x1200 with full viewing distance, and 20 with shadows ( everything's a shadow caster, every rock, every tree -- admittedly, my scenegraph culls shadows that won't be visible, but still ). Sweet.

I'll post my code later, I have to go home.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #9
FWIW, the MESA occlusion sample works just fine on my 9600 here.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #10
Are you sure that it is the fog and not the distance to the mountain what is causing the occlusion query to fail?
Quote this message in a reply
Moderator
Posts: 435
Joined: 2002.09
Post: #11
PowerMacX Wrote:Are you sure that it is the fog and not the distance to the mountain what is causing the occlusion query to fail?

Excellent observation. One way to test that would be to change the fog distance.

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #12
PowerMacX Wrote:Are you sure that it is the fog and not the distance to the mountain what is causing the occlusion query to fail?

I suspected that as well. My scenegraph draws fogged object differently than non-fogged ( by turning off all fancy stuff like lighting, shading, textures, etc ) so I modified it to draw all the terrain the same way, and it still failed.

Regarding the issues with the 9600 I'm stumped. I'm using GLEW for gl bindings, but I don't knw wether to use the ARB variants or not. Can anybody give me a pointer as to wether or when I should use the ARB versions ( not just for OQ, but for multitexture, etc) ?

EDIT: Boy, am I embarassed. My query was being drawn at a fixed distance, the active camera's far plane. I adjusted it to be twice the world's size and now it works as expected.

However, I doubt this fixes the issue with the 9600...
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #13
You should only use the non-ARB version if the current renderer's GL_VERSION is high enough to support the promoted core API. In the case of ARB_occlusion_query, it was promoted to the core in OpenGL 1.5. In the case of ARB_multitexture, 1.3.

Generally the API and enums for an extension are identical in the core, but not always. So read the specs carefully!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SOIL_load_OGL_texture - failing to load texture kropcke 3 7,381 Sep 5, 2012 10:08 AM
Last Post: kropcke
  query on Level Designing mchowdhury1983 1 2,939 Nov 20, 2011 12:08 PM
Last Post: sealfin
  2D Pixel Collision Detection using OCCLUSION Elphaba 0 3,358 Jun 8, 2009 06:30 AM
Last Post: Elphaba
  Occlusion query code failing on ATI 9600 TomorrowPlusX 4 5,554 Mar 10, 2007 08:52 AM
Last Post: arekkusu
  gl errors with occlusion queries TomorrowPlusX 1 2,477 Oct 12, 2005 10:08 AM
Last Post: TomorrowPlusX