奇怪的几何着色器程序行为...... GLSL

时间:2017-03-21 16:45:58

标签: opengl glsl

此几何程序是我的B T N可视化器着色器的一部分。 它在模式1中工作正常。但是似乎总有一个...... 如果模式<>,则切线和双切线部分永远不会被击中。 1?

#version 120

#extension GL_EXT_geometry_shader4 : enable         

uniform int mode;
uniform float l_length;

varying in vec3 n[];
varying in vec3 t[];
varying in vec3 b[];
varying vec4 color;

void main()
{
    vec4 sumV;
    vec4 sumN;

    // Normal
    color = vec4(1.0, 0.0, 0.0, 1.0);

    if (mode == 1)
    {
        sumV = (gl_PositionIn[0] + gl_PositionIn[1] + gl_PositionIn[2]) / 3.0;
        sumN.xyz = (n[0].xyz + n[1].xyz + n[2].xyz) / 3.0;
        sumN.w = 0.0;
        gl_Position = gl_ModelViewProjectionMatrix * sumV;
        EmitVertex();
        gl_Position = gl_ModelViewProjectionMatrix * (sumV + (sumN * l_length));
        EmitVertex();
        EndPrimitive();
    }
    else
    {
        for(int i = 0; i < gl_VerticesIn; ++i)
        {
            gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
            EmitVertex();
            gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + (vec4(n[i], 0) * l_length));
            EmitVertex();
            EndPrimitive();
        }
    }

    // Tangent
    color = vec4(0.0, 1.0, 0.0, 1.0);

    if (mode == 1)
    {
        sumV = (gl_PositionIn[0] + gl_PositionIn[1] + gl_PositionIn[2]) / 3.0;
        sumN.xyz = (t[0].xyz + t[1].xyz + t[2].xyz) / 3.0;
        sumN.w = 0.0;
        gl_Position = gl_ModelViewProjectionMatrix * sumV;
        EmitVertex();
        gl_Position = gl_ModelViewProjectionMatrix * (sumV + (sumN * l_length));
        EmitVertex();
        EndPrimitive();
    }
    else
    {
        for(int i = 0; i < gl_VerticesIn; ++i)
        {
            gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
            EmitVertex();
            gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + (vec4(t[i], 0) * l_length));
            EmitVertex();
            EndPrimitive();
        }
    }

    // biTangent
    color = vec4(0.0, 1.0, 1.0, 1.0);

    if (mode == 1)
    {
        sumV = (gl_PositionIn[0] + gl_PositionIn[1] + gl_PositionIn[2]) / 3.0;
        sumN.xyz = (b[0].xyz + b[1].xyz + b[2].xyz) / 3.0;
        sumN.w = 0.0;
        gl_Position = gl_ModelViewProjectionMatrix * sumV;
        EmitVertex();
        gl_Position = gl_ModelViewProjectionMatrix * (sumV + (sumN * l_length));
        EmitVertex();
        EndPrimitive();
    }
    else
    {
        for(int i = 0; i < gl_VerticesIn; ++i)
        {
            gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
            EmitVertex();
            gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + (vec4(b[i], 0) * l_length));
            EmitVertex();
            EndPrimitive();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

I figured it out finally.. I set the paramiter wrong.. It was at 6 but it needs to be 18 to work: It was this line:

Gl.glProgramParameteriEXT(shader, Gl.GL_GEOMETRY_VERTICES_OUT_EXT, 18)

End result...

enter image description here