I’m learning 3D and shaders and I’ve got a shader I’ve spent weeks creating.
I have an issue with a single line in this shader – commenting one and replacing it with another will cause the effect to fail when IDirect3DDevice9::CreateVertexShader() is called. All the fields have been set, and this behaviour also occurs when I set all the boneTransforms and viewProj to identity matrices. As is I’ll see the model, and changing that one line (commented) will cause the vertex shader not to compile. Why does this happen? I have spent days debugging this and cannot find a reason!
static const int MAX_MATRICES = 100;
float4x3 boneTransforms[MAX_MATRICES] : WORLDMATRIXARRAY;
float4x4 ViewProj : VIEWPROJECTION;
struct VS_INPUT
{
float3 Pos : POSITION;
float4 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
float3 Normal : NORMAL;
float2 Tex0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex0 : TEXCOORD0;
float4 Diffuse : COLOR;
};
VS_OUTPUT VShade(VS_INPUT i)
{
VS_OUTPUT o;
int4 blendIndicies = D3DCOLORtoUBYTE4(i.BlendIndices);
float blendWeights[4] = (float[4])i.BlendWeights;
int boneIndicies[4] = (int[4])blendIndicies;
float3 pos = mul(i.Pos, boneTransforms[boneIndicies[0]]) * blendWeights[0]
+ mul(i.Pos, boneTransforms[boneIndicies[1]]) * blendWeights[1]
+ mul(i.Pos, boneTransforms[boneIndicies[2]]) * blendWeights[2]
+ mul(i.Pos, boneTransforms[boneIndicies[3]]) * blendWeights[3];
float4 aaa = mul(float4(pos.xyz, 1.0f), ViewProj);
//////////////////////////////////////////////////////////////////////////////
// If I comment out this SINGLE line
o.Pos = mul(float4(i.Pos.xyz, 1.0f), ViewProj);
// and replace it with this one, then IDirect3DDevice9::CreateVertexShader() returns D3DERR_INVALIDCALL
// o.Pos = aaa;
//////////////////////////////////////////////////////////////////////////////
o.Diffuse = 1.0f;
o.Tex0 = i.Tex0.xy;
return o;
}
float4 PShade(VS_OUTPUT i) : COLOR
{
return float4(1.0, 1.0, 1.0, 1.0);
}
technique technique0
{
pass p0
{
//PixelShader = compile ps_2_0 PShade();
VertexShader = compile vs_2_0 VShade();
}
}
Thank you!
You need to try to reduce MAX_MATRICES
Otherwise you will go over the maximum constant buffer size.