I assumed that was how the geometry shader worked - just wasn’t sure. In fact I considered suggesting doing the billboarding there in the first place but since I wasn’t sure …
It seems we’re doing it two different ways. My way is just to use the depth value of the vertex before it was billboarded. Your way is to project the vertex along the camera’s forward vector until the base. I would say my way was simpler computationally, conceptually and practically. But technically due to the perspective projection, it is slightly inaccurate (more so the greater the rotation), which I’m only realizing now thanks to you. So your way is more accurate (if this can be such a thing) but I think it needs the tiniest bit of refinement.
Imagine if the camera was rotated the other way than it is in your diagram, then you would actually have to subtract the change in depth rather than add it right? A couple of weeks ago, it would have taken me several hours to solve this problem, but luckily for you I’ve recently had to solve it to implement a touch screen rotation system (where one finger works as a pivot point and the other drags the view around). The answer is to multiply the value by the sign of the cross product of the two vectors. I’m pretty sure GLSL has a sign() method. If not then it will be more difficult.
On to why it isn’t working. I’m afraid the only thing I can think of is that the vectors aren’t normalized, but I’m sure they would be. It might help if you did some more testing to see if there is any pattern to it not working. A tip on that front - I once modified my shader to set the fragment colour to a sort of greyscale of the depth value. (vec4(depth, depth, depth, 1); ). And rendered that on one half of the screen and the regular image on the other. I found it helps.
One other thing to note:
|A X B| = |A|.|B|.sin(theta)
Where || is magnitude, X is cross product and . is regular scalar multiply. Sorry to patronize but I’ve had some horrific misunderstandings before when it comes to mathematical notation. My point being that this is probably easier than messing around with trigonometric identities. Especially if you’re going to take my suggestion above.
Edit: Sorry to take so long. Typed out the reply, forgot to press post, made some tea, ended up talking for about an hour, came back, realized I am an idiot (funny how I keep forgetting that), wrote this apology.