I’m trying to do Object Picking while I’m using Vertex and Pixel Shader.
My Vertex Shader is applying Animation’s Matrix which makes vertices to translate/rotate from bind_pose to animation_X_pose.
This is working well.
But now I’m facing a problem: my Vertex_position in computer’s RAM is different from the GPU one. This because the Vertex Shader have changed vertices positions but the CPU has got “old” coordinates of before rotations/translations by Animation Matrix.
In this case if I try to Picking (I know GL_SELECTION is deprecated, but it was my first Select_function and I didn’t wanted to waste too much time to RayCast or Color_Picking) an object with GL_SELECT it refers to CPU_coordinates and not GPU_coordinates.
I think this is the same problem with RayCasting which it needs to intersecate a “ray” from POV to CPU_coords.
If I should calculate Animation Matrix for every vertex on CPU (to have updated vertices_coords) I lose the advantage of using “GPU Skinning” performances.
How can I resolve this?
I was thinking to use FBO with “color picking”:
- “render” the scene to a FBO texture using a specified color for all vertices of any single object, without rendering real textures (just objects with specified colors)
- use glReadPixel function (on that FBO texture) to read a specified pixel color where the mouse is it
- decode color floating value (same example: 0.3, 0.3, 0.3) to an integer value (example: it could began “123456” as integer) and so I’ve got the ID
- re-render the same scene directly to screen
It is another way?
Thanks in advance.