Stabilize visible render item sorting
This commit is contained in:
@@ -27,6 +27,10 @@ void AppendRenderItemsForGameObject(
|
||||
const Math::Vector3& cameraPosition,
|
||||
std::vector<VisibleRenderItem>& outVisibleItems);
|
||||
|
||||
bool CompareVisibleRenderItemsStable(
|
||||
const VisibleRenderItem& lhs,
|
||||
const VisibleRenderItem& rhs);
|
||||
|
||||
std::vector<VisibleRenderItem> CollectRenderItemsForEntityIds(
|
||||
const Components::Scene& scene,
|
||||
const std::vector<uint64_t>& entityIds,
|
||||
|
||||
@@ -113,22 +113,7 @@ uint32_t GetAdditionalLightTypeRank(const Components::LightComponent& light) {
|
||||
}
|
||||
|
||||
bool CompareVisibleItems(const VisibleRenderItem& lhs, const VisibleRenderItem& rhs) {
|
||||
if (lhs.renderQueue != rhs.renderQueue) {
|
||||
return lhs.renderQueue < rhs.renderQueue;
|
||||
}
|
||||
|
||||
const bool isTransparentQueue = IsTransparentRenderQueue(lhs.renderQueue);
|
||||
if (lhs.cameraDistanceSq != rhs.cameraDistanceSq) {
|
||||
return isTransparentQueue
|
||||
? lhs.cameraDistanceSq > rhs.cameraDistanceSq
|
||||
: lhs.cameraDistanceSq < rhs.cameraDistanceSq;
|
||||
}
|
||||
|
||||
if (lhs.gameObject != rhs.gameObject) {
|
||||
return lhs.gameObject < rhs.gameObject;
|
||||
}
|
||||
|
||||
return lhs.sectionIndex < rhs.sectionIndex;
|
||||
return CompareVisibleRenderItemsStable(lhs, rhs);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -116,6 +116,41 @@ void AppendRenderItemsForGameObject(
|
||||
outVisibleItems.push_back(visibleItem);
|
||||
}
|
||||
|
||||
bool CompareVisibleRenderItemsStable(
|
||||
const VisibleRenderItem& lhs,
|
||||
const VisibleRenderItem& rhs) {
|
||||
if (lhs.renderQueue != rhs.renderQueue) {
|
||||
return lhs.renderQueue < rhs.renderQueue;
|
||||
}
|
||||
|
||||
const bool isTransparentQueue = IsTransparentRenderQueue(lhs.renderQueue);
|
||||
if (lhs.cameraDistanceSq != rhs.cameraDistanceSq) {
|
||||
return isTransparentQueue
|
||||
? lhs.cameraDistanceSq > rhs.cameraDistanceSq
|
||||
: lhs.cameraDistanceSq < rhs.cameraDistanceSq;
|
||||
}
|
||||
|
||||
const Core::uint64 lhsObjectId = lhs.gameObject != nullptr ? lhs.gameObject->GetID() : 0u;
|
||||
const Core::uint64 rhsObjectId = rhs.gameObject != nullptr ? rhs.gameObject->GetID() : 0u;
|
||||
if (lhsObjectId != rhsObjectId) {
|
||||
return lhsObjectId < rhsObjectId;
|
||||
}
|
||||
|
||||
if (lhs.hasSection != rhs.hasSection) {
|
||||
return lhs.hasSection && !rhs.hasSection;
|
||||
}
|
||||
|
||||
if (lhs.sectionIndex != rhs.sectionIndex) {
|
||||
return lhs.sectionIndex < rhs.sectionIndex;
|
||||
}
|
||||
|
||||
if (lhs.materialIndex != rhs.materialIndex) {
|
||||
return lhs.materialIndex < rhs.materialIndex;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<VisibleRenderItem> CollectRenderItemsForEntityIds(
|
||||
const Components::Scene& scene,
|
||||
const std::vector<uint64_t>& entityIds,
|
||||
|
||||
Reference in New Issue
Block a user