Skip to content

Commit

Permalink
add source note and simplify calc of average_scale_from_transform a l…
Browse files Browse the repository at this point in the history
…il bit
  • Loading branch information
Wumpf committed Nov 10, 2023
1 parent 74d5a3f commit b7bf95c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/re_renderer/shader/utils/size.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ fn unresolved_size_to_world(_unresolved_size: f32, camera_distance: f32, auto_si
}

// Determines the scale factor of a matrix
//
// This quite expensive, you may want to precompute this.
fn average_scale_from_transform(transform: mat4x4f) -> f32 {
let scale = vec3f(length(transform[0]), length(transform[1]), length(transform[2]));
// Source: https://math.stackexchange.com/a/1463487
// Won't work with negative scale.
// Note we're only look at the scale, not at shear
let scale = vec3f(length(transform[0].xyz), length(transform[1].xyz), length(transform[2].xyz));
// Get geometric mean
return pow(scale.x * scale.y * scale.z, 0.3333);
}

0 comments on commit b7bf95c

Please sign in to comment.