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
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
pub mod node;
|
pub mod node;
|
||||||
|
|
||||||
|
use std::cmp::Reverse;
|
||||||
|
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::Reflect;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
@ -75,15 +77,17 @@ pub struct Opaque3dPrepass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PhaseItem for 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 {
|
fn entity(&self) -> Entity {
|
||||||
self.entity
|
self.entity
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sort_key(&self) -> Self::SortKey {
|
fn sort_key(&self) -> Self::SortKey {
|
||||||
FloatOrd(self.distance)
|
Reverse(FloatOrd(self.distance))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -93,7 +97,8 @@ impl PhaseItem for Opaque3dPrepass {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sort(items: &mut [Self]) {
|
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 {
|
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 {
|
fn entity(&self) -> Entity {
|
||||||
self.entity
|
self.entity
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sort_key(&self) -> Self::SortKey {
|
fn sort_key(&self) -> Self::SortKey {
|
||||||
FloatOrd(self.distance)
|
Reverse(FloatOrd(self.distance))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -135,7 +142,8 @@ impl PhaseItem for AlphaMask3dPrepass {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sort(items: &mut [Self]) {
|
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 New Issue
Block a user