OpenGL point sprites rotation in fragment shader

前端 未结 3 1552
感动是毒
感动是毒 2021-02-04 20:17

I\'m following this tutorial to learn something more about OpenGL and in particular point sprites. But I\'m stuck on one of the exercises at the end of the page:

3条回答
  •  遇见更好的自我
    2021-02-04 20:54

    You're right - a 2x2 rotation matrix will do what you want.

    This page: http://www.cg.info.hiroshima-cu.ac.jp/~miyazaki/knowledge/teche31.html shows how to compute the elements. Note that you will be rotating the texture coordinates, not the vertex positions - the result will probably not be what you're expecting - it will rotate around the 0,0 texture coordinate, for example.

    You may alse need to multiply the point_size by 2 and shrink the gl_PointCoord by 2 to ensure the whole texture fits into the point sprite when it's rotated. But do that as a second change. Note that a straight scale of texture coordinates move them towards the texture coordinate origin, not the middle of the sprite.

    If you use a higher dimension matrix (3x3) then you will be able to combine the offset, scale and rotation into one operation.

提交回复
热议问题