   Skinnig, Skeleton, Rotating around origin
  Hello, I have for a while trying to create my own skining vertex shader and I have one more problem that I just cant figure out.I Load my mesh as in a pose, that is the vertices are placed in worldspace, not relative to theirs joints..Each joints has a local and a world matrix, I add everything up as usual, world = parent world * localAfter this is done I add all world matrices for those joints to the matrix parameter in the shaderNow I start to render stuff...While looping through the vertex lists I set some parameters in the shader.First of, i set the array of indices that points to each joint that is affecting this vertex.I also set the array of weights for each joint....Now in the shader..I loop through a maximum of 4 bones / joint.->float3 newPosition = mul(model, InputPosition);netPosition += (Weight * newPosition);<-Most papers on this subject says the same thing, but leave out the part "But make sure you rotate around that joints origin"That I understand but how can it be done?As a result of the way i load my mesh, i have tried several methods...First of I read somewhere that you could precalculate the position of the vertices like:for (n)Vertex position = (Matrix[n].Position) * WeightTable[n];This will subtract the joints absolut position when loaded from the vertex to have it rotate around the origin when applying the matrix in the shader..This method works good if theres only one joint per vertex..But more weights give me an incorrect result.Another method i tried.If i leave my vertices as they are when loaded, and subtract the inputposition in the shader by its joints matrix position before rotatingIt works good for the first bone, but then its all ****** up..I know why it does. Just dont care to explain until I know that this method should work or not.Actually none of the methods Ive tried has really convinced me, but Ive tried them anyway.How on earth can you solve this without adding more paramters to the shader?/ Thanks in adv. 
  It looks like what you''re saying is "How can I transform the vertex from base pose model-space to bone-space so I can apply the bone-space to animated model-space that I''ve calculated?"Well, it seems that''s the question you -should- be asking  Now it seems that you understand this pretty well already, but I''m going to go through it step-by-step so that by the end you grok it completely.  You''ve solved for the 1-bone per vertex problem by subtracting the base-pose bone from the vertex position, but like you said, that doesn''t work for >1 vertex.To figure out the next step then you need to look at what you''re really doing when you do that subtraction -- you''re transforming the vertex from basepose model-space to bone-space, so of course the vertex will only be in the correct bone-space of that particular bone... what you want is to do that transformation for each bone that affects a vertex.  Which, thanks to concatenated matrices, is really easy!Your base-pose data for each bone is read in when you load the mesh, and this never changes.  Call the orientation/position of a bone in base-pose Mbp.  So to transform a bone from model-space back into bone-space you multiply by the inverse of Mbp, call it Mbp(-1) (note that if the rotation part of your bone''s matrix is the identity, then this is what you''re doing by doing that subtraction).  So for each bone, you can calculate Mbp(-1) when you load in the skeleton.Now, when you calculate the bone''s position in model-space based on the animation data, you come up with a matrix, call it Ma.  It sounds like you''re already doing this correctly?  Like I said, you want to transform the vertex from bp model-space to bone-space to animated model-space, so mathematically this is:V'' = Ma * Mbp(-1) * VWhat you want to do is multiply Ma by Mbp(-1) BEFORE you send it to the vertex shader.  Now assuming you''re doing your weighting correctly, in your shader you should select each bone affecting V, multiply it by V, scale that by its weight, and add it to the accumulated output vertex.  Most times you only need to skin your normal by the heaviest weighted bone and it will still look right.If this STILL doesn''t work, then you need to assert that your vertex weights sum to exactly one. ;  It really doesnt work but i think I understand you correctly.Well I will explain the way im currently doing it to see if I did miss understand you after all..1) I read my mesh, all bones are saved in relative positions to their parents. I have also removed all rotations for the bones because I want them to be stated as zero rotated when in model space.2) I Loop through them as usual and multiply by their parents to get the matrix as they are placed in the model space..3) I take this matrix and inverse it, and since their is no rotations i just inverte the translation elements in each and save the new matrix as Mbs. (You refere to this matrix as Mbp(-1)) If any joint in modelspace is located at (0, 10, 0) Mbp will be (0, -10, 0)4) I add some animations which will rotate the joints in their relative matrix.. 5) I loop all joints every frame and multiply parents animations with this joints relative animations and store them as MaI can see that all the joints are rotated as they should..6) Now im about to render the stuff so I do what you saidMa * Mbp(-1) Ma is my animation matrix which is the final position of that joint after rendering..So I do Ma = Ma * Mbp (This part i really didnt get a hang of, but i just did it) is Ma:s translation suppose to be how to get from that joint in model space to the origin? I mean thats how i can rotate my vertices around that point, but then i add that translation back to the final position and they are not the same so I suppose I didnt understand...7) Im sending the new Ma:s into the shader, and draw my vertices as usual.. (They are in model space when sended to the shader)8) While in the shader. I loop through all of the bones infuensing this vertex. I check the index to that bone and get the Ma matrix thats related to it.I subtract the position from the vertix and then newPosition = Ma * VertexPosition.NetPosition += newPosition * Weight;When done NetPosition should be the right position when the animation is done.....If everything I've said is true, theres something else that is wrong with my code./Tx for answering, took me a while to understand (if i did)  [edited by - Dies_Irae on February 4, 2004 12:54:07 PM];  The only part that''s wrong is the part near the end where you say"I subtract the position from the vertex"  That''s what you''re doing when you invert the base-pose matrix so don''t do it again.Just eliminate that little bit of code and you should be alright. ;  Awesome! Thants a lot, models looks wonderful.  [edited by - Dies_Irae on February 4, 2004 12:56:22 PM]