c++ – Instancing with Directx11

c++ – Instancing with Directx11

[ad_1]

I am a complete newbie with Directx/3D programming. I need assistance with implementing {hardware} instancing on Directx 11. I am attempting to render a number of cubes on the display screen, to create some kind of Minecraft-esque voxel engine. The issue is, I do not know the place to begin to obtain this. That is how my “render body” operate seems:

void RenderFrame(void)
{
    D3DXMATRIX matView, matProjection;
    D3DXMATRIX matFinal;

    // create a view matrix
    D3DXMatrixLookAtLH(&matView,
    &D3DXVECTOR3(0.0f, 9.0f, 24.0f),   // the digicam place
    &D3DXVECTOR3(0.0f, 0.0f, 0.0f),    // the look-at place
    &D3DXVECTOR3(0.0f, 1.0f, 0.0f));   // the up course

    // create a projection matrix
    D3DXMatrixPerspectiveFovLH(&matProjection,
    (FLOAT)D3DXToRadian(45),                    // discipline of view
    (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // facet ratio
    1.0f,                                       // close to view-plane
    100.0f);                                    // far view-plane

    // create the ultimate remodel
    matFinal = matView * matProjection;

    devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

    devcon->ClearDepthStencilView(zbuffer, D3D11_CLEAR_DEPTH, 1.0f, 0);

    UINT stride = sizeof(VERTEX);
    UINT offset = 0;
    devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);
    devcon->IASetIndexBuffer(pIBuffer, DXGI_FORMAT_R32_UINT, 0);
    devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    devcon->UpdateSubresource(pCBuffer, 0, 0, &matFinal, 0, 0);
    devcon->DrawIndexed(24, 0, 0);

    swapchain->Current(0, 0);
}

Discover that there is a single vertex buffer containing the verteces of a dice, and index buffer containing its indeces. I wish to render many (5000+) cubes on the display screen directly on a single draw name, with out efficiency points, so I do know instancing is the best way to go, however I do not know learn how to implement it in my code. What modifications do I would like to do to my code with a purpose to show a number of cases of the dice?

Thanks upfront!

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply