Search Unity

Tile-based map with multiple shaders problem

Discussion in 'Shaders' started by madks13, Feb 9, 2017.

  1. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    Hello,

    until recently, i never had to work directly on shaders, so i'm pretty new to it.

    As mentioned in the title, i have a tile-based side-view map, represented in multiple meshes. Usually it would be a 200x200 tiles chunk placed in meshes of 64x64.

    Each tile can have (yes, each of them can be present or not) :
    - Terrain (texture, big high res image spanning over several tiles)
    - Resource (sprite, from a sprite sheet)
    - Decoration (like adding grass on top of the surface dirt tiles)
    - Glow (only on resource, time based)
    - Outline (for special effects, like showing ownership of tiles)
    - Selection outline (drawn when mouse hovering over the tile)

    I read the tutorials and documentation on Unity website, so i can more or less make separate shaders for each of the points. However, i'm not sure how to make it so it can know when to apply each one depending on the tile's data. Especially since selection outline is dependent on mouse position.

    Is there some way i'm not seeing due to my lack of knowledge or do i have to hack together something special for my situation? Or is there some other solution?

    Help please.
     
  2. asdfghjkloi87654

    asdfghjkloi87654

    Joined:
    Feb 16, 2013
    Posts:
    43
    I didn't understand your map system but you end up having a mesh (which is called tile or chunk or whatever). Then you can either add multiple materials with multiple shaders and activate them using a script or you create one shader and do all work internally. (you can use one features output in a shader to trigger another)
     
  3. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    Hello,

    i was very busy so i didn't have time to work on this for awhile. In the end after testing i found out i can make one mesh per tile (the tests i did before showed different results), so now i can actually assign materials per tile which eases the work a lot.