Migrate cameras to required components (#15641)

# Objective

Yet another PR for migrating stuff to required components. This time,
cameras!

## Solution

As per the [selected
proposal](https://hackmd.io/tsYID4CGRiWxzsgawzxG_g#Combined-Proposal-1-Selected),
deprecate `Camera2dBundle` and `Camera3dBundle` in favor of `Camera2d`
and `Camera3d`.

Adding a `Camera` without `Camera2d` or `Camera3d` now logs a warning,
as suggested by Cart [on
Discord](https://discord.com/channels/691052431525675048/1264881140007702558/1291506402832945273).
I would personally like cameras to work a bit differently and be split
into a few more components, to avoid some footguns and confusing
semantics, but that is more controversial, and shouldn't block this core
migration.

## Testing

I ran a few 2D and 3D examples, and tried cameras with and without
render graphs.

---

## Migration Guide

`Camera2dBundle` and `Camera3dBundle` have been deprecated in favor of
`Camera2d` and `Camera3d`. Inserting them will now also insert the other
components required by them automatically.
This commit is contained in:
Joona Aalto 2024-10-05 04:59:52 +03:00 committed by GitHub
parent ac9b0c848c
commit 25bfa80e60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
241 changed files with 871 additions and 970 deletions

View file

@ -346,7 +346,7 @@ android_shared_stdcxx = ["bevy_internal/android_shared_stdcxx"]
# Enable detailed trace event logging. These trace events are expensive even when off, thus they require compile time opt-in
detailed_trace = ["bevy_internal/detailed_trace"]
# Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the `Tonemapping` method on your `Camera2dBundle` or `Camera3dBundle`.
# Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the `Tonemapping` method for your `Camera2d` or `Camera3d`.
tonemapping_luts = ["bevy_internal/tonemapping_luts", "ktx2", "zstd"]
# Include SMAA Look Up Tables KTX2 Files

View file

@ -1,3 +1,5 @@
#![expect(deprecated)]
use crate::{
core_2d::graph::Core2d,
tonemapping::{DebandDither, Tonemapping},
@ -17,12 +19,25 @@ use bevy_render::{
};
use bevy_transform::prelude::{GlobalTransform, Transform};
/// A 2D camera component. Enables the 2D render graph for a [`Camera`].
#[derive(Component, Default, Reflect, Clone, ExtractComponent)]
#[extract_component_filter(With<Camera>)]
#[reflect(Component, Default)]
#[require(
Camera,
DebandDither,
CameraRenderGraph(|| CameraRenderGraph::new(Core2d)),
OrthographicProjection(OrthographicProjection::default_2d),
Frustum(|| OrthographicProjection::default_2d().compute_frustum(&GlobalTransform::from(Transform::default()))),
Tonemapping(|| Tonemapping::None),
)]
pub struct Camera2d;
#[derive(Bundle, Clone)]
#[deprecated(
since = "0.15.0",
note = "Use the `Camera2d` component instead. Inserting it will now also insert the other components required by it automatically."
)]
pub struct Camera2dBundle {
pub camera: Camera,
pub camera_render_graph: CameraRenderGraph,

View file

@ -1,3 +1,5 @@
#![expect(deprecated)]
use crate::{
core_3d::graph::Core3d,
tonemapping::{DebandDither, Tonemapping},
@ -15,12 +17,22 @@ use bevy_render::{
use bevy_transform::prelude::{GlobalTransform, Transform};
use serde::{Deserialize, Serialize};
/// Configuration for the "main 3d render graph".
/// The camera coordinate space is right-handed x-right, y-up, z-back.
/// A 3D camera component. Enables the main 3D render graph for a [`Camera`].
///
/// The camera coordinate space is right-handed X-right, Y-up, Z-back.
/// This means "forward" is -Z.
#[derive(Component, Reflect, Clone, ExtractComponent)]
#[extract_component_filter(With<Camera>)]
#[reflect(Component, Default)]
#[require(
Camera,
DebandDither(|| DebandDither::Enabled),
CameraRenderGraph(|| CameraRenderGraph::new(Core3d)),
Projection,
Tonemapping,
ColorGrading,
Exposure
)]
pub struct Camera3d {
/// The depth clear operation to perform for the main 3d pass.
pub depth_load_op: Camera3dDepthLoadOp,
@ -139,6 +151,10 @@ pub enum ScreenSpaceTransmissionQuality {
/// The camera coordinate space is right-handed x-right, y-up, z-back.
/// This means "forward" is -Z.
#[derive(Bundle, Clone)]
#[deprecated(
since = "0.15.0",
note = "Use the `Camera3d` component instead. Inserting it will now also insert the other components required by it automatically."
)]
pub struct Camera3dBundle {
pub camera: Camera,
pub camera_render_graph: CameraRenderGraph,

View file

@ -45,6 +45,7 @@ pub mod experimental {
/// The core pipeline prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
#[expect(deprecated)]
pub mod prelude {
#[doc(hidden)]
pub use crate::{

View file

@ -59,11 +59,11 @@ pub struct MotionBlurBundle {
/// camera.
///
/// ```
/// # use bevy_core_pipeline::{core_3d::Camera3dBundle, motion_blur::MotionBlur};
/// # use bevy_core_pipeline::{core_3d::Camera3d, motion_blur::MotionBlur};
/// # use bevy_ecs::prelude::*;
/// # fn test(mut commands: Commands) {
/// commands.spawn((
/// Camera3dBundle::default(),
/// Camera3d::default(),
/// MotionBlur::default(),
/// ));
/// # }

View file

@ -263,7 +263,7 @@ impl SpecializedRenderPipeline for TonemappingPipeline {
error!(
"AgX tonemapping requires the `tonemapping_luts` feature.
Either enable the `tonemapping_luts` feature for bevy in `Cargo.toml` (recommended),
or use a different `Tonemapping` method in your `Camera2dBundle`/`Camera3dBundle`."
or use a different `Tonemapping` method for your `Camera2d`/`Camera3d`."
);
shader_defs.push("TONEMAP_METHOD_AGX".into());
}
@ -275,7 +275,7 @@ impl SpecializedRenderPipeline for TonemappingPipeline {
error!(
"TonyMcMapFace tonemapping requires the `tonemapping_luts` feature.
Either enable the `tonemapping_luts` feature for bevy in `Cargo.toml` (recommended),
or use a different `Tonemapping` method in your `Camera2dBundle`/`Camera3dBundle`."
or use a different `Tonemapping` method for your `Camera2d`/`Camera3d`."
);
shader_defs.push("TONEMAP_METHOD_TONY_MC_MAPFACE".into());
}
@ -284,7 +284,7 @@ impl SpecializedRenderPipeline for TonemappingPipeline {
error!(
"BlenderFilmic tonemapping requires the `tonemapping_luts` feature.
Either enable the `tonemapping_luts` feature for bevy in `Cargo.toml` (recommended),
or use a different `Tonemapping` method in your `Camera2dBundle`/`Camera3dBundle`."
or use a different `Tonemapping` method for your `Camera2d`/`Camera3d`."
);
shader_defs.push("TONEMAP_METHOD_BLENDER_FILMIC".into());
}

View file

@ -4,7 +4,7 @@ use core::any::{Any, TypeId};
use bevy_app::{App, Plugin, PostUpdate};
use bevy_color::Hsla;
use bevy_core::Name;
use bevy_core_pipeline::core_2d::Camera2dBundle;
use bevy_core_pipeline::core_2d::Camera2d;
use bevy_ecs::{prelude::*, system::SystemParam};
use bevy_gizmos::{config::GizmoConfigStore, prelude::Gizmos, AppGizmoBuilder};
use bevy_hierarchy::{Children, Parent};
@ -88,19 +88,17 @@ fn update_debug_camera(
} else {
let spawn_cam = || {
cmds.spawn((
Camera2dBundle {
projection: OrthographicProjection {
Camera2d,
OrthographicProjection {
far: 1000.0,
viewport_origin: Vec2::new(0.0, 0.0),
..OrthographicProjection::default_3d()
},
camera: Camera {
Camera {
order: LAYOUT_DEBUG_CAMERA_ORDER,
clear_color: ClearColorConfig::None,
..default()
},
..default()
},
LAYOUT_DEBUG_LAYERS.clone(),
DebugOverlayCamera,
Name::new("Layout Debug Camera"),

View file

@ -55,9 +55,6 @@ use core::{any::TypeId, ptr::NonNull};
/// would create incoherent behavior.
/// This would be unexpected if bundles were treated as an abstraction boundary, as
/// the abstraction would be unmaintainable for these cases.
/// For example, both `Camera3dBundle` and `Camera2dBundle` contain the `CameraRenderGraph`
/// component, but specifying different render graphs to use.
/// If the bundles were both added to the same entity, only one of these two bundles would work.
///
/// For this reason, there is intentionally no [`Query`] to match whether an entity
/// contains the components of a bundle.

View file

@ -9,7 +9,7 @@ use bevy_asset::{
};
use bevy_color::{Color, LinearRgba};
use bevy_core::Name;
use bevy_core_pipeline::prelude::Camera3dBundle;
use bevy_core_pipeline::prelude::Camera3d;
use bevy_ecs::{
entity::{Entity, EntityHashMap},
world::World,
@ -1413,15 +1413,15 @@ fn load_node(
Projection::Perspective(perspective_projection)
}
};
node.insert(Camera3dBundle {
node.insert((
Camera3d::default(),
projection,
transform,
camera: Camera {
Camera {
is_active: !*active_camera_found,
..Default::default()
},
..Default::default()
});
));
*active_camera_found = true;
}

View file

@ -29,10 +29,7 @@ use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
/// # fn system(mut commands: Commands) {
/// commands.spawn((
/// // Setup your camera as usual
/// Camera3dBundle {
/// // ... camera options
/// # ..Default::default()
/// },
/// Camera3d::default(),
/// // Add fog to the same entity
/// DistanceFog {
/// color: Color::WHITE,

View file

@ -8,27 +8,29 @@ use crate::{
render_resource::TextureView,
texture::GpuImage,
view::{
ColorGrading, ExtractedView, ExtractedWindows, GpuCulling, RenderLayers, VisibleEntities,
ColorGrading, ExtractedView, ExtractedWindows, GpuCulling, Msaa, RenderLayers, Visibility,
VisibleEntities,
},
world_sync::RenderEntity,
world_sync::{RenderEntity, SyncToRenderWorld},
Extract,
};
use bevy_asset::{AssetEvent, AssetId, Assets, Handle};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{
change_detection::DetectChanges,
component::Component,
component::{Component, ComponentId},
entity::Entity,
event::EventReader,
prelude::With,
query::Has,
reflect::ReflectComponent,
system::{Commands, Query, Res, ResMut, Resource},
world::DeferredWorld,
};
use bevy_math::{ops, vec2, Dir3, Mat4, Ray3d, Rect, URect, UVec2, UVec4, Vec2, Vec3};
use bevy_reflect::prelude::*;
use bevy_render_macros::ExtractComponent;
use bevy_transform::components::GlobalTransform;
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_utils::{tracing::warn, warn_once, HashMap, HashSet};
use bevy_window::{
NormalizedWindowRef, PrimaryWindow, Window, WindowCreated, WindowRef, WindowResized,
@ -274,10 +276,25 @@ pub enum ViewportConversionError {
/// to transform the 3D objects into a 2D image, as well as the render target into which that image
/// is produced.
///
/// Adding a camera is typically done by adding a bundle, either the `Camera2dBundle` or the
/// `Camera3dBundle`.
/// Note that a [`Camera`] needs a [`CameraRenderGraph`] to render anything.
/// This is typically provided by adding a [`Camera2d`] or [`Camera3d`] component,
/// but custom render graphs can also be defined. Inserting a [`Camera`] with no render
/// graph will emit an error at runtime.
///
/// [`Camera2d`]: https://docs.rs/crate/bevy_core_pipeline/latest/core_2d/struct.Camera2d.html
/// [`Camera3d`]: https://docs.rs/crate/bevy_core_pipeline/latest/core_3d/struct.Camera3d.html
#[derive(Component, Debug, Reflect, Clone)]
#[reflect(Component, Default, Debug)]
#[component(on_add = warn_on_no_render_graph)]
#[require(
Frustum,
CameraMainTextureUsages,
VisibleEntities,
Transform,
Visibility,
Msaa,
SyncToRenderWorld
)]
pub struct Camera {
/// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`].
pub viewport: Option<Viewport>,
@ -309,6 +326,12 @@ pub struct Camera {
pub sub_camera_view: Option<SubCameraView>,
}
fn warn_on_no_render_graph(world: DeferredWorld, entity: Entity, _: ComponentId) {
if !world.entity(entity).contains::<CameraRenderGraph>() {
warn!("Entity {entity} has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.");
}
}
impl Default for Camera {
fn default() -> Self {
Self {

View file

@ -200,8 +200,7 @@ impl HalfSpace {
/// This process is called frustum culling, and entities can opt out of it using
/// the [`NoFrustumCulling`] component.
///
/// The frustum component is typically added from a bundle, either the `Camera2dBundle`
/// or the `Camera3dBundle`.
/// The frustum component is typically added automatically for cameras, either `Camera2d` or `Camera3d`.
/// It is usually updated automatically by [`update_frusta`] from the
/// [`CameraProjection`] component and [`GlobalTransform`] of the camera entity.
///

View file

@ -27,7 +27,7 @@ use bevy_transform::prelude::{GlobalTransform, Transform};
use bevy_utils::HashSet;
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
/// The bundle of components needed to draw text in a 2D scene via a 2D `Camera2dBundle`.
/// The bundle of components needed to draw text in a 2D scene via a `Camera2d`.
/// [Example usage.](https://github.com/bevyengine/bevy/blob/latest/examples/2d/text2d.rs)
#[derive(Bundle, Clone, Debug, Default)]
pub struct Text2dBundle {

View file

@ -464,7 +464,7 @@ mod tests {
use taffy::TraversePartialTree;
use bevy_asset::{AssetEvent, Assets};
use bevy_core_pipeline::core_2d::Camera2dBundle;
use bevy_core_pipeline::core_2d::Camera2d;
use bevy_ecs::{
entity::Entity,
event::Events,
@ -539,7 +539,7 @@ mod tests {
},
PrimaryWindow,
));
world.spawn(Camera2dBundle::default());
world.spawn(Camera2d);
let mut ui_schedule = Schedule::default();
ui_schedule.add_systems(
@ -646,7 +646,7 @@ mod tests {
assert!(ui_surface.camera_entity_to_taffy.is_empty());
// respawn camera
let camera_entity = world.spawn(Camera2dBundle::default()).id();
let camera_entity = world.spawn(Camera2d).id();
let ui_entity = world
.spawn((NodeBundle::default(), TargetCamera(camera_entity)))
@ -970,13 +970,13 @@ mod tests {
let (mut world, mut ui_schedule) = setup_ui_test_world();
world.spawn(Camera2dBundle {
camera: Camera {
world.spawn((
Camera2d,
Camera {
order: 1,
..default()
},
..default()
});
));
world.spawn((
NodeBundle {

View file

@ -2437,7 +2437,7 @@ impl TargetCamera {
/// # use bevy_ui::prelude::*;
/// # use bevy_ecs::prelude::Commands;
/// # use bevy_render::camera::{Camera, RenderTarget};
/// # use bevy_core_pipeline::prelude::Camera2dBundle;
/// # use bevy_core_pipeline::prelude::Camera2d;
/// # use bevy_window::{Window, WindowRef};
///
/// fn spawn_camera(mut commands: Commands) {
@ -2446,13 +2446,11 @@ impl TargetCamera {
/// ..Default::default()
/// }).id();
/// commands.spawn((
/// Camera2dBundle {
/// camera: Camera {
/// Camera2d,
/// Camera {
/// target: RenderTarget::Window(WindowRef::Entity(another_window)),
/// ..Default::default()
/// },
/// ..Default::default()
/// },
/// // We add the Marker here so all Ui will spawn in
/// // another window if no TargetCamera is specified
/// IsDefaultUiCamera
@ -2502,7 +2500,7 @@ impl<'w, 's> DefaultUiCamera<'w, 's> {
///
/// fn spawn_camera(mut commands: Commands) {
/// commands.spawn((
/// Camera2dBundle::default(),
/// Camera2d,
/// // This will cause all Ui in this camera to be rendered without
/// // anti-aliasing
/// UiAntiAlias::Off,

View file

@ -41,7 +41,7 @@ The default feature set enables most of the expected features of a game engine,
|png|PNG image format support|
|smaa_luts|Include SMAA Look Up Tables KTX2 Files|
|sysinfo_plugin|Enables system information diagnostic plugin|
|tonemapping_luts|Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the `Tonemapping` method on your `Camera2dBundle` or `Camera3dBundle`.|
|tonemapping_luts|Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the `Tonemapping` method for your `Camera2d` or `Camera3d`.|
|vorbis|OGG/VORBIS audio format support|
|webgl2|Enable some limitations to be able to use WebGL2. Please refer to the [WebGL2 and WebGPU](https://github.com/bevyengine/bevy/tree/latest/examples#webgl2-and-webgpu) section of the examples README for more information on how to run Wasm builds with WebGPU.|
|x11|X11 display server support|

View file

@ -40,10 +40,10 @@ fn setup_cube(
});
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
fn main() {
@ -83,10 +83,10 @@ fn setup_cube(
});
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
fn main() {

View file

@ -27,7 +27,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
let shapes = [
meshes.add(Circle::new(50.0)),

View file

@ -34,5 +34,5 @@ fn draw_cursor(
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}

View file

@ -23,14 +23,12 @@ fn setup(
asset_server: Res<AssetServer>,
) {
commands.spawn((
Camera2dBundle {
camera: Camera {
Camera2d,
Camera {
hdr: true, // 1. HDR is required for bloom
..default()
},
tonemapping: Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
..default()
},
Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
Bloom::default(), // 3. Enable bloom for the camera
));

View file

@ -206,7 +206,7 @@ const OFFSET_X: f32 = 125.;
const OFFSET_Y: f32 = 75.;
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn((
SpatialBundle {
transform: Transform::from_xyz(-OFFSET_X, OFFSET_Y, 0.),

View file

@ -60,7 +60,7 @@ fn setup(
));
// Add a camera
commands.spawn(Camera2dBundle { ..default() });
commands.spawn(Camera2d);
}
/// This custom material uses barycentric coordinates from

View file

@ -14,7 +14,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn((
Mesh2d(meshes.add(Rectangle::default())),
MeshMaterial2d(materials.add(Color::from(PURPLE))),

View file

@ -20,7 +20,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
let texture_handle = asset_server.load("branding/icon.png");
let mesh_handle = meshes.add(Rectangle::from_size(Vec2::splat(256.0)));

View file

@ -39,13 +39,13 @@ fn setup(
) {
let material = materials.add(asset_server.load("branding/icon.png"));
commands.spawn(Camera2dBundle {
camera: Camera {
commands.spawn((
Camera2d,
Camera {
clear_color: ClearColorConfig::Custom(DARK_SLATE_GREY.into()),
..default()
},
..default()
});
));
const UPPER_Y: f32 = 50.0;
const LOWER_Y: f32 = -50.0;

View file

@ -115,7 +115,7 @@ fn star(
));
// Spawn the camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}
// Require `HasMaterial2d` to indicate that no placeholder material should be rendeed.

View file

@ -33,7 +33,7 @@ fn setup(
let mesh_handle = meshes.add(mesh);
// Spawn camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// Spawn the quad with vertex colors
commands.spawn((

View file

@ -17,7 +17,7 @@ enum Direction {
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn((
SpriteBundle {
texture: asset_server.load("branding/icon.png"),

View file

@ -119,16 +119,14 @@ fn setup_camera(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
// this camera renders whatever is on `PIXEL_PERFECT_LAYERS` to the canvas
commands.spawn((
Camera2dBundle {
camera: Camera {
Camera2d,
Camera {
// render before the "main pass" camera
order: -1,
target: RenderTarget::Image(image_handle.clone()),
..default()
},
msaa: Msaa::Off,
..default()
},
Msaa::Off,
InGameCamera,
PIXEL_PERFECT_LAYERS,
));
@ -145,14 +143,7 @@ fn setup_camera(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
// the "outer" camera renders whatever is on `HIGH_RES_LAYERS` to the screen.
// here, the canvas and one of the sample sprites will be rendered by this camera
commands.spawn((
Camera2dBundle {
msaa: Msaa::Off,
..default()
},
OuterCamera,
HIGH_RES_LAYERS,
));
commands.spawn((Camera2d, Msaa::Off, OuterCamera, HIGH_RES_LAYERS));
}
/// Rotates entities to demonstrate grid snapping.

View file

@ -55,7 +55,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let enemy_b_handle = asset_server.load("textures/simplespace/enemy_B.png");
// 2D orthographic camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
let horizontal_margin = BOUNDS.x / 4.0;
let vertical_margin = BOUNDS.y / 4.0;

View file

@ -10,7 +10,7 @@ fn main() {
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn(SpriteBundle {
texture: asset_server.load("branding/bevy_bird_dark.png"),
..default()

View file

@ -90,7 +90,7 @@ fn setup(
asset_server: Res<AssetServer>,
mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// load the sprite sheet using the `AssetServer`
let texture = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");

View file

@ -10,7 +10,7 @@ fn main() {
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn(SpriteBundle {
texture: asset_server.load("branding/bevy_bird_dark.png"),
sprite: Sprite {

View file

@ -46,7 +46,7 @@ fn setup(
let texture_atlas_layout = texture_atlas_layouts.add(layout);
// Use only the subset of sprites in the sheet that make up the run animation
let animation_indices = AnimationIndices { first: 1, last: 6 };
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.spawn((
SpriteBundle {
transform: Transform::from_scale(Vec3::splat(6.0)),

View file

@ -98,7 +98,7 @@ fn spawn_sprites(
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
let style = TextStyle {
font: font.clone(),

View file

@ -19,7 +19,7 @@ struct AnimationState {
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
commands.insert_resource(AnimationState {
min: 128.0,
max: 512.0,

View file

@ -42,7 +42,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
};
let text_justification = JustifyText::Center;
// 2d camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// Demonstrate changing translation
commands.spawn((
Text2dBundle {

View file

@ -94,7 +94,7 @@ fn setup(
let atlas_nearest_padded_handle = texture_atlases.add(texture_atlas_nearest_padded);
// setup 2d scene
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// padded textures are to the right, unpadded to the left

View file

@ -11,7 +11,7 @@ fn main() {
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
let sprite_handle = asset_server.load("branding/icon.png");

View file

@ -85,7 +85,7 @@ fn setup(
));
// Camera
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// Text used to show controls
commands.spawn(

View file

@ -36,8 +36,8 @@ fn setup(
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

View file

@ -127,10 +127,10 @@ fn setup(
MeshMaterial3d(materials.add(Color::from(SILVER))),
));
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 7., 14.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 7., 14.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
));
#[cfg(not(target_arch = "wasm32"))]
commands.spawn(

View file

@ -69,8 +69,8 @@ fn setup(
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(15.0, 5.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(15.0, 5.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

View file

@ -17,11 +17,8 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(3.0, 1.0, 3.0)
.looking_at(Vec3::new(0.0, -0.5, 0.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(3.0, 1.0, 3.0).looking_at(Vec3::new(0.0, -0.5, 0.0), Vec3::Y),
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -64,11 +64,10 @@ fn main() {
/// Creates the initial scene.
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_status: Res<AppStatus>) {
commands.spawn(Camera3dBundle {
transform: Transform::from_translation(CAMERA_INITIAL_POSITION)
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_translation(CAMERA_INITIAL_POSITION).looking_at(Vec3::ZERO, Vec3::Y),
));
spawn_directional_light(&mut commands);

View file

@ -301,15 +301,12 @@ fn setup(
// Camera
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(0.7, 0.7, 1.0)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..default()
},
Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
ContrastAdaptiveSharpening {
enabled: false,
..default()

View file

@ -25,11 +25,8 @@ fn main() {
fn setup_camera_fog(mut commands: Commands) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-1.0, 0.1, 1.0)
.looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(-1.0, 0.1, 1.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
DistanceFog {
color: Color::srgba(0.35, 0.48, 0.66, 1.0),
directional_light_color: Color::srgba(1.0, 0.95, 0.85, 0.5),

View file

@ -39,14 +39,12 @@ fn setup(
let metering_mask = asset_server.load("textures/basic_metering_mask.png");
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(1.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Transform::from_xyz(1.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
AutoExposure {
metering_mask: metering_mask.clone(),
..default()

View file

@ -152,10 +152,10 @@ fn setup(
commands.spawn((PointLight::default(), Transform::from_xyz(4.0, 8.0, 4.0)));
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 2.5, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 2.5, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
));
// Controls Text

View file

@ -28,15 +28,13 @@ fn setup_scene(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true, // 1. HDR is required for bloom
..default()
},
tonemapping: Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
// 3. Enable bloom for the camera
Bloom::NATURAL,
));

View file

@ -72,8 +72,9 @@ fn setup(
));
// Main perspective Camera
commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(LARGE_SIZE, LARGE_SIZE),
physical_position: UVec2::new(PADDING, PADDING * 2 + SMALL_SIZE),
@ -82,12 +83,12 @@ fn setup(
..default()
},
transform,
..default()
});
));
// Perspective camera left half
commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(SMALL_SIZE, SMALL_SIZE),
physical_position: UVec2::new(PADDING, PADDING),
@ -109,13 +110,12 @@ fn setup(
..default()
},
transform,
..default()
});
));
// Perspective camera moving
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(SMALL_SIZE, SMALL_SIZE),
physical_position: UVec2::new(PADDING * 2 + SMALL_SIZE, PADDING),
@ -132,14 +132,13 @@ fn setup(
..default()
},
transform,
..default()
},
MovingCameraMarker,
));
// Perspective camera control
commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(SMALL_SIZE, SMALL_SIZE),
physical_position: UVec2::new(PADDING * 3 + SMALL_SIZE * 2, PADDING),
@ -156,17 +155,16 @@ fn setup(
..default()
},
transform,
..default()
});
));
// Main orthographic camera
commands.spawn(Camera3dBundle {
projection: OrthographicProjection {
commands.spawn((
Camera3d::default(),
Projection::from(OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical(6.0),
..OrthographicProjection::default_3d()
}
.into(),
camera: Camera {
}),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(LARGE_SIZE, LARGE_SIZE),
physical_position: UVec2::new(PADDING * 2 + LARGE_SIZE, PADDING * 2 + SMALL_SIZE),
@ -176,17 +174,16 @@ fn setup(
..default()
},
transform,
..default()
});
));
// Orthographic camera left half
commands.spawn(Camera3dBundle {
projection: OrthographicProjection {
commands.spawn((
Camera3d::default(),
Projection::from(OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical(6.0),
..OrthographicProjection::default_3d()
}
.into(),
camera: Camera {
}),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(SMALL_SIZE, SMALL_SIZE),
physical_position: UVec2::new(PADDING * 5 + SMALL_SIZE * 4, PADDING),
@ -206,18 +203,16 @@ fn setup(
..default()
},
transform,
..default()
});
));
// Orthographic camera moving
commands.spawn((
Camera3dBundle {
projection: OrthographicProjection {
Camera3d::default(),
Projection::from(OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical(6.0),
..OrthographicProjection::default_3d()
}
.into(),
camera: Camera {
}),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(SMALL_SIZE, SMALL_SIZE),
physical_position: UVec2::new(PADDING * 6 + SMALL_SIZE * 5, PADDING),
@ -234,19 +229,17 @@ fn setup(
..default()
},
transform,
..default()
},
MovingCameraMarker,
));
// Orthographic camera control
commands.spawn(Camera3dBundle {
projection: OrthographicProjection {
commands.spawn((
Camera3d::default(),
Projection::from(OrthographicProjection {
scaling_mode: ScalingMode::FixedVertical(6.0),
..OrthographicProjection::default_3d()
}
.into(),
camera: Camera {
}),
Camera {
viewport: Option::from(Viewport {
physical_size: UVec2::new(SMALL_SIZE, SMALL_SIZE),
physical_position: UVec2::new(PADDING * 7 + SMALL_SIZE * 6, PADDING),
@ -263,8 +256,7 @@ fn setup(
..default()
},
transform,
..default()
});
));
}
fn move_camera_view(

View file

@ -189,19 +189,19 @@ fn spawn_light(commands: &mut Commands) {
/// Spawns a camera with associated skybox and environment map.
fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
commands
.spawn(Camera3dBundle {
camera: Camera {
.spawn((
Camera3d::default(),
Camera {
hdr: true,
..default()
},
projection: Projection::Perspective(PerspectiveProjection {
Projection::Perspective(PerspectiveProjection {
fov: 27.0 / 180.0 * PI,
..default()
}),
transform: Transform::from_xyz(0.0, 0.0, 10.0),
tonemapping: AcesFitted,
..default()
})
Transform::from_xyz(0.0, 0.0, 10.0),
AcesFitted,
))
.insert(Skybox {
brightness: 5000.0,
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -352,16 +352,13 @@ fn add_text<'a>(
fn add_camera(commands: &mut Commands, asset_server: &AssetServer, color_grading: ColorGrading) {
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(0.7, 0.7, 1.0)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
color_grading,
..default()
},
DistanceFog {
color: Color::srgb_u8(43, 44, 47),
falloff: FogFalloff::Linear {

View file

@ -34,18 +34,15 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
) {
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
// Deferred both supports both hdr: true and hdr: false
hdr: false,
..default()
},
transform: Transform::from_xyz(0.7, 0.7, 1.0)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
// MSAA needs to be off for Deferred rendering
msaa: Msaa::Off,
..default()
},
Msaa::Off,
DistanceFog {
color: Color::srgb_u8(43, 44, 47),
falloff: FogFalloff::Linear {

View file

@ -70,16 +70,16 @@ fn main() {
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: Res<AppSettings>) {
// Spawn the camera. Enable HDR and bloom, as that highlights the depth of
// field effect.
let mut camera = commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 4.5, 8.25).looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
let mut camera = commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 4.5, 8.25).looking_at(Vec3::ZERO, Vec3::Y),
Camera {
hdr: true,
..default()
},
tonemapping: Tonemapping::TonyMcMapface,
..default()
});
camera.insert(Bloom::NATURAL);
Tonemapping::TonyMcMapface,
Bloom::NATURAL,
));
// Insert the depth of field settings.
if let Some(depth_of_field) = Option::<DepthOfField>::from(*app_settings) {

View file

@ -34,7 +34,7 @@ fn main() {
fn setup_camera_fog(mut commands: Commands) {
commands.spawn((
Camera3dBundle::default(),
Camera3d::default(),
DistanceFog {
color: Color::srgb(0.25, 0.25, 0.25),
falloff: FogFalloff::Linear {

View file

@ -61,23 +61,21 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
));
// Spawn a camera.
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-0.75, 1.0, 2.0)
.looking_at(vec3(0.0, 0.0, 0.0), Vec3::Y),
camera: Camera {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-0.75, 1.0, 2.0).looking_at(vec3(0.0, 0.0, 0.0), Vec3::Y),
Camera {
hdr: true,
..default()
},
..default()
})
.insert(VolumetricFog {
VolumetricFog {
// Make this relatively high in order to increase the fog quality.
step_count: 64,
// Disable ambient light.
ambient_intensity: 0.0,
..default()
});
},
));
}
/// Rotates the camera a bit every frame.

View file

@ -51,10 +51,7 @@ fn setup(
Transform::from_xyz(1.8, 1.8, 1.8).looking_at(Vec3::ZERO, Vec3::Y);
// Camera in 3D space.
commands.spawn(Camera3dBundle {
transform: camera_and_light_transform,
..default()
});
commands.spawn((Camera3d::default(), camera_and_light_transform));
// Light up the scene.
commands.spawn((PointLight::default(), camera_and_light_transform));

View file

@ -231,16 +231,15 @@ fn spawn_main_scene(commands: &mut Commands, assets: &ExampleAssets) {
}
fn spawn_camera(commands: &mut Commands, assets: &ExampleAssets) {
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-10.012, 4.8605, 13.281).looking_at(Vec3::ZERO, Vec3::Y),
..default()
})
.insert(Skybox {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-10.012, 4.8605, 13.281).looking_at(Vec3::ZERO, Vec3::Y),
Skybox {
image: assets.skybox.clone(),
brightness: 150.0,
..default()
});
},
));
}
fn spawn_irradiance_volume(commands: &mut Commands, assets: &ExampleAssets) {

View file

@ -244,11 +244,11 @@ fn setup(
);
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
exposure: Exposure::from_physical_camera(**parameters),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
Exposure::from_physical_camera(**parameters),
));
}
fn update_exposure(

View file

@ -16,10 +16,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
GltfAssetLabel::Scene(0).from_asset("models/CornellBox/CornellBox.glb"),
)));
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-278.0, 273.0, 800.0),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-278.0, 273.0, 800.0),
));
}
fn add_lightmaps_to_meshes(

View file

@ -59,10 +59,10 @@ fn setup(
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
#[derive(Asset, TypePath, Default, AsBindGroup, Debug, Clone)]

View file

@ -17,11 +17,8 @@ fn main() {
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.7, 0.7, 1.0)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -17,10 +17,10 @@ fn main() {
struct ExampleDisplay;
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn(DirectionalLight {
shadows_enabled: true,

View file

@ -49,12 +49,9 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(1.8, 0.4, -0.1))
.looking_at(Vec3::ZERO, Vec3::Y),
msaa: Msaa::Off,
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(1.8, 0.4, -0.1)).looking_at(Vec3::ZERO, Vec3::Y),
Msaa::Off,
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -18,7 +18,7 @@ fn main() {
fn setup_camera(mut commands: Commands) {
commands.spawn((
Camera3dBundle::default(),
Camera3d::default(),
// Add the `MotionBlur` component to a camera to enable motion blur.
// Motion blur requires the depth and motion vector prepass, which this bundle adds.
// Configure the amount and quality of motion blur per-camera using this component.

View file

@ -16,16 +16,15 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// camera
commands.spawn(Camera3dBundle {
projection: OrthographicProjection {
commands.spawn((
Camera3d::default(),
Projection::from(OrthographicProjection {
// 6 world units per window height.
scaling_mode: ScalingMode::FixedVertical(6.0),
..OrthographicProjection::default_3d()
}
.into(),
transform: Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}),
Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
// plane
commands.spawn((

View file

@ -212,10 +212,8 @@ fn setup(
// Camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(1.5, 1.5, 1.5).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(1.5, 1.5, 1.5).looking_at(Vec3::ZERO, Vec3::Y),
CameraController,
));

View file

@ -53,8 +53,8 @@ fn setup(
// light
commands.spawn((PointLight::default(), Transform::from_xyz(4.0, 5.0, -4.0)));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

View file

@ -114,15 +114,12 @@ fn setup(
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::default(), Vec3::Y),
projection: OrthographicProjection {
Camera3d::default(),
Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::default(), Vec3::Y),
Projection::from(OrthographicProjection {
scaling_mode: ScalingMode::WindowSize(100.0),
..OrthographicProjection::default_3d()
}
.into(),
..default()
},
}),
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -151,16 +151,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_status: Res
/// Spawns the camera, with the initial shadow filtering method.
fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-12.912 * 0.7, 4.466 * 0.7, -10.624 * 0.7)
.with_rotation(Quat::from_euler(
EulerRot::YXZ,
-134.76 / 180.0 * PI,
-0.175,
0.0,
)),
..default()
})
.spawn((
Camera3d::default(),
Transform::from_xyz(-12.912 * 0.7, 4.466 * 0.7, -10.624 * 0.7).with_rotation(
Quat::from_euler(EulerRot::YXZ, -134.76 / 180.0 * PI, -0.175, 0.0),
),
))
.insert(ShadowFilteringMethod::Gaussian)
// `TemporalJitter` is needed for TAA. Note that it does nothing without
// `TemporalAntiAliasSettings`.

View file

@ -59,15 +59,12 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: R
/// Spawns the camera, including the [`ChromaticAberration`] component.
fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(0.7, 0.7, 1.0)
.looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..default()
},
Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
DistanceFog {
color: Color::srgb_u8(43, 44, 47),
falloff: FogFalloff::Linear {

View file

@ -54,11 +54,8 @@ fn find_top_material_and_mesh(
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.6, 1.6, 11.3)
.looking_at(Vec3::new(0.0, 0.0, 3.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(0.6, 1.6, 11.3).looking_at(Vec3::new(0.0, 0.0, 3.0), Vec3::Y),
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -103,14 +103,14 @@ fn spawn_scene(commands: &mut Commands, asset_server: &AssetServer) {
// Spawns the camera.
fn spawn_camera(commands: &mut Commands) {
commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(-6.483, 0.325, 4.381).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
Transform::from_xyz(-6.483, 0.325, 4.381).looking_at(Vec3::ZERO, Vec3::Y),
));
}
// Creates the sphere mesh and spawns it.

View file

@ -84,16 +84,13 @@ fn setup(
));
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
target: image_handle.clone().into(),
clear_color: Color::WHITE.into(),
..default()
},
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Transform::from_translation(Vec3::new(0.0, 0.0, 15.0)).looking_at(Vec3::ZERO, Vec3::Y),
first_pass_layer,
));
@ -117,10 +114,10 @@ fn setup(
));
// The main pass camera.
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 0.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
/// Rotates the inner cube (first pass)

View file

@ -93,19 +93,19 @@ fn spawn_light(commands: &mut Commands) {
/// Spawns a camera with associated skybox and environment map.
fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
commands
.spawn(Camera3dBundle {
camera: Camera {
.spawn((
Camera3d::default(),
Camera {
hdr: true,
..default()
},
projection: Projection::Perspective(PerspectiveProjection {
Projection::Perspective(PerspectiveProjection {
fov: 27.0 / 180.0 * PI,
..default()
}),
transform: Transform::from_xyz(0.0, 0.0, 10.0),
tonemapping: AcesFitted,
..default()
})
Transform::from_xyz(0.0, 0.0, 10.0),
AcesFitted,
))
.insert(Skybox {
brightness: 5000.0,
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -49,16 +49,12 @@ fn setup(
) {
// Spawn camera with temporal anti-aliasing and a VolumetricFog configuration.
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 2.0, 0.0)
.looking_at(Vec3::new(-5.0, 3.5, -6.0), Vec3::Y),
camera: Camera {
Camera3d::default(),
Transform::from_xyz(0.0, 2.0, 0.0).looking_at(Vec3::new(-5.0, 3.5, -6.0), Vec3::Y),
Camera {
hdr: true,
..default()
},
msaa: Msaa::Off,
..default()
},
TemporalAntiAliasing::default(),
Bloom::default(),
VolumetricFog {

View file

@ -73,11 +73,8 @@ fn setup(
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-1.0, 1.0, 1.0)
.looking_at(Vec3::new(-1.0, 1.0, 0.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(-1.0, 1.0, 1.0).looking_at(Vec3::new(-1.0, 1.0, 0.0), Vec3::Y),
CameraController::default(),
ShadowFilteringMethod::Hardware2x2,
));

View file

@ -98,11 +98,10 @@ fn setup(
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-5.0, 5.0, 5.0)
.looking_at(Vec3::new(-1.0, 1.0, 0.0), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-5.0, 5.0, 5.0).looking_at(Vec3::new(-1.0, 1.0, 0.0), Vec3::Y),
));
}
fn toggle_light(

View file

@ -71,10 +71,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let skybox_handle = asset_server.load(CUBEMAPS[0].0);
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
CameraController::default(),
Skybox {
image: skybox_handle.clone(),

View file

@ -19,10 +19,10 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y),
));
// plane
commands.spawn((

View file

@ -68,16 +68,13 @@ fn setup(
{
let camera = commands
.spawn((
Camera3dBundle {
transform: Transform::from_translation(*camera_pos)
.looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
Camera3d::default(),
Transform::from_translation(*camera_pos).looking_at(Vec3::ZERO, Vec3::Y),
Camera {
// Renders cameras with different priorities to prevent ambiguities
order: index as isize,
..default()
},
..default()
},
CameraPosition {
pos: UVec2::new((index % 2) as u32, (index / 2) as u32),
},

View file

@ -117,14 +117,14 @@ fn setup(
}
// camera
commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(-4.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
Transform::from_xyz(-4.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn(
TextBundle::from_section(INSTRUCTIONS, TextStyle::default()).with_style(Style {

View file

@ -27,15 +27,13 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(-2.0, 2.0, -2.0).looking_at(Vec3::ZERO, Vec3::Y),
msaa: Msaa::Off,
..default()
},
Transform::from_xyz(-2.0, 2.0, -2.0).looking_at(Vec3::ZERO, Vec3::Y),
Msaa::Off,
ScreenSpaceAmbientOcclusion::default(),
TemporalAntiAliasing::default(),
));

View file

@ -225,16 +225,15 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
// rendering by adding depth and deferred prepasses. Turn on FXAA to make
// the scene look a little nicer. Finally, add screen space reflections.
commands
.spawn(Camera3dBundle {
transform: Transform::from_translation(vec3(-1.25, 2.25, 4.5))
.looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
.spawn((
Camera3d::default(),
Transform::from_translation(vec3(-1.25, 2.25, 4.5)).looking_at(Vec3::ZERO, Vec3::Y),
Camera {
hdr: true,
..default()
},
msaa: Msaa::Off,
..default()
})
Msaa::Off,
))
.insert(EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -71,8 +71,8 @@ fn setup(
Transform::from_xyz(0.0, 0.0, -1.5).with_rotation(Quat::from_rotation_x(-PI / 5.0)),
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

View file

@ -58,14 +58,12 @@ fn setup(
) {
// camera
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: camera_transform.0,
..default()
},
camera_transform.0,
DistanceFog {
color: Color::srgb_u8(43, 44, 47),
falloff: FogFalloff::Linear {

View file

@ -302,25 +302,23 @@ fn setup(
// Camera
commands.spawn((
Camera3dBundle {
camera: Camera {
Camera3d::default(),
Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(1.0, 1.8, 7.0).looking_at(Vec3::ZERO, Vec3::Y),
color_grading: ColorGrading {
Transform::from_xyz(1.0, 1.8, 7.0).looking_at(Vec3::ZERO, Vec3::Y),
ColorGrading {
global: ColorGradingGlobal {
post_saturation: 1.2,
..default()
},
..default()
},
tonemapping: Tonemapping::TonyMcMapface,
exposure: Exposure { ev100: 6.0 },
Tonemapping::TonyMcMapface,
Exposure { ev100: 6.0 },
#[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))]
msaa: Msaa::Off,
..default()
},
Msaa::Off,
#[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))]
TemporalAntiAliasing::default(),
EnvironmentMapLight {

View file

@ -90,10 +90,10 @@ fn setup(
));
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
/// Fades the alpha channel of all materials between 0 and 1 over time.

View file

@ -38,20 +38,20 @@ fn setup(
));
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(10.0, 10., -5.0).looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
// renders after / on top of the main camera
order: 1,
clear_color: ClearColorConfig::None,
..default()
},
..default()
});
Transform::from_xyz(10.0, 10., -5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

View file

@ -24,11 +24,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
},
));
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-0.5, 0.9, 1.5)
.looking_at(Vec3::new(-0.5, 0.3, 0.0), Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_xyz(-0.5, 0.9, 1.5).looking_at(Vec3::new(-0.5, 0.3, 0.0), Vec3::Y),
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -51,8 +51,8 @@ fn setup(
));
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

View file

@ -137,10 +137,10 @@ fn setup(
// Spawn a camera.
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.7, 0.7, 1.0).looking_at(CAMERA_FOCAL_POINT, Vec3::Y),
..default()
})
.spawn((
Camera3d::default(),
Transform::from_xyz(0.7, 0.7, 1.0).looking_at(CAMERA_FOCAL_POINT, Vec3::Y),
))
.insert(EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),

View file

@ -63,17 +63,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: R
// Spawn the camera.
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-1.7, 1.5, 4.5)
.looking_at(vec3(-1.5, 1.7, 3.5), Vec3::Y),
camera: Camera {
.spawn((
Camera3d::default(),
Camera {
hdr: true,
..default()
},
..default()
})
.insert(Tonemapping::TonyMcMapface)
.insert(Bloom::default())
Transform::from_xyz(-1.7, 1.5, 4.5).looking_at(vec3(-1.5, 1.7, 3.5), Vec3::Y),
Tonemapping::TonyMcMapface,
Bloom::default(),
))
.insert(Skybox {
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
brightness: 1000.0,

View file

@ -93,10 +93,10 @@ fn setup(
commands.spawn((PointLight::default(), Transform::from_xyz(2.0, 4.0, 2.0)));
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
// Text used to show controls
commands.spawn(

View file

@ -52,11 +52,10 @@ fn setup(
});
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(100.0, 100.0, 150.0)
.looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y),
));
// Plane
commands.spawn((

View file

@ -26,10 +26,10 @@ fn setup(
mut graphs: ResMut<Assets<AnimationGraph>>,
) {
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
));
// Light
commands.spawn((

View file

@ -144,7 +144,7 @@ fn setup(
animation_player.play(animation_node_index).repeat();
// Add a camera.
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
// Build the UI. We have a parent node that covers the whole screen and
// contains the `AnimationPlayer`, as well as a child node that contains the

View file

@ -218,10 +218,10 @@ fn setup_scene(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-10.0, 5.0, 13.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-10.0, 5.0, 13.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
));
commands.spawn((
PointLight {

View file

@ -122,11 +122,10 @@ fn setup_scene(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Spawn the camera.
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-15.0, 10.0, 20.0)
.looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-15.0, 10.0, 20.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
));
// Spawn the light.
commands.spawn((

Some files were not shown because too many files have changed in this diff Show more