質問

Okay first up I am using:

  • DirectX 10
  • C++

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.

In the DirectX vertex declaration I am passing a 3 component float (Pos x,y,z) and 2 component float (Texcoord x,y). Texcoord z is reserved for texture2d arrays, which I'm currently defaulting to 0 in the the pixel shader.

I wrote this to achieve the simple task:

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

IA Layout: (Update)

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

Data reaches the vertex shader in the following format: (Update)

struct VS_INPUT
{ 
    float3 fPos          :POSITION;
    float3 fTexcoord     :TEXCOORD0;
}

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 only 1 pixel of the sampled texture.

The workaround was in the pixel shader to do the following: (Update)

sampler s0                      : register(s0);
Texture2DArray<float4> 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;
}

It was also worth noting that this worked with the following VS out struct defined in the shaders:

struct VS_OUTPUT
{
    float4 fPos          :POSITION0; // SV_POSITION wont work in this case
    float3 fTexcoord    :TEXCOORD0;
}

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?

To clarify I am using a point sampler and have tried both clamp and wrapping UV.

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?

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top