Hi guys,
// TL;DR’able explaination
I’ve been searching on Google some ways I could improve the billboard shader in my project. I found that instead of simply projecting the billboard in the opposite camera orientation, I could improve it by (ofc) applying a rotation matrix so that it looks at the camera. This will most certainly be slower to process for the GPU but it will give a more realistic feel to the player, effectively not rotating the billboards when the players move the mouse to aim around them. That’s one thing I did not like about the simple billboard implementation I had before: if you were standing next to a tree, for example on the right side of a tree and aim at the right side, the tree would rotate and completely fill the camera frustum until you aim on the right enough for the tree to go on the back of your head if you will making it disappear out of your sight.
// The problem! <—
With my new billboard shader, it ALMOST works, but as you can see on the screenshot, it only works if the camera is at Z+ or /before/ the billboard. On the second screenshot you see that I only turned 180 degrees and aimed in the opposite direction to see billboards behind me. There are none, until I go forward past the billboard’s Z value, then it appears. All billboards having a Z position value /lower/ than the camera’s are oriented perfectly at the camera, but the ones having a Z position value /higher/ than the camera are not showing, probably because they’re facing backwards.
This is the vertex shader so far:
[java]
// pos = inPosition | texCoord = inTexCoord
vec3 toCamera = normalize(pos.xyz - vec3(g_CameraPosition.x, pos.y, g_CameraPosition.z));
vec3 t = normalize(cross(normalize(pos.xyz), toCamera));
vec3 c = cross(toCamera, t);
mat4 r = mat4(1.0, c.x, toCamera.x, 0.0, // m11, m21, m31, m41
t.y, 1.0, toCamera.y, 0.0, // m12, m22, m32, m42
t.z, c.z, 1.0 , 0.0, // m13, m23, m33, m43
0.0, 0.0, 0.0 , 1.0); // m14, m24, m34, m44
vec4 model_offset_pos = normalize(vec4(0.0, pos.y, 0.0, 1.0));
float offset = texCoord.x - 0.5; // (make it -0.5 to 0.5)
model_offset_pos.x += offset * inTexCoord2.x;
normalize(model_offset_pos);
pos = (r * model_offset_pos) + (pos);
gl_Position = g_WorldViewProjectionMatrix * pos;
[/java]
Thx for all your inputs.