View Full Version : Picking a skinned character

09-02-2009, 08:30 AM
Hi Opengl Gurus,

http://gedalia.net/images/shader_comparison.jpg 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?

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.

09-02-2009, 12:37 PM
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.

09-06-2009, 02:41 PM
Perhaps this is a stupid question, but why don't you determine the closest bone inside of the fragment shader instead?

09-08-2009, 11:25 PM
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.