此几何程序是我的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();
}
}
}