mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Fix world position of tiles
This commit is contained in:
parent
5e47c7c68e
commit
982f6599ac
@ -76,16 +76,19 @@ pub mod tile {
|
||||
array_stride: std::mem::size_of::<GpuVertexUniform>() 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,
|
||||
|
||||
@ -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<f32>(1.0, -1.0) * (position + normal * 3.0) + translate;
|
||||
|
||||
let position = globals.camera.view_proj * vec4<f32>(world_pos, z, 1.0);
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user