I need 2D billboarded items, that are screen-space constant in size, inside a 3D scene.
My solution:
Use 2 matrices, one for orthographic projection, one for perspective.
Using this solution works fine, except, i have depth issues. This is because the Z-Buffer would be linear when i use the ortho matrices, but non-linear for perspective matrices.
This is now leading to wrong depth test results.
I’m not sure how exactly i can solve this problem. Any insights would really be helpful.
Also, please let me know if this use-case is common.
Thanks for the reply! Yeah, i am using Shaders(OpenGL 2.0). Is it possible to have a linear depth buffer with a perspective matrix? Can you please explain this?
I am referring to something like 2D labels, that are drawn using alpha textured 2D quads. These label items in the 3D scene. And, these also need to be billboarded.
Thanks!
Hmm, from the top of my head I’d go straight to simply projecting the billboard as well, but scaling it with a factor that’s a function of distance to the camera. Another question is, do you want the billboards to show on top of everything else or is it ok if they are correctly depth tested?
> Hmm, from the top of my head I’d go straight to simply projecting the billboard as well, but scaling it with a factor that’s a function of distance to the camera.
Well the current implementation involves this scaling, that is a function of the Z distance from the near plane.
But, im trying for a better implementation.
> Another question is, do you want the billboards to show on top of everything else or is it ok if they are correctly depth tested?
Yes, depth test is the main concern.(i.e i need proper depth testing)
hmm, i currently do not have access to it.
But the problem is that the depth testing would have problems since there is a mix of linear and non-linear depth calculation. So, stuff that need to fail depth test would actually pass.
I found a very similar article here:
I saw the solution there. I’m wondering if there could be a different approach.