diff --git a/src/main.rs b/src/main.rs index 8f01c38..fd8ae4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -367,6 +367,10 @@ fn load_model() -> MeshData { m.mesh.positions[t + 2], -m.mesh.positions[t + 1], ], + tex_coords: [ + m.mesh.texcoords[i * 2], + m.mesh.texcoords[i * 2 + 1], + ], }); } @@ -479,8 +483,8 @@ fn main() { let mut camera = Flycam::new(10.0, 0.002); let mut is_grabbed = false; let mut ren = pollster::block_on(Renderer::new(&window)); - let mut state: Box = Box::new(Planets::new(&mut ren)); - // let mut state: Box = Box::new(Grid::new(&mut ren)); + // let mut state: Box = Box::new(Planets::new(&mut ren)); + let mut state: Box = Box::new(Grid::new(&mut ren)); event_loop.run(move |event, _, control_flow| match event { Event::RedrawRequested(_) => match ren.render(&camera, &state.render()) { diff --git a/src/mesh.rs b/src/mesh.rs index b3f91e6..1fccd7b 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -2,6 +2,7 @@ #[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] pub struct Vertex { pub position: [f32; 3], + pub tex_coords: [f32; 2], } impl Vertex { @@ -9,11 +10,18 @@ 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, - }], + 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, + }, + ], } } } diff --git a/src/shader.wgsl b/src/shader.wgsl index 19f500f..95a0cc3 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -12,10 +12,12 @@ struct MeshData { struct VertexInput { [[location(0)]] position: vec3; + [[location(1)]] tex_coords: vec2; }; struct VertexOutput { [[builtin(position)]] clip_position: vec4; + [[location(0)]] color: vec3; }; [[group(0), binding(0)]] @@ -32,6 +34,7 @@ fn vs_main( let transform = meshes.instances[mesh_idx].transform; var out: VertexOutput; out.clip_position = camera.vp * transform * vec4(vertex.position, 1.0); + out.color = vec3(vertex.tex_coords, 0.0); return out; } @@ -39,5 +42,5 @@ fn vs_main( fn fs_main( frag: VertexOutput, ) -> [[location(0)]] vec4 { - return vec4(1.0); + return vec4(frag.color, 1.0); }