mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
bevy_core_pipeline: Fix prepass sort orders (#7539)
# Objective - Prepass opaque and alpha mask are incorrectly sorted back to front. This slipped through review by accident. ## Solution - Sort prepass opaque and alpha mask front to back
This commit is contained in:
parent
f3a23fd569
commit
6d399bfaf8
1 changed files with 14 additions and 6 deletions
|
@ -26,6 +26,8 @@
|
|||
|
||||
pub mod node;
|
||||
|
||||
use std::cmp::Reverse;
|
||||
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_reflect::Reflect;
|
||||
use bevy_render::{
|
||||
|
@ -75,15 +77,17 @@ pub struct Opaque3dPrepass {
|
|||
}
|
||||
|
||||
impl PhaseItem for Opaque3dPrepass {
|
||||
type SortKey = FloatOrd;
|
||||
// NOTE: Values increase towards the camera. Front-to-back ordering for opaque means we need a descending sort.
|
||||
type SortKey = Reverse<FloatOrd>;
|
||||
|
||||
#[inline]
|
||||
fn entity(&self) -> Entity {
|
||||
self.entity
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sort_key(&self) -> Self::SortKey {
|
||||
FloatOrd(self.distance)
|
||||
Reverse(FloatOrd(self.distance))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -93,7 +97,8 @@ impl PhaseItem for Opaque3dPrepass {
|
|||
|
||||
#[inline]
|
||||
fn sort(items: &mut [Self]) {
|
||||
radsort::sort_by_key(items, |item| item.distance);
|
||||
// Key negated to match reversed SortKey ordering
|
||||
radsort::sort_by_key(items, |item| -item.distance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,15 +122,17 @@ pub struct AlphaMask3dPrepass {
|
|||
}
|
||||
|
||||
impl PhaseItem for AlphaMask3dPrepass {
|
||||
type SortKey = FloatOrd;
|
||||
// NOTE: Values increase towards the camera. Front-to-back ordering for alpha mask means we need a descending sort.
|
||||
type SortKey = Reverse<FloatOrd>;
|
||||
|
||||
#[inline]
|
||||
fn entity(&self) -> Entity {
|
||||
self.entity
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sort_key(&self) -> Self::SortKey {
|
||||
FloatOrd(self.distance)
|
||||
Reverse(FloatOrd(self.distance))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -135,7 +142,8 @@ impl PhaseItem for AlphaMask3dPrepass {
|
|||
|
||||
#[inline]
|
||||
fn sort(items: &mut [Self]) {
|
||||
radsort::sort_by_key(items, |item| item.distance);
|
||||
// Key negated to match reversed SortKey ordering
|
||||
radsort::sort_by_key(items, |item| -item.distance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue