<p>I've figured it out. It's bug in wgpu, if I use OpenGL backend everything is ok. The problem only occurs when using Vulkan.</p>

CC BY-SA 4.0
2023-09-25T07:22:09.407Z
What makes you so sure that it is a bug? Do you have a related bug report that you can share? Such artifacts can be caused by many things, for example, rounding of numbers. 2 APIs (Vulkan and OGL) might come to different valid results because they process things in a different order or they use different algorithms for the same thing. Doesn't mean it's a bug.
wychmaster
CC BY-SA 4.0
2023-09-23T10:12:38.200Z
2023-09-23T10:12:38.200Z
Josef Blažek
<p>I am trying to make Terraria like game using WGPU and rust. There are gaps between tiles. The gaps are bigger and more common as I get far from world center. I've read that nearest filtering should help, hovewer I am already using it.</p>
<p><a href="https://i.sstatic.net/yXKW6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yXKW6.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/ksEIv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ksEIv.png" alt="enter image description here" /></a></p>
<p>This is my code for calculating tile positions:</p>
<pre><code>glam::vec3(                            
    self.world_center.x + chunk_size * 
    (chunk.coords.0 as f32) - 
    chunk_size / 2.0 + self.block_size 
    / 2.0 + self.block_size * (x as 
    f32),
    self.world_center.y + chunk_size * 
    (chunk.coords.1 as f32) - 
    chunk_size / 2.0 + self.block_size 
    / 2.0 + self.block_size * (y as 
    f32),
    0.0,
)
</code></pre>
<p>x and y is a position of a tile in a  chunk. Tile (0, 0) is on the bottom left.</p>
<p>Thanks for your response!</p>

CC BY-SA 4.0
2023-09-21T10:14:05.050Z
can you discribe how you calculate the positions of your tiles? Maybe code would help to understand what happens
Thomas
CC BY-SA 4.0
2023-09-21T16:58:44.373Z
Oh, sorry. It's already there.
Josef Blažek
CC BY-SA 4.0
2023-09-22T07:46:40.913Z
Does this problem occur only vertically? If so, please check if your tile has the same number of pixels in x and y direction. At the moment I would say that the number of pixels in x-direction is smaller than the number of pixels in y-direction.
Thomas
CC BY-SA 4.0
2023-09-23T08:34:31.787Z
It also occurs horizontally. The player is just not far enough from the world center on a Y axis to see it.
Josef Blažek
CC BY-SA 4.0
2023-09-25T07:29:44.923Z
Since you are using floats (`f32`), I would suggest that you round all resulting numbers up (`ceil` function) and see if that makes a difference. Another usual (and better) trick is to add "a half-pixel" size and then use the default rounding function.
wychmaster
<texture><2d-graphics><tile-based-rendering>
Random spaces between textures
Josef Blažek
# Random spaces between textures

(Asked by: username_0 on 2023-09-20)

I am trying to make Terraria like game using WGPU and rust. There are gaps between tiles. The gaps are bigger and more common as I get far from world center. I've read that nearest filtering should help, hovewer I am already using it.

[![enter image description here](https://i.sstatic.net/yXKW6.png)](https://i.sstatic.net/yXKW6.png)
[![enter image description here](https://i.sstatic.net/ksEIv.png)](https://i.sstatic.net/ksEIv.png)

This is my code for calculating tile positions:

```
glam::vec3(                            
    self.world_center.x + chunk_size * 
    (chunk.coords.0 as f32) - 
    chunk_size / 2.0 + self.block_size 
    / 2.0 + self.block_size * (x as 
    f32),
    self.world_center.y + chunk_size * 
    (chunk.coords.1 as f32) - 
    chunk_size / 2.0 + self.block_size 
    / 2.0 + self.block_size * (y as 
    f32),
    0.0,
)

```

x and y is a position of a tile in a chunk. Tile (0, 0) is on the bottom left.

Thanks for your response!

**Tags:** texture, 2d-graphics, tile-based-rendering

> **Comments:**
> **username_1**: can you discribe how you calculate the positions of your tiles? Maybe code would help to understand what happens  
> **username_0**: Oh, sorry. It's already there.  
> **username_1**: Does this problem occur only vertically? If so, please check if your tile has the same number of pixels in x and y direction. At the moment I would say that the number of pixels in x-direction is smaller than the number of pixels in y-direction.  
> **username_0**: It also occurs horizontally. The player is just not far enough from the world center on a Y axis to see it.  
> **username_2**: Since you are using floats (`f32`), I would suggest that you round all resulting numbers up (`ceil` function) and see if that makes a difference. Another usual (and better) trick is to add "a half-pixel" size and then use the default rounding function.  

---

## 1 answers

### Answer by username_0 on 2023-09-23. Score: 0

I've figured it out. It's bug in wgpu, if I use OpenGL backend everything is ok. The problem only occurs when using Vulkan.

> **Comments:**
> **username_2**: What makes you so sure that it is a bug? Do you have a related bug report that you can share? Such artifacts can be caused by many things, for example, rounding of numbers. 2 APIs (Vulkan and OGL) might come to different valid results because they process things in a different order or they use different algorithms for the same thing. Doesn't mean it's a bug.  

---

