OpenGL: Single vertex attribute for multiple vertices?

前端 未结 5 2266
生来不讨喜
生来不讨喜 2021-02-13 12:42

I have a vertex shader that accepts the following attributes:

  • a_posCoord: vertex position
  • a_texCoord: texture coordinate (passed
相关标签:
5条回答
  • 2021-02-13 13:10

    A couple ideas:

    1.) Bite the bullet and update the vertex buffer but only when alphas change.

    2.) Break the list of quads into batches and only rebuild batches that change..

    3.) Control the number of billboards and bind an array of alpha values to a uniform... In the alpha of the vertex data, or in some unused channel/additional channel, store the index of the alpha for that billboard, in your uniform array. at least that way you're potentially only uploading n alpha values.

    4.) combine 2 and 3...

    I am only taking a wild guess... I'd like to see if anyone else has good solutions!

    0 讨论(0)
  • 2021-02-13 13:11

    I achieve this effect with instanced rendering. glVertexAttribDivisor(1); makes openGL read vertex attribute once per instance. If your bullboards have different geometry you may consider passing you model matrix as an attribute the same way as alpha.

    0 讨论(0)
  • 2021-02-13 13:14

    If some vertex attribute is constant for each vertex, why don't you use an uniform variable? If it is constant, it is uniform! By this way you set the uniform value only once and your data set is reduced.

    0 讨论(0)
  • 2021-02-13 13:18

    A vertex is not a position A vertex is a long vector consisting of multiplie attributes. Change one single attribute and you end up with a different vertex. So no, you can not use a single vertex attribute for multiple vertices, because that makes no sense semantically.

    However what is possible with newer versions of OpenGL is setting the rate at which a certain vertex attribute's buffer offset advances. Effectively this means that the data for a given vertex array gets duplicated to n vertices before the buffer offset for a attribute advances. The function to set this divisor is glVertexAttribDivisor. In your case you'd set a Binding Divisor of 6 for the alpha array. But it's important that this does not use a single attribute for multiple vertices, but it makes OpenGL do that duplication you were doing for you.

    0 讨论(0)
  • 2021-02-13 13:27

    I haven't looked into this in detail but I think you could possibly also use glDrawElementsInstanced. With this you would put your alpha values into a big uniform array and the instance index would somehow be passed to the shader. Check this out:

    http://sol.gfxile.net/instancing.html

    0 讨论(0)
提交回复
热议问题