I am migrating an XNA 4 project to MonoGame. I have a problem with a skinned shader, the blendindices have zero values when passed to the vertex shader. I have used colored pixel debugging to determine this, and compared the results with the original XNA project.
The shader was upgraded from SM 2 to SM 4 during the migration.
The vertex buffer contains the expected values before the Draw call.
Here is the input struct which is contained in the vertex buffer:
// This is passed into our vertex shader from Xna struct VS_INPUT { // This is the position of the vertex in the model file float4 position : SV_Position; // The vertex normal float3 normal : NORMAL0; // This is the texture coordinate for the vertex in the model file float2 texcoord : TEXCOORD0; // These are the indices (4 of them) that index the bones that affect // this vertex. The indices refer to the MatrixPalette. half4 indices : BLENDINDICES0; // These are the weights (4 of them) that determine how much each bone // affects this vertex. float4 weights : BLENDWEIGHT0; };
In the model processor, the blend indices for each vertex are packed into a Byte4 struct like so:
Vector4 bi = new Vector4(); bi.X = count > 0 ? indexer.GetBoneIndex(bwc[0].BoneName) : (byte)0; bi.Y = count > 1 ? indexer.GetBoneIndex(bwc[1].BoneName) : (byte)0; bi.Z = count > 2 ? indexer.GetBoneIndex(bwc[2].BoneName) : (byte)0; bi.W = count > 3 ? indexer.GetBoneIndex(bwc[3].BoneName) : (byte)0; indicesToAdd[i] = new Byte4(bi);
All of this works perfectly in XNA. I am wondering if the problem could be in marshalling data from Byte4 to half4. The latter structure is twice the size. But if I change it to float4, it makes no difference.