Like the title suggests, I am building a particle system in OpenGL using a geometry shader to create billboards from points. Everything seems okay but it looks like all particles share the rotation and color of the first particle. I've checked the inputs of course. Here are my current vertex and geometry shaders:
Vertex Shader:
#version 330 core
layout(location=0) in vec4 in_position;
layout(location=2) in float in_angle;
layout(location=3) in vec4 in_color;
uniform mat4 P;
uniform mat4 V;
out VertexData
{
vec4 color;
float angle;
} vertex;
void main()
{
vertex.color = in_color;
vertex.angle = in_angle;
gl_Position = in_position;
}
Geometry shader:
#version 330
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
uniform mat4 V;
uniform mat4 P;
in VertexData
{
vec4 color;
float angle;
} vertex[];
out vec4 fragColor;
out vec2 texcoord;
mat4 rotationMatrix(vec3 axis, float angle)
{
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0);
} // http://www.neilmendoza.com/glsl-rotation-about-an-arbitrary-axis/
void main()
{
mat4 R = rotationMatrix( vec3(0,0,1), vertex[0].angle );
vec4 pos = V * vec4( gl_in[0].gl_Position.xyz, 1.0 );
float size = gl_in[0].gl_Position.w;
texcoord = vec2( 0.0, 0.0);
gl_Position = P * ( pos + vec4( texcoord, 0, 0 ) * R * size );
fragColor = vertex[0].color;
EmitVertex();
texcoord = vec2( 1.0, 0.0);
gl_Position = P * ( pos + vec4( texcoord, 0, 0 ) * R * size );
fragColor = vertex[0].color;
EmitVertex();
texcoord = vec2( 0.0, 1.0);
gl_Position = P * ( pos + vec4( texcoord, 0, 0 ) * R * size );
fragColor = vertex[0].color;
EmitVertex();
texcoord = vec2( 1.0, 1.0);
gl_Position = P * ( pos + vec4( texcoord, 0, 0 ) * R * size );
fragColor = vertex[0].color;
EmitVertex();
EndPrimitive();
}
Am I doing something wrong in here?