Hey all, I have been putting together a complete tutorial that I will be releasing for free, on loading and rendering COLLADA in DirectX, I'm almost complete, all the code is written and most of the documentation is done. The tutorial covers static mesh loading, skinned mesh loading and morph targets mesh loading, all for indexed primitives, its been surprisingly easy to write so far however I've hit a problem.
Morph targets or blend shapes etc. will be exported as unindexed primitives, I'm using the COLLADAMaya 188.8.131.524 exporter with maya 2010; so there is no choice but unindexed primitives.
Ordinarily I have a pipeline set up whereby I would just use the COLLADARefinery "deindexer" conditioner and be on my way. This worked fine with static and skinned meshes, however with morph controlled meshes I think it doesn't work.
All the loading and drawing code is fine it seems but the morph target meshes look very erroneous upon deforming. Errors like holes in the face, incorrect normals and etc.
My vertex shader calculations could be wrong so I'll post that code here:
Code ://Sum the weights float weightSum = Weight.x + Weight.y + Weight.z + Weight.w; //Morph Position float4 Position = input.Position * (1 - weightSum); Position += (input.Position1 * Weight.x); Position += (input.Position2 * Weight.y); Position += (input.Position3 * Weight.z); Position += (input.Position4 * Weight.w); //Transform Position float4 worldPosition = mul(Position, World); float4 viewPosition = mul(worldPosition, View); output.Position = mul(viewPosition, Projection); //Morph Normal float3 Normal = input.Normal * (1 - weightSum); Normal += (input.Normal1 * Weight.x); Normal += (input.Normal2 * Weight.y); Normal += (input.Normal3 * Weight.z); Normal += (input.Normal4 * Weight.w); //Transform Normal output.Normal = normalize(mul(Normal, World));
I'm aware that I should be multiplying the Normal by the inverse transpose of the World matrix, generally I have found this to rarely impact anything visually and I have tried it but it didn't fix the problem as I suspected, it couldn't cause the problems I'm talking about anyway.
I noticed that prior to "deindex"-ing the file, the <morph> nodes had a "method" attribute, which curiously disappears after the operation. Seeing as how the vertex shader calculations above are for "NORMALIZED" method morph targets(I have so far only run into that type in maya export) the code should be fine.
This is what is leading me to believe that the deindex conditioner is causing problems. I thought I would seek advice here before I go and rewrite the importer to include unindexed primitives which I would then have to write my own indexing algorithm and blah blah blah; I'm trying to avoid all that for obvious reasons.
Checking the data in pix and perfhud it all seems okay, but I have only briefly glanced to see that the indices are all the same, will analyze everything further as I go but for now it seems like the data is okay. At the moment I'm fairly sure that it's the refinery that's causing my troubles.
Any help would be much appreciated.