Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexorg committed Mar 21, 2024
2 parents 4f75a3b + 7b842e3 commit 087bef3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
49 changes: 32 additions & 17 deletions crates/bevy_ui/src/render/mod.rs
Expand Up @@ -9,7 +9,6 @@ use bevy_core_pipeline::{core_2d::Camera2d, core_3d::Camera3d};
use bevy_hierarchy::Parent;
use bevy_render::{render_phase::PhaseItem, view::ViewVisibility, ExtractSchedule, Render};
use bevy_sprite::{SpriteAssetEvents, TextureAtlas};
use bevy_window::{PrimaryWindow, Window};
pub use pipeline::*;
pub use render_pass::*;
pub use ui_material_pipeline::*;
Expand Down Expand Up @@ -181,7 +180,7 @@ pub struct ExtractedUiNodes {

pub fn extract_uinode_background_colors(
mut extracted_uinodes: ResMut<ExtractedUiNodes>,
windows: Extract<Query<&Window, With<PrimaryWindow>>>,
camera_query: Extract<Query<(Entity, &Camera)>>,
default_ui_camera: Extract<DefaultUiCamera>,
ui_scale: Extract<Res<UiScale>>,
uinode_query: Extract<
Expand All @@ -197,12 +196,6 @@ pub fn extract_uinode_background_colors(
)>,
>,
) {
let viewport_size = windows
.get_single()
.map(|window| window.resolution.size())
.unwrap_or(Vec2::ZERO)
* ui_scale.0;

for (
entity,
uinode,
Expand All @@ -224,8 +217,22 @@ pub fn extract_uinode_background_colors(
continue;
}

let ui_logical_viewport_size = camera_query
.get(camera_entity)
.ok()
.and_then(|(_, c)| c.logical_viewport_size())
.unwrap_or(Vec2::ZERO)
// The logical window resolution returned by `Window` only takes into account the window scale factor and not `UiScale`,
// so we have to divide by `UiScale` to get the size of the UI viewport.
/ ui_scale.0;

let border_radius = if let Some(border_radius) = border_radius {
resolve_border_radius(border_radius, uinode.size(), viewport_size, ui_scale.0)
resolve_border_radius(
border_radius,
uinode.size(),
ui_logical_viewport_size,
ui_scale.0,
)
} else {
[0.; 4]
};
Expand Down Expand Up @@ -257,7 +264,7 @@ pub fn extract_uinode_background_colors(
pub fn extract_uinode_images(
mut commands: Commands,
mut extracted_uinodes: ResMut<ExtractedUiNodes>,
windows: Extract<Query<&Window, With<PrimaryWindow>>>,
camera_query: Extract<Query<(Entity, &Camera)>>,
texture_atlases: Extract<Res<Assets<TextureAtlasLayout>>>,
ui_scale: Extract<Res<UiScale>>,
default_ui_camera: Extract<DefaultUiCamera>,
Expand All @@ -275,12 +282,6 @@ pub fn extract_uinode_images(
)>,
>,
) {
let viewport_size = windows
.get_single()
.map(|window| window.resolution.size())
.unwrap_or(Vec2::ZERO)
* ui_scale.0;

for (uinode, transform, view_visibility, clip, camera, image, atlas, slices, border_radius) in
&uinode_query
{
Expand Down Expand Up @@ -326,8 +327,22 @@ pub fn extract_uinode_images(
),
};

let ui_logical_viewport_size = camera_query
.get(camera_entity)
.ok()
.and_then(|(_, c)| c.logical_viewport_size())
.unwrap_or(Vec2::ZERO)
// The logical window resolution returned by `Window` only takes into account the window scale factor and not `UiScale`,
// so we have to divide by `UiScale` to get the size of the UI viewport.
/ ui_scale.0;

let border_radius = if let Some(border_radius) = border_radius {
resolve_border_radius(border_radius, uinode.size(), viewport_size, ui_scale.0)
resolve_border_radius(
border_radius,
uinode.size(),
ui_logical_viewport_size,
ui_scale.0,
)
} else {
[0.; 4]
};
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/render/ui.wgsl
Expand Up @@ -300,12 +300,12 @@ fn draw(in: VertexOutput) -> vec4<f32> {
// is present, otherwise an outline about the external boundary would be drawn even without
// a border.
let t = 1. - select(step(0.0, border_distance), smoothstep(0.0, fborder, border_distance), external_distance < internal_distance);
return vec4(color.rgb * t * color.a, t * color.a);
return color.rgba * t;
}

// The item is a rectangle, draw normally with anti-aliasing at the edges.
let t = 1. - smoothstep(0.0, fexternal, external_distance);
return vec4(color.rgb * t * color.a, t * color.a);
return color.rgba * t;
}

@fragment
Expand Down

0 comments on commit 087bef3

Please sign in to comment.