Reputation: 127
When I try adding a geometry shader between working vertex and fragment shaders I get a link error:
Fragment shader(s) failed to link, vertex shader(s) failed to link.
ERROR: error(#280) Not all shaders have valid object code
ERROR: error(#280) Not all shaders have valid object code
All three shaders compile without errors. I guess the in and outs doesn't fit in the information flow pipeline. The built-in ins and outs confuse me so I can't spot the error.
Source for the shaders:
vertex_source =
"#version 330\n"
"in vec3 Position;\n"
"in vec2 TexCoord;\n"
"out vec3 oColor;\n"
"out vec2 oTexcoord;\n"
"void main() {\n"
" oTexcoord = TexCoord;\n"
" gl_Position = gl_ModelViewProjectionMatrix*vec4(Position, 1.0);\n"
"}\n";
geometry_source =
"#version 330\n";
"layout (triangles) in;\n";
"layout (triangle_strip, max_vertices=3) out;\n";
"in vec3 Color;\n";
"in vec2 TexCoord;\n";
"out vec3 oColor;\n";
"out vec2 oTexCoord;\n";
"void main() {\n";
" oColor = Color;\n";
" oTexCoord = TexCoord;\n";
" gl_Position = gl_in[0].gl_Position;\n";
" EmitVertex();\n";
" gl_Position = gl_in[1].gl_Position;\n";
" EmitVertex();\n";
" gl_Position = gl_in[2].gl_Position;\n";
" EmitVertex();\n";
" EndPrimitive();\n";
"}\n";
fragment_source =
"#version 330\n"
"in vec2 oTexcoord;\n"
"out vec4 oColor;\n"
"uniform sampler2D tex;\n"
"uniform sampler2D tex_norm;\n"
"uniform sampler2D tex_spec;\n"
"void main() {\n"
" vec4 lightpos = normalize(-gl_ModelViewProjectionMatrix*vec4(1.0, -1.0, -1.5, 1.0));\n"
" vec3 tmpNorm = normalize(texture2D(tex_norm, oTexcoord).rgb * 2.0 - 1.0);\n"
" float a = dot(tmpNorm, lightpos.xyz);\n"
" float difuse = max(a, 0.1);\n"
" float spec = texture2D(tex_spec, oTexcoord).r * pow(a, 2.0);\n"
" vec3 tmpcolor = difuse * texture2D(tex, oTexcoord).rgb;\n"
" oColor = vec4(tmpcolor+tmpcolor*spec, 1.0);\n"
"}\n";
What am I doing wrong in the geometry shader?
I have tried skipping the unused oColor out and changed to an array in geometry shader like this:
#define GLSL(src) "#version 330 core\n" #src
vertex_source = GLSL(
in vec3 Position;
in vec2 TexCoord;
out vec2 oTexcoord;
void main() {
gl_Position = gl_ModelViewProjectionMatrix*vec4(Position, 1.0);
oTexcoord = TexCoord;
}
);
geometry_source = GLSL(
layout (triangles) in;
layout (triangle_strip, max_vertices=3) out;
in vec2 gsTexCoord[];
out vec2 gsoTexCoord;
void main() {
gsoTexCoord = gsTexCoord[0];
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gsoTexCoord = gsTexCoord[1];
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gsoTexCoord = gsTexCoord[2];
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
);
fragment_source = GLSL(
in vec2 oTexcoord;
out vec4 oColor;
uniform sampler2D tex;
uniform sampler2D tex_norm;
uniform sampler2D tex_spec;
void main() {
vec4 lightpos = normalize(-gl_ModelViewProjectionMatrix*vec4(1.0, -1.0, -1.5, 1.0));
vec3 tmpNorm = normalize(texture2D(tex_norm, oTexcoord).rgb * 2.0 - 1.0);
float a = dot(tmpNorm, lightpos.xyz);
float difuse = max(a, 0.1);
float spec = texture2D(tex_spec, oTexcoord).r * pow(a, 2.0);
vec3 tmpcolor = difuse * texture2D(tex, oTexcoord).rgb;
oColor = vec4(tmpcolor+tmpcolor*spec, 1.0);
}
);
That gives me the following link error:
Fragment shader(s) failed to link, vertex shader(s) failed to link.
ERROR: error(#277) Symbol 'gsTexCoord[0]' usage doesn't match between two stages
ERROR: error(#277) Symbol 'oTexcoord' usage doesn't match between two stages
ERROR: error(#277) Symbol 'gsTexCoord[0]' usage doesn't match between two stages
ERROR: error(#277) Symbol 'oTexcoord' usage doesn't match between two stages
Upvotes: 3
Views: 1686
Reputation: 52157
Your geometry shader inputs need to be array-valued and match the names in your vertex shader:
// existing vertex shader outputs:
out vec3 oColor;
out vec2 oTexcoord;
// wrong geometry shader inputs:
in vec3 Color;
in vec2 TexCoord;
// correct geometry shader inputs:
in vec3 oColor[];
in vec2 oTexCoord[];
Upvotes: 3