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 8 of 8

Thread: gluUnProject without glReadpixels

  1. #1
    Intern Newbie
    Join Date
    May 2006
    Posts
    47

    Question gluUnProject without glReadpixels

    Hello,

    I have a quick question for you experts.

    I'm using gluUnProject, which is great. And commonly people would use glReadPixels with the GL_DEPTH_COMPONENT to find the viewing volume z value to feed to gluUnProject to determine a 3D point.

    My problem is, I want the z value where the projected ray intercepts the Z-plane, and not the object obstructing it. -For example a bunch of trees. ReadPixel would stop once it hit the tree in the depth component look up. -I need the ray to pass through the tree and stop when the z in the viewing volume touches the Z plane (zero) of OGL space.

    Put simply, I need the "ground" unprojected, not the stuff on it.

    I guess I need to use something other than glReadPixels to find viewing volume z of the Z plane?

    Any ideas?

    Thanks very much,

    Cameron

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    the win z value in gluUnProject is a value between 0 and 1 from the depth buffer. If you use 0 you get a point in the near plane, if you use 1 you get a point on the far plane. You now have a ray that you can do what you like with.

  3. #3
    Intern Newbie
    Join Date
    May 2006
    Posts
    47

    Arrow

    Quote Originally Posted by tonyo_au View Post
    the win z value in gluUnProject is a value between 0 and 1 from the depth buffer. If you use 0 you get a point in the near plane, if you use 1 you get a point on the far plane. You now have a ray that you can do what you like with.

    Thanks, but I understand that already. What I would like to do with that ray is find out where the Z plane (Z origin, Z zero) is within the zNear (0) and zFar (1) viewing area.

  4. #4
    Member Regular Contributor
    Join Date
    Jan 2005
    Location
    USA
    Posts
    411
    I think you will have to reformulate the question. I can't understand anyway, so I doubt anyone could

    ...so you are projecting through some 2D coordinate on the near plane (let's say your camera lens) and it needs to intersect with what precisely? Just describe it in everyday language if you can.
    God have mercy on the soul that wanted hard decimal points and pure ctor conversion in GLSL.

  5. #5
    Intern Newbie
    Join Date
    May 2006
    Posts
    47
    Quote Originally Posted by michagl View Post
    I think you will have to reformulate the question. I can't understand anyway, so I doubt anyone could

    ...so you are projecting through some 2D coordinate on the near plane (let's say your camera lens) and it needs to intersect with what precisely? Just describe it in everyday language if you can.
    Ok, imagine the camera has a location of 0,20,20 and we are looking directly at the Origin (0,0,0), so we're approximately looking at 45 degrees towards the Z plane which is treated as the ground, the camera has a zNear of 0.1 and a zFar of 100.

    My window is 500x500 and the mouse cursor is at 100,100 and I want to know where the mouse cursor is projecting a ray that touches the Z plane.

    A typical case would be an RTS game, where you have a view like this, and where the 2D mouse is in the window, sets a flat in-world 2D reticule on the ground. It ignores units and building structures, including trees and other stuff.

    It's just a flat ground, it's simply the Z-plane.

    Thanks,

    Cameron

  6. #6
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    455
    Just perform a line-plane intersection test. No need to use glReadPixels for this.

  7. #7
    Intern Newbie
    Join Date
    May 2006
    Posts
    47
    Oh yes, that works! Thanks Dan!

    .. and thanks to the other contributors for your feedback.

  8. #8
    Member Regular Contributor
    Join Date
    Jan 2005
    Location
    USA
    Posts
    411
    This is what I thought but I was not sure so I did not want to complicate the thread. Good job with your second description! And good luck
    God have mercy on the soul that wanted hard decimal points and pure ctor conversion in GLSL.

Posting Permissions

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