Picking a skinned character

Hi Opengl Gurus,

I’m attempting to get color picking working on parts of a skinned character. I have color pick working on parts of my scene, however it’s currently limited to rigid objects, or an entire skinned character. I’m interested in the nearest bone to the clicked location.

I’m using GLSL to do the skinning, and I’m able to hand the vertex shader a uniform array that can act as a lookup table (bone index to color). The vertex shader can then color vertex with color of the bone with the maximum weight influence (see image). The problem is that the pixel shader interpolates between the various colors. Making picking the area around the joints impossible.

Is there a way to make the pixel shader pick the color of the nearest vertex instead of interpolating, or another method that might work?
thanks,
-Gedalia

ps. a posting on a different board got the suggestion of setting glShadeModel(GL_FLAT);
which forces the triangle to be one of 3 colors with out interpolation, not perfect but I think what I was looking for.

Interesting problem.

You may try with the ‘flat’ qualifier for the vertex output color in vertex shader (and input to pixelshader).
That will not return ‘nearest’ but at least interpolation will be disabled.

Perhaps this is a stupid question, but why don’t you determine the closest bone inside of the fragment shader instead?

You might want to use the geometry shader? There you could use the three maximum weight/index pairs to determine the color for the triangle. If you can’t use the geometry shader, the flat shading method might be the only good way.