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.