Skinning problem using fx file

Started by
20 comments, last by Saad Manzur 10 years, 1 month ago

Hi,

Can anyone tell me if something wrong with the following fx code. I am trying to import and bind the skeleton to the vertices in order to animate . Got the original code from Frank D Luna and modified a bit without the tangent part.


# include "LightHelper.fx"

cbuffer cbPerFrame
{
	DirectionalLight gDirLights[3];
	float3 gEyePosW;
	float gFogStart;
	float gFogRange;
	float4 gFogColor;
};

cbuffer cbPerObject
{
	float4x4 gWorld;
	float4x4 gWorldInvTranspose;
	float4x4 gWorldViewProj;
	float4x4 gTexTransform;
	Material gMaterial;
};

cbuffer cbSkinned
{
	float4x4 gBoneTransforms[96];
};

Texture2D gDiffuseMap;

SamplerState samAnisotropic
{
	Filter = ANISOTROPIC;
	MaxAnisotropy = 4;

	AddressU = WRAP;
	AddressV = WRAP;
};

struct VertexIn
{
	float3 PosL : POSITION;
	float3 NormalL : NORMAL;
	float2 Tex : TEXCOORD;
};

struct SkinnedVertexIn
{
	float3 PosL : POSITION;
	float3 NormalL : NORMAL;
	float2 Tex : TEXCOORD;
	float3 Weights : WEIGHTS;
	uint4 BoneIndices : BONEINDICES;
};

struct VertexOut
{
	float4 PosH : SV_POSITION;
	float3 PosW : POSITION;
	float3 NormalW : NORMAL;
	float2 Tex : TEXCOORD;
};

VertexOut VS(VertexIn vin)
{
	VertexOut vout;

	vout.PosW = mul(float4(vin.PosL, 1.0f), gWorld).xyz;
	vout.NormalW = mul(vin.NormalL, (float3x3) gWorldInvTranspose);

	vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);
	vout.Tex = mul(float4(vin.Tex, 0.0f, 1.0f), gTexTransform).xy;
	
	return vout;
}

VertexOut SkinnedVS(SkinnedVertexIn vin)
{
	VertexOut vout;

	float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	weights[0] = vin.Weights.x;
	weights[1] = vin.Weights.y;
	weights[2] = vin.Weights.z;
	weights[3] = 1.0f - weights[0] - weights[1] - weights[2];
	
	float3 posL = float3(0.0f, 0.0f, 0.0f);
	float3 normalL = float3(0.0f, 0.0f, 0.0f);

	for (int i = 0; i < 4; i++)
	{
		posL += weights[i] * mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
		normalL += weights[i] * mul(vin.NormalL, (float3x3)gBoneTransforms[vin.BoneIndices[i]]).xyz;
	}

	vout.PosW = mul(float4(posL, 1.0f), gWorld).xyz;
	vout.NormalW = mul(normalL, (float3x3)gWorldInvTranspose);
	vout.PosH = mul(float4(posL, 1.0f), gWorldViewProj);
	vout.Tex = mul(float4(vin.Tex, 0.0f, 1.0f), gTexTransform).xy;

	return vout;
}

float4 PS(VertexOut pin, uniform int gLightCount, uniform bool gUseTexure, uniform bool gAlphaClip, uniform bool gFogEnabled) : SV_Target
{
	// Interpolating normal can unnormalize it, so normalize it.
	pin.NormalW = normalize(pin.NormalW);

	// The toEye vector is used in lighting.
	float3 toEye = gEyePosW - pin.PosW;

		// Cache the distance to the eye from this surface point.
		float distToEye = length(toEye);

	// Normalize.
	toEye /= distToEye;

	// Default to multiplicative identity.
	float4 texColor = float4(1, 1, 1, 1);
	if (gUseTexure)
	{
		// Sample texture.
		texColor = gDiffuseMap.Sample(samAnisotropic, pin.Tex);

		if (gAlphaClip)
		{
			// Discard pixel if texture alpha < 0.1.  Note that we do this
			// test as soon as possible so that we can potentially exit the shader 
			// early, thereby skipping the rest of the shader code.
			clip(texColor.a - 0.1f);
		}
	}

	//
	// Lighting.
	//

	float4 litColor = texColor;
	if (gLightCount > 0)
	{
		// Start with a sum of zero. 
		float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
			float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
			float4 spec = float4(0.0f, 0.0f, 0.0f, 0.0f);

			// Sum the light contribution from each light source.  
			[unroll]
		for (int i = 0; i < gLightCount; ++i)
		{
			float4 A, D, S;
			ComputeDirectionalLight(gMaterial, gDirLights[i], pin.NormalW, toEye,
				A, D, S);

			ambient += A;
			diffuse += D;
			spec += S;
		}

		// Modulate with late add.
		litColor = texColor*(ambient + diffuse) + spec;
	}

	//
	// Fogging
	//

	if (gFogEnabled)
	{
		float fogLerp = saturate((distToEye - gFogStart) / gFogRange);

		// Blend the fog color and the lit color.
		litColor = lerp(litColor, gFogColor, fogLerp);
	}

	// Common to take alpha from diffuse material and texture.
	litColor.a = gMaterial.Diffuse.a * texColor.a;

	return litColor;
}


technique11 Light1
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, false)));
	}
}

technique11 Light2
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, false)));
	}
}

technique11 Light3
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, false)));
	}
}

technique11 Light0Tex
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, false)));
	}
}

technique11 Light1Tex
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, false)));
	}
}

technique11 Light2Tex
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, false)));
	}
}

technique11 Light3Tex
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, false)));
	}
}

technique11 Light0TexAlphaClip
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, false)));
	}
}

technique11 Light1TexAlphaClip
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, false)));
	}
}

technique11 Light2TexAlphaClip
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, false)));
	}
}

technique11 Light3TexAlphaClip
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, false)));
	}
}

technique11 Light1Fog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, true)));
	}
}

technique11 Light2Fog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, true)));
	}
}

technique11 Light3Fog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, true)));
	}
}

technique11 Light0TexFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, true)));
	}
}

technique11 Light1TexFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, true)));
	}
}

technique11 Light2TexFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, true)));
	}
}

technique11 Light3TexFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, true)));
	}
}

technique11 Light0TexAlphaClipFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, true)));
	}
}

technique11 Light1TexAlphaClipFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, true)));
	}
}

technique11 Light2TexAlphaClipFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, true)));
	}
}

technique11 Light3TexAlphaClipFog
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, true)));
	}
}

technique11 Light1Reflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, false)));
	}
}

technique11 Light2Reflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, false)));
	}
}

technique11 Light3Reflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, false)));
	}
}

technique11 Light0TexReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, false)));
	}
}

technique11 Light1TexReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, false)));
	}
}

technique11 Light2TexReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, false)));
	}
}

technique11 Light3TexReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, false)));
	}
}

technique11 Light0TexAlphaClipReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, false)));
	}
}

technique11 Light1TexAlphaClipReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, false)));
	}
}

technique11 Light2TexAlphaClipReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, false)));
	}
}

technique11 Light3TexAlphaClipReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, false)));
	}
}

technique11 Light1FogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, true)));
	}
}

technique11 Light2FogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, true)));
	}
}

technique11 Light3FogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, true)));
	}
}

technique11 Light0TexFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, true)));
	}
}

technique11 Light1TexFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, true)));
	}
}

technique11 Light2TexFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, true)));
	}
}

technique11 Light3TexFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, true)));
	}
}

technique11 Light0TexAlphaClipFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, true)));
	}
}

technique11 Light1TexAlphaClipFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, true)));
	}
}

technique11 Light2TexAlphaClipFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, true)));
	}
}

technique11 Light3TexAlphaClipFogReflect
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, true)));
	}
}

technique11 Light1Skinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, false)));
	}
}

technique11 Light2Skinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, false)));
	}
}

technique11 Light3Skinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, false)));
	}
}

technique11 Light0TexSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, false)));
	}
}

technique11 Light1TexSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, false)));
	}
}

technique11 Light2TexSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, false)));
	}
}

technique11 Light3TexSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, false)));
	}
}

technique11 Light0TexAlphaClipSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, false)));
	}
}

technique11 Light1TexAlphaClipSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, false)));
	}
}

technique11 Light2TexAlphaClipSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, false)));
	}
}

technique11 Light3TexAlphaClipSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, false)));
	}
}

technique11 Light1FogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, true)));
	}
}

technique11 Light2FogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, true)));
	}
}

technique11 Light3FogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, true)));
	}
}

technique11 Light0TexFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, true)));
	}
}

technique11 Light1TexFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, true)));
	}
}

technique11 Light2TexFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, true)));
	}
}

technique11 Light3TexFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, true)));
	}
}

technique11 Light0TexAlphaClipFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, true)));
	}
}

technique11 Light1TexAlphaClipFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, true)));
	}
}

technique11 Light2TexAlphaClipFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, true)));
	}
}

technique11 Light3TexAlphaClipFogSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, true)));
	}
}

technique11 Light1ReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, false)));
	}
}

technique11 Light2ReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, false)));
	}
}

technique11 Light3ReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, false)));
	}
}

technique11 Light0TexReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, false)));
	}
}

technique11 Light1TexReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, false)));
	}
}

technique11 Light2TexReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, false)));
	}
}

technique11 Light3TexReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, false)));
	}
}

technique11 Light0TexAlphaClipReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, false)));
	}
}

technique11 Light1TexAlphaClipReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, false)));
	}
}

technique11 Light2TexAlphaClipReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, false)));
	}
}

technique11 Light3TexAlphaClipReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, false)));
	}
}

technique11 Light1FogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, false, false, true)));
	}
}

technique11 Light2FogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, false, false, true)));
	}
}

technique11 Light3FogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, false, false, true)));
	}
}

technique11 Light0TexFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, false, true)));
	}
}

technique11 Light1TexFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, false, true)));
	}
}

technique11 Light2TexFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, false, true)));
	}
}

technique11 Light3TexFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, false, true)));
	}
}

technique11 Light0TexAlphaClipFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(0, true, true, true)));
	}
}

technique11 Light1TexAlphaClipFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(1, true, true, true)));
	}
}

technique11 Light2TexAlphaClipFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(2, true, true, true)));
	}
}

technique11 Light3TexAlphaClipFogReflectSkinned
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, SkinnedVS()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_5_0, PS(3, true, true, true)));
	}
}

When I compile the effect file and use it to render the object the object just disappears. I mean when I loaded without trying to import the skeleton the object remained. In the graphics debugger visual studio ultimate 2013, I can make sure that in the input assembler everything is okay. I am stuck in this problem for days now and cannot debug the fx file in visual studio 2013. Can anyone give me a clue ? I have a deadline to do this project. Please give me some pointers.

About skeleton importing I used Assimp.

I stored offset matrix of every bone.
I traversed from root bone to each of the child and multiplied the child matrix with parent matrix.
I stored the weight with Bone indices in each vertices.
I think I set them correctly in the effect file.


        WorldViewProj = mFX->GetVariableByName("gWorldViewProj")->AsMatrix();
	World = mFX->GetVariableByName("gWorld")->AsMatrix();
	WorldInvTranspose = mFX->GetVariableByName("gWorldInvTranspose")->AsMatrix();
	TexTransform = mFX->GetVariableByName("gTexTransform")->AsMatrix();
	EyePosW = mFX->GetVariableByName("gEyePosW")->AsVector();
	FogColor = mFX->GetVariableByName("gFogColor")->AsVector();
	FogStart = mFX->GetVariableByName("gFogStart")->AsScalar();
	FogRange = mFX->GetVariableByName("gFogRange")->AsScalar();
	DirLights = mFX->GetVariableByName("gDirLights");
	Mat = mFX->GetVariableByName("gMaterial");
	DiffuseMap = mFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
	BoneTransforms = mFX->GetVariableByName("gBoneTransforms")->AsMatrix();

I do not have anyone in my country who can help me....

Advertisement

Just to clarify some things:

Are you using feature level 11? Have you verified your shader model can support 96 const matrices?

When the mesh appears correctly, are you using VS rather than SkinnedVS as the vertex shader?

It may not make a difference, but when you changed the "tangent" part, did you change the vertex declaration, semantics and input layout to match? Did you ensure you're not loading tangents into the vertex buffer?

For the skinned mesh (with skeleton), have you tried setting all bone transforms in the shader to the identity matrix (rather than using the bone transformation matrix) and use SkinnedVS? If the mesh appears correctly in VS, it should appear correctly with SkinnedVS using identity matrix gBoneTransforms,.

If you try that, and it renders correctly, then the problem is likely with the gBoneTransforms you calculate and load into the shader.

Take a look at Icebreaker's post. You may find some information there. Even though it's DX9, it may applicable to your problem.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


Are you using feature level 11? Have you verified your shader model can support 96 const matrices?


I am using feature 11 . But no I do not know if shader model 5 can support 96 const matrices.


When the mesh appears correctly, are you using VS rather than SkinnedVS as the vertex shader?


I am using VS() when it correctly renders.


It may not make a difference, but when you changed the "tangent" part, did you change the vertex declaration, semantics and input layout to match? Did you ensure you're not loading tangents into the vertex buffer?


I did change it. Here is the vertex structure and input layout that I am using...


struct PosNormalTexSkin
	{
		XMFLOAT3 Pos;
		XMFLOAT3 Normal;
		XMFLOAT2 Tex;
		std::vector<float> Weights;
		std::vector<UINT> BoneIndices;
	};

const D3D11_INPUT_ELEMENT_DESC InputLayoutDesc::PosNormalTexSkin[5] = 
{
	{"POSITION",     0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0},
	{"NORMAL",       0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
	{"TEXCOORD",     0, DXGI_FORMAT_R32G32_FLOAT,    0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
	{"WEIGHTS",      0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
	{"BONEINDICES",  0, DXGI_FORMAT_R32G32B32A32_UINT,   0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0}
};


For the skinned mesh (with skeleton), have you tried setting all bone transforms in the shader to the identity matrix (rather than using the bone transformation matrix) and use SkinnedVS? If the mesh appears correctly in VS, it should appear correctly with SkinnedVS using identity matrix gBoneTransforms,.

I tried it. If I use XMMatrixIdentity() the mesh does not load either. So, what's the problem here ?

Thanks for your help

Edit : Mesh does not load with identity matrix

Just for debugging , I printed the matrices to check if they are ok . It seems ok to me but I am not an expert .

2.54 0.000329 -3e-006 -0.000237
-0.000329 2.54 -3e-006 123.377
3e-006 3e-006 2.54 -0.157405
0 0 -0 1
This is the hip bone offset matrix.

It's too frustrating no matter what I do the nothing happens. Buck can you please help me fix this problem ? It's my term project and I have to submit it within last week of march.

Here is the code for the bone importer .


Bones::Bones()
{
	mBoneTransforms = new XMFLOAT4X4[96];
}

Bones::~Bones()
{
	//
}

void Bones::LoadBones(aiNode *pRoot, int parent)
{
	out_file2 << pRoot->mName.C_Str() << std::endl;

	BoneInfo bi;
	bi.Name = pRoot->mName.C_Str();
	AItoXM(pRoot->mTransformation, bi.offsetMatrix);
	//XMStoreFloat4x4(&bi.offsetMatrix,XMMatrixIdentity());
	bi.ownIndex = index;
	bi.parentIndex = parent;
	
	mBoneInfo.push_back(bi);
	mBoneInfoMap[bi.Name] = bi.ownIndex;


	index++;

	for (int i = 0; i < pRoot->mNumChildren; i++)
	{
		std::string s1(pRoot->mChildren[i]->mName.C_Str());
		if (s1.find("Bind_") != std::string::npos)
			LoadBones(pRoot->mChildren[i], bi.ownIndex);
	}
}



void Bones::Set()
{
	/*BoneHierarchy.resize(mBoneInfo.size());
	for (int i = 0; i < mBoneInfo.size(); i++)
	{
		BoneHierarchy[i] = mBoneInfo[i].parentIndex;
	}
	BoneOffsets.resize(mBoneInfo.size());
	for (int i = 0; i < mBoneInfo.size(); i++)
	{
		BoneOffsets[i] = mBoneInfo[i].offsetMatrix;
	}*/

	for (int i = 0; i < mBoneInfo.size(); i++)
	{
		if (mBoneInfo[i].parentIndex != -1)
			mBoneInfo[mBoneInfo[i].parentIndex].childrenIndices.push_back(i);
	}
	out_file2 << "\nChecking the set function...\n";
	for (int i = 0; i < mBoneInfo.size(); i++)
	{
		out_file2 << mBoneInfo[i].Name << " -> ";
		for (int j = 0; j < mBoneInfo[i].childrenIndices.size(); j++)
		{
			out_file2 << mBoneInfo[mBoneInfo[i].childrenIndices[j]].Name << ", ";
		}
		out_file2 << std::endl;
	}
}

void Bones::PrintBones()
{
	out_file2 << "\nParent Children Relation...\n";
	for (int i = 0; i < mBoneInfo.size(); i++)
	{
		out_file2 << mBoneInfo[i].Name << "->";

		for (int j = 0; j < mBoneInfo[i].childrenIndices.size(); j++)
		{
			int curIndex = mBoneInfo[i].childrenIndices[j];
			out_file2 << mBoneInfo[curIndex].Name << " ";
		}

		out_file2 << std::endl;
	}
	out_file2 << std::endl;
}

void Bones::Traverse(int index, XMFLOAT4X4 parentMat)
{
	XMMATRIX temp = XMLoadFloat4x4(&parentMat);
	XMMATRIX temp2 = XMLoadFloat4x4(&mBoneInfo[index].offsetMatrix);
	XMStoreFloat4x4(&mBoneInfo[index].offsetMatrix, XMMatrixMultiply(temp2, temp));

	out_file2 << mBoneInfo[index].Name << " traversed..." << std::endl;

	for (int i = 0; i < mBoneInfo[index].childrenIndices.size(); i++)
		Traverse(mBoneInfo[index].childrenIndices[i], mBoneInfo[index].offsetMatrix);
}

void Bones::XMBones()
{
	for (int i = 0; i < mBoneInfo.size(); i++)
	{
		mBoneTransforms[i] = mBoneInfo[i].offsetMatrix;
	}
}

void Model::SetWeight(aiBone *pBone)
{
	for (UINT i = 0; i < pBone->mNumWeights; i++)
	{
		BoneData bd;
		bd.vertexID = baseIndex + pBone->mWeights[i].mVertexId;
		bd.Weight = pBone->mWeights[i].mWeight;
		mBones.mBoneInfo[mBones.mBoneInfoMap[pBone->mName.C_Str()]].weightData.push_back(bd);
		out_file3 << bd.vertexID << " : " << bd.Weight << std::endl;
		if (vertices[bd.vertexID].Weights.size() == 4) return;
		vertices[bd.vertexID].Weights.push_back(bd.Weight);
		vertices[bd.vertexID].BoneIndices.push_back(mBones.mBoneInfoMap[pBone->mName.C_Str()]);
	}
}


I am really at my wit's end. ...

First, if you don't approach it methodically, you may never find the problem. You have to start with where the problem manifests itself and go from there.

So, back to the shader problem.

"If I use XMMatrixIdentity() the mesh does not load either." - I'm not sure what you did. Did you set the gBoneTransforms to the identity matrix and use SkinnedVS to render it? EDIT: from the code you posted, it appears that you're setting bone matrices to identity. That's not at all what I suggested.

The gBoneTransforms are an array in your shader. Those are the ones I suggest you set to identity matrices. Nothing else.

From what you printed out for the matrix above, it may indicate a problem, but I can't tell in what order you printed out the numbers. IF you printed it out row-by-row, that's a column-major matrix and the shader requires row-major matrices. However, I would suggest you continue to determine what problems may be with using the shader. That's where you know you have a problem.

Did you read the topic I linked? The one that IceBreaker posted?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I set them to identity matrices as you said. But nothing happened . I printed them row by row (first line is first row). Do I have to transpose them ? I am giving graphics debugger a try at the moment. To see the hlsl takes the values correctly.

I read the topic. It was talking about animation mostly though. Like icebreaker I built my importer based on the concept of the tutorial without the animation part. I just wanted to see if I can import the bones in T pose.

Edit : When using the debugger. The debugger gives an error message debugging the shader file. The graphics debugger failed to build shader trace and therefore it is unable to debug the shader


I am giving graphics debugger a try at the moment. To see the hlsl takes the values correctly.

That appears to be a good approach. IF you set the gBoneTransforms array in the shader to identity, you should be rendering just the mesh vertices without other matrices being involved. That, of course, depends on how you setup for rendering, etc. By setting the shader gBoneTransforms to identity, then there is essentially no difference between using VS and SkinnedVS. EDIT: An important thing you can do is to verify in SkinnedVS that posL is equal to vin.posL after the matrix calculation lines. That is IF you're using identity matrices for gBoneTransforms.


I printed them row by row (first line is first row). Do I have to transpose them ?

If there's any way for people to help you, you have to read what they post. Please read my previous post about the matrices. AGAIN - if you do not take a methodical approach you may never find the problem.

EDIT:


I read the topic. It was talking about animation mostly though.

Maybe I am misunderstanding what you're trying to do. I just assumed you were trying to render an animated skinned mesh as you said in your original post.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Ok, sorry for my impatience. I read through it thoroughly this time . But I didn't understand some points .

_finalBoneTransformations[boneID] = (_globalInverseMatrix * finalTransform * this->_bones[boneID].offsetMatrix).Transpose();

_globalInverseMatrix is the inverted matrix of the root node; Is this only to make sure the model is rotated correctly?

node->mTransformation is the matrix relative to the parent node

this->_bones[boneID]->offsetMatrix is a matrix which transforms from mesh into bone space

What is this _globalInverseMatrix ? I knew that every bone had its offset matrix. If I multiply them serially from parent to child . They will all link up . Am I wrong ?

So the sequence is: calculate row-major scale, rot and trans mats. Transpose each one. Multiply them in right-to-left order (an indication of column-major matrices) to get the node transformation. Multiply the node-transform with the parent (right-to-left order because the parent is column-major also). Multiply the result by globalinverse and bone-offsets (column-major) to get the final transform. Transpose the final to make it compatible with shader row-major requirement.

So it seems my code is written in column major. From the topic I have these following questions . What is global transform and local transform ? Why three matrices ? And how can I get them ?

Edit :

I have not animated the rig yet. Just the skeleton in T pose. And do you use the visual studio 2013 graphics debugger. I am unable to debug the shader files using it . It gives error message.

Edit2 :
I am going through your article on animated mesh again.


I have not animated the rig yet. Just the skeleton in T pose.

Have you bone-weighted the vertices? If you haven't, then there's no sense in testing SkinnedVS in the shader yet. By the way, the shader code looks fine. It's all but identical to Luna's and I assume you made the tangent changes and the remainder is the same.

If the vertices have bone-indices and bone-weights set properly, then you should be able to render the mesh using SkinnedVS with gBoneTransforms all set to identity. If the VS shader routine renders the vertices correctly, that indicates to me that you have not set the bone-indices and bone-weights correctly, or that the vertex data coming into the SkinnedVS routine in your shader, for whatever reason, is incorrect. I suggest that you pursue that fact. IF you have a problem, you have to start debugging at the place where the problem manifests itself, and work backward or forward from there.

With regard to your questions about various transforms IceBreaker uses, you should be able to examine your own code and find the parallels. I personally don't know what all of IceBreakers transform are, but made observations AFTER he had some information regarding the problem that manifested itself in the shader. You're not there yet. You're still at "The SkinnedVS portion of my shader doesn't seem to render the mesh properly." You have to determine why it doesn't. See the questions above about bone-weights and bone-indices.

EDIT: I saw that you posted a question about the shader debugging error message. Do you compile your shaders for debugging? I can't tell you how to do that, by the way, but googling indicates that may be your problem.

I do not use the 2013 graphics debugger because I've got the Express version of VS - I think only full versions support that.

EDIT2: I'm not sure if you were referring to IceBreaker's code or my article. In the skinned mesh article "local transform" is a transform that defines a frame's orientation with respect to it's parent (and only to it's parent). For instance, a roof rack could be considered to have the car as it's parent. The local transform defines it as parallel with and located at the center of the roof of that car. Note: the car may be moving, stationary or spinning wildly, but the local transform for the roof rack is still valid. That is to distinguish the child frame's orientation to the world.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement