Vertex weights

Started by
5 comments, last by Wilhelm van Huyssteen 12 years, 6 months ago
Hi.

I want to implement vertex wieghts in my engine.

I have a an idea of how i would do it but i dont know if its optimal. I havent done any reseach on this so im just guessing.

My way would limit the amount of parent bones of each vertice to 3.

I would create a vertex atribute that would store 3 parent bone id's.
I would create another vertice atribute that would store 3 weight values (one for each parent)
I would pass an array of matrixes to my vertice shader, one for each parent bone's absolute transformation.

My vertex shader will then use the 3 id's to get the 3 parent matrixes from the array of matrixes and using those together with the weight values to calculate the final matrix.

Is my line of thought more or less correct? anything else i should keep in mind? Thnx in Advance!
Advertisement
That's correct, although the traditional method has been to store the matrices in a cbuffer (or uniform array before cbuffers). Using a texture works too, as of DX9c/DX10.

3 is a strange number to choose as a limit though -- why not 2 or 4?
I just edited my origanel post from textures to uniforms right before you submitted your post.

but thnx for confirming that both ways would work. Just wondering about using uniforms.

Can the size of the array vary? or does it need to be declared with a fixed size in the shader. And if it has to have a fixed size whats a good amount? What if you have a mesh with alot of bones, wont that cause issues when using uniform arrays? I thought there was a limit with the amount of data you can send through using uniforms.

EDIT: I think i confused it with the limit there is on the amount of varying variables. Wich makes more sense.
Yea I dont think there is a limit to uniforms as they are just data, varying means it actually gets computed from vert to pixel shader.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Can the size of the array vary? or does it need to be declared with a fixed size in the shader. And if it has to have a fixed size whats a good amount? What if you have a mesh with alot of bones, wont that cause issues when using uniform arrays? I thought there was a limit with the amount of data you can send through using uniforms.
In DX9, you're limited to 256 float4's worth of uniform data (256 is the minimum for SM3 compliance, individual cards may support higher numbers).
In DX10/11, cbuffers can contain 4KB of data each (IIRC), and you can have 14 constant buffers bound at once. Alternatively, tbuffers can hold 128MB of data each ;)

Yes, the maximum size of your array has to be fixed at shader-compile time. In our DX9 renderer, we make an array of 150 float4's, which gives us storage for 50 4x3 bone matrices. If a model requires more than 50 bones, it has to be drawn in multiple draw-calls. This also means we can't use instancing with animated meshes.
In DX11, or on DX9 using the bones-in-a-texture method, you're less limited in this regard.
If you use a 4x3 matrix, do you just use x,y,z of the vertex, mutliply it and the do : glPosition = glModelViewProjectionMatrix*vec4(x,y,z,1.0) ?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Thnx! thats all i needed to know about vertex weights.

This topic is closed to new replies.

Advertisement