Reputation: 8160
I have a vector array of triangles which basically consist of a bunch of squares that need to be billboarded. Something that looks like
GLfloat vertexpositions[60 * 3];
// [x,y,z] * 6 for each square, and there are 10 squares
And after that, calling glDrawArray
with the appropriate arguments to draw a total of 10 squares.
Is it possible to write a shader program that can separately billboard all of these polygons which exist on the same vertex array?
Upvotes: 4
Views: 1378
Reputation: 6033
At a minimum, you need to store the center location of each billboard. Then you can use the geometry shader to generate vertices. Alternatively, you can also store the vertices relative to each center location and transform the vertices in the vertex shader.
Upvotes: 0
Reputation:
There are two approaches. Use point sprites, or "undo" the rotation after you have concatenated your transformations. With billboards you want translation, but no rotation.
If you pass on a final world matrix M to the vertex shader as a uniform, then:
M[0][0] = M[1][1] = M[2][2] = 1.0
will undo the rotation, assuming no shearing is done. Or you could simply extract its translation vector from M[0 - 3][3].
Upvotes: 1