Skip to content

rename GlobalTransform::compute_matrix to to_matrix #19643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2025
Merged
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
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/atmosphere/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ pub(super) fn prepare_atmosphere_transforms(
};

for (entity, view) in &views {
let world_from_view = view.world_from_view.compute_matrix();
let world_from_view = view.world_from_view.to_matrix();
let camera_z = world_from_view.z_axis.truncate();
let camera_y = world_from_view.y_axis.truncate();
let atmo_z = camera_z
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/cluster/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub(crate) fn assign_objects_to_clusters(

let mut requested_cluster_dimensions = config.dimensions_for_screen_size(screen_size);

let world_from_view = camera_transform.compute_matrix();
let world_from_view = camera_transform.to_matrix();
let view_from_world_scale = camera_transform.compute_transform().scale.recip();
let view_from_world_scale_max = view_from_world_scale.abs().max_element();
let view_from_world = world_from_view.inverse();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/light/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ pub fn build_directional_light_cascades(
.iter()
.filter_map(|(entity, transform, projection, camera)| {
if camera.is_active {
Some((entity, projection, transform.compute_matrix()))
Some((entity, projection, transform.to_matrix()))
} else {
None
}
Expand All @@ -357,7 +357,7 @@ pub fn build_directional_light_cascades(
// light_to_world has orthogonal upper-left 3x3 and zero translation.
// Even though only the direction (i.e. rotation) of the light matters, we don't constrain
// users to not change any other aspects of the transform - there's no guarantee
// `transform.compute_matrix()` will give us a matrix with our desired properties.
// `transform.to_matrix()` will give us a matrix with our desired properties.
// Instead, we directly create a good matrix from just the rotation.
let world_from_light = Mat4::from_quat(transform.compute_transform().rotation);
let light_to_world_inverse = world_from_light.inverse();
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light_probe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ where
) -> Option<LightProbeInfo<C>> {
environment_map.id(image_assets).map(|id| LightProbeInfo {
world_from_light: light_probe_transform.affine(),
light_from_world: light_probe_transform.compute_matrix().inverse(),
light_from_world: light_probe_transform.to_matrix().inverse(),
asset_id: id,
intensity: environment_map.intensity(),
affects_lightmapped_mesh_diffuse: environment_map.affects_lightmapped_mesh_diffuse(),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn update_previous_view_data(
query: Query<(Entity, &Camera, &GlobalTransform), Or<(With<Camera3d>, With<ShadowView>)>>,
) {
for (entity, camera, camera_transform) in &query {
let world_from_view = camera_transform.compute_matrix();
let world_from_view = camera_transform.to_matrix();
let view_from_world = world_from_view.inverse();
let view_from_clip = camera.clip_from_view().inverse();

Expand Down Expand Up @@ -703,7 +703,7 @@ pub fn prepare_previous_view_uniforms(
let prev_view_data = match maybe_previous_view_uniforms {
Some(previous_view) => previous_view.clone(),
None => {
let world_from_view = camera.world_from_view.compute_matrix();
let world_from_view = camera.world_from_view.to_matrix();
let view_from_world = world_from_view.inverse();
let view_from_clip = camera.clip_from_view.inverse();

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/volumetric_fog/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ pub fn prepare_volumetric_fog_uniforms(
// Do this up front to avoid O(n^2) matrix inversion.
local_from_world_matrices.clear();
for (_, _, fog_transform) in fog_volumes.iter() {
local_from_world_matrices.push(fog_transform.compute_matrix().inverse());
local_from_world_matrices.push(fog_transform.to_matrix().inverse());
}

let uniform_count = view_targets.iter().len() * local_from_world_matrices.len();
Expand All @@ -712,7 +712,7 @@ pub fn prepare_volumetric_fog_uniforms(
};

for (view_entity, extracted_view, volumetric_fog) in view_targets.iter() {
let world_from_view = extracted_view.world_from_view.compute_matrix();
let world_from_view = extracted_view.world_from_view.to_matrix();

let mut view_fog_volumes = vec![];

Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_simple() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals = None;
let indices: Option<&[u16]> = None;
Expand All @@ -338,7 +338,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_indices() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals = None;
let indices: Option<&[u16]> = Some(&[0, 1, 2]);
Expand All @@ -359,7 +359,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_indices_vertex_normals() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals: Option<&[[f32; 3]]> =
Some(&[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]);
Expand All @@ -381,7 +381,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_vertex_normals() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals: Option<&[[f32; 3]]> =
Some(&[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]);
Expand All @@ -403,7 +403,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_missing_vertex_normals() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals: Option<&[[f32; 3]]> = Some(&[]);
let indices: Option<&[u16]> = None;
Expand All @@ -424,7 +424,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_indices_missing_vertex_normals() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals: Option<&[[f32; 3]]> = Some(&[]);
let indices: Option<&[u16]> = Some(&[0, 1, 2]);
Expand All @@ -445,7 +445,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_not_enough_indices() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals = None;
let indices: Option<&[u16]> = Some(&[0]);
Expand All @@ -466,7 +466,7 @@ mod tests {
#[test]
fn ray_mesh_intersection_bad_indices() {
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
let positions = &[V0, V1, V2];
let vertex_normals = None;
let indices: Option<&[u16]> = Some(&[0, 1, 3]);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {
if let Some(distance) = ray_aabb_intersection_3d(
ray,
&Aabb3d::new(aabb.center, aabb.half_extents),
&transform.compute_matrix(),
&transform.to_matrix(),
) {
aabb_hits_tx.send((FloatOrd(distance), entity)).ok();
}
Expand Down Expand Up @@ -287,7 +287,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {

// Perform the actual ray cast.
let _ray_cast_guard = ray_cast_guard.enter();
let transform = transform.compute_matrix();
let transform = transform.to_matrix();
let intersection = ray_intersection_over_mesh(mesh, &transform, ray, backfaces);

if let Some(intersection) = intersection {
Expand Down
8 changes: 3 additions & 5 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@ impl Camera {
rect_relative.y = 1.0 - rect_relative.y;

let ndc = rect_relative * 2. - Vec2::ONE;
let ndc_to_world =
camera_transform.compute_matrix() * self.computed.clip_from_view.inverse();
let ndc_to_world = camera_transform.to_matrix() * self.computed.clip_from_view.inverse();
let world_near_plane = ndc_to_world.project_point3(ndc.extend(1.));
// Using EPSILON because an ndc with Z = 0 returns NaNs.
let world_far_plane = ndc_to_world.project_point3(ndc.extend(f32::EPSILON));
Expand Down Expand Up @@ -668,7 +667,7 @@ impl Camera {
) -> Option<Vec3> {
// Build a transformation matrix to convert from world space to NDC using camera data
let clip_from_world: Mat4 =
self.computed.clip_from_view * camera_transform.compute_matrix().inverse();
self.computed.clip_from_view * camera_transform.to_matrix().inverse();
let ndc_space_coords: Vec3 = clip_from_world.project_point3(world_position);

(!ndc_space_coords.is_nan()).then_some(ndc_space_coords)
Expand All @@ -689,8 +688,7 @@ impl Camera {
/// Will panic if the projection matrix is invalid (has a determinant of 0) and `glam_assert` is enabled.
pub fn ndc_to_world(&self, camera_transform: &GlobalTransform, ndc: Vec3) -> Option<Vec3> {
// Build a transformation matrix to convert from NDC to world space using camera data
let ndc_to_world =
camera_transform.compute_matrix() * self.computed.clip_from_view.inverse();
let ndc_to_world = camera_transform.to_matrix() * self.computed.clip_from_view.inverse();

let world_space_coords = ndc_to_world.project_point3(ndc);

Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_render/src/camera/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ pub trait CameraProjection {
/// This code is called by [`update_frusta`](crate::view::visibility::update_frusta) system
/// for each camera to update its frustum.
fn compute_frustum(&self, camera_transform: &GlobalTransform) -> Frustum {
let clip_from_world =
self.get_clip_from_view() * camera_transform.compute_matrix().inverse();
let clip_from_world = self.get_clip_from_view() * camera_transform.to_matrix().inverse();
Frustum::from_clip_from_world_custom_far(
&clip_from_world,
&camera_transform.translation(),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub struct ExtractedView {
impl ExtractedView {
/// Creates a 3D rangefinder for a view
pub fn rangefinder3d(&self) -> ViewRangefinder3d {
ViewRangefinder3d::from_world_from_view(&self.world_from_view.compute_matrix())
ViewRangefinder3d::from_world_from_view(&self.world_from_view.to_matrix())
}
}

Expand Down Expand Up @@ -934,7 +934,7 @@ pub fn prepare_view_uniforms(
}

let view_from_clip = clip_from_view.inverse();
let world_from_view = extracted_view.world_from_view.compute_matrix();
let world_from_view = extracted_view.world_from_view.to_matrix();
let view_from_world = world_from_view.inverse();

let clip_from_world = if temporal_jitter.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_solari/src/scene/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn prepare_raytracing_scene_bindings(
continue;
};

let transform = transform.compute_matrix();
let transform = transform.to_matrix();
*tlas.get_mut_single(instance_id).unwrap() = Some(TlasInstance::new(
blas,
tlas_transform(&transform),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl GlobalTransform {

/// Returns the 3d affine transformation matrix as a [`Mat4`].
#[inline]
pub fn compute_matrix(&self) -> Mat4 {
pub fn to_matrix(&self) -> Mat4 {
Mat4::from(self.0)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: GlobalTransform::compute_matrix rename
pull_requests: [19643]
---

`GlobalTransform::compute_matrix` has been renamed to `GlobalTransform::to_matrix` because it does not compute anything, it simply moves data into a different type.