Skip to content

Commit

Permalink
Merge branch 'bevyengine:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Litttlefish authored May 17, 2024
2 parents a30c3c4 + 11f0a2d commit 6b4adc1
Show file tree
Hide file tree
Showing 68 changed files with 2,068 additions and 293 deletions.
13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/bevyengine/bevy"
documentation = "https://docs.rs/bevy"
rust-version = "1.77.0"
rust-version = "1.78.0"

[workspace]
exclude = [
Expand Down Expand Up @@ -3044,6 +3044,17 @@ description = "Demonstrates depth of field"
category = "3D Rendering"
wasm = false

[[example]]
name = "volumetric_fog"
path = "examples/3d/volumetric_fog.rs"
doc-scrape-examples = true

[package.metadata.example.volumetric_fog]
name = "Volumetric fog"
description = "Demonstrates volumetric fog and lighting"
category = "3D Rendering"
wasm = true

[profile.wasm-release]
inherits = "release"
opt-level = "z"
Expand Down
Binary file not shown.
19 changes: 19 additions & 0 deletions benches/benches/bevy_render/render_layers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use bevy_render::view::RenderLayers;

fn render_layers(c: &mut Criterion) {
c.bench_function("layers_intersect", |b| {
let layer_a = RenderLayers::layer(1).with(2);
let layer_b = RenderLayers::layer(1);
b.iter(|| {
black_box(layer_a.intersects(&layer_b))
});
});
}

criterion_group!(
benches,
render_layers,
);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use std::any::Any;
/// }
/// }
/// # fn damp_flickering() {}
/// ````
/// ```
pub trait Plugin: Downcast + Any + Send + Sync {
/// Configures the [`App`] to which this plugin is added.
fn build(&self, app: &mut App);
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ impl Plugin for AssetPlugin {
}
}

#[diagnostic::on_unimplemented(
message = "`{Self}` is not an `Asset`",
label = "invalid `Asset`",
note = "consider annotating `{Self}` with `#[derive(Asset)]`"
)]
pub trait Asset: VisitAssetDependencies + TypePath + Send + Sync + 'static {}

pub trait VisitAssetDependencies {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/core_3d/camera_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Default for Camera3d {

#[derive(Clone, Copy, Reflect, Serialize, Deserialize)]
#[reflect(Serialize, Deserialize)]
pub struct Camera3dDepthTextureUsage(u32);
pub struct Camera3dDepthTextureUsage(pub u32);

impl From<TextureUsages> for Camera3dDepthTextureUsage {
fn from(value: TextureUsages) -> Self {
Expand Down
26 changes: 13 additions & 13 deletions crates/bevy_core_pipeline/src/dof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,21 @@ pub enum DepthOfFieldMode {
///
/// For more information, see [Wikipedia's article on *bokeh*].
///
/// This is the default.
/// This doesn't work on WebGPU.
///
/// [Wikipedia's article on *bokeh*]: https://en.wikipedia.org/wiki/Bokeh
#[default]
Bokeh,

/// A faster simulation, in which out-of-focus areas are simply blurred.
///
/// This is less accurate to actual lens behavior and is generally less
/// aesthetically pleasing but requires less video memory bandwidth.
///
/// This is the default.
///
/// This works on native and WebGPU.
/// If targeting native platforms, consider using [`DepthOfFieldMode::Bokeh`] instead.
#[default]
Gaussian,
}

Expand Down Expand Up @@ -790,12 +795,11 @@ impl SpecializedRenderPipeline for DepthOfFieldPipeline {
/// Extracts all [`DepthOfFieldSettings`] components into the render world.
fn extract_depth_of_field_settings(
mut commands: Commands,
msaa: Extract<Res<Msaa>>,
mut query: Extract<Query<(Entity, &DepthOfFieldSettings, &Projection)>>,
) {
if **msaa != Msaa::Off && !depth_textures_are_supported() {
if !DEPTH_TEXTURE_SAMPLING_SUPPORTED {
info_once!(
"Disabling depth of field on this platform because depth textures aren't available"
"Disabling depth of field on this platform because depth textures aren't supported correctly"
);
return;
}
Expand Down Expand Up @@ -889,10 +893,8 @@ impl DepthOfFieldPipelines {
/// `sampler2DShadow` and will cheerfully generate invalid GLSL that tries to
/// perform non-percentage-closer-filtering with such a sampler. Therefore we
/// disable depth of field entirely on WebGL 2.
#[cfg(target_arch = "wasm32")]
fn depth_textures_are_supported() -> bool {
false
}
#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
const DEPTH_TEXTURE_SAMPLING_SUPPORTED: bool = false;

/// Returns true if multisampled depth textures are supported on this platform.
///
Expand All @@ -901,7 +903,5 @@ fn depth_textures_are_supported() -> bool {
/// `sampler2DShadow` and will cheerfully generate invalid GLSL that tries to
/// perform non-percentage-closer-filtering with such a sampler. Therefore we
/// disable depth of field entirely on WebGL 2.
#[cfg(not(target_arch = "wasm32"))]
fn depth_textures_are_supported() -> bool {
true
}
#[cfg(any(feature = "webgpu", not(target_arch = "wasm32")))]
const DEPTH_TEXTURE_SAMPLING_SUPPORTED: bool = true;
6 changes: 3 additions & 3 deletions crates/bevy_dev_tools/src/ui_debug_overlay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod inset;
/// The [`Camera::order`] index used by the layout debug camera.
pub const LAYOUT_DEBUG_CAMERA_ORDER: isize = 255;
/// The [`RenderLayers`] used by the debug gizmos and the debug camera.
pub const LAYOUT_DEBUG_LAYERS: RenderLayers = RenderLayers::none().with(16);
pub const LAYOUT_DEBUG_LAYERS: RenderLayers = RenderLayers::layer(16);

#[derive(Clone, Copy)]
struct LayoutRect {
Expand Down Expand Up @@ -101,15 +101,15 @@ fn update_debug_camera(
},
..default()
},
LAYOUT_DEBUG_LAYERS,
LAYOUT_DEBUG_LAYERS.clone(),
DebugOverlayCamera,
Name::new("Layout Debug Camera"),
))
.id()
};
if let Some((config, _)) = gizmo_config.get_config_mut_dyn(&TypeId::of::<UiGizmosDebug>()) {
config.enabled = true;
config.render_layers = LAYOUT_DEBUG_LAYERS;
config.render_layers = LAYOUT_DEBUG_LAYERS.clone();
}
let cam = *options.layout_gizmos_camera.get_or_insert_with(spawn_cam);
let Ok(mut cam) = debug_cams.get_mut(cam) else {
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ use std::ptr::NonNull;
// bundle, in the _exact_ order that [`DynamicBundle::get_components`] is called.
// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by
// [`Bundle::component_ids`].
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a `Bundle`",
label = "invalid `Bundle`",
note = "consider annotating `{Self}` with `#[derive(Component)]` or `#[derive(Bundle)]`"
)]
pub unsafe trait Bundle: DynamicBundle + Send + Sync + 'static {
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
#[doc(hidden)]
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ use std::{
///
/// [`SyncCell`]: bevy_utils::synccell::SyncCell
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a `Component`",
label = "invalid `Component`",
note = "consider annotating `{Self}` with `#[derive(Component)]`"
)]
pub trait Component: Send + Sync + 'static {
/// A constant indicating the storage type used for this component.
const STORAGE_TYPE: StorageType;
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use super::EntityHashMap;
/// }
/// }
/// ```
///
pub trait MapEntities {
/// Updates all [`Entity`] references stored inside using `entity_mapper`.
///
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ use std::{
/// You can conveniently access events using the [`EventReader`] and [`EventWriter`] system parameter.
///
/// Events must be thread-safe.
#[diagnostic::on_unimplemented(
message = "`{Self}` is not an `Event`",
label = "invalid `Event`",
note = "consider annotating `{Self}` with `#[derive(Event]`"
)]
pub trait Event: Send + Sync + 'static {}

/// An `EventId` uniquely identifies an event stored in a specific [`World`].
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ use std::{cell::UnsafeCell, marker::PhantomData};
///
/// [`Query`]: crate::system::Query
/// [`ReadOnly`]: Self::ReadOnly
#[diagnostic::on_unimplemented(
message = "`{Self}` is not valid to request as data in a `Query`",
label = "invalid `Query` data"
)]
pub unsafe trait QueryData: WorldQuery {
/// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.
type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;
Expand Down
11 changes: 10 additions & 1 deletion crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ use std::{cell::UnsafeCell, marker::PhantomData};
/// [`matches_component_set`]: Self::matches_component_set
/// [`Query`]: crate::system::Query
/// [`State`]: Self::State

#[diagnostic::on_unimplemented(
message = "`{Self}` is not a valid `Query` filter",
label = "invalid `Query` filter",
note = "a `QueryFilter` typically uses a combination of `With<T>` and `Without<T>` statements"
)]
pub trait QueryFilter: WorldQuery {
/// Returns true if (and only if) this Filter relies strictly on archetypes to limit which
/// components are accessed by the Query.
Expand Down Expand Up @@ -938,6 +942,11 @@ impl<T: Component> QueryFilter for Changed<T> {
///
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
/// they do not implement [`ArchetypeFilter`].
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a valid `Query` filter based on archetype information",
label = "invalid `Query` filter",
note = "an `ArchetypeFilter` typically uses a combination of `With<T>` and `Without<T>` statements"
)]
pub trait ArchetypeFilter: QueryFilter {}

impl<T: Component> ArchetypeFilter for With<T> {}
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/schedule/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ impl<T> NodeConfigs<T> {
/// )
/// );
/// ```
#[diagnostic::on_unimplemented(
message = "`{Self}` does not describe a valid system configuration",
label = "invalid system configuration"
)]
pub trait IntoSystemConfigs<Marker>
where
Self: Sized,
Expand Down Expand Up @@ -562,6 +566,10 @@ impl SystemSetConfig {
pub type SystemSetConfigs = NodeConfigs<InternedSystemSet>;

/// Types that can convert into a [`SystemSetConfigs`].
#[diagnostic::on_unimplemented(
message = "`{Self}` does not describe a valid system set configuration",
label = "invalid system set configuration"
)]
pub trait IntoSystemSetConfigs
where
Self: Sized,
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/schedule/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ impl SystemSet for AnonymousSet {
}

/// Types that can be converted into a [`SystemSet`].
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a system set",
label = "invalid system set"
)]
pub trait IntoSystemSet<Marker>: Sized {
/// The type of [`SystemSet`] this instance converts into.
type Set: SystemSet;
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/system/adapter_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ use crate::{schedule::InternedSystemSet, world::unsafe_world_cell::UnsafeWorldCe
/// # system.initialize(&mut world);
/// # assert!(system.run((), &mut world));
/// ```
#[diagnostic::on_unimplemented(
message = "`{Self}` can not adapt a system of type `{S}`",
label = "invalid system adapter"
)]
pub trait Adapt<S: System>: Send + Sync + 'static {
/// The [input](System::In) type for an [`AdapterSystem`].
type In;
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/system/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ use super::{ReadOnlySystem, System};
/// # assert!(world.resource::<RanFlag>().0);
/// # world.resource_mut::<RanFlag>().0 = false;
/// ```
#[diagnostic::on_unimplemented(
message = "`{Self}` can not combine systems `{A}` and `{B}`",
label = "invalid system combination",
note = "the inputs and outputs of `{A}` and `{B}` are not compatible with this combiner"
)]
pub trait Combine<A: System, B: System> {
/// The [input](System::In) type for a [`CombinatorSystem`].
type In;
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_ecs/src/system/exclusive_function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ where
///
/// This trait can be useful for making your own systems which accept other systems,
/// sometimes called higher order systems.
#[diagnostic::on_unimplemented(
message = "`{Self}` is not an exclusive system",
label = "invalid system"
)]
pub trait ExclusiveSystemParamFunction<Marker>: Send + Sync + 'static {
/// The input type to this system. See [`System::In`].
type In;

/// The return type of this system. See [`System::Out`].
type Out;

/// The [`ExclusiveSystemParam`]/s defined by this system's `fn` parameters.
/// The [`ExclusiveSystemParam`]'s defined by this system's `fn` parameters.
type Param: ExclusiveSystemParam;

/// Executes this system once. See [`System::run`].
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/system/exclusive_system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use std::marker::PhantomData;

/// A parameter that can be used in an exclusive system (a system with an `&mut World` parameter).
/// Any parameters implementing this trait must come after the `&mut World` parameter.
#[diagnostic::on_unimplemented(
message = "`{Self}` can not be used as a parameter for an exclusive system",
label = "invalid system parameter"
)]
pub trait ExclusiveSystemParam: Sized {
/// Used to store data which persists across invocations of a system.
type State: Send + Sync + 'static;
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ where
/// ```
/// [`PipeSystem`]: crate::system::PipeSystem
/// [`ParamSet`]: crate::system::ParamSet
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a valid system",
label = "invalid system"
)]
pub trait SystemParamFunction<Marker>: Send + Sync + 'static {
/// The input type to this system. See [`System::In`].
type In;
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ use crate::world::World;
// This trait has to be generic because we have potentially overlapping impls, in particular
// because Rust thinks a type could impl multiple different `FnMut` combinations
// even though none can currently
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a valid system with input `{In}` and output `{Out}`",
label = "invalid system"
)]
pub trait IntoSystem<In, Out, Marker>: Sized {
/// The type of [`System`] that this instance converts into.
type System: System<In = In, Out = Out>;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use super::IntoSystem;
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
/// It's possible to specify explicit execution order between specific systems,
/// see [`IntoSystemConfigs`](crate::schedule::IntoSystemConfigs).
#[diagnostic::on_unimplemented(message = "`{Self}` is not a system", label = "invalid system")]
pub trait System: Send + Sync + 'static {
/// The system's input. See [`In`](crate::system::In) for
/// [`FunctionSystem`](crate::system::FunctionSystem)s.
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ impl_param_set!();
/// ```
///
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a `Resource`",
label = "invalid `Resource`",
note = "consider annotating `{Self}` with `#[derive(Resource)]`"
)]
pub trait Resource: Send + Sync + 'static {}

// SAFETY: Res only reads a single World resource
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl From<&GizmoConfig> for GizmoMeshConfig {
GizmoMeshConfig {
line_perspective: item.line_perspective,
line_style: item.line_style,
render_layers: item.render_layers,
render_layers: item.render_layers.clone(),
}
}
}
1 change: 1 addition & 0 deletions crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod config;
pub mod gizmos;
pub mod grid;
pub mod primitives;
pub mod rounded_box;

#[cfg(feature = "bevy_pbr")]
pub mod light;
Expand Down
Loading

0 comments on commit 6b4adc1

Please sign in to comment.