Is this code alright?

This is about skeletal animation.
Some people use uniforms to index into the the bone array.
I was wondering why not use an attribute for that instead?

warning : the code may have bugs as I quickly typed it


attribute vec2 Weight;
uniform int index0;
uniform int index1;
uniform mat4 Bone[20];

mat4 transform = Bone[index0] * Weight.x + Bone[index1] * Weight.y;


attribute ivec2 index;
attribute vec2 Weight;
uniform mat4 Bone[20];

mat4 transform = Bone[index.x] * Weight.x + Bone[index.y] * Weight.y;

or a float version


attribute vec2 index;
attribute vec2 Weight;
uniform mat4 Bone[20];

mat4 transform = Bone[int(index.x)] * Weight.x + Bone[int(index.y)] * Weight.y;

Using attributes (rather than uniforms) is pretty much the standard way to do skeletal animation. If you use uniforms you might just as well simply send the looked up values rather than the indices.

So your code is OK, AFAICS.

Keep in mind that integer attributes are only available with GL_EXT_gpu_shader4.

Back in the NV3x-4x era I was just able to squeeze in 8 index/weight pairs needed for the Doom3 models into 4 texcoord vectors. Tight fit uniform wise, with around 120 quaternion/vec4 bones or so, but it worked great.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.