diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index d2f1abb1830aa..a1f47805fe8f4 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -10,6 +10,7 @@ use bevy_ecs::{ }; use bevy_image::BevyDefault; use bevy_light::Skybox; +use bevy_log::warn_once; use bevy_math::Mat4; use bevy_render::{ extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin}, @@ -227,17 +228,37 @@ fn prepare_skybox_bind_groups( views: Query<(Entity, &Skybox, &DynamicUniformIndex)>, ) { for (entity, skybox, skybox_uniform_index) in &views { - if let (Some(skybox), Some(view_uniforms), Some(skybox_uniforms)) = ( + if let (Some(skybox_image), Some(view_uniforms), Some(skybox_uniforms)) = ( images.get(&skybox.image), view_uniforms.uniforms.binding(), skybox_uniforms.binding(), ) { + let texture_view_dimension: Option = skybox_image + .texture_view_descriptor + .as_ref() + .and_then(|desc| desc.dimension); + if texture_view_dimension != Some(TextureViewDimension::Cube) { + // The texture view is not a cubemap and will fail validation if rendered. + // In this case, we ignore the skybox so as not to break rendering. + // + // There are other possible misconfigurations which will fail and which we do not + // catch here, but this is a common mistake (passing a 2D image to `Skybox`) and + // also the result of `Skybox::default()` and not overriding the `image`. + warn_once!( + "skybox {entity}'s image {image:?} has texture view dimension \ + {texture_view_dimension:?}, but it must be TextureViewDimension::Cube \ + to render a skybox", + image = skybox.image + ); + continue; + } + 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, + &skybox_image.texture_view, + &skybox_image.sampler, view_uniforms, skybox_uniforms, )),