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

Thread: Picking with OpenGL ES 2.0

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    21

    Picking with OpenGL ES 2.0

    Hi,

    i try to implement a coordinate picking function with OpenGL ES 2.0.
    I cannot implement the two versions i've implemented in my desktop version.

    Version 1 is to render every triangle in a unique color, which represent the index of the triangle and than to calculate the coordinate with an raycast. This version doesn't work, because in the OpenGL ES GLSL Version 1.0 is no variable GL_PrimitiveID an bitwise shifting is also not possible.

    Version 2 is to render the coordinate as the value of a floating-point texture, but floating-point texture is not available in OpenGL ES 2.0.

    Has anybody another idea what I can implement? I don't want to raycast every triangle, because it's not so performant.

    Thanks for help and any ideas.

  2. #2
    Junior Member Regular Contributor tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223
    You can render unique color for each triangle (or vertex, if you want to select points) in each object. You will need to prepare a vertex attribute which will carry triangle ID color in each object, and your rendering logic will need to maintain an offset ID color that you can add in shader. You need some extra logic to make sure no overflow from one component happens to next component (skip colors / per object offsets which would overflow). Also make sure you get 888 bit colors instead of something less like
    565.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    Does you es system support OES_depth_texture extension? This would allow you the capture the depth buffer and use the standard unproject method to caclulate the pick point.

  4. #4
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    302
    Quote Originally Posted by tonyo_au View Post
    Does you es system support OES_depth_texture extension? This would allow you the capture the depth buffer and use the standard unproject method to caclulate the pick point.
    Using this method can be somewhat imprecise, however. You can lose a lot of depth precision because of the non-linear Z transform quantizing eye Z to NDC. An alternative is to render uv or barycentric coords, and using that and the primitive ID you can compute the exact Z depth on the CPU using the pick result. Quite possible that the depth buffer provides enough precision for the OP's purposes, but if not, the uv method is a good alternative.

Posting Permissions

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