Use the itembuffer appoach. You render a distinct color per identifiable object into a 1x1 pixel sized FBO (with a proper projection matrix and viewport set, no MSAA enabled). Then you read back the pixel. This way you determine the ID of the foremost object. If you need per-triangle picking, you should be able to use a geometry shader and gl_PrimitiveID.
yes…I need ray-triangle intersection…
but i don’t understand what is 1 x 1 pixel rendering target…
and how use geometry shader to get nearest ray-triangle intersection (gl_PrimitiveID)…
i don’t find any suggestion of this problem in the inet…
Then simply sort a output buffer data for distance to view point.
I’ve never used the gl_PrimitiveIDIn, so I can only recommend to read GLSL Spec 1.50
The input variable gl_PrimitiveIDIn is available only in the geometry language and is filled with the
number of primitives processed by the geometry shader since the current set of rendering primitives was
started.
The output variable gl_PrimitiveID is available only in the geometry language and provides a single
integer that serves as a primitive identifier. This is then available to fragment shaders as the fragment
input gl_PrimitiveID, which will select the written primitive ID from the provoking vertex in the primitive
being shaded. If a fragment shader using gl_PrimitiveID is active and a geometry shader is also active,
the geometry shader must write to gl_PrimitiveID or the fragment shader input gl_PrimitiveID is
undefined.