Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Problem with multisample texture

  1. #1
    Junior Member Regular Contributor LangFox's Avatar
    Join Date
    Oct 2001
    Location
    Shen Zhen, Guangdong, China
    Posts
    103

    Problem with multisample texture

    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:
    Code :
    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:
    Code :
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture);

    Fragment Shader:
    Code :
    #version 150
     
    uniform sampler2DMS g_Texture0;
    out vec4 g_FragData;
     
    void main()
    {
    	g_FragData = texelFetch(g_Texture0, ivec2(gl_FragCoord.xy), 16);
    }
    Best Regards,
    LangFox


    http://hi.baidu.com/lang_fox

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Problem with multisample texture

    What about:
    Code :
    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".

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,719

    Re: Problem with multisample texture

    Did you glEnable(GL_MULTISAMPLE)?

    The functioning of all multisampled rendering depends on this.

  4. #4
    Junior Member Regular Contributor LangFox's Avatar
    Join Date
    Oct 2001
    Location
    Shen Zhen, Guangdong, China
    Posts
    103

    Re: Problem with multisample texture

    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!
    Best Regards,
    LangFox


    http://hi.baidu.com/lang_fox

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,719

    Re: Problem with multisample texture

    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?

  6. #6
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Problem with multisample texture

    http://www.opengl.org/sdk/docs/man/xhtml/glEnable.xml

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

  7. #7
    Junior Member Regular Contributor LangFox's Avatar
    Join Date
    Oct 2001
    Location
    Shen Zhen, Guangdong, China
    Posts
    103

    Re: Problem with multisample texture

    Quote Originally Posted by Alfonse Reinheart
    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.
    Best Regards,
    LangFox


    http://hi.baidu.com/lang_fox

  8. #8
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Problem with multisample texture

    Could you post png comparison images against the FramebufferBlit version? Afaik this shouldn't happen.

  9. #9
    Junior Member Regular Contributor LangFox's Avatar
    Join Date
    Oct 2001
    Location
    Shen Zhen, Guangdong, China
    Posts
    103

    Re: Problem with multisample texture

    Yes, I will try compare them later.
    Best Regards,
    LangFox


    http://hi.baidu.com/lang_fox

  10. #10
    Junior Member Regular Contributor LangFox's Avatar
    Join Date
    Oct 2001
    Location
    Shen Zhen, Guangdong, China
    Posts
    103

    Re: Problem with multisample texture

    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.
    Best Regards,
    LangFox


    http://hi.baidu.com/lang_fox

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •