locked
shader compile error issue?

    Question

  • Hi, all

         I met a problem about compile the vertex shader in vs2012, the vertex shader as

    cbuffer TransMatrix: register( b0 ){
       matrix u_Model;
       matrix u_View ;
       matrix u_Projection;
       matrix u_MVMatrix;
       matrix u_VPMatrix ;
       matrix u_WVPMatrix;
       matrix u_ModelInver;
       matrix u_PreWVMatrix ;
       matrix u_PreWVPMatrix;
        float4 light_position;
        float4 light_WDirect;
        float4 light_VDirect;
        float4 material_ambient;
        float4 material_diffuse;
        float4 material_specular;
        float4 material_color;
        float light_Cutoff;
        float light_Exponent;
        float   material_shininess;
        float   material_Aphla;
       float3 EyePosModel;
       float SpecularIntensity;
       float4 NTexRange;
       float4 MTexRange;
       float4 BTexRange;
       float4 RTexRange;
       float4 NTexBound;
       float4 MTexBound;
       float4 BTexBound;
       float4 RTexBound;
       float4 Deformbend[5];
       matrix BendInver[5];
       matrix BendMatrix[5];
       int    lDBNum;
       float u_MotionBlurStre ;
       float2 padding1 ;
       float4 u_effectParam;
       float4 u_darkcornerParam;
       float4 u_assistEffParam;
       float2 u_imgSize;
       float2 padding2 ;
       matrix u_NMatrix;
       float4 u_TexUVMatU;
       float4 u_TexUVMatV;
    }
    //////////////////////////////
    // VertexInput Type defines //
    //////////////////////////////
    struct VertexInputType
    {
       float3 Position : POSITION;
       float3 Texcoord : TEXCOORD0;
    };
    ////end of vertex input 
    ////define of vertex output 
    struct PixelInputType
    {
        float4 Position : SV_POSITION;
        float2 NTexcoord : TEXCOORD0;
        float2 MTexcoord : TEXCOORD1;
        float2 BTexcoord : TEXCOORD2;
        float2 EnvTexcoord : TEXCOORD3;
        float3 ReflectDir  : TEXCOORD4;
        float4 Illum : COLOR0;
        float4 Specu : COLOR1;
        float4 v_darkcorner : COLOR2;
        float4 v_TexPara    : COLOR3;
    };
    ////////////////////////////////
    ////////light caculate////////
    ////////////////////////////////
    void CalcPhoneLighting(float3 vEyeDir, float3 vNormal, float3 vLightDir, inout float4 vIllum, inout float4 vSpecu)
    {
     float NdotL = max(dot(vNormal, vLightDir), 0.0);
     vIllum.xyz += material_ambient.xyz + material_diffuse.xyz * NdotL;
     if (NdotL > 0.0) {
      float3 vHalfVector = normalize(vLightDir + vEyeDir);
      float NdotH = max(dot(vNormal, vHalfVector), 0.0);
      vSpecu.xyz += material_specular.xyz * pow(NdotH, material_shininess);
     }
    }
    
    ////////light caculate two face////////
    void CalcAmbientAndDiffuse2(in float4 vNormal, in float4 vLightDir, out float4 vIllum)
    {
     // Ambient
     float4 ambient  = 2*material_ambient;
     // Diffuse
     float4 diffuse  = material_diffuse;
     diffuse *= max(max(0.0, dot(vNormal, vLightDir)),dot(-vNormal, vLightDir));
     
     vIllum = ambient + diffuse;
     vIllum.w = 1;
    }
    
    void CalcSpecular2(in float4 vVertex, in float4 vNormal, in float4 vLightDir, out float4 vSpecu)
    {
     vSpecu = float4(0.0,0.0,0.0,1.0);
     float angleCos = dot(vNormal, vLightDir);
     vNormal = (angleCos<0.0)?-vNormal:vNormal;
     angleCos = abs(angleCos);
     if (angleCos > 0.0) {
      vLightDir = mul(u_View , vLightDir);
      vNormal   = mul(u_View , vNormal);
      vVertex  = mul(u_View , vVertex);
      
      float4 reflectline = reflect(-vLightDir, vNormal);
                float4 VertextoCamara = normalize(-vVertex);
      float specuCoeff = max(0.0, dot(VertextoCamara, reflectline));
      vSpecu = material_specular;
      vSpecu*= pow(specuCoeff, material_shininess);
      vSpecu = abs(vSpecu);
     }
    }
    
    ////////////////////////////////////
    ////////bend deform caculate////////
    ////////////////////////////////////
    void BendDeform(in out float4 wPosition)
    {
         //if(lDBNum==1) return;
         float4 dPosition = float4(0.0,0.0,0.0,0.0);
         for(int i = 0; i<lDBNum; i++)
         {        float4 vPosition = mul(BendInver[i], wPosition);
            float4 vMove =  float4(0.0,0.0,0.0,1.0);
            if(Deformbend[i].w==0.0) continue;
            float fRadius = 1.0/Deformbend[i].w;
            float fAngle = 0.0;
            float fcosA = 0.0;
            float fsinA = 0.0;
            float fTemp = 0.0;
            if(vPosition.y<Deformbend[i].y)
            {
                fAngle = Deformbend[i].y*Deformbend[i].w;
                fTemp = vPosition.y-Deformbend[i].y;
            }
            else if(vPosition.y>Deformbend[i].z)
              {
                  fAngle = Deformbend[i].z*Deformbend[i].w;
                  fTemp = vPosition.y-Deformbend[i].z;
              }
              else
              {
                  fAngle = vPosition.y*Deformbend[i].w;
                  fTemp = 0.0;
              }
            fcosA = cos(fAngle);
            fsinA = sin(fAngle);
            vMove.x = fRadius-fRadius*fcosA +fTemp*fsinA+vPosition.x*fcosA;
            vMove.y = fRadius*fsinA + fTemp*fcosA-vPosition.x*fsinA;
            vMove.z = vPosition.z;
            vMove = Deformbend[i].x*(vMove-vPosition);
            wPosition += mul(BendMatrix[i],vMove);
         }
         //wPosition=dPosition+ wPosition;
         //gl_Position = u_Projection * u_View *wPosition;
    }
    //////////////////////////////////
    //////////vertex shader///////////
    //////////////////////////////////
    PixelInputType VSMain(VertexInputType input)
    {
         PixelInputType output;
         float4 wVertex ; 
         wVertex = mul(u_Model, float4(input.Position,1.0));
    //deform bend vertex segment
         BendDeform(wVertex);
    //texCoord segment2
         output.NTexcoord = input.Texcoord.xy;
     
    //texCoord segment3
         output.NTexcoord.x = output.NTexcoord.x*NTexRange.x + NTexRange.y;
         output.NTexcoord.y = output.NTexcoord.y*NTexRange.z + NTexRange.w;
     
         output.Position = mul(u_View , wVertex);
         output.Position = mul(u_Projection, output.Position);
         return output;
    }    
    

       if I choose shader model as Shader Model 4 Level 9_3(/4_0_level_9_3), it will generate 2 errors:

    1.vs_deform_noAnimNormal_sub.hlsl(36,10-25): error X4019: multiple variables found with the same user-specified location
    2.vs_deform_noAnimNormal_sub.hlsl(37,11-18): error X4019: multiple variables found with the same user-specified location

    why it is happen?  if I delete (float u_MotionBlurStre)  and (float2 padding1 ) variable, it can compile success. 

    or if  for(int  i  = 0; i<lDBNum; i++) change to   for(int  i  = 0; i<lDBNum+0; i++) ,  it can compile success too.

    I don't know why this shader compile failed and how to fix the shader right ?

    Wednesday, September 19, 2012 8:24 AM

All replies

  • Hi zjubaoli
    Are you sure, you set correct entry point for your shader? I change the entry point from "VSMain" to "main" and it was compiled successfully.



    Best Regards. Pooya Eimandar.

    Friday, December 14, 2012 5:42 PM