Jump to content

  • Log In with Google      Sign In   
  • Create Account


Passing bone matrices to shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 belfegor   Crossbones+   -  Reputation: 2386

Like
1Likes
Like

Posted 05 January 2013 - 06:33 AM

I have couple of different models with varying bones count.
To get away from shaders switch could i just use one for all without consequence?

I tried this and it worked:
MAX_BONES = 35;
...
vector<D3DXMATRIX> vMat; // vMat size varies from 20 - 30 depending on a model
...
effect->SetValue(hMatrices, &vMat[0], MAX_BONES * sizeof(D3DXMATRIX));

...
float4x4 mats[MAX_BONES];
...

Edited by belfegor, 05 January 2013 - 06:35 AM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27930

Like
5Likes
Like

Posted 05 January 2013 - 06:57 AM

Yes, that is a common approach.
However, your SetValue call should use vMat.size()*sizeof(D3DXMATRIX), otherwise you're reading past the end of the vector.



#3 belfegor   Crossbones+   -  Reputation: 2386

Like
1Likes
Like

Posted 05 January 2013 - 07:02 AM

Then i always need a vector with size of MAX_BONES ?

Thats why i asked this question, is there a harm if it reads past the end of a vector, even if that data isn't used? Or is it undefined behaviour?

I got shader error if i pass it like this:
effect->SetValue(hMatrices, &vMat[0], vMat.size() * sizeof(D3DXMATRIX));
vMat size is 33, but in shader i have:
float4x4 mats[35];

Edited by belfegor, 05 January 2013 - 07:06 AM.


#4 Hodgman   Moderators   -  Reputation: 27930

Like
6Likes
Like

Posted 05 January 2013 - 07:40 AM

is there a harm if it reads past the end of a vector, even if that data isn't used? Or is it undefined behaviour?

Yes it's harmful; it could crash your program. If you're lucky, nothing bad will happen (besides the extra bones containing garbage values), but it could crash depending on how the OS has decided to allocate your memory...

I got shader error if i pass it like this:

Ah, that must be an issue with the D3DX Effect framework -- I usually just use D3D shaders directly, and they allow you to send less data than the shader requires (with the unsent elements of the array containing garbage values).

In that case, just use vMat.resize(MAX_BONES) to avoid the error and also avoid the undefined behaviour wink.png



#5 JohnnyCode   Members   -  Reputation: 195

Like
0Likes
Like

Posted 07 January 2013 - 09:57 AM

the bone indicies on verticies should always point to a defined matrix in the uniform array of matricies. So define the array correctly, feeding it matricies that conform to indicies. About that error, though it is unlikely, you may have a limit of 32 in the uniform array, in case you are using realy old pixel shader model.

Edited by JohnnyCode, 07 January 2013 - 09:57 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS