From 1029f58733aa99f9cdab5ab73edf589ab39b60a1 Mon Sep 17 00:00:00 2001 From: FreddyFunk <27208977+FreddyFunk@users.noreply.github.com> Date: Tue, 16 Jan 2024 20:09:04 +0100 Subject: [PATCH] fix orientation of slice renderer --- src/apps/slice_renderer.rs | 32 +++++++++-------------------- src/apps/slice_renderer_shader.wgsl | 6 ++++-- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/apps/slice_renderer.rs b/src/apps/slice_renderer.rs index e62b7f3..239e02b 100644 --- a/src/apps/slice_renderer.rs +++ b/src/apps/slice_renderer.rs @@ -158,7 +158,7 @@ impl SliceRenderer { ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D3, - sample_type: wgpu::TextureSampleType::Float { filterable: (true) }, + sample_type: wgpu::TextureSampleType::Float { filterable: true }, }, count: None, }, @@ -515,7 +515,6 @@ impl SliceRenderer { #[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)] struct Vertex { position: [f32; 3], - tex_coords: [f32; 2], } impl Vertex { @@ -523,18 +522,11 @@ impl Vertex { wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ - wgpu::VertexAttribute { - offset: 0, - shader_location: 0, - format: wgpu::VertexFormat::Float32x3, - }, - wgpu::VertexAttribute { - offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress, - shader_location: 1, - format: wgpu::VertexFormat::Float32x2, - }, - ], + attributes: &[wgpu::VertexAttribute { + offset: 0, + shader_location: 0, + format: wgpu::VertexFormat::Float32x3, + }], } } } @@ -543,20 +535,16 @@ const VERTICES: &[Vertex] = &[ // wgpu uses the coordinate systems of D3D and Metal // https://github.com/gfx-rs/wgpu#coordinate-systems Vertex { - position: [-1.0, -1.0, 1.0], - tex_coords: [0.0, 1.0], + position: [-1.0, -1.0, 0.0], }, // 0 Vertex { - position: [1.0, -1.0, 1.0], - tex_coords: [1.0, 1.0], + position: [1.0, -1.0, 0.0], }, // 1 Vertex { - position: [1.0, 1.0, 1.0], - tex_coords: [1.0, 0.0], + position: [1.0, 1.0, 0.0], }, // 2 Vertex { - position: [-1.0, 1.0, 1.0], - tex_coords: [0.0, 0.0], + position: [-1.0, 1.0, 0.0], }, // 3 // Vertex { position: [-1.0, -1.0, -1.0] }, // 4 // Vertex { position: [1.0, -1.0, -1.0] }, // 5 diff --git a/src/apps/slice_renderer_shader.wgsl b/src/apps/slice_renderer_shader.wgsl index d61fafb..b0e81d2 100644 --- a/src/apps/slice_renderer_shader.wgsl +++ b/src/apps/slice_renderer_shader.wgsl @@ -5,7 +5,6 @@ var scale_factor: vec3; struct VertexInput { @location(0) position: vec3, - @location(1) tex_coords: vec2, } struct VertexOutput { @@ -18,7 +17,10 @@ fn vs_main( model: VertexInput, ) -> VertexOutput { var out: VertexOutput; - out.tex_coords = 0.5 * vec2(model.position.x, model.position.y) + 0.5; + var tex_coordinates : vec2 = 0.5 * vec2(model.position.x, model.position.y) + 0.5; + // flip axis to to match origin in top left corner + tex_coordinates.y = 1.0f - tex_coordinates.y; + out.tex_coords = tex_coordinates; out.clip_position = vec4(scale_factor * model.position, 1.0); return out; }