Hello Guest

Author Topic: Bug for TileMap: gap in between tiles  (Read 19990 times)

dbanfield

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Bug for TileMap: gap in between tiles
« on: February 08, 2014, 10:42:05 am »
Hi,
A while ago I posted a problem with small lines in between my tiles when I was using individual sprites and the unity built-in snap to function.

http://2dtoolkit.com/forum/index.php/topic,2368.msg12142.html#msg12142


Since then I've grown older and wiser in the ways of TK2D, and started using the TileMap feature for my game. Everything is going well and I am now enjoying all the advantages of TileMap like easily creating a level rather than labouriously placing sprites, excellent support for colliders, and most importantly no frame rate drops when my levels get big.

Only problem is...


The dreaded lines in between tiles problem has returned  :(

Or rather it never went away. I did notice it when I first started using the tile maps but was hoping some setting would fix it, or that since it was indicated in my previous post it may have been a rounding error, was hoping perhaps rounding the camera position to 2dp would help. No joy.


Attached is an example project where I have managed to narrow down the exact camera position that creates a problem, at a 2dp camera position with the tile map at 0,0,0. I've messed around with settings with no success. 2dp position seems a pretty reasonable accuracy to not expect problems.


I would really appreciate a fix for this since it is pretty much one my last remaining problem in a production worthy build.

Thanks
Dan

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #1 on: February 08, 2014, 03:16:34 pm »
What version of unity are you using, and on what platform? If you're on windows, are you using DX11 or DX9, and also what gfx hardware?

I can't see any lines at all on my MBP (nvidia)

dbanfield

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #2 on: February 08, 2014, 05:37:58 pm »
Thanks for taking a look.

Unity version: 4.3.2f1
tk2d: 2.3.3
platform: Windows 8
DirectX: 9 (I presume, dx11 check box is not enabled)
graphics card: Nvidia GT 740M


I've attached a different variation of the bug example. I've now changed the update functions to simply slowly scroll along the x-axis. Reason being that a strange thing happened: the camera position I had in the previous project didn't show the bug after I performed a build.

However I found the same problem was now at 51.85 (instead of 51.75). Weird.

Basically, press play and watch the camera slowly pan in the game view. Sorry, know it's boring, but within the space of a minute or two you will see a flicker of one of these gaps as it scrolls over the problem coordinate, wherever that may be (this is how I always notice it when I'm test playing my game).


Just to add more weight to the problem, I have deployed this scrolling example to my Nexus 7 and Nexus 5, and both will show the bug occurring at some point.


I think some kind of rounding problem is still the suspect, but no idea how this might be fixed  :'(


* edit * yep, just tested it on my nexus 7 again. Ater about 35s of scrolling I see one, and then there's another 3 or 4 occurrences over the next 20 seconds of scrolling or so.
« Last Edit: February 08, 2014, 05:43:23 pm by dbanfield »

kurayami88

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #3 on: February 09, 2014, 03:59:52 pm »
in your 2dtoolkit atlas > settings ...

filter mode -> don't use bilinear/trilinear... use point...
hope that is the cause of your problems... because software filtering will sort of create alpha along the borders of the sprite.

------

if you are using regular imported texture instead, same thing... in the inspector panel of the texture... try using "point" filtering.


P.S.> point filtering looks like crap most of the time for complex images... if you really need point filtering for your bg but bilinear/trilinear filtering for the rest of your sprites, consider having two atlas (as the atlas setting is universal to all sprites within it... no two way about it that I know of)
« Last Edit: February 09, 2014, 04:06:55 pm by kurayami88 »

Udorn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #4 on: February 09, 2014, 05:30:06 pm »
Hi,

I've the same problems. I tried the point filter and it doesn't change anything. I'll attach images of my settings and the game view with the (blue) gaps between the tiles. I have seen this problem in several projects with different tile textures. There is probably something wrong in how I'm using 2dtk.

kurayami88

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #5 on: February 09, 2014, 06:38:00 pm »
to Udorn,

probably a dumb question.... but...
you did click the "commit" button right? just making sure...

i had issue with the 1~2 ish pixel gap before even though the sprites are tiled side-by-side ( not using 2d toolkit tilemapper though) and point filtering worked for me...

if it doesn't work for you then i got no other suggestions  :(

dbanfield

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #6 on: February 09, 2014, 07:48:38 pm »
Thanks for trying kurayami88, but using point made still didn't fix it.

I also tried point mode without "Extend" on the Sprite, no difference.
Also tried changing the wrap mode, but still nothing.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #7 on: February 09, 2014, 09:41:44 pm »
Hi,

I've the same problems. I tried the point filter and it doesn't change anything. I'll attach images of my settings and the game view with the (blue) gaps between the tiles. I have seen this problem in several projects with different tile textures. There is probably something wrong in how I'm using 2dtk.

Your textures look very much like they have alpha information there. Can you post a repro case?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #8 on: February 10, 2014, 03:04:06 pm »
Thanks for trying kurayami88, but using point made still didn't fix it.

I also tried point mode without "Extend" on the Sprite, no difference.
Also tried changing the wrap mode, but still nothing.

Just had a look at your demo and I saw it a couple times. Some notes -
1. You're using a perspective camera with an arbitrary distance to the tile map. This isn't pixel perfect, and moving by 0.01 is pretty much meaningless. If you use an ortho camera then that will be considerably easier to manage if you care about pixel perfection.

2. The seam seems to correspond to a chunk boundary. This is likely because there is a (very) tiny z offset in each chunk to get Unity to sort them properly. This is normally fine in an ortho camera, but can potentially round differently in a perspective cam. tk2dTileMapBUilderUtil.cs, comment out line 380 tilePosition.z += z; and recommit your tile map. When you click on Chunk 0 0, etc. they should all have position.z = 0. This means that if you need tiles to overlap, eg. for isometric, etc. that won't work any more.

If you use an ortho camera, set pixels per unit to 100, rounding to 0.01 = snapping to pixel.



Udorn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #9 on: February 10, 2014, 04:45:23 pm »
Your textures look very much like they have alpha information there. Can you post a repro case?

It seems that I have fixed my issue. I've rescaled the tile textures to exactly the pixles per meter setting (100), deleted the Tilemap and created a new one. Now the blue gaps are gone. Thanks for your outstanding support.  :)

dbanfield

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #10 on: February 23, 2014, 01:22:06 pm »
Sorry for the delayed reply, it's been a busy couple of weeks.

This must be a perspective camera issue then. I tried using an orthographic camera, and I don't seem to have the issue, as far as I could notice.
Even with the z offset modification though, I am still seeing the bug in perspective camera mode.

I'd really like to be able to use perspective camera as I will be using some decorative environment objects at different distances and didn't want to have to write my own parallax scrolling code.

Maybe it is something to do with my tile map scaling. In perspective camera mode, the technique I use is

  • Create a sprite
  • make it pixel perfect by hitting 1:1
  • This gives me the right scaling ratio to apply to the tile map so that it is pixel perfect for the current camera
  • Apply this scale to the tile map

This makes the tile map the perfect size. However maybe there is a better way should do this, or this is maybe where the rounding error comes from.

**EDIT** I've just tried rounding the scaling factor down to 2dp also, and it makes no difference. The bug still appears (this is still using the zoffset mod)
« Last Edit: February 23, 2014, 01:40:54 pm by dbanfield »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #11 on: February 23, 2014, 09:04:21 pm »
Are all the z positions definitely 0? The tile map scaling is fine, but only if your sprite is positioned at the same z value as the tile. If its pixel perfect + snapped to a pixel, this definitely shouldn't happen. If it doesn't happen in ortho mode, it suggests you're either not pixel perfect, or snapped correctly to a pixel.

dbanfield

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #12 on: February 28, 2014, 09:33:52 am »
So I verified

All chunk positions are 0
The tile map is the exact scale of the 1:1 Sprite
All objects are snapped to a pixel
I am using a camera view that keeps tkdCamera happy (no warning notifications in the component that I'm not using an unrecognised resolution)

Still seeing the bug. (this version including the zoffset hack attached)

Thinking about this some more, wouldn't this be something to do with the tile map? You say that "you're either not pixel perfect, or snapped correctly to a pixel". The tile map is snapped to a pixel since it is at 0, 0, and at the right scale according to a pixel perfect single tile that is also snapped correctly. But this doesn't necessarily imply that tile X, Y is perfectly snapped to a pixel. I'm relying on the tile map code to ensure that, and maybe somewhere along the way the precision isn't enough. Just a thought, I've no idea really!

For example the 1:1 scale is at 5dp. Maybe this isn't enough when you're talking about packing 100s of tiles next to each other.


Just as an aside, before I started using the tile map, I had my own similar (and far less sophisticated) editor script that would let you define a large box collider, and clicking a button on the component would create a bunch of tiles that would fill up the collider
i.e.
place tile at 0, 0
get width of tile
move along x by Value
place another tile
etc (repeat for y axis)

I actually found this same bug would appear, so rather than increasing by the perfect width I would increase by width to something like 4dp. Maybe there was an imperceptible overlap in the tiles but at least there were no unsightly gaps.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #13 on: February 28, 2014, 10:15:40 am »
The is to do with vertex shader precision and positions. At certain positions the vertices get snapped to the left vs the right pixel in the vertex shader. This happens most frequently when the matrix changes - i.e. at partition edges. Basically its much more likely to happen if you use a game object to position things, as it then gets multiplied by the other matrices, etc.

Basically, this is almost certainly going to happen if your camera isn't snapped to a pixel. You're using a perspective camera. Moving it by 0.01 pixel doesn't guarantee snapping to a pixel. You'd have to move it by a pixel, relative to all your objects. If you don't understand the maths behind snapping all of this to a pixel (you will need to consider all the layers you have for parallax), you should use one or more ortho cameras and manage your parallax manually, you get much more control that way.

Or if you want you can select all your sprites in the sprite collection editor and scale it up by a tiny amount in there, but this will likely cause pixel doubling / squashing in places. That will get rid of the gaps for sure, but at a cost.

dbanfield

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Bug for TileMap: gap in between tiles
« Reply #14 on: March 05, 2014, 09:34:30 pm »
ahhhh. yep makes sense - in my game where I first saw the error I was lerping the camera so would explain that too.
Solutions make sense too.

Thanks for taking the time to get to the bottom of this!!