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 155f465
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 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,12 @@ 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.
// Source: https://math.stackexchange.com/a/1463487
// Won't work with negative scale.
// Note we're only look at the scale, not at shear
fn average_scale_from_transform(transform: mat4x4f) -> f32 {
let scale = vec3f(length(transform[0]), length(transform[1]), length(transform[2]));
let scale = vec3f(length(transform[0].xyz), length(transform[1].xyz), length(transform[2].xyz));
return pow(scale.x * scale.y * scale.z, 0.3333);
}

0 comments on commit 155f465

Please sign in to comment.