Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 24

Thread: Fullscreen quad invoking fragment shader twice along triangle seam?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    9

    Fullscreen quad invoking fragment shader twice along triangle seam?

    I'm trying to implement linked-list based transparency. The final stage is to performs alpha blending on a linked list of fragments for each pixel. The problem I'm having is that, when I try to render a fullscreen quad, the seam between the two triangles appears to have some overlap, which causes the fragment shader to be run twice on those pixels. This is a major problem, because it means that I can not assume the shader will be run once for each pixel, and I can't assume that only one shader instance will be accessing a pixel's data structures at a time.

    I'm using what I think is a pretty standard technique for drawing the quad: currently, I'm calling glDrawElements(GL_TRIANGLES) on two triangles defined in clip space.

    I pass in the following vertices to my vertex buffer:
    {
    {1.0f, 1.0f, 0.5f, 1.0f},
    {-1.0f, 1.0f, 0.5f, 1.0f},
    {1.0f, -1.0f, 0.5f, 1.0f},
    {-1.0f, -1.0f, 0.5f, 1.0f}
    }

    And my index buffer contains:
    {0, 1, 2, 1, 2, 3}


    And here's my vertex shader:

    #version 420

    layout(location=0) in vec4 in_position;
    layout(location=1) in vec2 in_tex;

    smooth out vec2 texture_coords;

    void main()
    {
    gl_Position = in_position;
    texture_coords = in_tex;
    }

    How do I know the shader is being run twice on the seam? I wrote a test shader that atomically increments a pixel in an image corresponding to the fragment's pixel coordinates. The diagonal of the image has all '2's while everywhere else is 1. When I change the order of the vertices, the '2's appear along the other diagonal.

    I've tested this on a radeon HD 7970 and HD 5450 on Ubuntu 11.04 and a Geforce 670 GTX on Mint 13, and it shows up in all of those cases. Curiously, when I try it on windows, the problem does not appear.

    I'm wondering if anyone has run into a similar problem before, has advice on how to define the triangles such that the seams are removed, or a different method of rendering the fullscreen quad.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    989
    I have no idea how this could happen but why don't you render a full screen triangle instead of a full screen quad? Just render a triangle large enough that it covers all pixels. This way you definitely cannot experience any seams.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    9
    I just tried that. I end up with 1 or 2 lines along which the fragment shader appears to run twice. I'm *guessing* that what's going on is the fixed function pipeline clips the triangle and converts it into several smaller ones that fill up the screen, but there still seems to be some overlap.

  4. #4
    Member Regular Contributor
    Join Date
    Dec 2007
    Posts
    258
    ortho projection ? Perspective projection is the only thing I can think of that would cause this.

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    469
    If you have MSAA enabled, you might want to look into centroid sampling for texture coordinates.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Quote Originally Posted by jfslocum View Post
    I've tested this on a radeon HD 7970 and HD 5450 on Ubuntu 11.04 and a Geforce 670 GTX on Mint 13, and it shows up in all of those cases. Curiously, when I try it on windows, the problem does not appear.
    I noticed the same thing in Windows but it was a couple of releases of driver ago. I haven't checked with the most recent drivers

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    9
    Quote Originally Posted by dukey View Post
    ortho projection ? Perspective projection is the only thing I can think of that would cause this.
    No projection at all; I'm passing the vertices in NDC. Take a look at my vertex shader.


    Quote Originally Posted by ScottManDeath View Post
    If you have MSAA enabled, you might want to look into centroid sampling for texture coordinates.
    I'm not using MSAA currently.


    Quote Originally Posted by tonyo_au View Post
    I noticed the same thing in Windows but it was a couple of releases of driver ago. I haven't checked with the most recent drivers
    That's good to hear. Maybe this will be fixed in the future.


    Thanks for the suggestions, guys.

  8. #8
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294
    Could you test with this in the fragment shader:
    Code :
    layout(early_fragment_tests) in;

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    9
    Quote Originally Posted by Ilian Dinev View Post
    Could you test with this in the fragment shader:
    Code :
    layout(early_fragment_tests) in;
    No apparent effect.

  10. #10
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    9
    I tried compiling with clang instead of gcc - still the same. So I'm pretty confused as to what's going on. It seems strange that both NVidia and ATI drivers would have the same problem specifically on linux.

Posting Permissions

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