Skip to content
Open
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
27 changes: 24 additions & 3 deletions crates/bevy_core_pipeline/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -227,17 +228,37 @@ 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)) = (
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<TextureViewDimension> = 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,
)),
Expand Down