Direct3D11顶点着色器中的顶点变换错误

时间:2016-11-28 01:36:31

标签: c++ graphics directx direct3d direct3d11

我试图运行D3D 11渲染系统来加载和渲染FBX文件但我在顶点着色器中转换顶点时遇到了问题。

我不认为有什么问题,在Visual Studio图形调试器中我可以看到传递给管道的网格在输入汇编程序阶段是正常的但是在顶点着色器转换之后所有突发并且渲染出错,如果有人可以告诉我出了什么问题我会很感激信息。

View of the Input Assembler Stage

View of the Vertex Shader Output

这是顶点着色器代码

cbuffer MatrixBuffer
{
    matrix worldMatrix;
    matrix viewMatrix;
    matrix projectionMatrix;
};

struct VertexInputType
{
    float4 position : POSITION;
    float3 normal : NORMAL;
    float2 uv : TEXCOORD;
};

struct PixelInputType
{
    float4 position : SV_POSITION;
    float3 normal : NORMAL;
    float2 uv : TEXCOORD;
};

PixelInputType TextureVertexShader(VertexInputType input)
{
    PixelInputType output;

    output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    output.normal = input.normal;
    output.uv = input.uv;

    return output;
}

这是矩阵初始化的代码

float lFieldOfView = 3.141592f * 0.4f;
float lScreenAspect = static_cast<float>(width_) / static_cast<float>(height_);

DirectX::XMMATRIX lProjection = MatrixDirectX::XMMatrixPerspectiveFovLHlFieldOfView, lScreenAspect, 1.0f, 10000.0f);
DirectX::XMStoreFloat4x4(&lMatrixBuffer.projectionMatrix, lProjectionMatrix);

DirectX::XMMATRIX lWorldMatrix = DirectX::XMMatrixIdentity();
DirectX::XMStoreFloat4x4(&lMatrixBuffer.worldMatrix, lWorldMatrix);

DirectX::XMFLOAT3 lookAtPos(0.0f, 0.0f, 0.0f);
DirectX::XMFLOAT3 eyePos(0.0f, 0.0f, -50.0f);
DirectX::XMFLOAT3 upDir(0.0f, 1.0f, 0.0f);
DirectX::FXMVECTOR lLookAtPos = DirectX::XMLoadFloat3(&lookAtPos);
DirectX::FXMVECTOR lEyePos    = DirectX::XMLoadFloat3(&eyePos);
DirectX::FXMVECTOR lUpDir     = DirectX::XMLoadFloat3(&upDir);

DirectX::XMMATRIX lViewMatrix = DirectX::XMMatrixLookAtLH(lEyePos, lLookAtPos, lUpDir);
DirectX::XMStoreFloat4x4(&lMatrixBuffer.viewMatrix, lViewMatrix);

D3D11_BUFFER_DESC lBufferDesc = { 0 };
lBufferDesc.ByteWidth      = sizeof(MatrixBufferType);
lBufferDesc.Usage          = D3D11_USAGE_DYNAMIC;
lBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
lBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;

D3D11_SUBRESOURCE_DATA lMatrixBufferData;
lMatrixBufferData.pSysMem = &lMatrixBuffer;

hResult = D3DDevice_->CreateBuffer(&lBufferDesc, &lMatrixBufferData, &D3DMatrixBuffer_);

1 个答案:

答案 0 :(得分:0)

从评论看来,问题实际上可能是矩阵行 - 主要/列 - 主要差异。如果矩阵将转换到CPU端,原始的HLSL代码可能会起作用。