1#define_import_path bevy_gaussian_splatting::helpers 3#import bevy_gaussian_splatting::bindings::{ 14 cov3d[0], cov3d[1], cov3d[2], 15 cov3d[1], cov3d[3], cov3d[4], 16 cov3d[2], cov3d[4], cov3d[5], 19 var t = view.view_from_world * vec4<f32>(position, 1.0); 21 let focal = vec2<f32>( 22 view.clip_from_view[0].x * view.viewport.z, 23 view.clip_from_view[1].y * view.viewport.w, 26 let s = 1.0 / (t.z * t.z); 28 focal.x / t.z, 0.0, -(focal.x * t.x) * s, 29 0.0, -focal.y / t.z, (focal.y * t.y) * s, 35 view.view_from_world[0].xyz, 36 view.view_from_world[1].xyz, 37 view.view_from_world[2].xyz, 43 var cov = transpose(T) * transpose(Vrk) * T; 47 return vec3<f32>(cov[0][0], cov[0][1], cov[1][1]); 51fn get_bounding_box_clip( 58 let det = cov2d.x * cov2d.z - cov2d.y * cov2d.y; 59 let trace = cov2d.x + cov2d.z; 60 let mid = 0.5 * trace; 61 let discriminant = max(0.0, mid * mid - det); 63 let term = sqrt(discriminant); 65 let lambda1 = mid + term; 66 let lambda2 = max(mid - term, 0.0); 68 let x_axis_length = sqrt(lambda1); 69 let y_axis_length = sqrt(lambda2); 73 let radius_px = cutoff * max(x_axis_length, y_axis_length); 74 let radius_ndc = vec2<f32>( 75 radius_px / view.viewport.zw, 79 radius_ndc * direction, 80 radius_px * direction, 86 let a = (cov2d.x - cov2d.z) * (cov2d.x - cov2d.z); 87 let b = sqrt(a + 4.0 * cov2d.y * cov2d.y); 88 let major_radius = sqrt((cov2d.x + cov2d.z + b) * 0.5); 89 let minor_radius = sqrt((cov2d.x + cov2d.z - b) * 0.5); 91 let bounds = cutoff * vec2<f32>( 96 let eigvec1 = normalize(vec2<f32>( 100 let eigvec2 = vec2<f32>( 105 let rotation_matrix = transpose( 112 let scaled_vertex = direction * bounds; 113 let rotated_vertex = scaled_vertex * rotation_matrix; 115 let scaling_factor = 1.0 / view.viewport.zw; 116 let ndc_vertex = rotated_vertex * scaling_factor; 126fn intrinsic_matrix() -> mat3x4<f32> { 127 let focal = vec2<f32>( 128 view.clip_from_view[0].x * view.viewport.z / 2.0, 129 view.clip_from_view[1].y * view.viewport.w / 2.0, 132 let Ks = mat3x4<f32>( 133 vec4<f32>(focal.x, 0.0, 0.0, (view.viewport.z - 1.0) / 2.0), 134 vec4<f32>(0.0, focal.y, 0.0, (view.viewport.w - 1.0) / 2.0), 135 vec4<f32>(0.0, 0.0, 0.0, 1.0) 142fn get_rotation_matrix( 151 1.0 - 2.0 * (y * y + z * z), 152 2.0 * (x * y - r * z), 153 2.0 * (x * z + r * y), 155 2.0 * (x * y + r * z), 156 1.0 - 2.0 * (x * x + z * z), 157 2.0 * (y * z - r * x), 159 2.0 * (x * z - r * y), 160 2.0 * (y * z + r * x), 161 1.0 - 2.0 * (x * x + y * y), 170 scale.x * gaussian_uniforms.global_scale, 0.0, 0.0, 171 0.0, scale.y * gaussian_uniforms.global_scale, 0.0, 172 0.0, 0.0, scale.z * gaussian_uniforms.global_scale,