title: DirectX Clip space texture coordinates
body: <p>Okay first up I am using: </p>
  
  <ul>
  <li>DirectX 10</li>
  <li>C++</li>
  </ul>
  
  <p>Okay this is a bit of a bizarre one to me, I wouldn't usually ask the question, but I've been forced by circumstance. I have two triangles (not a quad for reasons I wont go into!) full screen, aligned to screen through the fact they are not transformed.</p>
  
  <p>In the DirectX vertex declaration I am passing a 3 component float (Pos x,y,z) and 2 component float (Texcoord x,y). <strong>Texcoord z is reserved for texture2d arrays, which I'm currently defaulting to 0 in the the pixel shader.</strong></p>
  
  <p>I wrote this to achieve the simple task:</p>
  
  <pre><code>float fStartX = -1.0f;
  float fEndX = 1.0f;
  float fStartY = 1.0f;
  float fEndY = -1.0f;
  float fStartU = 0.0f;
  float fEndU = 1.0f;
  float fStartV = 0.0f;
  float fEndV = 1.0f;
  vmvUIVerts.push_back(CreateVertex(fStartX, fStartY, 0, fStartU, fStartV));
  vmvUIVerts.push_back(CreateVertex(fEndX, fStartY, 0, fEndU, fStartV));
  vmvUIVerts.push_back(CreateVertex(fEndX, fEndY, 0, fEndU, fEndV));
  vmvUIVerts.push_back(CreateVertex(fStartX, fStartY, 0, fStartU, fStartV));
  vmvUIVerts.push_back(CreateVertex(fEndX, fEndY, 0, fEndU, fEndV));
  vmvUIVerts.push_back(CreateVertex(fStartX, fEndY, 0, fStartU, fEndV));
  </code></pre>
  
  <p><strong>IA Layout: (Update)</strong></p>
  
  <pre><code>D3D10_INPUT_ELEMENT_DESC ieDesc[2] = {
      { "POSITION",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
      { "TEXCOORD",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0,12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
  };
  </code></pre>
  
  <p><strong>Data reaches the vertex shader in the following format: (Update)</strong></p>
  
  <pre><code>struct VS_INPUT
  { 
      float3 fPos          :POSITION;
      float3 fTexcoord     :TEXCOORD0;
  }
  </code></pre>
  
  <p>Within my Vertex and Pixel shader not a lot is happening for this particular draw call, the pixel shader does most of the work sampling from a texture using the specified UV coordinates. However, this isn't working quite as expected, it appears that I am getting <strong>only 1 pixel</strong> of the sampled texture.</p>
  
  <p><strong>The workaround was in the pixel shader to do the following: (Update)</strong></p>
  
  <pre><code>sampler s0                      : register(s0);
  Texture2DArray&lt;float4&gt; meshTex  : register(t0);
  float4 psMain(in VS_OUTPUT vOut) : SV_TARGET
  {
      float4 Color;
      vOut.fTexcoord.z = 0;
      vOut.fTexcoord.x = vOut.fPosObj.x * 0.5f;
      vOut.fTexcoord.y = vOut.fPosObj.y * 0.5f;
      vOut.fTexcoord.x += 0.5f;
      vOut.fTexcoord.y += 0.5f;
      Color = quadTex.Sample(s0, vOut.fTexcoord);
      Color.a = 1.0f;
      return Color;
  }
  </code></pre>
  
  <p>It was also worth noting that this worked with the following VS out struct defined in the shaders:</p>
  
  <pre><code>struct VS_OUTPUT
  {
      float4 fPos          :POSITION0; // SV_POSITION wont work in this case
      float3 fTexcoord    :TEXCOORD0;
  }
  </code></pre>
  
  <p>Now I have a texture that's stretched to fit the entire screen, both triangles already cover this, but why did the texture UV's not get used as expected?</p>
  
  <p>To clarify I am using a point sampler and have tried both clamp and wrapping UV.</p>
  
  <p>I was a bit curious and found a solution / workaround mentioned above, however I'd prefer not to have to do it if anyone knows why it's happening?</p>