title: Adding normal information for the shader in DirectX 11 - normals not visible in shader?
body: <p>I wanted to add a normal map information for my shader. I was using tutorial 5 from DirectX 11 C++ SDK as a base.</p>
  
  <p>The code for shader creating is (I'm putting it just to be sure I have posted every important information, but I think that only the D3D11_INPUT_ELEMENT_DESC layout[] matters):</p>
  
  <pre><code>// Compile the vertex shader
  ID3DBlob* pVSBlob = NULL;
  HRESULT hr = CompileShaderFromFile( strToWchart(vertexShaderFileName), "VS", "vs_4_0", &amp;pVSBlob );
  
  // Create the vertex shader
  hr = device-&gt;CreateVertexShader( pVSBlob-&gt;GetBufferPointer(), pVSBlob-&gt;GetBufferSize(), NULL, &amp;vertexShader );
  if( FAILED( hr ) )
  {   
  pVSBlob-&gt;Release();
  }
  
  
  // Define the input layout
  D3D11_INPUT_ELEMENT_DESC layout[] =
  {
      { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
      { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
      { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 12, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
  };
  
  UINT numElements = ARRAYSIZE( layout );
  
  // Create the input layout
  hr = device-&gt;CreateInputLayout( layout, numElements, pVSBlob-&gt;GetBufferPointer(),
                                        pVSBlob-&gt;GetBufferSize(), &amp;*vertexLayout );
  pVSBlob-&gt;Release();
  
      // Set the input layout
  context-&gt;IASetInputLayout( *vertexLayout );
  
  // Compile the pixel shader
  ID3DBlob* pPSBlob = NULL;
  hr = CompileShaderFromFile( strToWchart(pixelShaderFileName), "PS", "ps_4_0", &amp;pPSBlob );
  
  // Create the pixel shader
  hr = device-&gt;CreatePixelShader( pPSBlob-&gt;GetBufferPointer(), pPSBlob-&gt;GetBufferSize(), NULL, &amp;pixelShader );
  pPSBlob-&gt;Release();
  
  }
  </code></pre>
  
  <p>So simply I have changed  D3D11_INPUT_ELEMENT_DESC layout[] to (adding "NORMAL" row): </p>
  
  <pre><code>D3D11_INPUT_ELEMENT_DESC layout[] =
  {
      { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
      { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
      { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 12, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
  };
  </code></pre>
  
  <p>Than I have changed few lines in the box creating method:</p>
  
  <pre><code>// Create vertex buffer
  SimpleVertex vertices[] =
  {
      { XMFLOAT3(  - halfSize.getX(),  + halfSize.getY(),  - halfSize.getZ() ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) },
      { XMFLOAT3(  + halfSize.getX(),  + halfSize.getY(),  - halfSize.getZ() ), XMFLOAT4( 0.0f, 1.0f, 0.0f, 1.0f ), XMFLOAT4( 0.0f, 1.0f, 1.0f, 1.0f ) },
      { XMFLOAT3(  + halfSize.getX(),  + halfSize.getY(),  + halfSize.getZ() ), XMFLOAT4( 0.0f, 1.0f, 1.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) },
      { XMFLOAT3(  - halfSize.getX(),  + halfSize.getY(),  + halfSize.getZ() ), XMFLOAT4( 1.0f, 0.0f, 0.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) },
      { XMFLOAT3(  - halfSize.getX(),  - halfSize.getY(),  - halfSize.getZ() ), XMFLOAT4( 1.0f, 0.0f, 1.0f, 1.0f ), XMFLOAT4( 0.0f, 1.0f, 1.0f, 1.0f ) },
      { XMFLOAT3(  + halfSize.getX(),  - halfSize.getY(),  - halfSize.getZ() ), XMFLOAT4( 1.0f, 1.0f, 0.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) },
      { XMFLOAT3(  + halfSize.getX(),  - halfSize.getY(),  + halfSize.getZ() ), XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ), XMFLOAT4( 1.0f, 0.0f, 1.0f, 0.0f ) },
      { XMFLOAT3(  - halfSize.getX(),  - halfSize.getY(),  + halfSize.getZ() ), XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f ), XMFLOAT4( 0.0f, 0.0f, 1.0f, 1.0f ) },
  };
  </code></pre>
  
  <p>So the last XMFLOAT4 in all rows are normal (not important that these are wrong normals, now I just want to make it visible in vertex shader).</p>
  
  <p>I have also changed SimpleVertex:</p>
  
  <pre><code>struct SimpleVertex
  {
      XMFLOAT3 Pos;
      XMFLOAT4 Color;
      XMFLOAT4 Normal;
  };
  </code></pre>
  
  <p>And my shader to check if the normals exists:</p>
  
  <pre><code>cbuffer ConstantBuffer : register( b0 )
  {
  matrix World;
  matrix View;
  matrix Projection;
  }
  
  struct VS_INPUT
  {
      float4 Pos : POSITION;
      float4 Color : COLOR;
  float4 Normal : NORMAL; 
  };
  
  struct PS_INPUT
  {
      float4 Pos : SV_POSITION;
      float4 Color : COLOR;
  };
  
  PS_INPUT VS( VS_INPUT input )
  {
      PS_INPUT output = (PS_INPUT)0;
  
  
  
      output.Pos = mul( input.Pos, World );
      output.Pos = mul( output.Pos, View );
      output.Pos = mul( output.Pos, Projection );
  output.Color = input.Normal; //just to know if I have a normals
      return output;
  }
  
  float4 PS( PS_INPUT input) : SV_Target
  {
      return input.Color;
  }
  </code></pre>
  
  <p>But the effect was just a black box (even with output.Color = input.Normal).</p>
  
  <p><strong>So, what's the problem?</strong> I have to change something else to get normals info in the shader?</p>