glsl skinning : bone index vertex attribute problem

Started by
3 comments, last by Mawww 17 years, 11 months ago
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] * gl_Vertex * bonesweights;
    }

    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 ?
Tchou kanaky ! tchou !
Advertisement
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
Power User / Programmer / Game Player ( Not computer nerd :)
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.
Tchou kanaky ! tchou !
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] * gl_Vertex * bonesweights;

to:

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

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.
Power User / Programmer / Game Player ( Not computer nerd :)
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.
Tchou kanaky ! tchou !

This topic is closed to new replies.

Advertisement