diff --git a/src/render/shaders/mod.rs b/src/render/shaders/mod.rs index 17495153..315d19be 100644 --- a/src/render/shaders/mod.rs +++ b/src/render/shaders/mod.rs @@ -76,16 +76,19 @@ pub mod tile { array_stride: std::mem::size_of::() as u64, step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ + // position wgpu::VertexAttribute { offset: 0, format: wgpu::VertexFormat::Float32x2, shader_location: 0, }, + // normal wgpu::VertexAttribute { offset: wgpu::VertexFormat::Float32x2.size(), format: wgpu::VertexFormat::Float32x2, shader_location: 1, }, + // tile_id wgpu::VertexAttribute { offset: 2 * wgpu::VertexFormat::Float32x2.size(), format: wgpu::VertexFormat::Uint32, diff --git a/src/render/shaders/tile.vertex.wgsl b/src/render/shaders/tile.vertex.wgsl index 50d6cedb..2d004048 100644 --- a/src/render/shaders/tile.vertex.wgsl +++ b/src/render/shaders/tile.vertex.wgsl @@ -33,7 +33,8 @@ fn main( ) -> VertexOutput { let z = 0.0; - let world_pos = position + translate + normal; + // position the anchor of a tile at the top left, instead of bottom right + let world_pos = vec2(1.0, -1.0) * (position + normal * 3.0) + translate; let position = globals.camera.view_proj * vec4(world_pos, z, 1.0); diff --git a/src/render/state.rs b/src/render/state.rs index 9f9d6f8d..3dd481fb 100644 --- a/src/render/state.rs +++ b/src/render/state.rs @@ -162,17 +162,16 @@ impl State { let instances = [ // Step 1 - MaskInstanceUniform::new([0.0, 0.0], 4.0, 4.0, [1.0, 0.0, 0.0, 1.0]), // horizontal - //MaskInstanceUniform::new([0.0, 2.0 * 4096.0], 4.0, 1.0, [1.0, 0.0, 0.0, 1.0]), // vertical + MaskInstanceUniform::new([0.0, 0.0], 4.0, -4.0, [1.0, 0.0, 0.0, 1.0]), // horizontal // Step 2 - MaskInstanceUniform::new([1.0 * 4096.0, 0.0], 1.0, 4.0, [0.0, 1.0, 0.0, 1.0]), // vertical - MaskInstanceUniform::new([3.0 * 4096.0, 0.0], 1.0, 4.0, [0.0, 1.0, 0.0, 1.0]), // vertical + MaskInstanceUniform::new([1.0 * 4096.0, 0.0], 1.0, -4.0, [0.0, 1.0, 0.0, 1.0]), // vertical + MaskInstanceUniform::new([3.0 * 4096.0, 0.0], 1.0, -4.0, [0.0, 1.0, 0.0, 1.0]), // vertical // Step 3 - MaskInstanceUniform::new([0.0, 1.0 * 4096.0], 4.0, 1.0, [0.0, 0.0, 1.0, 1.0]), // horizontal - MaskInstanceUniform::new([0.0, 3.0 * 4096.0], 4.0, 1.0, [0.0, 0.0, 1.0, 1.0]), // horizontal + MaskInstanceUniform::new([0.0, -1.0 * 4096.0], 4.0, 1.0, [0.0, 0.0, 1.0, 1.0]), // horizontal + MaskInstanceUniform::new([0.0, -3.0 * 4096.0], 4.0, 1.0, [0.0, 0.0, 1.0, 1.0]), // horizontal // Step 4 - MaskInstanceUniform::new([1.0 * 4096.0, 0.0], 1.0, 4.0, [0.5, 0.25, 0.5, 1.0]), // vertical - MaskInstanceUniform::new([3.0 * 4096.0, 0.0], 1.0, 4.0, [0.5, 0.25, 0.5, 1.0]), // vertical + MaskInstanceUniform::new([1.0 * 4096.0, 0.0], 1.0, -4.0, [0.5, 0.25, 0.5, 1.0]), // vertical + MaskInstanceUniform::new([3.0 * 4096.0, 0.0], 1.0, -4.0, [0.5, 0.25, 0.5, 1.0]), // vertical ]; let tile_mask_instances = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -382,7 +381,10 @@ impl State { let uniform = TileUniform::new( [0.0, 0.0, 0.0, 1.0], - [new_coords.x as f32 * 4096.0, new_coords.y as f32 * 4096.0], + [ + new_coords.x as f32 * 4096.0, + -1.0 * new_coords.y as f32 * 4096.0, // FIXME: Improve conversion to world tile coordinates + ], ); self.queue.write_buffer( &self.tiles_uniform_buffer, @@ -458,15 +460,19 @@ impl State { // Draw masks pass.set_pipeline(&self.mask_pipeline); pass.set_vertex_buffer(0, self.tile_mask_instances.slice(..)); - // Draw 11 squares each out of 6 vertices + // Draw 7 squares each out of 6 vertices pass.draw(0..6, 0..7); } { for entry in self.buffer_pool.available_vertices() { let TileCoords { x, y, .. } = entry.coords; + // FIXME: Improve conversion + let world_x = x as i32 - MUNICH_OFFSET_X as i32; + let world_y = y as i32 - MUNICH_OFFSET_Y as i32 * -1; + pass.set_pipeline(&self.render_pipeline); - let reference = match (x, y) { + let reference = match (world_x, world_y) { (x, y) if x % 2 == 0 && y % 2 == 0 => 1, (x, y) if x % 2 == 0 && y % 2 != 0 => 2, (x, y) if x % 2 != 0 && y % 2 == 0 => 3,