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.

A little problem with my tessellation shader. I try to implement a simple tessellation shader but it only makes points.

Here's my vertex shader :

out vec4 ecPosition;
out vec3 ecNormal;    
void main( void )
{
    vec4 position = gl_Vertex;

    gl_Position = gl_ModelViewProjectionMatrix * position;
    ecPosition  = gl_ModelViewMatrix * position;
    ecNormal    = normalize(gl_NormalMatrix * gl_Normal);
}

My tessellation control shader :

layout(vertices = 3) out;
out vec4 ecPosition3[];
in vec3 ecNormal[];
in vec4 ecPosition[];
out vec3 myNormal[];
void main()
{
    gl_out[gl_InvocationID].gl_Position =  gl_in[gl_InvocationID].gl_Position;
    myNormal[gl_InvocationID] = ecNormal[gl_InvocationID];
    ecPosition3[gl_InvocationID] = ecPosition[gl_InvocationID];
    gl_TessLevelOuter[0] = float(4.0);
    gl_TessLevelOuter[1] = float(4.0);
    gl_TessLevelOuter[2] = float(4.0);
    gl_TessLevelInner[0] = float(4.0);
}

And my Tessellation Evaluation shader:

layout(triangles, equal_spacing, ccw) in;
in vec3 myNormal[];
in vec4 ecPosition3[];
out vec3 ecNormal;
out vec4 ecPosition;

void main()
{
    float u = gl_TessCoord.x;                               
    float v = gl_TessCoord.y;                               
    float w = gl_TessCoord.z;                               
    vec3 position = vec4(gl_in[0].gl_Position.xyz * u +     
                 gl_in[1].gl_Position.xyz * v +     
                 gl_in[2].gl_Position.xyz * w );    
    vec3 position2 = vec4(ecPosition3[0].xyz * u +          
                  ecPosition3[1].xyz * v +          
                  ecPosition3[2].xyz * w );         
    vec3 normal = myNormal[0] * u +                         
              myNormal[1] * v +                         
              myNormal[2] * w );                        
    ecNormal = normal;                          
    gl_Position = vec4(position, 1.0);                      
    ecPosition = vec4(position2, 1.0);                      
}

Thank you !

Link to a screenshot : http://img4.imageshack.us/img4/9712/sanstitrektht.png

share|improve this question
add comment

1 Answer

You're only emitting one vertex. ;)

Here's how you should rewrite your geometry shader:

layout(vertices = 3) out;
out vec4 ecPosition3[];
in vec3 ecNormal[];
in vec4 ecPosition[];
out vec3 myNormal[];
void main()
{
    for (int p = 0; p < gl_in.length(); p++)
    {
        gl_Position =  gl_in[p].gl_Position;
        myNormal = ecNormal[p];
        ecPosition3 = ecPosition[p];
        gl_TessLevelOuter[0] = float(4.0);
        gl_TessLevelOuter[1] = float(4.0);
        gl_TessLevelOuter[2] = float(4.0);
        gl_TessLevelInner[0] = float(4.0);

        EmitVertex();
    }

    EndPrimitive();
}

Note: this may still not be exactly what you want, but at least you'll be getting triangles as output.

share|improve this answer
    
Sorry same result :( . Look my screenshot : link –  urza57 Jun 19 '12 at 8:49
1  
He doesn't have a geometry shader. That's a tessellation evaluation shader. –  Nicol Bolas Jun 19 '12 at 15:15
    
@NicolBolas Well now I just feel silly. :( You're right, I've never worked with tessellation shaders before and I assumed it was a geometry shader by a different name. –  knight666 Jun 19 '12 at 16:59
    
Hmm, you are writing into gl_Position already transformed vertices. have you tried instead to do next in vertex shader gl_Position = gl_Vertex (or add another out variable like you did e.g. for normals). And then in tessellation evaluation shader actually write gl_Position = MVP * position –  alariq Nov 14 '13 at 20:19
add comment

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.