Matrix Array problem Syntax or Bug ?

Im running this on a win desktop Gl template.
The problem im having appears to be a very strange bug.

I attempted to load a matrix array to the shader

// in the shader
matrix Bones[50];

in game1

    Matrix[] allBones = new Matrix[50];
        for (int i = 0; i < 50; i++)
            allBones[i] = Matrix.Identity;
        effect.Parameters["Bones"].SetValue(allBones);

Now if i loop the entire array with a calculation it works fine and as expected the model is just in its identity state.

// ____________________________
VsOutputQuad VertexShaderQuadDraw(VsInputQuad input)
{
VsOutputQuad output;
float4 pos = mul(input.Position, World);

//Case1

// compiles and runs with no problems.
for (int i = 0; i < 50; i++)
    pos = mul(pos, Bones[i]);

// case1 ends

float4x4 vp = mul(View, Projection);
output.Position = mul(pos, vp);
output.TexureCoordinateA = input.TexureCoordinateA;
return output;

}

However that isn’t very useful sooo…

Making the modification to use a index is were the big problem comes in.
Replacing case 1 with the following

// Case2
// little alt test
int index = (int) (pos.x);
index = min(index, 0);
index = max(index, 49);
pos = mul(pos, Bones[index]);

the app compiles and runs … but … The model doesn’t show and the mouse and keyboard no longer responds.

however other user primitives draw and the frame rate continue to display.

This appears to be a bug but i would of thought someone would of seen it already?

or

Is this simply not the way its typically done.

I was thinking that for complex models with lots of bones it would be better to just load a really big array of bone matrices and have the vertice bone weight indices point to the index in that way so for a single mesh object i wouldn’t need to split up the mesh into parts and it would be fairly easy to instance it.

Of course that would probably also mean hard coding a set amount of matrices which i really don’t like that idea… but… this problem came up before i could even make up my mind and im wondering what is wrong if its something this code is doing or if this is actually a bug.

Because my alternate route is to use 4 matrices with mesh parts but still what happens when a vertice only has one bone do i have to for loop all the matrices anyways ?

Not sure what index = (int) pos.x; is for - just a test I’m guessing?
I’m wondering:
if index = min(-10,0), it would result in -10 right?
And if max(150,49) it would result in 150?

Unless I’m mistaken – maybe min and max need to be swapped?

Ya that’s just a shortcut for the test to save time.

if index = min(-10,0), it would result in -10 right?

Oh ya you’re right… damn i got the min max backwards well that figures.

Anyways that line is just meant to simulate the below operation.

In a working example that index would be sent in with the vertice data along with up to 3 more as a blend Index. Then that would be used as one of the matrices that affect the vertices position passed in to morph it.
basically but not exactly this as translations have to be applied as well but i haven’t actually coded it yet this is the jist of it.

float4 pos = mul(input.position, matrix[(int)(input.Indice.x)]) * input.Weight.x 
+ mul(input.position, matrix[(int)(input.Indice.y)]) * input.Weight.y;
// then
pos = pos / (input.Weight.x + input.Weight.y);  

This would be for 4 bones though.

So i guess now the question is do i want to do it this way or do i want to do it with mesh parts if i do it with mesh parts i pass far less matrix data. But i have to draw for each mesh part and i have to build them first. Im not sure what the advantages are or aren’t either way. Which is better ?

I don’t like the idea of passing 50 bone matrices for a model that only has 2 or 3.

Ah that should do the trick.
I’m still thinking though that min(index, 0) and max(index,49) should actually be
max(index,0) and min(index,49) to make sure it ranges from 0 to 49 (instead of outside that range)

It’ll be interesting to see the result when you get it working. :slight_smile:

Yes thanks a bunch that worked i changed it to 49 as well.
Im surprised it even ran at all and didn’t crash the index must of been out of bounds.

Ill post up the results when im done for anyone to use after i get the animations to read correctly i might even then try to make a xnb or xml exporter for it.

This is basically loading in the models with the nuget version of assimp.
So far i have the vertices, indices, texture uv’s, and the normals loaded.
This part im doing is for the bone weights though im not sure which way is better.

1 Like