Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Tessellation Shader Generates No Output!

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Mar 2013
    Posts
    42

    Exclamation Tessellation Shader Generates No Output!

    Hallo,

    i've tried all to generate an output with my tessellation shader. If i add the tessellation evaluation and tessellation control shader to my shader program,
    the model to which i applied the shader is gone.

    Here is my vertex, tessellation evaluation and tessellation control shader:

    Vertex
    Code :
    #version 410
     
    #import "assets/shaders/libraries/VertexCore.glsl"
     
     
    //Varying variables out for tessellation control shader
    out vec4 v_TexCoordCS;
    out vec4 v_PositionCS;
    out vec4 v_ColorCS;
     
    out vec3 v_NormalCS;
     
    void main(void) {
        v_TexCoordCS = i_TexCoord;
        v_NormalCS   = normalize(m_ModelNormalMatrix * i_Normal);
        v_ColorCS    = i_Color;
        v_PositionCS = i_Vertex;
    }

    Tessellation Control
    Code :
    #version 410
     
    layout(vertices = 3) out;
     
    //Varying variables in from vertex shader
    in vec4[3] v_TexCoordCS;
    in vec4[3] v_PositionCS;
    in vec4[3] v_ColorCS;
     
    in vec3[3] v_NormalCS;
     
    //Varying variables out for tessellation evaluation shader
    out vec4[3] v_TexCoordES;
    out vec4[3] v_PositionES;
    out vec4[3] v_ColorES;
     
    out vec3[3] v_NormalES;
     
    void main(void) {
        v_TexCoordES[gl_InvocationID] = v_TexCoordCS[gl_InvocationID];
        v_PositionES[gl_InvocationID] = v_PositionCS[gl_InvocationID];
        v_ColorES[gl_InvocationID] = v_ColorCS[gl_InvocationID];
        v_NormalES[gl_InvocationID] = v_NormalCS[gl_InvocationID];
     
        gl_TessLevelInner[0] = 3.0;
     
        gl_TessLevelOuter[0] = 10.0;
        gl_TessLevelOuter[1] = 7.0;
        gl_TessLevelOuter[2] = 3.0;
    }

    Tessellation Evaluation
    Code :
    #version 410
     
    layout(triangles, equal_spacing, ccw) in;
     
    //Matrices
    uniform mat4 m_ModelMatrix;
    uniform mat4 m_ViewMatrix;
    uniform mat4 m_ProjectionMatrix;
     
    mat4 m_ModelViewMatrix = m_ViewMatrix * m_ModelMatrix;
    mat4 m_ModelViewProjectionMatrix = m_ProjectionMatrix * m_ModelViewMatrix;
    mat4 m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;
     
    //Uniforms
    uniform sampler2D m_DisplacementTexture;
    uniform float m_DisplacementFactor;
     
    //Varying variables in from tessellation control shader
    in vec4[3] v_TexCoordES;
    in vec4[3] v_PositionES;
    in vec4[3] v_ColorES;
     
    in vec3[3] v_NormalES;
     
    //Varying variables out for fragment shader
    out vec4 v_TexCoordFS;
    out vec4 v_PositionFS;
    out vec4 v_ColorFS;
     
    out vec3 v_NormalFS;
     
    vec2 interpolate(vec2 v0, vec2 v1, vec2 v2) {
        return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;
    }
     
    vec3 interpolate(vec3 v0, vec3 v1, vec3 v2) {
        return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2;
    }
     
    void main(void) {
        v_TexCoordFS = vec4(interpolate(v_TexCoordES[0].st, v_TexCoordES[1].st, v_TexCoordES[2].st), 0.0, 1.0);
        v_NormalFS = interpolate(v_NormalES[0], v_NormalES[1], v_NormalES[2]);
        v_NormalFS = normalize(v_NormalFS);
        v_PositionFS = vec4(interpolate(v_PositionES[0].xyz, v_PositionES[1].xyz, v_PositionES[2].xyz), 1.0);
        v_ColorFS = vec4(interpolate(v_ColorES[0].rgb, v_ColorES[1].rgb, v_ColorES[2].rgb), 1.0);
     
        float displacement = texture(m_DisplacementTexture, v_TexCoordFS.st).x;
        v_PositionFS += vec4(v_NormalFS, 1.0) * displacement * m_DisplacementFactor;
        gl_Position = m_ModelViewProjectionMatrix * v_PositionFS;
    }

    And yes, i've set the number of vertices per patch:
    Code :
    glPatchParameteri(GL_PATCH_VERTICES, 3);

    I really hope that someone can tell me the mistake in my code!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Do you get a triangle rendered if you don't tessellate? ie just have a shader with the vertex and frag parts.

  3. #3
    Intern Newbie
    Join Date
    Mar 2013
    Posts
    42
    Hallo,
    first of all, thank you for your reply!

    The scene is a bit more complex than just a single triangle

    Only with Vertex and Fragment Shader:
    Click image for larger version. 

Name:	Screenshot1.jpg 
Views:	49 
Size:	94.2 KB 
ID:	1206

    With Vertex, Fragment, Tessellation Control and Tessellation Evaluation Shader:
    Click image for larger version. 

Name:	Screenshot2.jpg 
Views:	73 
Size:	93.4 KB 
ID:	1207

    But i've to add the following line of code to my vertex shader.
    Code :
    gl_Position = m_ModelViewProjectionMatrix * i_Vertex;
    Yeah, otherwise the tessellation evaluation shader would do this as you may have seen in my code above!
    And, of course, the names of the input variables in the fragment shader must be renamed too.

    You will have recognized that the shadow is rendered anyway. This is because the tessellation shader pass will be skipped
    in the depth texture pass for shadow mapping.

    - Daniel
    Last edited by Alphaomega86; 12-23-2013 at 12:30 AM.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    OK since non-tessellated model looks fine I would focus on the displacement calculation because if this has bad values your vertex could end up anywhere. Look for things like the texture not being bound correctly or the scaling factor being wrong.

    One thing you can try is having a different evaluation shader that just generates lines from the original vertex to the displacement point. Since the original vertices look ok you should be able to see where each line goes.

  5. #5
    Intern Newbie
    Join Date
    Mar 2013
    Posts
    42
    ok, it was a really stupid bug ...

    When i use tessellation i've to render my objects using
    Code :
    glDrawArrays(GL_PATCHES, ...)
    i was so extrem focused on my shader, that i've forgot to change this small line of code

    Thank you for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •