I'm trying to create a particle system in OpenGL, and as such I need to use billboards.
I need these billboards to face the camera at all times.
The tutorials I've been following only rotated the billboard on 1 axis, such as billboards being used as grass or plants, but I need a method of rotating the quad to always face the camera, even when looking down on it.
While searching for an answer, I only really found the technique of turning the mat3 component of the camera's view/model matrix back to an identity matrix. This isn't quite what I need, as the point's location in space never change then.
How can I calculate a new rotation matrix that will successfully rotate a quad always towards the camera, or modify an existing matrix?
In the geometry shader I have access to the camera's position, the perspective matrix, and the view/model matrix.
I didn't include any shader code because it is really trivial; I create vertices that are an offset of the desired point's position based on the desired size. So if the quad should be 50 x 50, the vertex is the position offset by 25 on X and Y, multiplied by the Camera's Perspective x View matrix.
mat4 VP = pMatrix * vMatrix; vec3 CameraRight = vec3(vMatrix, vMatrix, vMatrix); vec3 CameraUp = vec3(vMatrix, vMatrix, vMatrix); vec3 Pos = gl_in.gl_Position.xyz; // The desired point for the billboard vec4 v1 = VP * vec4(Pos + CameraRight * 0.5 * Size + CameraUp * -0.5 * Size, 1.0); vec4 v2 = VP * vec4(Pos + CameraRight * 0.5 * Size + CameraUp * 0.5 * Size, 1.0); vec4 v3 = VP * vec4(Pos + CameraRight * -0.5 * Size + CameraUp * -0.5 * Size, 1.0); vec4 v4 = VP * vec4(Pos + CameraRight * -0.5 * Size + CameraUp * 0.5 * Size, 1.0);