tags:

views:

40

answers:

2

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?

+1  A: 

You can do per-primitive processing with a geometry shader.

Matias Valdenegro
A: 

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].

Mads Elvheim