1#define_import_path bevy_gaussian_splatting::helpers 3#import bevy_gaussian_splatting::bindings::{ 13 cov3d[0], cov3d[1], cov3d[2], 14 cov3d[1], cov3d[3], cov3d[4], 15 cov3d[2], cov3d[4], cov3d[5], 18 var t = view.view_from_world * vec4<f32>(position, 1.0); 20 let focal = vec2<f32>( 21 view.clip_from_view[0].x * view.viewport.z, 22 view.clip_from_view[1].y * view.viewport.w, 25 let s = 1.0 / (t.z * t.z); 27 focal.x / t.z, 0.0, -(focal.x * t.x) * s, 28 0.0, -focal.y / t.z, (focal.y * t.y) * s, 34 view.view_from_world[0].xyz, 35 view.view_from_world[1].xyz, 36 view.view_from_world[2].xyz, 42 var cov = transpose(T) * transpose(Vrk) * T; 46 return vec3<f32>(cov[0][0], cov[0][1], cov[1][1]); 49fn get_bounding_box_clip( 56 let det = cov2d.x * cov2d.z - cov2d.y * cov2d.y; 57 let trace = cov2d.x + cov2d.z; 58 let mid = 0.5 * trace; 59 let discriminant = max(0.0, mid * mid - det); 61 let term = sqrt(discriminant); 63 let lambda1 = mid + term; 64 let lambda2 = max(mid - term, 0.0); 66 let x_axis_length = sqrt(lambda1); 67 let y_axis_length = sqrt(lambda2); 70 let radius_px = cutoff * max(x_axis_length, y_axis_length); 71 let radius_ndc = vec2<f32>( 72 radius_px / view.viewport.zw, 76 radius_ndc * direction, 77 radius_px * direction, 83 let a = (cov2d.x - cov2d.z) * (cov2d.x - cov2d.z); 84 let b = sqrt(a + 4.0 * cov2d.y * cov2d.y); 85 let major_radius = sqrt((cov2d.x + cov2d.z + b) * 0.5); 86 let minor_radius = sqrt((cov2d.x + cov2d.z - b) * 0.5); 88 let bounds = cutoff * vec2<f32>( 93 let eigvec1 = normalize(vec2<f32>( 97 let eigvec2 = vec2<f32>( 102 let rotation_matrix = transpose( 109 let scaled_vertex = direction * bounds; 110 let rotated_vertex = scaled_vertex * rotation_matrix; 112 let scaling_factor = 1.0 / view.viewport.zw; 113 let ndc_vertex = rotated_vertex * scaling_factor; 122fn intrinsic_matrix() -> mat3x4<f32> { 123 let focal = vec2<f32>( 124 view.clip_from_view[0].x * view.viewport.z / 2.0, 125 view.clip_from_view[1].y * view.viewport.w / 2.0, 128 let Ks = mat3x4<f32>( 129 vec4<f32>(focal.x, 0.0, 0.0, (view.viewport.z - 1.0) / 2.0), 130 vec4<f32>(0.0, focal.y, 0.0, (view.viewport.w - 1.0) / 2.0), 131 vec4<f32>(0.0, 0.0, 0.0, 1.0) 137fn get_rotation_matrix( 146 1.0 - 2.0 * (y * y + z * z), 147 2.0 * (x * y - r * z), 148 2.0 * (x * z + r * y), 150 2.0 * (x * y + r * z), 151 1.0 - 2.0 * (x * x + z * z), 152 2.0 * (y * z - r * x), 154 2.0 * (x * z - r * y), 155 2.0 * (y * z + r * x), 156 1.0 - 2.0 * (x * x + y * y), 164 scale.x * gaussian_uniforms.global_scale, 0.0, 0.0, 165 0.0, scale.y * gaussian_uniforms.global_scale, 0.0, 166 0.0, 0.0, scale.z * gaussian_uniforms.global_scale,