# [D3D11 Effect] How to use SetMatrixArray?How access it on shader?

This topic is 2813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im currently use it like that:
XMMATRIX **ppMatrices = new XMMATRIX*[3];fxBoneMatrices->SetMatrixArray( (FLOAT*)ppMatrices[0], 0, 3 );

Im not sure if thats correct, since Im getting weird results, and using pix I dont understand the values Im getting(I want be sure the error is not sintax)..So I looked at DX10 sdk sample and they do it like that:
for( UINT i = 0; i < g_SkinnedMesh.GetNumInfluences( iMesh ); i++ )            {                const D3DXMATRIX* pMat = g_SkinnedMesh.GetMeshInfluenceMatrix( iMesh, i );                g_pmConstBoneWorld->SetMatrixArray( ( float* )pMat, i, 1 );            }

So I guess Im doing it right..
On the shader Im doing that:
matrix skinningTransform = 0;				if( input_p.BoneIDs.x != 5 )skinningTransform += mul( input_p.SkinWeights.x, BoneTransformsInterpolated[ input_p.BoneIDs.x ] );		if( input_p.BoneIDs.y != 5 )skinningTransform += mul( input_p.SkinWeights.y, BoneTransformsInterpolated[ input_p.BoneIDs.y ] );		if( input_p.BoneIDs.z != 5 )skinningTransform += mul( input_p.SkinWeights.z, BoneTransformsInterpolated[ input_p.BoneIDs.z ] );		if( input_p.BoneIDs.w != 5 )skinningTransform += mul( input_p.SkinWeights.w, BoneTransformsInterpolated[ input_p.BoneIDs.w ] );

Do you notice any mistake?

##### Share on other sites
Quote:
 since Im getting weird results

What exactly are the weird results?

Quote:
 XMMATRIX **ppMatrices = new XMMATRIX*[3];fxBoneMatrices->SetMatrixArray( (FLOAT*)ppMatrices[0], 0, 3 );

Did you ever initialize the matrices between those two lines?

How are the matrices in your shader declared? It should be something like :
cbuffer cbPerObject{    row_major float4x4 BoneTransformsInterpolated[ 3 ];};

##### Share on other sites
Original post by Icebone1000
Im currently use it like that:
XMMATRIX **ppMatrices = new XMMATRIX*[3];fxBoneMatrices->SetMatrixArray( (FLOAT*)ppMatrices[0], 0, 3 );

[/quote]
This looks suspicious. How are you filling the matrices before you send them off?
Why do you need a pointer to a pointer to a matrix?

##### Share on other sites
Is declared like that:

cbuffer cbChangers{

matrix BoneTransformsInterpolated[20];

};

I have a loop to initialize the matrices, so that they point to my bone matrices:
VOID SetBonesOnArray(){	//NOTE: remember that tha vertices IDs are according to the order of bones appareance in the pMesh->mBones!	//allocate mem:	ppMBoneArray = new XMMATRIX*[animSkeleton.iNBones];	//traverse mBones  of aiMesh:	Bone_Node *pBone = NULL;	for( UINT i = 0; i < pMesh->mNumBones; i++ ){		//get the bone_node by name:		animSkeleton.GetBoneByName( pMesh->mBones->mName.data, pBone, animSkeleton.pBoneRoot );		//reference its matrix onto array:		ppMBoneArray = &pBone->mFinal;	}}

Any mistake?
I dont know how to explain the weird values..My first array of matrices(for time 0.0) should be 3 identity matrices, and debuging I indeed get those..on pix I get other, but those other arent junk value ones, just not the expected one..and I dont have idea why(yet)..

On pix, the matrices are show like being just an array of rows, it shows my first matrix(for example) like that:(debuging on pix)
BoneTransformsInterpolated[0] float4
BoneTransformsInterpolated[1] float4
BoneTransformsInterpolated[2] float4
BoneTransformsInterpolated[3] float4

Can you see that Im not using it like that, when I use BoneTransformsInterpolated[ v.IDs.x ] Im expecting a full matrix here..At least is how Im imagining..

##### Share on other sites
Quote:
 the matrices are show like being just an array of rows

do the array of rows look like they contain the column values of the matrix? You need to make the following change :

cbuffer cbChangers{row_major matrix BoneTransformsInterpolated[20];};

HLSL receives the matrix data as column major by default (for optimization purposes), so if your matrix is row major and you don't make the suggested change, you'll get unexpected results.

##### Share on other sites
Using row_major or column_major keyword didnt changed anything..

I just seted a matrix like that just to see what I get on pix:
pCurrentBone_p->mFinal = XMMatrixSet( 11, 12, 13, 14,										21, 22, 23, 24,										31, 32, 33, 34,										41, 42, 43, 44 );

Pix display itlike this:
BoneTransformsInterpolated[0] (11.000, 12.000, 13.000, 14.000, )
BoneTransformsInterpolated[1] (21.000, 22.000, 23.000, 24.000, )
BoneTransformsInterpolated[2] (31.000, 32.000, 33.000, 34.000, )
BoneTransformsInterpolated[3] (41.000, 42.000, 43.000, 44.000 )

Its the same for column or row major..
The problem is with the next matrices( BoneTransformsInterpolated[4]..) I always get the same result:
BoneTransformsInterpolated[0] (0.000, 1.000, 0.000, 0.000, )
BoneTransformsInterpolated[1] (-1.000, 0.000, 0.000, 0.000, )
BoneTransformsInterpolated[2] (0.000, 0.000, 1.000, 0.000, )
BoneTransformsInterpolated[3] (2.495, 0.000, -0.009, 1.000 )

That matrix...I NEVER set this matrix to my bones->mFinal matrix..All my bones have the one I showed above( 11, 12..)
Quote:
 But that thing being displaied on pix, is the damn bone offsetmatrix, how is that there?..I never do this calculation ._.Debugging the call to the setmatrixarray, I have a watch on each of the 3 matrices, all of them have the same matrix(11, 12..)..

Damn..I just get it...My matrices arent contiguous on memory, the call to setmatrix array expect everything to lay like an array, since mine is an array of pointers..Im screwing everything(it gets the matrix next to the mFinal).. =D

I hope Im right...Hmm, how I solve that? I bet dont hold the final matrices on the bones, but in the structure that holds the bones, so I avoid a copy of all matrices per frame.. Im trying all that later, I cant right now.
Thanks a lot for the help!

-EDIT-
Indeed it was the problem, I got my skeletal animation/skinning working >w<

[Edited by - Icebone1000 on November 9, 2010 11:47:20 AM]

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002290
×