Search code examples
c++directxdirectx-11hlsl

Error when adding NORMAL to the inputLayout


I'm trying to add the NORMAL vector into the inputLayout but when I add this line, I have this error :

D3D11 ERROR: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'NORMAL'/0, but the declaration doesn't provide a matching name. [ STATE_CREATION ERROR #163: CREATEINPUTLAYOUT_MISSINGELEMENT]

Here is where I set up the InputLayout :

 {"POSITION",0,DXGI_FORMAT::DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_CLASSIFICATION::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, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},

And here is the VertexShader :

struct VSinput
{
float3 pos : POSITION;
float2 textCoord : TEXCOORD0;
float3 test : NORMAL0;
};

struct PSinput
{
float4 position : SV_Position;
float2 textCoord : TEXCOORD0;
float3 test : NORMAL0;
 };

 PSinput vs_main(VSinput input)
 {
  PSinput output = (PSinput) 0;

 // input.pos.y += Yoffset;
  output.position = mul(float4(input.pos, 1.0),mat);

  output.textCoord = input.textCoord;



  return output;


}

as you can see there is an input with the NORMAL SemanticName and the Index 0


Solution

  • You cannot change the layout order in Direct3D 10 or later due to shader linkage rules.

    Either make your shader use:

    struct VSinput
    {
    float3 pos : POSITION;
    float3 test : NORMAL0;
    float2 textCoord : TEXCOORD0;
    };
    

    -or- make your input layout use:

    {"POSITION",0,DXGI_FORMAT::DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0},
    {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"NORMAL",0, DXGI_FORMAT_R32G32B32_FLOAT,0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},