diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 00bf0fa81d3a13..2c96b407eb984f 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -1222,7 +1222,7 @@ pub(crate) fn assign_lights_to_clusters( let view_inv_scale = camera_transform.compute_transform().scale.recip(); let view_inv_scale_max = view_inv_scale.abs().max_element(); let inverse_view_transform = view_transform.inverse(); - let is_orthographic = camera.projection_matrix().w_axis.w == 1.0; + let is_orthographic = camera.projection_matrix_unchecked().w_axis.w == 1.0; let far_z = match config.far_z_mode() { ClusterFarZMode::MaxLightRange => { @@ -1248,7 +1248,8 @@ pub(crate) fn assign_lights_to_clusters( // 3,2 = r * far and 2,2 = r where r = 1.0 / (far - near) // rearranging r = 1.0 / (far - near), r * (far - near) = 1.0, r * far - 1.0 = r * near, near = (r * far - 1.0) / r // = (3,2 - 1.0) / 2,2 - (camera.projection_matrix().w_axis.z - 1.0) / camera.projection_matrix().z_axis.z + (camera.projection_matrix_unchecked().w_axis.z - 1.0) + / camera.projection_matrix_unchecked().z_axis.z } (false, 1) => config.first_slice_depth().max(far_z), _ => config.first_slice_depth(), @@ -1280,7 +1281,7 @@ pub(crate) fn assign_lights_to_clusters( let (light_aabb_min, light_aabb_max) = cluster_space_light_aabb( inverse_view_transform, view_inv_scale, - camera.projection_matrix(), + camera.projection_matrix_unchecked(), &light_sphere, ); @@ -1346,7 +1347,7 @@ pub(crate) fn assign_lights_to_clusters( clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z <= 4096 ); - let inverse_projection = camera.projection_matrix().inverse(); + let inverse_projection = camera.projection_matrix_unchecked().inverse(); for lights in &mut clusters.lights { lights.entities.clear(); @@ -1443,7 +1444,7 @@ pub(crate) fn assign_lights_to_clusters( cluster_space_light_aabb( inverse_view_transform, view_inv_scale, - camera.projection_matrix(), + camera.projection_matrix_unchecked(), &light_sphere, ); @@ -1486,7 +1487,7 @@ pub(crate) fn assign_lights_to_clusters( ) }); let light_center_clip = - camera.projection_matrix() * view_light_sphere.center.extend(1.0); + camera.projection_matrix_unchecked() * view_light_sphere.center.extend(1.0); let light_center_ndc = light_center_clip.xyz() / light_center_clip.w; let cluster_coordinates = ndc_position_to_cluster( clusters.dimensions, diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 7a1b831f8ec154..7c9b7e262c7b00 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -213,7 +213,7 @@ pub fn update_previous_view_data( let inverse_view = camera_transform.compute_matrix().inverse(); commands.entity(entity).try_insert(PreviousViewData { inverse_view, - view_proj: camera.projection_matrix() * inverse_view, + view_proj: camera.projection_matrix_unchecked() * inverse_view, }); } } diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 0904105b2ea52a..1d348b9c441736 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -349,12 +349,12 @@ impl Camera { /// The projection matrix computed using this camera's [`CameraProjection`]. #[inline] - pub fn projection_matrix(&self) -> Mat4 { + pub fn projection_matrix_unchecked(&self) -> Mat4 { self.computed.projection_matrix.unwrap_or_default() } #[inline] - fn checked_projection_matrix(&self) -> Result { + fn projection_matrix(&self) -> Result { let projection_matrix = self .computed .projection_matrix @@ -443,7 +443,7 @@ impl Camera { let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform) .map_err(ViewportToWorldError::CameraTransformNotFinite)?; let projection_matrix = self - .checked_projection_matrix() + .projection_matrix() .map_err(ViewportToWorldError::ProjectionMatrixNotFinite)?; let ndc_to_world = camera_transform_matrix * projection_matrix.inverse(); @@ -505,7 +505,7 @@ impl Camera { .map_err(WorldToNdcError::CameraTransformNotFinite)?; let projection_matrix = self - .checked_projection_matrix() + .projection_matrix() .map_err(WorldToNdcError::ProjectionMatrixNotFinite)?; // Build a transformation matrix to convert from world space to NDC using camera data @@ -537,7 +537,7 @@ impl Camera { .map_err(NdcToWorldError::CameraTransformNotFinite)?; let projection_matrix = self - .checked_projection_matrix() + .projection_matrix() .map_err(NdcToWorldError::ProjectionMatrixNotFinite)?; // Build a transformation matrix to convert from NDC to world space using camera data @@ -1037,7 +1037,7 @@ pub fn extract_cameras( .unwrap_or_else(|| Exposure::default().exposure()), }, ExtractedView { - projection: camera.projection_matrix(), + projection: camera.projection_matrix_unchecked(), transform: *transform, view_projection: None, hdr: camera.hdr,