diff --git a/crates/bevy_pbr/src/entity.rs b/crates/bevy_pbr/src/entity.rs index 5cf11e89844e49..ba8f3fcbf039dd 100644 --- a/crates/bevy_pbr/src/entity.rs +++ b/crates/bevy_pbr/src/entity.rs @@ -2,7 +2,7 @@ use crate::{light::Light, material::StandardMaterial, render_graph::FORWARD_PIPE use bevy_asset::Handle; use bevy_ecs::Bundle; use bevy_render::{ - draw::Draw, + draw::{Draw, Transparent}, mesh::Mesh, pipeline::{RenderPipeline, RenderPipelines}, prelude::Visible, @@ -18,6 +18,7 @@ pub struct PbrBundle { pub main_pass: MainPass, pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub render_pipelines: RenderPipelines, pub transform: Transform, pub global_transform: GlobalTransform, @@ -31,6 +32,7 @@ impl Default for PbrBundle { )]), mesh: Default::default(), visible: Default::default(), + transparent: Default::default(), material: Default::default(), main_pass: Default::default(), draw: Default::default(), diff --git a/crates/bevy_render/src/camera/visible_entities.rs b/crates/bevy_render/src/camera/visible_entities.rs index 9c7edd59168eb3..9865069d3dc538 100644 --- a/crates/bevy_render/src/camera/visible_entities.rs +++ b/crates/bevy_render/src/camera/visible_entities.rs @@ -1,5 +1,5 @@ use super::{Camera, DepthCalculation}; -use crate::prelude::Visible; +use crate::{draw::Transparent, prelude::Visible}; use bevy_core::FloatOrd; use bevy_ecs::{Entity, Query, With}; use bevy_reflect::{Reflect, ReflectComponent}; @@ -204,8 +204,8 @@ pub fn visible_entities_system( &mut VisibleEntities, Option<&RenderLayers>, )>, - visible_query: Query<(Entity, &Visible, Option<&RenderLayers>)>, - visible_transform_query: Query<&GlobalTransform, With>, + visible_query: Query<(Entity, Option<&RenderLayers>, Option<&Transparent>), With>, + visible_transform_query: Query<(&GlobalTransform, Option<&Transparent>), With>, ) { for (camera, camera_global_transform, mut visible_entities, maybe_camera_mask) in camera_query.iter_mut() @@ -216,17 +216,16 @@ pub fn visible_entities_system( let mut no_transform_order = 0.0; let mut transparent_entities = Vec::new(); - for (entity, visible, maybe_entity_mask) in visible_query.iter() { - if !visible.is_visible { - continue; - } + for (entity, maybe_entity_mask, transparent) in visible_query.iter() { let entity_mask = maybe_entity_mask.copied().unwrap_or_default(); if !camera_mask.intersects(&entity_mask) { continue; } - let order = if let Ok(global_transform) = visible_transform_query.get(entity) { + let order = if let Ok(global_transform) = + visible_transform_query.get_component::(entity) + { let position = global_transform.translation; // smaller distances are sorted to lower indices by using the distance from the camera FloatOrd(match camera.depth_calculation { @@ -239,7 +238,7 @@ pub fn visible_entities_system( order }; - if visible.is_transparent { + if transparent.is_some() { transparent_entities.push(VisibleEntity { entity, order }) } else { visible_entities.value.push(VisibleEntity { entity, order }) diff --git a/crates/bevy_render/src/draw.rs b/crates/bevy_render/src/draw.rs index ab6c6192465bd2..51e441804c708c 100644 --- a/crates/bevy_render/src/draw.rs +++ b/crates/bevy_render/src/draw.rs @@ -46,20 +46,25 @@ pub enum RenderCommand { }, } +/// Marker Component. If an Entity *has* this component, it *is* visible. #[derive(Debug, Clone, Reflect)] #[reflect(Component)] -pub struct Visible { - pub is_visible: bool, - // TODO: consider moving this to materials - pub is_transparent: bool, -} +pub struct Visible; impl Default for Visible { fn default() -> Self { - Visible { - is_visible: true, - is_transparent: false, - } + Visible + } +} + +/// Marker Component. If an Entity *has* this component, it *is* transparent. +#[derive(Debug, Clone, Reflect)] +#[reflect(Component)] +pub struct Transparent; + +impl Default for Transparent { + fn default() -> Self { + Transparent } } diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 8097cfefd68601..09f03d0fa99afc 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -13,7 +13,7 @@ pub mod texture; use bevy_ecs::{IntoExclusiveSystem, IntoSystem, SystemStage}; use bevy_reflect::RegisterTypeBuilder; -use draw::Visible; +use draw::{Transparent, Visible}; pub use once_cell; pub mod prelude { @@ -129,6 +129,7 @@ impl Plugin for RenderPlugin { .register_type::() .register_type::() .register_type::() + .register_type::() .register_type::() .register_type::() .register_type::() diff --git a/crates/bevy_render/src/pipeline/render_pipelines.rs b/crates/bevy_render/src/pipeline/render_pipelines.rs index da2928e5fe4c2b..92a612e74eefbb 100644 --- a/crates/bevy_render/src/pipeline/render_pipelines.rs +++ b/crates/bevy_render/src/pipeline/render_pipelines.rs @@ -6,7 +6,7 @@ use crate::{ renderer::RenderResourceBindings, }; use bevy_asset::{Assets, Handle}; -use bevy_ecs::{Query, Res, ResMut}; +use bevy_ecs::{Query, Res, ResMut, With}; use bevy_reflect::{Reflect, ReflectComponent}; use bevy_utils::HashSet; @@ -82,13 +82,9 @@ pub fn draw_render_pipelines_system( mut render_resource_bindings: ResMut, msaa: Res, meshes: Res>, - mut query: Query<(&mut Draw, &mut RenderPipelines, &Handle, &Visible)>, + mut query: Query<(&mut Draw, &mut RenderPipelines, &Handle), With>, ) { - for (mut draw, mut render_pipelines, mesh_handle, visible) in query.iter_mut() { - if !visible.is_visible { - continue; - } - + for (mut draw, mut render_pipelines, mesh_handle) in query.iter_mut() { // don't render if the mesh isn't loaded yet let mesh = if let Some(mesh) = meshes.get(mesh_handle) { mesh diff --git a/crates/bevy_render/src/render_graph/nodes/pass_node.rs b/crates/bevy_render/src/render_graph/nodes/pass_node.rs index 2db0058ac52b4c..b067a4bb3fe1b5 100644 --- a/crates/bevy_render/src/render_graph/nodes/pass_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/pass_node.rs @@ -237,10 +237,8 @@ where continue; }; - if let Ok(visible) = world.get::(visible_entity.entity) { - if !visible.is_visible { - continue; - } + if world.get::(visible_entity.entity).is_err() { + continue; } // each Draw component contains an ordered list of render commands. we turn those into actual render commands here diff --git a/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs b/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs index 141d8bfc9d7573..be18a418480bc4 100644 --- a/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/render_resources_node.rs @@ -437,8 +437,11 @@ fn render_resources_node_system( mut entities_waiting_for_textures: Local>, render_resource_context: Res>, mut queries: QuerySet<( - Query<(Entity, &T, &Visible, &mut RenderPipelines), Or<(Changed, Changed)>>, - Query<(Entity, &T, &Visible, &mut RenderPipelines)>, + Query< + (Entity, &T, Option<&Visible>, &mut RenderPipelines), + Or<(Changed, Changed)>, + >, + Query<(Entity, &T, &mut RenderPipelines), With>, )>, ) { let state = state.deref_mut(); @@ -456,9 +459,7 @@ fn render_resources_node_system( // handle entities that were waiting for texture loads on the last update for entity in std::mem::take(&mut *entities_waiting_for_textures) { - if let Ok((entity, uniforms, _visible, mut render_pipelines)) = - queries.q1_mut().get_mut(entity) - { + if let Ok((entity, uniforms, mut render_pipelines)) = queries.q1_mut().get_mut(entity) { if !setup_uniform_texture_resources::( &uniforms, render_resource_context, @@ -470,7 +471,7 @@ fn render_resources_node_system( } for (entity, uniforms, visible, mut render_pipelines) in queries.q0_mut().iter_mut() { - if !visible.is_visible { + if visible.is_none() { continue; } uniform_buffer_arrays.prepare_uniform_buffers(entity, uniforms); @@ -497,13 +498,7 @@ fn render_resources_node_system( &mut |mut staging_buffer, _render_resource_context| { // if the buffer array was resized, write all entities to the new buffer, otherwise only write changes if resized { - for (entity, uniforms, visible, mut render_pipelines) in - queries.q1_mut().iter_mut() - { - if !visible.is_visible { - continue; - } - + for (entity, uniforms, mut render_pipelines) in queries.q1_mut().iter_mut() { state.uniform_buffer_arrays.write_uniform_buffers( entity, &uniforms, @@ -517,7 +512,7 @@ fn render_resources_node_system( for (entity, uniforms, visible, mut render_pipelines) in queries.q0_mut().iter_mut() { - if !visible.is_visible { + if visible.is_none() { continue; } diff --git a/crates/bevy_render/src/shader/shader_defs.rs b/crates/bevy_render/src/shader/shader_defs.rs index 977872462732cc..818c3baf48d1cd 100644 --- a/crates/bevy_render/src/shader/shader_defs.rs +++ b/crates/bevy_render/src/shader/shader_defs.rs @@ -1,8 +1,8 @@ use bevy_asset::{Asset, Assets, Handle}; -use crate::{pipeline::RenderPipelines, Texture}; +use crate::{pipeline::RenderPipelines, prelude::Visible, Texture}; pub use bevy_derive::ShaderDefs; -use bevy_ecs::{Query, Res}; +use bevy_ecs::{Query, Res, With}; /// Something that can either be "defined" or "not defined". This is used to determine if a "shader def" should be considered "defined" pub trait ShaderDef { @@ -60,7 +60,7 @@ impl ShaderDef for Option> { } /// Updates [RenderPipelines] with the latest [ShaderDefs] -pub fn shader_defs_system(mut query: Query<(&T, &mut RenderPipelines)>) +pub fn shader_defs_system(mut query: Query<(&T, &mut RenderPipelines), With>) where T: ShaderDefs + Send + Sync + 'static, { @@ -93,7 +93,7 @@ pub fn clear_shader_defs_system(mut query: Query<&mut RenderPipelines>) { /// Updates [RenderPipelines] with the latest [ShaderDefs] from a given asset type pub fn asset_shader_defs_system( assets: Res>, - mut query: Query<(&Handle, &mut RenderPipelines)>, + mut query: Query<(&Handle, &mut RenderPipelines), With>, ) where T: ShaderDefs + Send + Sync + 'static, { diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index 2ae632f368ac75..516621f8a454c9 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -24,6 +24,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.4.0", features = ["bevy" bevy_render = { path = "../bevy_render", version = "0.4.0" } bevy_transform = { path = "../bevy_transform", version = "0.4.0" } bevy_utils = { path = "../bevy_utils", version = "0.4.0" } +bevy_window = { path = "../bevy_window", version = "0.4.0" } # other rectangle-pack = "0.2" diff --git a/crates/bevy_sprite/src/entity.rs b/crates/bevy_sprite/src/entity.rs index ca5bb47853cd93..5a9ec8543f2c98 100644 --- a/crates/bevy_sprite/src/entity.rs +++ b/crates/bevy_sprite/src/entity.rs @@ -5,6 +5,7 @@ use crate::{ use bevy_asset::Handle; use bevy_ecs::Bundle; use bevy_render::{ + draw::Transparent, mesh::Mesh, pipeline::{RenderPipeline, RenderPipelines}, prelude::{Draw, Visible}, @@ -20,6 +21,7 @@ pub struct SpriteBundle { pub main_pass: MainPass, pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub render_pipelines: RenderPipelines, pub transform: Transform, pub global_transform: GlobalTransform, @@ -32,10 +34,8 @@ impl Default for SpriteBundle { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( SPRITE_PIPELINE_HANDLE.typed(), )]), - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, main_pass: MainPass, draw: Default::default(), sprite: Default::default(), @@ -57,6 +57,7 @@ pub struct SpriteSheetBundle { /// Data pertaining to how the sprite is drawn on the screen pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub render_pipelines: RenderPipelines, pub main_pass: MainPass, pub mesh: Handle, // TODO: maybe abstract this out @@ -70,10 +71,8 @@ impl Default for SpriteSheetBundle { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( SPRITE_SHEET_PIPELINE_HANDLE.typed(), )]), - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, main_pass: MainPass, mesh: QUAD_HANDLE.typed(), draw: Default::default(), diff --git a/crates/bevy_sprite/src/frustum_culling.rs b/crates/bevy_sprite/src/frustum_culling.rs new file mode 100644 index 00000000000000..f72f13b2f97e63 --- /dev/null +++ b/crates/bevy_sprite/src/frustum_culling.rs @@ -0,0 +1,126 @@ +use bevy_asset::{Assets, Handle}; +use bevy_ecs::{Commands, Entity, Query, Res, With}; +use bevy_math::Vec2; +use bevy_render::{camera::Camera, prelude::Visible}; +use bevy_transform::components::Transform; +use bevy_window::Windows; + +use crate::{Sprite, TextureAtlas, TextureAtlasSprite}; + +struct Rect { + position: Vec2, + size: Vec2, +} + +impl Rect { + #[inline] + pub fn is_overlapping(&self, other: Rect) -> bool { + !(self.position.x > other.end().x + || self.end().x < other.position.x + || self.position.y > other.end().y + || self.end().y < other.position.y) + } + + #[inline] + pub fn end(&self) -> Vec2 { + self.position + self.size + } +} +pub fn frustum_culling_sprites( + commands: &mut Commands, + windows: Res, + cameras: Query<&Transform, With>, + visible: Query<&Visible, With>, + sprites: Query<(Entity, &Transform, &Sprite)>, +) { + let window = windows.get_primary().unwrap(); + let window_size = Vec2::new(window.width(), window.height()); + + for camera_transform in cameras.iter() { + let camera_position = Vec2::new( + camera_transform.translation.x, + camera_transform.translation.y, + ); + + let camera_size = window_size * camera_transform.scale.truncate(); + + let rect = Rect { + position: camera_position - camera_size / Vec2::new(2.0, 2.0), + size: camera_size, + }; + + for (entity, drawable_transform, sprite) in sprites.iter() { + let sprite_rect = Rect { + position: drawable_transform.translation.truncate() + - sprite.size / Vec2::new(2.0, 2.0), + size: sprite.size, + }; + + if rect.is_overlapping(sprite_rect) { + if visible.get(entity).is_err() { + commands.insert_one(entity, Visible::default()); + } + } else if visible.get(entity).is_ok() { + commands.remove_one::(entity); + } + } + } +} + +pub fn frustum_culling_atlases( + commands: &mut Commands, + windows: Res, + textures: Res>, + cameras: Query<&Transform, With>, + visible: Query<&Visible, With>, + sprites: Query<( + Entity, + &Transform, + &TextureAtlasSprite, + &Handle, + )>, +) { + let window = windows.get_primary().unwrap(); + let window_size = Vec2::new(window.width(), window.height()); + + for camera_transform in cameras.iter() { + let camera_position = Vec2::new( + camera_transform.translation.x, + camera_transform.translation.y, + ); + + let camera_size = window_size * camera_transform.scale.truncate(); + + let rect = Rect { + position: camera_position - camera_size / Vec2::new(2.0, 2.0), + size: camera_size, + }; + + for (entity, drawable_transform, sprite, atlas_handle) in sprites.iter() { + let atlas = match textures.get(atlas_handle) { + Some(atlas) => atlas, + None => continue, + }; + + let sprite = match atlas.textures.get(sprite.index as usize) { + Some(sprite) => sprite, + None => continue, + }; + + let size = Vec2::new(sprite.width(), sprite.height()); + + let sprite_rect = Rect { + position: drawable_transform.translation.truncate() - size / Vec2::new(2.0, 2.0), + size, + }; + + if rect.is_overlapping(sprite_rect) { + if visible.get(entity).is_err() { + commands.insert_one(entity, Visible::default()); + } + } else if visible.get(entity).is_ok() { + commands.remove_one::(entity); + } + } + } +} diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index e0ea01cb2a1f3f..19db2ce77909bf 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -3,6 +3,7 @@ pub mod entity; mod color_material; mod dynamic_texture_atlas_builder; +mod frustum_culling; mod rect; mod render; mod sprite; @@ -48,6 +49,14 @@ impl Plugin for SpritePlugin { .add_asset::() .register_type::() .add_system_to_stage(CoreStage::PostUpdate, sprite_system.system()) + .add_system_to_stage( + CoreStage::PostUpdate, + frustum_culling::frustum_culling_sprites.system(), + ) + .add_system_to_stage( + CoreStage::PostUpdate, + frustum_culling::frustum_culling_atlases.system(), + ) .add_system_to_stage( CoreStage::PostUpdate, asset_shader_defs_system::.system(), diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index f35f712f252257..988178950995b5 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -1,9 +1,9 @@ use crate::ColorMaterial; use bevy_asset::{Assets, Handle}; -use bevy_ecs::{Query, Res}; +use bevy_ecs::{Query, Res, With}; use bevy_math::Vec2; use bevy_reflect::{Reflect, ReflectDeserialize, TypeUuid}; -use bevy_render::{renderer::RenderResources, texture::Texture}; +use bevy_render::{prelude::Visible, renderer::RenderResources, texture::Texture}; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Clone, RenderResources, TypeUuid, Reflect)] @@ -41,7 +41,7 @@ impl Sprite { pub fn sprite_system( materials: Res>, textures: Res>, - mut query: Query<(&mut Sprite, &Handle)>, + mut query: Query<(&mut Sprite, &Handle), With>, ) { for (mut sprite, handle) in query.iter_mut() { match sprite.resize_mode { diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 52b146b8430789..05e2227ceadf2c 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -2,7 +2,7 @@ use bevy_asset::Assets; use bevy_ecs::{Bundle, Changed, Entity, Local, Query, QuerySet, Res, ResMut, With}; use bevy_math::{Size, Vec3}; use bevy_render::{ - draw::{DrawContext, Drawable}, + draw::{DrawContext, Drawable, Transparent}, mesh::Mesh, prelude::{Draw, Msaa, Texture, Visible}, render_graph::base::MainPass, @@ -22,6 +22,7 @@ use crate::{ pub struct Text2dBundle { pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub text: Text, pub transform: Transform, pub global_transform: GlobalTransform, @@ -35,10 +36,8 @@ impl Default for Text2dBundle { draw: Draw { ..Default::default() }, - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, text: Default::default(), transform: Default::default(), global_transform: Default::default(), @@ -61,15 +60,8 @@ pub fn draw_text2d_system( mut render_resource_bindings: ResMut, text_pipeline: Res, mut query: Query< - ( - Entity, - &mut Draw, - &Visible, - &Text, - &GlobalTransform, - &CalculatedSize, - ), - With, + (Entity, &mut Draw, &Text, &GlobalTransform, &CalculatedSize), + (With, With), >, ) { let font_quad = meshes.get(&QUAD_HANDLE).unwrap(); @@ -81,11 +73,7 @@ pub fn draw_text2d_system( 1. }; - for (entity, mut draw, visible, text, global_transform, calculated_size) in query.iter_mut() { - if !visible.is_visible { - continue; - } - + for (entity, mut draw, text, global_transform, calculated_size) in query.iter_mut() { let (width, height) = (calculated_size.size.width, calculated_size.size.height); if let Some(text_glyphs) = text_pipeline.get_glyphs(&entity) { diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index 7e31c3e2b699e6..600e1624e6a41b 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -8,7 +8,7 @@ use bevy_asset::Handle; use bevy_ecs::Bundle; use bevy_render::{ camera::{Camera, DepthCalculation, OrthographicProjection, VisibleEntities, WindowOrigin}, - draw::Draw, + draw::{Draw, Transparent}, mesh::Mesh, pipeline::{RenderPipeline, RenderPipelines}, prelude::Visible, @@ -25,6 +25,7 @@ pub struct NodeBundle { pub material: Handle, pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub render_pipelines: RenderPipelines, pub transform: Transform, pub global_transform: GlobalTransform, @@ -37,10 +38,8 @@ impl Default for NodeBundle { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( UI_PIPELINE_HANDLE.typed(), )]), - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, node: Default::default(), style: Default::default(), material: Default::default(), @@ -61,6 +60,7 @@ pub struct ImageBundle { pub material: Handle, pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub render_pipelines: RenderPipelines, pub transform: Transform, pub global_transform: GlobalTransform, @@ -79,10 +79,8 @@ impl Default for ImageBundle { style: Default::default(), material: Default::default(), draw: Default::default(), - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, transform: Default::default(), global_transform: Default::default(), } @@ -95,6 +93,7 @@ pub struct TextBundle { pub style: Style, pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub text: Text, pub calculated_size: CalculatedSize, pub focus_policy: FocusPolicy, @@ -109,10 +108,8 @@ impl Default for TextBundle { draw: Draw { ..Default::default() }, - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, text: Default::default(), node: Default::default(), calculated_size: Default::default(), @@ -134,6 +131,7 @@ pub struct ButtonBundle { pub material: Handle, pub draw: Draw, pub visible: Visible, + pub transparent: Transparent, pub render_pipelines: RenderPipelines, pub transform: Transform, pub global_transform: GlobalTransform, @@ -153,10 +151,8 @@ impl Default for ButtonBundle { style: Default::default(), material: Default::default(), draw: Default::default(), - visible: Visible { - is_transparent: true, - ..Default::default() - }, + visible: Visible, + transparent: Transparent, transform: Default::default(), global_transform: Default::default(), } diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 97d4850d3fcf6d..494bb255217adc 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -1,6 +1,6 @@ use crate::{Node, Style, Val}; use bevy_asset::Assets; -use bevy_ecs::{Changed, Entity, Local, Or, Query, QuerySet, Res, ResMut}; +use bevy_ecs::{Changed, Entity, Local, Or, Query, QuerySet, Res, ResMut, With}; use bevy_math::Size; use bevy_render::{ draw::{Draw, DrawContext, Drawable}, @@ -133,7 +133,7 @@ pub fn draw_text_system( meshes: Res>, mut render_resource_bindings: ResMut, text_pipeline: Res, - mut query: Query<(Entity, &mut Draw, &Visible, &Text, &Node, &GlobalTransform)>, + mut query: Query<(Entity, &mut Draw, &Text, &Node, &GlobalTransform), With>, ) { let scale_factor = if let Some(window) = windows.get_primary() { window.scale_factor() @@ -144,11 +144,7 @@ pub fn draw_text_system( let font_quad = meshes.get(&QUAD_HANDLE).unwrap(); let vertex_buffer_layout = font_quad.get_vertex_buffer_layout(); - for (entity, mut draw, visible, text, node, global_transform) in query.iter_mut() { - if !visible.is_visible { - continue; - } - + for (entity, mut draw, text, node, global_transform) in query.iter_mut() { if let Some(text_glyphs) = text_pipeline.get_glyphs(&entity) { let position = global_transform.translation - (node.size / 2.0).extend(0.0); diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index 32d0a929d90739..29809df357c92b 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -58,10 +58,6 @@ fn setup( rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() }, - visible: Visible { - is_transparent: true, - ..Default::default() - }, ..Default::default() }) // textured quad - modulated @@ -73,10 +69,6 @@ fn setup( rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() }, - visible: Visible { - is_transparent: true, - ..Default::default() - }, ..Default::default() }) // textured quad - modulated @@ -88,10 +80,6 @@ fn setup( rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0), ..Default::default() }, - visible: Visible { - is_transparent: true, - ..Default::default() - }, ..Default::default() }) // camera