PDA

View Full Version : Shadow map blinking with FBO implementation



Nighthawk
08-22-2007, 08:36 AM
Hi,

i have switched my shadow map implementation from pbuffer to framebuffer object. It basically works(shadows look the same as they did with the pbuffer most of the time).

But at random intervals(every 30 seconds on average) the shadows are not visible for a few frames(the areas are fully lit), then they are visible again, but i can't figure out why

For the shadowmap impementation, i used basically the example from the FBO spec(render directly to depth texture with no color buffer bound). Then i sample that depth texture in my fragment program with:
"!!ARBfp1.0 OPTION ARB_fragment_program_shadow; "
"TEX shadow, tex0, texture[0], SHADOW2D; "

What i checked already:
- I logged the matrix used to generate the shadow map, it does not change while blinking.
- I wrote a small shader to render the shadow map, there the blinking occurs as well.
- The code has glGetError() in many places, none of them reports an error. The FBO is reported to be complete.
- Happens on ATI X800 as well as on Nvidia 8800(with various drivers), so i don't think it is a driver bug.
-The application is singlethreaded with one context only, so no race conditions.

The blinking seems to occur more often in debug mode(when the glgetErrors are active and the framerate is low), but also in release mode(faster but no errorchecks). The duration of the shadow disapperance seems not to depend on the framerate.

Anyone got an idea what might be the cause of this weird behaviour? :confused:

Martin

Nighthawk
08-22-2007, 10:20 AM
Hate to answer my own questions, it was really a stupid error... had the alpha test enabled during shadow map generation.

The pbuffer created a seperate context and reseted the color(to alpha=1 i assume).
With the shadowbuffer the last set color is used(alpha=random since its the same context as the main rendering) and then the alpha test failed sometimes depending on the rendering order etc.

Costed me me 1 day to comment out 1 line, ouch...

k_szczech
08-23-2007, 04:44 AM
You shouldn't hate to answer your own questions. If you have an answer - share it. It may save someone else the trouble.
I think many people were/are switching from PBO to FBO recently and the fact that PBO uses separate context may lead to many surprizes. Everyone who will read your post will benefit from your experience, so thanks :)

martinsm
08-23-2007, 01:35 PM
PBO = Pixel Buffer Object ?

Korval
08-23-2007, 02:42 PM
No, k_szczech is confusing PBO with P-Buffers.

Nighthawk
08-24-2007, 09:24 AM
k_szczech you are of course right about posting the answer here. I just hated the fact that i was thinking much too complicated when the problem was rather trivial ;)

About the PBO, just the wrong name for the right thing, i guess.

the fact that PBO uses separate context may lead to many surprizes should read

the fact that P-Buffer uses separate context may lead to many surprizes To make it clearer:
- the GL state changes inside the the shadow map generation will affect the rest of the rendering and vice versa after switching to FBO
- the GL state when entering the shadow map generation will not be the default state from the created pbuffer, but the state from the main rendering path

I had the first point in mind when i ported my implementation but not the second....