Here's what I know.
1. I have to check if the vertex positions are coplanar with the view, and if they aren't, move them. I need to do this by using an imaginary center of each quad, and checking against that position. I am still not sure how to go about this.
2. jK has an example of billboarded quads in SimpleParticles, but it doesn't fit the case, and I'm not sure what parts of his equation I can drop. The math is here:
Code: Select all
// calc particle attributes
vec3 attrib = vec3(1.0) - pow(vec3(1.0 - life), abs(attributesExp));
//if (attributesExp.x<0.0) attrib.x = 1.0 - attrib.x; // speed (no need for backward movement)
if (attributesExp.y<0.0) attrib.y = 1.0 - attrib.y; // size
if (attributesExp.z<0.0) attrib.z = 1.0 - attrib.z; // rot
attrib.yz = attributesStart.yz + attrib.yz * attributesEnd.yz;
// calc vertex position
vec3 forceV = (1.0 - pow(1.0 - life, abs(forceExp))) * forceDir; //FIXME combine with other attribs!
vec4 pos4 = vec4(posV + attrib.x * dirV + forceV, 1.0);
gl_Position = gl_ModelViewMatrix * pos4;
// calc particle rotation
float alpha = attrib.z;
float ca = cos(alpha);
float sa = sin(alpha);
mat2 rotation = mat2( ca , -sa, sa, ca );
// offset vertex from center of the polygon
gl_Position.xy += rotation * ( (gl_Vertex.xy - 0.5) * attrib.y );
// end
gl_Position = gl_ProjectionMatrix * gl_Position;
gl_TexCoord[0].st = gl_Vertex.xy;
All I need to do is to determine whether the given vertex is coplanar with the plane xy perpendicular with the camera that the center lies on, and if not, move it until it's coplanar. This could also be done at the beginning, before I move and scale the quad. I can define quads with vertex positions (-0.5,-0.5) --> (0.5,0.5) so that the center is (0,0), for simplicity's sake, but from there I get stuck on how I'm supposed to get the plane and alter the vertex positions to make them all coplanar.
I've read various things about it online, and have tried various chunks of GLSL, and none of it worked correctly- at best, I get a very distorted projection, and the quads end up doing all sorts of bizarre stuff. Very annoying, but that's where things stand today.