Skip to content

Commit 718688e

Browse files
authored
Use stack_z_offsets in all the cases we create a TransparentUi (#16197)
# Objective Use same pattern when creating `TransparentUi` items where the `sort_key` is the `UiNode` stack index + some offset. ## Solution Refactored to follow same pattern. ## Testing Ran few UI examples. ## Doubts Maybe `stack_z_offsets::BACKGROUND_COLOR` should be renamed. This is used for `ExtractedUiNode`, which is not only used for "background color" it's also used to render borders, images and text (I think).
1 parent 50dde9b commit 718688e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

crates/bevy_ui/src/render/box_shadow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use bevy_render::{
3232
use bevy_transform::prelude::GlobalTransform;
3333
use bytemuck::{Pod, Zeroable};
3434

35-
use super::{QUAD_INDICES, QUAD_VERTEX_POSITIONS};
35+
use super::{stack_z_offsets, QUAD_INDICES, QUAD_VERTEX_POSITIONS};
3636

3737
pub const BOX_SHADOW_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(17717747047134343426);
3838

@@ -365,7 +365,7 @@ pub fn queue_shadows(
365365
pipeline,
366366
entity: (*entity, extracted_shadow.main_entity),
367367
sort_key: (
368-
FloatOrd(extracted_shadow.stack_index as f32 - 0.1),
368+
FloatOrd(extracted_shadow.stack_index as f32 + stack_z_offsets::BOX_SHADOW),
369369
entity.index(),
370370
),
371371
batch_range: 0..0,

crates/bevy_ui/src/render/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ pub mod graph {
7575
/// When this is _not_ possible, pick a suitably unique index unlikely to clash with other things (ex: `0.1826823` not `0.1`).
7676
///
7777
/// Offsets should be unique for a given node entity to avoid z fighting.
78-
/// These should pretty much _always_ be larger than -1.0 and smaller than 1.0 to avoid clipping into nodes
78+
/// These should pretty much _always_ be larger than -0.5 and smaller than 0.5 to avoid clipping into nodes
7979
/// above / below the current node in the stack.
8080
///
8181
/// A z-index of 0.0 is the baseline, which is used as the primary "background color" of the node.
8282
///
8383
/// Note that nodes "stack" on each other, so a negative offset on the node above could clip _into_
8484
/// a positive offset on a node below.
8585
pub mod stack_z_offsets {
86-
pub const BACKGROUND_COLOR: f32 = 0.0;
86+
pub const BOX_SHADOW: f32 = -0.1;
87+
pub const TEXTURE_SLICE: f32 = 0.0;
88+
pub const NODE: f32 = 0.0;
8789
pub const MATERIAL: f32 = 0.18267;
8890
}
8991

@@ -861,7 +863,7 @@ pub fn queue_uinodes(
861863
pipeline,
862864
entity: (*entity, extracted_uinode.main_entity),
863865
sort_key: (
864-
FloatOrd(extracted_uinode.stack_index as f32 + stack_z_offsets::BACKGROUND_COLOR),
866+
FloatOrd(extracted_uinode.stack_index as f32 + stack_z_offsets::NODE),
865867
entity.index(),
866868
),
867869
// batch_range will be calculated in prepare_uinodes

crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ pub fn queue_ui_slices(
365365
pipeline,
366366
entity: (*entity, extracted_slicer.main_entity),
367367
sort_key: (
368-
FloatOrd(extracted_slicer.stack_index as f32),
368+
FloatOrd(extracted_slicer.stack_index as f32 + stack_z_offsets::TEXTURE_SLICE),
369369
entity.index(),
370370
),
371371
batch_range: 0..0,

0 commit comments

Comments
 (0)