HW skinning

Hi, I’m trying to make a vertex shaders
that multiplies the vertex position with a proper bone matrix and performs a simple diffuse lighting.

Here’s my code:

struct vpin
{
float4 position : POSITION;
float4 normal : NORMAL;
float4 color : COLOR0;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};

struct vpout
{
float4 position : POSITION;
float4 color : COLOR0;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};

vpout main(vpin IN, uniform float4x4 ModelViewProj,
uniform float3x4 Bones[64], uniform float3 Light, uniform float3 LRGB)
{

vpout OUT;
float3x4 m;
float3 pos;
float3 normal;
int index=(int)IN.position.w;

/* get proper position and normal vectors */
OUT.position.xyz = mul(Bones[index], IN.position);
OUT.position = mul(ModelViewProj, OUT.position);
normal = mul(Bones[index], IN.normal);
normal.x -= m[0][3];
normal.y -= m[1][3];
normal.z -= m[2][3];

/* define diffuse color by light */
OUT.color.a = IN.color.a;
OUT.color.rgb = clamp( dot(Light, normal), 0.0f, 1.0f)*LRGB;

/* pass texture coordinates */
OUT.texcoord0 = IN.texcoord0;
OUT.texcoord1 = IN.texcoord1;

return OUT;
}

When I compile it with NVidia’s compiler with arbvp1 path it crashes. Damn it!
When I reduce the bone matrix constant array to 16 ir compiles fine.
Any ideas what’s this about?

You mean taking 64->16 in this array: Bones[64]? What graphics card do you have?

I’m betting the problem is that ARB_vertex_program only guarentees a minimum of 96 const shader 4-vectors, so you’re overflowing it. You have 64*3 + 5 const shader slots (‘parameters’ in ARB_vertex_program syntax).

When you’re loading up your bones, you should check the native resource limit for the # of the parameters:

int maxProgramNativeParams = 0;
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &maxProgramNativeParams);

And adjust the number of arrays you pack accordingly.

Most cards just have 96 param slots, but some of the newer ones like my Radeon9800 has 256.

edit - UBB codes
edit - not sure about the 5 extra slots for (m, pos, normal) in 64*3 + 5, would need to the ARB_vertex_program version to be absolutely sure

[This message has been edited by Stephen_H (edited 01-02-2004).]

“I’m betting the problem is that ARB_vertex_program only guarentees a minimum of 96 const shader 4-vectors”

I checked and you’re right. Though I don’t know why the compiler crashed and didn’t just pop an error message.
However 96 const vectors is ridiculous for doing skinning, I need the vp to support at least 64 bones.

However 96 const vectors is ridiculous for doing skinning, I need the vp to support at least 64 bones.

Then split the model up into seperate rendering calls.