From 47e99c828530db18b85e4f0648170096cfed1f37 Mon Sep 17 00:00:00 2001 From: atlv Date: Sat, 5 Jul 2025 10:40:59 -0400 Subject: [PATCH] move Cubemap stuff alongside CubemapFrusta in bevy_camera::primitives (#19955) # Objective - Make bevy_light possible ## Solution - Move some stuff it needs out of somewhere it cant depend on. Plus it makes sense, cubemap stuff goes next to cubemap stuff. ## Testing - 3d_scene runs Note: no breaking changes thanks to re-exports --- crates/bevy_camera/src/primitives.rs | 57 +++++++++++++++++++++++++++ crates/bevy_pbr/src/render/light.rs | 58 +--------------------------- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/crates/bevy_camera/src/primitives.rs b/crates/bevy_camera/src/primitives.rs index e08422b052..127a2d9c29 100644 --- a/crates/bevy_camera/src/primitives.rs +++ b/crates/bevy_camera/src/primitives.rs @@ -347,6 +347,63 @@ impl Frustum { } } +pub struct CubeMapFace { + pub target: Vec3, + pub up: Vec3, +} + +// Cubemap faces are [+X, -X, +Y, -Y, +Z, -Z], per https://www.w3.org/TR/webgpu/#texture-view-creation +// Note: Cubemap coordinates are left-handed y-up, unlike the rest of Bevy. +// See https://registry.khronos.org/vulkan/specs/1.2/html/chap16.html#_cube_map_face_selection +// +// For each cubemap face, we take care to specify the appropriate target/up axis such that the rendered +// texture using Bevy's right-handed y-up coordinate space matches the expected cubemap face in +// left-handed y-up cubemap coordinates. +pub const CUBE_MAP_FACES: [CubeMapFace; 6] = [ + // +X + CubeMapFace { + target: Vec3::X, + up: Vec3::Y, + }, + // -X + CubeMapFace { + target: Vec3::NEG_X, + up: Vec3::Y, + }, + // +Y + CubeMapFace { + target: Vec3::Y, + up: Vec3::Z, + }, + // -Y + CubeMapFace { + target: Vec3::NEG_Y, + up: Vec3::NEG_Z, + }, + // +Z (with left-handed conventions, pointing forwards) + CubeMapFace { + target: Vec3::NEG_Z, + up: Vec3::Y, + }, + // -Z (with left-handed conventions, pointing backwards) + CubeMapFace { + target: Vec3::Z, + up: Vec3::Y, + }, +]; + +pub fn face_index_to_name(face_index: usize) -> &'static str { + match face_index { + 0 => "+x", + 1 => "-x", + 2 => "+y", + 3 => "-y", + 4 => "+z", + 5 => "-z", + _ => "invalid", + } +} + #[derive(Component, Clone, Debug, Default, Reflect)] #[reflect(Component, Default, Debug, Clone)] pub struct CubemapFrusta { diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index c7d9efbab7..1f36d45fd6 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -2,6 +2,7 @@ use self::assign::ClusterableObjectType; use crate::assign::calculate_cluster_factors; use crate::*; use bevy_asset::UntypedAssetId; +pub use bevy_camera::primitives::{face_index_to_name, CubeMapFace, CUBE_MAP_FACES}; use bevy_color::ColorToComponents; use bevy_core_pipeline::core_3d::{Camera3d, CORE_3D_DEPTH_FORMAT}; use bevy_derive::{Deref, DerefMut}; @@ -585,63 +586,6 @@ pub(crate) fn remove_light_view_entities( } } -pub(crate) struct CubeMapFace { - pub(crate) target: Vec3, - pub(crate) up: Vec3, -} - -// Cubemap faces are [+X, -X, +Y, -Y, +Z, -Z], per https://www.w3.org/TR/webgpu/#texture-view-creation -// Note: Cubemap coordinates are left-handed y-up, unlike the rest of Bevy. -// See https://registry.khronos.org/vulkan/specs/1.2/html/chap16.html#_cube_map_face_selection -// -// For each cubemap face, we take care to specify the appropriate target/up axis such that the rendered -// texture using Bevy's right-handed y-up coordinate space matches the expected cubemap face in -// left-handed y-up cubemap coordinates. -pub(crate) const CUBE_MAP_FACES: [CubeMapFace; 6] = [ - // +X - CubeMapFace { - target: Vec3::X, - up: Vec3::Y, - }, - // -X - CubeMapFace { - target: Vec3::NEG_X, - up: Vec3::Y, - }, - // +Y - CubeMapFace { - target: Vec3::Y, - up: Vec3::Z, - }, - // -Y - CubeMapFace { - target: Vec3::NEG_Y, - up: Vec3::NEG_Z, - }, - // +Z (with left-handed conventions, pointing forwards) - CubeMapFace { - target: Vec3::NEG_Z, - up: Vec3::Y, - }, - // -Z (with left-handed conventions, pointing backwards) - CubeMapFace { - target: Vec3::Z, - up: Vec3::Y, - }, -]; - -fn face_index_to_name(face_index: usize) -> &'static str { - match face_index { - 0 => "+x", - 1 => "-x", - 2 => "+y", - 3 => "-y", - 4 => "+z", - 5 => "-z", - _ => "invalid", - } -} - #[derive(Component)] pub struct ShadowView { pub depth_attachment: DepthAttachment,