Im implementing webgl picking from scratch, and have decided to go down the GLSL route, as oppose to ray intersection testing.
so Im rendering the whole scene into a separate frame buffer, assigning each object a unique color which is passed to the fragment shader as a uniform variable. when the scene is rendered then I gl.readPixels() the buffer, and get the color values at the click coordinates (I invert the coord system to account for GL differing from the browsers coord system).
the issue Im having is that shaders represent colors passed to the gl_FragColor shader output as vec4 floats with 0.0-1.0 range per color channel, whereas gl.readPixels() returns color channels as integers in the 0-255 range... doing this translation loses some precision, and might create picking errors (if there are a lot of objects in the scene (more then 255), or if the integer-to-float rounding is larger then the granularity needed to differentiate between different object ID's).
does anyone have an idea how to resolve this, or point me in the right direction? can readPixels() return float values for color channels in the 0.0-1.0 range? can I pack a single object ID spread over multiple channels (so that Im not limited to a single channel and only being able to pick 255 objects?)
thank you for your help