移除线框包围盒渲染代码
This commit is contained in:
56
main.cpp
56
main.cpp
@@ -93,25 +93,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
bboxCenter[0], bboxCenter[1], bboxCenter[2],
|
||||
bboxSize[0], bboxSize[1], bboxSize[2]);
|
||||
|
||||
float cubeVertices[] = {
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
};
|
||||
uint32_t cubeIndices[] = {
|
||||
0, 1, 1, 2, 2, 3, 3, 0,
|
||||
4, 5, 5, 6, 6, 7, 7, 4,
|
||||
0, 4, 1, 5, 2, 6, 3, 7
|
||||
};
|
||||
ID3D12Resource* cubeVBO = CreateBufferObject(commandList, cubeVertices, sizeof(cubeVertices), D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);
|
||||
ID3D12Resource* cubeIBO = CreateBufferObject(commandList, cubeIndices, sizeof(cubeIndices), D3D12_RESOURCE_STATE_INDEX_BUFFER);
|
||||
printf("Cube mesh created\n");
|
||||
|
||||
float quadVertices[] = {
|
||||
-1.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
@@ -154,23 +135,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
printf("Quad PSO created: %p\n", quadPSO);
|
||||
}
|
||||
|
||||
D3D12_SHADER_BYTECODE wireframeVS, wireframePS;
|
||||
memset(&wireframeVS, 0, sizeof(wireframeVS));
|
||||
memset(&wireframePS, 0, sizeof(wireframePS));
|
||||
CreateShaderFromFile(L"Res/Shader/wireframe.hlsl", "MainVS", "vs_5_1", &wireframeVS);
|
||||
CreateShaderFromFile(L"Res/Shader/wireframe.hlsl", "MainPS", "ps_5_1", &wireframePS);
|
||||
printf("Wireframe VS: ptr=%p, size=%zu\n", wireframeVS.pShaderBytecode, wireframeVS.BytecodeLength);
|
||||
printf("Wireframe PS: ptr=%p, size=%zu\n", wireframePS.pShaderBytecode, wireframePS.BytecodeLength);
|
||||
|
||||
ID3D12PipelineState* volumePSO = CreateVolumePSO(volumeRootSignature, wireframeVS, wireframePS);
|
||||
if (!volumePSO) {
|
||||
printf("Volume PSO creation failed!\n");
|
||||
} else {
|
||||
printf("Volume PSO created: %p\n", volumePSO);
|
||||
}
|
||||
|
||||
ID3D12Resource* volumeCB = CreateConstantBufferObject(65536);
|
||||
ID3D12Resource* wireframeCB = CreateConstantBufferObject(65536);
|
||||
|
||||
ID3D12Resource* cb = CreateConstantBufferObject(65536);//1024x64(4x4)
|
||||
DirectX::XMMATRIX projectionMatrix=DirectX::XMMatrixPerspectiveFovLH(
|
||||
@@ -330,27 +295,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
commandList->DrawIndexedInstanced(6, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
DirectX::XMMATRIX bboxScale = DirectX::XMMatrixScaling(bboxSize[0], bboxSize[1], bboxSize[2]);
|
||||
DirectX::XMMATRIX bboxTranslate = DirectX::XMMatrixTranslation(bboxCenter[0], bboxCenter[1], bboxCenter[2]);
|
||||
DirectX::XMMATRIX bboxModel = bboxScale * bboxTranslate;
|
||||
DirectX::XMMATRIX bboxViewProj = bboxModel * viewMatrix * projectionMatrix;
|
||||
DirectX::XMFLOAT4X4 bboxViewProjMat;
|
||||
DirectX::XMStoreFloat4x4(&bboxViewProjMat, bboxViewProj);
|
||||
|
||||
float wireframeCBData[16];
|
||||
memcpy(wireframeCBData, &bboxViewProjMat, sizeof(float) * 16);
|
||||
UpdateConstantBuffer(wireframeCB, wireframeCBData, sizeof(float) * 16);
|
||||
|
||||
if (volumePSO) {
|
||||
commandList->SetPipelineState(volumePSO);
|
||||
commandList->SetGraphicsRootSignature(volumeRootSignature);
|
||||
commandList->SetGraphicsRootConstantBufferView(0, wireframeCB->GetGPUVirtualAddress());
|
||||
commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST);
|
||||
commandList->IASetVertexBuffers(0, 1, &D3D12_VERTEX_BUFFER_VIEW{ cubeVBO->GetGPUVirtualAddress(), 8 * 3 * sizeof(float), sizeof(float) * 3 });
|
||||
commandList->IASetIndexBuffer(&D3D12_INDEX_BUFFER_VIEW{ cubeIBO->GetGPUVirtualAddress(), 24 * sizeof(uint32_t), DXGI_FORMAT_R32_UINT });
|
||||
commandList->DrawIndexedInstanced(24, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
EndRenderToSwapChain(commandList);
|
||||
EndCommandList();
|
||||
SwapD3D12Buffers();
|
||||
|
||||
Reference in New Issue
Block a user