PDA

View Full Version : Problem with multisample texture



LangFox
12-08-2009, 08:37 AM
Hi guys,

I tried multisample texture with fbo. The fbo is completed, and object is rendered. But the result is NOT multisampled, just like rendered to normal texture with normal fbo. I can't figure it out...

Code to generate texture and fbo:


glGenFramebuffers(1, &m_FrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_FrameBuffer);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 16, GL_RGBA16F, 512, 512, false);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 16, GL_DEPTH_COMPONENT32, 512, 512, false);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture, 0);


Code to bind multisample texture:


glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture);


Fragment Shader:


#version 150

uniform sampler2DMS g_Texture0;
out vec4 g_FragData;

void main()
{
g_FragData = texelFetch(g_Texture0, ivec2(gl_FragCoord.xy), 16);
}

Ilian Dinev
12-08-2009, 09:17 AM
What about:


void main()
{
vec4 sum=vec4(0);
for(int i=0;i<16;i++){
sum += texelFetch(g_Texture0, ivec2(gl_FragCoord.xy), i);
}
g_FragData = sum/16.0;
}


I do not see any specs defining that sample-index 16 (out of bounds) means "the average sum of all samples".

Alfonse Reinheart
12-08-2009, 12:47 PM
Did you glEnable(GL_MULTISAMPLE)?

The functioning of all multisampled rendering depends on this.

LangFox
12-08-2009, 04:33 PM
To Alfonse Reinheart:
I think the "glEnable(GL_MULTISAMPLE)" effects frame buffer only, but not multisample texture?

To Ilian Dinev:
I didn't realize I have to average the sum of all samples myself. Thanks!

Alfonse Reinheart
12-08-2009, 05:41 PM
I think the "glEnable(GL_MULTISAMPLE)" effects frame buffer only, but not multisample texture?

Did you have it on when you were rendering to this texture?

Ilian Dinev
12-08-2009, 05:51 PM
http://www.opengl.org/sdk/docs/man/xhtml/glEnable.xml

"The initial value for GL_DITHER and GL_MULTISAMPLE is GL_TRUE."

LangFox
12-08-2009, 11:49 PM
I think the "glEnable(GL_MULTISAMPLE)" effects frame buffer only, but not multisample texture?

Did you have it on when you were rendering to this texture?

I forgot to answer it:
I have tried Enable(GL_MULTISAMPLE) or not, nothing changed.

But when I average the sum of samples, I feel the result is a little blurred, especially on the edge.

Ilian Dinev
12-09-2009, 12:19 AM
Could you post png comparison images against the FramebufferBlit version? Afaik this shouldn't happen.

LangFox
12-09-2009, 02:44 AM
Yes, I will try compare them later.

LangFox
12-09-2009, 07:34 AM
After reading article 2.8 in ShaderX7, Deferred Shading with Multisampling Anti-Aliasing in DirectX 10, I recognize there are much more things to do than just rendering to a multisample texture. For example:

- All calculations should be performed on a per-sample basis.
- A sensible optimization is to detect pixels whose samples have different values and only perform per-sample pixel shader execution on those "edge" pixels.

I'd like to try this article and inferred shading in the next few days. Any sharing about these is appreciated.