Shader question

Started by
6 comments, last by lucky6969b 11 years, 8 months ago

////////////////////////////////////////////////////////////////////////////
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
Advertisement
have you tried to use PIX? it could debugg a specific pixel for you and show you your output and from there you could see abit more whats causing the problem.


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]]);


what im not sure of here is why you after you have calulcated your local net transform, are again adding this

p += lastWeight * mul(IN.position, FinalTransforms[IN.boneIndices[n]]);


it´s like, adding bone 0 twice so you get extra much skinning from this joint.
"There will be major features. none to be thought of yet"
Hi,
Ran PIX-64-bit. Got the following error
https://www.asuswebstorage.com/navigate/share/GYYAKUIM5Y
Basically my program runs except there are some memory leaks and crashes at the end of execution
that hardens the problem some...

But why are you adding the first bone to the netpos after you have calculated the weighted netpos??
"There will be major features. none to be thought of yet"
You're correct after a deep thought. I need to clean that up later, now I want to concentrate on rendering.
Thanks for your help
but... did you solve your problem?
"There will be major features. none to be thought of yet"
Can run PIX now. Locale problem... thanks

This topic is closed to new replies.

Advertisement