Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Issues with Linear Z buffer due to Ortho projection

  1. #1
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81

    Issues with Linear Z buffer due to Ortho projection

    Hello All,

    I have the following problem:
    - 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!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    If you need a linear depth buffer, just lay out a linear depth buffer. Are you using shaders or is this legacy stuff?

  3. #3
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81
    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?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    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?

  5. #5
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81
    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!

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    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?

  7. #7
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81
    > 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)

    Thanks!

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Could you post a screen shot of what is actually going wrong?

  9. #9
    Intern Contributor
    Join Date
    Jan 2012
    Posts
    81
    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:
    http://stackoverflow.com/questions/8...e-depth-buffer

    I saw the solution there. I'm wondering if there could be a different approach.

  10. #10
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Well, I guess Alfonse's SO answer sums it up pretty nicely. I guess this is best solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •