I'm currently trying to change my project to use GL_TRIANGLE_ADJACENCY instead of GL_TRIANGLES.

Following this question, I have managed to construct my index buffer fine, but when it comes to the drawing stage, I'm getting unexpected results.

Screenshot showing incorrect geometry

Here is my geometry shader code. Bare in mind that I store my indices like so:


Geometry Shader

    #version 330

    precision highp float;

    layout (triangles_adjacency) in;
    layout (triangle_strip, max_vertices = 3) out;

    smooth in vec2 vVaryingTexCoords[];
    smooth in vec3 vVaryingNormals[];

    smooth out vec2 gsUV;
    smooth out vec3 gsNormals;

    void main(void)
        int i;

        for(i = 0; i < gl_in.length(); i++)
                case 0:
                case 2:
                case 4:
                    gl_Position = gl_in[i].gl_Position;
                    gsUV = vVaryingTexCoords[i];
                    gsNormals = vVaryingNormals[i];


Any ideas?


Just like to point out that setting the adjacent index to be the same as the vertex index, i.e v1/v1/v2/v2/v3/v3 still produces the same results.


It is an old question but recently I faced the same problem doing some real time hatching in the geometry shader.

By the sound of your code seems there is nothing wrong in your GS, problem could possibly be in your algorithm to build an adjacency list. I found a good tutorial here, which provides an implementation for finding the adjacent triangles (tutorial is about silhouette detection).

It uses assimp for loading a model, but I'm sure the concept can be extended to any other model loader if you have a face list or a indices list.

hope it helps


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.