Picking after Vertex Shader has changed vertex

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”:

  1. “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)
  2. use glReadPixel function (on that FBO texture) to read a specified pixel color where the mouse is it
  3. 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
  4. re-render the same scene directly to screen

It is another way?

Thanks in advance.

You could render the scene to a Frame Buffer Object like deferred rendering. In this way, the transformed vertex data could be written to a MRT colour attachment, then you will have an exact floating point value of the vertex data. I’d use RGBA32F as the colour attachment.

Another choice is to use transform feedback on the model before you render it for real. This TFB would write the results of the skinning vertex shader to a vertex buffer. This would be ideal as it is then available for you to get a copy of this and transfer it back to CPU memory. You can then render the VBO as you would normally, except the vertex shader is simpler as you would have already skinned the models.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.