PDA

View Full Version : (GL3.2) texelFetch of multisample depth texture



somboon
02-18-2010, 07:07 AM
I tried to implement antialiased deferred shader using method given by
Llian Dinev .


http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=52473&Number=2714 70#Post271470

and got it working for the most part.

I can "texelFetch" texel of g-buffer fine but have a problem fetching multisample depth texture

The preblem is "texelFetch" of multisample depth texture alway return 0 for all sampling position and give no error.

this is the snippet of code I use to set up multisample depth texture of g-buffer FBO



glGenTextures(1, &depthBufferTexID);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, depthBufferTexID);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sample , GL_DEPTH_COMPONENT24 , width, height,GL_FALSE);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D_MULTISAMPLE,depthBufferTexID, 0);


Note that the FBO above is working fine and g-buffer are render correctly.

Ilian Dinev
02-18-2010, 07:50 AM
I initialize the FBO with these funcs:


for(int i=0;i<NumTextures;i++){
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, f->Textures[i]->glTexHandle, 0);
}
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, f->DepthTex->glTexHandle, 0);

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);


Maybe these MSAA binds require the glFramebufferTexture() to be used instead of glFramebufferTexture2DEXT() ?

Ilian Dinev
02-18-2010, 07:54 AM
Also, check the value returned by
glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES,&amp;maxSam ples);

In http://www.opengl.org/registry/specs/ARB/texture_multisample.txt it's specified, that implementations (Radeon HD2x00) could return '1' as that value. :(

somboon
02-18-2010, 08:12 AM
Can you post the depth texture setup code ?

my is



glGenTextures(1, &amp;depthBufferTexID);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, depthBufferTexID);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sample , GL_DEPTH_COMPONENT24 , width, height,GL_FALSE);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D_MULTISAMPLE,depthBufferTexID, 0);


with is working fine when doing g-buffer creation (depth testing working as expect)

but had a problem when tried to texelFetch it in lighting pass

Ilian Dinev
02-18-2010, 01:52 PM
Same, but as already noted: I use glFramebufferTexture() instead of glFramebufferTexture2DEXT()

What gpu and driver-version are you using?

somboon
02-18-2010, 03:00 PM
ATI 4670 , catalyst 10.1 driver.
change all FBO code to core doesn't help.

May be the problem is I tried to read depth when it attach to the same FBO.

Actually my g-buffer and final shading-buffer are on the same FBO It setup like this.

depthbuffer = depth_component24
color attachment 0 = g-buffer(normal)
color attachment 1 = g-buffer(diffuse/albedo)
color attachment 2 = g-buffer(specular)
color attachment 3 = final-shading buffer

In g-buffer creation state I enable depth test and use the first three (0-2) color attachment to store g-buffer content.

In final-shading state , I switch draw buffer to color attachment 3 of the same FBO and do deferred shading there (disable depth testing,texel fetch from color attachment 0-2 + depth texture).

The process above work fine for non-multisample FBO.

Why I setup my FBO like this is so that I dont have to switch FBO and make a copy of depth texture when do final shading and forward rendering pass.

I will try to make a copy of depth texture and feed it to final shading state instead of using the attached one and see if the problem are still there.

Pierre Boudier
02-18-2010, 03:23 PM
this is probably not your issue, but reading from a msaa depth texture is only available on rv7xx HW and above, as indicated by the query.

somboon
02-18-2010, 03:44 PM
glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES,&amp;maxSam ples);

return 8

somboon
02-18-2010, 04:18 PM
Got it working now !!!.

I have to disable depth testing right after I switch draw buffer for final-shading state (switch to color attachment 3).

If I do some depth testing before the fetching even if I disable depth testing after that the fetching will always failed.

this will not work


-switch to color attachment 3
-enable depth testing
-do some rendering (ambient pass)
-disable depth testing
-do some texelFetch of depth (shading pass)


this work


-switch to color attachment 3
-disable depth testing
-do some rendering (ambient pass)
-do some texelFetch of depth (shading pass)