Search Unity

2017.2 Tilemap - Additional Data per Tile Instance

Discussion in '2D' started by Sarkahn, Oct 14, 2017.

  1. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Hello, I'm messing with the newly released Tilemap in 2017.2. I want to add additional per-tile data that can be read through a custom shader. From what I can see by default the Tilemap uses the default sprite shader. It's also possible to set per-tile-instance colors via Tilemap.SetColor, which tells me there must be some kind of instancing going on under the hood.

    Is there some way I can set custom shader properties for an individual tile in the tilemap through the TilemapRenderer? If there is no instancing going on is it possible to set data directly to the underlying mesh?

    I've tried using the "traditional" gpu instancing methods that you would use with DrawMeshInstanced and DrawMeshInstancedIndirect - retrieving the property block from the tile map renderer, pushing const buffer and compute buffer arrays to it and setting it back to the tile map renderer but it didn't seem do anything.

    To give a more specific example of what I want - I want to be able to set secondary color data per tile that I can read through the shader. Maybe there's a more obvious way I can do this that I'm not thinking of?
     
  2. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
  3. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
  4. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    For the benefit of future googlers: On further testing it looks like there isn't any instancing going on. I can only guess but it seems like any color change you see via Tilemap.SetColor are embedded into the underlying mesh, and are read in the shader through the vertex colors.

    It would be nice to have access to the underlying mesh at least, but after experiencing Unity's attempt to provide "convenient" access to their uGUI meshes with their so called "Vertex Helper" maybe it's best left alone.
     
    Denzil likes this.
  5. Denzil

    Denzil

    Joined:
    Nov 15, 2012
    Posts:
    8
    Thanks for posting this. Some instance data would've been great.