Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. We're excited to be bringing you the newest Unity features, news, demos, and we've even got some special guests from some of the industry’s most storied franchises. Set a reminder to tune in on YouTube here
    Dismiss Notice
  3. Unity 2018.3 is now released.
    Dismiss Notice

Think i found z sorting solution in chunk mode

Discussion in '2D Experimental Preview' started by o1o1o1o1o2, Dec 27, 2018.

  1. o1o1o1o1o2

    o1o1o1o1o2

    Joined:
    May 22, 2014
    Posts:
    14
    But it is a bit tricky. First of all you need to take Sprites-Default shader here https://github.com/nubick/unity-uti...Assets/Scripts/Shaders/Sprites-Default.shader and make new sprites-default-zwrite where you change ZWrite from Off to On. Now we have pure proper z ordering in chunk mode, but loose automatic Y-sorting. Because of that, to have correct sorting of tiles based on its height (position above plane if it were in 3d), we need to set each tile using pure z ordering: x = x + heigh, y = y + height, z = x + y - height. Then to get tile height first you need to have collider for each tile wich position based not only on x and y but on z too. Then height = (x+y-z)/3 . I not already test it much, but even if formula not correct it is possible to make it correct(?), try it yourself, maybe i am wrong, invented an hour ago but wanna share to maybe recieve some help in it. This solution is good cause chunk mode is much more performant than individual.

    p.s Also chunk mode work strange, so if you have artefacts try to make several tilemaps that will store less tiles 16x16 or 8x8. Or try to set custom outline on sprites
     

    Attached Files:

    Last edited: Dec 28, 2018
    Sylmerria likes this.
  2. o1o1o1o1o2

    o1o1o1o1o2

    Joined:
    May 22, 2014
    Posts:
    14
    Looks like it works!!!! huawei p10 60 fps (maximum pissible), in a chunk mode vs ~25 individual, video can not show, but everithing is very smooth, this tilemap made of chunks16*64*16 (data in 3d) and 16*16 (in iso) and with them i generate 3d mesh collider chunks to have oportunity get height of a tiles.

     
    Last edited: Dec 29, 2018
  3. synchrok

    synchrok

    Joined:
    Feb 5, 2015
    Posts:
    3
    Looks very cool!

    Could you explain a little more about the way you did it?

    I also have to work on a large tile map, individual mode is too slow and chunk mode does not sort correctly.

    I set the shader and the material with ZWrite on, but I do not know what part of the x y z formula means.
     
  4. o1o1o1o1o2

    o1o1o1o1o2

    Joined:
    May 22, 2014
    Posts:
    14
    First i would like to say that you shoud think twice before implementing that? it suits not all cases because of extra complexity added if you for example have sprites bigger than one cell (for example big trees in one sprite) and also when moving sprites you'll have to think about how to change z coord of each moving sprite to keep right sorting order. So then about formula:
    if you for example have simple unity 3d world coords of voxel and need representation of it on a tilemap then
    x_cell_pos_on_tilemap = x_world_pos + y_world_pos
    y_cell_pos_on_tilemap = z_world_pos + y_world_pos
    z_cell_pos_on_tilemap = x_world_pos + z_world_pos - y_world_pos,

    y_world_pos is height of voxel in 3d world coord,

    and i also changed scale of parent 3d object(all collider voxels are child of it), to vector3(0.707,0.578,0.707) to match the size of 3d cell to the size of tilemap cell if i look at 3d collider in isometric angle (i have 2 synchronized cameras, one look at tilemap and one at 3d collider representing terrain)
     
    Last edited: Mar 15, 2019 at 1:24 PM