PDA

View Full Version : skeleton anim without dynamic array index???



linghuye
04-27-2007, 06:30 PM
hi guys,
I wrote a GLSL vertex shader for my skeleton animation, and it works well under Nvidia card(from 6100 to 7950).
But it run very slowly under ATI card X1650XT on WinXP with the lastest 7.4 driver, and I found the link log said:
"Link successful. The GLSL vertex shader will run in software - unsupported language element used"
After some debuging I found the unsupported language element is that dynamic array index used for bone matrix.
And I search the net and find someone say that current graphic card does not support non-compile-time-constant array index.

So I am confused, if dynamic array index is not supported, How can I or how do you guys do the GPU skeleton animation?
By the way, the glsl language spec is too vague to catch whether or not it support dynamic array index.

Any help or insight would be appreciated.


attribute vec4 bone;
attribute vec4 weight;
uniform mat4 boneMatrices[32];

void main()
{
vec4 blendVertex = vec4(0, 0, 0, 0);
vec4 blendWeight = weight;
ivec4 blendBone = ivec4(bone);

for(int i = 0; (i < 4) &amp;&amp; (blendWeight.x > 0); i++)
{
blendVertex += boneMatrices[blendBone.x] * gl_Vertex * blendWeight.x;
blendBone = blendBone.yzwx;
blendWeight = blendWeight.yzwx;
}

gl_Position = gl_ModelViewProjectionMatrix * blendVertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;

vec4 ecPos = gl_ModelViewMatrix * blendVertex;
gl_FogFragCoord = abs(ecPos.z);
}

oc2k1
04-27-2007, 07:30 PM
Some optimizations:

remove the complex condition from the for loop. The dynamic for loop is more expensive the a static unrolled version.


attribute vec4 bone;
attribute vec4 weight;
uniform mat4 boneMatrices[32];

void main()
{
vec4 blendVertex = vec4(0, 0, 0, 0);
for(int i = 0; i < 4; i++)
{
blendVertex += boneMatrices[int(bone[i])] * gl_Vertex * weight[i];
}
gl_Position = gl_ModelViewProjectionMatrix * blendVertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
vec4 ecPos = gl_ModelViewMatrix * blendVertex;
gl_FogFragCoord = abs(ecPos.z);
} That code is simpler for the compiler. (But it won't fix that problem)

Korval
04-27-2007, 07:48 PM
And I search the net and find someone say that current graphic card does not support non-compile-time-constant array index.That's untrue. Graphics cards have been able to index into arrays since GeForce 3. Not in fragment programs, mind you, but it's been there. I'd guess your problem is what oc2k1 mentioned; the complex conditional logic. Just do what he suggested and do the extra work.

linghuye
04-28-2007, 04:22 AM
Amazingly the optimizations do fix that problem. Now it works well on the ATI X1650XT in hardware mode.

Thanks very much for your kind replies.

yooyo
04-28-2007, 03:26 PM
Take look this thread..
http://www.opengl.org/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic;f=11;t=000459;p=1