开发者

Billboarding a vertex array with GLSL?

I have a vector array of triangles which basically consist of a bunch of squares th开发者_JAVA百科at 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?


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜