Skip to content

Commit

Permalink
HnRenderPass: added draw list ordering by skinning transform
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 26, 2024
1 parent 285261e commit 934f289
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Hydrogent/src/HnRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,11 @@ void HnRenderPass::UpdateDrawListGPUResources(RenderState& State)

bool DrawOrderDirty = false;

entt::registry& Registry = State.RenderDelegate.GetEcsRegistry();
auto SkinningCmpView = Registry.view<const HnMesh::Components::Skinning>();

std::sort(m_RenderOrder.begin(), m_RenderOrder.end(),
[this, &DrawOrderDirty](Uint32 i0, Uint32 i1) {
[this, &DrawOrderDirty, &SkinningCmpView](Uint32 i0, Uint32 i1) {
const DrawListItem& Item0 = m_DrawList[i0];
const DrawListItem& Item1 = m_DrawList[i1];

Expand All @@ -990,7 +993,12 @@ void HnRenderPass::UpdateDrawListGPUResources(RenderState& State)
}
else
{
// Sort by PSO first, then by material SRB, then by material, and finally by entity ID
// Sorting order:
// 1. PSO
// 2. Material SRB
// 3. Material
// 4. Skinning Transform
// 5. Entity ID
if (Item0.pPSO < Item1.pPSO)
Item0PrecedesItem1 = true;
else if (Item0.pPSO > Item1.pPSO)
Expand All @@ -1004,7 +1012,14 @@ void HnRenderPass::UpdateDrawListGPUResources(RenderState& State)
else if (Item0.pMaterial > Item1.pMaterial)
Item0PrecedesItem1 = false;
else
Item0PrecedesItem1 = Item0.MeshEntity < Item1.MeshEntity;
{
size_t XformsHash0 = SkinningCmpView.get<const HnMesh::Components::Skinning>(Item0.MeshEntity).XformsHash;
size_t XformsHash1 = SkinningCmpView.get<const HnMesh::Components::Skinning>(Item1.MeshEntity).XformsHash;
if (XformsHash0 != XformsHash1)
Item0PrecedesItem1 = XformsHash0 < XformsHash1;
else
Item0PrecedesItem1 = Item0.MeshEntity < Item1.MeshEntity;
}
}

if ((i0 < i1) != Item0PrecedesItem1)
Expand Down

0 comments on commit 934f289

Please sign in to comment.