2012-10-12 3 views
1

3D와 셰이더를 배우고 있으며 몇 주 동안 쉐이더를 만들었습니다.한 줄을 변경하면 셰이더에서 오류가 발생합니다.

이 셰이더에서 한 행에 문제가 있습니다. 하나를 주석 처리하고 다른 행으로 교체하면 IDirect3DDevice9::CreateVertexShader()이 호출 될 때 오류가 발생합니다. 모든 필드가 설정되어 있고이 동작은 모두 boneTransformsviewProj을 단위 행렬로 설정할 때도 발생합니다. 내가 모델을 보게 될 것이고, 그 한 라인 (주석 처리 된)을 변경하면 버텍스 쉐이더가 컴파일되지 않을 것이다. 왜 이런 일이 발생합니까? 나는이 일을 디버깅하는 데 보냈으며 이유를 찾을 수 없다!

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(); 
    } 
} 

감사합니다!

답변

1

당신은 그렇지 않으면 최대 일정한 버퍼 크기 이상 갈 것

static const int MAX_MATRICES = 50; 

MAX_MATRICES

을 줄이기 위해 필요합니다.

관련 문제