I've written a very simple pass-through geometry shader. My input and output primitives are points. I also want to forward the color and normal from vertex shader to fragment shader through geometry shader. The shaders are compiled and linked flawlessly but the final color is very weird. I think there is something wrong with this forwarding. Can anyone point out the problem? Here are my shaders:
Vertex shader:
#version 330 compatibility
struct vData
{
vec3 normal;
vec4 color;
};
out vData vertex;
void main()
{
vertex.normal = gl_NormalMatrix * gl_Normal;
vertex.color = gl_Color;
gl_Position = ftransform();
}
Geometry shader:
#version 330
layout (points) in;
layout (points) out;
layout (max_vertices = 1) out;
struct vData
{
vec3 normal;
vec4 color;
};
in vData vertices[];
out vData frag;
void main()
{
int i;
for(i = 0;i < gl_in.length();i++)
{
frag.normal = vertices[i].normal;
frag.color = vertices[i].color;
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
Fragment shader:
#version 330
struct vData
{
vec3 normal;
vec4 color;
};
in vData frag;
void main()
{
gl_FragColor = frag.color;
}