I am trying to add MSAA to my multi-pass rendering algorithm, which I originally wrote with a home-rolled supersampling technique in mind.
I may be barking completely up the wrong tree in the rest of this post, because even when I do not set gl_FragDepth at all, I get this odd kind of translucency: http://imagebin.org/62759
It appears that setting glDepthFunc() to anything other than GL_ALWAYS will cause it.
One of the challenges I’m facing is that I need to store depth values in a way that I can access them from a shader. This is to work around the fact that OpenGL does not allow for 2 depth tests, which my algorithm (modified depth peeling) requires.
Since I am using GL_EXT_framebuffer_multisample, I cannot render directly to a texture. Instead I copy my depth values using GL_EXT_framebuffer_blit to an FBO with my depth texture bound to it. This causes the depth values from my multisampled FBO to be downsampled.
Now, when I go to render my shaded [multisampled] output on the next pass, I have to test against the depth values from the previous pass in my shader. The trouble is that those values won’t match up as they did before, because of the resolution difference. What I do to make up for that is that instead of setting my depth test to GL_EQUAL, I set it to GL_LESS, and then in my shader I do this:
float depthHere=texture2DRect(depthPeelTexture,gl_FragCoord.xy).r; gl_FragDepth = abs(gl_FragCoord.z-depthHere);
So that, in theory, I should get the fragment displayed whose depth is the “closest match” to the depth in my depth texture. However, the result renders looking half-transparent. I’ve removed the lighting and just rendered the passing fragments pure green in this example:
My thought is that I am somehow breaking the MSAA implementation. Perhaps it uses the depth values somewhere downstream to make decisions about what to render? When I set up the render FBO without multisampling, I see the expected result.
Thanks for any ideas or tips! I am having trouble finding pertinent implementation details, and I figure maybe someone here knows it intimately…
P.S. This is on an NVidia GeForce 8600M.