Sign in to follow this  
Mawww

glsl skinning : bone index vertex attribute problem

Recommended Posts

hello, I am currently adding skinning support in my engine, and I have problem with glsl and skinning. here is the vertex shader :
// 20 is a dumb limit...
uniform mat4 bonesmat[20];
attribute vec4 bonesidx;
attribute vec4 bonesweights;

varying vec3 normal;
varying vec3 viewvec;

void main(void)
{
    gl_Position = vec4 (0, 0, 0, 0);
    ivec4 ibonesidx = ivec4(bonesidx);
    for (int i = 0; i < 4; i++)
    {
        gl_Position += bonesmat[ibonesidx[i]] * gl_Vertex * bonesweights[i];
    }

    gl_Position = gl_ModelViewProjectionMatrix * gl_Position;

    normal = gl_NormalMatrix * gl_Normal;
    viewvec = gl_NormalMatrix * vec3 (gl_Vertex);
}
the problem is simply that this is really slow, under 2 fps on a radeon 9700. The problem seems to be in the float to int conversion. The question is : how can I pass integer value without killing my performances ?

Share this post


Link to post
Share on other sites
Hey Mawww,

I took a look at your code there and it looks mostly fine. The cause of the slowness may be related to that you are setting the output gl_Position 6 times during the program run, as well as reading from it once. I suggest making a temporary variable, maybe vec4 transVert = vec4(0.0); and using that in your loop, then finally doing gl_Position = gl_ModelViewProjectionMatrix * transVert;

Hopefully that'll help,

-Jeremiah

Share this post


Link to post
Share on other sites
I tested your suggestion Jeremiah and it does not change anything to the framerate. But I'm pretty sure that's due to float to int conversion, I tested using a fixed index, and then I get the normal performance.

Share this post


Link to post
Share on other sites
Alright, hmm. In your test of using a fixed index, did you still have the ivec4 ibonesidx = ivec4(bonesidx); line in there, but just didn't use that vector? What is the fixed index you're using? Are the ranges of your input data for indices within the [0-19] bounds?

Does modifying this line:

gl_Position += bonesmat[ibonesidx[i]] * gl_Vertex * bonesweights[i];

to:

gl_Position += bonesmat[int(bonesidx[i])] * gl_Vertex * bonesweights[i];

affect the speed?

If you take out the loop and use just the first index, does that affect anything?

I have noticed that on certain driver revisions, the ATI glsl compiler does strange things, so make sure you have the latest on that as well. I have a 9800 pro, but at the moment I'm unable to test with that because we are doing hardware testing for our game and the video card i'm currently using doesn't support GLSL.

Share this post


Link to post
Share on other sites
well, i tested without the ibonesweight and a replacing the index by 1 and the slowdown disapeared, I also tested with a fixed float value casted to an int and there was the slowdown.

If it may be a compiler problem more than a card one, I should mention that I am under linux, however as my engine is windows compatible, I will test under windows to see if all goes the same way.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this