Jump to content

  • Log In with Google      Sign In   
  • Create Account


Skinning problem using fx file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
21 replies to this topic

#1 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 March 2014 - 05:15 AM

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....



Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 4460

Like
2Likes
Like

Posted 09 March 2014 - 06:48 AM

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.


Edited by Buckeye, 09 March 2014 - 06:51 AM.

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


#3 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 March 2014 - 12:09 PM


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


Edited by Saad Manzur, 09 March 2014 - 02:02 PM.


#4 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 March 2014 - 01:18 PM

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. 

Edited by Saad Manzur, 09 March 2014 - 01:42 PM.


#5 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 March 2014 - 02:42 PM

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. ...



#6 Buckeye   Crossbones+   -  Reputation: 4460

Like
0Likes
Like

Posted 09 March 2014 - 03:06 PM

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?


Edited by Buckeye, 09 March 2014 - 03:13 PM.

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


#7 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 March 2014 - 03:18 PM

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


Edited by Saad Manzur, 09 March 2014 - 03:28 PM.


#8 Buckeye   Crossbones+   -  Reputation: 4460

Like
0Likes
Like

Posted 09 March 2014 - 03:34 PM


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.


Edited by Buckeye, 09 March 2014 - 03:52 PM.

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


#9 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 09 March 2014 - 04:01 PM

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. 


Edited by Saad Manzur, 09 March 2014 - 04:11 PM.


#10 Buckeye   Crossbones+   -  Reputation: 4460

Like
1Likes
Like

Posted 09 March 2014 - 05:02 PM


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.


Edited by Buckeye, 09 March 2014 - 09:36 PM.

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


#11 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 10 March 2014 - 07:30 AM

Buck I read your article not the IceBreaker's one. The one you wrote about skeleton and skinning. Yes I have weighted each vertex. But there is a tad bit problem. Not every vertex have bone influencing it less than 4. That may be the problem I guess. 

As for your article I came to understand this . I will have toParent matrix from the file I imported. I have to multiply it by gradually to get toRoot transformation. And then I have to import a new matrix of transformation from each key frame for each bone and store it in the transformation matrix . Am I correct ? I did not multiply 3 matrices as you can see. I only traversed using the matrix I got from the imported file. So the local is equivalent to toParent ? 

toParent = a matrix in reference with the parent

toRoot = a matrix in reference with the root

transformation = ... I am still confused what it does actually

And also each vertex has variable length bones. How do I set the input layout according to that. I mean some have only 2 bones influencing it and some have 6. 



#12 Buckeye   Crossbones+   -  Reputation: 4460

Like
0Likes
Like

Posted 10 March 2014 - 08:22 AM

First: it appears you have the concept of the "toParent" and "toRoot" matrices correct. The TransformationMatrix is primarily just a handy storage place. However, depending on how you import data, TransformationMatrix often starts out initialized as the "toParent" matrix. In that case, be sure to calculate the "toRoot" matrices before you use the TransformationMatrix for any other purpose. That is, "use it before you lose it." Once the "toRoot" and offset matrix calcs have been done, you won't need the "toParent" matrix any more.

 

Second: You have to decide on some maximum number of influence bones. I can't remember where I read it, but 4 influences per-vertex is usually more than enough. Your shader code (which is a very common implementation BTW) assumes a maximum of 4 influence bones.

 

Third: Assume you set a maximum vertex influence at 4 bones. When you set up the vertices (probably during loading or shortly thereafter), make sure each vertex has at least one influence bone, and no more than 4.

 

If your model has more than 4 influence bones, the best approach is to go back to the modeling program and redo the bone-weighting. At this point, I really don't think you want to get into adding code to your import routine to handle more than 4. Alternatively, when you import, you can simply ignore any bone influences greater than 4. However, depending on how the model was weighted, you won't know what you're throwing away.

 

In any case:

 

Also, when setting up the vertices, make sure the indices and weights for "unused" bones are set to 0.

 

For instance, assume a vertex has 2 influence bones, indexed as A and B. The vertex structure requires 4 bone indices and weights be defined.

 

For that vertex:

bone index 0: A

bone index 1: B

bone index 2: 0

bone index 3: 0

 

bone weight 0: A's weight factor

bone weight 1: B's weight factor

bone weight 2: 0

bone weight 3: 0

 

That should keep you busy for a little while.


Edited by Buckeye, 10 March 2014 - 08:25 AM.

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


#13 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 10 March 2014 - 01:32 PM

I had already imported the weights but did not initialize the unused ones as 0. If I decide to keep maximum of 6 bone influences what would be the input layout for that ? Just curious...

 



#14 Buckeye   Crossbones+   -  Reputation: 4460

Like
0Likes
Like

Posted 10 March 2014 - 02:41 PM


If I decide to keep maximum of 6 bone influences what would be the input layout for that ?


You should write your own code. Besides, I personally wouldn't know a good way to do that. But if you use something other than 4 influences, remember to revise the shader.


Edited by Buckeye, 10 March 2014 - 02:44 PM.

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


#15 ankhd   Members   -  Reputation: 1220

Like
0Likes
Like

Posted 10 March 2014 - 04:40 PM

Hi.
Try loading your mesh in a viewer program.
And when first writting skinning shader make sure you have a skinned mesh that works.
And some time the scale of the mesh is so small you can't see it or it's behind the camera.

#16 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 14 March 2014 - 11:22 AM

Hi.
Try loading your mesh in a viewer program.
And when first writting skinning shader make sure you have a skinned mesh that works.
And some time the scale of the mesh is so small you can't see it or it's behind the camera.

I have tried using Assimp viewer to view the file. In the viewer I can see the mesh , material and skeleton just fine



#17 Saad Manzur   Members   -  Reputation: 196

Like
0Likes
Like

Posted 14 March 2014 - 12:50 PM

Hey Buck,

What can you make of this output for weights ?
 

0.030172, 0.969828, 0, -1.07374e+008, 
0.030955, 0.969045, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.029477, 0.970523, 0, -1.07374e+008, 
0.030172, 0.969828, 0, -1.07374e+008, 
0.030955, 0.969045, 0, -1.07374e+008, 
0.031927, 0.968073, 0, -1.07374e+008, 
0.031205, 0.968795, 0, -1.07374e+008, 
0.031205, 0.968795, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.030955, 0.969045, 0, -1.07374e+008, 
0.029477, 0.970523, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.029685, 0.970315, 0, -1.07374e+008, 
0.029685, 0.970315, 0, -1.07374e+008, 
0.029, 0.971, 0, -1.07374e+008, 
0.029477, 0.970523, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 
0.031205, 0.968795, 0, -1.07374e+008, 
0.030684, 0.969316, 0, -1.07374e+008, 
0.030684, 0.969316, 0, -1.07374e+008, 
0.029685, 0.970315, 0, -1.07374e+008, 
0.03023, 0.96977, 0, -1.07374e+008, 

Something definitely is going wrong I think. This prints the weight for each vertex. The fourth weight remains constant as you can see. I set them initially to zero.



#18 Buckeye   Crossbones+   -  Reputation: 4460

Like
0Likes
Like

Posted 14 March 2014 - 01:08 PM

Looks pretty good. You don't say what "output" is from, but looks like those vertices all have 2 bone weights which sum to 1 (which should be fine). The other weights are 0. Looks as one might expect for vertices with 2 influence bones, but can take up to 4 influence bones. I wouldn't worry about the 4th weight looking "constant." It's close enough to 0 as makes no difference.

 

The last value might just be the normal process of using the first 3 weights and setting the last weight to 1.0 - weight1 - weight2 - weight3.


Edited by Buckeye, 14 March 2014 - 01:11 PM.

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


#19 unbird   Crossbones+   -  Reputation: 4973

Like
1Likes
Like

Posted 15 March 2014 - 03:32 AM

Buckeye, it's e+ not e- wink.png 
 
A float value of -1.07374e+008 gives me raw hex of 0xCCCCCCB6, which almost looks like the magic number for bad memory. Anyway, a weight of -107 millions sounds bad.

#20 Buckeye   Crossbones+   -  Reputation: 4460

Like
0Likes
Like

Posted 15 March 2014 - 08:02 AM

Buckeye, it's e+ not e- wink.png 
 
A float value of -1.07374e+008 gives me raw hex of 0xCCCCCCB6, which almost looks like the magic number for bad memory. Anyway, a weight of -107 millions sounds bad.

 

Hokey Smokes, Rockie! Wow. Missed that one. Good catch, unbird. However, I suspect it's immaterial.

 

@Saad: Where are you getting the data you posted? From what point in your code? If it's coming from the input to the shader, and you're using the shader you posted in this topic, there's only 3 weights being input to the shader (which is fine), and you only need to look at 3.

 

Does your vertex format support 3 weights or 4? If it supports 3 weights and you're setting 4, you may be trashing some memory somewhere.


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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS