Search Unity

2D Tiles - Lighting issue. Light introduces transparency when tiles overlap

Discussion in '2D' started by jaywree, Jan 24, 2019.

  1. jaywree

    jaywree

    Joined:
    Jan 24, 2019
    Posts:
    1
    Hi Unity community.

    This is an issue I've been trying to fix for over a week, so I would be incredible grateful if someone can help.

    TLDR - So I've narrowed the problem down to being:

    - When tiles overlap, with a "Sprite/Diffuse" material attached to them, light will shine through where they overlap.
    - When using tiles that are large (240x240 pixels), they always seem to overlap by a fair bit.


    I've been creating a 2D top-down RPG game in Unity.

    I've been using Unity's Tilemaps which has been working ok so far.

    I started by following a tutorial which uses 16x16 pixel tiles. I originally had some of the usual tile cell gap issues but fixed them by turning off compression, anti-aliasing, adding a very small minus cell gap, using a Sprite Material with "pixel snap" turned on, making sure "Filter mode" is "Point (no filter)" etc. There were lots of helpful posts online outlining this issue and how to fix it so that didn't worry me too much.

    Now, I've switched out to using a much bigger sprite for my Tile Map which has tiles that are 240px by 240px instead.

    When I use these tiles, I find that each of the tiles seems to overlap slightly (maybe by one or two pixels) even with all the same fixes from above... this isn't great, but isn't that obvious.

    UNTIL, I added lighting to my map. When I change the Tile Maps to have a Material with a "Sprites/Diffuse" shader, and then add a Light to the map, it seems to make all my tiles have some sort of strange transparency.

    I've tried this with the 16x16 pixel tiles and it doesn't have the same issue. It just occurs with my 240x240 tiles because of this annoying overlap. Where the tiles overlap, it looks as though light is shining through them. I've tried compressing my large png and removing the alpha from everything that isn't fully transparent, and I still seem to get the issue (I even tried removing the alpha altogether and I still get the issue.)

    With the 16x16 pixel tiles, if I decrease the cell gap more, and force them to overlap, I see the issue as well.

    (See TLDR for a recap of what I think is causing the issue)

    Any suggestions with how to fix this would be greatly appreciated.

    Thanks
    Josh


    IMAGE: Notice the white lines between the purple tiles
    Screenshot 2019-01-24 at 12.04.13.png

    IMAGE: When I remove the "Sprite/Diffuse" material from the tiles, you can't see the issue
    Screenshot 2019-01-24 at 12.04.51.png
     
    Last edited: Jan 24, 2019
  2. angetlog

    angetlog

    Joined:
    Jul 26, 2018
    Posts:
    2
    Same issue, but I don't think it is a problem with the sprite sizes. I'm using a 64x64 tile and the problem is still there.
     
  3. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    267