Geometry shader, color and Texture coords

howdy folks,

very basic question: do I have to pass color values and texture coordinates through a geometry shader?
I wrote a simple passthough GS that renders the geometry fine but OpenGL fails to include color and texcoord values. If I remove the GS and use only the vertex shader and fragment shader, color and texcoords are fine.

Maybe someone can give me a hint?

Thx in advance :slight_smile:

Here’s my GS:

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
void main() {
gl_Position = vec4(0,0,0,0);
for(int i = 0; i < gl_in.length(); i++) {
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}

And here my VS:

attribute vec4 li_vtx;
attribute vec3 li_normal;
attribute vec2 li_texcoord;
attribute vec4 li_ambient;

uniform mat4 u_pjmatrix; // projection matrix
uniform mat4 u_mvmatrix; // modelview matrix

varying vec2 g_texcoord;
varying vec4 g_gambient;
void main(void) {
g_gambient = li_ambient;
g_texcoord = li_texcoord;
gl_Position = u_pjmatrix * u_mvmatrix * li_vtx;
}

And finally my FS:

uniform sampler2D u_colormap;
varying vec2 g_texcoord;
varying vec4 g_gambient;

void main(void) {
vec4 texcolor = texture2D(u_colormap, g_texcoord.st);
gl_FragColor = g_gambient * texcolor;
}

very basic question: do I have to pass color values and texture coordinates through a geometry shader?

yes

Your program shouldnt even link, as interfaces betwean VS -> GS -> FS are inconsistent.

hi,

thanks for your fast reply! I did try to pass the color and texcoord through the shader but glDrawElements() didn’t like that. And yes the nvidia compiler compiles and links without any warning :(.

could you please point me to a comprehensive tutorial or at least to a complete sample(maybe version 150+)? So far I didn’t find any GS sample passing color and texture coords.

thanks a bunch :slight_smile:

Have a look at gtruc samples:
http://ogl-samples.git.sourceforge.net/git/gitweb.cgi?p=ogl-samples/ogl-samples;a=blob;f=data/330/smooth-shading-geom.geom

Here is a shader that passes color values across all shaders the vertex shader. The color comes in as vColor and is assigned to vFragColorVs in the vertex shader. It then comes into the geometry shader as vFragColorVs and gets assigned to vFragColor. The fragment shader then has vFragColor come in and assigns it to gl_FragColor.

Vertex Shader


#version 330
uniform mat4 mvpMatrix;
uniform vec4 vColor;
out vec4 vFragColorVs;
in vec4 vVertex;
void main(void) {
 vFragColorVs = vColor;
 gl_Position = mvpMatrix * vVertex;
}

Geometry Shader


#version 330
precision highp float;
in vec4 vFragColorVs[];
out vec4 vFragColor;
layout (triangles) in;
layout (triangle_strip, max_vertices = 6) out;
void main(void) {
 int i;
 for ( i=0; i < gl_in.length(); i++) {
  vFragColor = vFragColorVs[i];
  gl_Position = gl_in[i].gl_Position;
  EmitVertex();
 }
 EndPrimitive();
}

Fragment Shader


#version 330
in vec4 vFragColor;
void main(void) {
 gl_FragColor = vFragColor;
}

thanks a lot to you both. now I see my mistakes - silly me :wink:
btw. the opengl samples git has some really interesting demos, great resource!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.