1
votes

Here is a picture of what I have so far. demo with overlapping triangles

Don't worry about the gaps between the black quads. My issue is with stuff like what happens where the red, green and blue areas touch. You can see that one quad is behind the green triangle, and another is partly behind the blue triangle but in front of the green triangle.

This all happens because I take 3 triangles (red, green and blue) and tessellate and deform them in the tessellation shaders, then draw the quads in the geometry shader. The quad is always drawn after the triangle it is attached to, but they always go together, so the next triangle generated by tessellation will be above the previous quad.

My question is, is there a way to avoid this besides using two different shader programs? It seems like transform feedback might work, like rendering the triangles to one buffer and the quads to another and combine them later. Would that work? Would it be faster than switching shaders? (Or sometimes faster) Any other ideas?

EDIT: Sorry I am making my question harder. Eventually when I get the quads fixed the edges will be alpha blended to do antialiasing. So ideally an answer would work in that scenario.

EDIT 2: In the final version the three colored triangles will be considered together. Eventually they might all be part of the same gradient or share a texture, in the near term they will always be the same color. (The colors are there now just to help me figure out what is going on.) So some tricks could be done by giving the color information to the quads in the geometry shader to help in the alpha blending mentioned above. This might allow the depth buffer to be used. Sorry for not giving all the information earlier, I am not used to asking such open-ended questions.

1
How do you draw them now? In OpenGL all draw calls happen in exactly the order you issue them.BDL
The 3 big triangles are sent through to the shaders in patches of 3 vertices, then the tesselation shader generates more triangles, in the geometry shader I emit the vertices for the triangle, and for the edge quad if appropriate. I know that the draw calls happen in order, but I can't see a way to cause all the quads to be drawn after the triangles when the geometry shader only sees one triangle at a time. Hence, the question.Jeremy Sorensen

1 Answers

1
votes

You could apply a small offset in the depth (z) direction to the triangles you want in front. Then, as long as your framebuffer has a depth buffer, and depth testing is enabled, they will appear in front of the other triangles.