I have the following problem:
- I need 2D billboarded items, that are screen-space constant in size, inside a 3D scene.
- 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.
If you need a linear depth buffer, just lay out a linear depth buffer. Are you using shaders or is this legacy stuff?
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?
Well the mathematics is simple, but I think I might have misunderstood something.
You want billboards that have a constant size in screen-space. Are we talking something like a HUD or what is it you want?
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.
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)
Could you post a screen shot of what is actually going wrong?
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.
Well, I guess Alfonse’s SO answer sums it up pretty nicely. I guess this is best solution.