Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

(vertex1/adjacent1/vertex2/adjacent2/vertex3/adjacent3)

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++)
        {
            switch(i)
            {
                case 0:
                case 2:
                case 4:
                    gl_Position = gl_in[i].gl_Position;
                    gsUV = vVaryingTexCoords[i];
                    gsNormals = vVaryingNormals[i];
                    EmitVertex();
                    break;

                default:
                    break;
            }
    }
    EndPrimitive();
}

Any ideas?

EDIT

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.

share|improve this question

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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