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.

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.

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.