[Tiled2Unity] Lighting effect


(Alon Kreynes) #1

I’m new to Unity and Tiled in a whole. I’ve successfully exported a map into unity, all’s dandy, but i’m trying to make a night scene so i’d need lighting.

I’ve read somewhere that you need to add a material with a Sprite/Diffuse shader, but I have absolutely no clue where to exactly add it. I have a few layers on the map, but haven’t found the right component to add the material to. It either screws up the tile or doesn’t work.


(Seanba) #2

Hi Alon, this is a better question for the Unity forums but you you won’t be adding a material, instead you will edit the material on the layer(s) on the prefab to use the shader of your choice.

Best,
Sean


(Alon Kreynes) #3

Thanks for the reply, Sean, very appreciated!

Problem is, when i change the material that comes with Tiled2Unity, the tiles don’t snap and I get this very weird artifact of black lines showing on the tile borders. So ultimately, I have to choose between the two.
I hope you have an insight about this and could shed some light about what to do with it.

Thanks in advance,
Best Regards,
Alon


(Seanba) #4

Yes, those seams you are getting a common in Unity for some reason when you are using lighting. Very annoying.

The very best to combat that is to re-author your tiles in this kind of way (assuming you have 32x32 pixel tiles):

  • Make each tile 34x34 instead (adding a row/column of pixels to each side)
  • Have the top row of pixels the same as the pixels that come below it (on the source tile)
  • Have the bottom row of pixels the same as the pixels above it
  • Have the left column of pixels the same as those on the right
  • Have the right column of pixels the same as those on the left
  • Change your tileset properties so that there is a margin of 1 pixel around each tile. (This way, your tiles are still 32x32 in the tileset, but 34x34 in the texture)

What you are doing here is making up for the Unity texture sampler going out of bounds due to mathematical precision errors. In this case, should the texture sampler pick a texel “just outside” your tile then it will end up picking the same pixel that comes before it – if that makes sense. (If you look up “seams” and “texture sampling” on the internets you’ll get a better explanation.)

If you have a lot of tiles on a texture you can use a GIMP pluging called Gutter that should automate the process of adding a pixel boundary around each tile.

Here, I’ve found a blog post that explains all this with Tiled, Tiled2Unity, and Gimp: http://www.firebelly.net/post/114529965784/tile-gaps-using-unity-5-and-tiled2unity


(Alon Kreynes) #5

You sir, have helped me tons!

Thanks a bunch!!!


(Seanba) #6

Right on, dude. Good luck with your game.


(fross narazakyo) #7

this post might be old and your problem seems to already have been solved but after I fixed the material and got those lines in-between each tile, I fixed that by going to Edit>Project Settings>Quality, and turning anti-aliasing off, I’m not sure if this process is easier than the GIMP process but this one works for me and I can’t really see a drop in quality. GamesPlusJames (youtube) taught me that.

also thank you Seanba for the answer