Renders all meshes using depth-only rendering
| 689 | |
| 690 | // Renders all meshes using depth-only rendering |
| 691 | void MeshRenderer::RenderDepth(ID3D11DeviceContext* context, const Camera& camera, bool noZClip, bool flippedZRange) |
| 692 | { |
| 693 | PIXEvent event(L"Mesh Depth Rendering"); |
| 694 | |
| 695 | // Set states |
| 696 | float blendFactor[4] = {1, 1, 1, 1}; |
| 697 | context->OMSetBlendState(blendStates.ColorWriteDisabled(), blendFactor, 0xFFFFFFFF); |
| 698 | context->OMSetDepthStencilState(flippedZRange ? depthStencilStates.ReverseDepthWriteEnabled() |
| 699 | : depthStencilStates.DepthWriteEnabled(), 0); |
| 700 | |
| 701 | if(noZClip) |
| 702 | context->RSSetState(noZClipRSState); |
| 703 | else |
| 704 | context->RSSetState(rasterizerStates.BackFaceCull()); |
| 705 | |
| 706 | // Set constant buffers |
| 707 | meshVSConstants.Data.World = Float4x4(); |
| 708 | meshVSConstants.Data.View = Float4x4::Transpose(camera.ViewMatrix()); |
| 709 | meshVSConstants.Data.WorldViewProjection = Float4x4::Transpose(camera.ViewProjectionMatrix()); |
| 710 | meshVSConstants.ApplyChanges(context); |
| 711 | meshVSConstants.SetVS(context, 0); |
| 712 | |
| 713 | // Set shaders |
| 714 | context->VSSetShader(meshDepthVS , nullptr, 0); |
| 715 | context->PSSetShader(nullptr, nullptr, 0); |
| 716 | context->GSSetShader(nullptr, nullptr, 0); |
| 717 | context->DSSetShader(nullptr, nullptr, 0); |
| 718 | context->HSSetShader(nullptr, nullptr, 0); |
| 719 | |
| 720 | for(uint32 meshIdx = 0; meshIdx < sceneModel->Meshes().size(); ++meshIdx) |
| 721 | { |
| 722 | const Mesh& mesh = sceneModel->Meshes()[meshIdx]; |
| 723 | |
| 724 | // Set the vertices and indices |
| 725 | ID3D11Buffer* vertexBuffers[1] = { mesh.VertexBuffer() }; |
| 726 | UINT vertexStrides[1] = { mesh.VertexStride() }; |
| 727 | UINT offsets[1] = { 0 }; |
| 728 | context->IASetVertexBuffers(0, 1, vertexBuffers, vertexStrides, offsets); |
| 729 | context->IASetIndexBuffer(mesh.IndexBuffer(), mesh.IndexBufferFormat(), 0); |
| 730 | context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
| 731 | |
| 732 | // Set the input layout |
| 733 | context->IASetInputLayout(meshDepthInputLayouts[meshIdx]); |
| 734 | |
| 735 | // Draw all parts |
| 736 | for(uint64 partIdx = 0; partIdx < mesh.MeshParts().size(); ++partIdx) |
| 737 | { |
| 738 | const MeshPart& part = mesh.MeshParts()[partIdx]; |
| 739 | context->DrawIndexed(part.IndexCount, part.IndexStart, 0); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | // Renders meshes using cascaded shadow mapping |
| 745 | void MeshRenderer::RenderSunShadowMap(ID3D11DeviceContext* context, const Camera& camera) |
no test coverage detected