StarArawn / bevy_ecs_tilemap

A tilemap rendering crate for bevy which is more ECS friendly.
MIT License
925 stars 195 forks source link

Sampling issue at certain scales #123

Open timbess opened 2 years ago

timbess commented 2 years ago

I noticed while adjusting the camera's scale that there is an issue with the sampling when zoomed in at different levels. Seems to happen mostly when zoomed out: tilemap_sampling_issue

It seems like this line was an attempt to fix it:

https://github.com/StarArawn/bevy_ecs_tilemap/blob/d7c4f8c8aa7775061f38aaf22bf2040610012f31/src/render/square-tilemap.vert#L113

Back when I tried to implement this myself, this seemed to fix my problem (adding 1px of padding to the textureatlas): https://github.com/bevyengine/bevy/issues/1949#issuecomment-825637328

So I expect the padding calculations done here will fix the bug: https://github.com/bevyengine/bevy/blob/de8edd3165c379e05aabb38359b3f4b97f46540a/crates/bevy_sprite/src/texture_atlas.rs#L125-L159

StarArawn commented 2 years ago

We have existing padding support already. Checkout the tile spacing field here: https://github.com/StarArawn/bevy_ecs_tilemap/blob/main/src/layer.rs#L47

A better solution to this problem is to not rely on texture atlases which are prone to bugs like this. In the far distant future, when I get some time, bevy_ecs_tilemap will no longer support atlases directly and instead internally everything will use a texture array instead. This will allow us to use texture filtering as well as mip maps which will great increase the quality of tilemap rendering when zooming.

timbess commented 2 years ago

@StarArawn Yeah I tried adding padding in that field and it seems to completely mess up the sampling at that point. This is what happens when I add Vec2::new(1.0, 1.0) of spacing. image

StarArawn commented 2 years ago

I would suggest we look at fixing this in the new renderer since it involves only fixing 1 spot. I can try to look at this tonight. 🤔

timbess commented 2 years ago

Thanks! I'll try to look into it too, but I'm a noob with graphics programming and bevy internals for that matter. Very cool what you've done here though, way better than my naive approach when I did it manually.

gerasim13 commented 1 year ago

Screen Recording 2023-07-08 at 00 12 17 I have the same issue