Search Unity

Question Separate normal maps for separate Tiles on a Tilemap

Discussion in '2D' started by Cevia, Apr 2, 2021.

  1. Cevia

    Cevia

    Joined:
    Jun 7, 2016
    Posts:
    3
    Recently I've been looking into using normal maps with the Unity Tilemap system, but was disappointed to find that as far as I can tell the only way this is possible is by using the Material property of the Tilemap Renderer component - restricting you to one normal map that is used for every Tile on the given Tilemap. This makes it quite difficult to create any kind of truly dynamically lit environment using Tilemaps.

    What I'm especially curious about is whether there is some kind of "hidden" SpriteRenderer component attached to individual Tiles, and if so whether there is any way to access it.

    In general I was just curious to hear if anyone has found a way to work around this restriction, or if there are plans in place to update this functionality in the near future.
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    tilemaps are made of a mesh, when you set tiles you are drawing on that mesh, there is no hidden sprite renderer per tile
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    You should look into Secondary Textures. https://docs.unity3d.com/Manual/SpriteEditor-SecondaryTextures.html

    If the material/shader uses _NormalMap then it will be supplied to it. An Individual Mode tilemap can have any number of _MainTex/_NormalMap pairs for the same material. It pulls dynamically from the sprite's secondary texture data. You're still restricted to 1 material per tilemap, but you have flexibility in supplying sprites to that tilemap. Unique items with unique materials could go onto a different tilemap or use SpriteRenderers.
     
  4. Cevia

    Cevia

    Joined:
    Jun 7, 2016
    Posts:
    3
    Thanks a lot! I wasn't aware of this functionality, looks like it should be exactly what I'm looking for. Will look into it more.
     
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    There's still the performance advantage of having one spritesheet / SpriteAtlas for as many of your tiles as possible.

    Luckily with an Individual Mode tilemap you can still mix and match sprites using different source textures.

    And Unity's SpriteAtlas supports packing secondary textures in parallel so that you can try to get the best of both worlds.

    Chunked tilemaps in contrast have the strict restriction that they must share the same spritesheet / atlas.