1

DirectX 11のレンダリングに問題があります。複数のモデルをレンダリングしようとすると、インデックスが奇数のモデルだけが表示されます。偶数のインデックスでレンダリングされたすべてのモデルは表示されません。

ラスタテックチュートリアルに基づく私のコード:

m_dx->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
{
    m_camera->Render();

    XMMATRIX view;
    m_camera->GetViewMatrix(view);

    XMMATRIX world;
    m_dx->GetWorldMatrix(world);

    XMMATRIX projection;
    m_dx->GetProjectionMatrix(projection);

    XMMATRIX ortho;
    m_dx->GetOrthoMatrix(ortho);

    world = XMMatrixTranslation(-2, 0, -4);
    m_model->Render(m_dx->GetDeviceContext());
    m_texture_shader->Render(m_dx->GetDeviceContext(), m_model->GetIndicesCount(), world, view, projection,
        m_model->GetTexture());

    world = XMMatrixTranslation(2, 0, -2);
    m_model->Render(m_dx->GetDeviceContext());
    m_texture_shader->Render(m_dx->GetDeviceContext(), m_model->GetIndicesCount(), world, view, projection,
        m_model->GetTexture());

    world = XMMatrixTranslation(0, 0, -3);
    m_model->Render(m_dx->GetDeviceContext());
    m_texture_shader->Render(m_dx->GetDeviceContext(), m_model->GetIndicesCount(), world, view, projection,
        m_model->GetTexture());

}
m_dx->EndScene();

モデルのレンダリング方法

UINT stride, offset;

stride = sizeof(VertexPosTextureNormal);
offset = 0;

device_context->IASetVertexBuffers(0, 1, &m_vertex_buffer, &stride, &offset);
device_context->IASetIndexBuffer(m_index_buffer, DXGI_FORMAT_R32_UINT, 0);
device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

シェーダーレンダリングメソッド:

world = XMMatrixTranspose(world);
view = XMMatrixTranspose(view);
projection = XMMatrixTranspose(projection);

D3D11_MAPPED_SUBRESOURCE mapped_subres;
RETURN_FALSE_IF_FAILED(context->Map(m_matrix_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_subres));
MatrixBuffer* data = (MatrixBuffer*)mapped_subres.pData;
data->world = world;
data->view = view;
data->projection = projection;
context->Unmap(m_matrix_buffer, 0);
context->VSSetConstantBuffers(0, 1, &m_matrix_buffer);
context->PSSetShaderResources(0, 1, &texture);

    // render
    context->IASetInputLayout(m_layout);

context->VSSetShader(m_vertex_shader, NULL, 0);
context->PSSetShader(m_pixel_shader, NULL, 0);
context->PSSetSamplers(0, 1, &m_sampler_state);
context->DrawIndexed(indices, 0, 0);

これの理由は何でしょうか?

ありがとうございました。

4

1 に答える 1

0

このコード-

world = XMMatrixTranspose(world);
view = XMMatrixTranspose(view);
projection = XMMatrixTranspose(projection); 

は、呼び出すたびに同じ行列を転置するため、正しい値が交互に表示されるだけです。ワールドマトリックスは呼び出し元のコードで毎回リセットされていますが、ビューとプロジェクトのマトリックスは交互に間違っています。

于 2012-11-06T09:23:47.770 に答える