HRESULT hr = D3DXCreateEffectFromFile(Graphic::device, "Data\\Shader\\SkinnedMesh.fx",
0, 0, D3DXSHADER_DEBUG, 0, &m_pEffect, &errors);
the return value is E_FAIL, and m_pEffect point to null, when i change the SkinnedMesh.fx to Water.fx, hr = S_OK,
so i think something wrong with SkinnedMesh.fx, here is the code
float4 black = {0.0f, 0.0f, 0.0f, 0.0f};
float4 lhtDir = {1.0f, -1.0f, -1.0f, 1.0f}; //light Direction
float4 MaterialAmbient : MATERIALAMBIENT = {0.3f, 0.3f, 0.3f, 1.0f};
uniform float4 MaterialDiffuse : MATERIALDIFFUSE = {0.8f, 0.8f, 0.8f, 1.0f};
static const int MAX_MATRICES = 26;
uniform float4x3 mWorldMatrixArray[MAX_MATRICES];
uniform matrix mWVP;
uniform matrix mWV;
uniform matrix mVP;
uniform matrix mW;
uniform matrix mV;
uniform matrix mP;
uniform texture tex;
uniform texture toontex;
uniform int CurNumBones = 2;
uniform float k;
float3 Pos = 0.0f;
float3 Normal = 0.0f;
float LastWeight = 0.0f;
sampler tt= sampler_state
{
Texture = <tex>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
};
sampler tx = sampler_state
{
Texture = <toontex>;
};
///////////////////////////////////////////////////////
struct SAVS_INPUT //SA: simple animation
{
float4 Pos : POSITION;
float4 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
float3 Normal : NORMAL;
float3 Tex0 : TEXCOORD0;
};
struct SAVS_OUTPUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR;
float2 Tex0 : TEXCOORD0;
};
SAVS_OUTPUT SAVS(SAVS_INPUT input)
{
SAVS_OUTPUT output= (SAVS_OUTPUT)0;
int4 IndexVector = D3DCOLORtoUBYTE4(input.BlendIndices);
float BlendWeightsArray[4] = (float[4])input.BlendWeights;
int IndexArray[4] = (int[4])IndexVector;
int NumBones=CurNumBones%3;
for (int iBone = 0; iBone NumBones; iBone++)
{
LastWeight = LastWeight + BlendWeightsArray[iBone];
Pos += mul(input.Pos, mWorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
Normal += mul(input.Normal, mWorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
}
LastWeight = 1.0f - LastWeight;
Pos += (mul(input.Pos, mWorldMatrixArray[IndexArray[NumBones]]) * LastWeight);
Normal += (mul(input.Normal, mWorldMatrixArray[IndexArray[NumBones]]) * LastWeight);
output.Pos = mul(float4(Pos.xyz, 1.0f), mVP);
output.Diffuse.xyz = MaterialAmbient.xyz + MaterialDiffuse.xyz * saturate( dot(normalize(Normal), -normalize(lhtDir.xyz)) );
output.Diffuse.w = 1.0f;
output.Tex0 = input.Tex0.xy;
return output;
}
/////////////////////////////////
struct SVS_INPUT
{
float4 position : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct SVS_OUTPUT
{
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR;
};
SVS_OUTPUT SVS(SVS_INPUT input)
{
SVS_OUTPUT output = (SVS_OUTPUT)0;
output.position = mul(input.position, mWVP);
output.texcoord = input.texcoord;
input.normal = normalize(mul(input.normal, mW));
output.color.xyz = MaterialAmbient.xyz + MaterialDiffuse.xyz * saturate(dot(input.normal, -normalize(lhtDir.xyz)));
output.color.w =1.0f;
return output;
}
////////////////////////////////
struct CAVS_INPUT
{
float4 Pos : POSITION;
float4 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
float3 Normal : NORMAL;
float3 Tex0 : TEXCOORD0;
};
struct CAVS_OUTPUT
{
float4 Pos : POSITION;
float3 Tex0 : TEXCOORD0;
};
CAVS_OUTPUT ACartoonVS(CAVS_INPUT input)
{
CAVS_OUTPUT output= (CAVS_OUTPUT)0;
int4 IndexVector = D3DCOLORtoUBYTE4(input.BlendIndices);
float BlendWeightsArray[4] = (float[4])input.BlendWeights;
int IndexArray[4] = (int[4])IndexVector;
int NumBones=CurNumBones%3;
for (int iBone = 0; iBone NumBones; iBone++)
{
LastWeight = LastWeight + BlendWeightsArray[iBone];
Pos += mul(input.Pos, mWorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
Normal += mul(input.Normal, mWorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
}
LastWeight = 1.0f - LastWeight;
Pos += (mul(input.Pos, mWorldMatrixArray[IndexArray[NumBones]]) * LastWeight);
Normal += (mul(input.Normal, mWorldMatrixArray[IndexArray[NumBones]]) * LastWeight);
output.Pos = mul(float4(Pos.xyz, 1.0f), mVP);
output.Tex0 = input.Tex0;
output.Tex0.z=0.0f;
output.Tex0.z += saturate( dot(normalize(Normal), -normalize(lhtDir.xyz)));
return output;
}
//////////////////////////////////
struct CVS_INPUT
{
float4 position : POSITION;
float3 normal : NORMAL;
float3 texcoord : TEXCOORD0;
};
struct CVS_OUTPUT
{
float4 position : POSITION;
float3 texcoord : TEXCOORD0;
};
CVS_OUTPUT CartoonVS(CVS_INPUT input)
{
CVS_OUTPUT output = (CVS_OUTPUT)0;
output.position = mul(input.position, mWVP);
output.texcoord = input.texcoord;
input.normal = normalize(mul(input.normal, mW));
output.texcoord.z = 0;
output.texcoord.z += saturate(dot(input.normal, -normalize(lhtDir.xyz)));
return output;
}
struct CPS_INPUT
{
float3 texcoord : TEXCOORD0;
};
struct CPS_OUTPUT
{
float4 color : COLOR;
};
CPS_OUTPUT CartoonPS(CPS_INPUT input)
{
CPS_OUTPUT output = (CPS_OUTPUT)0;
float3 vIntensity = (1.0f, 1.0f, 1.0f);
vIntensity *= tex2D(tt, input.texcoord.xy);
vIntensity *= max(0.4, tex1D(tx, input.texcoord.z).b);
output.color = float4(vIntensity, 0);
return output;
}
struct OUTLINE_INPUT
{
float4 position : POSITION;
float4 normal : NORMAL0;
};
struct OUTLINE_OUTPUT
{
float4 position : POSITION;
float4 color : COLOR;
};
OUTLINE_OUTPUT Main(OUTLINE_INPUT input)
{
OUTLINE_OUTPUT output = (OUTLINE_OUTPUT)0;
input.position = mul(input.position, mWV);
input.normal.w = 0.0f;
input.normal = mul(input.normal, mWV);
input.position += k * input.normal;
output.position = mul(input.position, mP);
output.color = black;
return output;
}
//////////////////////////////////////
struct outVS_INPUT //SA: simple animation
{
float4 Pos : POSITION;
float4 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
float3 Normal : NORMAL;
};
struct outVS_OUTPUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR;
};
outVS_OUTPUT outVS(outVS_INPUT input)
{
outVS_OUTPUT output= (outVS_OUTPUT)0;
int4 IndexVector = D3DCOLORtoUBYTE4(input.BlendIndices);
float BlendWeightsArray[4] = (float[4])input.BlendWeights;
int IndexArray[4] = (int[4])IndexVector;
int NumBones=CurNumBones%3;
for (int iBone = 0; iBone NumBones; iBone++)
{
LastWeight = LastWeight + BlendWeightsArray[iBone];
Pos += mul(input.Pos, mWorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
Normal += mul(input.Normal, mWorldMatrixArray[IndexArray[iBone]]) * BlendWeightsArray[iBone];
}
LastWeight = 1.0f - LastWeight;
Pos += (mul(input.Pos, mWorldMatrixArray[IndexArray[NumBones]]) * LastWeight);
Normal += (mul(input.Normal, mWorldMatrixArray[IndexArray[NumBones]]) * LastWeight);
input.Pos = mul(float4(Pos,1.0f), mV);
input.Normal = normalize(mul(Normal, mV));
input.Pos.xyz+= k *input.Normal ;
output.Pos = mul(input.Pos, mP);
output.Diffuse =black;
return output;
}
technique ASimpleTech
{
pass p0
{
VertexShader = compile vs_2_0 SAVS();
Sampler[0] = <tt>;
}
}
technique SimpleTech
{
pass p0
{
VertexShader = compile vs_2_0 SVS();
Sampler[0] = <tt>;
}
}
technique ACartoonTech
{
pass P0
{
VertexShader = compile vs_2_0 ACartoonVS();
PixelShader = compile ps_2_0 CartoonPS();
}
pass P1
{
VertexShader = compile vs_2_0 outVS();
PixelShader = NULL;
CullMode = CW;
}
}
technique CartoonTech
{
pass P0
{
VertexShader = compile vs_2_0 CartoonVS();
PixelShader = compile ps_2_0 CartoonPS();
}
pass P1
{
VertexShader = compile vs_2_0 Main();
PixelShader = NULL;
CullMode = CW;
}
}
technique AWaterTech
{
pass P0
{
VertexShader = compile vs_2_0 ACartoonVS();
PixelShader = compile ps_2_0 CartoonPS();
}
}
technique WaterTech
{
pass P0
{
VertexShader = compile vs_2_0 CartoonVS();
PixelShader = compile ps_2_0 CartoonPS();
}
}
I would appreciate for your help