kamziro
kamziro

Reputation: 8160

Billboarding a vertex array with GLSL?

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

Answers (3)

cyrf
cyrf

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

Mads Elvheim
Mads Elvheim

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

Dr. Snoopy
Dr. Snoopy

Reputation: 56377

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

Upvotes: 1

Related Questions