Renders all meshes to the G-Buffer
| 562 | |
| 563 | // Renders all meshes to the G-Buffer |
| 564 | void MeshRenderer::RenderGBuffer(ID3D12GraphicsCommandList* cmdList, const Camera& camera) |
| 565 | { |
| 566 | PIXMarker marker(cmdList, L"Render G-Buffer"); |
| 567 | CPUProfileBlock cpuProfileBlock("Render G-Buffer"); |
| 568 | |
| 569 | uint64 numVisible = 0; |
| 570 | if(AppSettings::SortByDepth) |
| 571 | numVisible = CullMeshesAndSort(camera, meshBoundingBoxes, meshZDepths, meshDrawIndices); |
| 572 | else |
| 573 | numVisible = CullMeshes(camera, meshBoundingBoxes, meshDrawIndices); |
| 574 | |
| 575 | cmdList->SetGraphicsRootSignature(gBufferRootSignature); |
| 576 | cmdList->SetPipelineState(gBufferPSO); |
| 577 | cmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
| 578 | |
| 579 | Float4x4 world; |
| 580 | |
| 581 | // Set constant buffers |
| 582 | meshVSConstants.Data.World = world; |
| 583 | meshVSConstants.Data.View = camera.ViewMatrix(); |
| 584 | meshVSConstants.Data.WorldViewProjection = world * camera.ViewProjectionMatrix(); |
| 585 | meshVSConstants.Data.NearClip = camera.NearClip(); |
| 586 | meshVSConstants.Data.FarClip = camera.FarClip(); |
| 587 | meshVSConstants.Upload(); |
| 588 | meshVSConstants.SetAsGfxRootParameter(cmdList, 0); |
| 589 | |
| 590 | // Bind vertices and indices |
| 591 | D3D12_VERTEX_BUFFER_VIEW vbView = model->VertexBuffer().VBView(); |
| 592 | D3D12_INDEX_BUFFER_VIEW ibView = model->IndexBuffer().IBView(); |
| 593 | cmdList->IASetVertexBuffers(0, 1, &vbView); |
| 594 | cmdList->IASetIndexBuffer(&ibView); |
| 595 | |
| 596 | // Draw all visible meshes |
| 597 | uint32 currMaterial = uint32(-1); |
| 598 | for(uint64 i = 0; i < numVisible; ++i) |
| 599 | { |
| 600 | uint64 meshIdx = meshDrawIndices[i]; |
| 601 | const Mesh& mesh = model->Meshes()[meshIdx]; |
| 602 | |
| 603 | // Draw all parts |
| 604 | for(uint64 partIdx = 0; partIdx < mesh.NumMeshParts(); ++partIdx) |
| 605 | { |
| 606 | const MeshPart& part = mesh.MeshParts()[partIdx]; |
| 607 | if(part.MaterialIdx != currMaterial) |
| 608 | { |
| 609 | cmdList->SetGraphicsRoot32BitConstant(1, part.MaterialIdx, 0); |
| 610 | currMaterial = part.MaterialIdx; |
| 611 | } |
| 612 | cmdList->DrawIndexedInstanced(part.IndexCount, 1, mesh.IndexOffset() + part.IndexStart, mesh.VertexOffset(), 0); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | // Renders all meshes using depth-only rendering |
| 618 | void MeshRenderer::RenderDepth(ID3D12GraphicsCommandList* cmdList, const Camera& camera, ID3D12PipelineState* pso, uint64 numVisible) |
no test coverage detected