Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions _release-content/migration-guides/skybox_image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "`Skybox` `image` is now optional"
pull_requests: [23691]
---

The `image` field of the `Skybox` component now has the type `Option<Handle<Image>>` instead of `Handle<Image>`.
A `Skybox` component without an image will not draw anything, just like it was not present.

If you were creating a skybox with an image, wrap the image handle in `Some`:

```rust
// 0.18
Skybox {
image: my_skybox,
brightness: 1000.0,
..default()
}

// 0.19
Skybox {
image: Some(my_skybox),
brightness: 1000.0,
..default()
}
```

If you were previously creating a `Skybox` component with a placeholder image to be changed later, you can now remove the placeholder:

```rust
// 0.18
Skybox {
image: cubemap_image_that_will_not_actually_be_seen,
brightness: 1000.0,
..default()
}

// 0.19
Skybox {
brightness: 1000.0,
..default()
}
```
13 changes: 8 additions & 5 deletions crates/bevy_core_pipeline/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,18 @@ fn prepare_skybox_bind_groups(
views: Query<(Entity, &Skybox, &DynamicUniformIndex<SkyboxUniforms>)>,
) {
for (entity, skybox, skybox_uniform_index) in &views {
if let (Some(skybox), Some(view_uniforms), Some(skybox_uniforms)) = (
images.get(&skybox.image),
if let (Some(image_handle), Some(view_uniforms), Some(skybox_uniforms)) = (
&skybox.image,
view_uniforms.uniforms.binding(),
skybox_uniforms.binding(),
) {
) && let Some(image) = images.get(image_handle)
{
let bind_group = render_device.create_bind_group(
"skybox_bind_group",
&pipeline_cache.get_bind_group_layout(&pipeline.bind_group_layout),
&BindGroupEntries::sequential((
&skybox.texture_view,
&skybox.sampler,
&image.texture_view,
&image.sampler,
view_uniforms,
skybox_uniforms,
)),
Expand All @@ -246,6 +247,8 @@ fn prepare_skybox_bind_groups(
commands
.entity(entity)
.insert(SkyboxBindGroup((bind_group, skybox_uniform_index.index())));
} else {
commands.entity(entity).remove::<SkyboxBindGroup>();
}
}
}
12 changes: 9 additions & 3 deletions crates/bevy_light/src/probe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use bevy_asset::{Assets, Handle, RenderAssetUsages};
use bevy_asset::{Assets, Handle, HandleTemplate, RenderAssetUsages};
use bevy_camera::visibility::{self, ViewVisibility, Visibility, VisibilityClass};
use bevy_color::{Color, ColorToComponents, Srgba};
use bevy_ecs::prelude::*;
use bevy_ecs::template::{FromTemplate, OptionTemplate};
use bevy_image::Image;
use bevy_math::{Quat, UVec2, Vec3};
use bevy_reflect::prelude::*;
Expand Down Expand Up @@ -224,7 +225,12 @@ impl Default for EnvironmentMapLight {
#[reflect(Component, Default, Clone)]
pub struct Skybox {
/// The cubemap to use.
pub image: Handle<Image>,
///
/// If this is [`None`], the skybox will not be rendered, as if it does not exist.
/// This allows `Skybox` to implement [`Default`].
#[template(OptionTemplate<HandleTemplate<Image>>)]
pub image: Option<Handle<Image>>,

/// Scale factor applied to the skybox image.
/// After applying this multiplier to the image samples, the resulting values should
/// be in units of [cd/m^2](https://en.wikipedia.org/wiki/Candela_per_square_metre).
Expand All @@ -239,7 +245,7 @@ pub struct Skybox {
impl Default for Skybox {
fn default() -> Self {
Skybox {
image: Handle::default(),
image: None,
brightness: 0.0,
rotation: Quat::IDENTITY,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/anisotropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ fn add_skybox_and_environment_map(
.entity(entity)
.insert(Skybox {
brightness: 5000.0,
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
..default()
})
.insert(EnvironmentMapLight {
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/auto_exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn setup(
..default()
},
Skybox {
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
brightness: light_consts::lux::DIRECT_SUNLIGHT,
..default()
},
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/clearcoat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
))
.insert(Skybox {
brightness: 5000.0,
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
..default()
})
.insert(EnvironmentMapLight {
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/contact_shadows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Hdr,
Skybox {
brightness: 1000.0,
image: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2")),
..default()
},
EnvironmentMapLight {
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/irradiance_volumes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn spawn_camera(commands: &mut Commands, assets: &ExampleAssets) {
Camera3d::default(),
Transform::from_xyz(-10.012, 4.8605, 13.281).looking_at(Vec3::ZERO, Vec3::Y),
Skybox {
image: assets.skybox.clone(),
image: Some(assets.skybox.clone()),
brightness: 150.0,
..default()
},
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/pcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
.insert(MotionVectorPrepass)
// Add a nice skybox.
.insert(Skybox {
image: asset_server.load("environment_maps/sky_skybox.ktx2"),
image: Some(asset_server.load("environment_maps/sky_skybox.ktx2")),
brightness: 500.0,
rotation: Quat::IDENTITY,
});
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/reflection_probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn add_environment_map_to_camera(
.entity(camera_entity)
.insert(create_camera_environment_map_light(&cubemaps))
.insert(Skybox {
image: cubemaps.specular_environment_map.clone(),
image: Some(cubemaps.specular_environment_map.clone()),
brightness: ENV_MAP_INTENSITY,
..default()
});
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/rotate_environment_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
))
.insert(Skybox {
brightness: 5000.0,
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
..default()
})
.insert(EnvironmentMapLight {
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/skybox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
FreeCamera::default(),
Skybox {
image: skybox_handle.clone(),
image: Some(skybox_handle.clone()),
brightness: 1000.0,
..default()
},
Expand Down Expand Up @@ -168,7 +168,7 @@ fn asset_loaded(
}

for mut skybox in &mut skyboxes {
skybox.image = cubemap.image_handle.clone();
skybox.image = Some(cubemap.image_handle.clone());
}

cubemap.is_loaded = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/specular_tint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn setup(
Hdr,
Camera3d::default(),
Skybox {
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
brightness: 3000.0,
..default()
},
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/ssr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer, app_setting
..default()
},
Skybox {
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
brightness: 5000.0,
..default()
},
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/volumetric_fog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: R
Bloom::default(),
))
.insert(Skybox {
image: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
image: Some(asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2")),
brightness: 1000.0,
..default()
})
Expand Down
4 changes: 2 additions & 2 deletions examples/testbed/3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ mod white_furnace_solid_color_light {
..OrthographicProjection::default_3d()
}),
Skybox {
image: white_cubemap_handle,
image: Some(white_cubemap_handle),
// middle gray
brightness: 500.0,
..default()
Expand Down Expand Up @@ -701,7 +701,7 @@ mod white_furnace_environment_map_light {
..OrthographicProjection::default_3d()
}),
Skybox {
image: white_cubemap_handle,
image: Some(white_cubemap_handle),
// middle gray
brightness: 500.0,
..default()
Expand Down