Advertisement
arxeiss

Billboarding

May 3rd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. glm::mat4 billboardMVMatrix(glm::mat4 mvmatrix, glm::vec3 scale) {
  2.     // Column 0:
  3.     mvmatrix[0][0] = scale[0];
  4.     mvmatrix[0][1] = 0;
  5.     mvmatrix[0][2] = 0;
  6.  
  7.     // Column 1:
  8.     mvmatrix[1][0] = 0;
  9.     mvmatrix[1][1] = scale[1];
  10.     mvmatrix[1][2] = 0;
  11.  
  12.     // Column 2:
  13.     mvmatrix[2][0] = 0;
  14.     mvmatrix[2][1] = 0;
  15.     mvmatrix[2][2] = scale[2];
  16.  
  17.     return mvmatrix;
  18. }
  19.  
  20. glm::mat4 tmp = ss->m_activeCamera->getVM() * spark->m_modelMatrix;
  21. uniform = glGetUniformLocation(ss->m_activeShader->m_programObject, "MVMatrix");
  22. glUniformMatrix4fv(uniform, 1, GL_FALSE, (float*)&(this->billboardMVMatrix(tmp, spark->scale))[0]);
  23.  
  24. // Shader
  25. #version 330 core //compatibility
  26.  
  27. layout(location = 0) in vec3 VertexPosition;
  28. // layout(location = 1) in vec3 VertexNormal;
  29. layout(location = 2) in vec2 VertexTex;
  30.  
  31. uniform mat4 PMatrix;       //Camera projection matrix
  32. uniform mat4 MVMatrix;      //VMatrix * Model matrix
  33.  
  34. out vec2 textureCoords;
  35.  
  36. void main()
  37. {
  38.     gl_Position = PMatrix * MVMatrix * vec4(VertexPosition, 1.0);
  39.     textureCoords = VertexTex.xy;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement