////////////////////////////////////////////////////////////////////////////
extern float4x4 FinalTransforms[100];
extern int NumVertInfluences = 2; // <--- Normally set dynamically.
//Vertex Input
struct VS_INPUT_SKIN
{
float4 position : POSITION0;
float3 normal : NORMAL;
float2 tex0 : TEXCOORD0;
float4 weights : BLENDWEIGHT0;
int4 boneIndices : BLENDINDICES0;
};
//Pixel Shader
float4 ps_lighting(VS_OUTPUT IN) : COLOR0
{
//float4 color = tex2D(DiffuseSampler, IN.tex0);
//return color * IN.shade;
return IN.color;
}
VS_OUTPUT vs_Skinning(VS_INPUT_SKIN IN)
{
VS_OUTPUT OUT = (VS_OUTPUT)0;
float4 p = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 norm = float3(0.0f, 0.0f, 0.0f);
float lastWeight = 0.0f;
int n = NumVertInfluences-1;
IN.normal = normalize(IN.normal);
for(int i = 0; i < n; ++i)
{
lastWeight += IN.weights;
p += IN.weights * mul(IN.position, FinalTransforms[IN.boneIndices]);
norm += IN.weights * mul(IN.normal, FinalTransforms[IN.boneIndices]);
}
lastWeight = 1.0f - lastWeight;
p += lastWeight * mul(IN.position, FinalTransforms[IN.boneIndices[n]]);
norm += lastWeight * mul(IN.normal, FinalTransforms[IN.boneIndices[n]]);
p.w = 1.0f;
// matW is the world transform of the "whole" object
// where p is the object transform of the "part" object
float4 posWorld = mul(p, matW);
// matVP is the transform into view-projection space
OUT.position = mul(posWorld, matVP);
OUT.color = vMaterialColor;
OUT.tex0 = IN.tex0;
//Calculate Lighting
norm = normalize(norm);
norm = mul(norm, matW);
OUT.shade = max(dot(norm, normalize(lightPos - posWorld)), 0.2f);
return OUT;
}
technique Skinning
{
pass P0
{
Lighting = false;
AlphaBlendEnable = TRUE;
DestBlend = INVSRCALPHA;
SrcBlend = SRCALPHA;
VertexShader = compile vs_2_0 vs_Skinning();
PixelShader = compile ps_2_0 ps_lighting();
}
}
In the above snippet, there is something wrong with rendering. The pixel shader is no doubt and is correct because I could use different vs and rendered correctly. However when it comes to skinning, it has some problems. First, the mesh cannot be scaled down and the vMaterialColor has no effect unlike the other technique that uses the same pixel shader. When I output just the color of the mesh, it should be okay to work without normals and since the lighting is turned off by default. In the C++ program, I can see the correct material values, it is in the "default" pose where i have actually posed and animated the character.
[attachment=10788:character_mesh.png]
what is going on?
Thanks
Jack