diff --git a/mp_elements/image.png b/mp_elements/image.png index df1c11d..638423d 100644 Binary files a/mp_elements/image.png and b/mp_elements/image.png differ diff --git a/mp_elements/shaders/ppi.wgsl b/mp_elements/shaders/ppi.wgsl index a7a1048..9d2d22a 100644 --- a/mp_elements/shaders/ppi.wgsl +++ b/mp_elements/shaders/ppi.wgsl @@ -22,24 +22,24 @@ struct UniformParams { struct VertexOutput { @builtin(position) position: vec4f, - @location(0) r_range: vec2f, + @location(0) r_range: vec4f, @location(1) idx: u32 } @vertex fn vertex( - @location(0) position: vec3f, - @location(1) r_range: vec2f, - @location(2) idx: u32 + @location(0) position: vec4f, + @location(1) r_range: vec4f, + // @location(2) idx: u32 ) -> VertexOutput { var out: VertexOutput; // Transform position // out.position = common_tools.proj_matrix * common_tools.view_matrix * common_tools.model_matrix * vec4f(position, 1.0); - out.position = vec4(position, 1.0); + out.position = vec4(position.xyz, 1.0); out.r_range = r_range; - out.idx = idx; + out.idx = 0u; return out; } @@ -68,6 +68,6 @@ fn fragment(input: VertexOutput) -> @location(0) vec4f { // let is_outside = outside_lower_bound + outside_upper_bound; // color.a *= 1.0 - is_outside; - return color; + return vec4(r,r,r,r); } diff --git a/mp_elements/src/app.rs b/mp_elements/src/app.rs index b0afb45..c90937c 100644 --- a/mp_elements/src/app.rs +++ b/mp_elements/src/app.rs @@ -46,7 +46,10 @@ impl App { // Request a device and a queue from the adapter. The device is the handle to the GPU, and the queue is used to submit commands to the GPU. let (device, queue) = adapter - .request_device(&Default::default(), None) + .request_device(&wgpu::DeviceDescriptor{ + required_features: wgpu::Features::POLYGON_MODE_LINE, + ..Default::default() + }, None) .await .unwrap(); @@ -404,11 +407,14 @@ mod test { use super::*; #[test] fn test_app() { - let plugin_manager = PluginManager::new(r#"/Users/tsuki/projects/mp/loaders"#).unwrap(); + let plugin_manager = PluginManager::new( + // r#"/Users/tsuki/projects/mp/loaders"# + r#"C:\Users\qwin7\projects\radarmp\loaders"# + ).unwrap(); let data = plugin_manager.try_load_data( - "/Users/tsuki/Desktop/Z_RADR_I_X5775_20230726180000_O_DOR-XPD-CAP-FMT.BIN.zip", - // r#"C:\Users\qwin7\Downloads\ZJSXAA_20230113070200_R.dat.gz"#, + // "/Users/tsuki/Desktop/Z_RADR_I_X5775_20230726180000_O_DOR-XPD-CAP-FMT.BIN.zip", + r#"C:\Users\qwin7\Downloads\ZJSXAA_20230113070200_R.dat.gz"#, ); pollster::block_on(async { diff --git a/mp_elements/src/elements/ppi.rs b/mp_elements/src/elements/ppi.rs index d59ea11..451da8c 100644 --- a/mp_elements/src/elements/ppi.rs +++ b/mp_elements/src/elements/ppi.rs @@ -29,9 +29,9 @@ pub struct PPIUniform { #[repr(C)] #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] pub struct PPIVertex { - position: Vec3, - r_ranges: [f32; 2], - idx: u32, + position: Vec4, + r_ranges: [f32; 4], + // idx: u32, } impl PPIVertex { @@ -43,18 +43,18 @@ impl PPIVertex { wgpu::VertexAttribute { offset: 0, shader_location: 0, - format: wgpu::VertexFormat::Float32x3, + format: wgpu::VertexFormat::Float32x4, }, wgpu::VertexAttribute { - offset: std::mem::size_of::() as wgpu::BufferAddress, + offset: std::mem::size_of::() as wgpu::BufferAddress, shader_location: 1, - format: wgpu::VertexFormat::Float32x2, - }, - wgpu::VertexAttribute { - offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress, - shader_location: 2, - format: wgpu::VertexFormat::Uint32, + format: wgpu::VertexFormat::Float32x4, }, + // wgpu::VertexAttribute { + // offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress, + // shader_location: 2, + // format: wgpu::VertexFormat::Uint32, + // }, ], } } @@ -135,7 +135,7 @@ impl Element for PPI { strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: None, - polygon_mode: wgpu::PolygonMode::Fill, + polygon_mode: wgpu::PolygonMode::Line, unclipped_depth: false, conservative: false, }, @@ -166,7 +166,7 @@ impl Element for PPI { } = coord_typ { let e = elevation.map(|v| *v.first().unwrap_or(&0.0)).unwrap_or(0.0); - let (vertices, indices) = Self::bake_vi(e, azimuth, &range); + let (vertices, indices) = Self::bake_vi(e as f32, azimuth, &range); (vertices, Some(indices)) } else { @@ -189,6 +189,7 @@ impl Element for PPI { buffer_pool: &mut DataBufferPool, ) -> ElementAttach { let (vertex, index) = self.bake(data); + println!("index: {:?}", &(index.as_ref()).unwrap()[0..24]); let device = &ctx.device; let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -257,7 +258,8 @@ impl Element for PPI { impl PPI { fn init_shader(device: &wgpu::Device) -> wgpu::ShaderModule { - let shader_str = merge_shader(r#"/Users/tsuki/projects/mp/mp_elements/shaders/ppi.wgsl"#); + // let shader_str = merge_shader(r#"/Users/tsuki/projects/mp/mp_elements/shaders/ppi.wgsl"#); + let shader_str = merge_shader(r#"C:\Users\qwin7\projects\radarmp\mp_elements\shaders\ppi.wgsl"#); let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("PPI Shader Module"), source: wgpu::ShaderSource::Wgsl(shader_str.into()), @@ -274,7 +276,7 @@ impl PPI { BufferKey::new(key_name) } - fn bake_vi(e: f64, a: &Vec, r: &Vec) -> (Vec, Vec) { + fn bake_vi(e: f32, a: &Vec, r: &Vec) -> (Vec, Vec) { // Sort azimuth let mut sorted_azimuth = a.clone(); sorted_azimuth.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Greater)); @@ -283,40 +285,43 @@ impl PPI { let azi_step = max_step(&sorted_azimuth, f64::MIN) / 2.0; let r_step = min_step(&r, f64::MAX) / (r[r.len() - 1]) / 2.0; let r_step_f32 = r_step as f32; + let r_max = r[r.len() - 1] as f32; // One cell has 4 vertices let mut vertexs = Vec::with_capacity(a.len() * r.len() * 4); for (a_idx, _a) in sorted_azimuth.into_iter().enumerate() { for (r_idx, _r) in r.iter().enumerate() { - let r_ranges = [*_r as f32 - r_step_f32, *_r as f32 + r_step_f32]; + + let cr = *_r as f32 / r_max; + let r_ranges = [cr - r_step_f32, cr + r_step_f32, 0.0, 0.0]; let idx = (a_idx * r.len() + r_idx) as u32; // Left Top - let lt = polar_to_cartesian(*_r + r_step, _a - azi_step, e); + let lt = polar_to_cartesian(cr + r_step_f32, (_a - azi_step) as f32, e); vertexs.push(PPIVertex { - position: Vec3::new(lt.0, lt.1, lt.2), + position: Vec4::new(lt.0, lt.1, lt.2,0.0), r_ranges, - idx, + // idx, }); // Left Bot - let lb = polar_to_cartesian(*_r - r_step, _a - azi_step, e); + let lb = polar_to_cartesian(cr - r_step_f32, (_a - azi_step) as f32, e); vertexs.push(PPIVertex { - position: Vec3::new(lb.0, lb.1, lb.2), + position: Vec4::new(lb.0, lb.1, lb.2,0.0), r_ranges, - idx, + // idx, }); // Right Top - let rt = polar_to_cartesian(*_r + r_step, _a + azi_step, e); + let rt = polar_to_cartesian(cr + r_step_f32, (_a + azi_step) as f32, e); vertexs.push(PPIVertex { - position: Vec3::new(rt.0, rt.1, rt.2), + position: Vec4::new(rt.0, rt.1, rt.2,0.0), r_ranges, - idx, + // idx, }); // Right Bot - let rb = polar_to_cartesian(*_r - r_step, _a + azi_step, e); + let rb = polar_to_cartesian(cr - r_step_f32, (_a + azi_step) as f32, e); vertexs.push(PPIVertex { - position: Vec3::new(rb.0, rb.1, rb.2), + position: Vec4::new(rb.0, rb.1, rb.2,0.0), r_ranges, - idx, + // idx, }); } } @@ -325,13 +330,14 @@ impl PPI { let mut indice_buffer = Vec::with_capacity(a.len() * r.len() * 6); for i in 0..a.len() * r.len() { - indice_buffer.push(i as u32 * 4); - indice_buffer.push(i as u32 * 4 + 1); - indice_buffer.push(i as u32 * 4 + 2); + let start = (i * 2) as u32; + indice_buffer.push(start); + indice_buffer.push(start + 1); + indice_buffer.push(start + 2); - indice_buffer.push(i as u32 * 4 + 1); - indice_buffer.push(i as u32 * 4 + 3); - indice_buffer.push(i as u32 * 4 + 2); + indice_buffer.push(start + 2); + indice_buffer.push(start + 1); + indice_buffer.push(start + 3); } return (vertexs, indice_buffer); @@ -372,9 +378,9 @@ where return max_gap; } -fn polar_to_cartesian(r: f64, azimuth: f64, elevation: f64) -> (f32, f32, f32) { +fn polar_to_cartesian(r: f32, azimuth: f32, elevation: f32) -> (f32, f32, f32) { let x = r * azimuth.cos() * elevation.cos(); let y = r * azimuth.sin() * elevation.cos(); let z = r * elevation.sin(); - (x as f32, y as f32, z as f32) + (x, y, z ) } diff --git a/mp_elements/src/utils.rs b/mp_elements/src/utils.rs index 128562e..cd675c8 100644 --- a/mp_elements/src/utils.rs +++ b/mp_elements/src/utils.rs @@ -33,7 +33,8 @@ struct UniformCommonTools { Ok(path) => path.parent().unwrap().to_owned(), Err(e) => { // panic!("Failed to canonicalize path: {}", e); - PathBuf::from(r#"/Users/tsuki/projects/mp/mp_elements/shaders"#) + // PathBuf::from(r#"/Users/tsuki/projects/mp/mp_elements/shaders"#) + PathBuf::from(r#"C:\Users\qwin7\projects\radarmp\mp_elements\shaders"#) } };