Skip to content

Commit

Permalink
fix orientation of slice renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddyFunk committed Jan 16, 2024
1 parent 5595d25 commit 1029f58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
32 changes: 10 additions & 22 deletions src/apps/slice_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -515,26 +515,18 @@ impl SliceRenderer {
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
struct Vertex {
position: [f32; 3],
tex_coords: [f32; 2],
}

impl Vertex {
fn desc() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Self>() 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,
}],
}
}
}
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/apps/slice_renderer_shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var<uniform> scale_factor: vec3<f32>;

struct VertexInput {
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}

struct VertexOutput {
Expand All @@ -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<f32> = 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<f32>(scale_factor * model.position, 1.0);
return out;
}
Expand Down

0 comments on commit 1029f58

Please sign in to comment.